Skip to content

Commit 81dd539

Browse files
committed
cleanup ICM45686 compiler warnings
1 parent 35f3a64 commit 81dd539

File tree

4 files changed

+37
-77
lines changed

4 files changed

+37
-77
lines changed

src/madflight/imu/ICM4xxxx/ICM45686/ICM45686.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ ICM456xx::ICM456xx(SPIClass &spi_ref,uint8_t cs_id) {
102102

103103
/* starts communication with the ICM456xx */
104104
int ICM456xx::begin() {
105-
int rc = 0;
106-
uint8_t who_am_i;
107-
108105
if (i2c != NULL) {
109106
i2c->begin();
110107
i2c->setClock(clk_freq);
@@ -188,7 +185,6 @@ int ICM456xx::setup_irq(uint8_t intpin, ICM456xx_irq_handler handler)
188185

189186
int ICM456xx::enableFifoInterrupt(uint8_t intpin, ICM456xx_irq_handler handler, uint8_t fifo_watermark) {
190187
int rc = 0;
191-
inv_imu_int_state_t it_conf;
192188
const inv_imu_fifo_config_t fifo_config = {
193189
.gyro_en=true,
194190
.accel_en=true,
@@ -481,7 +477,7 @@ int ICM456xx::startWakeOnMotion(uint8_t intpin, ICM456xx_irq_handler handler)
481477
inv_imu_set_config_int(&icm_driver,INV_IMU_INT1, &config_int);
482478

483479
/* All othher APEX disabled */
484-
for(int i; i < ICM456XX_APEX_NB; i++)
480+
for(int i = 0; i < ICM456XX_APEX_NB; i++)
485481
{
486482
apex_enable[i] = false;
487483
}
@@ -500,7 +496,6 @@ int ICM456xx::startWakeOnMotion(uint8_t intpin, ICM456xx_irq_handler handler)
500496
int ICM456xx::startTap(uint8_t intpin, ICM456xx_irq_handler handler)
501497
{
502498
int rc = 0;
503-
inv_imu_edmp_apex_parameters_t apex_parameters;
504499

505500
apex_enable[ICM456XX_APEX_TAP] = true;
506501

@@ -513,7 +508,6 @@ int ICM456xx::startTap(uint8_t intpin, ICM456xx_irq_handler handler)
513508
int ICM456xx::startRaiseToWake(uint8_t intpin, ICM456xx_irq_handler handler)
514509
{
515510
int rc = 0;
516-
inv_imu_edmp_apex_parameters_t apex_parameters;
517511

518512
apex_enable[ICM456XX_APEX_R2W] = true;
519513

src/madflight/imu/ICM4xxxx/ICM45686/imu/inv_imu_driver.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ typedef struct {
5757
* (only required when using advanced feature set).
5858
* @note In case advanced module is not used, this field can be removed.
5959
*/
60-
uint64_t adv_var[6];
60+
//uint64_t adv_var[6]; //warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
61+
uint8_t adv_var[48];
6162

6263
} inv_imu_device_t;
6364

src/madflight/imu/ICM4xxxx/MF_ICM45686.h

Lines changed: 31 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,7 @@
33
#define MF_ICM45686_H
44
#include "../imu_interface.h"
55

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"
277

288
class Invensensev3_Interface {
299
public:
@@ -54,52 +34,43 @@ class Invensensev3_InterfaceSPI : public Invensensev3_Interface {
5434
SPIClass * _spi;
5535
int _freq;
5636

57-
5837
Invensensev3_InterfaceSPI(SPIClass *spi, uint8_t cs) {
5938
_spi = spi;
6039
_spi_cs = cs;
6140
freqSlow = INV3_SPI_FREQ_SLOW;
6241
freqFast = INV3_SPI_FREQ_FAST;
6342
setFreq(freqSlow);
64-
}
43+
}
6544

66-
void setFreq(int freq) {
45+
void setFreq(int freq) {
6746
_freq = freq;
68-
}
69-
70-
71-
};
72-
47+
}
48+
};
7349

7450
// it is much slower without FIFO!!!
7551
#define MF_ICM45686_USE_IMU_FIFO 1
7652

7753
class MF_ICM45686 {
78-
7954
private:
80-
motionarduino::ICM456xx _wrapped_imu;
55+
ICM456xx _wrapped_imu;
8156

8257
//raw measurements in NED frame
8358
int16_t rawa[3]; //accelerometer
8459
int16_t rawg[3]; //gyroscope
8560
int16_t rawm[3]; //magnetometer
8661
int16_t rawt; //temperature
8762

88-
8963
int _rate_hz = 100;
9064
int _interrupt_pin = 0;
9165

9266
float acc_multiplier = 1.0;
9367
float gyro_multiplier = 1.0;
9468

9569
// 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() {}
9971

10072
uint8_t fifo_watermark_threshold = 1; // Watermark threshold value
10173

102-
10374
int _enableDataReadyInterrupt() {
10475
// route UI data ready interrupt to INT1
10576
// FIXME: this takes interrupt handler as argument, which is not standard interface in Madflight
@@ -150,18 +121,13 @@ class MF_ICM45686 {
150121
else if (range == 16) ret = 16;
151122
return ret;
152123
}
153-
154124

155125
public:
156126
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) {
161128
_interrupt_pin = intPin;
162129
}
163130

164-
165131
// Converting raw values to physical values
166132
// Madflight:
167133
// Body frame is NED: x-axis North(front), y-axis East(right), z-axis Down
@@ -246,37 +212,35 @@ class MF_ICM45686 {
246212

247213
// FIXME: implement magnetometer support?
248214
// P.S. Orientation of axes seem same as for MPU-xxxx, and is converted in getMotion6NED() function
249-
void read6() {
215+
void read6() {
250216
#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;
264230
#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);
267233

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];
271237

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;
276242
#endif
277243
}
278-
279-
280244
};
281245

282246
#endif // MF_ICM45686_H

src/madflight/imu/MPUxxxx/MPUxxxx.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class MPUXXXX {
104104
if(_type == MPU9150 && wai != 0x68) {
105105
Serial.printf("WARNING: MPU9150 whoami mismatch, got:0x%02X expected:0x68\n",wai);
106106
}
107-
if(_type == MPU9250 && wai != 0x71 && wai != 0x73) {
107+
if(_type == MPU9250 && wai != 0x71 && wai != 0x73) { // MPU9250 -> 0x71, MPU9255 -> 0x73
108108
if(wai == 0x70) {
109109
Serial.printf("WARNING: MPU9250 whoami mismatch, got:0x%02X expected:0x71 - this is probably a relabelled MPU6500\n",wai);
110110
}else{
@@ -141,7 +141,8 @@ class MPUXXXX {
141141
// MPU6050 should return 0x68
142142
// MPU6500 should return 0x70
143143
// MPU9150 should return 0x68
144-
// MPU9250 should return 0x71 or 0x73 , see https://github.com/kriswiner/MPU9250/issues/47
144+
// MPU9250 should return 0x71
145+
// MPU9255 should return 0x73
145146
unsigned int whoami()
146147
{
147148
_iface->setFreqSlow();

0 commit comments

Comments
 (0)