bolar_1 date 2026-7-1 d:/proc
This commit is contained in:
87
main/boards/common/bmi270.h
Normal file
87
main/boards/common/bmi270.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* BMI270 IMU Driver for ESP32
|
||||
* 整合自 3d_kalman_demo.cpp 和 bmi270_context.c
|
||||
*/
|
||||
|
||||
#ifndef BMI270_H
|
||||
#define BMI270_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// BMI270 寄存器定义
|
||||
#define BMI270_CHIP_ID 0x00
|
||||
#define BMI270_IF_CONF 0x6B
|
||||
#define BMI270_AUX_DEV_ID 0x4B
|
||||
#define BMI270_PWR_CONF 0x7C
|
||||
#define BMI270_PWR_CTRL 0x7D
|
||||
#define BMI270_CMD 0x7E
|
||||
#define BMI270_AUX_IF_CONFIG 0x4C
|
||||
#define BMI270_AUX_READ_ADDR 0x4D
|
||||
#define BMI270_AUX_WRITE_ADDR 0x4E
|
||||
#define BMI270_AUX_WRITE_DATA 0x4F
|
||||
#define BMI270_AUX_STATUS 0x03
|
||||
#define BMI270_AUX_DATA0 0x04
|
||||
#define BMI270_ACC_DATA0 0x0C
|
||||
#define BMI270_GYR_DATA0 0x12
|
||||
#define BMI270_ACC_CONF 0x40
|
||||
#define BMI270_ACC_RANGE 0x41
|
||||
#define BMI270_GYR_CONF 0x42
|
||||
#define BMI270_GYR_RANGE 0x43
|
||||
#define BMI270_AUX_CONF 0x44
|
||||
#define BMI270_INIT_CTRL 0x59
|
||||
#define BMI270_INIT_DATA 0x5E
|
||||
#define BMI270_INTERNAL_STATUS 0x21
|
||||
|
||||
// BMM150 寄存器定义
|
||||
#define BMM150_REG_POWER_CONTROL 0x4B
|
||||
#define BMM150_SHIP_ID 0x40
|
||||
#define BMM150_DATA0 0x42
|
||||
|
||||
// 传感器数据结构
|
||||
typedef struct {
|
||||
int16_t accel[3]; // 加速度计数据 (x, y, z)
|
||||
int16_t gyro[3]; // 陀螺仪数据 (x, y, z)
|
||||
int16_t magn[3]; // 磁力计数据 (x, y, z)
|
||||
float temperature; // 温度(如有)
|
||||
} bmi270_data_t;
|
||||
|
||||
// 配置结构
|
||||
typedef struct {
|
||||
uint8_t i2c_addr; // I2C 地址 (默认 0x69)
|
||||
uint8_t acc_range; // 加速度计量程
|
||||
uint8_t gyro_range; // 陀螺仪量程
|
||||
uint32_t i2c_speed_hz; // I2C 速度
|
||||
uint8_t aux_i2c_addr; // 辅助I2C地址 (BMM150磁力计)
|
||||
} bmi270_config_t;
|
||||
// BMI270 设备句柄类型(前向声明)
|
||||
typedef struct bmi270_dev_t* bmi270_handle_t;
|
||||
// 初始化函数
|
||||
esp_err_t bmi270_init(bmi270_config_t* config);
|
||||
esp_err_t bmi270_read_sensor_data(bmi270_data_t* data);
|
||||
|
||||
|
||||
// 配置函数
|
||||
esp_err_t bmi270_set_accel_range(uint8_t range);
|
||||
esp_err_t bmi270_set_gyro_range(uint8_t range);
|
||||
esp_err_t bmi270_set_power_mode(uint8_t mode);
|
||||
|
||||
// 工具函数
|
||||
esp_err_t bmi270_self_test(void);
|
||||
uint8_t bmi270_get_chip_id(void);
|
||||
esp_err_t bmi270_soft_reset(void);
|
||||
|
||||
// 原始数据访问
|
||||
esp_err_t bmi270_read_raw_accel(int16_t* x, int16_t* y, int16_t* z);
|
||||
esp_err_t bmi270_read_raw_gyro(int16_t* x, int16_t* y, int16_t* z);
|
||||
esp_err_t bmi270_read_raw_magn(int16_t* x, int16_t* y, int16_t* z);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // BMI270_H
|
||||
Reference in New Issue
Block a user