@@ -167,10 +167,6 @@ static int lis2dux12_decoder_get_frame_count(const uint8_t *buffer,
167
167
uint8_t tot_accel_fifo_words = 0 ;
168
168
uint8_t tot_ts_fifo_words = 0 ;
169
169
170
- #if defined(CONFIG_LIS2DUX12_ENABLE_TEMP )
171
- uint8_t tot_temp_fifo_words = 0 ;
172
- #endif
173
-
174
170
buffer += sizeof (struct lis2dux12_fifo_data );
175
171
buffer_end = buffer + LIS2DUX12_FIFO_SIZE (edata -> fifo_count );
176
172
@@ -205,9 +201,10 @@ static int lis2dux12_decoder_get_frame_count(const uint8_t *buffer,
205
201
206
202
#if defined(CONFIG_LIS2DUX12_ENABLE_TEMP )
207
203
case SENSOR_CHAN_DIE_TEMP :
208
- * frame_count = tot_temp_fifo_words ;
204
+ * frame_count = ( data -> fifo_mode_sel == 0 ) ? tot_accel_fifo_words : 0 ;
209
205
break ;
210
206
#endif
207
+
211
208
default :
212
209
* frame_count = 0 ;
213
210
break ;
@@ -227,11 +224,11 @@ static int lis2dux12_decode_fifo(const uint8_t *buffer, struct sensor_chan_spec
227
224
int count = 0 ;
228
225
uint8_t fifo_tag ;
229
226
uint16_t xl_count = 0 ;
230
- uint16_t tot_chan_fifo_words = 0 ;
227
+ uint16_t tot_fifo_samples = 0 ;
231
228
int ret ;
232
229
233
230
/* count total FIFO word for each tag */
234
- ret = lis2dux12_decoder_get_frame_count (buffer , chan_spec , & tot_chan_fifo_words );
231
+ ret = lis2dux12_decoder_get_frame_count (buffer , chan_spec , & tot_fifo_samples );
235
232
if (ret < 0 ) {
236
233
return 0 ;
237
234
}
@@ -247,8 +244,15 @@ static int lis2dux12_decode_fifo(const uint8_t *buffer, struct sensor_chan_spec
247
244
if (SENSOR_CHANNEL_IS_ACCEL (chan_spec .chan_type )) {
248
245
((struct sensor_data_header * )data_out )-> base_timestamp_ns =
249
246
edata -> header .timestamp -
250
- (tot_chan_fifo_words - 1 ) *
247
+ (tot_fifo_samples - 1 ) *
251
248
accel_period_ns (edata -> accel_odr , edata -> accel_batch_odr );
249
+ #if defined(CONFIG_LIS2DUX12_ENABLE_TEMP )
250
+ } else if (chan_spec .chan_type == SENSOR_CHAN_DIE_TEMP ) {
251
+ ((struct sensor_data_header * )data_out )-> base_timestamp_ns =
252
+ edata -> header .timestamp -
253
+ (tot_fifo_samples - 1 ) *
254
+ accel_period_ns (edata -> accel_odr , edata -> accel_batch_odr );
255
+ #endif
252
256
}
253
257
254
258
while (count < max_count && buffer < buffer_end ) {
@@ -261,12 +265,12 @@ static int lis2dux12_decode_fifo(const uint8_t *buffer, struct sensor_chan_spec
261
265
fifo_tag = (buffer [0 ] >> 3 );
262
266
263
267
switch (fifo_tag ) {
264
- case LIS2DUXXX_XL_TEMP_TAG : {
268
+ case LIS2DUXXX_XL_ONLY_2X_TAG : {
265
269
struct sensor_three_axis_data * out = data_out ;
266
270
int16_t x , y , z ;
267
271
const int32_t scale = accel_scaler [header -> range ];
268
272
269
- xl_count ++ ;
273
+ xl_count += 2 ;
270
274
if ((uintptr_t )buffer < * fit ) {
271
275
/* This frame was already decoded, move on to the next frame */
272
276
buffer = frame_end ;
@@ -278,22 +282,122 @@ static int lis2dux12_decode_fifo(const uint8_t *buffer, struct sensor_chan_spec
278
282
continue ;
279
283
}
280
284
285
+ out -> shift = accel_range [header -> range ];
286
+
281
287
out -> readings [count ].timestamp_delta =
282
- (xl_count - 1 ) * accel_period_ns (edata -> accel_odr ,
288
+ (xl_count - 2 ) * accel_period_ns (edata -> accel_odr ,
283
289
edata -> accel_batch_odr );
284
290
285
- x = (int16_t ) buffer [ 1 ] + ( int16_t ) buffer [2 ] * 256 ;
286
- y = (int16_t ) buffer [ 3 ] + ( int16_t ) buffer [4 ] * 256 ;
287
- z = (int16_t ) buffer [ 5 ] + ( int16_t ) buffer [6 ] * 256 ;
291
+ x = * (int16_t * ) & buffer [0 ] ;
292
+ y = * (int16_t * ) & buffer [1 ] ;
293
+ z = * (int16_t * ) & buffer [2 ] ;
288
294
289
- out -> shift = accel_range [header -> range ];
295
+ out -> readings [count ].x = Q31_SHIFT_MICROVAL (scale * x , out -> shift );
296
+ out -> readings [count ].y = Q31_SHIFT_MICROVAL (scale * y , out -> shift );
297
+ out -> readings [count ].z = Q31_SHIFT_MICROVAL (scale * z , out -> shift );
298
+ count ++ ;
290
299
300
+ out -> readings [count ].timestamp_delta =
301
+ (xl_count - 1 ) * accel_period_ns (edata -> accel_odr ,
302
+ edata -> accel_batch_odr );
303
+
304
+ x = * (int16_t * )& buffer [3 ];
305
+ y = * (int16_t * )& buffer [4 ];
306
+ z = * (int16_t * )& buffer [5 ];
291
307
out -> readings [count ].x = Q31_SHIFT_MICROVAL (scale * x , out -> shift );
292
308
out -> readings [count ].y = Q31_SHIFT_MICROVAL (scale * y , out -> shift );
293
309
out -> readings [count ].z = Q31_SHIFT_MICROVAL (scale * z , out -> shift );
294
310
break ;
295
311
}
296
312
313
+ case LIS2DUXXX_XL_TEMP_TAG : {
314
+ struct sensor_three_axis_data * out = data_out ;
315
+ int16_t x , y , z ;
316
+ #if defined(CONFIG_LIS2DUX12_ENABLE_TEMP )
317
+ struct sensor_q31_data * t_out = data_out ;
318
+ int16_t t ;
319
+ int64_t t_uC ;
320
+ #endif
321
+ const int32_t scale = accel_scaler [header -> range ];
322
+
323
+ xl_count ++ ;
324
+ if ((uintptr_t )buffer < * fit ) {
325
+ /* This frame was already decoded, move on to the next frame */
326
+ buffer = frame_end ;
327
+ continue ;
328
+ }
329
+
330
+ if (edata -> fifo_mode_sel == 1 ) {
331
+ out -> readings [count ].timestamp_delta =
332
+ (xl_count - 1 ) * accel_period_ns (edata -> accel_odr ,
333
+ edata -> accel_batch_odr );
334
+
335
+ if (!SENSOR_CHANNEL_IS_ACCEL (chan_spec .chan_type )) {
336
+ buffer = frame_end ;
337
+ continue ;
338
+ }
339
+
340
+ x = (int16_t )buffer [1 ] + (int16_t )buffer [2 ] * 256 ;
341
+ y = (int16_t )buffer [3 ] + (int16_t )buffer [4 ] * 256 ;
342
+ z = (int16_t )buffer [5 ] + (int16_t )buffer [6 ] * 256 ;
343
+
344
+ out -> shift = accel_range [header -> range ];
345
+
346
+ out -> readings [count ].x = Q31_SHIFT_MICROVAL (scale * x , out -> shift );
347
+ out -> readings [count ].y = Q31_SHIFT_MICROVAL (scale * y , out -> shift );
348
+ out -> readings [count ].z = Q31_SHIFT_MICROVAL (scale * z , out -> shift );
349
+ } else {
350
+ if (!SENSOR_CHANNEL_IS_ACCEL (chan_spec .chan_type )
351
+ #if defined(CONFIG_LIS2DUX12_ENABLE_TEMP )
352
+ & & (chan_spec .chan_type != SENSOR_CHAN_DIE_TEMP )
353
+ #endif
354
+ ) {
355
+ buffer = frame_end ;
356
+ continue ;
357
+ }
358
+
359
+ if (SENSOR_CHANNEL_IS_ACCEL (chan_spec .chan_type )) {
360
+ out -> readings [count ].timestamp_delta =
361
+ (xl_count - 1 ) * accel_period_ns (edata -> accel_odr ,
362
+ edata -> accel_batch_odr );
363
+
364
+ x = (int16_t )buffer [1 ];
365
+ x = (x + (int16_t )buffer [2 ] * 256 ) * 16 ;
366
+ y = (int16_t )buffer [2 ] / 16 ;
367
+ y = (y + ((int16_t )buffer [3 ] * 16 )) * 16 ;
368
+ z = (int16_t )buffer [4 ];
369
+ z = (z + (int16_t )buffer [5 ] * 256 ) * 16 ;
370
+
371
+ out -> shift = accel_range [header -> range ];
372
+
373
+ out -> readings [count ].x = Q31_SHIFT_MICROVAL (scale * x ,
374
+ out -> shift );
375
+ out -> readings [count ].y = Q31_SHIFT_MICROVAL (scale * y ,
376
+ out -> shift );
377
+ out -> readings [count ].z = Q31_SHIFT_MICROVAL (scale * z ,
378
+ out -> shift );
379
+ #if defined(CONFIG_LIS2DUX12_ENABLE_TEMP )
380
+ } else {
381
+ t_out -> readings [count ].timestamp_delta =
382
+ (xl_count - 1 ) * accel_period_ns (edata -> accel_odr ,
383
+ edata -> accel_batch_odr );
384
+
385
+ t = ((int16_t )buffer [5 ] / 16 +
386
+ (int16_t )buffer [6 ] * 16 ) * 16 ;
387
+
388
+ t_out -> shift = temp_range ;
389
+
390
+ /* transform temperature LSB into micro-Celsius */
391
+ t_uC = SENSOR_TEMP_UCELSIUS (t );
392
+ t_out -> readings [count ].temperature =
393
+ Q31_SHIFT_MICROVAL (t_uC , t_out -> shift );
394
+
395
+ #endif /* CONFIG_LIS2DUX12_ENABLE_TEMP */
396
+ }
397
+ }
398
+ break ;
399
+ }
400
+
297
401
default :
298
402
/* skip unhandled FIFO tag */
299
403
buffer = frame_end ;
0 commit comments