@@ -219,85 +219,73 @@ static int i2c_nrfx_twim_rtio_deinit(const struct device *dev)
219219 return i2c_nrfx_twim_common_deinit (dev );
220220}
221221
222- #define CONCAT_BUF_SIZE (idx ) \
223- COND_CODE_1(DT_NODE_HAS_PROP(DT_DRV_INST(idx), zephyr_concat_buf_size), \
224- (DT_INST_PROP(idx, zephyr_concat_buf_size)), (0))
225- #define FLASH_BUF_MAX_SIZE (idx ) \
226- COND_CODE_1(DT_NODE_HAS_PROP(DT_DRV_INST(idx), zephyr_flash_buf_max_size), \
227- (DT_INST_PROP(idx, zephyr_flash_buf_max_size)), (0))
228-
229- #define USES_MSG_BUF (idx ) \
230- COND_CODE_0(CONCAT_BUF_SIZE(idx), (COND_CODE_0(FLASH_BUF_MAX_SIZE(idx), (0), (1))), (1))
231- #define MSG_BUF_SIZE (idx ) MAX(CONCAT_BUF_SIZE(idx), FLASH_BUF_MAX_SIZE(idx))
232-
233- #define MSG_BUF_HAS_MEMORY_REGIONS (idx ) DT_NODE_HAS_PROP(DT_DRV_INST(idx), memory_regions)
234-
235- #define MSG_BUF_LINKER_REGION_NAME (idx ) \
236- LINKER_DT_NODE_REGION_NAME(DT_PHANDLE(DT_DRV_INST(idx), memory_regions))
237-
238- #define MSG_BUF_ATTR_SECTION (idx ) \
239- __attribute__((__section__(MSG_BUF_LINKER_REGION_NAME(idx))))
240-
241- #define MSG_BUF_ATTR (idx ) \
242- COND_CODE_1( \
243- MSG_BUF_HAS_MEMORY_REGIONS(idx), \
244- (MSG_BUF_ATTR_SECTION(idx)), \
245- () \
222+ #define MSG_BUF_HAS_MEMORY_REGIONS (inst ) DT_INST_NODE_HAS_PROP(inst, memory_regions)
223+
224+ #define MSG_BUF_LINKER_REGION_NAME (inst ) \
225+ LINKER_DT_NODE_REGION_NAME(DT_INST_PHANDLE(inst, memory_regions))
226+
227+ #define MSG_BUF_ATTR_SECTION (inst ) \
228+ __attribute__((__section__(MSG_BUF_LINKER_REGION_NAME(inst))))
229+
230+ #define MSG_BUF_ATTR (inst ) \
231+ COND_CODE_1( \
232+ MSG_BUF_HAS_MEMORY_REGIONS(inst), \
233+ (MSG_BUF_ATTR_SECTION(inst)), \
234+ () \
246235 )
247236
248- #define MSG_BUF_SYM (idx ) \
249- _CONCAT_3(twim_, idx, _msg_buf)
250-
251- #define MSG_BUF_DEFINE (idx ) \
252- static uint8_t MSG_BUF_SYM(idx)[MSG_BUF_SIZE(idx)] MSG_BUF_ATTR(idx)
253-
254- #define MAX_TRANSFER_SIZE (idx ) BIT_MASK(DT_INST_PROP(idx, easydma_maxcnt_bits))
255-
256- #define I2C_NRFX_TWIM_RTIO_DEVICE (idx ) \
257- NRF_DT_CHECK_NODE_HAS_PINCTRL_SLEEP(DT_DRV_INST(idx)); \
258- NRF_DT_CHECK_NODE_HAS_REQUIRED_MEMORY_REGIONS(DT_DRV_INST(idx)); \
259- BUILD_ASSERT(I2C_FREQUENCY(DT_DRV_INST(idx)) != I2C_NRFX_TWIM_INVALID_FREQUENCY, \
260- "Wrong I2C " #idx " frequency setting in dts"); \
261- static struct i2c_nrfx_twim_rtio_data twim_##idx##z_data = { \
262- .twim = \
263- { \
264- .p_twim = (NRF_TWIM_Type *)DT_INST_REG_ADDR(idx), \
265- }, \
266- }; \
267- static void pre_init##idx(void) \
268- { \
269- twim_##idx##z_data.twim.p_twim = (NRF_TWIM_Type *)DT_INST_REG_ADDR(idx); \
270- IRQ_CONNECT(DT_INST_IRQN(idx), DT_INST_IRQ(idx, priority), nrfx_twim_irq_handler, \
271- &twim_##idx##z_data.twim, 0); \
272- } \
273- IF_ENABLED(USES_MSG_BUF(idx), (MSG_BUF_DEFINE(idx);)) \
274- I2C_RTIO_DEFINE(_i2c##idx##_twim_rtio, \
275- DT_INST_PROP_OR(n, sq_size, CONFIG_I2C_RTIO_SQ_SIZE), \
276- DT_INST_PROP_OR(n, cq_size, CONFIG_I2C_RTIO_CQ_SIZE)); \
277- PINCTRL_DT_INST_DEFINE(idx); \
278- static const struct i2c_nrfx_twim_rtio_config twim_##idx##z_config = { \
279- .common = \
280- { \
281- .twim_config = \
282- { \
283- .skip_gpio_cfg = true, \
284- .skip_psel_cfg = true, \
285- .frequency = I2C_FREQUENCY(DT_DRV_INST(idx)), \
286- }, \
287- .event_handler = event_handler, \
288- .msg_buf_size = MSG_BUF_SIZE(idx), \
289- .pre_init = pre_init##idx, \
290- .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(idx), \
291- IF_ENABLED(USES_MSG_BUF(idx), (.msg_buf = MSG_BUF_SYM(idx),)) \
292- .max_transfer_size = MAX_TRANSFER_SIZE(idx), \
293- .twim = &twim_##idx##z_data.twim, \
294- }, \
295- .ctx = &_i2c##idx##_twim_rtio, \
296- }; \
297- PM_DEVICE_DT_INST_DEFINE(idx, twim_nrfx_pm_action, I2C_PM_ISR_SAFE(idx)); \
298- I2C_DEVICE_DT_INST_DEINIT_DEFINE(idx, i2c_nrfx_twim_rtio_init, i2c_nrfx_twim_rtio_deinit, \
299- PM_DEVICE_DT_INST_GET(idx), &twim_##idx##z_data, \
300- &twim_##idx##z_config, POST_KERNEL, \
301- CONFIG_I2C_INIT_PRIORITY, &i2c_nrfx_twim_driver_api);
237+ #define MSG_BUF_SYM (inst ) \
238+ _CONCAT_3(twim_, inst, _msg_buf)
239+
240+ #define MSG_BUF_DEFINE (inst ) \
241+ static uint8_t MSG_BUF_SYM(inst)[MSG_BUF_SIZE(inst)] MSG_BUF_ATTR(inst)
242+
243+ #define I2C_NRFX_TWIM_RTIO_DEVICE (inst ) \
244+ NRF_DT_CHECK_NODE_HAS_PINCTRL_SLEEP(DT_DRV_INST(inst)); \
245+ NRF_DT_CHECK_NODE_HAS_REQUIRED_MEMORY_REGIONS(DT_DRV_INST(inst)); \
246+ BUILD_ASSERT(I2C_FREQUENCY(inst) != I2C_NRFX_TWIM_INVALID_FREQUENCY, \
247+ "Wrong I2C " #inst " frequency setting in dts"); \
248+ static struct i2c_nrfx_twim_rtio_data twim_##inst##z_data = { \
249+ .twim = \
250+ { \
251+ .p_twim = (NRF_TWIM_Type *)DT_INST_REG_ADDR(inst), \
252+ }, \
253+ }; \
254+ static void pre_init##inst(void) \
255+ { \
256+ twim_##inst##z_data.twim.p_twim = (NRF_TWIM_Type *)DT_INST_REG_ADDR(inst); \
257+ IRQ_CONNECT(DT_INST_IRQN(inst), DT_INST_IRQ(inst, priority), \
258+ nrfx_twim_irq_handler, &twim_##inst##z_data.twim, 0); \
259+ } \
260+ IF_ENABLED(USES_MSG_BUF(inst), (MSG_BUF_DEFINE(inst);)) \
261+ I2C_RTIO_DEFINE(_i2c##inst##_twim_rtio, \
262+ DT_INST_PROP_OR(n, sq_size, CONFIG_I2C_RTIO_SQ_SIZE), \
263+ DT_INST_PROP_OR(n, cq_size, CONFIG_I2C_RTIO_CQ_SIZE)); \
264+ PINCTRL_DT_INST_DEFINE(inst); \
265+ static const struct i2c_nrfx_twim_rtio_config twim_##inst##z_config = { \
266+ .common = \
267+ { \
268+ .twim_config = \
269+ { \
270+ .skip_gpio_cfg = true, \
271+ .skip_psel_cfg = true, \
272+ .frequency = I2C_FREQUENCY(inst), \
273+ }, \
274+ .event_handler = event_handler, \
275+ .msg_buf_size = MSG_BUF_SIZE(inst), \
276+ .pre_init = pre_init##inst, \
277+ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
278+ IF_ENABLED(USES_MSG_BUF(inst), (.msg_buf = MSG_BUF_SYM(inst),)) \
279+ .max_transfer_size = MAX_TRANSFER_SIZE(inst), \
280+ .twim = &twim_##inst##z_data.twim, \
281+ }, \
282+ .ctx = &_i2c##inst##_twim_rtio, \
283+ }; \
284+ PM_DEVICE_DT_INST_DEFINE(inst, twim_nrfx_pm_action, I2C_PM_ISR_SAFE(inst)); \
285+ I2C_DEVICE_DT_INST_DEINIT_DEFINE(inst, i2c_nrfx_twim_rtio_init, \
286+ i2c_nrfx_twim_rtio_deinit, \
287+ PM_DEVICE_DT_INST_GET(inst), &twim_##inst##z_data, \
288+ &twim_##inst##z_config, POST_KERNEL, \
289+ CONFIG_I2C_INIT_PRIORITY, &i2c_nrfx_twim_driver_api); \
302290
303291DT_INST_FOREACH_STATUS_OKAY (I2C_NRFX_TWIM_RTIO_DEVICE )
0 commit comments