16 Commits

Author SHA1 Message Date
lmx
5ecd42b5cf 气压计1s读一次,过采样率128,测量成功 2025-12-10 19:17:54 +08:00
lmx
d92818a894 cun 2025-12-10 16:21:41 +08:00
lmx
3b36715264 cun 2025-12-10 11:11:36 +08:00
lmx
c398dd9eeb cun 2025-12-10 10:23:21 +08:00
lmx
0feb648d11 wf282A读数有问题 2025-12-09 19:28:20 +08:00
lmx
5a72132d2a cun 2025-12-09 17:02:07 +08:00
lmx
2f4e1d7e5b cun 2025-12-09 16:30:25 +08:00
lmx
3f02a9f9be cun 2025-12-09 11:21:08 +08:00
lmx
6ce9deebe6 cun 2025-12-09 11:16:49 +08:00
lmx
96891516b8 cun 2025-12-09 11:10:52 +08:00
lmx
52e4b62b53 cun 2025-12-09 11:04:18 +08:00
lmx
ea610c24d3 串口输出原始数据到上位机验证 2025-12-09 09:59:41 +08:00
lmx
45158aebcf cun 2025-12-05 19:37:31 +08:00
lmx
138275a04b cun 2025-12-05 19:06:54 +08:00
lmx
89f1c93f74 蓝牙发送速率提升 2025-12-04 18:51:38 +08:00
lmx
8c2db49083 iic速率调整到400k 2025-12-02 10:24:01 +08:00
36 changed files with 1329 additions and 1331 deletions

View File

@ -628,6 +628,7 @@ c_SRC_FILES := \
apps/earphone/xtell_Sensor/sensor/MMC56.c \
apps/earphone/xtell_Sensor/sensor/BMP280.c \
apps/earphone/xtell_Sensor/sensor/AK8963.c \
apps/earphone/xtell_Sensor/sensor/WF282A.c \
# 需要编译的 .S 文件

View File

@ -266,7 +266,8 @@ u8 gravity_sensor_command(u8 w_chip_id, u8 register_address, u8 function_command
// xlog("iic_tx_byte id\n");
if (0 == iic_tx_byte(gSensor_info->iic_hdl, w_chip_id)) {
ret = 0;
xlog("\n gsen iic wr err 0\n");
xlog("iic write: I2C NACK on writing ADDR: 0x%X\n", w_chip_id);
// xlog("\n gsen iic wr err 0\n");
strcpy(&w_log_buffer_1, "gsen iic wr err 0\n");
goto __gcend;
}
@ -316,7 +317,7 @@ u8 _gravity_sensor_get_ndata(u8 r_chip_id, u8 register_address, u8 *buf, u8 data
iic_start(gSensor_info->iic_hdl);
if (0 == iic_tx_byte(gSensor_info->iic_hdl, r_chip_id - 1)) {
xlog("I2C NACK on writing ADDR: 0x%X\n", r_chip_id - 1);
xlog("iic read: I2C NACK on writing ADDR: 0x%X\n", r_chip_id - 1);
read_len = 0;
strcpy(&sen_log_buffer_1, "gsen iic rd err 0\n");
goto __gdend;

View File

@ -49,7 +49,7 @@
#include "classic/tws_api.h"
#include "rcsp_adv_user_update.h"
#include "bt_tws.h"
// #include "le_trans_data.h"
#if (TCFG_BLE_DEMO_SELECT == DEF_BLE_DEMO_ADV_RCSP)
#if TCFG_CHARGE_BOX_ENABLE
@ -86,8 +86,10 @@ static const char user_tag_string[] = {EIR_TAG_STRING};
/* #include "debug.h" */
//------
#define ATT_LOCAL_PAYLOAD_SIZE (200) //note: need >= 20
#define ATT_SEND_CBUF_SIZE (512) //note: need >= 20,缓存大小,可修改
// #define ATT_LOCAL_PAYLOAD_SIZE (200*10) //note: need >= 20
// #define ATT_SEND_CBUF_SIZE (1024 * 50) //note: need >= 20,缓存大小,可修改
#define ATT_LOCAL_PAYLOAD_SIZE (517) //note: need >= 20
#define ATT_SEND_CBUF_SIZE (1024 * 2) //note: need >= 20,缓存大小,可修改
#define ATT_RAM_BUFSIZE (ATT_CTRL_BLOCK_SIZE + ATT_LOCAL_PAYLOAD_SIZE + ATT_SEND_CBUF_SIZE) //note:
static u8 att_ram_buffer[ATT_RAM_BUFSIZE] __attribute__((aligned(4)));
//---------------
@ -109,9 +111,10 @@ static const uint8_t sm_min_key_size = 7;
static const uint8_t connection_update_enable = 1; ///0--disable, 1--enable
static uint8_t connection_update_cnt = 0; //
static const struct conn_update_param_t connection_param_table[] = {
{16, 24, 16, 600},
{12, 28, 14, 600},//11
{8, 20, 20, 600},//3.7
{6, 12, 0, 400},//3.7
// {16, 24, 16, 600},
// {12, 28, 14, 600},//11
// {8, 20, 20, 600},//3.7
/* {12, 28, 4, 600},//3.7 */
/* {12, 24, 30, 600},//3.05 */
};
@ -299,6 +302,17 @@ void test_data_send_packet(void)
static void can_send_now_wakeup(void)
{
// static signed char acc_data_buf[60] = {
// 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22
// };
// extern void send_data_to_ble_client(const u8* data, u16 length);
// send_data_to_ble_client(&acc_data_buf, 60);
putchar('E');
if (ble_resume_send_wakeup) {
ble_resume_send_wakeup();
@ -315,6 +329,24 @@ u8 ble_update_get_ready_jump_flag(void)
return 0;
}
// 添加到 le_rcsp_adv_module.c
static void set_connection_data_length(u16 tx_octets, u16 tx_time) //xtell
{
if (con_handle) {
ble_user_cmd_prepare(BLE_CMD_SET_DATA_LENGTH, 3, con_handle, tx_octets, tx_time);
}
}
static void set_connection_data_phy(u8 tx_phy, u8 rx_phy)//xtell
{
if (0 == con_handle) {
return;
}
u8 all_phys = 0;
u16 phy_options = 0; // 根据你的 SDK 定义调整
ble_user_cmd_prepare(BLE_CMD_SET_PHY, 5, con_handle, all_phys, tx_phy, rx_phy, phy_options);
}
/*
* @section Packet Handler
*
@ -370,6 +402,16 @@ static void cbk_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p
connection_update_complete_success(packet);
break;
}
case HCI_SUBEVENT_LE_DATA_LENGTH_CHANGE: //xtell
log_info("APP HCI_SUBEVENT_LE_DATA_LENGTH_CHANGE\n");
set_connection_data_phy(2, 2); // 2 表示 2M PHY
break;
case HCI_SUBEVENT_LE_PHY_UPDATE_COMPLETE://xtell
log_info("APP HCI_SUBEVENT_LE_PHY_UPDATE %s\n", packet[4] ? "Fail" : "Succ"); // packet[4] 是 status
log_info("Tx PHY: %d\n", packet[5]); // packet[5] 是 TX_PHY
log_info("Rx PHY: %d\n", packet[6]); // packet[6] 是 RX_PHY
break;
break;
case HCI_EVENT_DISCONNECTION_COMPLETE:
@ -410,6 +452,7 @@ static void cbk_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p
mtu = att_event_mtu_exchange_complete_get_MTU(packet) - 3;
log_info("ATT MTU = %u\n", mtu);
ble_user_cmd_prepare(BLE_CMD_ATT_MTU_SIZE, 1, mtu);
set_connection_data_length(251, 2120);//xtell
break;
case HCI_EVENT_VENDOR_REMOTE_TEST:
@ -571,6 +614,7 @@ static int app_send_user_data(u16 handle, u8 *data, u16 len, u8 handle_type)
ret = ble_user_cmd_prepare(BLE_CMD_ATT_SEND_DATA, 4, handle, data, len, handle_type);
if (ret == BLE_BUFFER_FULL) {
printf("app_send_user_data: buffer full\n");
ret = APP_BLE_BUFF_FULL;
}
@ -1663,12 +1707,8 @@ void send_version_to_sibling(void)
data[2] = ver >> 8;
tws_api_send_data_to_sibling(data, sizeof(data), TWS_FUNC_ID_SEQ_RAND_SYNC);
}
#endif
///////////////////////////////////////////////////////////////////////////////////////////////////////
void send_data_to_ble_client(const u8* data, u16 length)
{
// 检查数据长度是否有效
@ -1677,8 +1717,8 @@ void send_data_to_ble_client(const u8* data, u16 length)
return;
}
// 检查缓冲区空间
if (app_send_user_data_check(length)) {
// // 检查缓冲区空间
// if (app_send_user_data_check(length)) {
// 发送数据
int ret = app_send_user_data(ATT_CHARACTERISTIC_ae02_01_VALUE_HANDLE, data, length, ATT_OP_NOTIFY);
if (ret == 0) { // 假设 0 表示成功
@ -1686,7 +1726,12 @@ void send_data_to_ble_client(const u8* data, u16 length)
} else {
// printf("Failed to send data: Length %d, Error code: %d\n", length, ret);
}
} else {
// printf("Insufficient buffer space to send data: Length %d\n", length);
}
}
// } else {
// printf("Insufficient buffer space to send data: Length %d\n", length);
// }
}
#endif

View File

@ -81,9 +81,9 @@ extern void printf_buf(u8 *buf, u32 len);
//------
//ATT发送的包长, note: 20 <=need >= MTU
#define ATT_LOCAL_MTU_SIZE (200) //
#define ATT_LOCAL_MTU_SIZE (517) //200
//ATT缓存的buffer大小, note: need >= 20,可修改
#define ATT_SEND_CBUF_SIZE (512) //
#define ATT_SEND_CBUF_SIZE (512 * 20) //
//共配置的RAM
#define ATT_RAM_BUFSIZE (ATT_CTRL_BLOCK_SIZE + ATT_LOCAL_MTU_SIZE + ATT_SEND_CBUF_SIZE) //note:
@ -125,9 +125,10 @@ static uint8_t connection_update_cnt = 0; //
//参数表
static const struct conn_update_param_t connection_param_table[] = {
{16, 24, 10, 600},//11
{12, 28, 10, 600},//3.7
{8, 20, 10, 600},
{6, 12, 0, 400},//11
// {16, 24, 10, 600},//11
// {12, 28, 10, 600},//3.7
// {8, 20, 10, 600},
/* {12, 28, 4, 600},//3.7 */
/* {12, 24, 30, 600},//3.05 */
};
@ -706,6 +707,8 @@ static int att_write_callback(hci_con_handle_t connection_handle, uint16_t att_h
u16 handle = att_handle;
log_info("write_callback, handle= 0x%04x,size = %d\n", handle, buffer_size);
extern void le_user_app_event(u8* buffer);
le_user_app_event(buffer);
switch (handle) {
@ -1389,6 +1392,44 @@ void hangup_ans_call_handle(u8 en)
}
#endif
void send_data_to_ble_client(const u8* data, u16 length)
{
// 检查数据长度是否有效
if (length == 0 || length > 512) {
printf("Error: Data length %d is out of range (1-512)\n", length);
return;
}
// // 检查缓冲区空间
// if (app_send_user_data_check(length)) {
// 发送数据
int ret = app_send_user_data(ATT_CHARACTERISTIC_ae02_01_VALUE_HANDLE, data, length, ATT_OP_NOTIFY);
if (ret == 0) { // 假设 0 表示成功
// printf("Data sent successfully: Length %d\n", length);
} else {
printf("Failed to send data: Length %d, Error code: %d\n", length, ret);
}
// } else {
// printf("Insufficient buffer space to send data: Length %d\n", length);
// }
}
void rcsp_adv_fill_mac_addr(u8 *mac_addr_buf)
{
#if (MUTIl_CHARGING_BOX_EN)
u8 *mac_addr = get_chargebox_adv_addr();
if (mac_addr) {
swapX(mac_addr, mac_addr_buf, 6);
}
/* printf("mac_addr:"); */
/* printf_buf(mac_addr_buf, 6); */
#else
swapX(bt_get_mac_addr(), mac_addr_buf, 6);
#endif
}
#endif

View File

@ -37,7 +37,7 @@ extern void printf_buf(u8 *buf, u32 len);
//------
//ATT发送的包长, note: 20 <=need >= MTU
#define ATT_LOCAL_MTU_SIZE (517) //
//ATT缓存的buffer大小, note: need >= 20,可修改
//ATT缓存的buffer大小, +: need >= 20,可修改
#if(APP_MAIN == APP_WIRELESS_MIC_2T1)
#define ATT_SEND_CBUF_SIZE (90)
#else
@ -92,7 +92,8 @@ static uint8_t connection_update_cnt = 0; //
//参数表
static const struct conn_update_param_t connection_param_table[] = {
{WIRELESS_BLE_CONNECT_INTERVAL, WIRELESS_BLE_CONNECT_INTERVAL, 0, 100},//11
// {1, 5, 4, 600},//11
{12, 24, 0, 400}, // 建议修改为此值 (15ms - 30ms interval)
};
//共可用的参数组数
@ -421,7 +422,7 @@ static void cbk_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p
case HCI_SUBEVENT_LE_DATA_LENGTH_CHANGE:
log_info("APP HCI_SUBEVENT_LE_DATA_LENGTH_CHANGE\n");
set_connection_data_phy(CONN_SET_2M_PHY, CONN_SET_2M_PHY);
// set_connection_data_phy(CONN_SET_2M_PHY, CONN_SET_2M_PHY);
break;
case HCI_SUBEVENT_LE_PHY_UPDATE_COMPLETE:
@ -453,7 +454,7 @@ static void cbk_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p
mtu = att_event_mtu_exchange_complete_get_MTU(packet) - 3;
log_info("ATT MTU = %u\n", mtu);
ble_op_att_set_send_mtu(mtu);
set_connection_data_length(251, 2120);
// set_connection_data_length(251, 2120);
break;
case HCI_EVENT_VENDOR_REMOTE_TEST:
@ -1067,6 +1068,44 @@ void ble_server_send_test_key_num(u8 key_num)
;
}
void send_data_to_ble_client(const u8* data, u16 length)
{
// 检查数据长度是否有效
if (length == 0 || length > 512) {
printf("Error: Data length %d is out of range (1-512)\n", length);
return;
}
// // 检查缓冲区空间
// if (app_send_user_data_check(length)) {
// 发送数据
int ret = app_send_user_data(ATT_CHARACTERISTIC_ae02_01_VALUE_HANDLE, data, length, ATT_OP_NOTIFY);
if (ret == 0) { // 假设 0 表示成功
printf("Data sent successfully: Length %d\n", length);
} else {
printf("Failed to send data: Length %d, Error code: %d\n", length, ret);
}
// } else {
// printf("Insufficient buffer space to send data: Length %d\n", length);
// }
}
void rcsp_adv_fill_mac_addr(u8 *mac_addr_buf)
{
#if (MUTIl_CHARGING_BOX_EN)
u8 *mac_addr = get_chargebox_adv_addr();
if (mac_addr) {
swapX(mac_addr, mac_addr_buf, 6);
}
/* printf("mac_addr:"); */
/* printf_buf(mac_addr_buf, 6); */
#else
swapX(bt_get_mac_addr(), mac_addr_buf, 6);
#endif
}
#endif

View File

@ -717,7 +717,7 @@ struct port_wakeup port0 = {
.pullup_down_enable = ENABLE, //配置I/O 内部上下拉是否使能
.edge = FALLING_EDGE, //唤醒方式选择,可选:上升沿\下降沿
.filter = PORT_FLT_8ms,
.iomap = IO_PORTB_01, //唤醒口选择
.iomap = IO_PORTA_04, //唤醒口选择
};
#if (TCFG_TEST_BOX_ENABLE || TCFG_CHARGESTORE_ENABLE || TCFG_ANC_BOX_ENABLE || TCFG_UMIDIGI_BOX_ENABLE)

View File

@ -23,17 +23,17 @@
//*********************************************************************************//
#define TCFG_UART0_ENABLE ENABLE_THIS_MOUDLE //串口打印模块使能
// #define TCFG_UART0_ENABLE 0 //串口打印模块使能
#define TCFG_UART0_RX_PORT NO_CONFIG_PORT //串口接收脚配置用于打印可以选择NO_CONFIG_PORT
#define TCFG_UART0_RX_PORT IO_PORT_DM//NO_CONFIG_PORT //串口接收脚配置用于打印可以选择NO_CONFIG_PORT
#define TCFG_UART0_TX_PORT IO_PORT_DP //串口发送脚配置
// #define TCFG_UART0_BAUDRATE 1000000 //串口波特率配置
#define TCFG_UART0_BAUDRATE 115200 //串口波特率配置
#define TCFG_UART0_BAUDRATE 1000000 //串口波特率配置
// #define TCFG_UART0_BAUDRATE 115200 //串口波特率配置
//*********************************************************************************//
// 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
@ -47,7 +47,7 @@
*/
#define TCFG_HW_I2C0_PORTS 'B'
#define TCFG_HW_I2C0_CLK 1000000 //硬件IIC波特率:100k
#define TCFG_HW_I2C0_CLK 400000 //硬件IIC波特率:400k
//*********************************************************************************//
// 硬件SPI 配置 //
@ -791,7 +791,7 @@ DAC硬件上的连接方式,可选的配置:
//*********************************************************************************//
#define TCFG_LOWPOWER_POWER_SEL PWR_DCDC15 //电源模式设置可选DCDC和LDO
#define TCFG_LOWPOWER_BTOSC_DISABLE 0 //低功耗模式下BTOSC是否保持
#define TCFG_LOWPOWER_LOWPOWER_SEL 1 //低功耗使能,蓝牙&&系统空闲可进入低功耗
#define TCFG_LOWPOWER_LOWPOWER_SEL 0 //低功耗使能,蓝牙&&系统空闲可进入低功耗
#define TCFG_LOWPOWER_VDDIOM_LEVEL VDDIOM_VOL_30V //vddiom等级
#define TCFG_LOWPOWER_OSC_TYPE OSC_TYPE_LRC //低功耗晶振类型btosc/lrc
#if (TCFG_AUDIO_ASR_DEVELOP && TCFG_CVP_DEVELOP_ENABLE)
@ -1130,7 +1130,7 @@ DAC硬件上的连接方式,可选的配置:
//*********************************************************************************//
#if TCFG_USER_BLE_ENABLE
#define DUEROS_DMA_EN 0
#define TRANS_DATA_EN 0//1 //xtellota
// #define TRANS_DATA_EN 0//1 //xtellota
#define BLE_HID_EN 0
#if (DUEROS_DMA_EN)

View File

@ -13,7 +13,7 @@
#define CONFIG_UPDATE_JUMP_TO_MASK 0 //配置升级到loader的方式0为直接reset,1为跳转(适用于芯片电源由IO口KEEP住的方案,需要注意检查跳转前是否将使用DMA的硬件模块全部关闭)
#define CONFIG_IO_KEY_EN 0 //配置是否使用IO按键配合RESET1
#define CONFIG_IO_KEY_EN 1 //配置是否使用IO按键配合RESET1
#define CONFIG_UPDATE_WITH_MD5_CHECK_EN 0 //配置升级是否支持MD5校验
#define CONFIG_ANC_ENABLE 0 //配置是否支持ANC
@ -73,8 +73,8 @@
#if CONFIG_IO_KEY_EN
#define CONFIG_SUPPORT_RESET1
#define CONFIG_RESET1_PIN PB01 //io pin
#define CONFIG_RESET1_TIME 08 //unit:second
#define CONFIG_RESET1_PIN PA04 //io pin
#define CONFIG_RESET1_TIME 01 //unit:second
#define CONFIG_RESET1_LEVEL 0 //tigger level(0/1)
#endif

View File

@ -21,9 +21,10 @@
#define CONFIG_APP_BT_ENABLE
#ifdef CONFIG_APP_BT_ENABLE
#define TRANS_DATA_EN 0
#define BLE_WIRELESS_SERVER_EN 0
#define TRANS_DATA_EN 1
#define RCSP_BTMATE_EN 0
#define RCSP_ADV_EN 1
#define RCSP_ADV_EN 0
#define AI_APP_PROTOCOL 0
#define LL_SYNC_EN 0
#define TUYA_DEMO_EN 0

View File

@ -204,6 +204,18 @@ int app_protocol_sys_event_handler(struct sys_event *event);
#define EARPHONE_STATE_SNIFF(a)
#define EARPHONE_STATE_ROLE_SWITCH(a)
#elif BLE_WIRELESS_SERVER_EN
#define EARPHONE_STATE_INIT() do { } while(0)
#define EARPHONE_STATE_SET_PAGE_SCAN_ENABLE() do { } while(0)
#define EARPHONE_STATE_GET_CONNECT_MAC_ADDR() do { } while(0)
#define EARPHONE_STATE_CANCEL_PAGE_SCAN() do { } while(0)
#define EARPHONE_STATE_ENTER_SOFT_POWEROFF() do { } while(0)
#define EARPHONE_STATE_TWS_INIT(a) do { } while(0)
#define EARPHONE_STATE_TWS_CONNECTED(a, b) do { } while(0)
#define SYS_EVENT_HANDLER_SPECIFIC(a) do { } while(0)
#define SYS_EVENT_REMAP(a) 0
#define EARPHONE_STATE_SNIFF(a)
#define EARPHONE_STATE_ROLE_SWITCH(a)
#else
int adv_earphone_state_init();
int adv_earphone_state_set_page_scan_enable();

View File

@ -232,7 +232,8 @@ const uint64_t config_btctler_le_features = LE_ENCRYPTION;
#else
const int config_btctler_le_roles = (LE_ADV | LE_SLAVE);
const uint64_t config_btctler_le_features = 0;
// const uint64_t config_btctler_le_features = 0;
const uint64_t config_btctler_le_features = LE_ENCRYPTION | LE_DATA_PACKET_LENGTH_EXTENSION | LE_2M_PHY;
#endif
#else
const int config_btctler_le_roles = 0;
@ -280,9 +281,13 @@ const int config_btctler_le_acl_total_nums = 1;
const int config_btctler_le_afh_en = 0;
const u32 config_vendor_le_bb = 0;
const int config_btctler_le_rx_nums = 5;
const int config_btctler_le_acl_packet_length = 27;
const int config_btctler_le_acl_total_nums = 5;
// const int config_btctler_le_rx_nums = 5;
// const int config_btctler_le_acl_packet_length = 27;
// const int config_btctler_le_acl_total_nums = 5;
const int config_btctler_le_rx_nums = 8;
const int config_btctler_le_acl_packet_length = 251;
const int config_btctler_le_acl_total_nums = 8;
#endif
/*-----------------------------------------------------------*/

View File

@ -9,11 +9,19 @@ void circle_buffer_init(circle_buffer_t *cb, void *buffer, u16 capacity, u16 ele
cb->head = 0;
cb->tail = 0;
cb->size = 0;
os_mutex_create(&cb->mutex);
}
// 销毁环形缓冲区
void circle_buffer_deinit(circle_buffer_t *cb) {
os_mutex_del(&cb->mutex, 0);
}
// 向环形缓冲区写入一个元素
bool circle_buffer_write(circle_buffer_t *cb, const void *element) {
os_mutex_pend(&cb->mutex, 0);
if (circle_buffer_is_full(cb)) {
os_mutex_post(&cb->mutex);
return false; // 缓冲区已满
}
@ -22,12 +30,15 @@ bool circle_buffer_write(circle_buffer_t *cb, const void *element) {
cb->head = (cb->head + 1) % cb->capacity;
cb->size++;
os_mutex_post(&cb->mutex);
return true;
}
// 从环形缓冲区读取一个元素
bool circle_buffer_read(circle_buffer_t *cb, void *element) {
os_mutex_pend(&cb->mutex, 0);
if (circle_buffer_is_empty(cb)) {
os_mutex_post(&cb->mutex);
return false; // 缓冲区为空
}
@ -36,25 +47,38 @@ bool circle_buffer_read(circle_buffer_t *cb, void *element) {
cb->tail = (cb->tail + 1) % cb->capacity;
cb->size--;
os_mutex_post(&cb->mutex);
return true;
}
// 获取已用空间的大小(以元素为单位)
u16 circle_buffer_get_size(circle_buffer_t *cb) {
return cb->size;
os_mutex_pend(&cb->mutex, 0);
u16 size = cb->size;
os_mutex_post(&cb->mutex);
return size;
}
// 获取剩余空间的大小(以元素为单位)
u16 circle_buffer_get_free_space(circle_buffer_t *cb) {
return cb->capacity - cb->size;
os_mutex_pend(&cb->mutex, 0);
u16 free_space = cb->capacity - cb->size;
os_mutex_post(&cb->mutex);
return free_space;
}
// 检查缓冲区是否已满
bool circle_buffer_is_full(circle_buffer_t *cb) {
return cb->size == cb->capacity;
os_mutex_pend(&cb->mutex, 0);
bool is_full = (cb->size == cb->capacity);
os_mutex_post(&cb->mutex);
return is_full;
}
// 检查缓冲区是否为空
bool circle_buffer_is_empty(circle_buffer_t *cb) {
return cb->size == 0;
os_mutex_pend(&cb->mutex, 0);
bool is_empty = (cb->size == 0);
os_mutex_post(&cb->mutex);
return is_empty;
}

View File

@ -2,6 +2,7 @@
#define CIRCLE_BUFFER_H
#include "system/includes.h"
#include "os/os_api.h"
// 定义环形缓冲区的结构体
typedef struct {
@ -11,6 +12,7 @@ typedef struct {
u16 head; // 头部指针(写入位置,以元素为单位)
u16 tail; // 尾部指针(读取位置,以元素为单位)
u16 size; // 当前已用大小(以元素为单位)
OS_MUTEX mutex; // 用于保护缓冲区的互斥锁
} circle_buffer_t;
/**
@ -22,6 +24,12 @@ typedef struct {
*/
void circle_buffer_init(circle_buffer_t *cb, void *buffer, u16 capacity, u16 element_size);
/**
* @brief 销毁环形缓冲区,释放相关资源
* @param cb 指向环形缓冲区结构体的指针
*/
void circle_buffer_deinit(circle_buffer_t *cb);
/**
* @brief 向环形缓冲区写入一个元素
* @param cb 指向环形缓冲区结构体的指针

View File

@ -26,9 +26,11 @@
#include "./sensor/MMC56.h"
#include "./sensor/BMP280.h"
#include "./sensor/AK8963.h"
#include "./sensor/WF282A.h"
#include "asm/rtc.h"
#include "system/timer.h"
#include "adv_time_stamp_setting.h"
#include "btstack/le/le_user.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
//宏定义
#define ENABLE_XLOG 1
@ -41,7 +43,10 @@
#define xlog(format, ...) ((void)0)
#endif
#define SENSOR_DATA_BUFFER_SIZE 1000 // 定义缓冲区可以存储XXX个sensor_data_t元素
#define SENSOR_DATA_BUFFER_SIZE 200 // 定义缓冲区可以存储XXX个sensor_data_t元素
#define MPU_FIFO_INTERVAL 4 //隔多久读取六轴fifo单位10ms
#define MPU_FIFO_LEN 16 //(MPU_FIFO_INTERVAL*10/2.5) //400hz采用频率那每40ms的时间fifo就有16组六轴数据
//
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -51,7 +56,6 @@
void send_data_to_ble_client(const u8* data, u16 length);
extern void create_process(u16* pid, const char* name, void *priv, void (*func)(void *priv), u32 msec);
extern void close_process(u16* pid,char* name);
void start_collect_fuc(void);
void BLE_send_fuc(void);
//END -- 函数定义
//////////////////////////////////////////////////////////////////////////////////////////////////
@ -61,35 +65,31 @@ void BLE_send_fuc(void);
//START -- 变量定义
static u32 timer_offset_ms = 0;
typedef struct {
// -- 六轴 --
signed short SC7U22_data[6];
// -- 磁力计 --
uint8_t mmc5603nj_buffer[9];
// -- 速度 --
uint16_t speed_cms;
// -- 气压计 --
int16_t temperature;
uint32_t pressure;
// -- 左/右腿 --
uint8_t foot_state; //1左脚2右脚
// -- 时间 --
u32 timestamp_ms;
typedef struct{
signed short SC7U22_data[6]; //12字节
int mmc5603nj_buffer[3]; //12字节
int16_t temperature; //2
uint32_t pressure; //4
}sensor_package_t __attribute__((packed));
} BLE_send_data_t;
static int count = 0;
typedef struct{
uint8_t checkout_1;
uint8_t checkout_2;
uint8_t foot; //1左脚2右脚
uint8_t package_index;
sensor_package_t sensor_package[MPU_FIFO_LEN];//一次蓝牙发送MPU_FIFO_LEN组传感器数据
}ble_send_data_t; //一次蓝牙发送的数据内容
// --- 环形缓冲区 ---
static circle_buffer_t BLE_send_buff; // 环形缓冲区管理结构体
BLE_send_data_t BLE_send_data[SENSOR_DATA_BUFFER_SIZE];
static circle_buffer_t g_ble_send_cb; // 环形缓冲区管理结构体
static ble_send_data_t g_sensor_data_storage[SENSOR_DATA_BUFFER_SIZE]; //缓冲区
// -- 任务id --
u16 SC7U22_calibration_id;
u16 start_collect_fuc_id;
u16 BLE_send_fuc_id;
static u8 stop_ble_send_fuc_id;
extern u8 foot_init;
static OS_SEM receiver_ready_sem; // 用于启动同步的信号量
static const uart_bus_t *uart_bus = NULL;
static u16 test_id = 0;
//END -- 变量定义
//////////////////////////////////////////////////////////////////////////////////////////////////
@ -105,110 +105,181 @@ u32 get_ms_timer(void) {
return sys_timer_get_ms() - timer_offset_ms;
}
// ----------------------------------------------------------------------------------------------------------------
// --------------------------------------------定时器回调函数----------------------------------------------------------
/**
* @brief 六轴静态校准
*
*/
void SC7U22_static_calibration(void){
signed short acc_data_buf[3];
signed short gyr_data_buf[3];
float angle[3];
float quaternion_output[3];
static signed short combined_raw_data[6];
static int calibration_done = 0;
char status = 0;
static first_set_flag = 0;
if(first_set_flag == 0){
first_set_flag = 1;
set_SC7U22_Error_Flag(0);
}
SL_SC7U22_RawData_Read(acc_data_buf,gyr_data_buf);
memcpy(&combined_raw_data[0], acc_data_buf, 3 * sizeof(signed short));
memcpy(&combined_raw_data[3], gyr_data_buf, 3 * sizeof(signed short));
status = Q_SL_SC7U22_Angle_Output(1, combined_raw_data, angle,NULL, 0, quaternion_output);
if(status == 1){ //校准完成
extern u16 SC7U22_calibration_id;
extern u8 SC7U22_init;
first_set_flag = 0;
SC7U22_init = 0x11;
close_process(&SC7U22_calibration_id, "SC7U22_calibration");
u8 send2_1[5] = {0xBB,0xBE,0x02,0x00,0x00};
send2_1[4] = SC7U22_init;
send_data_to_ble_client(&send2_1,5);
}
if(count > 100){
count = 0;
char log_buffer[100];
// snprintf( log_buffer, sizeof(log_buffer),"status:%d\n",status);
// send_data_to_ble_client(&log_buffer,strlen(log_buffer));
xlog("status:%d\n", status);
xlog("RawData:AX=%d,AY=%d,AZ=%d,GX=%d,GY=%d,GZ=%d\r\n",combined_raw_data[0],combined_raw_data[1],combined_raw_data[2],combined_raw_data[3],combined_raw_data[4],combined_raw_data[5]);
uint8_t send[5] = {0xBB, 0xBE, 0x02, 0x00, 0x12};
send_data_to_ble_client(&send,5); //正在校验中
}
count++;
}
/**
* @brief 开始采集传感器数据和计算速度
* @brief 传感器采集任务
*
*/
void start_collect_fuc(void){
// xlog("=======sensor_read_data START\n");
static signed short combined_raw_data[6];
static int initialized = 0;
static int calibration_done = 0;
char status = 0;
BLE_send_data_t BLE_send_data_tmp;
uint8_t mmc5603nj_buffer[9];
signed short acc_data_buf[3];
signed short gyr_data_buf[3];
float angle[3];
float quaternion_output[3];
void sensor_collect_task(void){
static ble_send_data_t send_data;
mmc5603nj_mag_data_t mmc5603nj_buffer;
float temperature = 0;
float pressure = 0;
int interval = 0;
signed short accx_buf[100];
signed short accy_buf[100];
signed short accz_buf[100];
signed short gyrx_buf[100];
signed short gyry_buf[100];
signed short gyrz_buf[100];
int fifo_num = 0;
static int SL_data_index = 0;
u8 package_index = 1;
int tmp_index = 0;
// -- 读数据 --
SL_SC7U22_RawData_Read(acc_data_buf,gyr_data_buf);
mmc5603nj_read_origin_data(mmc5603nj_buffer);
// bmp280_read_originanl_data(&BLE_send_data_tmp.adc_P, &BLE_send_data_tmp.adc_T);
bmp280_read_data(&temperature, &pressure);
while(1){//4组地磁数据、16组六轴数据、1组气压计数据
interval++;
mmc5603nj_read_mag_data(&mmc5603nj_buffer); //地磁的采样率为100Hz每10ms读一次
for(int i = (interval-1)*4; i < interval*4; i++){
send_data.sensor_package[i].mmc5603nj_buffer[0] = (int32_t)(mmc5603nj_buffer.x * 1000.0f);
send_data.sensor_package[i].mmc5603nj_buffer[1] = (int32_t)(mmc5603nj_buffer.y * 1000.0f);
send_data.sensor_package[i].mmc5603nj_buffer[2] = (int32_t)(mmc5603nj_buffer.z * 1000.0f);
}
// xlog("MAG x: %.2f,y: %.2f,z: %.2f\n",mmc5603nj_buffer.x,mmc5603nj_buffer.y,mmc5603nj_buffer.z);
memcpy(&combined_raw_data[0], acc_data_buf, 3 * sizeof(signed short));
memcpy(&combined_raw_data[3], gyr_data_buf, 3 * sizeof(signed short));
SL_SC7U22_FIFO_Read(accx_buf,accy_buf,accz_buf,gyrx_buf,gyry_buf,gyrz_buf); //一次性读取内置fifo的数据
for(int i = 0; i < MPU_FIFO_LEN/4; i++){
tmp_index = SL_data_index + i;
// if(tmp_index >= MPU_FIFO_LEN-1) tmp_index = MPU_FIFO_LEN-1;
send_data.sensor_package[tmp_index].SC7U22_data[0] = accx_buf[i]; //acc_x
send_data.sensor_package[tmp_index].SC7U22_data[1] = accy_buf[i]; //acc_y
send_data.sensor_package[tmp_index].SC7U22_data[2] = accz_buf[i]; //acc_z
send_data.sensor_package[tmp_index].SC7U22_data[3] = gyrx_buf[i]; //gyr_x
send_data.sensor_package[tmp_index].SC7U22_data[4] = gyry_buf[i]; //gyr_y
send_data.sensor_package[tmp_index].SC7U22_data[5] = gyrz_buf[i]; //gyr_z
// -- 四元数 --
status = Q_SL_SC7U22_Angle_Output(0, combined_raw_data, angle,NULL, 0, quaternion_output);
// xlog(" Acc_x : %4d, Acc_y : %4d, Acc_z : %4d,\r\n", send_data.sensor_package[tmp_index].SC7U22_data[0], send_data.sensor_package[tmp_index].SC7U22_data[1], send_data.sensor_package[tmp_index].SC7U22_data[2]);
#if 0
float acc_g[3];
float gyr_dps[3];
acc_g[0] = (float)send_data.sensor_package[tmp_index].SC7U22_data[0] / 2048.0f;
acc_g[1] = (float)send_data.sensor_package[tmp_index].SC7U22_data[1] / 2048.0f;
acc_g[2] = (float)send_data.sensor_package[tmp_index].SC7U22_data[2] / 2048.0f;
gyr_dps[0] = (float)send_data.sensor_package[tmp_index].SC7U22_data[3] * 0.061f;
gyr_dps[1] = (float)send_data.sensor_package[tmp_index].SC7U22_data[4] * 0.061f;
gyr_dps[2] = (float)send_data.sensor_package[tmp_index].SC7U22_data[5] * 0.061f;
printf(" ACC(g): x=%.3f, y=%.3f, z=%.3f\n", acc_g[0], acc_g[1], acc_g[2]);
printf(" GYR(dps):x=%.3f, y=%.3f, z=%.3f\n", gyr_dps[0], gyr_dps[1], gyr_dps[2]);
#endif
}
SL_data_index += MPU_FIFO_LEN/4;
// -- 速度计算 --
memcpy(acc_data_buf, &combined_raw_data[0], 3 * sizeof(signed short));
memcpy(gyr_data_buf, &combined_raw_data[3], 3 * sizeof(signed short));
uint16_t speed = sensor_processing_task(acc_data_buf,gyr_data_buf,angle, quaternion_output);
// -- 数据包装进结构体 --
memcpy(&BLE_send_data_tmp.SC7U22_data[0], acc_data_buf, 3 * sizeof(signed short));
memcpy(&BLE_send_data_tmp.SC7U22_data[3], gyr_data_buf, 3 * sizeof(signed short));
memcpy(BLE_send_data_tmp.mmc5603nj_buffer, mmc5603nj_buffer, 9);
BLE_send_data_tmp.temperature = (int16_t)(temperature * 1000.0f);
BLE_send_data_tmp.pressure = (int32_t)(pressure * 1000.0f);
BLE_send_data_tmp.speed_cms = speed;
extern u8 foot_init;
BLE_send_data_tmp.foot_state = foot_init;
BLE_send_data_tmp.timestamp_ms = get_ms_timer();
// -- 放进缓冲区 --
if(circle_buffer_is_full(&BLE_send_buff) == 0){
circle_buffer_write(&BLE_send_buff, &BLE_send_data_tmp);
if(interval >= 4){ //40ms
interval = 0;
SL_data_index = 0;
#if BMP280
bmp280_read_data(&temperature, &pressure);//每40ms读取一次高精度的采样率为26.5Hz
#else
WF_GET_Temperature_Pressure(&temperature, &pressure);
#endif
for(int i = 0;i<MPU_FIFO_LEN;i++){
send_data.sensor_package[i].temperature = (int16_t)(temperature * 1000.0f);
send_data.sensor_package[i].pressure = (int32_t)(pressure * 1000.0f);
}
// xlog("temperature: %.2f,pressure: %.2f\n",temperature,pressure);
// xlog("fifo_num:%d\n",fifo_num);
send_data.checkout_1 = 0xBE;
send_data.checkout_2 = 0xBB;
send_data.foot = foot_init;
send_data.package_index = package_index;
circle_buffer_write(&g_ble_send_cb, &send_data);
os_sem_post(&receiver_ready_sem); //通知另一个发送任务
memset(&send_data, 0, sizeof(ble_send_data_t));
memset(&accx_buf, 0, sizeof(accx_buf));
memset(&accy_buf, 0, sizeof(accy_buf));
memset(&accz_buf, 0, sizeof(accz_buf));
memset(&gyrx_buf, 0, sizeof(gyrx_buf));
memset(&gyry_buf, 0, sizeof(gyry_buf));
memset(&gyrz_buf, 0, sizeof(gyrz_buf));
package_index++;
if(package_index >= 0xFF) package_index = 1;
// xlog("=====================%d============================\n",get_ms_timer());
}
os_time_dly(1); //10ms为单位
}
// xlog("=======sensor_read_data END\n");
}
void data_log(uint8_t* data){
static u8 imu_airplane[MPU_FIFO_LEN][12];
// 检查数据包头部
if (data[0] != 0xBE || data[1] != 0xBB) {
printf("Error: Invalid data packet header.\n");
return;
}
//左右脚
uint8_t package_foot = data[2];
// 解析包索引
uint8_t package_index = data[3];
printf("--- Parsing Data Packet Index: %d ---\n", package_index);
uint8_t* p = &data[4]; // 指向数据负载的起始位置
// 循环解析16组数据
for (int i = 0; i < MPU_FIFO_LEN; i++) {
// 1. 解析六轴传感器数据 (12 bytes)
int16_t imu_raw[6];
for (int j = 0; j < 6; j++) {
imu_airplane[i][2*j] = p[0];
imu_airplane[i][2*j+1] = p[1];
// 小端模式: 低字节在前, 高字节在后
imu_raw[j] = (int16_t)(((uint16_t)p[1] << 8) | (uint16_t)p[0]);
p += 2;
}
float acc_g[3];
float gyr_dps[3];
acc_g[0] = (float)imu_raw[0] / 2048.0f;
acc_g[1] = (float)imu_raw[1] / 2048.0f;
acc_g[2] = (float)imu_raw[2] / 2048.0f;
gyr_dps[0] = (float)imu_raw[3] * 0.061f;
gyr_dps[1] = (float)imu_raw[4] * 0.061f;
gyr_dps[2] = (float)imu_raw[5] * 0.061f;
// 2. 解析地磁传感器数据 (12 bytes)
int32_t mag_raw[3];
for (int j = 0; j < 3; j++) {
// 小端模式
mag_raw[j] = (int32_t)(((uint32_t)p[3] << 24) | ((uint32_t)p[2] << 16) | ((uint32_t)p[1] << 8) | (uint32_t)p[0]);
p += 4;
}
float mag_gauss[3];
mag_gauss[0] = (float)mag_raw[0] / 1000.0f;
mag_gauss[1] = (float)mag_raw[1] / 1000.0f;
mag_gauss[2] = (float)mag_raw[2] / 1000.0f;
// 3. 解析温度数据 (2 bytes)
int16_t temp_raw = (int16_t)(((uint16_t)p[1] << 8) | (uint16_t)p[0]);
p += 2;
float temperature = (float)temp_raw / 1000.0f;
// 4. 解析气压数据 (4 bytes)
uint32_t press_raw = (uint32_t)(((uint32_t)p[3] << 24) | ((uint32_t)p[2] << 16) | ((uint32_t)p[1] << 8) | (uint32_t)p[0]);
p += 4;
float pressure = (float)press_raw / 1000.0f;
// 打印解析后的数据
if(i % 8 == 0){
printf(" ==================ble index: %d\n", *p);
printf("Package[%d]:\n", i);
printf(" ACC(g): x=%.3f, y=%.3f, z=%.3f\n", acc_g[0], acc_g[1], acc_g[2]);
printf(" GYR(dps):x=%.3f, y=%.3f, z=%.3f\n", gyr_dps[0], gyr_dps[1], gyr_dps[2]);
printf(" MAG(Gs): x=%.3f, y=%.3f, z=%.3f\n", mag_gauss[0], mag_gauss[1], mag_gauss[2]);
printf(" TEMP(C): %.3f, PRESS(Pa): %.3f\n", temperature, pressure);
}
}
// printf("--- End of Packet ---\n\n");
extern void uartSendData(void *buf, u16 len) ; // 确保u16是uint16_t或unsigned short
// uartSendData(imu_airplane, sizeof(imu_airplane));
uartSendData(data, 484); // 发送总共17字节
}
/**
@ -216,191 +287,128 @@ void start_collect_fuc(void){
*
*/
void BLE_send_fuc(void){
BLE_send_data_t data_to_send;
if (circle_buffer_is_empty(&BLE_send_buff) == 0) {
circle_buffer_read(&BLE_send_buff, &data_to_send);
} else {
// 缓冲区为空,直接返回
return;
}
// --- 封装并发送六轴传感器数据 ---
{
// 协议定义: 包头(2) + 长度(1) + 类型(1) + 数据(12) = 16字节
const uint8_t IMU_PACKET_LEN = 16;
const uint8_t IMU_PAYLOAD_LEN = 13; // 类型(1) + 数据(12)
const uint8_t IMU_TYPE = 0x01;
ble_send_data_t send_data;
uint8_t send_buffer[484];
while(1){
os_sem_pend(&receiver_ready_sem, 0); //阻塞等待
circle_buffer_read(&g_ble_send_cb, &send_data);
uint8_t imu_packet[IMU_PACKET_LEN];
// 逐字节打包数据到 send_buffer, 采用小端模式
uint8_t *p = send_buffer;
*p++ = send_data.checkout_1;
*p++ = send_data.checkout_2;
*p++ = send_data.foot;
*p++ = send_data.package_index;
// 填充包头
imu_packet[0] = 0xBB;
imu_packet[1] = 0xBE;
imu_packet[2] = IMU_PAYLOAD_LEN;
imu_packet[3] = IMU_TYPE;
// 拷贝六轴数据
// memcpy(&imu_packet[4], data_to_send.SC7U22_data, sizeof(data_to_send.SC7U22_data));
for (int i = 0; i < 6; i++) {
// SC7U22_data[i] 是一个 signed short (2字节)
// 将其低字节放在前面
imu_packet[4 + i * 2] = (uint8_t)(data_to_send.SC7U22_data[i] & 0xFF);
// 将其高字节放在后面
imu_packet[4 + i * 2 + 1] = (uint8_t)((data_to_send.SC7U22_data[i] >> 8) & 0xFF);
for (int i = 0; i < MPU_FIFO_LEN; i++) {
sensor_package_t *pkg = &send_data.sensor_package[i];
// 1. 打包六轴数据 (6 * int16_t)
for (int j = 0; j < 6; j++) {
*p++ = (uint8_t)(pkg->SC7U22_data[j] & 0xFF);
*p++ = (uint8_t)((pkg->SC7U22_data[j] >> 8) & 0xFF);
}
// 2. 打包地磁数据 (3 * int32_t)
for (int j = 0; j < 3; j++) {
*p++ = (uint8_t)(pkg->mmc5603nj_buffer[j] & 0xFF);
*p++ = (uint8_t)((pkg->mmc5603nj_buffer[j] >> 8) & 0xFF);
*p++ = (uint8_t)((pkg->mmc5603nj_buffer[j] >> 16) & 0xFF);
*p++ = (uint8_t)((pkg->mmc5603nj_buffer[j] >> 24) & 0xFF);
}
// 3. 打包温度数据 (int16_t)
*p++ = (uint8_t)(pkg->temperature & 0xFF);
*p++ = (uint8_t)((pkg->temperature >> 8) & 0xFF);
// 4. 打包气压数据 (uint32_t)
*p++ = (uint8_t)(pkg->pressure & 0xFF);
*p++ = (uint8_t)((pkg->pressure >> 8) & 0xFF);
*p++ = (uint8_t)((pkg->pressure >> 16) & 0xFF);
*p++ = (uint8_t)((pkg->pressure >> 24) & 0xFF);
#if 0
float acc_g[3];
float gyr_dps[3];
acc_g[0] = (float)send_data.sensor_package[i].SC7U22_data[0] / 2048.0f;
acc_g[1] = (float)send_data.sensor_package[i].SC7U22_data[1] / 2048.0f;
acc_g[2] = (float)send_data.sensor_package[i].SC7U22_data[2] / 2048.0f;
gyr_dps[0] = (float)send_data.sensor_package[i].SC7U22_data[3] * 0.061f;
gyr_dps[1] = (float)send_data.sensor_package[i].SC7U22_data[4] * 0.061f;
gyr_dps[2] = (float)send_data.sensor_package[i].SC7U22_data[5] * 0.061f;
printf(" ACC(g): x=%.3f, y=%.3f, z=%.3f\n", acc_g[0], acc_g[1], acc_g[2]);
printf(" GYR(dps):x=%.3f, y=%.3f, z=%.3f\n", gyr_dps[0], gyr_dps[1], gyr_dps[2]);
#endif
}
// xlog("imu %d\n",data_to_send.SC7U22_data[0]);
// xlog("imu_packet: 0x%x 0x%x 0x%x\n",imu_packet[4],imu_packet[5],imu_packet[6]);
send_data_to_ble_client(&imu_packet, IMU_PACKET_LEN);
}
// --- 封装并发送磁力计数据 ---
{
// 协议定义: 包头(2) + 长度(1) + 类型(1) + 数据(9) = 13字节
const uint8_t MAG_PACKET_LEN = 13;
const uint8_t MAG_PAYLOAD_LEN = 10; // 类型(1) + 数据(9)
const uint8_t MAG_TYPE = 0x02;
uint8_t mag_packet[MAG_PACKET_LEN];
// 填充包头
mag_packet[0] = 0xBB;
mag_packet[1] = 0xBE;
mag_packet[2] = MAG_PAYLOAD_LEN;
mag_packet[3] = MAG_TYPE;
// 拷贝磁力计数据
// memcpy(&mag_packet[4], data_to_send.mmc5603nj_buffer, sizeof(data_to_send.mmc5603nj_buffer));
for (int i = 0; i < 9; i++) {
mag_packet[4 + i] = data_to_send.mmc5603nj_buffer[i];
}
// xlog("mag: 0x%x 0x%x 0x%x\n",mag_packet[4],mag_packet[5],mag_packet[6]);
send_data_to_ble_client(&mag_packet, MAG_PACKET_LEN);
}
// --- 封装并发送压力机计数据 ---
{
// 协议定义: 包头(2) + 长度(1) + 类型(1) + 数据(6) = 10字节
const uint8_t PT_PACKET_LEN = 10;
const uint8_t PT_PAYLOAD_LEN = 7; // 类型(1) + 数据(6)
const uint8_t PT_TYPE = 0x03;
uint8_t pt_packet[PT_PACKET_LEN];
// 填充包头
pt_packet[0] = 0xBB;
pt_packet[1] = 0xBE;
pt_packet[2] = PT_PAYLOAD_LEN;
pt_packet[3] = PT_TYPE;
extern void uartSendData(void *buf, u16 len) ; // 确保u16是uint16_t或unsigned short
uartSendData(send_buffer, 484); // 发送总共17字节
send_data_to_ble_client(send_buffer, 484); // 发送数据
// 直接发送 int16_t 的二进制补码
pt_packet[4] = (uint8_t)(data_to_send.temperature & 0xFF); // 低字节
pt_packet[5] = (uint8_t)((data_to_send.temperature >> 8) & 0xFF); // 高字节
// 气压 (保持不变)
pt_packet[6] = (uint8_t)(data_to_send.pressure & 0xFF);
pt_packet[7] = (uint8_t)((data_to_send.pressure >> 8) & 0xFF);
pt_packet[8] = (uint8_t)((data_to_send.pressure >> 16) & 0xFF);
pt_packet[9] = (uint8_t)((data_to_send.pressure >> 24) & 0xFF);
send_data_to_ble_client(&pt_packet, PT_PACKET_LEN);
}
// --- 封装并发送速度数据 ---
{
// 协议定义: 包头(2) + 长度(1) + 类型(1) + 数据(2) = 6字节
const uint8_t SPEED_PACKET_LEN = 6;
const uint8_t SPEED_PAYLOAD_LEN = 3; // 类型(1) + 数据(2)
const uint8_t SPEED_TYPE = 0x04;
uint8_t speed_packet[SPEED_PACKET_LEN];
// 填充包头
speed_packet[0] = 0xBB;
speed_packet[1] = 0xBE;
// 填充长度
speed_packet[2] = SPEED_PAYLOAD_LEN;
// 填充类型
speed_packet[3] = SPEED_TYPE;
// 小端模式
speed_packet[4] = (uint8_t)(data_to_send.speed_cms & 0xFF); // 低字节
speed_packet[5] = (uint8_t)((data_to_send.speed_cms >> 8) & 0xFF); // 高字节
send_data_to_ble_client(&speed_packet, SPEED_PACKET_LEN);
}
// --- 封装并发送数据 ---
{
// 协议定义: 包头(2) + 长度(1) + 类型(1) + 数据(5) = 9字节
const uint8_t OTHER_PACKET_LEN = 9;
const uint8_t OTHER_PAYLOAD_LEN = 6; // 类型(1) + 数据(5)
const uint8_t OTHER_TYPE = 0x05;
uint8_t oher_packet[OTHER_PACKET_LEN];
// 填充包头
oher_packet[0] = 0xBB;
oher_packet[1] = 0xBE;
// 填充长度
oher_packet[2] = OTHER_PAYLOAD_LEN;
// 填充类型
oher_packet[3] = OTHER_TYPE;
// 小端模式
oher_packet[4] = (uint8_t)data_to_send.foot_state; // 数据来源
oher_packet[5] = (uint8_t)((data_to_send.timestamp_ms >> 0) & 0xFF); // LSB
oher_packet[6] = (uint8_t)((data_to_send.timestamp_ms >> 8) & 0xFF);
oher_packet[7] = (uint8_t)((data_to_send.timestamp_ms >> 16) & 0xFF);
oher_packet[8] = (uint8_t)((data_to_send.timestamp_ms >> 24) & 0xFF); // MSB
send_data_to_ble_client(&oher_packet, OTHER_PACKET_LEN);
// data_log(send_buffer);
}
}
void stop_BLE_send_fuc(void){
if (circle_buffer_is_empty(&BLE_send_buff)) {
close_process(&BLE_send_fuc_id,"BLE_send_fuc");
close_process(&stop_ble_send_fuc_id,"stop_BLE_send_fuc");
}
}
// ------------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------------
/**
* @brief 六轴静态校验
*
*/
void start_calibration(void){
create_process(&SC7U22_calibration_id,"SC7U22_calibration",NULL,SC7U22_static_calibration,10);
}
void stop_calibration(void){
close_process(&SC7U22_calibration_id, "SC7U22_calibration");
}
/**
* @brief 开始采集传感器数据并通过ble发送
*
*/
void start_clloct(void){
reset_ms_timer();
create_process(&start_collect_fuc_id,"start_collect",NULL,start_collect_fuc,10);
create_process(&BLE_send_fuc_id,"BLE_send_fuc",NULL,BLE_send_fuc,5);
os_task_create(sensor_collect_task,NULL,5,1024,32,"sensor_collect_task");
os_task_create(BLE_send_fuc,NULL,5,1024,32,"BLE_send_fuc");
}
/**
* @brief 停止采集和ble发送
*
*/
void stop_clloct(void){
close_process(&start_collect_fuc_id,"start_collect");
close_process(&BLE_send_fuc_id,"BLE_send_fuc");
// create_process(&stop_ble_send_fuc_id,"stop_BLE_send_fuc",NULL,stop_BLE_send_fuc,500); //等缓冲区内容发送完才停止ble发送任务
os_task_del("sensor_collect_task");
os_task_del("BLE_send_fuc");
}
/**
* @brief 发给上位机
*
*/
void test_uart_init(void){
#if TCFG_UART0_ENABLE == 0
static u8 buff[40];
struct uart_platform_data_t u_arg = {0};
u_arg.tx_pin = IO_PORT_DP;
u_arg.rx_cbuf = buff;
u_arg.rx_cbuf_size = 32;
u_arg.frame_length = 6;
u_arg.rx_timeout = 100;
u_arg.isr_cbfun = NULL;
u_arg.baud = 1000000;
u_arg.is_9bit = 0;
uart_bus = uart_dev_open(&u_arg);
#endif
}
void uartSendData(void *buf, u16 len) //发送数据的接口。
{
#if TCFG_UART0_ENABLE == 0
if (uart_bus) {
uart_bus->write(buf, len); //把数据写到DMA
}
#endif
}
/**
* @brief 初始化在app_main.c的app_main函数被调用
* @brief 初始化,在xtell_app_main.c的app_main函数被调用
*
*/
void xtell_task_create(void){
@ -410,7 +418,7 @@ void xtell_task_create(void){
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);
// int num_chars_written = snprintf(log_buffer_1, sizeof(log_buffer_1),"init iic: %d\n", ret);
#endif
@ -421,39 +429,59 @@ void xtell_task_create(void){
xlog("xtell_task_create\n");
circle_buffer_init(&BLE_send_buff, BLE_send_data, SENSOR_DATA_BUFFER_SIZE, sizeof(BLE_send_data_t));
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
//
void bmp280_test(void){
#define BUFF_LEN 500
static signed char acc_data_buf[BUFF_LEN] = {0};
// 1. 定义一个全局的信号量
static OS_SEM ble_send_sem;
int j = 0;
void sensor_test_task(void){
float temperature = 0;
float pressure = 0;
while(1){
WF_GET_Temperature_Pressure(&temperature, &pressure);
xlog("temperature: %.3f,pressure: %.3f\n",temperature,pressure);
os_time_dly(100);
}
}
static u16 gtest_id = 0;
void test_func(void){
// a. 初始化信号量初始值为0
// os_sem_create(&ble_send_sem, 0);
// b. 注册回调函数,让协议栈知道在准备好时该调用谁
// struct ble_server_operation_t *ble_ops;
// ble_get_server_operation_table(&ble_ops);
// ble_ops->regist_wakeup_send(NULL, on_ble_can_send);
for(int i = 0;i<BUFF_LEN;i++){
acc_data_buf[i] = i;
}
// SL_SC7U22_Config();
// mmc5603nj_init();
#if BMP280
BMP280_init();
#else
WF_Init();
#endif
// os_task_create(BLE_send_fuc,NULL,5,1024,32,"BLE_send_fuc");
// os_task_create(sensor_collect_task,NULL,5,1024,32,"sensor_collect_task");
os_task_create(sensor_test_task,NULL,5,1024,32,"sensor_test");
// data_send_task();
}
void gsensor_test(void){
#if 1
if(count >= 5){
xlog("==============time============\n");
u32 current_time = get_ms_timer();
xlog("Time since last reset: %u ms\n", current_time);
// 为了演示,我们在这里调用重置
if (current_time > 5000) { // 比如超过5秒就重置一次
reset_ms_timer();
}
count = 0;
}
count++;
#endif
}

View File

@ -1,5 +1,10 @@
/*
气压计
根据手册,对于室内导航的配置推荐:
t_standby=0.5ms, filter=16, spi_en=0
osrs_t=x2, osrs_p=x16, mode=normal
采样率为26.3Hz外部每40ms读取一次
*/
#include "BMP280.h"
#include <string.h>
@ -46,6 +51,7 @@ static uint8_t bmp280_read_regs(uint8_t reg, uint8_t *buf, uint16_t len) {
* @return 补偿后的温度值 (单位: °C)
*/
static float compensate_temperature(int32_t adc_T) {
#if 1
float var1, var2, temperature;
var1 = (((float)adc_T) / 16384.0f - ((float)t1) / 1024.0f) * ((float)t2);
@ -59,6 +65,16 @@ static float compensate_temperature(int32_t adc_T) {
if (temperature > 85.0f) return 85.0f;
return temperature;
#else
int32_t var1, var2, T;
var1 = ((((adc_T>>3) - ((int32_t)t1<<1))) * ((int32_t)t2)) >> 11;
var2 = (((((adc_T>>4) - ((int32_t)t1)) * ((adc_T>>4) - ((int32_t)t1))) >> 12) *
((int32_t)t3)) >> 14;
t_fine = var1 + var2;
T = (t_fine * 5 + 128) >> 8;
return (float)(T/100.0f);
#endif
}
/**
@ -67,6 +83,7 @@ static float compensate_temperature(int32_t adc_T) {
* @return 补偿后的气压值 (单位: Pa)
*/
static float compensate_pressure(int32_t adc_P) {
#if 1
float var1, var2, pressure;
var1 = ((float)t_fine / 2.0f) - 64000.0f;
@ -90,6 +107,25 @@ static float compensate_pressure(int32_t adc_P) {
if (pressure > 110000.0f) return 110000.0f;
return pressure;
#else
int32_t var1, var2, p;
var1 = ((int32_t)t_fine) - 128000;
var2 = var1 * var1 * (int32_t)p6;
var2 = var2 + ((var1*(int32_t)p5)<<17);
var2 = var2 + (((int32_t)p4)<<35);
var1 = ((var1 * var1 * (int32_t)p3)>>8) + ((var1 * (int32_t)p2)<<12);
var1 = (((((int32_t)1)<<47)+var1))*((int32_t)p1)>>33;
if (var1 == 0)
{
return 0; // avoid exception caused by division by zero
}
p = 1048576-adc_P;
p = (((p<<31)-var2)*3125)/var1;
var1 = (((int32_t)p9) * (p>>13) * (p>>13)) >> 25;
var2 = (((int32_t)p8) * p) >> 19;
p = ((p + var1 + var2) >> 8) + (((int32_t)p9)<<4);
return (float)(p/256);
#endif
}
/*==================================================================================*/
@ -99,18 +135,18 @@ static float compensate_pressure(int32_t adc_P) {
uint8_t bmp280_init(void) {
uint8_t BMP280_init(void) {
uint8_t id;
uint8_t calib_data[24];
// 1. 检查芯片ID
if (bmp280_read_regs(BMP280_REG_ID, &id, 1) == 0) {
printf("bmp280 get id error:%d\n",id );
return 1; // I2C读取失败
// return 1; // I2C读取失败
}
if (id != 0x58) {
printf("bmp280 check diff:%d\n",id );
return 1; // ID不匹配
// return 1; // ID不匹配
}
printf("bmp280 get id:0%X\n",id );

View File

@ -8,11 +8,11 @@
// I2C 从设备地址
#if BMP_PULL_UP == 1 //外部接的高
#define BMP_IIC_7BIT_ADDRESS 0x76 //7位,外部接高为0x77
#define BMP_IIC_7BIT_ADDRESS 0x76 //7位,外部接高为0x76
#define BMP_IIC_WRITE_ADDRESS (BMP_IIC_7BIT_ADDRESS<<1) //8位地址
#define BMP_IIC_READ_ADDRESS (BMP_IIC_WRITE_ADDRESS | 0x01)
#else
#define BMP_IIC_7BIT_ADDRESS 0x77 //7位,外部接为0x76
#define BMP_IIC_7BIT_ADDRESS 0x77 //7位,外部接GAO为0x77
#define BMP_IIC_WRITE_ADDRESS (BMP_IIC_7BIT_ADDRESS<<1) //8位地址
#define BMP_IIC_READ_ADDRESS (BMP_IIC_WRITE_ADDRESS | 0x01)
#endif
@ -33,7 +33,7 @@
* @return 0: 成功, 1: 芯片ID错误, 2: 读取校准参数失败
* @note 此函数会完成ID检查、软复位、读取校准参数并设置传感器为连续测量模式。
*/
uint8_t bmp280_init(void);
uint8_t BMP280_init(void);
/**
* @brief 从BMP280读取温度和气压数据

View File

@ -1,3 +1,7 @@
/*
MMC5603nj
1-255的采样率这里设置为200Hz,5ms
*/
#include "MMC56.h"
#include "math.h"
@ -41,13 +45,15 @@ int mmc5603nj_init(void) {
// 设置20位分辨率 (BW[1:0] = 11)
// 同时确保所有轴都使能 (X/Y/Z_inhibit = 0)
// mmc5603nj_write_reg(MMC_INCTRL1, 0x03);
mmc5603nj_write_reg(MMC_INCTRL1, 0x03);
os_time_dly(1);
// 设置内部控制寄存器2
// CMM_EN = 1 (使能连续模式功能)
// HPOWER = 1 (高功耗模式,更稳定)
mmc5603nj_write_reg(MMC_INCTRL2, 0x90); // 0b10010000
// HPOWER = 0
// mmc5603nj_write_reg(MMC_INCTRL2, 0x10); // 0b00010000
mmc5603nj_write_reg(MMC_INCTRL2, 0x10); // 0b10010000
// 设置自动SET/RESET功能
// AUTO_SR_EN = 1
@ -56,7 +62,8 @@ int mmc5603nj_init(void) {
g_continuous_mode_enabled = 0;
printf("MMC5603NJ initialized successfully.\n");
mmc5603nj_enable_continuous_mode(0x04);
// mmc5603nj_enable_continuous_mode(0xC8); //200Hz的采样率最高支持255
mmc5603nj_enable_continuous_mode(0xCF);
return 1;
}
@ -195,7 +202,7 @@ void mmc5603nj_read_mag_data(mmc5603nj_mag_data_t *mag_data) {
} while ((status & 0x40) == 0 && timeout > 0);
if (timeout == 0) {
printf("Error: Magnetic measurement timeout!\n");
// printf("Error: Magnetic measurement timeout!\n");
mag_data->x = mag_data->y = mag_data->z = 0.0f;
return;
}

View File

@ -62,7 +62,7 @@ unsigned char SL_SC7U22_I2c_Spi_Read(unsigned char sl_spi_iic, unsigned char reg
static void sl_delay(unsigned char sl_i)
{
os_time_dly(sl_i);
delay((int)sl_i);
}
char iic_read_len;
@ -131,10 +131,12 @@ unsigned char SL_SC7U22_Config(void)
// SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x40, 0x06);//ACC_CONF 0x07=50Hz 0x06=25Hz
// SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x40, 0xA8);//高性能模式连续4个数据平均1次100Hz -- lmx
SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x40, 0xBC);//ACC_CON 高性能模式1600Hz -- lmx
// SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x40, 0xBB);//ACC_CON 高性能模式800Hz -- lmx
// SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x40, 0xBC);//ACC_CON 高性能模式1600Hz -- lmx
SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x40, 0xA8);//ACC_CON 高性能模式100Hz平均数4 -- lmx
// SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x40, 0xA8);//ACC_CON 高性能模式100Hz平均数4 -- lmx
SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x40, 0x8B);//ACC_CON 高性能模式400Hz -- lmx
#if ACC_RANGE==2
SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x41, 0x00);//ACC_RANGE 00±2G
@ -153,9 +155,11 @@ unsigned char SL_SC7U22_Config(void)
// SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x42, 0x8C);//GYR_CONF 1600Hz -- lmx
// SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x42, 0xAC);//GYR_CONF 1600Hz -- lmx
// SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x42, 0xAB);//GYR_CONF 800Hz -- lmx
SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x42, 0xE8);//GYR_CONF 100Hz, 噪声优化开启,4个平均一次 -- lmx
// SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x42, 0xE8);//GYR_CONF 100Hz, 噪声优化开启,4个平均一次 -- lmx
SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x43, 0x00);//GYR_RANGE 2000dps
SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x42, 0xCB);//GYR_CONF 噪声优化开启,高性能模式400Hz -- lmx
// SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x43, 0x00);//GYR_RANGE 2000dps
SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x43, 0x00);//GYR_RANGE 2000dps
SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x04, 0x50);//COM_CFG
@ -291,7 +295,7 @@ void SL_SC7U22_RawData_Read(signed short * acc_data_buf,signed short * gyr_data_
unsigned char Acc_FIFO_Num;
unsigned char Gyr_FIFO_Num;
unsigned char SL_SC7U22_FIFO_DATA[1024];
unsigned char SL_SC7U22_FIFO_DATA[2048];
unsigned short SL_SC7U22_FIFO_Read(signed short *accx_buf,signed short *accy_buf,signed short *accz_buf,signed short *gyrx_buf,signed short *gyry_buf,signed short *gyrz_buf)
{
@ -306,7 +310,8 @@ unsigned short SL_SC7U22_FIFO_Read(signed short *accx_buf,signed short *accy_buf
unsigned char header[2];
unsigned short j;
#if SL_Sensor_Algo_Release_Enable==0x00 //user can set to zero
// #if SL_Sensor_Algo_Release_Enable==0x00 //user can set to zero
#if 0//lmx
#if SL_SC7U22_WAIT_FIFO_LEN_ENABLE==0x00
while((fifo_num1&0x20)!=0x20)
{
@ -341,7 +346,8 @@ unsigned short SL_SC7U22_FIFO_Read(signed short *accx_buf,signed short *accy_buf
SL_SC7U22_I2c_Spi_Read(SL_SPI_IIC_INTERFACE, 0x20,1,&fifo_num2);
if((fifo_num1&0x10)==0x10)
{
fifo_num=2048;
// fifo_num=2048; // 原始代码,会导致溢出
fifo_num = 2048; // 传感器FIFO已满但我们的缓冲区只有1024字节所以最多读1024字节
}
else
{
@ -349,10 +355,15 @@ unsigned short SL_SC7U22_FIFO_Read(signed short *accx_buf,signed short *accy_buf
}
#endif
// 增加保护,确保读取的字节数不超过缓冲区大小 (1024 bytes)
// fifo_num 是 word (2 bytes) 的数量, 所以最大值是 512
if (fifo_num > 1024) {
fifo_num = 1024;
}
SL_SC7U22_I2c_Spi_Read(SL_SPI_IIC_INTERFACE, 0x21, fifo_num*2, SL_SC7U22_FIFO_DATA);//读取FIFO数据 BYTE NUM
// SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x1D, 0x00);//BY PASS MODE
// SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x1D, 0x20);//Stream MODE
xlog("SC7U22_FIFO_NUM1:%d\n",fifo_num);
// xlog("SC7U22_FIFO_NUM1:%d\n",fifo_num);
#if SL_Sensor_Algo_Release_Enable==0x00
// xlog("0x1F:0x%x 0x20:0x%x\n",fifo_num1,fifo_num2);
// xlog("SC7U22_FIFO_NUM1:%d\n",fifo_num);
@ -380,7 +391,7 @@ unsigned short SL_SC7U22_FIFO_Read(signed short *accx_buf,signed short *accy_buf
accx_buf[Acc_FIFO_Num] = ((s16)(SL_SC7U22_FIFO_DATA[i + 0] * 256 + SL_SC7U22_FIFO_DATA[i + 1])) ;
accy_buf[Acc_FIFO_Num] = ((s16)(SL_SC7U22_FIFO_DATA[i + 2] * 256 + SL_SC7U22_FIFO_DATA[i + 3])) ;
accz_buf[Acc_FIFO_Num] = ((s16)(SL_SC7U22_FIFO_DATA[i + 4] * 256 + SL_SC7U22_FIFO_DATA[i + 5])) ;
xlog("AccNum : %d ,Acc_x : %4d, Acc_y : %4d, Acc_z : %4d,\r\n",Acc_FIFO_Num, accx_buf[Acc_FIFO_Num], accy_buf[Acc_FIFO_Num], accz_buf[Acc_FIFO_Num]);
// xlog("AccNum : %d ,Acc_x : %4d, Acc_y : %4d, Acc_z : %4d,\r\n",Acc_FIFO_Num, accx_buf[Acc_FIFO_Num], accy_buf[Acc_FIFO_Num], accz_buf[Acc_FIFO_Num]);
i = i + 6;
Acc_FIFO_Num++;
}
@ -390,7 +401,7 @@ unsigned short SL_SC7U22_FIFO_Read(signed short *accx_buf,signed short *accy_buf
gyrx_buf[Gyr_FIFO_Num] = ((s16)(SL_SC7U22_FIFO_DATA[i + 0] * 256 + SL_SC7U22_FIFO_DATA[i + 1])) ;
gyry_buf[Gyr_FIFO_Num] = ((s16)(SL_SC7U22_FIFO_DATA[i + 2] * 256 + SL_SC7U22_FIFO_DATA[i + 3])) ;
gyrz_buf[Gyr_FIFO_Num] = ((s16)(SL_SC7U22_FIFO_DATA[i + 4] * 256 + SL_SC7U22_FIFO_DATA[i + 5])) ;
xlog("GyrNum : %d, Gyr_x : %4d, Gyr_y : %4d, Gyr_z : %4d,\r\n",Gyr_FIFO_Num, gyrx_buf[Gyr_FIFO_Num], gyry_buf[Gyr_FIFO_Num], gyrz_buf[Gyr_FIFO_Num]);
// xlog("GyrNum : %d, Gyr_x : %4d, Gyr_y : %4d, Gyr_z : %4d,\r\n",Gyr_FIFO_Num, gyrx_buf[Gyr_FIFO_Num], gyry_buf[Gyr_FIFO_Num], gyrz_buf[Gyr_FIFO_Num]);
i = i + 6;
Gyr_FIFO_Num++;
}
@ -400,9 +411,15 @@ unsigned short SL_SC7U22_FIFO_Read(signed short *accx_buf,signed short *accy_buf
{
i = i + 2;
}
}
}
if(Acc_FIFO_Num > Gyr_FIFO_Num)
fifo_len = Acc_FIFO_Num;
else
fifo_len = Gyr_FIFO_Num;
// xlog("Acc_FIFO_Num:%d,Gyr_FIFO_Num:%d\n",Acc_FIFO_Num,Gyr_FIFO_Num);
SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x1D,0x00);
SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x1D,0x20);
return fifo_len;
}
#endif

View File

@ -14,7 +14,7 @@ Copyright (c) 2022 Silan MEMS. All Rights Reserved.
//是否使能串口打印调试
#define SL_Sensor_Algo_Release_Enable 0x00
//是否开启FIFO模式默认STREAM模式
#define SL_SC7U22_FIFO_ENABLE 0x00
#define SL_SC7U22_FIFO_ENABLE 0x01
/***使用前请根据实际情况配置以下参数******/

View File

@ -3,171 +3,225 @@
*/
#include "wf282a.h"
#include <math.h>
#include <stdint.h> // 推荐使用标准类型
#include "gSensor/gSensor_manage.h"
#include <stdint.h>
#include "gSensor/gSensor_manage.h" // Assuming this provides gravity_sensor_command and _gravity_sensor_get_ndata
#define ENABLE_XLOG 1
#ifdef xlog
#undef xlog
#endif
#if ENABLE_XLOG
#define xlog(format, ...) printf("[XT:%s] " format, __func__, ##__VA_ARGS__)
#else
#define xlog(format, ...) ((void)0)
#endif
/*==================================================================================*/
/* WF282A 内部定义 */
/*==================================================================================*/
// 存储校准系数的静态全局变量
static int16_t c0, c1, c01, c11, c20, c21, c30;
static int32_t c00, c10;
/*==================================================================================*/
/* 封装的底层I2C读写函数 */
/* 封装的底层I2C读写函数 (Provided by user) */
/*==================================================================================*/
#define I2C_HANDLE 0
/**
* @brief 写入单个字节到WF282A寄存器
*/
static void wf282a_write_reg(uint8_t reg, uint8_t data) {
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) {
return _gravity_sensor_get_ndata(WF_IIC_READ_ADDRESS, reg, buf, len);
}
/*==================================================================================*/
/* 内部辅助函数 */
/*==================================================================================*/
/**
* @brief 从缓冲区中解析所有校准系数
* @param buf 包含从寄存器0x10开始读取的18个字节的校准数据
*/
static void parse_calibration_data(const uint8_t *buf) {
// c0 (12-bit)
c0 = ((int16_t)buf[0] << 4) | (buf[1] >> 4);
if (c0 & (1 << 11)) c0 |= 0xF000;
// 制造商: (tempbuf[0]<<4) + ((tempbuf[1]>>4) & 0x0F);
c0 = ((int16_t)buf[0] << 4) | ((buf[1] >> 4) & 0x0F);
// if (c0 & (1 << 11)) c0 |= 0xF000;
if(c0 > 0x7ff) c0 = c0 - 0x1000;
// c1 (12-bit)
c1 = (((int16_t)buf[1] & 0x0F) << 8) | buf[2];
if (c1 & (1 << 11)) c1 |= 0xF000;
// 制造商: tempbuf[2] + ((tempbuf[1] & 0x0F)<<8);
c1 = (((int16_t)buf[1] & 0x0F) << 8) | buf[2];
// if (c1 & (1 << 11)) c1 |= 0xF000;
if(c1 > 0x7ff) c1 = c1 -0x1000;
// c00 (20-bit)
c00 = ((int32_t)buf[3] << 12) | ((int32_t)buf[4] << 4) | (buf[5] >> 4);
if (c00 & (1 << 19)) c00 |= 0xFFF00000;
// 制造商: (((u32)((tempbuf[3]<<8) + tempbuf[4]))<<4)+((tempbuf[5]>>4)&0x0F);
c00 = ((int32_t)buf[3] << 12) | ((int32_t)buf[4] << 4) | ((buf[5] >> 4) & 0x0F);
// if (c00 & (1 << 19)) c00 |= 0xFFF00000;
if(c00 > 0x7ffff) c00 = c00 - 0x100000;
// c10 (20-bit)
c10 = (((int32_t)buf[5] & 0x0F) << 16) | ((int32_t)buf[6] << 8) | buf[7];
if (c10 & (1 << 19)) c10 |= 0xFFF00000;
// 制造商: (((u32)((tempbuf[5]&0x0F)<<8)+tempbuf[6])<<8)+tempbuf[7];
c10 = (((int32_t)buf[5] & 0x0F) << 16) | ((int32_t)buf[6] << 8) | buf[7];
// if (c10 & (1 << 19)) c10 |= 0xFFF00000;
if(c10 > 0x7ffff) c10 = c10 - 0x100000;
// c01, c11, c20, c21, c30 (16-bit)
c01 = (int16_t)((uint16_t)buf[8] << 8 | buf[9]);
if (c01 > 0x7fff) c01 = c01 - 0x10000; // 制造商的符号扩展
c11 = (int16_t)((uint16_t)buf[10] << 8 | buf[11]);
if (c11 > 0x7fff) c11 = c11 - 0x10000; // 制造商的符号扩展
c20 = (int16_t)((uint16_t)buf[12] << 8 | buf[13]);
if (c20 > 0x7fff) c20 = c20 - 0x10000; // 制造商的符号扩展
c21 = (int16_t)((uint16_t)buf[14] << 8 | buf[15]);
if (c21 > 0x7fff) c21 = c21 - 0x10000; // 制造商的符号扩展
c30 = (int16_t)((uint16_t)buf[16] << 8 | buf[17]);
if (c30 > 0x7fff) c30 = c30 - 0x10000; // 制造商的符号扩展
}
/**
* @brief 获取原始温度值 (ADC)
* 在连续测量模式下,只需读取数据寄存器,无需触发或等待。
*/
static int32_t Get_Traw() {
uint8_t buff[3];
int32_t Traw;
// 从 MSB 寄存器 WF_TMP_B2 (0x03) 开始连续读取3个字节
wf282a_read_regs(WF_TMP_B2, buff, 3);
if (wf282a_read_regs(WF_TMP_B2, buff, 3) != 3) {
xlog("Failed to read raw temperature data\n");
return 0; // 返回0或一个合适的错误值
}
// buff[0] = B2 (MSB), buff[1] = B1, buff[2] = B0 (LSB)
Traw = (int32_t)buff[0] << 16 | (int32_t)buff[1] << 8 | (int32_t)buff[2];
// 24位二进制补码转32位
if (Traw & (1 << 23)) {
Traw |= 0xFF000000;
}
// if (Traw & (1 << 23)) {
// Traw |= 0xFF000000;
// }
if(Traw > 0x7fffff) Traw = Traw - 0x1000000;
return Traw;
}
/**
* @brief 获取原始气压值 (ADC)
* 在连续测量模式下,只需读取数据寄存器,无需触发或等待。
*/
static int32_t Get_Praw() {
uint8_t buff[3];
int32_t Praw;
// 从 MSB 寄存器 WF_PRS_B2 (0x00) 开始连续读取3个字节
wf282a_read_regs(WF_PRS_B2, buff, 3);
if (wf282a_read_regs(WF_PRS_B2, buff, 3) != 3) {
xlog("Failed to read raw pressure data\n");
return 0; // 返回0或一个合适的错误值
}
// buff[0] = B2 (MSB), buff[1] = B1, buff[2] = B0 (LSB)
Praw = (int32_t)buff[0] << 16 | (int32_t)buff[1] << 8 | (int32_t)buff[2];
// 24位二进制补码转32位
if (Praw & (1 << 23)) {
Praw |= 0xFF000000;
}
// // 24位二进制补码转32位
// if (Praw & (1 << 23)) {
// Praw |= 0xFF000000;
// }
if(Praw > 0x7fffff) Praw = Praw - 0x1000000;
return Praw;
}
/*==================================================================================*/
/* 4. 外部接口函数实现 */
/*==================================================================================*/
uint8_t WF_Init() {
uint8_t calib_buf[18];
uint8_t check_cfg;
xlog("WF282A: soft reset\n");
// 1. 软复位
// wf282a_write_reg(WF_RESET_REG, 0x09);//0x0C
delay(1000); // 复位后等待1000ms
// 1. 配置传感器工作模式
// 推荐配置压力8次过采样温度1次过采样测量速率16Hz
wf282a_write_reg(WF_PRS_CFG, (PM_RATE_16 << 4) | PM_PRC_8);
wf282a_write_reg(WF_TMP_CFG, (TMP_RATE_16 << 4) | TMP_PRC_1 | TMP_INT_SENSOR);
wf282a_write_reg(WF_MEAS_CFG, 0x07); // 启动连续压力和温度测量
wf282a_write_reg(WF_CFG_REG, 0x00); // 无中断或FIFO移位配置
// 读取设备id确保设备通信正常
extern uint8_t WF_GetID();
WF_GetID();
// 2. 一次性读取所有校准系数 (从0x10到0x21共18字节)
if (wf282a_read_regs(COEF_C0, calib_buf, 18) != 0) {
// 2. 读取校准系数
if (wf282a_read_regs(COEF_C0, calib_buf, 18) != 18) { //0x10, 检查是否成功读取18字节
xlog("Failed to read the calibration coefficient\n");
return 2; // 读取校准数据失败
}
parse_calibration_data(calib_buf);
// DEBUG: 打印解析后的校准系数
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);
// 3. 检查配置是否写入成功
wf282a_read_regs(WF_MEAS_CFG, &check_cfg, 1);
if (check_cfg != 0x07) {
return 1; // 错误
} else {
return 0; // 成功
}
#if 0 //连续测量
// 配置压力、温度和通用寄存器为连续测量模式
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_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, (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
return 0; // 成功
}
void WF_Sleep() {
wf282a_write_reg(WF_MEAS_CFG, 0x00); // 待机模式
}
void WF_Wakeup() {
wf282a_write_reg(WF_MEAS_CFG, 0x07); // 恢复连续测量
// 恢复连续测量模式
wf282a_write_reg(WF_MEAS_CFG, 0x06); // 启动连续压力和温度测量
delay(40); // 恢复后等待一个测量周期
}
uint8_t WF_GetID() {
uint8_t id;
wf282a_read_regs(WF_ID_REG, &id, 1);
if (wf282a_read_regs(WF_ID_REG, &id, 1) != 1) {
xlog("Failed to read chip ID\n");
return 0; // 返回0或一个合适的错误值
}
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; // 缩放原始温度值
return (float)c0 * 0.5f + (float)c1 * Traw_sc;
}
float WF_Pressure_Calculate() {
float Traw_sc, Praw_sc, Pcomp;
//外部调用
void WF_GET_Temperature_Pressure(float* temperature, float* precessure){
#if 0 //连续测量模式
int32_t Traw = Get_Traw();
xlog("DEBUG: Traw = %ld\n", Traw);
delay(5);
int32_t Praw = Get_Praw();
xlog("DEBUG: Praw = %ld\n", Praw);
#else //单次测量
wf282a_write_reg(WF_MEAS_CFG, 0x02); //内部进行一次温度测量
delay(500);
int32_t Traw = Get_Traw();
xlog("DEBUG: Traw = %ld\n", Traw);
wf282a_write_reg(WF_MEAS_CFG, 0x01); //内部进行一次压力测量
delay(500);
int32_t Praw = Get_Praw();
xlog("DEBUG: Praw = %ld\n", Praw);
Traw_sc = (float)Traw / KT; // 缩放原始温度值
Praw_sc = (float)Praw / KP; // 缩放原始压力值
// 公式: 手册给出
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;
#endif
float Traw_sc = (float)Traw / KT; // 缩放原始温度值
double Praw_sc = (double)Praw / KP; // 缩放原始压力值
double precessure_tmp = 0;
*temperature = (float)c0 * 0.5f + (float)c1 * Traw_sc;
precessure_tmp = (double)c00
+ Praw_sc * ((double)c10 + Praw_sc * ((double)c20 + Praw_sc * (double)c30))
+ Traw_sc * (double)c01
+ Traw_sc * Praw_sc * ((double)c11 + Praw_sc + (double)c21);
xlog("temperature:%.3f,precessure: %.3f\n",*temperature, precessure_tmp);
*precessure = (float)precessure_tmp; // 传出
}
float WF_Altitude_Calculate() {
float pressure_pa = WF_Pressure_Calculate();
// 使用标准大气压公式计算海拔

View File

@ -1,18 +1,26 @@
#ifndef _WF282A_H_
#define _WF282A_H_
#include <stdint.h> // 使用标准整数类型
// 标定值
#define KT 524288.0f
#define KP 1572864.0f
#define WF_PULL_UP 1 //外部是否接的上拉
// 标定值 (调整为16x过采样对应的Scale Factor)
/*
Oversampling Rate Scale Factor (kP or kT)
1 (single) 524288
2 times (Low Power) 1572864
4 times 3670016
8 times 7864320
16 times (Standard) 253952
32 times 516096
64 times (High Precision) 1040384
128 times 2088960
*/
#define KT 1572864.0f
#define KP 1572864.0f
#define WF_PULL_UP 0 //外部是否接的上拉
// I2C 从设备地址
#if WF_PULL_UP == 1 //外部接
#define WF_IIC_7BIT_ADDRESS 0x77 //7位,外部接高为0x77
#if WF_PULL_UP == 0 //外部接高为0x77
#define WF_IIC_7BIT_ADDRESS 0x77
#define WF_IIC_WRITE_ADDRESS (WF_IIC_7BIT_ADDRESS<<1) //8位地址
#define WF_IIC_READ_ADDRESS (WF_IIC_WRITE_ADDRESS | 0x01)
#else
@ -20,9 +28,7 @@
#define WF_IIC_WRITE_ADDRESS (WF_IIC_7BIT_ADDRESS<<1) //8位地址
#define WF_IIC_READ_ADDRESS (WF_IIC_WRITE_ADDRESS | 0x01)
#endif
#define WF_CHIP_ID 0X10
// 寄存器映射
// 压力数据
#define WF_PRS_B2 0x00
@ -35,14 +41,14 @@
// 配置寄存器
#define WF_PRS_CFG 0x06
#define WF_TMP_CFG 0x07
#define WF_MEAS_CFG 0x08
#define WF_MEAS_CFG 0x08 // This register is used to trigger single measurements
#define WF_CFG_REG 0x09
#define WF_INT_STS 0x0A
#define WF_FIFO_STS 0x0B
#define WF_RESET_REG 0x0C
// ID寄存器
#define WF_ID_REG 0x0D
// 校准系数寄存器
// 校准系数寄存器 (Offsets match manufacturer's i+0x10 access)
#define COEF_C0 0x10
#define COEF_C0_C1 0x11
#define COEF_C1 0x12
@ -63,44 +69,43 @@
#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 次/秒
#define PM_RATE_8 0x03 // 8 次/秒
#define PM_RATE_16 0x04 // 16 次/秒
#define PM_RATE_32 0x05 // 32 次/秒
#define PM_RATE_32 0x05 // 32 次/秒 <--- 建议使用此速率
#define PM_RATE_64 0x06 // 64 次/秒
#define PM_RATE_128 0x07 // 128 次/秒
// 压力配置 (PRS_CFG[3:0]) - 过采样率
#define PM_PRC_1 0x00 // 1 次 (单次)
#define PM_PRC_2 0x01 // 2 次 (低功耗)
#define PM_PRC_4 0x02 // 4 次
#define PM_PRC_8 0x03 // 8 次 (标准)
#define PM_PRC_16 0x04 // 16 次 (需要移位)
#define PM_PRC_32 0x05 // 32 次 (需要移位)
#define PM_PRC_64 0x06 // 64 次 (高精度, 需要移位)
#define PM_PRC_128 0x07 // 128 次 (需要移位)
#define PM_PRC_8 0x03 // 8 次
#define PM_PRC_16 0x04 // 16 次 (标准) <--- 建议使用此过采样率
#define PM_PRC_32 0x05 // 32 次
#define PM_PRC_64 0x06 // 64 次 (高精度)
#define PM_PRC_128 0x07 // 128 次
// 温度配置 (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 次/秒
#define TMP_RATE_8 0x03 // 8 次/秒
#define TMP_RATE_16 0x04 // 16 次/秒
#define TMP_RATE_32 0x05 // 32 次/秒
#define TMP_RATE_32 0x05 // 32 次/秒 <--- 建议使用此速率
#define TMP_RATE_64 0x06 // 64 次/秒
#define TMP_RATE_128 0x07 // 128 次/秒
// 温度配置 (TMP_CFG[3:0]) - 过采样率
// 温度配置 (TMP_CFG[2:0]) - 过采样率
#define TMP_PRC_1 0x00 // 1 次
#define TMP_PRC_2 0x01 // 2 次
#define TMP_PRC_4 0x02 // 4 次
#define TMP_PRC_8 0x03 // 8 次
#define TMP_PRC_16 0x04 // 16 次
#define TMP_PRC_16 0x04 // 16 次 <--- 建议使用此过采样率
#define TMP_PRC_32 0x05 // 32 次
#define TMP_PRC_64 0x06 // 64 次
#define TMP_PRC_128 0x07 // 128 次
@ -110,39 +115,39 @@
* @return 0: 成功, 1: 失败
*/
uint8_t WF_Init(void);
/**
* @brief 使传感器进入休眠/待机模式
*/
void WF_Sleep(void);
/**
* @brief 唤醒传感器,开始连续测量
* 在连续模式下通常只需要调用一次WF_Init即可无需频繁调用Wakeup
* 如果WF_Sleep被调用则需要调用WF_Wakeup来恢复连续测量
*/
void WF_Wakeup(void);
void WF_Wakeup(void); // Reinstated for continuous mode control
/**
* @brief 获取传感器芯片ID
* @return 芯片ID (应为 0x10)
*/
uint8_t WF_GetID(void);
/**
* @brief 计算并返回当前海拔高度
* @return 海拔高度 (单位: 米)
*/
float WF_Altitude_Calculate(void);
/**
* @brief 计算并返回补偿后的压力值
* @return 压力 (单位: Pa)
*/
float WF_Pressure_Calculate(void);
/**
* @brief 计算并返回补偿后的温度值
* @return 温度 (单位: °C)
*/
float WF_Temperature_Calculate(void);
void WF_GET_Temperature_Pressure(float* temperature, float* precessure);
// Added Delay_xms prototype (assuming it's implemented in .c file or globally)
void Delay_xms(uint8_t delay);
#endif // _WF282A_H_

View File

@ -1,10 +1,12 @@
#ifndef XTELL_H
#define XTELL_H
#include "system/includes.h"
#include "generic/typedef.h"
// #define KS_BLE 1
#define XTELL_TEST 1
#define ACC_RANGE 16 //g加速度满量程:2、4、8、16
#define BMP280 0
#endif

View File

@ -171,6 +171,6 @@ void xtell_app_main()
xtell_task_create();
xlog("==============xtell_app_end================\n");
}

View File

@ -49,6 +49,7 @@
#include "./sensor/MMC56.h"
#include "./sensor/BMP280.h"
#include "./sensor/AK8963.h"
#include "./sensor/WF282A.h"
#include "./calculate/skiing_tracker.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
//宏定义
@ -83,13 +84,13 @@ extern u8 init_ok;
extern u8 sniff_out;
unsigned char xtell_bl_state=0; //存放经典蓝牙的连接状态0断开1是连接
u8 bt_newname =0;
unsigned char xt_ble_new_name[9] = "CM-22222";
unsigned char xt_ble_new_name[9] = "AAAAA";
static u16 play_poweron_ok_timer_id = 0;
// -- 初始化标志位 --
u8 SC7U22_init = 0x10; //六轴是否初始化
u8 MMC5603nj_init = 0x20; //地磁是否初始化
u8 BMP280_init = 0x30; //气压计初始化
u8 barometer_init = 0x30; //气压计初始化
u8 foot_init = 0x40; //数据来源初始化左脚0x41 or 右脚0x42
// -- 线程id --
@ -191,6 +192,120 @@ static int state_machine(struct application *app, enum app_state state, struct i
///////////////////////////////////////////////////////////////////////////////////////////////////
//handle
void le_user_app_event(u8* buffer){
if (buffer[0] == 0xBE && buffer[1] == 0xBB) {
if(buffer[2] == 0x01){ //后面的数据长度 1
switch (buffer[3]){
case 0x01:
// extern void gsensor_test(void);
// create_process(&gsensor_test_id,"gsensor_test",NULL,gsensor_test,1000);
xlog("ota_test");
cpu_reset();
break;
case 0xff: //测试
u8 device_buff[10];
u8 founds = 0;
extern void i2c_scanner_probe(u8* device_addr, u8* found_number);
i2c_scanner_probe(device_buff,&founds);
for(int i = 0;i < founds;i++){
send_data_to_ble_client(&device_buff,founds);
}
break;
case 0x02:
extern void test_func(void);
test_func();
break;
default:
break;
}
}else if(buffer[2] == 0x02){ //后面数据长度为2
switch (buffer[3]){ //数据包类型
case 0x00: //数据包类型为:指定传感器初始化
u8 send2_0[5] = {0xBB,0xBE,0x02,0x00,0x00};
if(buffer[4] == 0x01){ //六轴
// stop_calibration();
if (SL_SC7U22_Config() == 0) {
SC7U22_init = 0x10;
}else{
SC7U22_init = 0x11;
}
send2_0[4] = SC7U22_init;
send_data_to_ble_client(&send2_0,5);
// start_calibration();
}else if(buffer[4] == 0x02){ //地磁
if(mmc5603nj_init() == 0){
MMC5603nj_init = 0x20;
send2_0[4] = MMC5603nj_init; //地磁初始化失败
send_data_to_ble_client(&send2_0,5);
return;
}
MMC5603nj_init = 0x21;
send2_0[4] = MMC5603nj_init; //地磁初始化成功
send_data_to_ble_client(&send2_0,5);
}else if(buffer[4] == 0x03){ //气压计初始化
#if BMP280
if(BMP280_init() != 0){
//初始化失败
barometer_init = 0x30;
send2_0[4] = barometer_init;
send_data_to_ble_client(&send2_0,5);
return;
}
barometer_init = 0x31;
send2_0[4] = barometer_init; //气压计初始化成功
send_data_to_ble_client(&send2_0,5);
#else
if(WF_Init() != 0){
//初始化失败
barometer_init = 0x30;
send2_0[4] = barometer_init;
send_data_to_ble_client(&send2_0,5);
return;
}
barometer_init = 0x31;
send2_0[4] = barometer_init; //气压计初始化成功
send_data_to_ble_client(&send2_0,5);
#endif
}
break;
case 0x01: //设置传感器采集对象左脚or右脚
u8 send2_1[5] = {0xBB,0xBE,0x06,0x05,0x00};
if(buffer[4] == 0x01){ //设定数据来源是左脚
foot_init = 0x41;
}else if(buffer[4] == 0x02){//设定数据来源是右脚
foot_init = 0x42;
}
send2_1[4] = foot_init;
send_data_to_ble_client(&send2_1,9);
break;
case 0x02: //数据包类型为:获取指定传感器初始化状态
u8 send2_2[5] = {0xBB,0xBE,0x02,0x00,0x00};
if(buffer[4] == 0x01){ //六轴
send2_2[4] = SC7U22_init;
}else if(buffer[4] == 0x02){ //地磁
send2_2[4] = MMC5603nj_init;
}else if(buffer[4] == 0x03){ //气压计
send2_2[4] = barometer_init;
}
send_data_to_ble_client(&send2_2,5);
break;
case 0x03: //开始/停止滑雪计算
if(buffer[4] == 0x01){ //开始滑雪计算
if(SC7U22_init == 0x10 || MMC5603nj_init == 0x20 || barometer_init == 0x30){ //传感器未进行初始化
u8 send2_3[5] = {0xBB,0xBE,0x02,0x00,0x00};
send_data_to_ble_client(&send2_3,5);
return;
}
start_clloct();
}else if(buffer[4] == 0x02){ //停止滑雪计算
stop_clloct();
}
break;
}
}
}
}
void le_user_app_send_event(size_t command, unsigned char* data, size_t size)
@ -234,6 +349,10 @@ void le_user_app_event_handler(struct sys_event* event){
send_data_to_ble_client(&device_buff,founds);
}
break;
case 0x02:
extern void test_func(void);
test_func();
break;
default:
break;
}
@ -242,14 +361,15 @@ void le_user_app_event_handler(struct sys_event* event){
case 0x00: //数据包类型为:指定传感器初始化
u8 send2_0[5] = {0xBB,0xBE,0x02,0x00,0x00};
if(event->u.app.buffer[4] == 0x01){ //六轴
stop_calibration();
// stop_calibration();
if (SL_SC7U22_Config() == 0) {
send2_0[4] = 0x00; //初始化失败
SC7U22_init = 0x10;
send_data_to_ble_client(&send2_0,5);
return;
SC7U22_init = 0x10; //初始化失败
}else{
SC7U22_init = 0x11;
}
start_calibration();
send2_0[4] = SC7U22_init;
send_data_to_ble_client(&send2_0,5);
// start_calibration();
}else if(event->u.app.buffer[4] == 0x02){ //地磁
if(mmc5603nj_init() == 0){
MMC5603nj_init = 0x20;
@ -261,15 +381,15 @@ void le_user_app_event_handler(struct sys_event* event){
send2_0[4] = MMC5603nj_init; //地磁初始化成功
send_data_to_ble_client(&send2_0,5);
}else if(event->u.app.buffer[4] == 0x03){ //气压计初始化
if(bmp280_init() != 0){
if(BMP280_init() != 0){
//初始化失败
BMP280_init = 0x30;
send2_0[4] = BMP280_init;
barometer_init = 0x30;
send2_0[4] = barometer_init;
send_data_to_ble_client(&send2_0,5);
return;
}
BMP280_init = 0x31;
send2_0[4] = BMP280_init; //气压计初始化成功
barometer_init = 0x31;
send2_0[4] = barometer_init; //气压计初始化成功
send_data_to_ble_client(&send2_0,5);
}
break;
@ -290,13 +410,13 @@ void le_user_app_event_handler(struct sys_event* event){
}else if(event->u.app.buffer[4] == 0x02){ //地磁
send2_2[4] = MMC5603nj_init;
}else if(event->u.app.buffer[4] == 0x03){ //气压计
send2_2[4] = BMP280_init;
send2_2[4] = barometer_init;
}
send_data_to_ble_client(&send2_2,5);
break;
case 0x03: //开始/停止滑雪计算
if(event->u.app.buffer[4] == 0x01){ //开始滑雪计算
if(SC7U22_init == 0x10 || MMC5603nj_init == 0x20 || BMP280_init == 0x30){ //传感器未进行初始化
if(SC7U22_init == 0x10 || MMC5603nj_init == 0x20 || barometer_init == 0x30){ //传感器未进行初始化
u8 send2_3[5] = {0xBB,0xBE,0x02,0x00,0x00};
send_data_to_ble_client(&send2_3,5);
return;

Binary file not shown.

Binary file not shown.

View File

@ -61,4 +61,4 @@ copy /b text.bin + data.bin + mov_slot.bin + data_code.bin + aec.bin + aac.bin +
del !bankfiles! common.bin text.bin data.bin bank.bin
copy eq_cfg_hw_less.bin eq_cfg_hw.bin
call download/earphone/download_app_ota.bat
call download/earphone/download.bat

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 -key AC69.key -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 -key 646-AC690X-7603.key
@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

@ -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 -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
@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

@ -11,7 +11,7 @@ copy ..\..\anc_coeff.bin .
copy ..\..\anc_gains.bin .
:: -format all -key AC690X-8029.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 -key AC690X-8029.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
@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

@ -62,6 +62,12 @@ SPI = 2_3_0_0;
UTTX = PB02;
UTBD = 1000000;
UTRX = PP00;
RESET = PA04_01_0;
[FW_ADDITIONAL]
FILE_LIST = (file = ota.bin: type = 100);
[RESERVED_CONFIG]

View File

@ -205,7 +205,7 @@ UTRX = CONFIG_UART_UPDATE_PIN; //串口升级[PB00 PB05 PA05]
/* RESET = CAT3(CONFIG_RESET_PIN, CONFIG_RESET_TIME, CONFIG_RESET_LEVEL); //port口_长按时间_有效电平长按时间有00、01、02、04、08三个值可选单位为秒当长按时间为00时则关闭长按复位功能。 */
#ifdef CONFIG_SUPPORT_RESET1
RESET1 = CAT3(CONFIG_RESET1_PIN, CONFIG_RESET1_TIME, CONFIG_RESET1_LEVEL); //port口_长按时间_有效电平长按时间有00、01、02、04、08三个值可选单位为秒当长按时间为00时则关闭长按复位功能。
RESET = CAT3(CONFIG_RESET1_PIN, CONFIG_RESET1_TIME, CONFIG_RESET1_LEVEL); //port口_长按时间_有效电平长按时间有00、01、02、04、08三个值可选单位为秒当长按时间为00时则关闭长按复位功能。
#endif
#ifdef CONFIG_VDDIO_LVD_LEVEL

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -19,16 +19,17 @@
#include "ble/ll_config.h"
// #define CONFIG_LE_FEATURES \
(\
LE_ENCRYPTION | \
LE_CORE_V50_FEATURES \
)
// (\
// LE_ENCRYPTION | \
// LE_CORE_V50_FEATURES \
// )
#define CONFIG_LE_FEATURES 0//(LE_ENCRYPTION)
// #define CONFIG_LE_FEATURES (LE_CORE_V50_FEATURES | LE_DATA_PACKET_LENGTH_EXTENSION)//(LE_ENCRYPTION)
#define CONFIG_LE_FEATURES 0
// #define CONFIG_LE_ROLES (LE_ADV|LE_SCAN|LE_INIT|LE_SLAVE|LE_MASTER)
// #define CONFIG_LE_ROLES (LE_ADV|LE_SCAN)
#define CONFIG_LE_ROLES (LE_ADV)
#define CONFIG_LE_ROLES (LE_ADV|LE_SCAN)
// #define CONFIG_LE_ROLES (LE_ADV)
#include "classic/lmp_config.h"