123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- #ifndef __DRV_LSM6DS3TR_C_H__
- #define __DRV_LSM6DS3TR_C_H__
- #ifdef __cplusplus
- extern "C" {
- #endif
- /*Includes ------------------------------------------------------*/
- #include <stdint.h>
- #include <stdio.h>
- #include <stdbool.h>
- #include "lsm6ds3tr-c_reg.h"
- /*STRUCTION -----------------------------------------------------*/
- typedef enum{
- LSM_ACC_ODR_OFF = LSM6DS3TR_C_XL_ODR_OFF, //关闭加速度
-
- LSM_ACC_ODR_12HZ5 = LSM6DS3TR_C_XL_ODR_12Hz5, //采样频率 - 12.5赫兹
-
- LSM_ACC_ODR_104HZ = LSM6DS3TR_C_XL_ODR_104Hz, //采样频率 - 104赫兹
-
- LSM_ACC_ODR_208HZ = LSM6DS3TR_C_XL_ODR_208Hz, //采样频率 - 208赫兹
-
- LSM_ACC_ODR_416HZ = LSM6DS3TR_C_XL_ODR_416Hz, //采样频率 - 416赫兹
-
- LSM_ACC_ODR_833HZ = LSM6DS3TR_C_XL_ODR_833Hz, //采样频率 - 833赫兹
-
- } LSM_ACC_ODR_e;
- typedef enum{
- LSM_GRY_ODR_OFF = LSM6DS3TR_C_GY_ODR_OFF, //关闭陀螺仪
-
- LSM_GRY_ODR_12HZ5 = LSM6DS3TR_C_GY_ODR_12Hz5, //采样频率 - 12.5赫兹
-
- LSM_GRY_ODR_104HZ = LSM6DS3TR_C_GY_ODR_104Hz, //采样频率 - 104赫兹
-
- LSM_GRY_ODR_208HZ = LSM6DS3TR_C_GY_ODR_208Hz, //采样频率 - 208赫兹
- LSM_GRY_ODR_416HZ = LSM6DS3TR_C_GY_ODR_416Hz, //采样频率 - 416赫兹
- LSM_GRY_ODR_833HZ = LSM6DS3TR_C_GY_ODR_833Hz, //采样频率 - 833赫兹
-
- } LSM_GRY_ODR_e;
- typedef enum{
- LSM_MAG_ODR_OFF = 0x00, //关闭地磁计
-
- LSM_MAG_ODR_10HZ = 0x31, //采样频率 - 10赫兹
-
- LSM_MAG_ODR_100HZ = 0x39, //采样频率 - 100赫兹
-
- LSM_MAG_ODR_200HZ = 0x3D, //采样频率 - 200赫兹
-
- } LSM_MAG_ODR_e;
- typedef enum{
- LSM_FIFO_ODR_OFF = LSM6DS3TR_C_FIFO_DISABLE, //关闭FIFO
-
- LSM_FIFO_ODR_12HZ5 = LSM6DS3TR_C_FIFO_12Hz5, //采样频率 - 12.5赫兹
-
- LSM_FIFO_ODR_104HZ = LSM6DS3TR_C_FIFO_104Hz, //采样频率 - 104赫兹
-
- LSM_FIFO_ODR_208HZ = LSM6DS3TR_C_FIFO_208Hz, //采样频率 - 208赫兹
-
- LSM_FIFO_ODR_416HZ = LSM6DS3TR_C_FIFO_416Hz, //采样频率 - 416赫兹
-
- LSM_FIFO_ODR_833HZ = LSM6DS3TR_C_FIFO_833Hz, //采样频率 - 833赫兹
-
- } LSM_FIFO_ODR_e;
- typedef enum{
- LSM_ACC_POWER_MODE_HIGH_PERFORMANCE = LSM6DS3TR_C_XL_HIGH_PERFORMANCE, //加速度工作模式 - 高性能
-
- LSM_ACC_POWER_MODE_NORMAL = LSM6DS3TR_C_XL_NORMAL, //加速度工作模式 - 正常
-
- } LSM_ACC_POWER_MODE_e;
- typedef enum{
- LSM_GRY_POWER_MODE_HIGH_PERFORMANCE = LSM6DS3TR_C_GY_HIGH_PERFORMANCE, //陀螺仪工作模式 - 高性能
-
- LSM_GRY_POWER_MODE_NORMAL = LSM6DS3TR_C_GY_NORMAL, //陀螺仪工作模式 - 正常
-
- } LSM_GRY_POWER_MODE_e;
- typedef enum{
- LSM_TIMESTAMP_6MS4 = LSM6DS3TR_C_LSB_6ms4, //时间戳精度 - 6.4毫秒
-
- LSM_TIMESTAMP_25US = LSM6DS3TR_C_LSB_25us, //时间戳精度 - 25微妙
-
- } LSM_TIMESTAMP_RESOLUTION_e;
- typedef enum{
- LSM_TIMESTAMP_OFF = 0, //时间戳关闭
-
- LSM_TIMESTAMP_ON = 1, //时间戳开启
-
- } LSM_TIMESTAMP_SWITCH_e;
- typedef enum{
- LSM_ACC_FS_2G = LSM6DS3TR_C_2g, //量程 - 2倍重力加速度
-
- LSM_ACC_FS_16G = LSM6DS3TR_C_16g, //量程 - 16倍重力加速度
-
- } LSM_ACC_FS_e;
- typedef enum{
- LSM_GRY_FS_250DPS = LSM6DS3TR_C_250dps, //量程 - 250角速度/秒
-
- LSM_GRY_FS_2000DPS = LSM6DS3TR_C_2000dps, //量程 - 2000角速度/秒
-
- } LSM_GRY_FS_e;
- typedef enum{
- LSM_MAG_FS_30GS = 0x00, //量程 - 30高斯
-
- } LSM_MAG_FS_e;
- typedef struct
- {
- LSM_ACC_POWER_MODE_e acc_power_mode; //加速度工作模式
-
- LSM_GRY_POWER_MODE_e gry_power_mode; //陀螺仪工作模式
-
- LSM_FIFO_ODR_e fifo_odr; //FIFO采样频率
-
- LSM_TIMESTAMP_RESOLUTION_e timestamp_resolution; //时间戳精度
-
- LSM_TIMESTAMP_SWITCH_e timestamp_switch; //时间戳开关,注:时间戳采样率和FIFO采样率一致
-
- LSM_ACC_ODR_e acc_odr; //加速度采样频率
-
- LSM_GRY_ODR_e gry_odr; //陀螺仪采样频率
-
- LSM_MAG_ODR_e mag_odr; //地磁计采样频率
-
- LSM_ACC_FS_e acc_fs; //加速度量程
-
- LSM_GRY_FS_e gry_fs; //陀螺仪量程
-
- LSM_MAG_FS_e mag_fs; //地磁计量程
-
- } drv_lsm_config_param_t;
- typedef struct
- {
- int16_t acc[3]; //加速度三轴
-
- int16_t gry[3]; //陀螺仪三轴
-
- int16_t mag[3]; //地磁计三轴
-
- int32_t fifo_timestamp; //fifo时间戳
-
- } lsm_data_t;
- /*API -------------------------------------------------------*/
- /**
- @brief 初始化LSM驱动
- @param 无
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_Init(void);
- /**
- @brief LSM断电
- @param 无
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_power_off(void);
- /**
- @brief LSM上电(默认配置挂起)
- @param 无
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_power_on(void);
- /**
- @brief 设置加速度工作模式
- @param acc_power_mode - [in] 加速度工作模式
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_set_acc_power_mode(LSM_ACC_POWER_MODE_e acc_power_mode);
- /**
- @brief 设置陀螺仪工作模式
- @param gry_power_mode - [in] 陀螺仪工作模式
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_set_gry_power_mode(LSM_GRY_POWER_MODE_e gry_power_mode);
- /**
- @brief 设置时间戳精度
- @param timestamp_resolution - [in] 时间戳精度
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_set_timestamp_resolution(LSM_TIMESTAMP_RESOLUTION_e timestamp_resolution);
- /**
- @brief 设置时间戳开关
- @param timestamp_switch - [in] 时间戳开关
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_set_timestamp_switch(LSM_TIMESTAMP_SWITCH_e timestamp_switch);
- /**
- @brief 设置FIFO采样频率
- @param fifo_odr - [in] FIFO采样频率
- @param acc_odr - [in] 加速度采样频率
- @param gry_odr - [in] 陀螺仪采样频率
- @param mag_odr - [in] 地磁计采样频率
- @param timestamp_switch - [in] 时间戳开关
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_set_fifo_odr(LSM_FIFO_ODR_e fifo_odr, LSM_ACC_ODR_e acc_odr, LSM_GRY_ODR_e gry_odr, LSM_MAG_ODR_e mag_odr, LSM_TIMESTAMP_SWITCH_e timestamp_switch);
- /**
- @brief 设置ACC量程
- @param acc_fs - [in] ACC量程
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_set_acc_fs(LSM_ACC_FS_e acc_fs);
- /**
- @brief 设置ACC采样频率
- @param acc_odr - [in] ACC采样频率
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_set_acc_odr(LSM_ACC_ODR_e acc_odr);
- /**
- @brief 设置GRY量程
- @param gry_fs - [in] GRY量程
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_set_gry_fs(LSM_GRY_FS_e gry_fs);
- /**
- @brief 设置GRY采样频率
- @param gry_odr - [in] GRY采样频率
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_set_gry_odr(LSM_GRY_ODR_e gry_odr);
- /**
- @brief 获取配置MAG量程需要的步骤数量
- @return 错误代码 - [out] 配置MAG量程需要的步骤数量
- */
- int drv_lsm_get_mag_fs_flow(void);
- /**
- @brief 设置MAG量程
- @param mag_fs - [in] MAG量程
- @param flow - [in] 当前需要处理的步骤
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_set_mag_fs(LSM_MAG_FS_e mag_fs, int flow);
- /**
- @brief 获取配置MAG采样频率需要的步骤数量
- @return 错误代码 - [out] 配置MAG采样频率需要的步骤数量
- */
- int drv_lsm_get_mag_odr_flow(void);
- /**
- @brief 设置MAG采样频率
- @param mag_odr - [in] MAG采样频率
- @param set_hub - [in] 是否配置hub
- @param flow - [in] 当前需要处理的步骤
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_set_mag_odr(LSM_MAG_ODR_e mag_odr, bool set_hub, int flow);
- /**
- @brief 获取LSM配置参数
- @param param - [in] LSM配置参数
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_get_config_param(drv_lsm_config_param_t *p_param);
- /**
- @brief 当前LSM的FIFO有几组数据
- @return 错误代码 - [out] FIFO当前有几组数据
- */
- int drv_lsm_get_fifo_group_num(void);
- /**
- @brief 获取LSM的FIFO数据
- @param p_data - [out] 返回的FIFO数据
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_get_fifo_data(lsm_data_t *p_data);
- /**
- @brief 获取LSM的ACC数据
- @param p_data - [out] 返回的ACC三轴数据
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_get_acc_data(lsm_data_t *p_data);
- /**
- @brief LSM自检步骤拆分——1,执行玩需等待100ms稳定输出才能执行步骤2
- @param 无
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_self_check_1(void);
- /**
- @brief LSM自检步骤拆分——2,执行玩需等待100ms稳定输出才能执行步骤3
- @param 无
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_self_check_2(void);
- /**
- @brief LSM自检步骤拆分——3,执行玩需等待150ms稳定输出才能执行步骤4
- @param 无
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_self_check_3(void);
- /**
- @brief LSM自检步骤拆分——4,执行玩需等待50ms稳定输出才能执行步骤5
- @param 无
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_self_check_4(void);
- /**
- @brief LSM自检步骤拆分——5,获取自检结果。
- @param 无
- @return 错误代码 - [out] -1失败,0成功
- */
- int drv_lsm_self_check_5(void);
- int drv_lsm_get_lsm_id(void);
- int drv_lsm_get_mag_id(void);
- int drv_lsm_selfcheck_mag(void);
- #ifdef __cplusplus
- }
- #endif
- #endif
|