1 /* Bosch BMI08X inertial measurement unit header
2 *
3 * Copyright (c) 2022 Meta Platforms, Inc. and its affiliates
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8 #ifndef ZEPHYR_DRIVERS_SENSOR_BMI08X_H_
9 #define ZEPHYR_DRIVERS_SENSOR_BMI08X_H_
10
11 #include <zephyr/drivers/gpio.h>
12 #include <zephyr/drivers/i2c.h>
13 #include <zephyr/drivers/sensor.h>
14 #include <zephyr/drivers/spi.h>
15 #include <zephyr/sys/util.h>
16
17 /* Accel Chip Id register */
18 #define BMI08X_REG_ACCEL_CHIP_ID 0x00
19
20 /* Accel Error condition register */
21 #define BMI08X_REG_ACCEL_ERR 0x02
22
23 /* Accel Status flag register */
24 #define BMI08X_REG_ACCEL_STATUS 0x03
25
26 /* Accel X LSB data register */
27 #define BMI08X_REG_ACCEL_X_LSB 0x12
28
29 /* Accel X MSB data register */
30 #define BMI08X_REG_ACCEL_X_MSB 0x13
31
32 /* Accel Y LSB data register */
33 #define BMI08X_REG_ACCEL_Y_LSB 0x14
34
35 /* Accel Y MSB data register */
36 #define BMI08X_REG_ACCEL_Y_MSB 0x15
37
38 /* Accel Z LSB data register */
39 #define BMI08X_REG_ACCEL_Z_LSB 0x16
40
41 /* Accel Z MSB data register */
42 #define BMI08X_REG_ACCEL_Z_MSB 0x17
43
44 /* Sensor time byte 0 register */
45 #define BMI08X_REG_ACCEL_SENSORTIME_0 0x18
46
47 /* Sensor time byte 1 register */
48 #define BMI08X_REG_ACCEL_SENSORTIME_1 0x19
49
50 /* Sensor time byte 2 register */
51 #define BMI08X_REG_ACCEL_SENSORTIME_2 0x1A
52
53 /* Accel Interrupt status0 register */
54 #define BMI08X_REG_ACCEL_INT_STAT_0 0x1C
55
56 /* Accel Interrupt status1 register */
57 #define BMI08X_REG_ACCEL_INT_STAT_1 0x1D
58
59 /* Accel general purpose register 0*/
60 #define BMI08X_REG_ACCEL_GP_0 0x1E
61
62 /* Sensor temperature MSB data register */
63 #define BMI08X_REG_TEMP_MSB 0x22
64
65 /* Sensor temperature LSB data register */
66 #define BMI08X_REG_TEMP_LSB 0x23
67
68 /* Accel general purpose register 4*/
69 #define BMI08X_REG_ACCEL_GP_4 0x27
70
71 /* Accel Internal status register */
72 #define BMI08X_REG_ACCEL_INTERNAL_STAT 0x2A
73
74 /* Accel configuration register */
75 #define BMI08X_REG_ACCEL_CONF 0x40
76
77 /* Accel range setting register */
78 #define BMI08X_REG_ACCEL_RANGE 0x41
79
80 /* Accel Interrupt pin 1 configuration register */
81 #define BMI08X_REG_ACCEL_INT1_IO_CONF 0x53
82
83 /* Accel Interrupt pin 2 configuration register */
84 #define BMI08X_REG_ACCEL_INT2_IO_CONF 0x54
85
86 /* Accel Interrupt latch configuration register */
87 #define BMI08X_REG_ACCEL_INT_LATCH_CONF 0x55
88
89 /* Accel Interrupt pin1 mapping register */
90 #define BMI08X_REG_ACCEL_INT1_MAP 0x56
91
92 /* Accel Interrupt pin2 mapping register */
93 #define BMI08X_REG_ACCEL_INT2_MAP 0x57
94
95 /* Accel Interrupt map register */
96 #define BMI08X_REG_ACCEL_INT1_INT2_MAP_DATA 0x58
97
98 /* Accel Init control register */
99 #define BMI08X_REG_ACCEL_INIT_CTRL 0x59
100
101 /* Accel Self test register */
102 #define BMI08X_REG_ACCEL_SELF_TEST 0x6D
103
104 /* Accel Power mode configuration register */
105 #define BMI08X_REG_ACCEL_PWR_CONF 0x7C
106
107 /* Accel Power control (switch on or off register */
108 #define BMI08X_REG_ACCEL_PWR_CTRL 0x7D
109
110 /* Accel Soft reset register */
111 #define BMI08X_REG_ACCEL_SOFTRESET 0x7E
112
113 /* BMI085 Accel unique chip identifier */
114 #define BMI085_ACCEL_CHIP_ID 0x1F
115
116 /* BMI088 Accel unique chip identifier */
117 #define BMI088_ACCEL_CHIP_ID 0x1E
118
119 /* Feature Config related Registers */
120 #define BMI08X_ACCEL_RESERVED_5B_REG 0x5B
121 #define BMI08X_ACCEL_RESERVED_5C_REG 0x5C
122 #define BMI08X_ACCEL_FEATURE_CFG_REG 0x5E
123
124 /* Interrupt masks */
125 #define BMI08X_ACCEL_DATA_READY_INT 0x80
126
127 /* Accel Bandwidth */
128 #define BMI08X_ACCEL_BW_OSR4 0x00
129 #define BMI08X_ACCEL_BW_OSR2 0x01
130 #define BMI08X_ACCEL_BW_NORMAL 0x02
131
132 /* BMI085 Accel Range */
133 #define BMI085_ACCEL_RANGE_2G 0x00
134 #define BMI085_ACCEL_RANGE_4G 0x01
135 #define BMI085_ACCEL_RANGE_8G 0x02
136 #define BMI085_ACCEL_RANGE_16G 0x03
137
138 /**\name BMI088 Accel Range */
139 #define BMI088_ACCEL_RANGE_3G 0x00
140 #define BMI088_ACCEL_RANGE_6G 0x01
141 #define BMI088_ACCEL_RANGE_12G 0x02
142 #define BMI088_ACCEL_RANGE_24G 0x03
143
144 /* Accel Output data rate */
145 #define BMI08X_ACCEL_ODR_12_5_HZ 0x05
146 #define BMI08X_ACCEL_ODR_25_HZ 0x06
147 #define BMI08X_ACCEL_ODR_50_HZ 0x07
148 #define BMI08X_ACCEL_ODR_100_HZ 0x08
149 #define BMI08X_ACCEL_ODR_200_HZ 0x09
150 #define BMI08X_ACCEL_ODR_400_HZ 0x0A
151 #define BMI08X_ACCEL_ODR_800_HZ 0x0B
152 #define BMI08X_ACCEL_ODR_1600_HZ 0x0C
153
154 /* Accel Init Ctrl */
155 #define BMI08X_ACCEL_INIT_CTRL_DISABLE 0x00
156 #define BMI08X_ACCEL_INIT_CTRL_ENABLE 0x01
157
158 /* Accel Self test */
159 #define BMI08X_ACCEL_SWITCH_OFF_SELF_TEST 0x00
160 #define BMI08X_ACCEL_POSITIVE_SELF_TEST 0x0D
161 #define BMI08X_ACCEL_NEGATIVE_SELF_TEST 0x09
162
163 /* Accel Power mode */
164 #define BMI08X_ACCEL_PM_ACTIVE 0x00
165 #define BMI08X_ACCEL_PM_SUSPEND 0x03
166
167 /* Accel Power control settings */
168 #define BMI08X_ACCEL_POWER_DISABLE 0x00
169 #define BMI08X_ACCEL_POWER_ENABLE 0x04
170
171 /* Accel internal interrupt pin mapping */
172 #define BMI08X_ACCEL_INTA_DISABLE 0x00
173 #define BMI08X_ACCEL_INTA_ENABLE 0x01
174 #define BMI08X_ACCEL_INTB_DISABLE 0x00
175 #define BMI08X_ACCEL_INTB_ENABLE 0x02
176 #define BMI08X_ACCEL_INTC_DISABLE 0x00
177 #define BMI08X_ACCEL_INTC_ENABLE 0x04
178
179 /* Accel Soft reset delay */
180 #define BMI08X_ACCEL_SOFTRESET_DELAY_MS 1
181
182 /* Mask definitions for ACCEL_ERR_REG register */
183 #define BMI08X_FATAL_ERR_MASK 0x01
184 #define BMI08X_ERR_CODE_MASK 0x1C
185
186 /* Position definitions for ACCEL_ERR_REG register */
187 #define BMI08X_CMD_ERR_POS 1
188 #define BMI08X_ERR_CODE_POS 2
189
190 /* Mask definition for ACCEL_STATUS_REG register */
191 #define BMI08X_ACCEL_STATUS_MASK 0x80
192
193 /* Position definitions for ACCEL_STATUS_REG */
194 #define BMI08X_ACCEL_STATUS_POS 7
195
196 /* Mask definitions for odr, bandwidth and range */
197 #define BMI08X_ACCEL_ODR_MASK 0x0F
198 #define BMI08X_ACCEL_BW_MASK 0x70
199 #define BMI08X_ACCEL_RANGE_MASK 0x03
200
201 /* Position definitions for odr, bandwidth and range */
202 #define BMI08X_ACCEL_BW_POS 4
203
204 /* Mask definitions for INT1_IO_CONF register */
205 #define BMI08X_ACCEL_INT_EDGE_MASK 0x01
206 #define BMI08X_ACCEL_INT_LVL_MASK 0x02
207 #define BMI08X_ACCEL_INT_OD_MASK 0x04
208 #define BMI08X_ACCEL_INT_IO_MASK 0x08
209 #define BMI08X_ACCEL_INT_IN_MASK 0x10
210
211 /* Position definitions for INT1_IO_CONF register */
212 #define BMI08X_ACCEL_INT_EDGE_POS 0
213 #define BMI08X_ACCEL_INT_LVL_POS 1
214 #define BMI08X_ACCEL_INT_OD_POS 2
215 #define BMI08X_ACCEL_INT_IO_POS 3
216 #define BMI08X_ACCEL_INT_IN_POS 4
217
218 /* Mask definitions for INT1/INT2 mapping register */
219 #define BMI08X_ACCEL_MAP_INTA_MASK 0x01
220
221 /* Mask definitions for INT1/INT2 mapping register */
222 #define BMI08X_ACCEL_MAP_INTA_POS 0x00
223
224 /* Mask definitions for INT1_INT2_MAP_DATA register */
225 #define BMI08X_ACCEL_INT1_DRDY_MASK 0x04
226 #define BMI08X_ACCEL_INT2_DRDY_MASK 0x40
227
228 /* Position definitions for INT1_INT2_MAP_DATA register */
229 #define BMI08X_ACCEL_INT1_DRDY_POS 2
230 #define BMI08X_ACCEL_INT2_DRDY_POS 6
231
232 /* Asic Initialization value */
233 #define BMI08X_ASIC_INITIALIZED 0x01
234
235 #define BMI08X_TEMP_OFFSET 32
236
237 /*************************** BMI08 Gyroscope Macros *****************************/
238 /** Register map */
239 /* Gyro registers */
240
241 /* Gyro Chip Id register */
242 #define BMI08X_REG_GYRO_CHIP_ID 0x00
243
244 /* Gyro X LSB data register */
245 #define BMI08X_REG_GYRO_X_LSB 0x02
246
247 /* Gyro X MSB data register */
248 #define BMI08X_REG_GYRO_X_MSB 0x03
249
250 /* Gyro Y LSB data register */
251 #define BMI08X_REG_GYRO_Y_LSB 0x04
252
253 /* Gyro Y MSB data register */
254 #define BMI08X_REG_GYRO_Y_MSB 0x05
255
256 /* Gyro Z LSB data register */
257 #define BMI08X_REG_GYRO_Z_LSB 0x06
258
259 /* Gyro Z MSB data register */
260 #define BMI08X_REG_GYRO_Z_MSB 0x07
261
262 /* Gyro Interrupt status register */
263 #define BMI08X_REG_GYRO_INT_STAT_1 0x0A
264
265 /* Gyro Range register */
266 #define BMI08X_REG_GYRO_RANGE 0x0F
267
268 /* Gyro Bandwidth register */
269 #define BMI08X_REG_GYRO_BANDWIDTH 0x10
270
271 /* Gyro Power register */
272 #define BMI08X_REG_GYRO_LPM1 0x11
273
274 /* Gyro Soft reset register */
275 #define BMI08X_REG_GYRO_SOFTRESET 0x14
276
277 /* Gyro Interrupt control register */
278 #define BMI08X_REG_GYRO_INT_CTRL 0x15
279
280 /* Gyro Interrupt Pin configuration register */
281 #define BMI08X_REG_GYRO_INT3_INT4_IO_CONF 0x16
282
283 /* Gyro Interrupt Map register */
284 #define BMI08X_REG_GYRO_INT3_INT4_IO_MAP 0x18
285
286 /* Gyro Self test register */
287 #define BMI08X_REG_GYRO_SELF_TEST 0x3C
288
289 /* Gyro unique chip identifier */
290 #define BMI08X_GYRO_CHIP_ID 0x0F
291
292 /* Gyro Range */
293 #define BMI08X_GYRO_RANGE_2000_DPS 0x00
294 #define BMI08X_GYRO_RANGE_1000_DPS 0x01
295 #define BMI08X_GYRO_RANGE_500_DPS 0x02
296 #define BMI08X_GYRO_RANGE_250_DPS 0x03
297 #define BMI08X_GYRO_RANGE_125_DPS 0x04
298
299 /* Gyro Output data rate and bandwidth */
300 #define BMI08X_GYRO_BW_532_ODR_2000_HZ 0x00
301 #define BMI08X_GYRO_BW_230_ODR_2000_HZ 0x01
302 #define BMI08X_GYRO_BW_116_ODR_1000_HZ 0x02
303 #define BMI08X_GYRO_BW_47_ODR_400_HZ 0x03
304 #define BMI08X_GYRO_BW_23_ODR_200_HZ 0x04
305 #define BMI08X_GYRO_BW_12_ODR_100_HZ 0x05
306 #define BMI08X_GYRO_BW_64_ODR_200_HZ 0x06
307 #define BMI08X_GYRO_BW_32_ODR_100_HZ 0x07
308 #define BMI08X_GYRO_ODR_RESET_VAL 0x80
309
310 /* Gyro Power mode */
311 #define BMI08X_GYRO_PM_NORMAL 0x00
312 #define BMI08X_GYRO_PM_DEEP_SUSPEND 0x20
313 #define BMI08X_GYRO_PM_SUSPEND 0x80
314
315 /* Gyro data ready interrupt enable value */
316 #define BMI08X_GYRO_DRDY_INT_DISABLE_VAL 0x00
317 #define BMI08X_GYRO_DRDY_INT_ENABLE_VAL 0x80
318
319 /* Gyro data ready map values */
320 #define BMI08X_GYRO_MAP_DRDY_TO_INT3 0x01
321 #define BMI08X_GYRO_MAP_DRDY_TO_INT4 0x80
322 #define BMI08X_GYRO_MAP_DRDY_TO_BOTH_INT3_INT4 0x81
323
324 /* Gyro Soft reset delay */
325 #define BMI08X_GYRO_SOFTRESET_DELAY 30
326
327 /* Gyro power mode config delay */
328 #define BMI08X_GYRO_POWER_MODE_CONFIG_DELAY 30
329
330 /** Mask definitions for range, bandwidth and power */
331 #define BMI08X_GYRO_RANGE_MASK 0x07
332 #define BMI08X_GYRO_BW_MASK 0x0F
333 #define BMI08X_GYRO_POWER_MASK 0xA0
334
335 /** Position definitions for range, bandwidth and power */
336 #define BMI08X_GYRO_POWER_POS 5
337
338 /* Mask definitions for BMI08X_GYRO_INT_CTRL_REG register */
339 #define BMI08X_GYRO_DATA_EN_MASK 0x80
340
341 /* Position definitions for BMI08X_GYRO_INT_CTRL_REG register */
342 #define BMI08X_GYRO_DATA_EN_POS 7
343
344 /* Mask definitions for BMI08X_GYRO_INT3_INT4_IO_CONF_REG register */
345 #define BMI08X_GYRO_INT3_LVL_MASK 0x01
346 #define BMI08X_GYRO_INT3_OD_MASK 0x02
347 #define BMI08X_GYRO_INT4_LVL_MASK 0x04
348 #define BMI08X_GYRO_INT4_OD_MASK 0x08
349
350 /* Position definitions for BMI08X_GYRO_INT3_INT4_IO_CONF_REG register */
351 #define BMI08X_GYRO_INT3_OD_POS 1
352 #define BMI08X_GYRO_INT4_LVL_POS 2
353 #define BMI08X_GYRO_INT4_OD_POS 3
354
355 /* Mask definitions for BMI08X_GYRO_INT_EN_REG register */
356 #define BMI08X_GYRO_INT_EN_MASK 0x80
357
358 /* Position definitions for BMI08X_GYRO_INT_EN_REG register */
359 #define BMI08X_GYRO_INT_EN_POS 7
360
361 /* Mask definitions for BMI088_GYRO_INT_MAP_REG register */
362 #define BMI08X_GYRO_INT3_MAP_MASK 0x01
363 #define BMI08X_GYRO_INT4_MAP_MASK 0x80
364
365 /* Position definitions for BMI088_GYRO_INT_MAP_REG register */
366 #define BMI08X_GYRO_INT3_MAP_POS 0
367 #define BMI08X_GYRO_INT4_MAP_POS 7
368
369 /* Mask definitions for BMI088_GYRO_INT_MAP_REG register */
370 #define BMI088_GYRO_INT3_MAP_MASK 0x01
371 #define BMI088_GYRO_INT4_MAP_MASK 0x80
372
373 /* Position definitions for BMI088_GYRO_INT_MAP_REG register */
374 #define BMI088_GYRO_INT3_MAP_POS 0
375 #define BMI088_GYRO_INT4_MAP_POS 7
376
377 /* Mask definitions for GYRO_SELF_TEST register */
378 #define BMI08X_GYRO_SELF_TEST_EN_MASK 0x01
379 #define BMI08X_GYRO_SELF_TEST_RDY_MASK 0x02
380 #define BMI08X_GYRO_SELF_TEST_RESULT_MASK 0x04
381 #define BMI08X_GYRO_SELF_TEST_FUNCTION_MASK 0x08
382
383 /* Position definitions for GYRO_SELF_TEST register */
384 #define BMI08X_GYRO_SELF_TEST_RDY_POS 1
385 #define BMI08X_GYRO_SELF_TEST_RESULT_POS 2
386 #define BMI08X_GYRO_SELF_TEST_FUNCTION_POS 3
387
388 /*************************** Common Macros for both Accel and Gyro *****************************/
389 /** Soft reset Value */
390 #define BMI08X_SOFT_RESET_CMD 0xB6
391
392 /* Constant values macros */
393 #define BMI08X_SENSOR_DATA_SYNC_TIME_MS 1
394 #define BMI08X_DELAY_BETWEEN_WRITES_MS 1
395 #define BMI08X_SELF_TEST_DELAY_MS 3
396 #define BMI08X_POWER_CONFIG_DELAY 5
397 #define BMI08X_SENSOR_SETTLE_TIME_MS 30
398 #define BMI08X_SELF_TEST_DATA_READ_MS 50
399 #define BMI08X_ASIC_INIT_TIME_MS 150
400
401 /* allowed ODR values */
402 enum bmi08x_odr {
403 BMI08X_ODR_25_2,
404 BMI08X_ODR_25,
405 BMI08X_ODR_50,
406 BMI08X_ODR_100,
407 BMI08X_ODR_200,
408 BMI08X_ODR_400,
409 BMI08X_ODR_800,
410 BMI08X_ODR_1600,
411 };
412
413 /* Range values for accelerometer */
414 #define BMI08X_ACC_RANGE_2G_3G 0x0
415 #define BMI08X_ACC_RANGE_4G_6G 0x1
416 #define BMI08X_ACC_RANGE_8G_12G 0x2
417 #define BMI08X_ACC_RANGE_16G_24G 0x3
418
419 /* Range values for gyro */
420 #define BMI08X_GYR_RANGE_2000DPS 0
421 #define BMI08X_GYR_RANGE_1000DPS 1
422 #define BMI08X_GYR_RANGE_500DPS 2
423 #define BMI08X_GYR_RANGE_250DPS 3
424 #define BMI08X_GYR_RANGE_125DPS 4
425
426 #define BMI08X_ACC_SCALE(range_g) ((2 * range_g * SENSOR_G) / 65536LL)
427 #define BMI08X_GYR_SCALE(range_dps) ((2 * range_dps * SENSOR_PI) / 180LL / 65536LL)
428
429 /* report of data sync is selected */
430 #define BMI08X_ACCEL_DATA_SYNC_EN(inst) DT_NODE_HAS_STATUS_OKAY(DT_INST_PHANDLE(inst, data_sync))
431 /* Macro used for compile time optimization to compile in/out code used for data-sync
432 * if at least 1 bmi08x has data-sync enabled
433 */
434 #define ACCEL_HELPER(inst) BMI08X_ACCEL_DATA_SYNC_EN(inst) ||
435 #define BMI08X_ACCEL_ANY_INST_HAS_DATA_SYNC DT_INST_FOREACH_STATUS_OKAY(ACCEL_HELPER) 0
436 #define GYRO_HELPER(inst) DT_INST_PROP(inst, data_sync) ||
437 #define BMI08X_GYRO_ANY_INST_HAS_DATA_SYNC DT_INST_FOREACH_STATUS_OKAY(GYRO_HELPER) 0
438
439 struct bmi08x_range {
440 uint16_t range;
441 uint8_t reg_val;
442 };
443
444 union bmi08x_bus {
445 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
446 struct spi_dt_spec spi;
447 #endif
448 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
449 struct i2c_dt_spec i2c;
450 #endif
451 };
452
453 struct bmi08x_accel_bus_io {
454 int (*check)(const union bmi08x_bus *bus);
455 int (*bus_init)(const struct device *dev);
456 int (*transceive)(const struct device *dev, uint8_t reg, bool write, void *data,
457 size_t length);
458 #if BMI08X_ACCEL_ANY_INST_HAS_DATA_SYNC
459 int (*write_config_file)(const struct device *dev);
460 #endif
461 };
462
463 struct bmi08x_gyro_bus_io {
464 int (*check)(const union bmi08x_bus *bus);
465 int (*transceive)(const struct device *dev, uint8_t reg, bool write, void *data,
466 size_t length);
467 };
468
469 struct bmi08x_accel_config {
470 union bmi08x_bus bus;
471 const struct bmi08x_accel_bus_io *api;
472 #if defined(CONFIG_BMI08X_ACCEL_TRIGGER)
473 struct gpio_dt_spec int_gpio;
474 #endif
475 #if defined(CONFIG_BMI08X_ACCEL_TRIGGER) || BMI08X_ACCEL_ANY_INST_HAS_DATA_SYNC
476 uint8_t int1_map;
477 uint8_t int2_map;
478 uint8_t int1_conf_io;
479 uint8_t int2_conf_io;
480 #endif
481 uint8_t accel_hz;
482 uint8_t accel_fs;
483 #if BMI08X_ACCEL_ANY_INST_HAS_DATA_SYNC
484 uint8_t data_sync;
485 #endif
486 };
487
488 struct bmi08x_gyro_config {
489 union bmi08x_bus bus;
490 const struct bmi08x_gyro_bus_io *api;
491 #if defined(CONFIG_BMI08X_GYRO_TRIGGER)
492 struct gpio_dt_spec int_gpio;
493 #endif
494 #if defined(CONFIG_BMI08X_GYRO_TRIGGER) || BMI08X_GYRO_ANY_INST_HAS_DATA_SYNC
495 uint8_t int3_4_map;
496 uint8_t int3_4_conf_io;
497 #endif
498 uint8_t gyro_hz;
499 uint16_t gyro_fs;
500 };
501
502 struct bmi08x_accel_data {
503 #if defined(CONFIG_BMI08X_ACCEL_TRIGGER)
504 struct gpio_callback gpio_cb;
505 #endif
506 uint16_t acc_sample[3];
507 uint16_t scale; /* micro m/s^2/lsb */
508
509 #if defined(CONFIG_BMI08X_ACCEL_TRIGGER_OWN_THREAD)
510 K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_BMI08X_ACCEL_THREAD_STACK_SIZE);
511 struct k_thread thread;
512 struct k_sem sem;
513 #elif defined(CONFIG_BMI08X_ACCEL_TRIGGER_GLOBAL_THREAD)
514 struct k_work work;
515 const struct device *dev;
516 #endif
517
518 #ifdef CONFIG_BMI08X_ACCEL_TRIGGER
519 sensor_trigger_handler_t handler_drdy_acc;
520 const struct sensor_trigger *drdy_trig_acc;
521 #endif /* CONFIG_BMI08X_ACCEL_TRIGGER */
522 uint8_t accel_chip_id;
523 };
524
525 struct bmi08x_gyro_data {
526 #if defined(CONFIG_BMI08X_GYRO_TRIGGER)
527 struct gpio_callback gpio_cb;
528 #endif
529 uint16_t gyr_sample[3];
530 uint16_t scale; /* micro radians/s/lsb */
531
532 #if defined(CONFIG_BMI08X_GYRO_TRIGGER_OWN_THREAD)
533 K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_BMI08X_GYRO_THREAD_STACK_SIZE);
534 struct k_thread thread;
535 struct k_sem sem;
536 #elif defined(CONFIG_BMI08X_GYRO_TRIGGER_GLOBAL_THREAD)
537 struct k_work work;
538 const struct device *dev;
539 #endif
540
541 #ifdef CONFIG_BMI08X_GYRO_TRIGGER
542 sensor_trigger_handler_t handler_drdy_gyr;
543 const struct sensor_trigger *drdy_trig_gyr;
544 #endif /* CONFIG_BMI08X_GYRO_TRIGGER */
545 };
546
547 /* common functions for accel and gyro */
548 int bmi08x_freq_to_odr_val(uint16_t freq_int, uint16_t freq_milli);
549 int32_t bmi08x_range_to_reg_val(uint16_t range, const struct bmi08x_range *range_map,
550 uint16_t range_map_size);
551 int32_t bmi08x_reg_val_to_range(uint8_t reg_val, const struct bmi08x_range *range_map,
552 uint16_t range_map_size);
553
554 int bmi08x_accel_read(const struct device *dev, uint8_t reg_addr, uint8_t *data, uint8_t len);
555 int bmi08x_accel_write(const struct device *dev, uint8_t reg_addr, uint8_t *data, uint16_t len);
556 int bmi08x_accel_byte_read(const struct device *dev, uint8_t reg_addr, uint8_t *byte);
557 int bmi08x_accel_byte_write(const struct device *dev, uint8_t reg_addr, uint8_t byte);
558 int bmi08x_accel_word_write(const struct device *dev, uint8_t reg_addr, uint16_t word);
559 int bmi08x_accel_reg_field_update(const struct device *dev, uint8_t reg_addr, uint8_t pos,
560 uint8_t mask, uint8_t val);
bmi08x_accel_reg_update(const struct device * dev,uint8_t reg_addr,uint8_t mask,uint8_t val)561 static inline int bmi08x_accel_reg_update(const struct device *dev, uint8_t reg_addr, uint8_t mask,
562 uint8_t val)
563 {
564 return bmi08x_accel_reg_field_update(dev, reg_addr, 0, mask, val);
565 }
566
567 int bmi08x_gyro_read(const struct device *dev, uint8_t reg_addr, uint8_t *data, uint8_t len);
568 int bmi08x_gyro_byte_read(const struct device *dev, uint8_t reg_addr, uint8_t *byte);
569 int bmi08x_gyro_byte_write(const struct device *dev, uint8_t reg_addr, uint8_t byte);
570 int bmi08x_gyro_word_write(const struct device *dev, uint8_t reg_addr, uint16_t word);
571 int bmi08x_gyro_reg_field_update(const struct device *dev, uint8_t reg_addr, uint8_t pos,
572 uint8_t mask, uint8_t val);
bmi08x_gyro_reg_update(const struct device * dev,uint8_t reg_addr,uint8_t mask,uint8_t val)573 static inline int bmi08x_gyro_reg_update(const struct device *dev, uint8_t reg_addr, uint8_t mask,
574 uint8_t val)
575 {
576 return bmi08x_gyro_reg_field_update(dev, reg_addr, 0, mask, val);
577 }
578
579 int bmi08x_acc_trigger_mode_init(const struct device *dev);
580 int bmi08x_trigger_set_acc(const struct device *dev, const struct sensor_trigger *trig,
581 sensor_trigger_handler_t handler);
582 int bmi08x_acc_slope_config(const struct device *dev, enum sensor_attribute attr,
583 const struct sensor_value *val);
584 int32_t bmi08x_acc_reg_val_to_range(uint8_t reg_val);
585
586 int bmi08x_gyr_trigger_mode_init(const struct device *dev);
587 int bmi08x_trigger_set_gyr(const struct device *dev, const struct sensor_trigger *trig,
588 sensor_trigger_handler_t handler);
589 int bmi08x_gyr_slope_config(const struct device *dev, enum sensor_attribute attr,
590 const struct sensor_value *val);
591 int32_t bmi08x_gyr_reg_val_to_range(uint8_t reg_val);
592
593 #endif /* ZEPHYR_DRIVERS_SENSOR_BMI08X_H_ */
594