@@ -167,10 +167,6 @@ static int lis2dux12_decoder_get_frame_count(const uint8_t *buffer,
167167 uint8_t tot_accel_fifo_words = 0 ;
168168 uint8_t tot_ts_fifo_words = 0 ;
169169
170- #if defined(CONFIG_LIS2DUX12_ENABLE_TEMP )
171- uint8_t tot_temp_fifo_words = 0 ;
172- #endif
173-
174170 buffer += sizeof (struct lis2dux12_fifo_data );
175171 buffer_end = buffer + LIS2DUX12_FIFO_SIZE (edata -> fifo_count );
176172
@@ -205,9 +201,10 @@ static int lis2dux12_decoder_get_frame_count(const uint8_t *buffer,
205201
206202#if defined(CONFIG_LIS2DUX12_ENABLE_TEMP )
207203 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 ;
209205 break ;
210206#endif
207+
211208 default :
212209 * frame_count = 0 ;
213210 break ;
@@ -227,11 +224,11 @@ static int lis2dux12_decode_fifo(const uint8_t *buffer, struct sensor_chan_spec
227224 int count = 0 ;
228225 uint8_t fifo_tag ;
229226 uint16_t xl_count = 0 ;
230- uint16_t tot_chan_fifo_words = 0 ;
227+ uint16_t tot_fifo_samples = 0 ;
231228 int ret ;
232229
233230 /* 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 );
235232 if (ret < 0 ) {
236233 return 0 ;
237234 }
@@ -247,8 +244,15 @@ static int lis2dux12_decode_fifo(const uint8_t *buffer, struct sensor_chan_spec
247244 if (SENSOR_CHANNEL_IS_ACCEL (chan_spec .chan_type )) {
248245 ((struct sensor_data_header * )data_out )-> base_timestamp_ns =
249246 edata -> header .timestamp -
250- (tot_chan_fifo_words - 1 ) *
247+ (tot_fifo_samples - 1 ) *
251248 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
252256 }
253257
254258 while (count < max_count && buffer < buffer_end ) {
@@ -261,12 +265,12 @@ static int lis2dux12_decode_fifo(const uint8_t *buffer, struct sensor_chan_spec
261265 fifo_tag = (buffer [0 ] >> 3 );
262266
263267 switch (fifo_tag ) {
264- case LIS2DUXXX_XL_TEMP_TAG : {
268+ case LIS2DUXXX_XL_ONLY_2X_TAG : {
265269 struct sensor_three_axis_data * out = data_out ;
266270 int16_t x , y , z ;
267271 const int32_t scale = accel_scaler [header -> range ];
268272
269- xl_count ++ ;
273+ xl_count += 2 ;
270274 if ((uintptr_t )buffer < * fit ) {
271275 /* This frame was already decoded, move on to the next frame */
272276 buffer = frame_end ;
@@ -278,22 +282,122 @@ static int lis2dux12_decode_fifo(const uint8_t *buffer, struct sensor_chan_spec
278282 continue ;
279283 }
280284
285+ out -> shift = accel_range [header -> range ];
286+
281287 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 ,
283289 edata -> accel_batch_odr );
284290
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 ] ;
288294
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 ++ ;
290299
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 ];
291307 out -> readings [count ].x = Q31_SHIFT_MICROVAL (scale * x , out -> shift );
292308 out -> readings [count ].y = Q31_SHIFT_MICROVAL (scale * y , out -> shift );
293309 out -> readings [count ].z = Q31_SHIFT_MICROVAL (scale * z , out -> shift );
294310 break ;
295311 }
296312
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+
297401 default :
298402 /* skip unhandled FIFO tag */
299403 buffer = frame_end ;
0 commit comments