1 /* ST Microelectronics LIS2DUX12 6-axis IMU sensor driver
2  *
3  * Copyright (c) 2023 Google LLC
4  * Copyright (c) 2024 STMicroelectronics
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #ifndef ZEPHYR_DRIVERS_SENSOR_LIS2DUX12_DECODER_H_
10 #define ZEPHYR_DRIVERS_SENSOR_LIS2DUX12_DECODER_H_
11 
12 #include <stdint.h>
13 #include <zephyr/drivers/sensor.h>
14 
15 /*
16  * This macro converts the Accelerometer full-scale range value (which should be a power of 2) to
17  * an index value used by the decoder. Note: this index is not the same as the RAW register value.
18  */
19 #define LIS2DUX12_ACCEL_FS_VAL_TO_FS_IDX(x) (__builtin_clz(x) - 1)
20 
21 struct lis2dux12_decoder_header {
22 	uint64_t timestamp;
23 	uint8_t is_fifo: 1;
24 	uint8_t range: 2;
25 	uint8_t reserved: 5;
26 	uint8_t int_status;
27 } __attribute__((__packed__));
28 
29 struct lis2dux12_fifo_data {
30 	struct lis2dux12_decoder_header header;
31 	uint32_t accel_odr: 4;
32 	uint32_t fifo_mode_sel: 2;
33 	uint32_t fifo_count: 7;
34 	uint32_t reserved_1: 5;
35 	uint32_t accel_batch_odr: 3;
36 	uint32_t ts_batch_odr: 2;
37 	uint32_t reserved: 9;
38 } __attribute__((__packed__));
39 
40 struct lis2dux12_rtio_data {
41 	struct lis2dux12_decoder_header header;
42 	struct {
43 		uint8_t has_accel: 1; /* set if accel channel has data */
44 		uint8_t has_temp: 1;  /* set if temp channel has data */
45 		uint8_t reserved: 6;
46 	}  __attribute__((__packed__));
47 	int16_t acc[3];
48 	int16_t temp;
49 };
50 
51 int lis2dux12_encode(const struct device *dev, const struct sensor_chan_spec *const channels,
52 		      const size_t num_channels, uint8_t *buf);
53 
54 int lis2dux12_get_decoder(const struct device *dev, const struct sensor_decoder_api **decoder);
55 
56 #endif /* ZEPHYR_DRIVERS_SENSOR_LIS2DUX12_DECODER_H_ */
57