1 /*
2  * Copyright (c) 2024 Bootlin
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_DRIVERS_SENSOR_LSM9DS1_LSM9DS1_H_
8 #define ZEPHYR_DRIVERS_SENSOR_LSM9DS1_LSM9DS1_H_
9 
10 #include "lsm9ds1_reg.h"
11 
12 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
13 #include <zephyr/drivers/spi.h>
14 #endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) */
15 
16 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
17 #include <zephyr/drivers/i2c.h>
18 #endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) */
19 
20 #define GAIN_UNIT_XL (61LL)
21 #define GAIN_UNIT_G  (8750LL)
22 
23 #define TEMP_OFFSET      25 /* raw output of zero indicate 25°C */
24 #define TEMP_SENSITIVITY 16 /* 16 LSB / °C */
25 
26 #define GYRO_ODR_MASK 0x7
27 
28 struct lsm9ds1_config {
29 	stmdev_ctx_t ctx;
30 	union {
31 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
32 		const struct i2c_dt_spec i2c;
33 #endif
34 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
35 		const struct spi_dt_spec spi;
36 #endif
37 	} stmemsc_cfg;
38 	uint8_t accel_range;
39 	uint8_t gyro_range;
40 	uint8_t imu_odr;
41 };
42 
43 struct lsm9ds1_data {
44 	int16_t acc[3];
45 	uint32_t acc_gain;
46 	int16_t gyro[3];
47 	uint32_t gyro_gain;
48 
49 	uint16_t accel_odr;
50 	uint16_t gyro_odr;
51 #if defined(CONFIG_LSM9DS1_ENABLE_TEMP)
52 	int16_t temp_sample;
53 #endif
54 };
55 
56 #endif /* ZEPHYR_DRIVERS_SENSOR_LSM9DS1_LSM9DS1_H_ */
57