#ifndef TDK_ICM42688_H #define TDK_ICM42688_H #include #include #include "fusion_measurement.h" #ifndef TDK_IMU_RAW_QUEUE_CAPACITY #define TDK_IMU_RAW_QUEUE_CAPACITY 256u #endif #ifndef TDK_IMU_ODR_HZ #define TDK_IMU_ODR_HZ 500u #endif typedef enum { TDK_ACCEL_FS_2G = 2, TDK_ACCEL_FS_4G = 4, TDK_ACCEL_FS_8G = 8, TDK_ACCEL_FS_16G = 16 } tdk_accel_full_scale_t; typedef enum { TDK_GYRO_FS_15D625 = 15625, TDK_GYRO_FS_31D25 = 31250, TDK_GYRO_FS_62D5 = 62500, TDK_GYRO_FS_125 = 125000, TDK_GYRO_FS_250 = 250000, TDK_GYRO_FS_500 = 500000, TDK_GYRO_FS_1000 = 1000000, TDK_GYRO_FS_2000 = 2000000 } tdk_gyro_full_scale_mdps_t; typedef struct { uint32_t odr_hz; tdk_accel_full_scale_t accel_full_scale_g; tdk_gyro_full_scale_mdps_t gyro_full_scale_mdps; uint8_t ui_filter_config; } tdk_icm42688_config_t; typedef struct { uint64_t timestamp_ticks; int16_t temperature_raw; int16_t accel_raw[3]; int16_t gyro_raw[3]; uint32_t sequence; } tdk_icm42688_raw_sample_t; typedef struct { uint64_t irq_count; uint64_t sample_count; uint64_t invalid_sample_count; uint64_t spurious_irq_count; uint64_t queue_overflow_count; uint64_t estimated_missed_sample_count; uint64_t last_timestamp_ticks; uint8_t who_am_i; bool initialized; bool running; } tdk_icm42688_diagnostics_t; void tdk_icm42688_default_config(tdk_icm42688_config_t* config); bool tdk_icm42688_init(const tdk_icm42688_config_t* config); bool tdk_icm42688_start(void); void tdk_icm42688_stop(void); /* Called only by the common PLIC ISR for BSP_PMOD_IRQ. */ void tdk_icm42688_irq_handler(void); /* Foreground conversion; no floating-point work is performed in the ISR. */ bool tdk_icm42688_take_measurement(fusion_imu_measurement_t* measurement_out); void tdk_icm42688_get_diagnostics(tdk_icm42688_diagnostics_t* diagnostics_out); #endif