@@ -41,8 +41,7 @@ static int32_t iis3dwb_set_odr_raw(const struct device *dev, uint8_t odr)
41
41
return iis3dwb_xl_data_rate_set (ctx , odr );
42
42
}
43
43
44
- static int iis3dwb_odr_set (const struct device * dev ,
45
- const struct sensor_value * val )
44
+ static int iis3dwb_odr_set (const struct device * dev , const struct sensor_value * val )
46
45
{
47
46
iis3dwb_odr_xl_t odr ;
48
47
@@ -58,32 +57,27 @@ static int iis3dwb_odr_set(const struct device *dev,
58
57
}
59
58
60
59
if (iis3dwb_set_odr_raw (dev , odr )) {
61
- LOG_DBG ("failed to set sampling rate" );
60
+ LOG_ERR ("failed to set sampling rate" );
62
61
return - EIO ;
63
62
}
64
63
65
64
return 0 ;
66
65
}
67
66
68
- static int iis3dwb_set_fs (const struct device * dev , uint8_t fs )
67
+ static int iis3dwb_set_fs (const struct device * dev , int32_t fs )
69
68
{
70
69
int ret ;
71
70
uint8_t range ;
72
71
73
- switch (fs ) {
74
- case 2 :
72
+ if (fs <= 2 ) {
75
73
range = IIS3DWB_DT_FS_2G ;
76
- break ;
77
- case 4 :
74
+ } else if (fs <= 4 ) {
78
75
range = IIS3DWB_DT_FS_4G ;
79
- break ;
80
- case 8 :
76
+ } else if (fs <= 8 ) {
81
77
range = IIS3DWB_DT_FS_8G ;
82
- break ;
83
- case 16 :
78
+ } else if (fs <= 16 ) {
84
79
range = IIS3DWB_DT_FS_16G ;
85
- break ;
86
- default :
80
+ } else {
87
81
LOG_ERR ("fs [%d] not supported." , fs );
88
82
return - EINVAL ;
89
83
}
@@ -98,10 +92,8 @@ static int iis3dwb_set_fs(const struct device *dev, uint8_t fs)
98
92
return ret ;
99
93
}
100
94
101
- static int iis3dwb_attr_set (const struct device * dev ,
102
- enum sensor_channel chan ,
103
- enum sensor_attribute attr ,
104
- const struct sensor_value * val )
95
+ static int iis3dwb_attr_set (const struct device * dev , enum sensor_channel chan ,
96
+ enum sensor_attribute attr , const struct sensor_value * val )
105
97
{
106
98
if (chan != SENSOR_CHAN_ALL ) {
107
99
LOG_WRN ("attr_set() not supported on this channel." );
@@ -115,16 +107,14 @@ static int iis3dwb_attr_set(const struct device *dev,
115
107
case SENSOR_ATTR_SAMPLING_FREQUENCY :
116
108
return iis3dwb_odr_set (dev , val );
117
109
default :
118
- LOG_DBG ("operation not supported." );
110
+ LOG_ERR ("operation not supported." );
119
111
return - ENOTSUP ;
120
112
}
121
113
122
114
return 0 ;
123
115
}
124
116
125
- static void iis3dwb_one_shot_complete_cb (struct rtio * ctx ,
126
- const struct rtio_sqe * sqe ,
127
- void * arg )
117
+ static void iis3dwb_one_shot_complete_cb (struct rtio * ctx , const struct rtio_sqe * sqe , void * arg )
128
118
{
129
119
struct rtio_iodev_sqe * iodev_sqe = (struct rtio_iodev_sqe * )sqe -> userdata ;
130
120
int err = 0 ;
@@ -155,6 +145,7 @@ static void iis3dwb_submit_one_shot(const struct device *dev, struct rtio_iodev_
155
145
rc = rtio_sqe_rx_buf (iodev_sqe , min_buf_len , min_buf_len , & buf , & buf_len );
156
146
if (rc != 0 ) {
157
147
LOG_ERR ("Failed to get a read buffer of size %u bytes" , min_buf_len );
148
+ rtio_iodev_sqe_err (iodev_sqe , - ENOMEM );
158
149
return ;
159
150
}
160
151
@@ -246,43 +237,28 @@ static void iis3dwb_submit_one_shot(const struct device *dev, struct rtio_iodev_
246
237
}
247
238
}
248
239
249
- if (edata -> has_accel == 0 ) {
240
+ if (edata -> has_accel == 0 && edata -> has_temp == 0 ) {
250
241
rtio_iodev_sqe_err (iodev_sqe , - EIO );
251
242
}
252
243
}
253
244
254
- void iis3dwb_submit_sync ( struct rtio_iodev_sqe * iodev_sqe )
245
+ void iis3dwb_submit ( const struct device * dev , struct rtio_iodev_sqe * iodev_sqe )
255
246
{
256
247
const struct sensor_read_config * cfg = iodev_sqe -> sqe .iodev -> data ;
257
- const struct device * dev = cfg -> sensor ;
258
248
259
249
if (!cfg -> is_streaming ) {
260
250
iis3dwb_submit_one_shot (dev , iodev_sqe );
251
+ } else if (IS_ENABLED (CONFIG_IIS3DWB_STREAM )) {
252
+ iis3dwb_submit_stream (dev , iodev_sqe );
261
253
} else {
262
254
rtio_iodev_sqe_err (iodev_sqe , - ENOTSUP );
263
255
}
264
256
}
265
257
266
- void iis3dwb_submit (const struct device * dev , struct rtio_iodev_sqe * iodev_sqe )
267
- {
268
- struct rtio_work_req * req = rtio_work_req_alloc ();
269
-
270
- if (req == NULL ) {
271
- LOG_ERR ("RTIO work item allocation failed. Consider to increase "
272
- "CONFIG_RTIO_WORKQ_POOL_ITEMS." );
273
- rtio_iodev_sqe_err (iodev_sqe , - ENOMEM );
274
- return ;
275
- }
276
-
277
- rtio_work_req_submit (req , iodev_sqe , iis3dwb_submit_sync );
278
- }
279
-
280
258
static DEVICE_API (sensor , iis3dwb_driver_api ) = {
281
259
.attr_set = iis3dwb_attr_set ,
282
- #ifdef CONFIG_SENSOR_ASYNC_API
283
260
.get_decoder = iis3dwb_get_decoder ,
284
261
.submit = iis3dwb_submit ,
285
- #endif
286
262
};
287
263
288
264
static int iis3dwb_init_chip (const struct device * dev )
@@ -292,22 +268,20 @@ static int iis3dwb_init_chip(const struct device *dev)
292
268
uint8_t chip_id , rst ;
293
269
294
270
if (iis3dwb_device_id_get (ctx , & chip_id ) < 0 ) {
295
- LOG_DBG ("Failed reading chip id" );
271
+ LOG_ERR ("Failed reading chip id" );
296
272
return - EIO ;
297
273
}
298
274
299
275
if (chip_id != IIS3DWB_ID ) {
300
- LOG_DBG ("Invalid chip id 0x%x" , chip_id );
276
+ LOG_ERR ("Invalid chip id 0x%x" , chip_id );
301
277
return - EIO ;
302
278
}
303
279
304
280
/*
305
281
* Restore default configuration
306
282
*/
307
283
iis3dwb_reset_set (ctx , PROPERTY_ENABLE );
308
- do {
309
- iis3dwb_reset_get (ctx , & rst );
310
- } while (rst );
284
+ WAIT_FOR ((iis3dwb_reset_get (ctx , & rst ) == 0 ) && !rst , 100 * USEC_PER_MSEC , k_msleep (10 ));
311
285
312
286
/* Enable Block Data Update */
313
287
iis3dwb_block_data_update_set (ctx , PROPERTY_ENABLE );
@@ -322,9 +296,16 @@ static int iis3dwb_init(const struct device *dev)
322
296
int ret ;
323
297
324
298
if (iis3dwb_init_chip (dev ) < 0 ) {
325
- LOG_DBG ("Failed to initialize chip" );
299
+ LOG_ERR ("Failed to initialize chip" );
300
+ return - EIO ;
301
+ }
302
+
303
+ #ifdef CONFIG_IIS3DWB_TRIGGER
304
+ if (cfg -> trig_enabled && iis3dwb_init_interrupt (dev ) < 0 ) {
305
+ LOG_ERR ("Failed to initialize interrupt." );
326
306
return - EIO ;
327
307
}
308
+ #endif
328
309
329
310
/* set sensor default scale (used to convert sample values) */
330
311
LOG_DBG ("%s: range is %d" , dev -> name , cfg -> range );
@@ -361,6 +342,17 @@ static int iis3dwb_init(const struct device *dev)
361
342
DT_DRV_INST(inst), IIS3DWB_SPI_OPERATION, 0U); \
362
343
RTIO_DEFINE(iis3dwb_rtio_ctx_##inst, 8, 8);
363
344
345
+ #ifdef CONFIG_IIS3DWB_TRIGGER
346
+ #define IIS3DWB_CFG_IRQ (inst ) \
347
+ .trig_enabled = true, \
348
+ .int1_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, int1_gpios, {0}), \
349
+ .int2_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, int2_gpios, {0}), \
350
+ .drdy_pulsed = DT_INST_PROP(inst, drdy_pulsed), \
351
+ .drdy_pin = DT_INST_PROP(inst, drdy_pin),
352
+ #else
353
+ #define IIS3DWB_CFG_IRQ (inst )
354
+ #endif /* CONFIG_IIS3DWB_TRIGGER */
355
+
364
356
#define IIS3DWB_CONFIG (inst ) \
365
357
{ \
366
358
STMEMSC_CTX_SPI(&iis3dwb_config_##inst.stmemsc_cfg), \
@@ -372,6 +364,16 @@ static int iis3dwb_init(const struct device *dev)
372
364
.range = DT_INST_PROP(inst, range), \
373
365
.filter = DT_INST_PROP(inst, filter), \
374
366
.odr = DT_INST_PROP(inst, odr), \
367
+ \
368
+ IF_ENABLED(CONFIG_IIS3DWB_STREAM, \
369
+ (.fifo_wtm = DT_INST_PROP(inst, fifo_watermark), \
370
+ .accel_batch = DT_INST_PROP(inst, accel_fifo_batch_rate), \
371
+ .temp_batch = DT_INST_PROP(inst, temp_fifo_batch_rate), \
372
+ .ts_batch = DT_INST_PROP(inst, timestamp_fifo_batch_rate),)) \
373
+ \
374
+ IF_ENABLED(UTIL_OR(DT_INST_NODE_HAS_PROP(inst, int1_gpios), \
375
+ DT_INST_NODE_HAS_PROP(inst, int2_gpios)), \
376
+ (IIS3DWB_CFG_IRQ(inst))) \
375
377
}
376
378
377
379
#define IIS3DWB_DEFINE (inst ) \
0 commit comments