diff options
Diffstat (limited to 'examples/imx7d_sdb_m4/demo_apps/sensor_demo/common/fxas21002.h')
-rw-r--r-- | examples/imx7d_sdb_m4/demo_apps/sensor_demo/common/fxas21002.h | 129 |
1 files changed, 111 insertions, 18 deletions
diff --git a/examples/imx7d_sdb_m4/demo_apps/sensor_demo/common/fxas21002.h b/examples/imx7d_sdb_m4/demo_apps/sensor_demo/common/fxas21002.h index a3adbae..aa8408f 100644 --- a/examples/imx7d_sdb_m4/demo_apps/sensor_demo/common/fxas21002.h +++ b/examples/imx7d_sdb_m4/demo_apps/sensor_demo/common/fxas21002.h @@ -31,21 +31,23 @@ #ifndef __FXAS21002_H__ #define __FXAS21002_H__ -#define OVERSAMPLE_RATIO (64) // int32: 8x: 3DOF, 6DOF, 9DOF run at SENSORFS / OVERSAMPLE_RATIO Hz - -// place the gain in the gyro structure -#define FXAS21002_COUNTSPERDEGPERSEC (16.0F) // for production 2000dps range (2000dps=32000) -#define FXAS21002_DEGPERSECPERCOUNT (0.0625F) // must be reciprocal of FCOUNTSPERDEGPERSEC +/*! + * @addtogroup fxas21002 + * @{ + */ -/* I2C Slave Address define */ +/******************************************************************************* + * Definitions + ******************************************************************************/ +/*! @brief FXAS21002 I2C address. */ #define FXAS21002_ADDRESS_0 (0x20) #define FXAS21002_ADDRESS_1 (0x21) #define FXAS21002_ADDRESS_DEFAULT (FXAS21002_ADDRESS_0) -/* FXAS21002 device ID number */ +/*! @brief FXAS21002 device ID number. */ #define FXAS21002_DEVICE_ID (0xD7) -/* FXAS21002 Registers address definition */ +/*! @brief FXAS21002 Registers address definition. */ #define FXAS21002_STATUS (0x00) #define FXAS21002_OUT_X_MSB (0x01) #define FXAS21002_OUT_X_LSB (0x02) @@ -69,28 +71,119 @@ #define FXAS21002_CTRL_REG2 (0x14) #define FXAS21002_CTRL_REG3 (0x15) -// gyro sensor structure definition -typedef struct _gyro_sensor +/* + * Field Definitions. + */ + +/*! @brief fxas21002 output data rate configuration. */ +typedef enum _fxas_data_rate_cfg +{ + fxasDataRate800Hz = 0x0 << 2, + fxasDataRate400HZ = 0x1 << 2, + fxasDataRate200HZ = 0x2 << 2, + fxasDataRate100HZ = 0x3 << 2, + fxasDataRate50HZ = 0x4 << 2, + fxasDataRate25HZ = 0x5 << 2, + fxasDataRate12_5HZ = 0x6 << 2, +} fxas_data_rate_cfg_t; + +/*! @brief fxas21002 gyroscope full-scale range */ +typedef enum _fxas_range_cfg +{ + fxasRange2000Dps = 0x0, /*!< +-2000 dps mode */ + fxasRange1000Dps = 0x1, /*!< +-1000 dps mode */ + fxasRange500Dps = 0x2, /*!< +-500 dps mode */ + fxasRange250Dps = 0x3 /*!< +-250 dps mode */ +} fxas_range_cfg_t; + +/*! @brief fxas21002 configure definition. */ +typedef struct _fxas_handle +{ + /* I2C relevant definition. */ + i2c_handle_t *device; /*!< I2C handle. */ + uint8_t address; /*!< fxas21002 I2C bus address. */ +} fxas_handle_t; + +/*! @brief Initialize structure of fxas21002 */ +typedef struct _fxas_init +{ + fxas_data_rate_cfg_t dataRate; /*!< Output data rate selection */ + fxas_range_cfg_t range; /*!< Accelerometer full scale range selection */ +} fxas_init_t; + +/*! @brief fxas gyroscope data struct */ +typedef struct _fxas_data { - int32_t iSumYpFast[3]; // sum of fast measurements - float fYp[3]; // raw gyro sensor output (deg/s) - float fDegPerSecPerCount; // initialized to FDEGPERSECPERCOUNT - int16_t iYpFast[3]; // fast (typically 200Hz) readings - int16_t iYp[3]; // averaged gyro sensor output (counts) -} gyro_sensor_t; + int16_t gyroX; + int16_t gyroY; + int16_t gyroZ; +} fxas_data_t; /* Function prototypes */ #if defined(__cplusplus) extern "C" { #endif -bool fxas21002_init(gyro_sensor_t*); -bool fxas21002_read_data(gyro_sensor_t*); +/*! + * @brief fxas21002 initialize function. + * + * This function should be called after i2c module initialize, and in this function, + * some configurations are fixed. The second parameter is the initialize structure to fxas21002. + * If users want to change the settings after initialization, they have to use FXAS_writeReg() + * to set the register value of fxas21002. + * @param handle fxas21002 handle structure. + * @param fxos_config fxas21002 configuration structure. + */ +bool FXAS_Init(fxas_handle_t *handle, const fxas_init_t *fxas_config); + +/*! + * @brief Deinit the fxas21002 sensor. + * + * Mainly used to set fxas21002 to standby mode and reset its registers content. + * @param handle fxas21002 handle structure pointer. + */ +bool FXAS_Deinit(fxas_handle_t *handle); + +/*! + * @brief Enable the FXAS21002 sensor. + * @param handle FXAS21002 handler structure. + */ +bool FXAS_Enable(fxas_handle_t *handle); + +/*! + * @brief Disable the FXAS21002 sensor. + * @param handle FXAS21002 handler structure. + */ +bool FXAS_Disable(fxas_handle_t *handle); + +/*! + * @brief Write register to fxas21002 using I2C. + * @param handle fxas21002 handle structure. + * @param regAddr The register address in fxas21002. + * @param regVal Value needs to write into the register. + */ +bool FXAS_WriteReg(fxas_handle_t *handle, uint8_t regAddr, uint8_t regVal); + +/*! + * @brief Read register from fxas21002 using I2C. + * @param handle fxas21002 handle structure. + * @param regAddr The register address in fxas21002. + * @param regValPtr The read value buffer pointer. + */ +bool FXAS_ReadReg(fxas_handle_t *handle, uint8_t regAddr, uint8_t *regValPtr); + +/*! + * @brief Read sensor data from fxas21002 using I2C + * @param handler fxas21002 handler structure. + * @param val Sensor data read from fxas21002. + */ +bool FXAS_ReadData(fxas_handle_t *handle, fxas_data_t *val); #ifdef __cplusplus } #endif +/*! @} */ #endif /* __FXAS21002_H__ */ /******************************************************************************* |