@@ -22,6 +22,19 @@ enum bmp581_stream_state {
22
22
BMP581_STREAM_BUSY = 2 ,
23
23
};
24
24
25
+ static inline void bmp581_stream_result (const struct device * dev , int err )
26
+ {
27
+ struct bmp581_data * data = dev -> data ;
28
+ struct rtio_iodev_sqe * iodev_sqe = data -> stream .iodev_sqe ;
29
+
30
+ data -> stream .iodev_sqe = NULL ;
31
+ if (err < 0 ) {
32
+ rtio_iodev_sqe_err (iodev_sqe , err );
33
+ } else {
34
+ rtio_iodev_sqe_ok (iodev_sqe , 0 );
35
+ }
36
+ }
37
+
25
38
static void bmp581_stream_event_complete (struct rtio * ctx , const struct rtio_sqe * sqe , void * arg0 )
26
39
{
27
40
struct rtio_iodev_sqe * iodev_sqe = (struct rtio_iodev_sqe * )arg0 ;
@@ -65,12 +78,7 @@ static void bmp581_stream_event_complete(struct rtio *ctx, const struct rtio_sqe
65
78
66
79
bmp581_stream_evt_finish :
67
80
atomic_set (& data -> stream .state , BMP581_STREAM_ON );
68
-
69
- if (err < 0 ) {
70
- rtio_iodev_sqe_err (iodev_sqe , err );
71
- } else {
72
- rtio_iodev_sqe_ok (iodev_sqe , 0 );
73
- }
81
+ bmp581_stream_result (dev , err );
74
82
}
75
83
76
84
static void bmp581_event_handler (const struct device * dev )
@@ -115,7 +123,7 @@ static void bmp581_event_handler(const struct device *dev)
115
123
& buf , & buf_len );
116
124
CHECKIF (err != 0 || buf_len < sizeof (struct bmp581_encoded_data )) {
117
125
LOG_ERR ("Failed to allocate BMP581 encoded buffer: %d" , err );
118
- rtio_iodev_sqe_err ( iodev_sqe , - ENOMEM );
126
+ bmp581_stream_result ( dev , - ENOMEM );
119
127
return ;
120
128
}
121
129
@@ -126,7 +134,7 @@ static void bmp581_event_handler(const struct device *dev)
126
134
edata -> payload , sizeof (edata -> payload ),
127
135
& read_sqe );
128
136
CHECKIF (err < 0 || !read_sqe ) {
129
- rtio_iodev_sqe_err ( iodev_sqe , err );
137
+ bmp581_stream_result ( dev , err );
130
138
return ;
131
139
}
132
140
read_sqe -> flags |= RTIO_SQE_CHAINED ;
@@ -141,7 +149,7 @@ static void bmp581_event_handler(const struct device *dev)
141
149
142
150
CHECKIF (err != 0 || (buf_len < len_required )) {
143
151
LOG_ERR ("Failed to allocate BMP581 encoded buffer: %d" , err );
144
- rtio_iodev_sqe_err ( iodev_sqe , - ENOMEM );
152
+ bmp581_stream_result ( dev , - ENOMEM );
145
153
return ;
146
154
}
147
155
@@ -152,7 +160,7 @@ static void bmp581_event_handler(const struct device *dev)
152
160
(uint8_t * )edata -> frame , len_data ,
153
161
& read_sqe );
154
162
CHECKIF (err < 0 || !read_sqe ) {
155
- rtio_iodev_sqe_err ( iodev_sqe , err );
163
+ bmp581_stream_result ( dev , err );
156
164
return ;
157
165
}
158
166
read_sqe -> flags |= RTIO_SQE_CHAINED ;
@@ -179,7 +187,7 @@ static void bmp581_event_handler(const struct device *dev)
179
187
cb_sqe = rtio_sqe_acquire (cfg -> bus .rtio .ctx );
180
188
if (cb_sqe == NULL ) {
181
189
LOG_ERR ("Failed to acquire callback SQE" );
182
- rtio_iodev_sqe_err ( iodev_sqe , - ENOMEM );
190
+ bmp581_stream_result ( dev , - ENOMEM );
183
191
return ;
184
192
}
185
193
@@ -299,7 +307,7 @@ void bmp581_stream_submit(const struct device *dev,
299
307
if ((enabled_mask & BMP581_EVENT_FIFO_WM ) != 0 ) {
300
308
err = bmp581_stream_prep_fifo_wm_async (dev );
301
309
if (err < 0 ) {
302
- rtio_iodev_sqe_err ( iodev_sqe , err );
310
+ bmp581_stream_result ( dev , err );
303
311
return ;
304
312
}
305
313
}
@@ -312,7 +320,7 @@ void bmp581_stream_submit(const struct device *dev,
312
320
err = bmp581_prep_reg_write_rtio_async (& cfg -> bus , BMP5_REG_INT_SOURCE , & val , 1 ,
313
321
& int_src_sqe );
314
322
if (err < 0 ) {
315
- rtio_iodev_sqe_err ( iodev_sqe , err );
323
+ bmp581_stream_result ( dev , err );
316
324
return ;
317
325
}
318
326
int_src_sqe -> flags |= RTIO_SQE_CHAINED ;
@@ -325,15 +333,15 @@ void bmp581_stream_submit(const struct device *dev,
325
333
err = bmp581_prep_reg_write_rtio_async (& cfg -> bus , BMP5_REG_INT_CONFIG , & val , 1 ,
326
334
NULL );
327
335
if (err < 0 ) {
328
- rtio_iodev_sqe_err ( iodev_sqe , err );
336
+ bmp581_stream_result ( dev , err );
329
337
return ;
330
338
}
331
339
332
340
(void )rtio_submit (cfg -> bus .rtio .ctx , 0 );
333
341
334
342
err = gpio_pin_interrupt_configure_dt (& cfg -> int_gpio , GPIO_INT_EDGE_TO_ACTIVE );
335
343
if (err < 0 ) {
336
- rtio_iodev_sqe_err ( iodev_sqe , err );
344
+ bmp581_stream_result ( dev , err );
337
345
}
338
346
}
339
347
}
0 commit comments