@@ -29,14 +29,33 @@ struct i2c_nrfx_twim_rtio_config {
2929struct i2c_nrfx_twim_rtio_data {
3030 uint8_t * user_rx_buf ;
3131 uint16_t user_rx_buf_size ;
32+ uint8_t * buf_ptr ;
3233};
3334
3435static bool i2c_nrfx_twim_rtio_msg_start (const struct device * dev , uint8_t flags , uint8_t * buf ,
3536 size_t buf_len , uint16_t i2c_addr )
3637{
3738 const struct i2c_nrfx_twim_rtio_config * config = dev -> config ;
39+ struct i2c_nrfx_twim_rtio_data * data = dev -> data ;
3840 struct i2c_rtio * ctx = config -> ctx ;
3941 int ret = 0 ;
42+ uint8_t * dma_buf ;
43+
44+ if (flags & I2C_MSG_READ ) {
45+ ret = dmm_buffer_in_prepare (config -> common .mem_reg , buf , buf_len ,
46+ (void * * )& dma_buf );
47+ } else {
48+ ret = dmm_buffer_out_prepare (config -> common .mem_reg , buf , buf_len ,
49+ (void * * )& dma_buf );
50+ }
51+
52+ if (ret < 0 ) {
53+ LOG_ERR ("Failed to prepare buffer: %d" , ret );
54+ return false;
55+ }
56+
57+ data -> buf_ptr = buf ;
58+ buf = dma_buf ;
4059
4160 ret = i2c_nrfx_twim_msg_transfer (dev , flags , buf , buf_len , i2c_addr );
4261 if (ret != 0 ) {
@@ -188,6 +207,21 @@ static void event_handler(nrfx_twim_evt_t const *p_event, void *p_context)
188207 const struct i2c_nrfx_twim_rtio_config * config = dev -> config ;
189208 struct i2c_nrfx_twim_rtio_data * data = dev -> data ;
190209 int status = p_event -> type == NRFX_TWIM_EVT_DONE ? 0 : - EIO ;
210+ int ret = 0 ;
211+
212+ if (p_event -> xfer_desc .type == NRFX_TWIM_XFER_TX ) {
213+ ret = dmm_buffer_out_release (config -> common .mem_reg ,
214+ (void * * )& p_event -> xfer_desc .p_primary_buf );
215+ } else {
216+ ret = dmm_buffer_in_release (config -> common .mem_reg , data -> buf_ptr ,
217+ p_event -> xfer_desc .primary_length ,
218+ p_event -> xfer_desc .p_primary_buf );
219+ }
220+
221+ if (ret < 0 ) {
222+ i2c_nrfx_twim_rtio_complete (dev , ret );
223+ return ;
224+ }
191225
192226 if (data -> user_rx_buf ) {
193227 memcpy (data -> user_rx_buf , config -> common .msg_buf , data -> user_rx_buf_size );
@@ -284,6 +318,7 @@ static int i2c_nrfx_twim_rtio_deinit(const struct device *dev)
284318 .pcfg = PINCTRL_DT_DEV_CONFIG_GET(I2C(idx)), \
285319 IF_ENABLED(USES_MSG_BUF(idx), (.msg_buf = MSG_BUF_SYM(idx),)) \
286320 .max_transfer_size = MAX_TRANSFER_SIZE(idx), \
321+ .mem_reg = DMM_DEV_TO_REG(I2C(idx)), \
287322 }, \
288323 .ctx = &_i2c##idx##_twim_rtio, \
289324 }; \
0 commit comments