@@ -767,17 +767,17 @@ ICM_20948_Status_e ICM_20948::i2cMasterReset()
767
767
return status;
768
768
}
769
769
770
- ICM_20948_Status_e ICM_20948::i2cControllerConfigurePeripheral (uint8_t peripheral, uint8_t addr, uint8_t reg, uint8_t len, bool Rw, bool enable, bool data_only, bool grp, bool swap)
770
+ ICM_20948_Status_e ICM_20948::i2cControllerConfigurePeripheral (uint8_t peripheral, uint8_t addr, uint8_t reg, uint8_t len, bool Rw, bool enable, bool data_only, bool grp, bool swap, uint8_t dataOut )
771
771
{
772
- status = ICM_20948_i2c_controller_configure_peripheral (&_device, peripheral, addr, reg, len, Rw, enable, data_only, grp, swap);
772
+ status = ICM_20948_i2c_controller_configure_peripheral (&_device, peripheral, addr, reg, len, Rw, enable, data_only, grp, swap, dataOut );
773
773
return status;
774
774
}
775
775
776
776
// Provided for backward-compatibility only. Please update to i2cControllerConfigurePeripheral and i2cControllerPeriph4Transaction.
777
777
// https://www.oshwa.org/2020/06/29/a-resolution-to-redefine-spi-pin-names/
778
778
ICM_20948_Status_e ICM_20948::i2cMasterConfigureSlave (uint8_t peripheral, uint8_t addr, uint8_t reg, uint8_t len, bool Rw, bool enable, bool data_only, bool grp, bool swap)
779
779
{
780
- return (i2cControllerConfigurePeripheral (peripheral, addr, reg, len, Rw, enable, data_only, grp, swap));
780
+ return (i2cControllerConfigurePeripheral (peripheral, addr, reg, len, Rw, enable, data_only, grp, swap, 0 ));
781
781
}
782
782
783
783
ICM_20948_Status_e ICM_20948::i2cControllerPeriph4Transaction (uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len, bool Rw, bool send_reg_addr)
@@ -856,7 +856,7 @@ ICM_20948_Status_e ICM_20948::startupDefault(bool minimal)
856
856
return status;
857
857
}
858
858
859
- retval = startupMagnetometer ();
859
+ retval = startupMagnetometer (minimal); // Pass the minimal startup flag to startupMagnetometer
860
860
if (retval != ICM_20948_Stat_Ok)
861
861
{
862
862
debugPrint (F (" ICM_20948::startupDefault: startupMagnetometer returned: " ));
@@ -956,6 +956,17 @@ ICM_20948_Status_e ICM_20948::writeMag(AK09916_Reg_Addr_e reg, uint8_t *pdata)
956
956
return status;
957
957
}
958
958
959
+ ICM_20948_Status_e ICM_20948::resetMag ()
960
+ {
961
+ uint8_t SRST = 1 ;
962
+ // SRST: Soft reset
963
+ // “0”: Normal
964
+ // “1”: Reset
965
+ // When “1” is set, all registers are initialized. After reset, SRST bit turns to “0” automatically.
966
+ status = i2cMasterSingleW (MAG_AK09916_I2C_ADDR, AK09916_REG_CNTL3, SRST);
967
+ return status;
968
+ }
969
+
959
970
// FIFO
960
971
961
972
ICM_20948_Status_e ICM_20948::enableFIFO (bool enable)
@@ -1185,13 +1196,15 @@ ICM_20948_Status_e ICM_20948_I2C::begin(TwoWire &wirePort, bool ad0val, uint8_t
1185
1196
return status;
1186
1197
}
1187
1198
1188
- ICM_20948_Status_e ICM_20948::startupMagnetometer (void )
1199
+ ICM_20948_Status_e ICM_20948::startupMagnetometer (bool minimal )
1189
1200
{
1190
1201
ICM_20948_Status_e retval = ICM_20948_Stat_Ok;
1191
1202
1192
1203
i2cMasterPassthrough (false ); // Do not connect the SDA/SCL pins to AUX_DA/AUX_CL
1193
1204
i2cMasterEnable (true );
1194
1205
1206
+ resetMag ();
1207
+
1195
1208
// After a ICM reset the Mag sensor may stop responding over the I2C master
1196
1209
// Reset the Master I2C until it responds
1197
1210
uint8_t tries = 0 ;
@@ -1230,6 +1243,7 @@ ICM_20948_Status_e ICM_20948::startupMagnetometer(void)
1230
1243
// Set up magnetometer
1231
1244
AK09916_CNTL2_Reg_t reg;
1232
1245
reg.MODE = AK09916_mode_cont_100hz;
1246
+ reg.reserved_0 = 0 ; // Make sure the unused bits are clear. Probably redundant, but prevents confusion when looking at the I2C traffic
1233
1247
retval = writeMag (AK09916_REG_CNTL2, (uint8_t *)®);
1234
1248
if (retval != ICM_20948_Stat_Ok)
1235
1249
{
@@ -1240,6 +1254,13 @@ ICM_20948_Status_e ICM_20948::startupMagnetometer(void)
1240
1254
return status;
1241
1255
}
1242
1256
1257
+ // Return now if minimal is true. The mag will be configured manually for the DMP
1258
+ if (minimal) // Return now if minimal is true
1259
+ {
1260
+ debugPrintln (F (" ICM_20948::startupMagnetometer: minimal startup complete!" ));
1261
+ return status;
1262
+ }
1263
+
1243
1264
retval = i2cControllerConfigurePeripheral (0 , MAG_AK09916_I2C_ADDR, AK09916_REG_ST1, 9 , true , true , false , false , false );
1244
1265
if (retval != ICM_20948_Stat_Ok)
1245
1266
{
0 commit comments