ICM42670 Portable Driver
Public API reference for the ICM-42670-P IMU driver
Loading...
Searching...
No Matches
ICM42670_apex.c File Reference

ICM-42670-P APEX motion feature functions. More...

#include "ICM42670_apex.h"
#include "ICM42670_internal.h"
#include <stddef.h>
Include dependency graph for ICM42670_apex.c:

Macros

#define ICM42670_APEX_MEM_RESET_DELAY_MS   1U
 
#define ICM42670_APEX_INIT_DELAY_MS   50U
 
#define ICM42670_REG_APEX_DATA4   0x1DU
 
#define ICM42670_REG_APEX_DATA0   0x31U
 
#define ICM42670_MREG1_APEX_CONFIG3   0x45U
 
#define ICM42670_MREG1_APEX_CONFIG5   0x47U
 
#define ICM42670_MREG1_APEX_CONFIG9   0x48U
 
#define ICM42670_MREG1_APEX_CONFIG10   0x49U
 
#define ICM42670_MREG1_ACCEL_WOM_X_THR   0x4BU
 
#define ICM42670_MREG1_ACCEL_WOM_Y_THR   0x4CU
 
#define ICM42670_MREG1_ACCEL_WOM_Z_THR   0x4DU
 
#define ICM42670_MREG1_APEX_CONFIG12   0x67U
 
#define ICM42670_APEX_CONFIG1_PED_ENABLE   0x08U
 
#define ICM42670_APEX_CONFIG1_TILT_ENABLE   0x10U
 
#define ICM42670_APEX_CONFIG1_FF_ENABLE   0x20U
 
#define ICM42670_APEX_CONFIG1_SMD_ENABLE   0x40U
 
#define ICM42670_APEX_CONFIG0_DMP_MEM_RESET_EN   0x01U
 
#define ICM42670_APEX_CONFIG0_DMP_INIT_EN   0x04U
 
#define ICM42670_APEX_CONFIG0_DMP_POWER_SAVE_EN   0x08U
 
#define ICM42670_APEX_CONFIG1_DMP_ODR_MASK   0x03U
 
#define ICM42670_APEX_CONFIG1_DMP_ODR_50HZ   0x02U
 
#define ICM42670_APEX_CONFIG1_FEATURE_ENABLE_MASK   0x78U
 
#define ICM42670_WOM_CONFIG_WOM_EN   0x01U
 
#define ICM42670_INT_STATUS2_WOM_Z   0x01U
 
#define ICM42670_INT_STATUS2_WOM_Y   0x02U
 
#define ICM42670_INT_STATUS2_WOM_X   0x04U
 
#define ICM42670_INT_STATUS2_SMD   0x08U
 
#define ICM42670_INT_STATUS3_LOWG   0x02U
 
#define ICM42670_INT_STATUS3_FF   0x04U
 
#define ICM42670_INT_STATUS3_TILT   0x08U
 
#define ICM42670_INT_STATUS3_STEP_OVF   0x10U
 
#define ICM42670_INT_STATUS3_STEP_DET   0x20U
 
#define ICM42670_APEX_CONFIG3_PED_STEP_CNT_TH_MASK   0x0FU
 
#define ICM42670_APEX_CONFIG3_PED_STEP_CNT_TH_ONE_STEP   0x01U
 
#define ICM42670_APEX_CONFIG5_TILT_WAIT_MASK   0xC0U
 
#define ICM42670_APEX_CONFIG9_FF_DEBOUNCE_MASK   0xF0U
 
#define ICM42670_APEX_CONFIG9_SMD_SENSITIVITY_MASK   0x0EU
 
#define ICM42670_APEX_CONFIG9_PED_SLOW_WALK_MASK   0x01U
 
#define ICM42670_APEX_CONFIG10_LOWG_MASK   0xFFU
 
#define ICM42670_APEX_CONFIG12_FF_DURATION_MASK   0xFFU
 
#define ICM42670_APEX_PEDO_INVALID_BYTE   0xFFU
 
#define ICM42670_APEX_PEDO_READ_ATTEMPTS   3U
 

Enumerations

enum  ICM42670_ApexState_t { ICM42670_APEX_DISABLE = 0U , ICM42670_APEX_ENABLE = 1U }
 

Functions

ICM42670_Status_t ICM42670_Init_Apex (const ICM42670_Config *config)
 Initialize the APEX DMP block before enabling tilt/pedometer features.
 
ICM42670_Status_t ICM42670_Enable_Pedo (const ICM42670_Config *config, const ICM42670_PedoConfig_t *pedo_config)
 Pedometer tracks step count and issues a step detect interrupt.
 
ICM42670_Status_t ICM42670_Disable_Pedo (const ICM42670_Config *config)
 Disable pedometer reporting.
 
ICM42670_Status_t ICM42670_Read_Pedo (const ICM42670_Config *config, ICM42670_PedoData_t *pedo_data)
 Read pedometer data and read-clear step status flags.
 
ICM42670_Status_t ICM42670_Enable_Tilt (const ICM42670_Config *config, const ICM42670_TiltConfig_t *tilt_config)
 Tilt detection issues an interrupt when the tilt angle exceeds 35 degrees for more than a programmable time.
 
ICM42670_Status_t ICM42670_Disable_Tilt (const ICM42670_Config *config)
 Disable tilt detection.
 
ICM42670_Status_t ICM42670_Read_Tilt (const ICM42670_Config *config, uint8_t *tilt_detected)
 Read and clear the tilt event flag.
 
ICM42670_Status_t ICM42670_Enable_Low_G (const ICM42670_Config *config, const ICM42670_LowGConfig_t *low_g_config)
 Low-g detection triggers an interrupt when the absolute value of the accelerometer combined axis falls below a programmable threshold and stays below the threshold for a programmable time.
 
ICM42670_Status_t ICM42670_Disable_Low_G (const ICM42670_Config *config)
 Disable low-g detection.
 
ICM42670_Status_t ICM42670_Read_Low_G (const ICM42670_Config *config, uint8_t *low_g_detected)
 Read and clear the low-g event flag.
 
ICM42670_Status_t ICM42670_Enable_Free_Fall (const ICM42670_Config *config, const ICM42670_FreeFallConfig_t *free_fall_config)
 Freefall detection triggers an interrupt when device freefall is detected and outputs freefall duration.
 
ICM42670_Status_t ICM42670_Disable_Free_Fall (const ICM42670_Config *config)
 Disable freefall detection.
 
ICM42670_Status_t ICM42670_Read_Free_Fall (const ICM42670_Config *config, ICM42670_FreeFallData_t *free_fall_data)
 Read freefall data and read-clear the freefall event flag.
 
ICM42670_Status_t ICM42670_Enable_Wake_On_Motion (const ICM42670_Config *config, const ICM42670_WakeOnMotionConfig_t *wake_on_motion_config)
 Wake on Motion detects motion when accelerometer samples exceed a programmable threshold. This motion event can be used to enable device operation from sleep mode.
 
ICM42670_Status_t ICM42670_Disable_Wake_On_Motion (const ICM42670_Config *config)
 Disable wake-on-motion detection.
 
ICM42670_Status_t ICM42670_Read_Wake_On_Motion (const ICM42670_Config *config, ICM42670_WakeOnMotionData_t *wake_on_motion_data)
 Read and clear wake-on-motion axis flags.
 
ICM42670_Status_t ICM42670_Enable_Significant_Motion (const ICM42670_Config *config, const ICM42670_SignificantMotionConfig_t *significant_motion_config)
 Significant Motion Detector detects significant motion based on accelerometer data.
 
ICM42670_Status_t ICM42670_Disable_Significant_Motion (const ICM42670_Config *config)
 Disable significant-motion detection.
 
ICM42670_Status_t ICM42670_Read_Significant_Motion (const ICM42670_Config *config, uint8_t *significant_motion_detected)
 Read and clear the significant-motion event flag.
 
ICM42670_Status_t ICM42670_Read_Apex (const ICM42670_Config *config, ICM42670_ApexData_t *apex_data)
 Read a combined APEX data snapshot.
 

Detailed Description

ICM-42670-P APEX motion feature functions.

Author
Anthony / SleepPandas

Function Documentation

◆ ICM42670_Disable_Free_Fall()

ICM42670_Status_t ICM42670_Disable_Free_Fall ( const ICM42670_Config config)

Disable freefall detection.

Parameters
configDriver configuration with read and write callbacks.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR.

◆ ICM42670_Disable_Low_G()

ICM42670_Status_t ICM42670_Disable_Low_G ( const ICM42670_Config config)

Disable low-g detection.

Parameters
configDriver configuration with read and write callbacks.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR.

◆ ICM42670_Disable_Pedo()

ICM42670_Status_t ICM42670_Disable_Pedo ( const ICM42670_Config config)

Disable pedometer reporting.

Parameters
configDriver configuration with read and write callbacks.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR.

◆ ICM42670_Disable_Significant_Motion()

ICM42670_Status_t ICM42670_Disable_Significant_Motion ( const ICM42670_Config config)

Disable significant-motion detection.

Parameters
configDriver configuration with read and write callbacks.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR.

◆ ICM42670_Disable_Tilt()

ICM42670_Status_t ICM42670_Disable_Tilt ( const ICM42670_Config config)

Disable tilt detection.

Parameters
configDriver configuration with read and write callbacks.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR.

◆ ICM42670_Disable_Wake_On_Motion()

ICM42670_Status_t ICM42670_Disable_Wake_On_Motion ( const ICM42670_Config config)

Disable wake-on-motion detection.

Parameters
configDriver configuration with read and write callbacks.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR.

◆ ICM42670_Enable_Free_Fall()

ICM42670_Status_t ICM42670_Enable_Free_Fall ( const ICM42670_Config config,
const ICM42670_FreeFallConfig_t free_fall_config 
)

Freefall detection triggers an interrupt when device freefall is detected and outputs freefall duration.

Parameters
configDriver configuration with read and write callbacks.
free_fall_configFreefall setup values.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR or ICM42670_BUSY.

References ICM42670_FreeFallConfig_t::debounce_ms, ICM42670_ERROR, ICM42670_OK, ICM42670_FreeFallConfig_t::max_distance_cm, and ICM42670_FreeFallConfig_t::min_distance_cm.

◆ ICM42670_Enable_Low_G()

ICM42670_Status_t ICM42670_Enable_Low_G ( const ICM42670_Config config,
const ICM42670_LowGConfig_t low_g_config 
)

Low-g detection triggers an interrupt when the absolute value of the accelerometer combined axis falls below a programmable threshold and stays below the threshold for a programmable time.

Parameters
configDriver configuration with read and write callbacks.
low_g_configLow-g setup values.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR or ICM42670_BUSY.

References ICM42670_ERROR, ICM42670_OK, ICM42670_LowGConfig_t::sample_count, and ICM42670_LowGConfig_t::threshold_mg.

◆ ICM42670_Enable_Pedo()

ICM42670_Status_t ICM42670_Enable_Pedo ( const ICM42670_Config config,
const ICM42670_PedoConfig_t pedo_config 
)

Pedometer tracks step count and issues a step detect interrupt.

Parameters
configDriver configuration with read and write callbacks.
pedo_configPedometer setup values.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR or ICM42670_BUSY.

References ICM42670_ERROR, ICM42670_OK, and ICM42670_PedoConfig_t::slow_walk_enable.

◆ ICM42670_Enable_Significant_Motion()

ICM42670_Status_t ICM42670_Enable_Significant_Motion ( const ICM42670_Config config,
const ICM42670_SignificantMotionConfig_t significant_motion_config 
)

Significant Motion Detector detects significant motion based on accelerometer data.

Parameters
configDriver configuration with read and write callbacks.
significant_motion_configSignificant-motion setup values.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR or ICM42670_BUSY.

References ICM42670_ERROR, ICM42670_OK, and ICM42670_SignificantMotionConfig_t::sensitivity_level.

◆ ICM42670_Enable_Tilt()

ICM42670_Status_t ICM42670_Enable_Tilt ( const ICM42670_Config config,
const ICM42670_TiltConfig_t tilt_config 
)

Tilt detection issues an interrupt when the tilt angle exceeds 35 degrees for more than a programmable time.

Parameters
configDriver configuration with read and write callbacks.
tilt_configTilt setup values.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR or ICM42670_BUSY.

References ICM42670_ERROR, ICM42670_OK, and ICM42670_TiltConfig_t::wait_time_s.

◆ ICM42670_Enable_Wake_On_Motion()

ICM42670_Status_t ICM42670_Enable_Wake_On_Motion ( const ICM42670_Config config,
const ICM42670_WakeOnMotionConfig_t wake_on_motion_config 
)

Wake on Motion detects motion when accelerometer samples exceed a programmable threshold. This motion event can be used to enable device operation from sleep mode.

Parameters
configDriver configuration with read and write callbacks.
wake_on_motion_configWake-on-motion threshold setup.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR or ICM42670_BUSY.

References ICM42670_ERROR, ICM42670_OK, ICM42670_WakeOnMotionConfig_t::x_threshold_mg, ICM42670_WakeOnMotionConfig_t::y_threshold_mg, and ICM42670_WakeOnMotionConfig_t::z_threshold_mg.

◆ ICM42670_Init_Apex()

ICM42670_Status_t ICM42670_Init_Apex ( const ICM42670_Config config)

Initialize the APEX DMP block before enabling tilt/pedometer features.

This sets DMP_ODR to 50 Hz, disables DMP power-save for direct polling use, resets APEX memory, and runs the DMP initialization command.

Parameters
configDriver configuration with read, write, and delay callbacks.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR or ICM42670_BUSY.

References ICM42670_Config::delay_ms, ICM42670_ERROR, and ICM42670_OK.

◆ ICM42670_Read_Apex()

ICM42670_Status_t ICM42670_Read_Apex ( const ICM42670_Config config,
ICM42670_ApexData_t apex_data 
)

◆ ICM42670_Read_Free_Fall()

ICM42670_Status_t ICM42670_Read_Free_Fall ( const ICM42670_Config config,
ICM42670_FreeFallData_t free_fall_data 
)

Read freefall data and read-clear the freefall event flag.

Parameters
configDriver configuration with a read callback.
free_fall_dataDestination for freefall data.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR.

References ICM42670_FreeFallData_t::detected, ICM42670_FreeFallData_t::duration_samples, ICM42670_ERROR, and ICM42670_OK.

◆ ICM42670_Read_Low_G()

ICM42670_Status_t ICM42670_Read_Low_G ( const ICM42670_Config config,
uint8_t *  low_g_detected 
)

Read and clear the low-g event flag.

Parameters
configDriver configuration with a read callback.
low_g_detectedDestination flag, nonzero when low-g was reported.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR.

References ICM42670_ERROR, and ICM42670_OK.

◆ ICM42670_Read_Pedo()

ICM42670_Status_t ICM42670_Read_Pedo ( const ICM42670_Config config,
ICM42670_PedoData_t pedo_data 
)

Read pedometer data and read-clear step status flags.

Parameters
configDriver configuration with a read callback.
pedo_dataDestination for pedometer data.
Returns
ICM42670_OK on success, ICM42670_BUSY if data is invalid, otherwise ICM42670_ERROR.

References ICM42670_PedoData_t::activity, ICM42670_PedoData_t::cadence_raw, ICM42670_BUSY, ICM42670_ERROR, ICM42670_OK, ICM42670_PedoData_t::overflow, ICM42670_PedoData_t::step_count, and ICM42670_PedoData_t::step_detected.

◆ ICM42670_Read_Significant_Motion()

ICM42670_Status_t ICM42670_Read_Significant_Motion ( const ICM42670_Config config,
uint8_t *  significant_motion_detected 
)

Read and clear the significant-motion event flag.

Parameters
configDriver configuration with a read callback.
significant_motion_detectedDestination flag, nonzero when reported.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR.

References ICM42670_ERROR, and ICM42670_OK.

◆ ICM42670_Read_Tilt()

ICM42670_Status_t ICM42670_Read_Tilt ( const ICM42670_Config config,
uint8_t *  tilt_detected 
)

Read and clear the tilt event flag.

Parameters
configDriver configuration with a read callback.
tilt_detectedDestination flag, nonzero when tilt was reported.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR.

References ICM42670_ERROR, and ICM42670_OK.

◆ ICM42670_Read_Wake_On_Motion()

ICM42670_Status_t ICM42670_Read_Wake_On_Motion ( const ICM42670_Config config,
ICM42670_WakeOnMotionData_t wake_on_motion_data 
)

Read and clear wake-on-motion axis flags.

Parameters
configDriver configuration with a read callback.
wake_on_motion_dataDestination for axis flags.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR.

References ICM42670_ERROR, ICM42670_OK, ICM42670_WakeOnMotionData_t::x_detected, ICM42670_WakeOnMotionData_t::y_detected, and ICM42670_WakeOnMotionData_t::z_detected.