10 Commits

Author SHA1 Message Date
lmx
6c9ec6cec8 skiing_mtp 2025-12-11 10:49:13 +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
lmx
627780ea20 11月28日发客户的版本 2025-11-28 18:13:35 +08:00
lmx
ade4b0a1f8 feat: Add rfid feature and .gitignore file 2025-11-28 16:25:35 +08:00
lmx
818e8c3778 chore: Remove tracked build artifacts 2025-11-28 16:24:27 +08:00
lmx
892ed9267b feat: Add rfid feature and .gitignore file 2025-11-28 16:23:06 +08:00
1146 changed files with 1260 additions and 279845 deletions

16
.gitignore vendored
View File

@ -1,32 +1,16 @@
# 编译生成的目标文件
*.o
*.a
*.so
*.d
# 编译生成的最终产物
*.elf
*.bin
*.fw
*.ufw
*.map
*.lst
*.bc
# 编译产物目录
# 看起来你所有的编译结果都在 objs/ 目录下,直接忽略整个目录更方便
/objs/
# 工具链和构建产物
# 根据你的路径,这些文件也应该被忽略
/cpu/br28/tools/app.bin
/cpu/br28/tools/data_code.bin
/cpu/br28/tools/download/
/cpu/br28/tools/isd_config.ini
/cpu/br28/tools/sdk.elf*
/cpu/br28/tools/sdk.lst
/cpu/br28/tools/sdk.map
/cpu/br28/sdk_used_list.used
# VSCode 用户个人设置
# 团队协作时,每个人的配置可能不同,通常不建议提交

33
.vscode/settings.json vendored
View File

@ -1,33 +0,0 @@
{
"files.associations": {
"board_config.h": "c",
"board_jl701n_demo_cfg.h": "c",
"colorful_lights.h": "c",
"board_jl701n_anc_cfg.h": "c",
"update_loader_download.h": "c",
"iic_soft.h": "c",
"circle_buffer.h": "c",
"default_event_handler.h": "c",
"ui_manage.h": "c",
"charge.h": "c",
"app_main.h": "c",
"app_config.h": "c",
"app_action.h": "c",
"includes.h": "c",
"key_event_deal.h": "c",
"app_umidigi_chargestore.h": "c",
"hci_lmp.h": "c",
"bluetooth.h": "c",
"SCU722.C": "cpp",
"math.h": "c",
"avctp_user.h": "c",
"string.h": "c",
"dev_manager.h": "c",
"bt_tws.h": "c",
"skiing_tracker.h": "c",
"xtell.h": "c",
"debug.h": "c",
"ano_protocol.h": "c",
"board_jl701n_demo_global_build_cfg.h": "c"
}
}

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

@ -530,6 +530,7 @@ void JL_rcsp_msg_deal(void *hdl, u8 event, u8 *msg)
case MSG_JL_ENTER_UPDATE_MODE:
rcsp_printf("MSG_JL_ENTER_UPDATE_MODE:%x %x\n", msg[0], msg[1]);
clk_set("sys",96*1000000L);
bt_set_low_latency_mode(0);
if (support_dual_bank_update_en && !tws_api_get_role()) {
u8 status = 0;

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

@ -81,10 +81,10 @@ const struct task_info task_info_table[] = {
#if AUDIO_ENC_MPT_SELF_ENABLE
{"enc_mpt_self", 3, 0, 512, 128 },
#endif/*AUDIO_ENC_MPT_SELF_ENABLE*/
// {"update", 1, 0, 256, 0 },
// {"tws_ota", 2, 0, 256, 0 },
// {"tws_ota_msg", 2, 0, 256, 128 },
// {"dw_update", 2, 0, 256, 128 },
{"update", 1, 0, 256, 0 },
{"tws_ota", 2, 0, 256, 0 },
{"tws_ota_msg", 2, 0, 256, 128 },
{"dw_update", 2, 0, 256, 128 },
{"rcsp_task", 2, 0, 640, 128 },
// {"aud_capture", 4, 0, 512, 256 },
// {"data_export", 5, 0, 512, 256 },

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

@ -21,12 +21,12 @@
//*********************************************************************************//
// UART配置 //
//*********************************************************************************//
#define TCFG_UART0_ENABLE ENABLE_THIS_MOUDLE //串口打印模块使能
// #define TCFG_UART0_ENABLE 0 //串口打印模块使能
// #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_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配置 //
@ -47,7 +47,7 @@
*/
#define TCFG_HW_I2C0_PORTS 'B'
#define TCFG_HW_I2C0_CLK 1000000 //硬件IIC波特率:100k
#define TCFG_HW_I2C0_CLK 1000000 //硬件IIC波特率:400k
//*********************************************************************************//
// 硬件SPI 配置 //
@ -87,7 +87,7 @@
//*********************************************************************************//
// USB 配置 //
//*********************************************************************************//
#define TCFG_PC_ENABLE 1//DISABLE_THIS_MOUDLE//PC模块使能
#define TCFG_PC_ENABLE 0//DISABLE_THIS_MOUDLE//PC模块使能
#define TCFG_UDISK_ENABLE 0//ENABLE_THIS_MOUDLE//U盘模块使能
#define TCFG_OTG_USB_DEV_EN BIT(0)//USB0 = BIT(0) USB1 = BIT(1)
@ -729,7 +729,7 @@ DAC硬件上的连接方式,可选的配置:
// 充电舱/蓝牙测试盒/ANC测试三者为同级关系,开启任一功能都会初始化PP0通信接口 //
//*********************************************************************************//
#define TCFG_CHARGESTORE_ENABLE DISABLE_THIS_MOUDLE //是否支持智能充电舱
#define TCFG_TEST_BOX_ENABLE ENABLE_THIS_MOUDLE //是否支持蓝牙测试盒 //xtell
#define TCFG_TEST_BOX_ENABLE DISABLE_THIS_MOUDLE//ENABLE_THIS_MOUDLE //是否支持蓝牙测试盒 //xtell
#define TCFG_ANC_BOX_ENABLE CONFIG_ANC_ENABLE //是否支持ANC测试盒
#define TCFG_UMIDIGI_BOX_ENABLE DISABLE_THIS_MOUDLE //是否支持UMIDIGI充电舱 //xtell
#if TCFG_UMIDIGI_BOX_ENABLE
@ -807,7 +807,7 @@ DAC硬件上的连接方式,可选的配置:
// EQ配置 //
//*********************************************************************************//
//EQ配置使用在线EQ时EQ文件和EQ模式无效。有EQ文件时使能TCFG_USE_EQ_FILE,默认不用EQ模式切换功能
#define TCFG_EQ_ENABLE 1 //支持EQ功能,EQ总使能
#define TCFG_EQ_ENABLE 0 //支持EQ功能,EQ总使能
// #if TCFG_EQ_ENABLE
#define TCFG_EQ_ONLINE_ENABLE 0 //支持在线EQ调试,如果使用蓝牙串口调试,需要打开宏 APP_ONLINE_DEBUG否则默认使用uart调试(二选一)
#define TCFG_BT_MUSIC_EQ_ENABLE 1 //支持蓝牙音乐EQ
@ -1010,7 +1010,7 @@ DAC硬件上的连接方式,可选的配置:
//*********************************************************************************//
#define TCFG_USER_TWS_ENABLE 0 //tws功能使能
#define TCFG_USER_BLE_ENABLE 1 //BLE功能使能
#define TCFG_BT_SUPPORT_AAC 1 //AAC格式支持
#define TCFG_BT_SUPPORT_AAC 0 //AAC格式支持
#define TCFG_BT_SUPPORT_LDAC 0 //LDAC格式支持
#if TCFG_BT_SUPPORT_LDAC
@ -1084,7 +1084,7 @@ DAC硬件上的连接方式,可选的配置:
// 编解码格式配置(CodecFormat) //
//*********************************************************************************//
/*解码格式使能*/
#define TCFG_DEC_MP3_ENABLE ENABLE
#define TCFG_DEC_MP3_ENABLE DISABLE
#define TCFG_DEC_WTGV2_ENABLE ENABLE
#define TCFG_DEC_G729_ENABLE DISABLE
#define TCFG_DEC_WMA_ENABLE DISABLE
@ -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

@ -8,12 +8,12 @@
/* Following Macros Affect Periods Of Both Code Compiling And Post-build */
#define CONFIG_DOUBLE_BANK_ENABLE 0 //单双备份选择(若打开了改宏,FLASH结构变为双备份结构适用于接入第三方协议的OTA PS: JL-OTA同样支持双备份升级, 需要根据实际FLASH大小同时配置CONFIG_FLASH_SIZE)
#define CONFIG_APP_OTA_ENABLE 0 //是否支持RCSP升级(JL-OTA)
#define CONFIG_DOUBLE_BANK_ENABLE 1 //单双备份选择(若打开了改宏,FLASH结构变为双备份结构适用于接入第三方协议的OTA PS: JL-OTA同样支持双备份升级, 需要根据实际FLASH大小同时配置CONFIG_FLASH_SIZE)
#define CONFIG_APP_OTA_ENABLE 1 //是否支持RCSP升级(JL-OTA)
#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
@ -33,7 +33,7 @@
/* Following Macros Only For Post Bulid Configuaration */
#define CONFIG_DB_UPDATE_DATA_GENERATE_EN 0 //是否生成db_data.bin(用于第三方协议接入使用)
#define CONFIG_ONLY_GRENERATE_ALIGN_4K_CODE 0 //ufw只生成1份4K对齐的代码
#define CONFIG_ONLY_GRENERATE_ALIGN_4K_CODE 1 //ufw只生成1份4K对齐的代码
//config for supported chip version
#ifdef CONFIG_BR30_C_VERSION
@ -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
@ -65,8 +66,8 @@
#if CONFIG_APP_OTA_ENABLE
#define RCSP_UPDATE_EN 1 //是否支持rcsp升级
#if CONFIG_DOUBLE_BANK_ENABLE //双备份才能打开同步升级流程
#define OTA_TWS_SAME_TIME_ENABLE 1 //是否支持TWS同步升级
#define OTA_TWS_SAME_TIME_NEW 1 //使用新的tws ota流程
#define OTA_TWS_SAME_TIME_ENABLE 0 //是否支持TWS同步升级
#define OTA_TWS_SAME_TIME_NEW 0 //使用新的tws ota流程
#else
#define OTA_TWS_SAME_TIME_ENABLE 1//0 xtellota //是否支持TWS同步升级
#define OTA_TWS_SAME_TIME_NEW 1//0 //使用新的tws ota流程

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

@ -531,7 +531,7 @@ void skiing_tracker_update(skiing_tracker_t *tracker, float *acc_g, float *gyr_d
#if 0
#if 1
float linear_acc_device[3];
float linear_acc_world[3];
float tmp_world_acc[3];
@ -547,7 +547,7 @@ void skiing_tracker_update(skiing_tracker_t *tracker, float *acc_g, float *gyr_d
tmp_world_acc[2] * tmp_world_acc[2]);
static int count = 0;
if(count > 10){
if(count > 100){
xlog("===original(g): x %.2f, y %.2f, z %.2f===\n",acc_g[0],acc_g[1],acc_g[2]);
xlog("===world(m/s^2) no g: x %.2f, y %.2f, z %.2f, all %.2f===\n",tmp_world_acc[0],tmp_world_acc[1],tmp_world_acc[2],all_world_mag); //去掉重力加速度
xlog("===gyr(dps) : x %.2f, y %.2f, z %.2f===\n",gyr_dps[0],gyr_dps[1],gyr_dps[2]); //angle

View File

@ -6,6 +6,8 @@
#include "tone_player.h"
#include "ui_manage.h"
#include "gpio.h"
#include <math.h>
#include <string.h>
#include "app_main.h"
#include "asm/charge.h"
#include "update.h"
@ -24,6 +26,10 @@
#include "./sensor/MMC56.h"
#include "./sensor/BMP280.h"
#include "./sensor/AK8963.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
@ -36,7 +42,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组六轴数据
//
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -46,126 +55,226 @@
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 BLE_send_fuc(void);
//END -- 函数定义
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//START -- 变量定义
static u32 timer_offset_ms = 0;
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));
typedef struct {
// -- 六轴 --
signed short SC7U22_data[6];
// -- 磁力计 --
uint8_t mmc5603nj_buffer[9];
// -- 速度 --
uint16_t speed_cms;
// -- 气压计 --
int adc_P;
int adc_T;
} 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]; //缓冲区
extern u8 foot_init;
static OS_SEM receiver_ready_sem; // 用于启动同步的信号量
static const uart_bus_t *uart_bus = NULL;
static u16 test_id = 0;
//END -- 变量定义
//////////////////////////////////////////////////////////////////////////////////////////////////
/**
* @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]);
}
count++;
// 重置计时器
void reset_ms_timer(void) {
timer_offset_ms = sys_timer_get_ms();
xlog("Timer has been reset.\n");
}
// 获取从上次重置后经过的毫秒数
u32 get_ms_timer(void) {
return sys_timer_get_ms() - timer_offset_ms;
}
/**
* @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);
while(1){//4组地磁数据、16组六轴数据、1组气压计数据
interval++;
mmc5603nj_read_mag_data(&mmc5603nj_buffer);
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.speed_cms = speed;
// -- 放进缓冲区 --
if(circle_buffer_is_full(&BLE_send_buff) == 0){
circle_buffer_write(&BLE_send_buff, &BLE_send_data_tmp);
if(interval >= 4){
interval = 0;
SL_data_index = 0;
// bmp280_read_data(&temperature, &pressure);//每40ms读取一次
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字节
}
/**
@ -173,124 +282,98 @@ 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) + 数据(8) = 12字节
const uint8_t PT_PACKET_LEN = 12;
const uint8_t PT_PAYLOAD_LEN = 9; // 类型(1) + 数据(8)
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;
// 打包压力数据 data_to_send.adc_P (占 pt_packet[4] 到 pt_packet[7])
pt_packet[4] = (uint8_t)(data_to_send.adc_P & 0xFF); // 最低字节 (LSB)
pt_packet[5] = (uint8_t)((data_to_send.adc_P >> 8) & 0xFF);
pt_packet[6] = (uint8_t)((data_to_send.adc_P >> 16) & 0xFF);
pt_packet[7] = (uint8_t)((data_to_send.adc_P >> 24) & 0xFF); // 最高字节 (MSB)
// 打包温度数据 data_to_send.adc_T (占 pt_packet[8] 到 pt_packet[11])
pt_packet[8] = (uint8_t)(data_to_send.adc_T & 0xFF); // 最低字节 (LSB)
pt_packet[9] = (uint8_t)((data_to_send.adc_T >> 8) & 0xFF);
pt_packet[10] = (uint8_t)((data_to_send.adc_T >> 16) & 0xFF);
pt_packet[11] = (uint8_t)((data_to_send.adc_T >> 24) & 0xFF); // 最高字节 (MSB)
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];
// 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); // 发送数据
// 填充包头
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);
// data_log(send_buffer);
}
}
static u8 bmp280_test_id = 0;
// ------------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------------
/**
* @brief 开始采集传感器数据并通过ble发送
*
*/
void start_clloct(void){
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){
os_task_del("sensor_collect_task");
os_task_del("BLE_send_fuc");
}
/**
* @brief 初始化在app_main.c的app_main函数被调用
*
*/
void xtell_task_create(void){
#if TCFG_GSENOR_USER_IIC_TYPE
@ -309,25 +392,130 @@ 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();
bmp280_init();
extern void bmp280_test(void);
xlog("barometer start measeure\n");
// create_process(&bmp280_test_id,"bmp280_test",NULL, bmp280_test, 100);
float Temp = 0;
float Press = 0;
xlog("test_func\n");
bmp280_read_data(&Temp, &Press);
xlog("Temp:%.2f, Press:%.2f\n",Temp,Press);
}
/**
* @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
}
//////////////////////////////////////////////////////////////////////////////
//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 data_send_task(void){
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];
SL_SC7U22_FIFO_Read(accx_buf,accy_buf,accz_buf,gyrx_buf,gyry_buf,gyrz_buf); //一次性读取内置fifo的数据
#if 1
// 定义新的Packet ID和数据长度
#define PACKET_ID_RAW_IMU 0x04
#define PACKET_LENGTH_RAW_IMU 12 // 6个传感器值每个2字节
// 声明一个发送缓冲区用于包含帧头、ID、长度、数据和校验和
// 帧头 (2) + ID (1) + 长度 (1) + 数据 (12) + 校验和 (1) = 17 字节
uint8_t tx_buffer[2 + 1 + 1 + PACKET_LENGTH_RAW_IMU + 1];
uint8_t checksum = 0;
int i; // 用于循环计算校验和
// 填充帧头
tx_buffer[0] = 0xAA;
tx_buffer[1] = 0xFF;
// 填充Packet ID和长度
tx_buffer[2] = PACKET_ID_RAW_IMU;
tx_buffer[3] = PACKET_LENGTH_RAW_IMU;
// 填充原始传感器数据 (与你原先的processing_data内容相同)
tx_buffer[4] = (uint8_t)(accx_buf[0] & 0xFF); // accX LSB
tx_buffer[5] = (uint8_t)(accx_buf[0] >> 8 & 0xFF); // accX MSB
tx_buffer[6] = (uint8_t)(accy_buf[0] & 0xFF); // accY LSB
tx_buffer[7] = (uint8_t)(accy_buf[0] >> 8 & 0xFF); // accY MSB
tx_buffer[8] = (uint8_t)(accz_buf[0] & 0xFF); // accZ LSB
tx_buffer[9] = (uint8_t)(accz_buf[0] >> 8 & 0xFF); // accZ MSB
tx_buffer[10] = (uint8_t)(gyrx_buf[0] & 0xFF); // gyrX LSB
tx_buffer[11] = (uint8_t)(gyrx_buf[0] >> 8 & 0xFF); // gyrX MSB
tx_buffer[12] = (uint8_t)(gyry_buf[0] & 0xFF); // gyrY LSB
tx_buffer[13] = (uint8_t)(gyry_buf[0] >> 8 & 0xFF); // gyrY MSB
tx_buffer[14] = (uint8_t)(gyrz_buf[0] & 0xFF); // gyrZ LSB
tx_buffer[15] = (uint8_t)(gyrz_buf[0] >> 8 & 0xFF); // gyrZ MSB
// 计算校验和 (从 Packet ID 到所有数据字节的和)
checksum = tx_buffer[2] + tx_buffer[3]; // ID + Length
for (i = 0; i < PACKET_LENGTH_RAW_IMU; i++) {
checksum += tx_buffer[4 + i]; // 加上所有数据字节
}
tx_buffer[4 + PACKET_LENGTH_RAW_IMU] = checksum; // 校验和是最后一个字节
// 发送整个缓冲区
extern void uartSendData(void *buf, u16 len) ; // 确保u16是uint16_t或unsigned short
uartSendData(tx_buffer, sizeof(tx_buffer)); // 发送总共17字节
#endif
}
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();
bmp280_init();
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");
// create_process(&test_id, "sensor_test",NULL,data_send_task ,3);
// data_send_task();
}

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>

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
@ -1504,6 +1521,8 @@ unsigned char Q_SL_SC7U22_Angle_Output(unsigned char calibration_en, signed shor
SL_SC7U22_Error_cnt2 = 0;
SL_SC7U22_Error_cnt = 0;
for (sl_i = 0; sl_i < 6; sl_i++) Sum_Avg_Accgyro[sl_i] = Sum_Avg_Accgyro[sl_i] / 50;
Error_Accgyro[0] = 0 - Sum_Avg_Accgyro[0];
Error_Accgyro[1] = 0 - Sum_Avg_Accgyro[1];
#if ACC_RANGE==2
@ -1518,6 +1537,8 @@ unsigned char Q_SL_SC7U22_Angle_Output(unsigned char calibration_en, signed shor
Error_Accgyro[3] = 0 - Sum_Avg_Accgyro[3];
Error_Accgyro[4] = 0 - Sum_Avg_Accgyro[4];
Error_Accgyro[5] = 0 - Sum_Avg_Accgyro[5];
// xlog("AVG_Recode AX:%d,AY:%d,AZ:%d,GX:%d,GY:%d,GZ:%d\r\n", Sum_Avg_Accgyro[0], Sum_Avg_Accgyro[1], Sum_Avg_Accgyro[2], Sum_Avg_Accgyro[3], Sum_Avg_Accgyro[4], Sum_Avg_Accgyro[5]);
// xlog("Error_Recode AX:%d,AY:%d,AZ:%d,GX:%d,GY:%d,GZ:%d\r\n", Error_Accgyro[0], Error_Accgyro[1], Error_Accgyro[2], Error_Accgyro[3], Error_Accgyro[4], Error_Accgyro[5]);
}

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

@ -1,7 +1,7 @@
#ifndef XTELL_H
#define XTELL_H
#include "system/includes.h"
#include "generic/typedef.h"
// #define KS_BLE 1
#define XTELL_TEST 1

View File

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

View File

@ -83,17 +83,18 @@ 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] = "xtell_1";
static u16 play_poweron_ok_timer_id = 0;
// -- 初始化标志位 --
u8 SC7U22_init = 0x10; //六轴是否初始化
u8 MMC5603nj_init = 0x20; //地磁是否初始化
u8 BMP280_init = 0x30; //气压计初始化
u8 foot_init = 0x40; //数据来源初始化左脚0x41 or 右脚0x42
// -- 线程id --
u16 SC7U22_calibration_id;
u16 start_collect_fuc_id;
u16 BLE_send_fuc_id;
u16 gsensor_test_id = 0;
//
///////////////////////////////////////////////////////////////////////////////////////////////////
extern int bt_hci_event_handler(struct bt_event *bt);
@ -102,6 +103,11 @@ extern void create_process(u16* pid, const char* name, void *priv, void (*func)(
extern void close_process(u16* pid,char* name);
extern void start_collect_fuc(void);
extern void BLE_send_fuc(void);
extern void start_calibration(void);
extern void start_clloct(void);
extern void stop_clloct(void);
extern void set_foot_state(u8 state);
extern void stop_calibration(void);
///////////////////////////////////////////////////////////////////////////////////////////////////
/*
* 模式状态机, 通过start_app()控制状态切换
@ -185,6 +191,106 @@ 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_init() != 0){
//初始化失败
BMP280_init = 0x30;
send2_0[4] = BMP280_init;
send_data_to_ble_client(&send2_0,5);
return;
}
BMP280_init = 0x31;
send2_0[4] = BMP280_init; //气压计初始化成功
send_data_to_ble_client(&send2_0,5);
}
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] = BMP280_init;
}
send_data_to_ble_client(&send2_2,5);
break;
case 0x03: //开始/停止滑雪计算
if(buffer[4] == 0x01){ //开始滑雪计算
if(SC7U22_init == 0x10 || MMC5603nj_init == 0x20 || BMP280_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)
@ -213,6 +319,12 @@ void le_user_app_event_handler(struct sys_event* event){
if (event->u.app.buffer[0] == 0xBE && event->u.app.buffer[1] == 0xBB) {
if(event->u.app.buffer[2] == 0x01){ //后面的数据长度 1
switch (event->u.app.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;
@ -222,6 +334,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;
}
@ -230,13 +346,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();
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;
}
create_process(&SC7U22_calibration_id,"SC7U22_calibration",NULL,SC7U22_static_calibration,10);
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;
@ -260,29 +378,37 @@ void le_user_app_event_handler(struct sys_event* event){
send_data_to_ble_client(&send2_0,5);
}
break;
case 0x01: //数据包类型为:获取指定传感器初始化状态
u8 send2_1[5] = {0xBB,0xBE,0x02,0x00,0x00};
if(event->u.app.buffer[4] == 0x01){ //六轴
send2_1[4] = SC7U22_init;
}else if(event->u.app.buffer[4] == 0x02){ //地磁
send2_1[4] = MMC5603nj_init;
}else if(event->u.app.buffer[4] == 0x03){ //气压计
send2_1[4] = BMP280_init;
case 0x01: //设置传感器采集对象左脚or右脚
u8 send2_1[9] = {0xBB,0xBE,0x06,0x05,0x00,0x00,0x00,0x00,0x00};
if(event->u.app.buffer[4] == 0x01){ //设定数据来源是左脚
foot_init = 0x41;
}else if(event->u.app.buffer[4] == 0x02){//设定数据来源是右脚
foot_init = 0x42;
}
send_data_to_ble_client(&send2_1,5);
send2_1[4] = foot_init;
send_data_to_ble_client(&send2_1,9);
break;
case 0x02: //开始/停止滑雪计算
case 0x02: //数据包类型为:获取指定传感器初始化状态
u8 send2_2[5] = {0xBB,0xBE,0x02,0x00,0x00};
if(event->u.app.buffer[4] == 0x01){ //六轴
send2_2[4] = SC7U22_init;
}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;
}
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){ //传感器未进行初始化
u8 send2_2[5] = {0xBB,0xBE,0x02,0x00,0x00};
send_data_to_ble_client(&send2_2,5);
u8 send2_3[5] = {0xBB,0xBE,0x02,0x00,0x00};
send_data_to_ble_client(&send2_3,5);
return;
}
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,1);
start_clloct();
}else if(event->u.app.buffer[4] == 0x02){ //停止滑雪计算
close_process(&start_collect_fuc_id,"start_collect");
close_process(&BLE_send_fuc_id,"BLE_send_fuc");
stop_clloct();
}
break;
}

View File

@ -253,6 +253,7 @@
_MASK_MEM_BEGIN = ABSOLUTE(0x19fc00);
_MASK_MEM_SIZE = ABSOLUTE(0x1a4);
EXTERN(
_start
@ -274,25 +275,14 @@ cvsd_decoder
pcm_decoder
mp3_decoder
wtgv2_decoder
aac_decoder
cvsd_encoder
msbc_encoder
audio_dac_driver
);
UPDATA_SIZE = 0x80;
@ -428,7 +418,8 @@ SECTIONS
battery_notify_begin = .;
*(.battery_notify)
battery_notify_end = .;
. = ALIGN(4);
. = ALIGN(4);
__VERSION_BEGIN = .;
KEEP(*(.sys.version))
__VERSION_END = .;
@ -518,6 +509,7 @@ SECTIONS
*(.audio_track_data)
*(.audio_adc_data)
. = ALIGN(4);
*(.data*)
@ -726,6 +718,7 @@ SECTIONS
} > ram0
data_code_pc_limit_end = .;
__report_overlay_end = .;
@ -815,6 +808,7 @@ SECTIONS
}
SECTIONS
{
.data : ALIGN(4)
@ -846,6 +840,7 @@ SECTIONS
UPDATE_CODE_TOTAL_SIZE = update_code_end - update_code_start;
}
SECTIONS
{
.data : ALIGN(4)
@ -948,6 +943,7 @@ BTSTACK_LE_HOST_MESH_RAM_TOTAL = BTSTACK_LE_HOST_MESH_DATA_SIZE + BTSTACK_LE_HOS
BTSTACK_LE_HOST_MESH_FLASH_TOTAL = BTSTACK_LE_HOST_MESH_CODE_SIZE;
BTSTACK_CODE_SIZE = (btstack_code_end - btstack_code_start) + (btstack_data_end - btstack_data_start);
SECTIONS
{
.data : ALIGN(4)
@ -1241,6 +1237,7 @@ SECTIONS
*(.os_code)
} > ram0
}
SECTIONS
{
.data : ALIGN(4)
@ -1450,6 +1447,7 @@ SECTIONS
BTCTLER_RAM_TOTAL = (btctler_data_end - btctler_data_start) + (btctler_bss_end - btctler_bss_start);
BTCTLER_CODE_TOTAL = (btctler_code_end - btctler_code_start);
}
SECTIONS
{
.data : ALIGN(4)
@ -1567,7 +1565,8 @@ SECTIONS
*(.timer.text.cache.L1)
*(.gpio.text.cache.L1)
*(.iic_hw.text.cache.L1)
driver_data_code_end = .;
driver_data_code_end = .;
. = ALIGN(4);
} > ram0
@ -1577,6 +1576,7 @@ SECTIONS
DRIVER_DATA_CODE_TOTAL = (driver_data_code_end - driver_data_code_start);
}
SECTIONS
{
.data : ALIGN(4)
@ -2016,6 +2016,7 @@ SECTIONS
} > ram0
}
text_begin = ADDR(.text);
text_size = SIZEOF(.text);
text_end = text_begin + text_size;

View File

@ -33,19 +33,7 @@ cvsd_decoder
pcm_decoder
mp3_decoder
wtgv2_decoder
aac_decoder
cvsd_encoder

View File

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

@ -14,13 +14,12 @@
[EXTRA_CFG_PARAM]
NEW_FLASH_FS = YES;
BR22_TWS_DB = YES;
FLASH_SIZE = 0x100000;
BR22_TWS_VERSION = 0;
FORCE_4K_ALIGN = YES;
SPECIAL_OPT = 0;
CHIP_NAME = AC701N;
ENTRY = 0x6000100;
PID = AC701N;
@ -63,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 it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

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"

Some files were not shown because too many files have changed in this diff Show More