1 /**
2 * Copyright (c) 2024 Bosch Sensortec GmbH. All rights reserved.
3 *
4 * gyro_bmi270.h as part of the * /chipsets subdirectory
5 * is dual licensed: you can use it either under the terms of
6 * the GPL, or the BSD license, at your option.
7 * See the LICENSE file in the root of this repository for complete details.
8 */
9 
10 #ifndef GYRO_BMI270_H
11 #define GYRO_BMI270_H
12 
13 #include "sensor_gyro_driver.h"
14 #include "sensor_config_parser.h"
15 
16 #define BMI270_GYR_DATA_FRAME_SIZE      6
17 #define BMI270_ONE_BYTE                 sizeof(uint8_t)
18 #define BMI270_TWO_BYTE                 sizeof(uint16_t)
19 
20 // bus operation delay
21 #define BMI270_NORMAL_MODE_WRITE_DELAY_IN_US   4
22 #define BMI270_LP_MODE_WRITE_DELAY_IN_US       460
23 
24 // feature operation delay
25 #define BMI270_RESET_DELAY_IN_MS               5
26 #define BMI270_LOAD_RAM_PATCH_DELAY_IN_MS      10
27 
28 // bit definition
29 #define BMI270_GYR_POWER_BIT_POS_IN_PWR_CTRL_REG    1
30 
31 
32 #define BST_GET_VAL_BIT(val, bit)      (((val)>>(bit)) & 0x01)
33 #define BST_SET_VAL_BIT(val, bit)      ((val) | (1 << (bit)))
34 #define BST_CLR_VAL_BIT(val, bit)      ((val) & (~(1 << (bit))))
35 
36 #define BMI270_GYRO_REGA_STATUS             0x03
37 /* GYRO DATA REGISTERS ADDR */
38 #define BMI270_GYRO_REGA_X_LSB_ADDR         0X12
39 #define BMI270_GYRO_REGA_X_MSB_ADDR         0X13
40 #define BMI270_GYRO_REGA_Y_LSB_ADDR         0X14
41 #define BMI270_GYRO_REGA_Y_MSB_ADDR         0X15
42 #define BMI270_GYRO_REGA_Z_LSB_ADDR         0X16
43 #define BMI270_GYRO_REGA_Z_MSB_ADDR         0X17
44 #define BMI270_STATUS_ADDR                  0x1B
45 
46 /* GYRO ODR */
47 #define BMI270_GYRO_ODR_RESERVED            0x00
48 #define BMI270_GYRO_ODR_25HZ                0x06
49 #define BMI270_GYRO_ODR_50HZ                0x07
50 #define BMI270_GYRO_ODR_100HZ               0x08
51 #define BMI270_GYRO_ODR_200HZ               0x09
52 #define BMI270_GYRO_ODR_400HZ               0x0A
53 #define BMI270_GYRO_ODR_800HZ               0x0B
54 #define BMI270_GYRO_ODR_1600HZ              0x0C
55 #define BMI270_GYRO_ODR_3200HZ              0x0D
56 
57 /* default HZ */
58 #define BMI270_GYRO_DEFAULT_ODR_100HZ       100
59 #define BMI270_GYRO_DEFAULT_ODR_25HZ        25
60 
61 /* GYRO RANGE */
62 #define BMI270_GYRO_RANGE_2000DPS           0X00
63 #define BMI270_GYRO_RANGE_1000DPS           0X01
64 #define BMI270_GYRO_RANGE_500DPS            0X02
65 #define BMI270_GYRO_RANGE_250DPS            0X03
66 #define BMI270_GYRO_RANGE_125DPS            0X04
67 
68 /* GYRO sensitivity */
69 #define BMI270_GYRO_SENSITIVITY_2000DPS     61
70 
71 /* GYRO DATA READY */
72 #define BMI270_GYRO_DATA_READY_MASK         0x40
73 #define BMI26X_REGV_WHOAMI                  0x24
74 #define BMI270_REGA_INTERNAL_STATUS         0x21
75 
76 #define BMI26X_REGA_GYRO_ODR                0x42
77 #define BMI26X_REGA_GYRO_RANGE              0x43
78 
79 #define BMI26X_REGA_USR_TITAN_CTRL          0x59
80 #define BMI26X_REGA_USR_CONF_STREAM_IDX_LSB 0x5b
81 #define BMI26X_REGA_USR_CONF_STREAM_IN      0x5e
82 
83 #define BMI270_REGA_PWR_CFG                 0x7C
84 #define BMI270_REGA_PWR_CTRL                0x7D
85 #define BMI26X_REGA_USR_CMD                 0x7E
86 
87 #define BMI26X_CHECK_CONFIGURE_STATUS_TIMES 15
88 
89 #define BMI26X_REGV_CMD_SOFT_RESET          0xB6
90 
91 struct Bmi270DrvData {
92     struct IDeviceIoService ioService;
93     struct HdfDeviceObject *device;
94     struct SensorCfgData *sensorCfg;
95 };
96 
97 #endif /* GYRO_BMI270_H */
98