Browse Source

config edit

Juraj Ďuďák 2 years ago
parent
commit
0fee21f7f9
3 changed files with 34 additions and 26 deletions
  1. 30 23
      src/icm20948.cpp
  2. 3 2
      src/icm20948.h
  3. 1 1
      src/icm_datatypes.h

+ 30 - 23
src/icm20948.cpp

@@ -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;

+ 3 - 2
src/icm20948.h

@@ -119,7 +119,7 @@ public:
 
     Icm20948(SpiManager *spi, icm20948_Config *config);
     void SetInterruptSource(interrupt_source_enum int_source);
-    void Calibrate(void);
+    void Calibrate(icm20948_Config *config);
     void Read(void);
 	void Wakeup(void);
 	void Sleep(void);
@@ -127,7 +127,8 @@ public:
 	bool IsReady(void);
 	uint8_t GetDataStatus(void);
 	uint8_t GetIndex(void);
-	void Reset();
+	uint8_t GetIndexZeroBased(void);
+	void Reset(uint8_t toSleep);
 
 	void Stop(void);
 	void Start(void);

+ 1 - 1
src/icm_datatypes.h

@@ -190,7 +190,7 @@ typedef struct
 typedef struct
 {
 	McuPin_typeDef *pinCS = NULL;
-	McuPin_typeDef *pinINT = NULL;
+	//McuPin_typeDef *pinINT = NULL;
 	McuPin_typeDef *pinLED = NULL;
 	Config_Accel_t accel;
 	Config_Gyro_t gyro;