
# ICM 20948 driver for STM32

Basic driver for TDK InvenSense ICM-20948. It support 2 modes:

- pooling
- interrupt

# working modes

## Pooling
```c

#include "icm20948.h"


int main(void)
{
  // HAL_Init, etc...

  SpiManager manager(&hspi2);

  icm20948_Config config2;
  config2.pinCS = &pinCS;
  config2.gyro.low_pass_filter = GYRO_lpf_196_6Hz;
  config2.gyro.sample_rate = GYRO_samplerate_281_3Hz;
  config2.accel.low_pass_filter = ACCEL_lpf_246Hz;
  config2.accel.sample_rate = ACCEL_samplerate_281_3Hz;

  Icm20948 sensor2(&manager, &config2);

  axises *my_gyro2 = NULL;
  axises *my_accel2 = NULL;

  while (1)
  {
    // read raw values
    if(sensor2.GetDataStatus() == 1 ){
      //read data
      my_accel2 = sensor2.accSensor->Read();
      my_gyro2 = sensor2.gyroSensor->Read();
      my_mag2 = sensor2.magSensor->Read();

      // or unit conversion
      my_accel2 = sensor2.accSensor->ReadUnit();
      my_gyro2 = sensor2.gyroSensor->ReadUnit();
      my_mag2 = sensor2.magSensor->ReadUnit();
    }

  }
}

```

## Interrupt

```c

#include "icm20948.h"


Device_TypeDef *module;
volatile uint8_t icm_ready;


void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  if(GPIO_Pin == ICM_INT_Pin){
    icm_ready = 1;
  }
}


int main(void)
{

  // HAL_Init, etc...

  axises *my_gyro1 = NULL;
  axises *my_accel1 = NULL;

  SpiManager manager(&hspi2);
  
  icm20948_Config config1;
  config1.pinCS = &pinCS;
  config1.pinINT = &pinINT;
  config1.gyro.low_pass_filter = GYRO_lpf_196_6Hz;
  config1.gyro.sample_rate = GYRO_samplerate_281_3Hz;
  config1.accel.low_pass_filter = ACCEL_lpf_246Hz;
  config1.accel.sample_rate = ACCEL_samplerate_281_3Hz;
  config1.mag.mode = mag_mode_cont_measurement_100hz;
  config1.int_source = interrupt_RAW_DATA_0_RDY_EN;

  while (1)
  {
    if(icm_ready1 == 1){
      icm_ready1 = 0;

      sensor1.Read();   // read data from sensors

      my_accel1 = sensor1.accSensor->GetData(); // only return prepared data
      my_gyro1 = sensor1.gyroSensor->GetData();
      my_mag1 = sensor1.magSensor->GetData();
    }
  }
}

```