Skip to content

ICM20948

ICM20948 9-axis IMU service (3-axis accelerometer + 3-axis gyroscope + 3-axis magnetometer via AK09916). Reads the DMP FIFO on a data-ready interrupt and publishes a sensor packet via pub/sub.

APID: K_ICM20948_SERVICE_APID (0x0002)


Files

File Description
icm20948.h Public API, register map, ICM20948_t context struct
icm20948.c Driver implementation, DMP loading, service task
dmpImage.h DMP firmware binary image (do not edit)

Key types

typedef struct {
    /* Config — set at declaration */
    spp_uint8_t  spiDevIdx;    // SPI device index (0 = ICM20948 on ESP32 port)
    spp_uint32_t intPin;       // Data-ready interrupt GPIO
    spp_uint32_t intIntrType;  // Interrupt trigger type (rising edge = 1)
    spp_uint32_t intPull;      // Pull resistor: 0=none 1=up 2=down

    /* Runtime — filled by init, do not set manually */
    void                  *p_spi;
    ICM20948_Data_t        icmData;    // drdyFlag + ISR context
    ICM20948_SensorData_t  lastData;
    spp_uint16_t           seq;
} ICM20948_t;

typedef struct {
    float      ax, ay, az;   // Accelerometer (g)
    float      gx, gy, gz;   // Gyroscope (dps)
    float      mx, my, mz;   // Magnetometer (µT)
    spp_bool_t dataReady;
} ICM20948_SensorData_t;

Register banks

The ICM20948 has four register banks (0–3) selected via register 0x7F. The driver handles bank switching transparently — do not write to 0x7F directly.


DMP support

The DMP firmware (dmpImage.h) is loaded into the sensor's RAM at init time. Current config: - DATA_OUT_CTL1 = 0x8400 → Accel + Quat9 only - Packet size = 24 bytes: Header(2) + Accel(6) + Quat9(14) + Footer(2)

Disable DMP at build time with -DSPP_ICM20948_NO_DMP=1 to save ~14 KB of flash.


Registration

extern const SPP_Module_t g_icm20948Module;

static ICM20948_t s_icm = {
    .spiDevIdx   = 0U,
    .intPin      = 10U,
    .intIntrType = 1U,   // rising edge
    .intPull     = 0U,   // no pull
};

SPP_SERVICES_register(&g_icm20948Module, &s_icm);

register() calls init (loads DMP firmware, installs ISR) and start immediately.


Packet payload layout (24 bytes — Accel + Quat9)

Offset Type Field
0 float Accel X (g)
4 float Accel Y (g)
8 float Accel Z (g)
12 float Quat9 Q1
16 float Quat9 Q2
20 float Quat9 Q3

Hardware configuration (ESP32-S3)

  • SPI device index: 0 (CS GPIO 21, 1 MHz, MODE0)
  • INT pin: 10 (configured via ICM20948_t)