Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
bmi088_hal.hpp
Go to the documentation of this file.
1/*****************************************************************************/
2/********** !!! WARNING: CODE GENERATED BY TAPROOT. DO NOT EDIT !!! **********/
3/*****************************************************************************/
4
5/*
6 * Copyright (c) 2020-2022 Advanced Robotics at the University of Washington <robomstr@uw.edu>
7 *
8 * This file is part of Taproot.
9 *
10 * Taproot is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Taproot is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Taproot. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef TAPROOT_BMI088_HAL_HPP_
25#define TAPROOT_BMI088_HAL_HPP_
26
27#if defined(ENV_UNIT_TESTS)
28#include <deque>
29#endif
30
31#include "tap/board/board.hpp"
32#include "tap/util_macros.hpp"
33
34#include "bmi088_data.hpp"
35
37{
39{
40private:
41#if defined(ENV_UNIT_TESTS)
43 static std::deque<uint8_t> rxData;
44#endif
45
46 static inline void chipSelectAccelLow()
47 {
48#if !defined(PLATFORM_HOSTED)
49 Board::ImuCS1Accel::setOutput(modm::GpioOutput::Low);
50#endif
51 }
52
53 static inline void chipSelectAccelHigh()
54 {
55#if !defined(PLATFORM_HOSTED)
56 Board::ImuCS1Accel::setOutput(modm::GpioOutput::High);
57#endif
58 }
59
60 static inline void chipSelectGyroLow()
61 {
62#if !defined(PLATFORM_HOSTED)
63 Board::ImuCS1Gyro::setOutput(modm::GpioOutput::Low);
64#endif
65 }
66
67 static inline void chipSelectGyroHigh()
68 {
69#if !defined(PLATFORM_HOSTED)
70 Board::ImuCS1Gyro::setOutput(modm::GpioOutput::High);
71#endif
72 }
73
74 static inline uint8_t bmi088ReadWriteByte(uint8_t tx)
75 {
76#if !defined(PLATFORM_HOSTED)
77 uint8_t rx = 0;
78 Board::ImuSpiMaster::transferBlocking(&tx, &rx, 1);
79 return rx;
80#elif defined(ENV_UNIT_TESTS)
81 UNUSED(tx);
82 if (rxData.size() != 0)
83 {
84 uint8_t data = rxData.front();
85 rxData.pop_front();
86 return data;
87 }
88 else
89 {
90 return 255;
91 }
92#else
93 UNUSED(tx);
94 return 255;
95#endif
96 }
97
101 static inline void bmi088WriteSingleReg(uint8_t reg, uint8_t data)
102 {
103 bmi088ReadWriteByte(reg & ~Bmi088Data::BMI088_READ_BIT);
104 bmi088ReadWriteByte(data);
105 }
106
110 static inline uint8_t bmi088ReadSingleReg(uint8_t reg)
111 {
112 bmi088ReadWriteByte(reg | Bmi088Data::BMI088_READ_BIT);
113 return bmi088ReadWriteByte(0x55);
114 }
115
116 static inline void bmi088ReadMultiReg(
117 uint8_t reg,
118 uint8_t *rxBuff,
119 uint8_t len,
120 bool readExtraByte)
121 {
122 bmi088ReadWriteByte(reg | Bmi088Data::BMI088_READ_BIT);
123
124 if (readExtraByte)
125 {
126 bmi088ReadWriteByte(0x55);
127 }
128
129 while (len != 0)
130 {
131 *rxBuff = bmi088ReadWriteByte(0x55);
132 rxBuff++;
133 len--;
134 }
135 }
136
137public:
138 static inline void bmi088AccWriteSingleReg(
141 {
142 chipSelectAccelLow();
143 bmi088WriteSingleReg(static_cast<uint8_t>(reg), data.value);
144 chipSelectAccelHigh();
145 }
146
156 {
157 chipSelectAccelLow();
158 bmi088ReadSingleReg(static_cast<uint8_t>(reg));
159 uint8_t res = bmi088ReadWriteByte(0x55);
160 chipSelectAccelHigh();
161 return res;
162 }
163
164 static inline void bmi088AccReadMultiReg(
166 uint8_t *rxBuff,
167 uint8_t len)
168 {
169 chipSelectAccelLow();
170 bmi088ReadMultiReg(static_cast<uint8_t>(reg), rxBuff, len, true);
171 chipSelectAccelHigh();
172 }
173
174 static inline void bmi088GyroWriteSingleReg(
177 {
178 chipSelectGyroLow();
179 bmi088WriteSingleReg(static_cast<uint8_t>(reg), data.value);
180 chipSelectGyroHigh();
181 }
182
184 {
185 chipSelectGyroLow();
186 uint8_t res = bmi088ReadSingleReg(static_cast<uint8_t>(reg));
187 chipSelectGyroHigh();
188 return res;
189 }
190
191 static inline void bmi088GyroReadMultiReg(
193 uint8_t *rxBuff,
194 uint8_t len)
195 {
196 chipSelectGyroLow();
197 bmi088ReadMultiReg(static_cast<uint8_t>(reg), rxBuff, len, false);
198 chipSelectGyroHigh();
199 }
200
201#if defined(ENV_UNIT_TESTS)
206 static void setRxData(uint8_t data) { rxData.push_back(data); }
207
208 static void expectAccWriteSingleReg()
209 {
210 setRxData(0);
211 setRxData(0);
212 }
213
214 static void expectAccReadSingleReg(uint8_t data)
215 {
216 setRxData(0);
217 setRxData(0);
218 setRxData(data);
219 }
220
221 static void expectAccMultiRead(uint8_t *data, uint8_t len)
222 {
223 setRxData(0);
224 setRxData(0);
225 for (uint8_t i = 0; i < len; i++)
226 {
227 setRxData(data[i]);
228 }
229 }
230
231 static void expectGyroWriteSingleReg()
232 {
233 setRxData(0);
234 setRxData(0);
235 }
236
237 static void expectGyroReadSingleReg(uint8_t data)
238 {
239 setRxData(0);
240 setRxData(data);
241 }
242
243 static void expectGyroMultiRead(uint8_t *data, uint8_t len)
244 {
245 setRxData(0);
246 for (uint8_t i = 0; i < len; i++)
247 {
248 setRxData(data[i]);
249 }
250 }
251
252 static void clearData() { rxData.clear(); }
253#endif
254};
255
256} // namespace tap::communication::sensors::imu::bmi088
257
258#endif // TAPROOT_BMI088_HAL_HPP_
static constexpr uint8_t BMI088_READ_BIT
Definition bmi088_data.hpp:42
static void bmi088AccWriteSingleReg(Bmi088Data::Acc::Register reg, Bmi088Data::Acc::Registers_t data)
Definition bmi088_hal.hpp:138
static void bmi088GyroReadMultiReg(Bmi088Data::Gyro::Register reg, uint8_t *rxBuff, uint8_t len)
Definition bmi088_hal.hpp:191
static void bmi088GyroWriteSingleReg(Bmi088Data::Gyro::Register reg, Bmi088Data::Gyro::Registers_t data)
Definition bmi088_hal.hpp:174
static void bmi088AccReadMultiReg(Bmi088Data::Acc::Register reg, uint8_t *rxBuff, uint8_t len)
Definition bmi088_hal.hpp:164
static uint8_t bmi088GyroReadSingleReg(Bmi088Data::Gyro::Register reg)
Definition bmi088_hal.hpp:183
static uint8_t bmi088AccReadSingleReg(Bmi088Data::Acc::Register reg)
Definition bmi088_hal.hpp:155
IUnit i
Definition dimensional_smooth_pid.hpp:2
modm::FlagsGroup< AccErr_t, AccStatus_t, AccIntStat1_t, AccConf_t, Int1IoConf_t, Int2IoConf_t, AccSelfTest_t, AccRange_t, AccPwrConf_t, AccPwrCtrl_t, AccSoftreset_t, IntMapData_t > Registers_t
Definition bmi088_data.hpp:443
Register
List of register addresses for the bmi088's accelerometer.
Definition bmi088_data.hpp:255
modm::FlagsGroup< GyroIntStat1_t, FifoStatus_t, GyroRange_t, GyroBandwidth_t, GyroLpm1_t, GyroSoftreset_t, GyroIntCtrl_t, Int3Int4IoConf_t, Int3Int4IoMap_t, FifoWmEnable_t, FifoExtIntS_t, GyroSelfTest_t, FifoConfig0_t, FifoConfig1_t > Registers_t
Definition bmi088_data.hpp:248
#define UNUSED(var)
Definition util_macros.hpp:43