This commit is contained in:
lmx
2025-12-10 16:21:41 +08:00
parent 3b36715264
commit d92818a894
9 changed files with 79 additions and 160 deletions

View File

@ -32,8 +32,8 @@
// IIC配置 //
//*********************************************************************************//
/*软件IIC设置*/ //xtell
#define TCFG_SW_I2C0_CLK_PORT IO_PORTA_05 //软件IIC CLK脚选择 XTELL
#define TCFG_SW_I2C0_DAT_PORT IO_PORTA_06 //软件IIC DAT脚选择
#define TCFG_SW_I2C0_CLK_PORT IO_PORTB_04 //软件IIC CLK脚选择 XTELL
#define TCFG_SW_I2C0_DAT_PORT IO_PORTB_05 //软件IIC DAT脚选择
#define TCFG_SW_I2C0_DELAY_CNT 10 //IIC延时参数影响通讯时钟频率
/*硬件IIC端口选择 -- 具体看手册,这里写的不准 -- lmx

View File

@ -375,36 +375,7 @@ void stop_clloct(void){
os_task_del("BLE_send_fuc");
}
/**
* @brief 初始化在app_main.c的app_main函数被调用
*
*/
void xtell_task_create(void){
#if TCFG_GSENOR_USER_IIC_TYPE
int ret = hw_iic_init(0);
xlog("init iic result:%d\n", ret); //返回0成功
#else
int ret = soft_iic_init(0);
int num_chars_written = snprintf(log_buffer_1, sizeof(log_buffer_1),"init iic: %d\n", ret);
#endif
// MPU9250_Mag_Init();
//iic总线设备扫描
// extern void i2c_scanner_probe(void);
// i2c_scanner_probe();
xlog("xtell_task_create\n");
circle_buffer_init(&g_ble_send_cb, g_sensor_data_storage, SENSOR_DATA_BUFFER_SIZE, sizeof(ble_send_data_t));
os_sem_create(&receiver_ready_sem, 0);
extern void test_uart_init(void);
test_uart_init();
}
/**
@ -435,7 +406,38 @@ void uartSendData(void *buf, u16 len) //发送数据的接口。
}
#endif
}
//////////////////////////////////////////////////////////////////////////////
/**
* @brief 初始化在xtell_app_main.c的app_main函数被调用
*
*/
void xtell_task_create(void){
#if TCFG_GSENOR_USER_IIC_TYPE
int ret = hw_iic_init(0);
xlog("init iic result:%d\n", ret); //返回0成功
#else
int ret = soft_iic_init(0);
// int num_chars_written = snprintf(log_buffer_1, sizeof(log_buffer_1),"init iic: %d\n", ret);
#endif
// MPU9250_Mag_Init();
//iic总线设备扫描
// extern void i2c_scanner_probe(void);
// i2c_scanner_probe();
xlog("xtell_task_create\n");
circle_buffer_init(&g_ble_send_cb, g_sensor_data_storage, SENSOR_DATA_BUFFER_SIZE, sizeof(ble_send_data_t));
os_sem_create(&receiver_ready_sem, 0);
extern void test_uart_init(void);
test_uart_init();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//test
//
@ -452,7 +454,7 @@ void sensor_test_task(void){
while(1){
WF_GET_Temperature_Pressure(&temperature, &pressure);
xlog("temperature: %.3f,pressure: %.3f\n",temperature,pressure);
os_time_dly(100);
os_time_dly(40);
}
}
@ -469,8 +471,8 @@ void test_func(void){
acc_data_buf[i] = i;
}
SL_SC7U22_Config();
mmc5603nj_init();
// SL_SC7U22_Config();
// mmc5603nj_init();
#if BMP280
BMP280_init();
#else

View File

@ -28,77 +28,16 @@ static int32_t c00, c10;
* @brief 写入单个字节到WF282A寄存器
*/
static void wf282a_write_reg(uint8_t reg, uint8_t data) {
// hw_iic_start(I2C_HANDLE);
// // 发送从设备地址 (写模式)
// if (!hw_iic_tx_byte(I2C_HANDLE, WF_IIC_WRITE_ADDRESS)) {
// // 如果没有收到ACK可能是设备不存在或忙直接停止
// hw_iic_stop(I2C_HANDLE);
// // 可以添加错误日志或返回错误码
// xlog("WF282A Write: No ACK after slave address\n");
// return;
// }
// // 发送寄存器地址
// if (!hw_iic_tx_byte(I2C_HANDLE, reg)) {
// hw_iic_stop(I2C_HANDLE);
// xlog("WF282A Write: No ACK after register address\n");
// return;
// }
// // 发送数据字节
// if (!hw_iic_tx_byte(I2C_HANDLE, data)) {
// hw_iic_stop(I2C_HANDLE);
// xlog("WF282A Write: No ACK after data byte\n");
// return;
// }
// hw_iic_stop(I2C_HANDLE);
gravity_sensor_command(WF_IIC_WRITE_ADDRESS, reg, data);
}
/**
* @brief 从WF282A读取多个字节
*/
static uint32_t wf282a_read_regs(uint8_t reg, uint8_t *buf, uint8_t len) {
// uint32_t bytes_read = 0;
// if (len == 0) return 0;
// hw_iic_start(I2C_HANDLE);
// // 1. 发送从设备地址 (写模式) 和寄存器地址
// if (!hw_iic_tx_byte(I2C_HANDLE, WF_IIC_WRITE_ADDRESS)) {
// hw_iic_stop(I2C_HANDLE);
// xlog("WF282A Read: No ACK after slave address (write phase)\n");
// return 0;
// }
// if (!hw_iic_tx_byte(I2C_HANDLE, reg)) {
// hw_iic_stop(I2C_HANDLE);
// xlog("WF282A Read: No ACK after register address\n");
// return 0;
// }
// // 2. 发送重复开始条件
// hw_iic_start(I2C_HANDLE); // Repeated START
// // 3. 发送从设备地址 (读模式)
// if (!hw_iic_tx_byte(I2C_HANDLE, WF_IIC_READ_ADDRESS)) {
// hw_iic_stop(I2C_HANDLE);
// xlog("WF282A Read: No ACK after slave address (read phase)\n");
// return 0;
// }
// // 4. 循环读取数据
// for (uint32_t i = 0; i < len; i++) {
// // 如果是最后一个字节发送NACK
// // hw_iic_rx_byte 的第二个参数是 ack_enable (1 for ACK, 0 for NACK)
// uint8_t ack_val = (i == (len - 1)) ? 0 : 1; // 最后一个字节NACK其余ACK
// buf[i] = hw_iic_rx_byte(I2C_HANDLE, ack_val);
// bytes_read++;
// }
// hw_iic_stop(I2C_HANDLE);
// return bytes_read;
return _gravity_sensor_get_ndata(WF_IIC_READ_ADDRESS, reg, buf, len);
}
/*==================================================================================*/
/* Delay functions (Copied from manufacturer's code for consistency) */
/*==================================================================================*/
/*==================================================================================*/
@ -194,10 +133,15 @@ uint8_t WF_Init() {
uint8_t calib_buf[18];
xlog("WF282A: soft reset\n");
// 1. 软复位
wf282a_write_reg(WF_RESET_REG, 0x09);
// wf282a_write_reg(WF_RESET_REG, 0x09);//0x0C
delay(1000); // 复位后等待1000ms
// 读取设备id确保设备通信正常
extern uint8_t WF_GetID();
WF_GetID();
// 2. 读取校准系数
if (wf282a_read_regs(COEF_C0, calib_buf, 18) != 18) { // 检查是否成功读取18字节
if (wf282a_read_regs(COEF_C0, calib_buf, 18) != 18) { //0x10, 检查是否成功读取18字节
xlog("Failed to read the calibration coefficient\n");
return 2; // 读取校准数据失败
}
@ -206,33 +150,25 @@ uint8_t WF_Init() {
xlog("Parsed Coefficients: c0=%d, c1=%d, c00=%ld, c10=%ld, c01=%d, c11=%d, c20=%d, c21=%d, c30=%d\n",
c0, c1, c00, c10, c01, c11, c20, c21, c30);
#if 0 //连续测量
// 3. 配置压力、温度和通用寄存器为连续测量模式
// 压力配置: 32Hz测量速率 (PM_RATE_32), 16x过采样 (PM_PRC_16) -> 0x54
wf282a_write_reg(WF_PRS_CFG, (PM_RATE_32 << 4) | PM_PRC_16);
#if 1 //连续测量
// 配置压力、温度和通用寄存器为连续测量模式
wf282a_write_reg(WF_PRS_CFG, (PM_RATE_32 << 4) | PM_PRC_1); //reg: 0x06
// 温度配置: 内部传感器 (TMP_INT_SENSOR), 32Hz测量速率 (TMP_RATE_32), 16x过采样 (TMP_PRC_16) -> 0x54
wf282a_write_reg(WF_TMP_CFG, TMP_INT_SENSOR | (TMP_RATE_32 << 4) | TMP_PRC_16);
// 通用配置寄存器 (保持制造商的0x0C配置)
wf282a_write_reg(WF_CFG_REG, 0x0C);
// 4. 启动连续测量模式 (同时测量压力和温度)
// 0x06: Continuous Pressure and Temperature measurement
wf282a_write_reg(WF_MEAS_CFG, 0x06);
// 首次启动连续测量后,需要等待一个完整的转换周期才能获取有效数据。
// 16x过采样的转换时间约为27.6ms32Hz测量速率下数据每31.25ms更新。
// 所以在此处等待至少32ms确保第一次读取时有有效数据。
wf282a_write_reg(WF_TMP_CFG, TMP_EXT_SENSOR | (TMP_RATE_32 << 4) | TMP_PRC_1); //reg: 0x07
// 启动连续测量模式 (同时测量压力和温度)
wf282a_write_reg(WF_MEAS_CFG, 0x06); //reg: 0x08
//过采样率大于8要对移位置配置1
// wf282a_write_reg(WF_CFG_REG, 0x0C); //reg: 0x09
delay(40); // 稍长一点的延迟,确保传感器开始正常工作
#else
wf282a_write_reg(WF_PRS_CFG, 0x07);
wf282a_write_reg(WF_TMP_CFG, 0x87);
wf282a_write_reg(WF_CFG_REG, 0x0C);
// wf282a_write_reg(WF_MEAS_CFG, 0x07);//后台连续测量温度和压力
wf282a_write_reg(WF_PRS_CFG, (PM_RATE_1 << 4) | PM_PRC_128); //reg: 0x06压力
wf282a_write_reg(WF_TMP_CFG, TMP_EXT_SENSOR | (TMP_RATE_1 << 4) | TMP_PRC_128); //reg: 0x07温度
//过采样率大于8要对移位置配置1
// wf282a_write_reg(WF_CFG_REG, 0x0C); //reg: 0x09
delay(40); // 稍长一点的延迟,确保传感器开始正常工作
#endif
extern uint8_t WF_GetID();
WF_GetID();
return 0; // 成功
}
void WF_Sleep() {
@ -252,40 +188,25 @@ uint8_t WF_GetID() {
xlog("wf get id : %d\n", id);
return id;
}
float WF_Temperature_Calculate() {
float Traw_sc;
int32_t Traw = Get_Traw();
Traw_sc = (float)Traw / KT; // 缩放原始温度值 (KT is now 16x scale factor)
return (float)c0 * 0.5f + (float)c1 * Traw_sc;
}
float WF_Pressure_Calculate() {
float Traw_sc, Praw_sc, Pcomp;
int32_t Traw = Get_Traw();
int32_t Praw = Get_Praw();
Traw_sc = (float)Traw / KT; // 缩放原始温度值 (KT is now 16x scale factor)
Praw_sc = (float)Praw / KP; // 缩放原始压力值 (KP is now 16x scale factor)
// 补偿公式 (与制造商提供的公式一致)
Pcomp = (float)c00
+ Praw_sc * ((float)c10 + Praw_sc * ((float)c20 + Praw_sc * (float)c30))
+ Traw_sc * (float)c01
+ Traw_sc * Praw_sc * ((float)c11 + Praw_sc * (float)c21);
return Pcomp;
}
//非连续测量
void WF_start_measure(void){
wf282a_write_reg(WF_MEAS_CFG, 0x02); //进行一次温度测量
//外部调用
void WF_GET_Temperature_Pressure(float* temperature, float* precessure){
#if 0 //单词测量模式
wf282a_write_reg(WF_MEAS_CFG, 0x02); //内部进行一次温度测量
delay(200);
int32_t Traw = Get_Traw();
wf282a_write_reg(WF_MEAS_CFG, 0x01); //内部进行一次压力测量
delay(200);
}
void WF_GET_Temperature_Pressure(float* temperature, float* precessure){
WF_start_measure();
int32_t Praw = Get_Praw();
#else
int32_t Traw = Get_Traw();
int32_t Praw = Get_Praw();
float Traw_sc = (float)Traw / KT; // 缩放原始温度值 (KT is now 16x scale factor)
float Praw_sc = (float)Praw / KP; // 缩放原始压力值 (KP is now 16x scale factor)
#endif
float Traw_sc = (float)Traw / KT; // 缩放原始温度值
float Praw_sc = (float)Praw / KP; // 缩放原始压力值
*temperature = (float)c0 * 0.5f + (float)c1 * Traw_sc;
*precessure = (float)c00
+ Praw_sc * ((float)c10 + Praw_sc * ((float)c20 + Praw_sc * (float)c30))

View File

@ -9,13 +9,13 @@ Oversampling Rate Scale Factor (kP or kT)
2 times (Low Power) 1572864
4 times 3670016
8 times 7864320
16 times (Standard) 253952 <--- 使用此值
16 times (Standard) 253952
32 times 516096
64 times (High Precision) 1040384
128 times 2088960
*/
#define KT 2088960.0f // 温度 (16x过采样)
#define KP 2088960.0f // 压力 (16x过采样)
#define KT 524288.0f
#define KP 524288.0f
#define WF_PULL_UP 0 //外部是否接的上拉
// I2C 从设备地址
@ -69,7 +69,7 @@ Oversampling Rate Scale Factor (kP or kT)
#define COEF_C30_L 0x21
// --- 配置宏 ---
// 压力配置 (PRS_CFG[6:4]) - 测量速率
// 压力配置 (PRS_CFG[6:4]) - 后台测量速率
#define PM_RATE_1 0x00 // 1 次/秒
#define PM_RATE_2 0x01 // 2 次/秒
#define PM_RATE_4 0x02 // 4 次/秒
@ -91,7 +91,7 @@ Oversampling Rate Scale Factor (kP or kT)
// 温度配置 (TMP_CFG[7]) - 传感器源
#define TMP_EXT_SENSOR 0x80 // 使用外部传感器
#define TMP_INT_SENSOR 0x00 // 使用内部传感器
// 温度配置 (TMP_CFG[6:4]) - 测量速率
// 温度配置 (TMP_CFG[6:4]) - 后台测量速率
#define TMP_RATE_1 0x00 // 1 次/秒
#define TMP_RATE_2 0x01 // 2 次/秒
#define TMP_RATE_4 0x02 // 4 次/秒

Binary file not shown.

Binary file not shown.

View File

@ -10,7 +10,7 @@ copy ..\..\ota.bin .
copy ..\..\anc_coeff.bin .
copy ..\..\anc_gains.bin .
..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin -res ..\..\cfg_tool.bin tone.cfg p11_code.bin ..\..\eq_cfg_hw.bin -uboot_compress -format all -key 646-AC690X-7603.key
..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin -res ..\..\cfg_tool.bin tone.cfg p11_code.bin ..\..\eq_cfg_hw.bin -uboot_compress -format all
@REM..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br34 -boot 0x20000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin ..\..\cfg_tool.bin -res tone.cfg kws_command.bin p11_code.bin -uboot_compress

View File

@ -5388,15 +5388,13 @@ objs/apps/earphone/xtell_Sensor/send_data.c.o
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,os_task_create,l
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,stop_clloct,pl
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,os_task_del,l
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,test_uart_init,pl
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,xtell_task_create,pl
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,hw_iic_init,l
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,circle_buffer_init,l
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,os_sem_create,l
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,test_uart_init,pl
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,sensor_test_task,pl
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,test_func,pl
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,SL_SC7U22_Config,l
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,mmc5603nj_init,l
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,WF_Init,l
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,puts,l
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,foot_init,l
@ -5521,14 +5519,12 @@ objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,WF_GetID,pl
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,WF_Sleep,pl
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,WF_Wakeup,pl
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,WF_Temperature_Calculate,pl
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,WF_Pressure_Calculate,pl
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,WF_start_measure,pl
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,WF_GET_Temperature_Pressure,pl
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,WF_Altitude_Calculate,pl
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,WF_Pressure_Calculate,
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,powf,l
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,gravity_sensor_command,l
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,_gravity_sensor_get_ndata,l
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,gravity_sensor_command,l
cpu/br28/liba/cpu.a.llvm.19376.crc16.c
-r=cpu/br28/liba/cpu.a.llvm.19376.crc16.c,__crc16_mutex_init,pl
-r=cpu/br28/liba/cpu.a.llvm.19376.crc16.c,os_mutex_create,l