|
ICM42670 Portable Driver
Public API reference for the ICM-42670-P IMU driver
|
Core ICM-42670-P configuration and sensor read API. More...


Go to the source code of this file.
Data Structures | |
| struct | ICM42670_Accel_t |
| Scaled accelerometer sample in g. More... | |
| struct | ICM42670_Gyro_t |
| Scaled gyroscope sample in degrees per second. More... | |
| struct | ICM42670_Gyro_Offsets_t |
| Raw gyroscope bias offsets subtracted by ICM42670_ReadGyroDps(). More... | |
| struct | ICM42670_Config |
| Platform-independent driver configuration. More... | |
Enumerations | |
| enum | ICM42670_Status_t { ICM42670_OK = 0 , ICM42670_ERROR = -1 , ICM42670_BUSY = -2 } |
| Return codes used by the ICM-42670-P driver. More... | |
| enum | ICM42670_AccelFS_t { ICM42670_ACCEL_FS_16G = 0x00U , ICM42670_ACCEL_FS_8G = 0x20U , ICM42670_ACCEL_FS_4G = 0x40U , ICM42670_ACCEL_FS_2G = 0x60U } |
| Accelerometer full-scale range values for ACCEL_CONFIG0. | |
| enum | ICM42670_GyroFS_t { ICM42670_GYRO_FS_2000_DPS = 0x00U , ICM42670_GYRO_FS_1000_DPS = 0x20U , ICM42670_GYRO_FS_500_DPS = 0x40U , ICM42670_GYRO_FS_250_DPS = 0x60U } |
| Gyroscope full-scale range values for GYRO_CONFIG0. | |
| enum | ICM42670_Odr_t { ICM42670_ODR_1600_HZ = 0x05U , ICM42670_ODR_800_HZ = 0x06U , ICM42670_ODR_400_HZ = 0x07U , ICM42670_ODR_200_HZ = 0x08U , ICM42670_ODR_100_HZ = 0x09U , ICM42670_ODR_50_HZ = 0x0AU , ICM42670_ODR_25_HZ = 0x0BU , ICM42670_ODR_12_5_HZ = 0x0CU , ICM42670_ACCEL_ODR_6_25_HZ = 0x0DU , ICM42670_ACCEL_ODR_3_125_HZ = 0x0EU , ICM42670_ACCEL_ODR_1_5625_HZ = 0x0FU } |
| Output data rate values for accelerometer and gyroscope setup. | |
| enum | ICM42670_Lpf_t { ICM42670_LPF_BYPASSED = 0x00U , ICM42670_LPF_180_HZ = 0x01U , ICM42670_LPF_121_HZ = 0x02U , ICM42670_LPF_73_HZ = 0x03U , ICM42670_LPF_53_HZ = 0x04U , ICM42670_LPF_34_HZ = 0x05U , ICM42670_LPF_25_HZ = 0x06U , ICM42670_LPF_16_HZ = 0x07U } |
| UI low-pass filter bandwidth selections. | |
| enum | ICM42670_PowerState_t { ICM42670_POWER_SLEEP = 0x00U , ICM42670_POWER_STANDBY , ICM42670_POWER_ACCEL_LP , ICM42670_POWER_ACCEL_LN , ICM42670_POWER_GYRO_LN , ICM42670_POWER_6AXIS_LN } |
| Standard PWR_MGMT0 power states exposed by the driver. More... | |
Functions | |
| ICM42670_Status_t | ICM42670_Init (ICM42670_Config *config) |
| Initialize the device and enter 6-axis low-noise mode. | |
| ICM42670_Status_t | ICM42670_SetPowerState (ICM42670_Config *config, ICM42670_PowerState_t state) |
| Switch the ICM-42670-P to one of the standard datasheet power modes. | |
| ICM42670_Status_t | ICM42670_SetAccelRange (ICM42670_Config *config, ICM42670_AccelFS_t accel_fs) |
| Set the accelerometer full-scale range. | |
| ICM42670_Status_t | ICM42670_SetGyroRange (ICM42670_Config *config, ICM42670_GyroFS_t gyro_fs) |
| Set the gyroscope full-scale range. | |
| ICM42670_Status_t | ICM42670_SetAccelOdr (ICM42670_Config *config, ICM42670_Odr_t odr) |
| Set the accelerometer output data rate. | |
| ICM42670_Status_t | ICM42670_SetGyroOdr (ICM42670_Config *config, ICM42670_Odr_t odr) |
| Set the gyroscope output data rate. | |
| ICM42670_Status_t | ICM42670_SetAccelLpf (ICM42670_Config *config, ICM42670_Lpf_t lpf) |
| Set the accelerometer UI low-pass filter bandwidth. | |
| ICM42670_Status_t | ICM42670_SetGyroLpf (ICM42670_Config *config, ICM42670_Lpf_t lpf) |
| Set the gyroscope UI low-pass filter bandwidth. | |
| ICM42670_Status_t | ICM42670_ReadAccelRaw (const ICM42670_Config *config, int16_t accel_raw[3]) |
| Read raw accelerometer counts. | |
| ICM42670_Status_t | ICM42670_ReadGyroRaw (const ICM42670_Config *config, int16_t gyro_raw[3]) |
| Read raw gyroscope counts. | |
| ICM42670_Status_t | ICM42670_ReadTempRaw (const ICM42670_Config *config, int16_t *temp_raw) |
| Read the raw temperature register value. | |
| ICM42670_Status_t | ICM42670_ReadAccelG (const ICM42670_Config *config, ICM42670_Accel_t *accel) |
| Read accelerometer data converted to g. | |
| ICM42670_Status_t | ICM42670_ReadGyroDps (const ICM42670_Config *config, ICM42670_Gyro_t *gyro) |
| Read gyroscope data converted to degrees per second. | |
| ICM42670_Status_t | ICM42670_ReadTempC (const ICM42670_Config *config, float *temp_c) |
| Read temperature converted to degrees Celsius. | |
| ICM42670_Status_t | ICM42670_Gyro_Calibration (ICM42670_Config *config) |
| Estimate gyroscope bias while the board is stationary. | |
Core ICM-42670-P configuration and sensor read API.
The core driver is platform independent. Applications provide register read/write callbacks and a millisecond delay callback through ICM42670_Config.
Standard PWR_MGMT0 power states exposed by the driver.
| Enumerator | |
|---|---|
| ICM42670_POWER_SLEEP | Sleep mode: gyro off, accel off. Lowest normal sensor-off state. MREG access is not available in sleep unless the RC oscillator is kept on with PWR_MGMT0.IDLE. |
| ICM42670_POWER_STANDBY | Standby mode: gyro drive on, accel off. Use when preparing gyro operation without accelerometer data. The gyro should stay enabled for at least 45 ms once powered on, and callers should wait more than 20 ms after powering it off before enabling it again. |
| ICM42670_POWER_ACCEL_LP | Accelerometer low-power mode: gyro off, accel duty-cycled. Use for low-current, always-on motion sensing. Configure a valid accelerometer ODR and LP averaging before entering this mode: 1600 Hz and 800 Hz are LN-only, while 6.25 Hz, 3.125 Hz, and 1.5625 Hz are LP-only. MREG access is not supported with the WUOSC LP clock unless IDLE enables the RC oscillator. |
| ICM42670_POWER_ACCEL_LN | Accelerometer low-noise mode: gyro off, accel on. Use for accelerometer-only reads when lower noise is more important than minimum current draw. |
| ICM42670_POWER_GYRO_LN | Gyroscope low-noise mode: gyro on, accel off. Use for gyroscope-only reads. The ICM-42670-P does not provide a gyro low-power measurement mode. |
| ICM42670_POWER_6AXIS_LN | 6-axis low-noise mode: gyro on, accel on. Use when both accelerometer and gyroscope data are needed. This is the default mode selected by ICM42670_Init(). |
| enum ICM42670_Status_t |
| ICM42670_Status_t ICM42670_Gyro_Calibration | ( | ICM42670_Config * | config | ) |
Estimate gyroscope bias while the board is stationary.
This averages raw gyro samples and stores the offsets in config.
| config | Driver configuration with read and delay callbacks. |
References ICM42670_Config::delay_ms, ICM42670_Config::gyro_offsets, ICM42670_ERROR, ICM42670_OK, ICM42670_ReadGyroRaw(), ICM42670_Gyro_Offsets_t::x_raw_offset, ICM42670_Gyro_Offsets_t::y_raw_offset, and ICM42670_Gyro_Offsets_t::z_raw_offset.
| ICM42670_Status_t ICM42670_Init | ( | ICM42670_Config * | config | ) |
Initialize the device and enter 6-axis low-noise mode.
The function validates callbacks, checks WHO_AM_I, normalizes invalid range/ODR values to defaults, writes accel/gyro configuration, and enables both sensors.
| config | Driver configuration with valid callbacks. |
References ICM42670_Config::accel_fs, ICM42670_Config::accel_odr, ICM42670_Config::delay_ms, ICM42670_Config::gyro_fs, ICM42670_Config::gyro_odr, ICM42670_Config::handle, ICM42670_ERROR, ICM42670_OK, ICM42670_POWER_6AXIS_LN, ICM42670_SetPowerState(), ICM42670_Config::read_reg, and ICM42670_Config::write_reg.
| ICM42670_Status_t ICM42670_ReadAccelG | ( | const ICM42670_Config * | config, |
| ICM42670_Accel_t * | accel | ||
| ) |
Read accelerometer data converted to g.
| config | Driver configuration with current accel_fs value. |
| accel | Destination for scaled acceleration. |
References ICM42670_Config::accel_fs, ICM42670_ERROR, ICM42670_OK, ICM42670_ReadAccelRaw(), ICM42670_Accel_t::x_g, ICM42670_Accel_t::y_g, and ICM42670_Accel_t::z_g.
| ICM42670_Status_t ICM42670_ReadAccelRaw | ( | const ICM42670_Config * | config, |
| int16_t | accel_raw[3] | ||
| ) |
Read raw accelerometer counts.
| config | Driver configuration with a read callback. |
| accel_raw | Destination array: X, Y, Z raw counts. |
References ICM42670_Config::handle, ICM42670_ERROR, ICM42670_OK, and ICM42670_Config::read_reg.
Referenced by ICM42670_ReadAccelG().
| ICM42670_Status_t ICM42670_ReadGyroDps | ( | const ICM42670_Config * | config, |
| ICM42670_Gyro_t * | gyro | ||
| ) |
Read gyroscope data converted to degrees per second.
Configured gyro_offsets are subtracted before scaling.
| config | Driver configuration with current gyro_fs value. |
| gyro | Destination for scaled angular rate. |
References ICM42670_Config::gyro_fs, ICM42670_Config::gyro_offsets, ICM42670_ERROR, ICM42670_OK, ICM42670_ReadGyroRaw(), ICM42670_Gyro_t::x_dps, ICM42670_Gyro_Offsets_t::x_raw_offset, ICM42670_Gyro_t::y_dps, ICM42670_Gyro_Offsets_t::y_raw_offset, ICM42670_Gyro_t::z_dps, and ICM42670_Gyro_Offsets_t::z_raw_offset.
| ICM42670_Status_t ICM42670_ReadGyroRaw | ( | const ICM42670_Config * | config, |
| int16_t | gyro_raw[3] | ||
| ) |
Read raw gyroscope counts.
| config | Driver configuration with a read callback. |
| gyro_raw | Destination array: X, Y, Z raw counts. |
References ICM42670_Config::handle, ICM42670_ERROR, ICM42670_OK, and ICM42670_Config::read_reg.
Referenced by ICM42670_Gyro_Calibration(), and ICM42670_ReadGyroDps().
| ICM42670_Status_t ICM42670_ReadTempC | ( | const ICM42670_Config * | config, |
| float * | temp_c | ||
| ) |
Read temperature converted to degrees Celsius.
| config | Driver configuration with a read callback. |
| temp_c | Destination for temperature in degrees Celsius. |
References ICM42670_ERROR, ICM42670_OK, and ICM42670_ReadTempRaw().
| ICM42670_Status_t ICM42670_ReadTempRaw | ( | const ICM42670_Config * | config, |
| int16_t * | temp_raw | ||
| ) |
Read the raw temperature register value.
| config | Driver configuration with a read callback. |
| temp_raw | Destination for the signed raw temperature count. |
References ICM42670_Config::handle, ICM42670_ERROR, ICM42670_OK, ICM42670_REG_TEMP_DATA1, and ICM42670_Config::read_reg.
Referenced by ICM42670_ReadTempC().
| ICM42670_Status_t ICM42670_SetAccelLpf | ( | ICM42670_Config * | config, |
| ICM42670_Lpf_t | lpf | ||
| ) |
Set the accelerometer UI low-pass filter bandwidth.
| config | Driver configuration with read and write callbacks. |
| lpf | Low-pass filter selection. |
| ICM42670_Status_t ICM42670_SetAccelOdr | ( | ICM42670_Config * | config, |
| ICM42670_Odr_t | odr | ||
| ) |
Set the accelerometer output data rate.
| config | Driver configuration with read and write callbacks. |
| odr | Accelerometer output data rate. |
References ICM42670_Config::accel_odr, ICM42670_ERROR, and ICM42670_OK.
| ICM42670_Status_t ICM42670_SetAccelRange | ( | ICM42670_Config * | config, |
| ICM42670_AccelFS_t | accel_fs | ||
| ) |
Set the accelerometer full-scale range.
| config | Driver configuration with read and write callbacks. |
| accel_fs | Accelerometer range selection. |
References ICM42670_Config::accel_fs, ICM42670_ERROR, and ICM42670_OK.
| ICM42670_Status_t ICM42670_SetGyroLpf | ( | ICM42670_Config * | config, |
| ICM42670_Lpf_t | lpf | ||
| ) |
Set the gyroscope UI low-pass filter bandwidth.
| config | Driver configuration with read and write callbacks. |
| lpf | Low-pass filter selection. |
| ICM42670_Status_t ICM42670_SetGyroOdr | ( | ICM42670_Config * | config, |
| ICM42670_Odr_t | odr | ||
| ) |
Set the gyroscope output data rate.
| config | Driver configuration with read and write callbacks. |
| odr | Gyroscope output data rate. |
References ICM42670_Config::gyro_odr, ICM42670_ERROR, and ICM42670_OK.
| ICM42670_Status_t ICM42670_SetGyroRange | ( | ICM42670_Config * | config, |
| ICM42670_GyroFS_t | gyro_fs | ||
| ) |
Set the gyroscope full-scale range.
| config | Driver configuration with read and write callbacks. |
| gyro_fs | Gyroscope range selection. |
References ICM42670_Config::gyro_fs, ICM42670_ERROR, and ICM42670_OK.
| ICM42670_Status_t ICM42670_SetPowerState | ( | ICM42670_Config * | config, |
| ICM42670_PowerState_t | state | ||
| ) |
Switch the ICM-42670-P to one of the standard datasheet power modes.
This writes PWR_MGMT0 and then waits 1 ms so the datasheet's 200 us no-register-write window is respected when either sensor transitions from off to an active mode. Gyro off/on timing and accel LP ODR/filter restrictions remain caller responsibilities.
| config | Driver configuration with write and delay callbacks. |
| state | Target power state. |
References ICM42670_Config::delay_ms, ICM42670_Config::handle, ICM42670_ERROR, ICM42670_OK, and ICM42670_Config::write_reg.
Referenced by ICM42670_Init().