/*******************************************************************************
 * @file	app_raw.h
 * @author	CandyPops Co.
 * @version V1.0.0
 * @date	2022-09-05
 * @brief
 ******************************************************************************/

/*******************************************************************************
 * [Header overview] ICM42670P IMU driver application layer declarations
 *
 * Function prototypes and operating mode configuration macros for
 * IMU sensor initialization, configuration, and data reading.
 *
 * Key configuration macros:
 *   SERIF_TYPE         - Communication interface (UI_I2C)
 *   USE_LOW_NOISE_MODE - 1: low-noise (800Hz), 0: low-power (100Hz)
 *   USE_HIGH_RES_MODE  - 1: 20-bit high-res, 0: 16-bit standard
 *   USE_FIFO           - 1: use FIFO, 0: direct register read
 ******************************************************************************/

#ifndef _APP_RAW_H_
#define _APP_RAW_H_
#include "sdk_config.h"

#include <stdint.h>
#include "inv_imu_transport.h"
#include "inv_imu_defs.h"
#include "inv_imu_driver.h"


/*** Configuration macros ***/

/*
 * MCU-IMU communication interface selection
 * UI_I2C: use I2C communication (default)
 */
#define SERIF_TYPE           UI_I2C

/*
 * Power mode selection
 * 1: Low-noise mode — 800Hz ODR, high precision, higher power consumption
 * 0: Low-power mode — 100Hz ODR, lower power consumption
 * Note: Low-noise mode cannot be used with ODR below 12.5Hz
 */
#define USE_LOW_NOISE_MODE   1

/*
 * FIFO resolution mode selection
 * 0: Low resolution — 16-bit data (default)
 * 1: High resolution — 20-bit data (FSR locked to 16g/2000dps)
 */
#define USE_HIGH_RES_MODE    0

/*
 * Data read method selection
 * 0: Direct register read (currently in use)
 * 1: Read from FIFO
 */
#define USE_FIFO             0


/**
 * \brief Resets and initializes the IMU device. Includes WHOAMI verification.
 *        Must complete successfully before calling any other IMU access functions.
 *
 * \return 0=success, negative=error
 */
int setup_imu_device(struct inv_imu_serif *icm_serif);

/**
 * \brief Configures the device for gyro and accel output.
 *        Applies FSR, ODR, power mode, and FIFO settings.
 * \return 0=success, negative=error
 */
int configure_imu_device(void);

/**
 * \brief Retrieves IMU data from FIFO or registers.
 *        Internally triggers imu_callback() for data processing.
 * \return 0=success, negative=error
 */
int get_imu_data(void);

/**
 * \brief Sensor data receive callback. Applies mounting matrix then
 *        outputs data according to info4/BLE/UART mode.
 * \param[in] event Structure containing one sensor data packet
 */
void imu_callback(inv_imu_sensor_event_t *event);

/**
 * \brief Direct I2C register read bypassing the driver API.
 *        Reads sensor data immediately without DRDY interrupt and sends via BLE.
 *        Switches IMU to sleep mode after reading to save power.
 * \return 0=success, negative=error
 */
int imu_read_direct(void);


#endif /* !_APP_RAW_H_ */
