drivers: i2c: nordic: move to new DT API
Keep existing per-instance Kconfig options around. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
parent
df8be2d2e0
commit
11fbc0b2fa
2 changed files with 23 additions and 24 deletions
|
@ -242,17 +242,17 @@ static int twi_nrfx_pm_control(struct device *dev, u32_t ctrl_command,
|
||||||
: bitrate == 250000 ? NRF_TWI_FREQ_250K \
|
: bitrate == 250000 ? NRF_TWI_FREQ_250K \
|
||||||
: bitrate == I2C_BITRATE_FAST ? NRF_TWI_FREQ_400K \
|
: bitrate == I2C_BITRATE_FAST ? NRF_TWI_FREQ_400K \
|
||||||
: I2C_NRFX_TWI_INVALID_FREQUENCY)
|
: I2C_NRFX_TWI_INVALID_FREQUENCY)
|
||||||
|
#define I2C(idx) DT_NODELABEL(i2c##idx)
|
||||||
|
#define I2C_FREQUENCY(idx) \
|
||||||
|
I2C_NRFX_TWI_FREQUENCY(DT_PROP(I2C(idx), clock_frequency))
|
||||||
|
|
||||||
#define I2C_NRFX_TWI_DEVICE(idx) \
|
#define I2C_NRFX_TWI_DEVICE(idx) \
|
||||||
BUILD_ASSERT( \
|
BUILD_ASSERT(I2C_FREQUENCY(idx) != \
|
||||||
I2C_NRFX_TWI_FREQUENCY( \
|
I2C_NRFX_TWI_INVALID_FREQUENCY, \
|
||||||
DT_NORDIC_NRF_TWI_I2C_##idx##_CLOCK_FREQUENCY) \
|
"Wrong I2C " #idx " frequency setting in dts"); \
|
||||||
!= I2C_NRFX_TWI_INVALID_FREQUENCY, \
|
|
||||||
"Wrong I2C " #idx " frequency setting in dts"); \
|
|
||||||
static int twi_##idx##_init(struct device *dev) \
|
static int twi_##idx##_init(struct device *dev) \
|
||||||
{ \
|
{ \
|
||||||
IRQ_CONNECT(DT_NORDIC_NRF_TWI_I2C_##idx##_IRQ_0, \
|
IRQ_CONNECT(DT_IRQN(I2C(idx)), DT_IRQ(I2C(idx), priority), \
|
||||||
DT_NORDIC_NRF_TWI_I2C_##idx##_IRQ_0_PRIORITY, \
|
|
||||||
nrfx_isr, nrfx_twi_##idx##_irq_handler, 0); \
|
nrfx_isr, nrfx_twi_##idx##_irq_handler, 0); \
|
||||||
return init_twi(dev); \
|
return init_twi(dev); \
|
||||||
} \
|
} \
|
||||||
|
@ -265,14 +265,13 @@ static int twi_nrfx_pm_control(struct device *dev, u32_t ctrl_command,
|
||||||
static const struct i2c_nrfx_twi_config twi_##idx##z_config = { \
|
static const struct i2c_nrfx_twi_config twi_##idx##z_config = { \
|
||||||
.twi = NRFX_TWI_INSTANCE(idx), \
|
.twi = NRFX_TWI_INSTANCE(idx), \
|
||||||
.config = { \
|
.config = { \
|
||||||
.scl = DT_NORDIC_NRF_TWI_I2C_##idx##_SCL_PIN, \
|
.scl = DT_PROP(I2C(idx), scl_pin), \
|
||||||
.sda = DT_NORDIC_NRF_TWI_I2C_##idx##_SDA_PIN, \
|
.sda = DT_PROP(I2C(idx), sda_pin), \
|
||||||
.frequency = I2C_NRFX_TWI_FREQUENCY( \
|
.frequency = I2C_FREQUENCY(idx), \
|
||||||
DT_NORDIC_NRF_TWI_I2C_##idx##_CLOCK_FREQUENCY) \
|
|
||||||
} \
|
} \
|
||||||
}; \
|
}; \
|
||||||
DEVICE_DEFINE(twi_##idx, \
|
DEVICE_DEFINE(twi_##idx, \
|
||||||
DT_NORDIC_NRF_TWI_I2C_##idx##_LABEL, \
|
DT_LABEL(I2C(idx)), \
|
||||||
twi_##idx##_init, \
|
twi_##idx##_init, \
|
||||||
twi_nrfx_pm_control, \
|
twi_nrfx_pm_control, \
|
||||||
&twi_##idx##_data, \
|
&twi_##idx##_data, \
|
||||||
|
|
|
@ -217,16 +217,17 @@ static int twim_nrfx_pm_control(struct device *dev, u32_t ctrl_command,
|
||||||
: bitrate == I2C_BITRATE_FAST ? NRF_TWIM_FREQ_400K \
|
: bitrate == I2C_BITRATE_FAST ? NRF_TWIM_FREQ_400K \
|
||||||
: I2C_NRFX_TWIM_INVALID_FREQUENCY)
|
: I2C_NRFX_TWIM_INVALID_FREQUENCY)
|
||||||
|
|
||||||
|
#define I2C(idx) DT_NODELABEL(i2c##idx)
|
||||||
|
#define I2C_FREQUENCY(idx) \
|
||||||
|
I2C_NRFX_TWIM_FREQUENCY(DT_PROP(I2C(idx), clock_frequency))
|
||||||
|
|
||||||
#define I2C_NRFX_TWIM_DEVICE(idx) \
|
#define I2C_NRFX_TWIM_DEVICE(idx) \
|
||||||
BUILD_ASSERT( \
|
BUILD_ASSERT(I2C_FREQUENCY(idx) != \
|
||||||
I2C_NRFX_TWIM_FREQUENCY( \
|
I2C_NRFX_TWIM_INVALID_FREQUENCY, \
|
||||||
DT_NORDIC_NRF_TWIM_I2C_##idx##_CLOCK_FREQUENCY) \
|
"Wrong I2C " #idx " frequency setting in dts"); \
|
||||||
!= I2C_NRFX_TWIM_INVALID_FREQUENCY, \
|
|
||||||
"Wrong I2C " #idx " frequency setting in dts"); \
|
|
||||||
static int twim_##idx##_init(struct device *dev) \
|
static int twim_##idx##_init(struct device *dev) \
|
||||||
{ \
|
{ \
|
||||||
IRQ_CONNECT(DT_NORDIC_NRF_TWIM_I2C_##idx##_IRQ_0, \
|
IRQ_CONNECT(DT_IRQN(I2C(idx)), DT_IRQ(I2C(idx), priority), \
|
||||||
DT_NORDIC_NRF_TWIM_I2C_##idx##_IRQ_0_PRIORITY, \
|
|
||||||
nrfx_isr, nrfx_twim_##idx##_irq_handler, 0); \
|
nrfx_isr, nrfx_twim_##idx##_irq_handler, 0); \
|
||||||
return init_twim(dev); \
|
return init_twim(dev); \
|
||||||
} \
|
} \
|
||||||
|
@ -239,14 +240,13 @@ static int twim_nrfx_pm_control(struct device *dev, u32_t ctrl_command,
|
||||||
static const struct i2c_nrfx_twim_config twim_##idx##z_config = { \
|
static const struct i2c_nrfx_twim_config twim_##idx##z_config = { \
|
||||||
.twim = NRFX_TWIM_INSTANCE(idx), \
|
.twim = NRFX_TWIM_INSTANCE(idx), \
|
||||||
.config = { \
|
.config = { \
|
||||||
.scl = DT_NORDIC_NRF_TWIM_I2C_##idx##_SCL_PIN, \
|
.scl = DT_PROP(I2C(idx), scl_pin), \
|
||||||
.sda = DT_NORDIC_NRF_TWIM_I2C_##idx##_SDA_PIN, \
|
.sda = DT_PROP(I2C(idx), sda_pin), \
|
||||||
.frequency = I2C_NRFX_TWIM_FREQUENCY( \
|
.frequency = I2C_FREQUENCY(idx), \
|
||||||
DT_NORDIC_NRF_TWIM_I2C_##idx##_CLOCK_FREQUENCY)\
|
|
||||||
} \
|
} \
|
||||||
}; \
|
}; \
|
||||||
DEVICE_DEFINE(twim_##idx, \
|
DEVICE_DEFINE(twim_##idx, \
|
||||||
DT_NORDIC_NRF_TWIM_I2C_##idx##_LABEL, \
|
DT_LABEL(I2C(idx)), \
|
||||||
twim_##idx##_init, \
|
twim_##idx##_init, \
|
||||||
twim_nrfx_pm_control, \
|
twim_nrfx_pm_control, \
|
||||||
&twim_##idx##_data, \
|
&twim_##idx##_data, \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue