|
3 | 3 | #define MF_ICM45686_H |
4 | 4 | #include "../imu_interface.h" |
5 | 5 |
|
6 | | -// prevent naming conflicts, e.g. static spi |
7 | | -namespace motionarduino { |
8 | | - #include "./ICM45686/ICM45686.h" |
9 | | - // Force linking |
10 | | - #include "./ICM45686/ICM45686.cpp" |
11 | | - #include "./ICM45686/imu/inv_imu_driver.c" |
12 | | - #include "./ICM45686/imu/inv_imu_driver_advanced.c" |
13 | | - #include "./ICM45686/imu/inv_imu_transport.c" |
14 | | - |
15 | | - // below, not needed it seems: |
16 | | - //#include "./ICM45686/imu/inv_imu_edmp.c" |
17 | | - //#include "./ICM45686/imu/inv_imu_i2cm.c" |
18 | | - // #include "./ICM45686/imu/inv_imu_driver_aux1.c" |
19 | | - // #include "./ICM45686/imu/inv_imu_edmp_compass.c" |
20 | | - // #include "./ICM45686/imu/inv_imu_edmp_wearable.c" |
21 | | - // #include "./ICM45686/imu/inv_imu_i2cm.c" |
22 | | - // #include "./ICM45686/imu/inv_imu_selftest.c" |
23 | | - // #include "./ICM45686/imu/inv_imu_transport.c" |
24 | | -} |
25 | | - |
26 | | - |
| 6 | +#include "./ICM45686/ICM45686.h" |
27 | 7 |
|
28 | 8 | class Invensensev3_Interface { |
29 | 9 | public: |
@@ -54,52 +34,43 @@ class Invensensev3_InterfaceSPI : public Invensensev3_Interface { |
54 | 34 | SPIClass * _spi; |
55 | 35 | int _freq; |
56 | 36 |
|
57 | | - |
58 | 37 | Invensensev3_InterfaceSPI(SPIClass *spi, uint8_t cs) { |
59 | 38 | _spi = spi; |
60 | 39 | _spi_cs = cs; |
61 | 40 | freqSlow = INV3_SPI_FREQ_SLOW; |
62 | 41 | freqFast = INV3_SPI_FREQ_FAST; |
63 | 42 | setFreq(freqSlow); |
64 | | - } |
| 43 | + } |
65 | 44 |
|
66 | | - void setFreq(int freq) { |
| 45 | + void setFreq(int freq) { |
67 | 46 | _freq = freq; |
68 | | - } |
69 | | - |
70 | | - |
71 | | - }; |
72 | | - |
| 47 | + } |
| 48 | +}; |
73 | 49 |
|
74 | 50 | // it is much slower without FIFO!!! |
75 | 51 | #define MF_ICM45686_USE_IMU_FIFO 1 |
76 | 52 |
|
77 | 53 | class MF_ICM45686 { |
78 | | - |
79 | 54 | private: |
80 | | - motionarduino::ICM456xx _wrapped_imu; |
| 55 | + ICM456xx _wrapped_imu; |
81 | 56 |
|
82 | 57 | //raw measurements in NED frame |
83 | 58 | int16_t rawa[3]; //accelerometer |
84 | 59 | int16_t rawg[3]; //gyroscope |
85 | 60 | int16_t rawm[3]; //magnetometer |
86 | 61 | int16_t rawt; //temperature |
87 | 62 |
|
88 | | - |
89 | 63 | int _rate_hz = 100; |
90 | 64 | int _interrupt_pin = 0; |
91 | 65 |
|
92 | 66 | float acc_multiplier = 1.0; |
93 | 67 | float gyro_multiplier = 1.0; |
94 | 68 |
|
95 | 69 | // Note: this is needed because original ICM-45686 driver interface .enableFifoInterrupt() requires to pass a interrupt handler function |
96 | | - static void fake_interrupt_handler() { |
97 | | - } |
98 | | - |
| 70 | + static void fake_interrupt_handler() {} |
99 | 71 |
|
100 | 72 | uint8_t fifo_watermark_threshold = 1; // Watermark threshold value |
101 | 73 |
|
102 | | - |
103 | 74 | int _enableDataReadyInterrupt() { |
104 | 75 | // route UI data ready interrupt to INT1 |
105 | 76 | // FIXME: this takes interrupt handler as argument, which is not standard interface in Madflight |
@@ -150,18 +121,13 @@ class MF_ICM45686 { |
150 | 121 | else if (range == 16) ret = 16; |
151 | 122 | return ret; |
152 | 123 | } |
153 | | - |
154 | 124 |
|
155 | 125 | public: |
156 | 126 | MF_ICM45686(uint8_t intPin, Invensensev3_InterfaceSPI *iface) |
157 | | - : _wrapped_imu( |
158 | | - *((arduino::SPIClass *)(iface->_spi)), |
159 | | - iface->_spi_cs, |
160 | | - iface->_freq) { |
| 127 | + : _wrapped_imu( *(iface->_spi), iface->_spi_cs, iface->_freq) { |
161 | 128 | _interrupt_pin = intPin; |
162 | 129 | } |
163 | 130 |
|
164 | | - |
165 | 131 | // Converting raw values to physical values |
166 | 132 | // Madflight: |
167 | 133 | // Body frame is NED: x-axis North(front), y-axis East(right), z-axis Down |
@@ -246,37 +212,35 @@ class MF_ICM45686 { |
246 | 212 |
|
247 | 213 | // FIXME: implement magnetometer support? |
248 | 214 | // P.S. Orientation of axes seem same as for MPU-xxxx, and is converted in getMotion6NED() function |
249 | | - void read6() { |
| 215 | + void read6() { |
250 | 216 | #ifdef MF_ICM45686_USE_IMU_FIFO |
251 | | - motionarduino::inv_imu_fifo_data_t imu_data; |
252 | | - // FIXME: this might yield multiple samples if fifo_watermark_threshold>1 and there's imu_data.byte_16.timestamp !!! |
253 | | - // FIXME there's also values represented as int20_t , if extra precission is needed... |
254 | | - _wrapped_imu.getDataFromFifo(imu_data); |
255 | | - rawa[0] = imu_data.byte_16.accel_data[0]; |
256 | | - rawa[1] = imu_data.byte_16.accel_data[1]; |
257 | | - rawa[2] = imu_data.byte_16.accel_data[2]; |
258 | | - |
259 | | - rawg[0] = imu_data.byte_16.gyro_data[0]; |
260 | | - rawg[1] = imu_data.byte_16.gyro_data[1]; |
261 | | - rawg[2] = imu_data.byte_16.gyro_data[2]; |
262 | | - // Temperature in Degrees Centigrade = (TEMP_DATA / 128) + 25 |
263 | | - rawt = imu_data.byte_16.temp_data; |
| 217 | + inv_imu_fifo_data_t imu_data; |
| 218 | + // FIXME: this might yield multiple samples if fifo_watermark_threshold>1 and there's imu_data.byte_16.timestamp !!! |
| 219 | + // FIXME there's also values represented as int20_t , if extra precission is needed... |
| 220 | + _wrapped_imu.getDataFromFifo(imu_data); |
| 221 | + rawa[0] = imu_data.byte_16.accel_data[0]; |
| 222 | + rawa[1] = imu_data.byte_16.accel_data[1]; |
| 223 | + rawa[2] = imu_data.byte_16.accel_data[2]; |
| 224 | + |
| 225 | + rawg[0] = imu_data.byte_16.gyro_data[0]; |
| 226 | + rawg[1] = imu_data.byte_16.gyro_data[1]; |
| 227 | + rawg[2] = imu_data.byte_16.gyro_data[2]; |
| 228 | + // Temperature in Degrees Centigrade = (TEMP_DATA / 128) + 25 |
| 229 | + rawt = imu_data.byte_16.temp_data; |
264 | 230 | #else |
265 | | - motionarduino::inv_imu_sensor_data_t imu_data; |
266 | | - _wrapped_imu.getDataFromRegisters(imu_data); |
| 231 | + inv_imu_sensor_data_t imu_data; |
| 232 | + _wrapped_imu.getDataFromRegisters(imu_data); |
267 | 233 |
|
268 | | - rawa[0] = imu_data.accel_data[0]; |
269 | | - rawa[1] = imu_data.accel_data[1]; |
270 | | - rawa[2] = imu_data.accel_data[2]; |
| 234 | + rawa[0] = imu_data.accel_data[0]; |
| 235 | + rawa[1] = imu_data.accel_data[1]; |
| 236 | + rawa[2] = imu_data.accel_data[2]; |
271 | 237 |
|
272 | | - rawg[0] = imu_data.gyro_data[0]; |
273 | | - rawg[1] = imu_data.gyro_data[1]; |
274 | | - rawg[2] = imu_data.gyro_data[2]; |
275 | | - rawt = imu_data.temp_data; |
| 238 | + rawg[0] = imu_data.gyro_data[0]; |
| 239 | + rawg[1] = imu_data.gyro_data[1]; |
| 240 | + rawg[2] = imu_data.gyro_data[2]; |
| 241 | + rawt = imu_data.temp_data; |
276 | 242 | #endif |
277 | 243 | } |
278 | | - |
279 | | - |
280 | 244 | }; |
281 | 245 |
|
282 | 246 | #endif // MF_ICM45686_H |
0 commit comments