|
|
@@ -51,7 +51,6 @@ uint16_t GYRO_SampleRate_Table[16] = {
|
|
|
Icm20948::Icm20948(SpiManager *spi, icm20948_Config *config){
|
|
|
|
|
|
_activeDevice = spi->addSlave(config->pinCS);
|
|
|
- _pinINT = config->pinINT;
|
|
|
_spi = spi;
|
|
|
|
|
|
accSensor = new SensorAccel(spi, _activeDevice);
|
|
|
@@ -64,13 +63,20 @@ Icm20948::Icm20948(SpiManager *spi, icm20948_Config *config){
|
|
|
this->gyroSensor->data.type = ICM20948_GYRO + _activeDevice;
|
|
|
this->magSensor->data.type = ICM20948_MAG + _activeDevice;
|
|
|
|
|
|
- this->Reset();
|
|
|
+ this->Reset(1);
|
|
|
this->Wakeup();
|
|
|
+ this->Calibrate(config);
|
|
|
|
|
|
- this->icm20948_clock_source(1);
|
|
|
- this->icm20948_odr_align_enable();
|
|
|
+ _sensor_ready = true;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void Icm20948::Calibrate(icm20948_Config *config)
|
|
|
+{
|
|
|
+ this->SetInterruptSource(config->int_source);
|
|
|
|
|
|
- this->icm20948_spi_slave_enable();
|
|
|
+ this->accSensor->Calibrate();
|
|
|
+ this->gyroSensor->Calibrate();
|
|
|
|
|
|
this->gyroSensor->SetLowPassFilter(config->gyro.low_pass_filter);
|
|
|
this->accSensor->SetLowPassFilter(config->accel.low_pass_filter);
|
|
|
@@ -78,25 +84,10 @@ Icm20948::Icm20948(SpiManager *spi, icm20948_Config *config){
|
|
|
this->gyroSensor->SetSampleRate(config->gyro.sample_rate);
|
|
|
this->accSensor->SetSampleRate(config->accel.sample_rate);
|
|
|
|
|
|
-
|
|
|
- if(_pinINT != NULL){
|
|
|
- this->SetInterruptSource(config->int_source);
|
|
|
- }
|
|
|
-
|
|
|
- this->Calibrate();
|
|
|
-
|
|
|
this->accSensor->SetRange(config->accel.full_scale);
|
|
|
this->gyroSensor->SetRange(config->gyro.full_scale);
|
|
|
|
|
|
this->ak09916_init(&config->mag);
|
|
|
- _sensor_ready = true;
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-void Icm20948::Calibrate(void)
|
|
|
-{
|
|
|
- this->accSensor->Calibrate();
|
|
|
- this->gyroSensor->Calibrate();
|
|
|
}
|
|
|
|
|
|
bool Icm20948::icm20948_who_am_i()
|
|
|
@@ -109,10 +100,20 @@ bool Icm20948::icm20948_who_am_i()
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-void Icm20948::Reset()
|
|
|
+void Icm20948::Reset(uint8_t toSleep)
|
|
|
{
|
|
|
- _spi->write_single_reg(_activeDevice, ub_0, B0_PWR_MGMT_1, 0x80 | 0x41); // reset, sleep, source PLL auto
|
|
|
+ _spi->write_single_reg(_activeDevice, ub_0, B0_PWR_MGMT_1, 0x80 | toSleep == 1 ? 0x41 : 0x01); // reset, sleep, source PLL auto
|
|
|
HAL_Delay(100);
|
|
|
+
|
|
|
+ this->Wakeup();
|
|
|
+
|
|
|
+ //if(toSleep == 0) // reset without sleep - set internal settings
|
|
|
+ {
|
|
|
+ this->icm20948_clock_source(1);
|
|
|
+ this->icm20948_odr_align_enable();
|
|
|
+ this->icm20948_spi_slave_enable();
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -122,7 +123,7 @@ void Icm20948::Wakeup(void)
|
|
|
new_val &= 0xBF;
|
|
|
|
|
|
_spi->write_single_reg(_activeDevice, ub_0, B0_PWR_MGMT_1, new_val);
|
|
|
- HAL_Delay(100);
|
|
|
+ HAL_Delay(50);
|
|
|
}
|
|
|
|
|
|
uint8_t Icm20948::IsSleep(void)
|
|
|
@@ -290,6 +291,12 @@ void Icm20948::ak09916_operation_mode_setting(AK09916_operation_mode mode)
|
|
|
}
|
|
|
|
|
|
|
|
|
+uint8_t Icm20948::GetIndexZeroBased(void)
|
|
|
+{
|
|
|
+ return this->_activeDevice;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
uint8_t Icm20948::GetIndex(void)
|
|
|
{
|
|
|
return this->_activeDevice + 1;
|