2 * Copyright © 2022 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24 struct ao_bmi088_acc_sample {
30 struct ao_bmi088_gyr_sample {
36 struct ao_bmi088_sample {
37 struct ao_bmi088_acc_sample acc;
38 struct ao_bmi088_gyr_sample gyr;
41 extern struct ao_bmi088_sample ao_bmi088_current;
46 #define BMI088_ACC_CHIP_ID 0x00
47 #define BMI088_ACC_CHIP_ID_BMI088 0x1e
49 #define BMI088_ACC_ERR_REG 0x02
50 # define BMI088_ACC_ERR_REG_ERROR_CODE 2
51 # define BMI088_ACC_ERR_REG_FATAL_ERR 0
53 #define BMI088_ACC_STATUS 0x03
54 # define BMI088_ACC_STATUS_ACC_DRDY 7
56 #define BMI088_ACC_DATA 0x12
57 #define BMI088_ACC_TIME 0x18
59 #define BMI088_ACC_INT_STAT_1 0x1d
60 # define BMI088_ACC_INT_STAT_1_ACC_DRDY 7
62 #define BMI088_ACC_TEMP 0x22
64 #define BMI088_ACC_CONF 0x40
65 # define BMI088_ACC_CONF_BWP 4
66 # define BMI088_ACC_CONF_BWP_OSR4 0x08
67 # define BMI088_ACC_CONF_BWP_OSR2 0x08
68 # define BMI088_ACC_CONF_BWP_NORMAL 0x0a
69 # define BMI088_ACC_CONF_ODR 0
70 # define BMI088_ACC_CONF_ODR_12_5 0x05
71 # define BMI088_ACC_CONF_ODR_25 0x06
72 # define BMI088_ACC_CONF_ODR_50 0x07
73 # define BMI088_ACC_CONF_ODR_100 0x08
74 # define BMI088_ACC_CONF_ODR_200 0x09
75 # define BMI088_ACC_CONF_ODR_400 0x0a
76 # define BMI088_ACC_CONF_ODR_800 0x0b
77 # define BMI088_ACC_CONF_ODR_1600 0x0c
79 #define BMI088_ACC_RANGE 0x41
80 # define BMI088_ACC_RANGE_3 0x00
81 # define BMI088_ACC_RANGE_6 0x01
82 # define BMI088_ACC_RANGE_12 0x02
83 # define BMI088_ACC_RANGE_24 0x03
85 #define BMI088_INT1_IO_CONF 0x53
86 # define BMI088_INT1_IO_CONF_INT1_IN 4
87 # define BMI088_INT1_IO_CONF_INT1_OUT 3
88 # define BMI088_INT1_IO_CONF_INT1_OD 2
89 # define BMI088_INT1_IO_CONF_INT1_LVL 1
91 #define BMI088_INT2_IO_CONF 0x54
92 # define BMI088_INT2_IO_CONF_INT2_IN 4
93 # define BMI088_INT2_IO_CONF_INT2_OUT 3
94 # define BMI088_INT2_IO_CONF_INT2_OD 2
95 # define BMI088_INT2_IO_CONF_INT2_LVL 1
97 #define BMI088_INT2_INT2_MAP_DATA 0x58
98 # define BMI088_INT2_INT2_MAP_DATA_INT2_DRDY 6
99 # define BMI088_INT2_INT2_MAP_DATA_INT1_DRDY 2
101 #define BMI088_ACC_SELF_TEST 0x6d
102 # define BMI088_ACC_SELF_TEST_OFF 0x00
103 # define BMI088_ACC_SELF_TEST_POSITIVE 0x0d
104 # define BMI088_ACC_SELF_TEST_NEGATIVE 0x09
106 #define BMI088_ACC_PWR_CONF 0x7c
107 # define BMI088_ACC_PWR_CONF_SUSPEND 0x03
108 # define BMI088_ACC_PWR_CONF_ACTIVE 0x00
110 #define BMI088_ACC_PWR_CTRL 0x7d
111 # define BMI088_ACC_PWR_CTRL_OFF 0x00
112 # define BMI088_ACC_PWR_CTRL_ON 0x04
114 #define BMI088_ACC_SOFTRESET 0x7e
115 # define BMI088_ACC_SOFTRESET_RESET 0xb6
117 #define BMI088_GYRO_CHIP_ID 0x00
118 # define BMI088_GYRO_CHIP_ID_BMI088 0x0f
120 #define BMI088_GYRO_DATA 0x02
121 #define BMI088_GYRO_DATA_X 0x02
122 #define BMI088_GYRO_DATA_Y 0x04
123 #define BMI088_GYRO_DATA_Z 0x06
125 #define BMI088_GYRO_INT_STAT_1 0x0a
126 # define BMI088_GYRO_INT_STAT_1_GYRO_DRDY 7
128 #define BMI088_GYRO_RANGE 0x0f
129 # define BMI088_GYRO_RANGE_2000 0x00
130 # define BMI088_GYRO_RANGE_1000 0x01
131 # define BMI088_GYRO_RANGE_500 0x02
132 # define BMI088_GYRO_RANGE_250 0x03
133 # define BMI088_GYRO_RANGE_125 0x04
135 #define BMI088_GYRO_BANDWIDTH 0x10
136 # define BMI088_GYRO_BANDWIDTH_2000_532 0x00
137 # define BMI088_GYRO_BANDWIDTH_2000_230 0x01
138 # define BMI088_GYRO_BANDWIDTH_1000_116 0x02
139 # define BMI088_GYRO_BANDWIDTH_400_47 0x03
140 # define BMI088_GYRO_BANDWIDTH_200_23 0x04
141 # define BMI088_GYRO_BANDWIDTH_100_12 0x05
142 # define BMI088_GYRO_BANDWIDTH_200_64 0x06
143 # define BMI088_GYRO_BANDWIDTH_100_32 0x07
145 #define BMI088_GYRO_LPM1 0x11
146 # define BMI088_GYRO_LPM1_NORMAL 0x00
147 # define BMI088_GYRO_LPM1_SUSPEND 0x80
148 # define BMI088_GYRO_LPM1_DEEP_SUSPEND 0x20
150 #define BMI088_GYRO_SOFTRESET 0x14
151 # define BMI088_GYRO_SOFTRESET_RESET 0xb6
153 #define BMI088_GYRO_INT_CTRL 0x15
154 # define BMI088_GYRO_INT_CTRL_DISABLE 0x00
155 # define BMI088_GYRO_INT_CTRL_ENABLE 0x80
157 #define BMI088_INT3_INT4_IO_CONF 0x16
158 # define BMI088_INT3_INT4_IO_CONF_INT4_OD 3
159 # define BMI088_INT3_INT4_IO_CONF_INT4_LVL 2
160 # define BMI088_INT3_INT4_IO_CONF_INT3_OD 1
161 # define BMI088_INT3_INT4_IO_CONF_INT3_LVL 0
163 #define BMI088_INT3_INT4_IO_MAP 0x18
164 # define BMI088_INT3_INT4_IO_MAP_NONE 0x00
165 # define BMI088_INT3_INT4_IO_MAP_INT3 0x01
166 # define BMI088_INT3_INT4_IO_MAP_INT4 0x80
167 # define BMI088_INT3_INT4_IO_MAP_INT3_INT4 0x81
169 #define BMI088_GYRO_SELF_TEST 0x3c
170 # define BMI088_GYRO_SELF_TEST_RATE_OK 4
171 # define BMI088_GYRO_SELF_TEST_BIST_FAIL 2
172 # define BMI088_GYRO_SELF_TEST_BIST_RDY 1
173 # define BMI088_GYRO_SELF_TEST_TRIG_BIST 0
175 #define BMI088_GYRO_FULLSCALE ((float) 2000.0f * (float) M_PI / 180.0f)
178 ao_bmi088_gyro(float sensor) {
179 return sensor * ((float) (BMI088_GYRO_FULLSCALE / 32767.0));
182 #define ao_bmi_gyro_to_sample(gyro) ((gyro) * (32767.0f / (BMI088_GYRO_FULLSCALE
184 #define BMI088_ACCEL_FULLSCALE 24
187 ao_bmi088_accel(int16_t sensor) {
188 return (float) sensor * ((float) (BMI088_ACCEL_FULLSCALE * GRAVITY / 32767.0));
191 #define ao_bmi_accel_to_sample(accel) ((accel) * (32767.0f / (BMI088_ACCEL_FULLSCALE * GRAVITY)))
193 #endif /* _AO_BMI088_H_ */