i2c: nordic: switch to phandle arrays for pinmux
Deprecate the scl-pin and sda-pin properties in the devicetree.
Provide new scl-gpios and sda-gpios properties instead.
This lets the user specify SCL and SDA like this:
&i2c0 {
scl-gpios = <&gpio0 1 0>;
sda-gpios = <&gpio1 4 0>;
};
Instead of having to use:
&i2c0 {
scl-pin = <1>;
sda-pin = <36>;
};
Provide error checking and understandable error messages for invalid
configurations.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
parent
f7aeb2ae4b
commit
821c03a14a
@ -8,6 +8,7 @@
|
||||
#include <drivers/i2c.h>
|
||||
#include <dt-bindings/i2c/i2c.h>
|
||||
#include <nrfx_twi.h>
|
||||
#include <soc.h>
|
||||
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_REGISTER(i2c_nrfx_twi, CONFIG_I2C_LOG_LEVEL);
|
||||
@ -276,6 +277,14 @@ static int twi_nrfx_pm_control(const struct device *dev,
|
||||
BUILD_ASSERT(I2C_FREQUENCY(idx) != \
|
||||
I2C_NRFX_TWI_INVALID_FREQUENCY, \
|
||||
"Wrong I2C " #idx " frequency setting in dts"); \
|
||||
NRF_DT_PSEL_CHECK_EXACTLY_ONE(I2C(idx), \
|
||||
sda_pin, "sda-pin", \
|
||||
sda_gpios, "sda-gpios"); \
|
||||
NRF_DT_PSEL_CHECK_EXACTLY_ONE(I2C(idx), \
|
||||
scl_pin, "scl-pin", \
|
||||
scl_gpios, "scl-gpios"); \
|
||||
NRF_DT_CHECK_GPIO_CTLR_IS_SOC(I2C(idx), sda_gpios, "sda-gpios"); \
|
||||
NRF_DT_CHECK_GPIO_CTLR_IS_SOC(I2C(idx), scl_gpios, "scl-gpios"); \
|
||||
static int twi_##idx##_init(const struct device *dev) \
|
||||
{ \
|
||||
IRQ_CONNECT(DT_IRQN(I2C(idx)), DT_IRQ(I2C(idx), priority), \
|
||||
@ -291,8 +300,8 @@ static int twi_nrfx_pm_control(const struct device *dev,
|
||||
static const struct i2c_nrfx_twi_config twi_##idx##z_config = { \
|
||||
.twi = NRFX_TWI_INSTANCE(idx), \
|
||||
.config = { \
|
||||
.scl = DT_PROP(I2C(idx), scl_pin), \
|
||||
.sda = DT_PROP(I2C(idx), sda_pin), \
|
||||
.scl = NRF_DT_PSEL(I2C(idx), scl_pin, scl_gpios, 0), \
|
||||
.sda = NRF_DT_PSEL(I2C(idx), sda_pin, sda_gpios, 0), \
|
||||
.frequency = I2C_FREQUENCY(idx), \
|
||||
} \
|
||||
}; \
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#include <dt-bindings/i2c/i2c.h>
|
||||
#include <nrfx_twim.h>
|
||||
#include <sys/util.h>
|
||||
#include <soc.h>
|
||||
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_REGISTER(i2c_nrfx_twim, CONFIG_I2C_LOG_LEVEL);
|
||||
@ -324,6 +325,14 @@ static int twim_nrfx_pm_control(const struct device *dev,
|
||||
BUILD_ASSERT(I2C_FREQUENCY(idx) != \
|
||||
I2C_NRFX_TWIM_INVALID_FREQUENCY, \
|
||||
"Wrong I2C " #idx " frequency setting in dts"); \
|
||||
NRF_DT_PSEL_CHECK_EXACTLY_ONE(I2C(idx), \
|
||||
sda_pin, "sda-pin", \
|
||||
sda_gpios, "sda-gpios"); \
|
||||
NRF_DT_PSEL_CHECK_EXACTLY_ONE(I2C(idx), \
|
||||
scl_pin, "scl-pin", \
|
||||
scl_gpios, "scl-gpios"); \
|
||||
NRF_DT_CHECK_GPIO_CTLR_IS_SOC(I2C(idx), sda_gpios, "sda-gpios"); \
|
||||
NRF_DT_CHECK_GPIO_CTLR_IS_SOC(I2C(idx), scl_gpios, "scl-gpios"); \
|
||||
static int twim_##idx##_init(const struct device *dev) \
|
||||
{ \
|
||||
IRQ_CONNECT(DT_IRQN(I2C(idx)), DT_IRQ(I2C(idx), priority), \
|
||||
@ -344,8 +353,8 @@ static int twim_nrfx_pm_control(const struct device *dev,
|
||||
static const struct i2c_nrfx_twim_config twim_##idx##z_config = { \
|
||||
.twim = NRFX_TWIM_INSTANCE(idx), \
|
||||
.config = { \
|
||||
.scl = DT_PROP(I2C(idx), scl_pin), \
|
||||
.sda = DT_PROP(I2C(idx), sda_pin), \
|
||||
.scl = NRF_DT_PSEL(I2C(idx), scl_pin, scl_gpios, 0), \
|
||||
.sda = NRF_DT_PSEL(I2C(idx), sda_pin, sda_gpios, 0), \
|
||||
.frequency = I2C_FREQUENCY(idx), \
|
||||
} \
|
||||
}; \
|
||||
|
||||
@ -13,10 +13,36 @@ properties:
|
||||
interrupts:
|
||||
required: true
|
||||
|
||||
sda-gpios:
|
||||
type: phandle-array
|
||||
required: false
|
||||
description: |
|
||||
The SDA pin to use. The value is "<&gpioX Y flags>".
|
||||
Pin PX.Y will be used for SDA. The "flags" portion currently
|
||||
has no effect, but must be set to zero.
|
||||
|
||||
For example, to use P0.16 for SDA, set:
|
||||
|
||||
sda-gpios = <&gpio0 16 0>;
|
||||
|
||||
To use P1.2 for SDA, set:
|
||||
|
||||
sda-gpios = <&gpio1 2 0>;
|
||||
|
||||
scl-gpios:
|
||||
type: phandle-array
|
||||
required: false
|
||||
description: |
|
||||
The SCL pin to use. The value should be set in the same
|
||||
way as the sda-gpios property.
|
||||
|
||||
sda-pin:
|
||||
type: int
|
||||
required: true
|
||||
required: false
|
||||
deprecated: true
|
||||
description: |
|
||||
Deprecated; use sda-gpios instead.
|
||||
|
||||
The SDA pin to use.
|
||||
|
||||
For pins P0.0 through P0.31, use the pin number. For example,
|
||||
@ -31,7 +57,10 @@ properties:
|
||||
|
||||
scl-pin:
|
||||
type: int
|
||||
required: true
|
||||
required: false
|
||||
deprecated: true
|
||||
description: |
|
||||
Deprecated; use scl-gpios instead.
|
||||
|
||||
The SCL pin to use. The pin numbering scheme is the same as
|
||||
the sda-pin property's.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user