@@ -29,14 +29,33 @@ struct i2c_nrfx_twim_rtio_config {
29
29
struct i2c_nrfx_twim_rtio_data {
30
30
uint8_t * user_rx_buf ;
31
31
uint16_t user_rx_buf_size ;
32
+ uint8_t * buf_ptr ;
32
33
};
33
34
34
35
static bool i2c_nrfx_twim_rtio_msg_start (const struct device * dev , uint8_t flags , uint8_t * buf ,
35
36
size_t buf_len , uint16_t i2c_addr )
36
37
{
37
38
const struct i2c_nrfx_twim_rtio_config * config = dev -> config ;
39
+ struct i2c_nrfx_twim_rtio_data * data = dev -> data ;
38
40
struct i2c_rtio * ctx = config -> ctx ;
39
41
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 ;
40
59
41
60
ret = i2c_nrfx_twim_msg_transfer (dev , flags , buf , buf_len , i2c_addr );
42
61
if (ret != 0 ) {
@@ -188,6 +207,21 @@ static void event_handler(nrfx_twim_evt_t const *p_event, void *p_context)
188
207
const struct i2c_nrfx_twim_rtio_config * config = dev -> config ;
189
208
struct i2c_nrfx_twim_rtio_data * data = dev -> data ;
190
209
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
+ }
191
225
192
226
if (data -> user_rx_buf ) {
193
227
memcpy (data -> user_rx_buf , config -> common .msg_buf , data -> user_rx_buf_size );
@@ -283,6 +317,7 @@ static int i2c_nrfx_twim_rtio_deinit(const struct device *dev)
283
317
.pcfg = PINCTRL_DT_DEV_CONFIG_GET(I2C(idx)), \
284
318
IF_ENABLED(USES_MSG_BUF(idx), (.msg_buf = MSG_BUF_SYM(idx),)) \
285
319
.max_transfer_size = MAX_TRANSFER_SIZE(idx), \
320
+ .mem_reg = DMM_DEV_TO_REG(I2C(idx)), \
286
321
}, \
287
322
.ctx = &_i2c##idx##_twim_rtio, \
288
323
}; \
0 commit comments