Compare commits
12 Commits
627780ea20
...
0feb648d11
| Author | SHA1 | Date | |
|---|---|---|---|
| 0feb648d11 | |||
| 5a72132d2a | |||
| 2f4e1d7e5b | |||
| 3f02a9f9be | |||
| 6ce9deebe6 | |||
| 96891516b8 | |||
| 52e4b62b53 | |||
| ea610c24d3 | |||
| 45158aebcf | |||
| 138275a04b | |||
| 89f1c93f74 | |||
| 8c2db49083 |
1
Makefile
1
Makefile
@ -628,6 +628,7 @@ c_SRC_FILES := \
|
|||||||
apps/earphone/xtell_Sensor/sensor/MMC56.c \
|
apps/earphone/xtell_Sensor/sensor/MMC56.c \
|
||||||
apps/earphone/xtell_Sensor/sensor/BMP280.c \
|
apps/earphone/xtell_Sensor/sensor/BMP280.c \
|
||||||
apps/earphone/xtell_Sensor/sensor/AK8963.c \
|
apps/earphone/xtell_Sensor/sensor/AK8963.c \
|
||||||
|
apps/earphone/xtell_Sensor/sensor/WF282A.c \
|
||||||
|
|
||||||
|
|
||||||
# 需要编译的 .S 文件
|
# 需要编译的 .S 文件
|
||||||
|
|||||||
@ -49,7 +49,7 @@
|
|||||||
#include "classic/tws_api.h"
|
#include "classic/tws_api.h"
|
||||||
#include "rcsp_adv_user_update.h"
|
#include "rcsp_adv_user_update.h"
|
||||||
#include "bt_tws.h"
|
#include "bt_tws.h"
|
||||||
|
// #include "le_trans_data.h"
|
||||||
#if (TCFG_BLE_DEMO_SELECT == DEF_BLE_DEMO_ADV_RCSP)
|
#if (TCFG_BLE_DEMO_SELECT == DEF_BLE_DEMO_ADV_RCSP)
|
||||||
|
|
||||||
#if TCFG_CHARGE_BOX_ENABLE
|
#if TCFG_CHARGE_BOX_ENABLE
|
||||||
@ -86,8 +86,10 @@ static const char user_tag_string[] = {EIR_TAG_STRING};
|
|||||||
/* #include "debug.h" */
|
/* #include "debug.h" */
|
||||||
|
|
||||||
//------
|
//------
|
||||||
#define ATT_LOCAL_PAYLOAD_SIZE (200) //note: need >= 20
|
// #define ATT_LOCAL_PAYLOAD_SIZE (200*10) //note: need >= 20
|
||||||
#define ATT_SEND_CBUF_SIZE (512) //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:
|
#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)));
|
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 const uint8_t connection_update_enable = 1; ///0--disable, 1--enable
|
||||||
static uint8_t connection_update_cnt = 0; //
|
static uint8_t connection_update_cnt = 0; //
|
||||||
static const struct conn_update_param_t connection_param_table[] = {
|
static const struct conn_update_param_t connection_param_table[] = {
|
||||||
{16, 24, 16, 600},
|
{6, 12, 0, 400},//3.7
|
||||||
{12, 28, 14, 600},//11
|
// {16, 24, 16, 600},
|
||||||
{8, 20, 20, 600},//3.7
|
// {12, 28, 14, 600},//11
|
||||||
|
// {8, 20, 20, 600},//3.7
|
||||||
/* {12, 28, 4, 600},//3.7 */
|
/* {12, 28, 4, 600},//3.7 */
|
||||||
/* {12, 24, 30, 600},//3.05 */
|
/* {12, 24, 30, 600},//3.05 */
|
||||||
};
|
};
|
||||||
@ -299,6 +302,17 @@ void test_data_send_packet(void)
|
|||||||
|
|
||||||
static void can_send_now_wakeup(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');
|
putchar('E');
|
||||||
if (ble_resume_send_wakeup) {
|
if (ble_resume_send_wakeup) {
|
||||||
ble_resume_send_wakeup();
|
ble_resume_send_wakeup();
|
||||||
@ -315,6 +329,24 @@ u8 ble_update_get_ready_jump_flag(void)
|
|||||||
return 0;
|
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
|
* @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);
|
connection_update_complete_success(packet);
|
||||||
break;
|
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;
|
break;
|
||||||
|
|
||||||
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
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;
|
mtu = att_event_mtu_exchange_complete_get_MTU(packet) - 3;
|
||||||
log_info("ATT MTU = %u\n", mtu);
|
log_info("ATT MTU = %u\n", mtu);
|
||||||
ble_user_cmd_prepare(BLE_CMD_ATT_MTU_SIZE, 1, mtu);
|
ble_user_cmd_prepare(BLE_CMD_ATT_MTU_SIZE, 1, mtu);
|
||||||
|
set_connection_data_length(251, 2120);//xtell
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HCI_EVENT_VENDOR_REMOTE_TEST:
|
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);
|
ret = ble_user_cmd_prepare(BLE_CMD_ATT_SEND_DATA, 4, handle, data, len, handle_type);
|
||||||
if (ret == BLE_BUFFER_FULL) {
|
if (ret == BLE_BUFFER_FULL) {
|
||||||
|
printf("app_send_user_data: buffer full\n");
|
||||||
ret = APP_BLE_BUFF_FULL;
|
ret = APP_BLE_BUFF_FULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1663,12 +1707,8 @@ void send_version_to_sibling(void)
|
|||||||
data[2] = ver >> 8;
|
data[2] = ver >> 8;
|
||||||
tws_api_send_data_to_sibling(data, sizeof(data), TWS_FUNC_ID_SEQ_RAND_SYNC);
|
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)
|
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;
|
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);
|
int ret = app_send_user_data(ATT_CHARACTERISTIC_ae02_01_VALUE_HANDLE, data, length, ATT_OP_NOTIFY);
|
||||||
if (ret == 0) { // 假设 0 表示成功
|
if (ret == 0) { // 假设 0 表示成功
|
||||||
@ -1686,7 +1726,12 @@ void send_data_to_ble_client(const u8* data, u16 length)
|
|||||||
} else {
|
} else {
|
||||||
// printf("Failed to send data: Length %d, Error code: %d\n", length, ret);
|
// printf("Failed to send data: Length %d, Error code: %d\n", length, ret);
|
||||||
}
|
}
|
||||||
} else {
|
// } else {
|
||||||
// printf("Insufficient buffer space to send data: Length %d\n", length);
|
// printf("Insufficient buffer space to send data: Length %d\n", length);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -81,9 +81,9 @@ extern void printf_buf(u8 *buf, u32 len);
|
|||||||
|
|
||||||
//------
|
//------
|
||||||
//ATT发送的包长, note: 20 <=need >= MTU
|
//ATT发送的包长, note: 20 <=need >= MTU
|
||||||
#define ATT_LOCAL_MTU_SIZE (200) //
|
#define ATT_LOCAL_MTU_SIZE (517) //200
|
||||||
//ATT缓存的buffer大小, note: need >= 20,可修改
|
//ATT缓存的buffer大小, note: need >= 20,可修改
|
||||||
#define ATT_SEND_CBUF_SIZE (512) //
|
#define ATT_SEND_CBUF_SIZE (512 * 20) //
|
||||||
|
|
||||||
//共配置的RAM
|
//共配置的RAM
|
||||||
#define ATT_RAM_BUFSIZE (ATT_CTRL_BLOCK_SIZE + ATT_LOCAL_MTU_SIZE + ATT_SEND_CBUF_SIZE) //note:
|
#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[] = {
|
static const struct conn_update_param_t connection_param_table[] = {
|
||||||
{16, 24, 10, 600},//11
|
{6, 12, 0, 400},//11
|
||||||
{12, 28, 10, 600},//3.7
|
// {16, 24, 10, 600},//11
|
||||||
{8, 20, 10, 600},
|
// {12, 28, 10, 600},//3.7
|
||||||
|
// {8, 20, 10, 600},
|
||||||
/* {12, 28, 4, 600},//3.7 */
|
/* {12, 28, 4, 600},//3.7 */
|
||||||
/* {12, 24, 30, 600},//3.05 */
|
/* {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;
|
u16 handle = att_handle;
|
||||||
|
|
||||||
log_info("write_callback, handle= 0x%04x,size = %d\n", handle, buffer_size);
|
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) {
|
switch (handle) {
|
||||||
|
|
||||||
@ -1389,6 +1392,44 @@ void hangup_ans_call_handle(u8 en)
|
|||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -37,7 +37,7 @@ extern void printf_buf(u8 *buf, u32 len);
|
|||||||
//------
|
//------
|
||||||
//ATT发送的包长, note: 20 <=need >= MTU
|
//ATT发送的包长, note: 20 <=need >= MTU
|
||||||
#define ATT_LOCAL_MTU_SIZE (517) //
|
#define ATT_LOCAL_MTU_SIZE (517) //
|
||||||
//ATT缓存的buffer大小, note: need >= 20,可修改
|
//ATT缓存的buffer大小, +: need >= 20,可修改
|
||||||
#if(APP_MAIN == APP_WIRELESS_MIC_2T1)
|
#if(APP_MAIN == APP_WIRELESS_MIC_2T1)
|
||||||
#define ATT_SEND_CBUF_SIZE (90)
|
#define ATT_SEND_CBUF_SIZE (90)
|
||||||
#else
|
#else
|
||||||
@ -92,7 +92,8 @@ static uint8_t connection_update_cnt = 0; //
|
|||||||
|
|
||||||
//参数表
|
//参数表
|
||||||
static const struct conn_update_param_t connection_param_table[] = {
|
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:
|
case HCI_SUBEVENT_LE_DATA_LENGTH_CHANGE:
|
||||||
log_info("APP HCI_SUBEVENT_LE_DATA_LENGTH_CHANGE\n");
|
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;
|
break;
|
||||||
|
|
||||||
case HCI_SUBEVENT_LE_PHY_UPDATE_COMPLETE:
|
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;
|
mtu = att_event_mtu_exchange_complete_get_MTU(packet) - 3;
|
||||||
log_info("ATT MTU = %u\n", mtu);
|
log_info("ATT MTU = %u\n", mtu);
|
||||||
ble_op_att_set_send_mtu(mtu);
|
ble_op_att_set_send_mtu(mtu);
|
||||||
set_connection_data_length(251, 2120);
|
// set_connection_data_length(251, 2120);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HCI_EVENT_VENDOR_REMOTE_TEST:
|
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
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -717,7 +717,7 @@ struct port_wakeup port0 = {
|
|||||||
.pullup_down_enable = ENABLE, //配置I/O 内部上下拉是否使能
|
.pullup_down_enable = ENABLE, //配置I/O 内部上下拉是否使能
|
||||||
.edge = FALLING_EDGE, //唤醒方式选择,可选:上升沿\下降沿
|
.edge = FALLING_EDGE, //唤醒方式选择,可选:上升沿\下降沿
|
||||||
.filter = PORT_FLT_8ms,
|
.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)
|
#if (TCFG_TEST_BOX_ENABLE || TCFG_CHARGESTORE_ENABLE || TCFG_ANC_BOX_ENABLE || TCFG_UMIDIGI_BOX_ENABLE)
|
||||||
|
|||||||
@ -23,10 +23,10 @@
|
|||||||
//*********************************************************************************//
|
//*********************************************************************************//
|
||||||
#define TCFG_UART0_ENABLE ENABLE_THIS_MOUDLE //串口打印模块使能
|
#define TCFG_UART0_ENABLE ENABLE_THIS_MOUDLE //串口打印模块使能
|
||||||
// #define TCFG_UART0_ENABLE 0 //串口打印模块使能
|
// #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_TX_PORT IO_PORT_DP //串口发送脚配置
|
||||||
// #define TCFG_UART0_BAUDRATE 1000000 //串口波特率配置
|
#define TCFG_UART0_BAUDRATE 1000000 //串口波特率配置
|
||||||
#define TCFG_UART0_BAUDRATE 115200 //串口波特率配置
|
// #define TCFG_UART0_BAUDRATE 115200 //串口波特率配置
|
||||||
|
|
||||||
//*********************************************************************************//
|
//*********************************************************************************//
|
||||||
// IIC配置 //
|
// IIC配置 //
|
||||||
@ -47,7 +47,7 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
#define TCFG_HW_I2C0_PORTS 'B'
|
#define TCFG_HW_I2C0_PORTS 'B'
|
||||||
#define TCFG_HW_I2C0_CLK 1000000 //硬件IIC波特率:100k
|
#define TCFG_HW_I2C0_CLK 1000000 //硬件IIC波特率:400k
|
||||||
|
|
||||||
//*********************************************************************************//
|
//*********************************************************************************//
|
||||||
// 硬件SPI 配置 //
|
// 硬件SPI 配置 //
|
||||||
@ -791,7 +791,7 @@ DAC硬件上的连接方式,可选的配置:
|
|||||||
//*********************************************************************************//
|
//*********************************************************************************//
|
||||||
#define TCFG_LOWPOWER_POWER_SEL PWR_DCDC15 //电源模式设置,可选DCDC和LDO
|
#define TCFG_LOWPOWER_POWER_SEL PWR_DCDC15 //电源模式设置,可选DCDC和LDO
|
||||||
#define TCFG_LOWPOWER_BTOSC_DISABLE 0 //低功耗模式下BTOSC是否保持
|
#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_VDDIOM_LEVEL VDDIOM_VOL_30V //vddiom等级
|
||||||
#define TCFG_LOWPOWER_OSC_TYPE OSC_TYPE_LRC //低功耗晶振类型,btosc/lrc
|
#define TCFG_LOWPOWER_OSC_TYPE OSC_TYPE_LRC //低功耗晶振类型,btosc/lrc
|
||||||
#if (TCFG_AUDIO_ASR_DEVELOP && TCFG_CVP_DEVELOP_ENABLE)
|
#if (TCFG_AUDIO_ASR_DEVELOP && TCFG_CVP_DEVELOP_ENABLE)
|
||||||
@ -1130,7 +1130,7 @@ DAC硬件上的连接方式,可选的配置:
|
|||||||
//*********************************************************************************//
|
//*********************************************************************************//
|
||||||
#if TCFG_USER_BLE_ENABLE
|
#if TCFG_USER_BLE_ENABLE
|
||||||
#define DUEROS_DMA_EN 0
|
#define DUEROS_DMA_EN 0
|
||||||
#define TRANS_DATA_EN 0//1 //xtellota
|
// #define TRANS_DATA_EN 0//1 //xtellota
|
||||||
#define BLE_HID_EN 0
|
#define BLE_HID_EN 0
|
||||||
|
|
||||||
#if (DUEROS_DMA_EN)
|
#if (DUEROS_DMA_EN)
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
#define CONFIG_UPDATE_JUMP_TO_MASK 0 //配置升级到loader的方式0为直接reset,1为跳转(适用于芯片电源由IO口KEEP住的方案,需要注意检查跳转前是否将使用DMA的硬件模块全部关闭)
|
#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_UPDATE_WITH_MD5_CHECK_EN 0 //配置升级是否支持MD5校验
|
||||||
|
|
||||||
#define CONFIG_ANC_ENABLE 0 //配置是否支持ANC
|
#define CONFIG_ANC_ENABLE 0 //配置是否支持ANC
|
||||||
@ -73,8 +73,8 @@
|
|||||||
|
|
||||||
#if CONFIG_IO_KEY_EN
|
#if CONFIG_IO_KEY_EN
|
||||||
#define CONFIG_SUPPORT_RESET1
|
#define CONFIG_SUPPORT_RESET1
|
||||||
#define CONFIG_RESET1_PIN PB01 //io pin
|
#define CONFIG_RESET1_PIN PA04 //io pin
|
||||||
#define CONFIG_RESET1_TIME 08 //unit:second
|
#define CONFIG_RESET1_TIME 01 //unit:second
|
||||||
#define CONFIG_RESET1_LEVEL 0 //tigger level(0/1)
|
#define CONFIG_RESET1_LEVEL 0 //tigger level(0/1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -21,9 +21,10 @@
|
|||||||
#define CONFIG_APP_BT_ENABLE
|
#define CONFIG_APP_BT_ENABLE
|
||||||
|
|
||||||
#ifdef 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_BTMATE_EN 0
|
||||||
#define RCSP_ADV_EN 1
|
#define RCSP_ADV_EN 0
|
||||||
#define AI_APP_PROTOCOL 0
|
#define AI_APP_PROTOCOL 0
|
||||||
#define LL_SYNC_EN 0
|
#define LL_SYNC_EN 0
|
||||||
#define TUYA_DEMO_EN 0
|
#define TUYA_DEMO_EN 0
|
||||||
|
|||||||
@ -204,6 +204,18 @@ int app_protocol_sys_event_handler(struct sys_event *event);
|
|||||||
#define EARPHONE_STATE_SNIFF(a)
|
#define EARPHONE_STATE_SNIFF(a)
|
||||||
#define EARPHONE_STATE_ROLE_SWITCH(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
|
#else
|
||||||
int adv_earphone_state_init();
|
int adv_earphone_state_init();
|
||||||
int adv_earphone_state_set_page_scan_enable();
|
int adv_earphone_state_set_page_scan_enable();
|
||||||
|
|||||||
@ -232,7 +232,8 @@ const uint64_t config_btctler_le_features = LE_ENCRYPTION;
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
const int config_btctler_le_roles = (LE_ADV | LE_SLAVE);
|
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
|
#endif
|
||||||
#else
|
#else
|
||||||
const int config_btctler_le_roles = 0;
|
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 int config_btctler_le_afh_en = 0;
|
||||||
const u32 config_vendor_le_bb = 0;
|
const u32 config_vendor_le_bb = 0;
|
||||||
|
|
||||||
const int config_btctler_le_rx_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_packet_length = 27;
|
||||||
const int config_btctler_le_acl_total_nums = 5;
|
// 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
|
#endif
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|||||||
@ -9,11 +9,19 @@ void circle_buffer_init(circle_buffer_t *cb, void *buffer, u16 capacity, u16 ele
|
|||||||
cb->head = 0;
|
cb->head = 0;
|
||||||
cb->tail = 0;
|
cb->tail = 0;
|
||||||
cb->size = 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) {
|
bool circle_buffer_write(circle_buffer_t *cb, const void *element) {
|
||||||
|
os_mutex_pend(&cb->mutex, 0);
|
||||||
if (circle_buffer_is_full(cb)) {
|
if (circle_buffer_is_full(cb)) {
|
||||||
|
os_mutex_post(&cb->mutex);
|
||||||
return false; // 缓冲区已满
|
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->head = (cb->head + 1) % cb->capacity;
|
||||||
cb->size++;
|
cb->size++;
|
||||||
|
os_mutex_post(&cb->mutex);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从环形缓冲区读取一个元素
|
// 从环形缓冲区读取一个元素
|
||||||
bool circle_buffer_read(circle_buffer_t *cb, void *element) {
|
bool circle_buffer_read(circle_buffer_t *cb, void *element) {
|
||||||
|
os_mutex_pend(&cb->mutex, 0);
|
||||||
if (circle_buffer_is_empty(cb)) {
|
if (circle_buffer_is_empty(cb)) {
|
||||||
|
os_mutex_post(&cb->mutex);
|
||||||
return false; // 缓冲区为空
|
return false; // 缓冲区为空
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,25 +47,38 @@ bool circle_buffer_read(circle_buffer_t *cb, void *element) {
|
|||||||
|
|
||||||
cb->tail = (cb->tail + 1) % cb->capacity;
|
cb->tail = (cb->tail + 1) % cb->capacity;
|
||||||
cb->size--;
|
cb->size--;
|
||||||
|
os_mutex_post(&cb->mutex);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取已用空间的大小(以元素为单位)
|
// 获取已用空间的大小(以元素为单位)
|
||||||
u16 circle_buffer_get_size(circle_buffer_t *cb) {
|
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) {
|
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) {
|
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) {
|
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;
|
||||||
}
|
}
|
||||||
@ -2,6 +2,7 @@
|
|||||||
#define CIRCLE_BUFFER_H
|
#define CIRCLE_BUFFER_H
|
||||||
|
|
||||||
#include "system/includes.h"
|
#include "system/includes.h"
|
||||||
|
#include "os/os_api.h"
|
||||||
|
|
||||||
// 定义环形缓冲区的结构体
|
// 定义环形缓冲区的结构体
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -11,6 +12,7 @@ typedef struct {
|
|||||||
u16 head; // 头部指针(写入位置,以元素为单位)
|
u16 head; // 头部指针(写入位置,以元素为单位)
|
||||||
u16 tail; // 尾部指针(读取位置,以元素为单位)
|
u16 tail; // 尾部指针(读取位置,以元素为单位)
|
||||||
u16 size; // 当前已用大小(以元素为单位)
|
u16 size; // 当前已用大小(以元素为单位)
|
||||||
|
OS_MUTEX mutex; // 用于保护缓冲区的互斥锁
|
||||||
} circle_buffer_t;
|
} circle_buffer_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,6 +24,12 @@ typedef struct {
|
|||||||
*/
|
*/
|
||||||
void circle_buffer_init(circle_buffer_t *cb, void *buffer, u16 capacity, u16 element_size);
|
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 向环形缓冲区写入一个元素
|
* @brief 向环形缓冲区写入一个元素
|
||||||
* @param cb 指向环形缓冲区结构体的指针
|
* @param cb 指向环形缓冲区结构体的指针
|
||||||
|
|||||||
@ -26,9 +26,11 @@
|
|||||||
#include "./sensor/MMC56.h"
|
#include "./sensor/MMC56.h"
|
||||||
#include "./sensor/BMP280.h"
|
#include "./sensor/BMP280.h"
|
||||||
#include "./sensor/AK8963.h"
|
#include "./sensor/AK8963.h"
|
||||||
|
#include "./sensor/WF282A.h"
|
||||||
#include "asm/rtc.h"
|
#include "asm/rtc.h"
|
||||||
#include "system/timer.h"
|
#include "system/timer.h"
|
||||||
#include "adv_time_stamp_setting.h"
|
#include "adv_time_stamp_setting.h"
|
||||||
|
#include "btstack/le/le_user.h"
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//宏定义
|
//宏定义
|
||||||
#define ENABLE_XLOG 1
|
#define ENABLE_XLOG 1
|
||||||
@ -41,7 +43,10 @@
|
|||||||
#define xlog(format, ...) ((void)0)
|
#define xlog(format, ...) ((void)0)
|
||||||
#endif
|
#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);
|
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 create_process(u16* pid, const char* name, void *priv, void (*func)(void *priv), u32 msec);
|
||||||
extern void close_process(u16* pid,char* name);
|
extern void close_process(u16* pid,char* name);
|
||||||
void start_collect_fuc(void);
|
|
||||||
void BLE_send_fuc(void);
|
void BLE_send_fuc(void);
|
||||||
//END -- 函数定义
|
//END -- 函数定义
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -61,35 +65,31 @@ void BLE_send_fuc(void);
|
|||||||
//START -- 变量定义
|
//START -- 变量定义
|
||||||
static u32 timer_offset_ms = 0;
|
static u32 timer_offset_ms = 0;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct{
|
||||||
// -- 六轴 --
|
signed short SC7U22_data[6]; //12字节
|
||||||
signed short SC7U22_data[6];
|
int mmc5603nj_buffer[3]; //12字节
|
||||||
// -- 磁力计 --
|
int16_t temperature; //2
|
||||||
uint8_t mmc5603nj_buffer[9];
|
uint32_t pressure; //4
|
||||||
// -- 速度 --
|
}sensor_package_t __attribute__((packed));
|
||||||
uint16_t speed_cms;
|
|
||||||
// -- 气压计 --
|
|
||||||
int16_t temperature;
|
|
||||||
uint32_t pressure;
|
|
||||||
// -- 左/右腿 --
|
|
||||||
uint8_t foot_state; //1:左脚;2:右脚
|
|
||||||
// -- 时间 --
|
|
||||||
u32 timestamp_ms;
|
|
||||||
|
|
||||||
} BLE_send_data_t;
|
typedef struct{
|
||||||
|
uint8_t checkout_1;
|
||||||
static int count = 0;
|
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; // 环形缓冲区管理结构体
|
static circle_buffer_t g_ble_send_cb; // 环形缓冲区管理结构体
|
||||||
BLE_send_data_t BLE_send_data[SENSOR_DATA_BUFFER_SIZE];
|
static ble_send_data_t g_sensor_data_storage[SENSOR_DATA_BUFFER_SIZE]; //缓冲区
|
||||||
|
|
||||||
// -- 任务id --
|
extern u8 foot_init;
|
||||||
u16 SC7U22_calibration_id;
|
static OS_SEM receiver_ready_sem; // 用于启动同步的信号量
|
||||||
u16 start_collect_fuc_id;
|
|
||||||
u16 BLE_send_fuc_id;
|
|
||||||
static u8 stop_ble_send_fuc_id;
|
|
||||||
|
|
||||||
|
static const uart_bus_t *uart_bus = NULL;
|
||||||
|
|
||||||
|
static u16 test_id = 0;
|
||||||
//END -- 变量定义
|
//END -- 变量定义
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -105,110 +105,181 @@ u32 get_ms_timer(void) {
|
|||||||
return sys_timer_get_ms() - timer_offset_ms;
|
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){
|
void sensor_collect_task(void){
|
||||||
// xlog("=======sensor_read_data START\n");
|
static ble_send_data_t send_data;
|
||||||
static signed short combined_raw_data[6];
|
mmc5603nj_mag_data_t mmc5603nj_buffer;
|
||||||
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];
|
|
||||||
|
|
||||||
float temperature = 0;
|
float temperature = 0;
|
||||||
float pressure = 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;
|
||||||
|
|
||||||
// -- 读数据 --
|
while(1){//4组地磁数据、16组六轴数据、1组气压计数据
|
||||||
SL_SC7U22_RawData_Read(acc_data_buf,gyr_data_buf);
|
interval++;
|
||||||
mmc5603nj_read_origin_data(mmc5603nj_buffer);
|
mmc5603nj_read_mag_data(&mmc5603nj_buffer);
|
||||||
// bmp280_read_originanl_data(&BLE_send_data_tmp.adc_P, &BLE_send_data_tmp.adc_T);
|
for(int i = (interval-1)*4; i < interval*4; i++){
|
||||||
bmp280_read_data(&temperature, &pressure);
|
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));
|
SL_SC7U22_FIFO_Read(accx_buf,accy_buf,accz_buf,gyrx_buf,gyry_buf,gyrz_buf); //一次性读取内置fifo的数据
|
||||||
memcpy(&combined_raw_data[3], gyr_data_buf, 3 * sizeof(signed short));
|
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
|
||||||
|
|
||||||
// -- 四元数 --
|
// 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]);
|
||||||
status = Q_SL_SC7U22_Angle_Output(0, combined_raw_data, angle,NULL, 0, quaternion_output);
|
#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(interval >= 4){
|
||||||
if(circle_buffer_is_full(&BLE_send_buff) == 0){
|
interval = 0;
|
||||||
circle_buffer_write(&BLE_send_buff, &BLE_send_data_tmp);
|
SL_data_index = 0;
|
||||||
|
#if BMP280
|
||||||
|
bmp280_read_data(&temperature, &pressure);//每40ms读取一次
|
||||||
|
#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,187 +287,92 @@ void start_collect_fuc(void){
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void BLE_send_fuc(void){
|
void BLE_send_fuc(void){
|
||||||
BLE_send_data_t data_to_send;
|
ble_send_data_t send_data;
|
||||||
|
uint8_t send_buffer[484];
|
||||||
if (circle_buffer_is_empty(&BLE_send_buff) == 0) {
|
while(1){
|
||||||
circle_buffer_read(&BLE_send_buff, &data_to_send);
|
os_sem_pend(&receiver_ready_sem, 0); //阻塞等待
|
||||||
} else {
|
circle_buffer_read(&g_ble_send_cb, &send_data);
|
||||||
// 缓冲区为空,直接返回
|
|
||||||
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;
|
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
// 填充包头
|
for (int i = 0; i < MPU_FIFO_LEN; i++) {
|
||||||
imu_packet[0] = 0xBB;
|
sensor_package_t *pkg = &send_data.sensor_package[i];
|
||||||
imu_packet[1] = 0xBE;
|
|
||||||
imu_packet[2] = IMU_PAYLOAD_LEN;
|
// 1. 打包六轴数据 (6 * int16_t)
|
||||||
imu_packet[3] = IMU_TYPE;
|
for (int j = 0; j < 6; j++) {
|
||||||
// 拷贝六轴数据
|
*p++ = (uint8_t)(pkg->SC7U22_data[j] & 0xFF);
|
||||||
// memcpy(&imu_packet[4], data_to_send.SC7U22_data, sizeof(data_to_send.SC7U22_data));
|
*p++ = (uint8_t)((pkg->SC7U22_data[j] >> 8) & 0xFF);
|
||||||
for (int i = 0; i < 6; i++) {
|
}
|
||||||
// SC7U22_data[i] 是一个 signed short (2字节)
|
|
||||||
// 将其低字节放在前面
|
// 2. 打包地磁数据 (3 * int32_t)
|
||||||
imu_packet[4 + i * 2] = (uint8_t)(data_to_send.SC7U22_data[i] & 0xFF);
|
for (int j = 0; j < 3; j++) {
|
||||||
// 将其高字节放在后面
|
*p++ = (uint8_t)(pkg->mmc5603nj_buffer[j] & 0xFF);
|
||||||
imu_packet[4 + i * 2 + 1] = (uint8_t)((data_to_send.SC7U22_data[i] >> 8) & 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];
|
|
||||||
|
|
||||||
// 填充包头
|
extern void uartSendData(void *buf, u16 len) ; // 确保u16是uint16_t或unsigned short
|
||||||
mag_packet[0] = 0xBB;
|
uartSendData(send_buffer, 484); // 发送总共17字节
|
||||||
mag_packet[1] = 0xBE;
|
send_data_to_ble_client(send_buffer, 484); // 发送数据
|
||||||
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;
|
|
||||||
|
|
||||||
// 直接发送 int16_t 的二进制补码
|
// data_log(send_buffer);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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发送
|
* @brief 开始采集传感器数据并通过ble发送
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void start_clloct(void){
|
void start_clloct(void){
|
||||||
reset_ms_timer();
|
os_task_create(sensor_collect_task,NULL,5,1024,32,"sensor_collect_task");
|
||||||
create_process(&start_collect_fuc_id,"start_collect",NULL,start_collect_fuc,10);
|
os_task_create(BLE_send_fuc,NULL,5,1024,32,"BLE_send_fuc");
|
||||||
create_process(&BLE_send_fuc_id,"BLE_send_fuc",NULL,BLE_send_fuc,5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 停止采集和ble发送
|
* @brief 停止采集和ble发送
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void stop_clloct(void){
|
void stop_clloct(void){
|
||||||
close_process(&start_collect_fuc_id,"start_collect");
|
os_task_del("sensor_collect_task");
|
||||||
close_process(&BLE_send_fuc_id,"BLE_send_fuc");
|
os_task_del("BLE_send_fuc");
|
||||||
// create_process(&stop_ble_send_fuc_id,"stop_BLE_send_fuc",NULL,stop_BLE_send_fuc,500); //等缓冲区内容发送完,才停止ble发送任务
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -421,39 +397,89 @@ void xtell_task_create(void){
|
|||||||
|
|
||||||
xlog("xtell_task_create\n");
|
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();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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
|
//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
|
|
||||||
}
|
|
||||||
@ -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 "BMP280.h"
|
||||||
#include <string.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)
|
* @return 补偿后的温度值 (单位: °C)
|
||||||
*/
|
*/
|
||||||
static float compensate_temperature(int32_t adc_T) {
|
static float compensate_temperature(int32_t adc_T) {
|
||||||
|
#if 1
|
||||||
float var1, var2, temperature;
|
float var1, var2, temperature;
|
||||||
|
|
||||||
var1 = (((float)adc_T) / 16384.0f - ((float)t1) / 1024.0f) * ((float)t2);
|
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;
|
if (temperature > 85.0f) return 85.0f;
|
||||||
|
|
||||||
return temperature;
|
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)
|
* @return 补偿后的气压值 (单位: Pa)
|
||||||
*/
|
*/
|
||||||
static float compensate_pressure(int32_t adc_P) {
|
static float compensate_pressure(int32_t adc_P) {
|
||||||
|
#if 1
|
||||||
float var1, var2, pressure;
|
float var1, var2, pressure;
|
||||||
|
|
||||||
var1 = ((float)t_fine / 2.0f) - 64000.0f;
|
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;
|
if (pressure > 110000.0f) return 110000.0f;
|
||||||
|
|
||||||
return pressure;
|
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 id;
|
||||||
uint8_t calib_data[24];
|
uint8_t calib_data[24];
|
||||||
|
|
||||||
// 1. 检查芯片ID
|
// 1. 检查芯片ID
|
||||||
if (bmp280_read_regs(BMP280_REG_ID, &id, 1) == 0) {
|
if (bmp280_read_regs(BMP280_REG_ID, &id, 1) == 0) {
|
||||||
printf("bmp280 get id error:%d\n",id );
|
printf("bmp280 get id error:%d\n",id );
|
||||||
return 1; // I2C读取失败
|
// return 1; // I2C读取失败
|
||||||
}
|
}
|
||||||
if (id != 0x58) {
|
if (id != 0x58) {
|
||||||
printf("bmp280 check diff:%d\n",id );
|
printf("bmp280 check diff:%d\n",id );
|
||||||
return 1; // ID不匹配
|
// return 1; // ID不匹配
|
||||||
}
|
}
|
||||||
printf("bmp280 get id:0%X\n",id );
|
printf("bmp280 get id:0%X\n",id );
|
||||||
|
|
||||||
|
|||||||
@ -8,11 +8,11 @@
|
|||||||
|
|
||||||
// I2C 从设备地址
|
// I2C 从设备地址
|
||||||
#if BMP_PULL_UP == 1 //外部接的高
|
#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_WRITE_ADDRESS (BMP_IIC_7BIT_ADDRESS<<1) //8位地址
|
||||||
#define BMP_IIC_READ_ADDRESS (BMP_IIC_WRITE_ADDRESS | 0x01)
|
#define BMP_IIC_READ_ADDRESS (BMP_IIC_WRITE_ADDRESS | 0x01)
|
||||||
#else
|
#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_WRITE_ADDRESS (BMP_IIC_7BIT_ADDRESS<<1) //8位地址
|
||||||
#define BMP_IIC_READ_ADDRESS (BMP_IIC_WRITE_ADDRESS | 0x01)
|
#define BMP_IIC_READ_ADDRESS (BMP_IIC_WRITE_ADDRESS | 0x01)
|
||||||
#endif
|
#endif
|
||||||
@ -33,7 +33,7 @@
|
|||||||
* @return 0: 成功, 1: 芯片ID错误, 2: 读取校准参数失败
|
* @return 0: 成功, 1: 芯片ID错误, 2: 读取校准参数失败
|
||||||
* @note 此函数会完成ID检查、软复位、读取校准参数,并设置传感器为连续测量模式。
|
* @note 此函数会完成ID检查、软复位、读取校准参数,并设置传感器为连续测量模式。
|
||||||
*/
|
*/
|
||||||
uint8_t bmp280_init(void);
|
uint8_t BMP280_init(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 从BMP280读取温度和气压数据
|
* @brief 从BMP280读取温度和气压数据
|
||||||
|
|||||||
@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
MMC5603nj
|
||||||
|
1-255的采样率,这里设置为200Hz,5ms
|
||||||
|
*/
|
||||||
|
|
||||||
#include "MMC56.h"
|
#include "MMC56.h"
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
@ -41,13 +45,15 @@ int mmc5603nj_init(void) {
|
|||||||
|
|
||||||
// 设置20位分辨率 (BW[1:0] = 11)
|
// 设置20位分辨率 (BW[1:0] = 11)
|
||||||
// 同时确保所有轴都使能 (X/Y/Z_inhibit = 0)
|
// 同时确保所有轴都使能 (X/Y/Z_inhibit = 0)
|
||||||
|
// mmc5603nj_write_reg(MMC_INCTRL1, 0x03);
|
||||||
mmc5603nj_write_reg(MMC_INCTRL1, 0x03);
|
mmc5603nj_write_reg(MMC_INCTRL1, 0x03);
|
||||||
os_time_dly(1);
|
os_time_dly(1);
|
||||||
|
|
||||||
// 设置内部控制寄存器2
|
// 设置内部控制寄存器2
|
||||||
// CMM_EN = 1 (使能连续模式功能)
|
// CMM_EN = 1 (使能连续模式功能)
|
||||||
// HPOWER = 1 (高功耗模式,更稳定)
|
// HPOWER = 0
|
||||||
mmc5603nj_write_reg(MMC_INCTRL2, 0x90); // 0b10010000
|
// mmc5603nj_write_reg(MMC_INCTRL2, 0x10); // 0b00010000
|
||||||
|
mmc5603nj_write_reg(MMC_INCTRL2, 0x10); // 0b10010000
|
||||||
|
|
||||||
// 设置自动SET/RESET功能
|
// 设置自动SET/RESET功能
|
||||||
// AUTO_SR_EN = 1
|
// AUTO_SR_EN = 1
|
||||||
@ -56,7 +62,8 @@ int mmc5603nj_init(void) {
|
|||||||
g_continuous_mode_enabled = 0;
|
g_continuous_mode_enabled = 0;
|
||||||
printf("MMC5603NJ initialized successfully.\n");
|
printf("MMC5603NJ initialized successfully.\n");
|
||||||
|
|
||||||
mmc5603nj_enable_continuous_mode(0x04);
|
// mmc5603nj_enable_continuous_mode(0xC8); //200Hz的采样率,最高支持255
|
||||||
|
mmc5603nj_enable_continuous_mode(0xCF);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -195,7 +202,7 @@ void mmc5603nj_read_mag_data(mmc5603nj_mag_data_t *mag_data) {
|
|||||||
} while ((status & 0x40) == 0 && timeout > 0);
|
} while ((status & 0x40) == 0 && timeout > 0);
|
||||||
|
|
||||||
if (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;
|
mag_data->x = mag_data->y = mag_data->z = 0.0f;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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)
|
static void sl_delay(unsigned char sl_i)
|
||||||
{
|
{
|
||||||
os_time_dly(sl_i);
|
delay((int)sl_i);
|
||||||
}
|
}
|
||||||
|
|
||||||
char iic_read_len;
|
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, 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, 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, 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, 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
|
#if ACC_RANGE==2
|
||||||
SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x41, 0x00);//ACC_RANGE 00:±2G
|
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, 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, 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, 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, 0x43, 0x00);//GYR_RANGE 2000dps
|
||||||
SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x04, 0x50);//COM_CFG
|
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 Acc_FIFO_Num;
|
||||||
unsigned char Gyr_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)
|
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 char header[2];
|
||||||
unsigned short j;
|
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
|
#if SL_SC7U22_WAIT_FIFO_LEN_ENABLE==0x00
|
||||||
while((fifo_num1&0x20)!=0x20)
|
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);
|
SL_SC7U22_I2c_Spi_Read(SL_SPI_IIC_INTERFACE, 0x20,1,&fifo_num2);
|
||||||
if((fifo_num1&0x10)==0x10)
|
if((fifo_num1&0x10)==0x10)
|
||||||
{
|
{
|
||||||
fifo_num=2048;
|
// fifo_num=2048; // 原始代码,会导致溢出
|
||||||
|
fifo_num = 2048; // 传感器FIFO已满,但我们的缓冲区只有1024字节,所以最多读1024字节
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -349,10 +355,15 @@ unsigned short SL_SC7U22_FIFO_Read(signed short *accx_buf,signed short *accy_buf
|
|||||||
}
|
}
|
||||||
#endif
|
#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_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, 0x00);//BY PASS MODE
|
||||||
// SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x1D, 0x20);//Stream 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
|
#if SL_Sensor_Algo_Release_Enable==0x00
|
||||||
// xlog("0x1F:0x%x 0x20:0x%x\n",fifo_num1,fifo_num2);
|
// xlog("0x1F:0x%x 0x20:0x%x\n",fifo_num1,fifo_num2);
|
||||||
// xlog("SC7U22_FIFO_NUM1:%d\n",fifo_num);
|
// 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])) ;
|
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])) ;
|
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])) ;
|
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;
|
i = i + 6;
|
||||||
Acc_FIFO_Num++;
|
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])) ;
|
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])) ;
|
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])) ;
|
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;
|
i = i + 6;
|
||||||
Gyr_FIFO_Num++;
|
Gyr_FIFO_Num++;
|
||||||
}
|
}
|
||||||
@ -400,9 +411,15 @@ unsigned short SL_SC7U22_FIFO_Read(signed short *accx_buf,signed short *accy_buf
|
|||||||
{
|
{
|
||||||
i = i + 2;
|
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;
|
return fifo_len;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -14,7 +14,7 @@ Copyright (c) 2022 Silan MEMS. All Rights Reserved.
|
|||||||
//是否使能串口打印调试
|
//是否使能串口打印调试
|
||||||
#define SL_Sensor_Algo_Release_Enable 0x00
|
#define SL_Sensor_Algo_Release_Enable 0x00
|
||||||
//是否开启FIFO模式,默认STREAM模式
|
//是否开启FIFO模式,默认STREAM模式
|
||||||
#define SL_SC7U22_FIFO_ENABLE 0x00
|
#define SL_SC7U22_FIFO_ENABLE 0x01
|
||||||
|
|
||||||
|
|
||||||
/***使用前请根据实际情况配置以下参数******/
|
/***使用前请根据实际情况配置以下参数******/
|
||||||
|
|||||||
@ -3,76 +3,95 @@
|
|||||||
*/
|
*/
|
||||||
#include "wf282a.h"
|
#include "wf282a.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdint.h> // 推荐使用标准类型
|
#include <stdint.h>
|
||||||
#include "gSensor/gSensor_manage.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 内部定义 */
|
/* WF282A 内部定义 */
|
||||||
/*==================================================================================*/
|
/*==================================================================================*/
|
||||||
|
|
||||||
// 存储校准系数的静态全局变量
|
// 存储校准系数的静态全局变量
|
||||||
static int16_t c0, c1, c01, c11, c20, c21, c30;
|
static int16_t c0, c1, c01, c11, c20, c21, c30;
|
||||||
static int32_t c00, c10;
|
static int32_t c00, c10;
|
||||||
|
|
||||||
/*==================================================================================*/
|
/*==================================================================================*/
|
||||||
/* 封装的底层I2C读写函数 */
|
/* 封装的底层I2C读写函数 (Provided by user) */
|
||||||
/*==================================================================================*/
|
/*==================================================================================*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 写入单个字节到WF282A寄存器
|
* @brief 写入单个字节到WF282A寄存器
|
||||||
*/
|
*/
|
||||||
static void wf282a_write_reg(uint8_t reg, uint8_t data) {
|
static void wf282a_write_reg(uint8_t reg, uint8_t data) {
|
||||||
gravity_sensor_command(WF_IIC_WRITE_ADDRESS, reg, data);
|
gravity_sensor_command(WF_IIC_WRITE_ADDRESS, reg, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 从WF282A读取多个字节
|
* @brief 从WF282A读取多个字节
|
||||||
*/
|
*/
|
||||||
static uint32_t wf282a_read_regs(uint8_t reg, uint8_t *buf, uint8_t len) {
|
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);
|
return _gravity_sensor_get_ndata(WF_IIC_READ_ADDRESS, reg, buf, len);
|
||||||
}
|
}
|
||||||
|
/*==================================================================================*/
|
||||||
|
/* Delay functions (Copied from manufacturer's code for consistency) */
|
||||||
|
/*==================================================================================*/
|
||||||
|
|
||||||
|
|
||||||
/*==================================================================================*/
|
/*==================================================================================*/
|
||||||
/* 内部辅助函数 */
|
/* 内部辅助函数 */
|
||||||
/*==================================================================================*/
|
/*==================================================================================*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 从缓冲区中解析所有校准系数
|
* @brief 从缓冲区中解析所有校准系数
|
||||||
* @param buf 包含从寄存器0x10开始读取的18个字节的校准数据
|
* @param buf 包含从寄存器0x10开始读取的18个字节的校准数据
|
||||||
*/
|
*/
|
||||||
static void parse_calibration_data(const uint8_t *buf) {
|
static void parse_calibration_data(const uint8_t *buf) {
|
||||||
// c0 (12-bit)
|
// c0 (12-bit)
|
||||||
c0 = ((int16_t)buf[0] << 4) | (buf[1] >> 4);
|
// 制造商: (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 & (1 << 11)) c0 |= 0xF000;
|
||||||
|
|
||||||
// c1 (12-bit)
|
// c1 (12-bit)
|
||||||
c1 = (((int16_t)buf[1] & 0x0F) << 8) | buf[2];
|
// 制造商: tempbuf[2] + ((tempbuf[1] & 0x0F)<<8);
|
||||||
|
c1 = (((int16_t)buf[1] & 0x0F) << 8) | buf[2];
|
||||||
if (c1 & (1 << 11)) c1 |= 0xF000;
|
if (c1 & (1 << 11)) c1 |= 0xF000;
|
||||||
|
|
||||||
// c00 (20-bit)
|
// c00 (20-bit)
|
||||||
c00 = ((int32_t)buf[3] << 12) | ((int32_t)buf[4] << 4) | (buf[5] >> 4);
|
// 制造商: (((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 & (1 << 19)) c00 |= 0xFFF00000;
|
||||||
|
|
||||||
// c10 (20-bit)
|
// c10 (20-bit)
|
||||||
c10 = (((int32_t)buf[5] & 0x0F) << 16) | ((int32_t)buf[6] << 8) | buf[7];
|
// 制造商: (((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 & (1 << 19)) c10 |= 0xFFF00000;
|
||||||
|
|
||||||
// c01, c11, c20, c21, c30 (16-bit)
|
// c01, c11, c20, c21, c30 (16-bit)
|
||||||
c01 = (int16_t)((uint16_t)buf[8] << 8 | buf[9]);
|
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]);
|
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]);
|
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]);
|
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]);
|
c30 = (int16_t)((uint16_t)buf[16] << 8 | buf[17]);
|
||||||
|
if (c30 > 0x7fff) c30 = c30 - 0x10000; // 制造商的符号扩展
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 获取原始温度值 (ADC)
|
* @brief 获取原始温度值 (ADC)
|
||||||
|
* 在连续测量模式下,只需读取数据寄存器,无需触发或等待。
|
||||||
*/
|
*/
|
||||||
static int32_t Get_Traw() {
|
static int32_t Get_Traw() {
|
||||||
uint8_t buff[3];
|
uint8_t buff[3];
|
||||||
int32_t Traw;
|
int32_t Traw;
|
||||||
// 从 MSB 寄存器 WF_TMP_B2 (0x03) 开始连续读取3个字节
|
// 从 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)
|
// 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];
|
Traw = (int32_t)buff[0] << 16 | (int32_t)buff[1] << 8 | (int32_t)buff[2];
|
||||||
// 24位二进制补码转32位
|
// 24位二进制补码转32位
|
||||||
@ -81,15 +100,18 @@ static int32_t Get_Traw() {
|
|||||||
}
|
}
|
||||||
return Traw;
|
return Traw;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 获取原始气压值 (ADC)
|
* @brief 获取原始气压值 (ADC)
|
||||||
|
* 在连续测量模式下,只需读取数据寄存器,无需触发或等待。
|
||||||
*/
|
*/
|
||||||
static int32_t Get_Praw() {
|
static int32_t Get_Praw() {
|
||||||
uint8_t buff[3];
|
uint8_t buff[3];
|
||||||
int32_t Praw;
|
int32_t Praw;
|
||||||
// 从 MSB 寄存器 WF_PRS_B2 (0x00) 开始连续读取3个字节
|
// 从 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)
|
// 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];
|
Praw = (int32_t)buff[0] << 16 | (int32_t)buff[1] << 8 | (int32_t)buff[2];
|
||||||
// 24位二进制补码转32位
|
// 24位二进制补码转32位
|
||||||
@ -98,76 +120,101 @@ static int32_t Get_Praw() {
|
|||||||
}
|
}
|
||||||
return Praw;
|
return Praw;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*==================================================================================*/
|
/*==================================================================================*/
|
||||||
/* 4. 外部接口函数实现 */
|
/* 4. 外部接口函数实现 */
|
||||||
/*==================================================================================*/
|
/*==================================================================================*/
|
||||||
|
|
||||||
uint8_t WF_Init() {
|
uint8_t WF_Init() {
|
||||||
uint8_t calib_buf[18];
|
uint8_t calib_buf[18];
|
||||||
uint8_t check_cfg;
|
// 1. 软复位
|
||||||
|
wf282a_write_reg(WF_RESET_REG, 0x09);
|
||||||
// 1. 配置传感器工作模式
|
delay(100); // 复位后等待100ms
|
||||||
// 推荐配置:压力8次过采样,温度1次过采样,测量速率16Hz
|
// 2. 读取校准系数
|
||||||
wf282a_write_reg(WF_PRS_CFG, (PM_RATE_16 << 4) | PM_PRC_8);
|
if (wf282a_read_regs(COEF_C0, calib_buf, 18) != 18) { // 检查是否成功读取18字节
|
||||||
wf282a_write_reg(WF_TMP_CFG, (TMP_RATE_16 << 4) | TMP_PRC_1 | TMP_INT_SENSOR);
|
xlog("Failed to read the calibration coefficient\n");
|
||||||
wf282a_write_reg(WF_MEAS_CFG, 0x07); // 启动连续压力和温度测量
|
|
||||||
wf282a_write_reg(WF_CFG_REG, 0x00); // 无中断或FIFO移位配置
|
|
||||||
|
|
||||||
// 2. 一次性读取所有校准系数 (从0x10到0x21,共18字节)
|
|
||||||
if (wf282a_read_regs(COEF_C0, calib_buf, 18) != 0) {
|
|
||||||
return 2; // 读取校准数据失败
|
return 2; // 读取校准数据失败
|
||||||
}
|
}
|
||||||
parse_calibration_data(calib_buf);
|
parse_calibration_data(calib_buf);
|
||||||
|
|
||||||
// 3. 检查配置是否写入成功
|
// DEBUG: 打印解析后的校准系数
|
||||||
wf282a_read_regs(WF_MEAS_CFG, &check_cfg, 1);
|
xlog("Parsed Coefficients: c0=%d, c1=%d, c00=%ld, c10=%ld, c01=%d, c11=%d, c20=%d, c21=%d, c30=%d\n",
|
||||||
if (check_cfg != 0x07) {
|
c0, c1, c00, c10, c01, c11, c20, c21, c30);
|
||||||
return 1; // 错误
|
|
||||||
} else {
|
|
||||||
return 0; // 成功
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#if 0 //test:0
|
||||||
|
// 3. 配置压力、温度和通用寄存器为连续测量模式
|
||||||
|
// 压力配置: 32Hz测量速率 (PM_RATE_32), 16x过采样 (PM_PRC_16) -> 0x54
|
||||||
|
wf282a_write_reg(WF_PRS_CFG, (PM_RATE_32 << 4) | PM_PRC_16);
|
||||||
|
// 温度配置: 内部传感器 (TMP_INT_SENSOR), 32Hz测量速率 (TMP_RATE_32), 16x过采样 (TMP_PRC_16) -> 0x54
|
||||||
|
wf282a_write_reg(WF_TMP_CFG, TMP_INT_SENSOR | (TMP_RATE_32 << 4) | TMP_PRC_16);
|
||||||
|
// 通用配置寄存器 (保持制造商的0x0C配置)
|
||||||
|
wf282a_write_reg(WF_CFG_REG, 0x0C);
|
||||||
|
// 4. 启动连续测量模式 (同时测量压力和温度)
|
||||||
|
// 0x06: Continuous Pressure and Temperature measurement
|
||||||
|
wf282a_write_reg(WF_MEAS_CFG, 0x06);
|
||||||
|
// 首次启动连续测量后,需要等待一个完整的转换周期才能获取有效数据。
|
||||||
|
// 16x过采样的转换时间约为27.6ms,32Hz测量速率下数据每31.25ms更新。
|
||||||
|
// 所以在此处等待至少32ms,确保第一次读取时有有效数据。
|
||||||
|
delay(40); // 稍长一点的延迟,确保传感器开始正常工作
|
||||||
|
#else
|
||||||
|
|
||||||
|
wf282a_write_reg(WF_PRS_CFG, 0x07);
|
||||||
|
wf282a_write_reg(WF_TMP_CFG, 0x87);
|
||||||
|
wf282a_write_reg(WF_CFG_REG, 0x0C);
|
||||||
|
wf282a_write_reg(WF_MEAS_CFG, 0x07);//后台连续测量温度和压力
|
||||||
|
delay(40); // 稍长一点的延迟,确保传感器开始正常工作
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
extern uint8_t WF_GetID();
|
||||||
|
WF_GetID();
|
||||||
|
return 0; // 成功
|
||||||
|
}
|
||||||
void WF_Sleep() {
|
void WF_Sleep() {
|
||||||
wf282a_write_reg(WF_MEAS_CFG, 0x00); // 待机模式
|
wf282a_write_reg(WF_MEAS_CFG, 0x00); // 待机模式
|
||||||
}
|
}
|
||||||
|
|
||||||
void WF_Wakeup() {
|
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 WF_GetID() {
|
||||||
uint8_t id;
|
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;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
float WF_Temperature_Calculate() {
|
float WF_Temperature_Calculate() {
|
||||||
float Traw_sc;
|
float Traw_sc;
|
||||||
int32_t Traw = Get_Traw();
|
int32_t Traw = Get_Traw();
|
||||||
|
Traw_sc = (float)Traw / KT; // 缩放原始温度值 (KT is now 16x scale factor)
|
||||||
Traw_sc = (float)Traw / KT; // 缩放原始温度值
|
|
||||||
return (float)c0 * 0.5f + (float)c1 * Traw_sc;
|
return (float)c0 * 0.5f + (float)c1 * Traw_sc;
|
||||||
}
|
}
|
||||||
|
|
||||||
float WF_Pressure_Calculate() {
|
float WF_Pressure_Calculate() {
|
||||||
float Traw_sc, Praw_sc, Pcomp;
|
float Traw_sc, Praw_sc, Pcomp;
|
||||||
int32_t Traw = Get_Traw();
|
int32_t Traw = Get_Traw();
|
||||||
int32_t Praw = Get_Praw();
|
int32_t Praw = Get_Praw();
|
||||||
|
Traw_sc = (float)Traw / KT; // 缩放原始温度值 (KT is now 16x scale factor)
|
||||||
Traw_sc = (float)Traw / KT; // 缩放原始温度值
|
Praw_sc = (float)Praw / KP; // 缩放原始压力值 (KP is now 16x scale factor)
|
||||||
Praw_sc = (float)Praw / KP; // 缩放原始压力值
|
// 补偿公式 (与制造商提供的公式一致)
|
||||||
|
|
||||||
// 公式: 手册给出
|
|
||||||
Pcomp = (float)c00
|
Pcomp = (float)c00
|
||||||
+ Praw_sc * ((float)c10 + Praw_sc * ((float)c20 + Praw_sc * (float)c30))
|
+ Praw_sc * ((float)c10 + Praw_sc * ((float)c20 + Praw_sc * (float)c30))
|
||||||
+ Traw_sc * (float)c01
|
+ Traw_sc * (float)c01
|
||||||
+ Traw_sc * Praw_sc * ((float)c11 + Praw_sc * (float)c21);
|
+ Traw_sc * Praw_sc * ((float)c11 + Praw_sc * (float)c21);
|
||||||
|
|
||||||
return Pcomp;
|
return Pcomp;
|
||||||
}
|
}
|
||||||
|
void WF_GET_Temperature_Pressure(float* temperature, float* precessure){
|
||||||
|
int32_t Traw = Get_Traw();
|
||||||
|
int32_t Praw = Get_Praw();
|
||||||
|
float Traw_sc = (float)Traw / KT; // 缩放原始温度值 (KT is now 16x scale factor)
|
||||||
|
float Praw_sc = (float)Praw / KP; // 缩放原始压力值 (KP is now 16x scale factor)
|
||||||
|
*temperature = (float)c0 * 0.5f + (float)c1 * Traw_sc;
|
||||||
|
*precessure = (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);
|
||||||
|
}
|
||||||
float WF_Altitude_Calculate() {
|
float WF_Altitude_Calculate() {
|
||||||
float pressure_pa = WF_Pressure_Calculate();
|
float pressure_pa = WF_Pressure_Calculate();
|
||||||
// 使用标准大气压公式计算海拔
|
// 使用标准大气压公式计算海拔
|
||||||
|
|||||||
@ -1,18 +1,26 @@
|
|||||||
#ifndef _WF282A_H_
|
#ifndef _WF282A_H_
|
||||||
#define _WF282A_H_
|
#define _WF282A_H_
|
||||||
|
|
||||||
#include <stdint.h> // 使用标准整数类型
|
#include <stdint.h> // 使用标准整数类型
|
||||||
|
|
||||||
// 标定值
|
// 标定值 (调整为16x过采样对应的Scale Factor)
|
||||||
#define KT 524288.0f
|
/*
|
||||||
#define KP 1572864.0f
|
Oversampling Rate Scale Factor (kP or kT)
|
||||||
|
1 (single) 524288
|
||||||
|
2 times (Low Power) 1572864
|
||||||
#define WF_PULL_UP 1 //外部是否接的上拉
|
4 times 3670016
|
||||||
|
8 times 7864320
|
||||||
|
16 times (Standard) 253952 <--- 使用此值
|
||||||
|
32 times 516096
|
||||||
|
64 times (High Precision) 1040384
|
||||||
|
128 times 2088960
|
||||||
|
*/
|
||||||
|
#define KT 2088960.0f // 温度 (16x过采样)
|
||||||
|
#define KP 2088960.0f // 压力 (16x过采样)
|
||||||
|
|
||||||
|
#define WF_PULL_UP 0 //外部是否接的上拉
|
||||||
// I2C 从设备地址
|
// I2C 从设备地址
|
||||||
#if WF_PULL_UP == 1 //外部接的高
|
#if WF_PULL_UP == 0 //外部接高为0x77
|
||||||
#define WF_IIC_7BIT_ADDRESS 0x77 //7位,外部接高为0x77
|
#define WF_IIC_7BIT_ADDRESS 0x77
|
||||||
#define WF_IIC_WRITE_ADDRESS (WF_IIC_7BIT_ADDRESS<<1) //8位地址
|
#define WF_IIC_WRITE_ADDRESS (WF_IIC_7BIT_ADDRESS<<1) //8位地址
|
||||||
#define WF_IIC_READ_ADDRESS (WF_IIC_WRITE_ADDRESS | 0x01)
|
#define WF_IIC_READ_ADDRESS (WF_IIC_WRITE_ADDRESS | 0x01)
|
||||||
#else
|
#else
|
||||||
@ -20,9 +28,7 @@
|
|||||||
#define WF_IIC_WRITE_ADDRESS (WF_IIC_7BIT_ADDRESS<<1) //8位地址
|
#define WF_IIC_WRITE_ADDRESS (WF_IIC_7BIT_ADDRESS<<1) //8位地址
|
||||||
#define WF_IIC_READ_ADDRESS (WF_IIC_WRITE_ADDRESS | 0x01)
|
#define WF_IIC_READ_ADDRESS (WF_IIC_WRITE_ADDRESS | 0x01)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define WF_CHIP_ID 0X10
|
#define WF_CHIP_ID 0X10
|
||||||
|
|
||||||
// 寄存器映射
|
// 寄存器映射
|
||||||
// 压力数据
|
// 压力数据
|
||||||
#define WF_PRS_B2 0x00
|
#define WF_PRS_B2 0x00
|
||||||
@ -35,14 +41,14 @@
|
|||||||
// 配置寄存器
|
// 配置寄存器
|
||||||
#define WF_PRS_CFG 0x06
|
#define WF_PRS_CFG 0x06
|
||||||
#define WF_TMP_CFG 0x07
|
#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_CFG_REG 0x09
|
||||||
#define WF_INT_STS 0x0A
|
#define WF_INT_STS 0x0A
|
||||||
#define WF_FIFO_STS 0x0B
|
#define WF_FIFO_STS 0x0B
|
||||||
#define WF_RESET_REG 0x0C
|
#define WF_RESET_REG 0x0C
|
||||||
// ID寄存器
|
// ID寄存器
|
||||||
#define WF_ID_REG 0x0D
|
#define WF_ID_REG 0x0D
|
||||||
// 校准系数寄存器
|
// 校准系数寄存器 (Offsets match manufacturer's i+0x10 access)
|
||||||
#define COEF_C0 0x10
|
#define COEF_C0 0x10
|
||||||
#define COEF_C0_C1 0x11
|
#define COEF_C0_C1 0x11
|
||||||
#define COEF_C1 0x12
|
#define COEF_C1 0x12
|
||||||
@ -63,25 +69,24 @@
|
|||||||
#define COEF_C30_L 0x21
|
#define COEF_C30_L 0x21
|
||||||
|
|
||||||
// --- 配置宏 ---
|
// --- 配置宏 ---
|
||||||
|
|
||||||
// 压力配置 (PRS_CFG[6:4]) - 测量速率
|
// 压力配置 (PRS_CFG[6:4]) - 测量速率
|
||||||
#define PM_RATE_1 0x00 // 1 次/秒
|
#define PM_RATE_1 0x00 // 1 次/秒
|
||||||
#define PM_RATE_2 0x01 // 2 次/秒
|
#define PM_RATE_2 0x01 // 2 次/秒
|
||||||
#define PM_RATE_4 0x02 // 4 次/秒
|
#define PM_RATE_4 0x02 // 4 次/秒
|
||||||
#define PM_RATE_8 0x03 // 8 次/秒
|
#define PM_RATE_8 0x03 // 8 次/秒
|
||||||
#define PM_RATE_16 0x04 // 16 次/秒
|
#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_64 0x06 // 64 次/秒
|
||||||
#define PM_RATE_128 0x07 // 128 次/秒
|
#define PM_RATE_128 0x07 // 128 次/秒
|
||||||
// 压力配置 (PRS_CFG[3:0]) - 过采样率
|
// 压力配置 (PRS_CFG[3:0]) - 过采样率
|
||||||
#define PM_PRC_1 0x00 // 1 次 (单次)
|
#define PM_PRC_1 0x00 // 1 次 (单次)
|
||||||
#define PM_PRC_2 0x01 // 2 次 (低功耗)
|
#define PM_PRC_2 0x01 // 2 次 (低功耗)
|
||||||
#define PM_PRC_4 0x02 // 4 次
|
#define PM_PRC_4 0x02 // 4 次
|
||||||
#define PM_PRC_8 0x03 // 8 次 (标准)
|
#define PM_PRC_8 0x03 // 8 次
|
||||||
#define PM_PRC_16 0x04 // 16 次 (需要移位)
|
#define PM_PRC_16 0x04 // 16 次 (标准) <--- 建议使用此过采样率
|
||||||
#define PM_PRC_32 0x05 // 32 次 (需要移位)
|
#define PM_PRC_32 0x05 // 32 次
|
||||||
#define PM_PRC_64 0x06 // 64 次 (高精度, 需要移位)
|
#define PM_PRC_64 0x06 // 64 次 (高精度)
|
||||||
#define PM_PRC_128 0x07 // 128 次 (需要移位)
|
#define PM_PRC_128 0x07 // 128 次
|
||||||
|
|
||||||
// 温度配置 (TMP_CFG[7]) - 传感器源
|
// 温度配置 (TMP_CFG[7]) - 传感器源
|
||||||
#define TMP_EXT_SENSOR 0x80 // 使用外部传感器
|
#define TMP_EXT_SENSOR 0x80 // 使用外部传感器
|
||||||
@ -92,15 +97,15 @@
|
|||||||
#define TMP_RATE_4 0x02 // 4 次/秒
|
#define TMP_RATE_4 0x02 // 4 次/秒
|
||||||
#define TMP_RATE_8 0x03 // 8 次/秒
|
#define TMP_RATE_8 0x03 // 8 次/秒
|
||||||
#define TMP_RATE_16 0x04 // 16 次/秒
|
#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_64 0x06 // 64 次/秒
|
||||||
#define TMP_RATE_128 0x07 // 128 次/秒
|
#define TMP_RATE_128 0x07 // 128 次/秒
|
||||||
// 温度配置 (TMP_CFG[3:0]) - 过采样率
|
// 温度配置 (TMP_CFG[2:0]) - 过采样率
|
||||||
#define TMP_PRC_1 0x00 // 1 次
|
#define TMP_PRC_1 0x00 // 1 次
|
||||||
#define TMP_PRC_2 0x01 // 2 次
|
#define TMP_PRC_2 0x01 // 2 次
|
||||||
#define TMP_PRC_4 0x02 // 4 次
|
#define TMP_PRC_4 0x02 // 4 次
|
||||||
#define TMP_PRC_8 0x03 // 8 次
|
#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_32 0x05 // 32 次
|
||||||
#define TMP_PRC_64 0x06 // 64 次
|
#define TMP_PRC_64 0x06 // 64 次
|
||||||
#define TMP_PRC_128 0x07 // 128 次
|
#define TMP_PRC_128 0x07 // 128 次
|
||||||
@ -110,39 +115,39 @@
|
|||||||
* @return 0: 成功, 1: 失败
|
* @return 0: 成功, 1: 失败
|
||||||
*/
|
*/
|
||||||
uint8_t WF_Init(void);
|
uint8_t WF_Init(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 使传感器进入休眠/待机模式
|
* @brief 使传感器进入休眠/待机模式
|
||||||
*/
|
*/
|
||||||
void WF_Sleep(void);
|
void WF_Sleep(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 唤醒传感器,开始连续测量
|
* @brief 唤醒传感器,开始连续测量
|
||||||
|
* 在连续模式下,通常只需要调用一次WF_Init即可,无需频繁调用Wakeup
|
||||||
|
* 如果WF_Sleep被调用,则需要调用WF_Wakeup来恢复连续测量
|
||||||
*/
|
*/
|
||||||
void WF_Wakeup(void);
|
void WF_Wakeup(void); // Reinstated for continuous mode control
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 获取传感器芯片ID
|
* @brief 获取传感器芯片ID
|
||||||
* @return 芯片ID (应为 0x10)
|
* @return 芯片ID (应为 0x10)
|
||||||
*/
|
*/
|
||||||
uint8_t WF_GetID(void);
|
uint8_t WF_GetID(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 计算并返回当前海拔高度
|
* @brief 计算并返回当前海拔高度
|
||||||
* @return 海拔高度 (单位: 米)
|
* @return 海拔高度 (单位: 米)
|
||||||
*/
|
*/
|
||||||
float WF_Altitude_Calculate(void);
|
float WF_Altitude_Calculate(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 计算并返回补偿后的压力值
|
* @brief 计算并返回补偿后的压力值
|
||||||
* @return 压力 (单位: Pa)
|
* @return 压力 (单位: Pa)
|
||||||
*/
|
*/
|
||||||
float WF_Pressure_Calculate(void);
|
float WF_Pressure_Calculate(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 计算并返回补偿后的温度值
|
* @brief 计算并返回补偿后的温度值
|
||||||
* @return 温度 (单位: °C)
|
* @return 温度 (单位: °C)
|
||||||
*/
|
*/
|
||||||
float WF_Temperature_Calculate(void);
|
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_
|
#endif // _WF282A_H_
|
||||||
@ -1,10 +1,12 @@
|
|||||||
#ifndef XTELL_H
|
#ifndef XTELL_H
|
||||||
#define XTELL_H
|
#define XTELL_H
|
||||||
#include "system/includes.h"
|
#include "system/includes.h"
|
||||||
|
#include "generic/typedef.h"
|
||||||
// #define KS_BLE 1
|
// #define KS_BLE 1
|
||||||
#define XTELL_TEST 1
|
#define XTELL_TEST 1
|
||||||
|
|
||||||
#define ACC_RANGE 16 //g,加速度满量程:2、4、8、16
|
#define ACC_RANGE 16 //g,加速度满量程:2、4、8、16
|
||||||
|
|
||||||
|
#define BMP280 0
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -171,6 +171,6 @@ void xtell_app_main()
|
|||||||
xtell_task_create();
|
xtell_task_create();
|
||||||
|
|
||||||
xlog("==============xtell_app_end================\n");
|
xlog("==============xtell_app_end================\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -49,6 +49,7 @@
|
|||||||
#include "./sensor/MMC56.h"
|
#include "./sensor/MMC56.h"
|
||||||
#include "./sensor/BMP280.h"
|
#include "./sensor/BMP280.h"
|
||||||
#include "./sensor/AK8963.h"
|
#include "./sensor/AK8963.h"
|
||||||
|
#include "./sensor/WF282A.h"
|
||||||
#include "./calculate/skiing_tracker.h"
|
#include "./calculate/skiing_tracker.h"
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//宏定义
|
//宏定义
|
||||||
@ -83,13 +84,13 @@ extern u8 init_ok;
|
|||||||
extern u8 sniff_out;
|
extern u8 sniff_out;
|
||||||
unsigned char xtell_bl_state=0; //存放经典蓝牙的连接状态,0断开,1是连接
|
unsigned char xtell_bl_state=0; //存放经典蓝牙的连接状态,0断开,1是连接
|
||||||
u8 bt_newname =0;
|
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;
|
static u16 play_poweron_ok_timer_id = 0;
|
||||||
|
|
||||||
// -- 初始化标志位 --
|
// -- 初始化标志位 --
|
||||||
u8 SC7U22_init = 0x10; //六轴是否初始化
|
u8 SC7U22_init = 0x10; //六轴是否初始化
|
||||||
u8 MMC5603nj_init = 0x20; //地磁是否初始化
|
u8 MMC5603nj_init = 0x20; //地磁是否初始化
|
||||||
u8 BMP280_init = 0x30; //气压计初始化
|
u8 barometer_init = 0x30; //气压计初始化
|
||||||
u8 foot_init = 0x40; //数据来源初始化:左脚0x41 or 右脚0x42
|
u8 foot_init = 0x40; //数据来源初始化:左脚0x41 or 右脚0x42
|
||||||
// -- 线程id --
|
// -- 线程id --
|
||||||
|
|
||||||
@ -191,6 +192,120 @@ static int state_machine(struct application *app, enum app_state state, struct i
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//handle
|
//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)
|
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);
|
send_data_to_ble_client(&device_buff,founds);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 0x02:
|
||||||
|
extern void test_func(void);
|
||||||
|
test_func();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -242,14 +361,15 @@ void le_user_app_event_handler(struct sys_event* event){
|
|||||||
case 0x00: //数据包类型为:指定传感器初始化
|
case 0x00: //数据包类型为:指定传感器初始化
|
||||||
u8 send2_0[5] = {0xBB,0xBE,0x02,0x00,0x00};
|
u8 send2_0[5] = {0xBB,0xBE,0x02,0x00,0x00};
|
||||||
if(event->u.app.buffer[4] == 0x01){ //六轴
|
if(event->u.app.buffer[4] == 0x01){ //六轴
|
||||||
stop_calibration();
|
// stop_calibration();
|
||||||
if (SL_SC7U22_Config() == 0) {
|
if (SL_SC7U22_Config() == 0) {
|
||||||
send2_0[4] = 0x00; //初始化失败
|
SC7U22_init = 0x10; //初始化失败
|
||||||
SC7U22_init = 0x10;
|
}else{
|
||||||
send_data_to_ble_client(&send2_0,5);
|
SC7U22_init = 0x11;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
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){ //地磁
|
}else if(event->u.app.buffer[4] == 0x02){ //地磁
|
||||||
if(mmc5603nj_init() == 0){
|
if(mmc5603nj_init() == 0){
|
||||||
MMC5603nj_init = 0x20;
|
MMC5603nj_init = 0x20;
|
||||||
@ -261,15 +381,15 @@ void le_user_app_event_handler(struct sys_event* event){
|
|||||||
send2_0[4] = MMC5603nj_init; //地磁初始化成功
|
send2_0[4] = MMC5603nj_init; //地磁初始化成功
|
||||||
send_data_to_ble_client(&send2_0,5);
|
send_data_to_ble_client(&send2_0,5);
|
||||||
}else if(event->u.app.buffer[4] == 0x03){ //气压计初始化
|
}else if(event->u.app.buffer[4] == 0x03){ //气压计初始化
|
||||||
if(bmp280_init() != 0){
|
if(BMP280_init() != 0){
|
||||||
//初始化失败
|
//初始化失败
|
||||||
BMP280_init = 0x30;
|
barometer_init = 0x30;
|
||||||
send2_0[4] = BMP280_init;
|
send2_0[4] = barometer_init;
|
||||||
send_data_to_ble_client(&send2_0,5);
|
send_data_to_ble_client(&send2_0,5);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BMP280_init = 0x31;
|
barometer_init = 0x31;
|
||||||
send2_0[4] = BMP280_init; //气压计初始化成功
|
send2_0[4] = barometer_init; //气压计初始化成功
|
||||||
send_data_to_ble_client(&send2_0,5);
|
send_data_to_ble_client(&send2_0,5);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -290,13 +410,13 @@ void le_user_app_event_handler(struct sys_event* event){
|
|||||||
}else if(event->u.app.buffer[4] == 0x02){ //地磁
|
}else if(event->u.app.buffer[4] == 0x02){ //地磁
|
||||||
send2_2[4] = MMC5603nj_init;
|
send2_2[4] = MMC5603nj_init;
|
||||||
}else if(event->u.app.buffer[4] == 0x03){ //气压计
|
}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);
|
send_data_to_ble_client(&send2_2,5);
|
||||||
break;
|
break;
|
||||||
case 0x03: //开始/停止滑雪计算
|
case 0x03: //开始/停止滑雪计算
|
||||||
if(event->u.app.buffer[4] == 0x01){ //开始滑雪计算
|
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};
|
u8 send2_3[5] = {0xBB,0xBE,0x02,0x00,0x00};
|
||||||
send_data_to_ble_client(&send2_3,5);
|
send_data_to_ble_client(&send2_3,5);
|
||||||
return;
|
return;
|
||||||
|
|||||||
528
apps/earphone/xtell_remote_control/ble_handler/ble_handler.c
Normal file
528
apps/earphone/xtell_remote_control/ble_handler/ble_handler.c
Normal file
@ -0,0 +1,528 @@
|
|||||||
|
#include "system/includes.h"
|
||||||
|
#include "media/includes.h"
|
||||||
|
#include "tone_player.h"
|
||||||
|
#include "earphone.h"
|
||||||
|
|
||||||
|
#include "app_config.h"
|
||||||
|
#include "app_action.h"
|
||||||
|
#include "app_task.h"
|
||||||
|
|
||||||
|
#include "btstack/avctp_user.h"
|
||||||
|
#include "btstack/btstack_task.h"
|
||||||
|
#include "btctrler/btctrler_task.h"
|
||||||
|
#include "btstack/frame_queque.h"
|
||||||
|
#include "user_cfg.h"
|
||||||
|
// #include "aec_user.h"
|
||||||
|
#include "classic/hci_lmp.h"
|
||||||
|
#include "bt_common.h"
|
||||||
|
#include "bt_ble.h"
|
||||||
|
#include "bt_tws.h"
|
||||||
|
#include "pbg_user.h"
|
||||||
|
#include "btstack/bluetooth.h"
|
||||||
|
#include "colorful_lights/colorful_lights.h"
|
||||||
|
|
||||||
|
#include "app_chargestore.h"
|
||||||
|
#include "jl_kws/jl_kws_api.h"
|
||||||
|
|
||||||
|
#include "asm/charge.h"
|
||||||
|
#include "app_charge.h"
|
||||||
|
#include "ui_manage.h"
|
||||||
|
|
||||||
|
#include "app_chargestore.h"
|
||||||
|
#include "app_umidigi_chargestore.h"
|
||||||
|
#include "app_testbox.h"
|
||||||
|
#include "app_online_cfg.h"
|
||||||
|
#include "app_main.h"
|
||||||
|
#include "app_power_manage.h"
|
||||||
|
#include "gSensor/gSensor_manage.h"
|
||||||
|
#include "key_event_deal.h"
|
||||||
|
#include "classic/tws_api.h"
|
||||||
|
#include "asm/pwm_led.h"
|
||||||
|
#include "ir_sensor/ir_manage.h"
|
||||||
|
#include "in_ear_detect/in_ear_manage.h"
|
||||||
|
#include "vol_sync.h"
|
||||||
|
#include "bt_background.h"
|
||||||
|
#include "default_event_handler.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "system/event.h"
|
||||||
|
#include "../nvs/nvs.h"
|
||||||
|
#if (JL_EARPHONE_APP_EN)
|
||||||
|
#include "rcsp_adv_bluetooth.h"
|
||||||
|
#endif
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//宏定义
|
||||||
|
#define LOG_TAG_CONST EARPHONE
|
||||||
|
#define LOG_TAG "[EARPHONE]"
|
||||||
|
#define LOG_ERROR_ENABLE
|
||||||
|
#define LOG_DEBUG_ENABLE
|
||||||
|
#define xlog_ENABLE
|
||||||
|
|
||||||
|
|
||||||
|
#if(USE_DMA_UART_TEST) //使用dm串口测试时不能同时打开
|
||||||
|
#define MY_SNIFF_EN 0
|
||||||
|
#else
|
||||||
|
#define MY_SNIFF_EN 1 //默认打开
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#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
|
||||||
|
//
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//变量
|
||||||
|
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-55555";
|
||||||
|
static u16 play_poweron_ok_timer_id = 0;
|
||||||
|
|
||||||
|
// -- 初始化标志位 --
|
||||||
|
u8 SC7U22_init = 0x10; //六轴是否初始化
|
||||||
|
u8 MMC5603nj_init = 0x20; //地磁是否初始化
|
||||||
|
u8 barometer_init = 0x30; //气压计初始化
|
||||||
|
// -- 线程id --
|
||||||
|
u16 SC7U22_calibration_id;
|
||||||
|
u16 start_collect_fuc_id;
|
||||||
|
u16 BLE_send_fuc_id;
|
||||||
|
u16 rfid_fuc_id;
|
||||||
|
//
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
extern int bt_hci_event_handler(struct bt_event *bt);
|
||||||
|
extern void SC7U22_static_calibration(void);
|
||||||
|
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);
|
||||||
|
extern void start_collect_fuc(void);
|
||||||
|
extern void BLE_send_fuc(void);
|
||||||
|
extern void xtell_ble_central_test_start(void);
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/*
|
||||||
|
* 模式状态机, 通过start_app()控制状态切换
|
||||||
|
*/
|
||||||
|
/* extern int audio_mic_init(); */
|
||||||
|
|
||||||
|
static int state_machine(struct application *app, enum app_state state, struct intent *it){
|
||||||
|
int error = 0;
|
||||||
|
static u8 tone_player_err = 0;
|
||||||
|
xlog("bt_state_machine=%d\n", state);
|
||||||
|
switch (state) {
|
||||||
|
case APP_STA_CREATE:
|
||||||
|
xlog("APP_STA_CREATE\n");
|
||||||
|
/* set_adjust_conn_dac_check(0); */
|
||||||
|
|
||||||
|
break;
|
||||||
|
case APP_STA_START:
|
||||||
|
xlog("APP_STA_START\n");
|
||||||
|
if (!it) {
|
||||||
|
xlog("APP_STA_START:it none\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (it->action) {
|
||||||
|
case ACTION_EARPHONE_MAIN:
|
||||||
|
xlog("ble init\n");
|
||||||
|
/*
|
||||||
|
* handler 初始化
|
||||||
|
*/
|
||||||
|
clk_set("sys", BT_NORMAL_HZ);
|
||||||
|
u32 sys_clk = clk_get("sys");
|
||||||
|
bt_pll_para(TCFG_CLOCK_OSC_HZ, sys_clk, 0, 0);
|
||||||
|
/* bredr_set_dut_enble(1, 1); */
|
||||||
|
bt_function_select_init();
|
||||||
|
bredr_handle_register();
|
||||||
|
EARPHONE_STATE_INIT();
|
||||||
|
btstack_init();
|
||||||
|
sys_auto_shut_down_enable();
|
||||||
|
bt_sniff_feature_init();
|
||||||
|
sys_auto_sniff_controle(MY_SNIFF_EN, NULL);
|
||||||
|
app_var.dev_volume = -1;
|
||||||
|
break;
|
||||||
|
case ACTION_A2DP_START: //蓝牙音频传输协议
|
||||||
|
xlog("ACTION_A2DP_START\n");
|
||||||
|
break;
|
||||||
|
case ACTION_BY_KEY_MODE:
|
||||||
|
xlog("ACTION_BY_KEY_MODE\n");
|
||||||
|
break;
|
||||||
|
case ACTION_TONE_PLAY:
|
||||||
|
xlog("ACTION_TONE_PLAY\n");
|
||||||
|
// STATUS *p_tone = get_tone_config();
|
||||||
|
// tone_play_index(p_tone->bt_init_ok, 1);
|
||||||
|
break;
|
||||||
|
case ACTION_DO_NOTHING:
|
||||||
|
xlog("ACTION_DO_NOTHING\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case APP_STA_PAUSE:
|
||||||
|
xlog("APP_STA_PAUSE\n");
|
||||||
|
break;
|
||||||
|
case APP_STA_RESUME:
|
||||||
|
xlog("APP_STA_RESUME\n");
|
||||||
|
//恢复前台运行
|
||||||
|
sys_auto_shut_down_disable();
|
||||||
|
sys_key_event_enable();
|
||||||
|
break;
|
||||||
|
case APP_STA_STOP:
|
||||||
|
xlog("APP_STA_STOP\n");
|
||||||
|
break;
|
||||||
|
case APP_STA_DESTROY:
|
||||||
|
xlog("APP_STA_DESTROY\n");
|
||||||
|
r_printf("APP_STA_DESTROY\n");
|
||||||
|
if (!app_var.goto_poweroff_flag) {
|
||||||
|
bt_app_exit(NULL);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
xlog("state machine error\n");
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//handle
|
||||||
|
|
||||||
|
|
||||||
|
void le_user_app_send_event(size_t command, unsigned char* data, size_t size)
|
||||||
|
{
|
||||||
|
// 中断->事件
|
||||||
|
static unsigned char buffer[512];
|
||||||
|
if(data && size && size <= sizeof(buffer)) {
|
||||||
|
// 拷贝到缓存,避免转发事件的时候,地址发送改变。
|
||||||
|
memcpy(buffer, data, size);
|
||||||
|
struct sys_event event;
|
||||||
|
event.type = SYS_APP_USER_EVENT;
|
||||||
|
event.u.app.command = command;
|
||||||
|
event.u.app.buffer = buffer;
|
||||||
|
event.u.app.size = size;
|
||||||
|
sys_event_notify(&event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void le_user_app_event_handler(struct sys_event* event){
|
||||||
|
|
||||||
|
switch (event->type) {
|
||||||
|
// 打印接收到的数据
|
||||||
|
printf("BLE data\n");
|
||||||
|
put_buf(event->u.app.buffer, event->u.app.size);
|
||||||
|
case SYS_APP_USER_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:
|
||||||
|
nvs_test_factory_info();
|
||||||
|
break;
|
||||||
|
case 0x02:
|
||||||
|
// factory_info_t read_info;;
|
||||||
|
// nvs_read_factory_info(&read_info);
|
||||||
|
extern void rfid_task_fuc(void);
|
||||||
|
create_process(&rfid_fuc_id,"rfid",NULL,rfid_task_fuc,2000);
|
||||||
|
break;
|
||||||
|
case 0xff: //测试
|
||||||
|
int ret = hw_iic_init(0);
|
||||||
|
// int ret = soft_iic_init(0);
|
||||||
|
xlog("init iic result:%d\n", ret); //返回0成功
|
||||||
|
extern void i2c_scanner_probe(void);
|
||||||
|
i2c_scanner_probe();
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}else if(event->u.app.buffer[2] == 0x02){ //后面数据长度为2
|
||||||
|
switch (event->u.app.buffer[3]){ //数据包类型
|
||||||
|
case 0x00:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
xlog("%d\n",event->type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void play_poweron_ok_timer(void *priv)
|
||||||
|
{
|
||||||
|
app_var.wait_timer_do = 0;
|
||||||
|
|
||||||
|
log_d("\n-------play_poweron_ok_timer-------\n", priv);
|
||||||
|
if (is_dac_power_off()) {
|
||||||
|
#if TCFG_USER_TWS_ENABLE
|
||||||
|
bt_tws_poweron();
|
||||||
|
#else
|
||||||
|
bt_wait_connect_and_phone_connect_switch(0);
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
app_var.wait_timer_do = sys_timeout_add(priv, play_poweron_ok_timer, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void play_bt_connect_dly(void *priv)
|
||||||
|
{
|
||||||
|
app_var.wait_timer_do = 0;
|
||||||
|
|
||||||
|
log_d("\n-------play_bt_connect_dly-------\n", priv);
|
||||||
|
|
||||||
|
if (!app_var.goto_poweroff_flag) {
|
||||||
|
STATUS *p_tone = get_tone_config();
|
||||||
|
tone_play_index(p_tone->bt_connect_ok, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int bt_connction_status_event_handler(struct bt_event *bt)
|
||||||
|
{
|
||||||
|
STATUS *p_tone = get_tone_config();
|
||||||
|
u8 *phone_number = NULL;
|
||||||
|
|
||||||
|
switch (bt->event) {
|
||||||
|
case BT_STATUS_INIT_OK:
|
||||||
|
/*
|
||||||
|
* 蓝牙初始化完成
|
||||||
|
*/
|
||||||
|
xlog("BT_STATUS_INIT_OK\n");
|
||||||
|
init_ok = 1;
|
||||||
|
__set_sbc_cap_bitpool(38);
|
||||||
|
|
||||||
|
#if (TCFG_USER_BLE_ENABLE)
|
||||||
|
if (BT_MODE_IS(BT_BQB)) {
|
||||||
|
ble_bqb_test_thread_init();
|
||||||
|
} else {
|
||||||
|
#if !TCFG_WIRELESS_MIC_ENABLE
|
||||||
|
bt_ble_init(); // lmx,初始化完,初始化ble,决定ble是作为主设备还是从设备
|
||||||
|
// xtell_ble_central_test_start(); //xtell
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
bt_init_ok_search_index();
|
||||||
|
#if TCFG_TEST_BOX_ENABLE
|
||||||
|
testbox_set_bt_init_ok(1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ((CONFIG_BT_MODE == BT_BQB)||(CONFIG_BT_MODE == BT_PER))
|
||||||
|
bt_wait_phone_connect_control(1);
|
||||||
|
#else
|
||||||
|
if (is_dac_power_off()) {
|
||||||
|
bt_wait_connect_and_phone_connect_switch(0);
|
||||||
|
} else {
|
||||||
|
app_var.wait_timer_do = sys_timeout_add(NULL, play_poweron_ok_timer, 100);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*if (app_var.play_poweron_tone) {
|
||||||
|
tone_play_index(p_tone->power_on, 1);
|
||||||
|
}*/
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BT_STATUS_SECOND_CONNECTED:
|
||||||
|
clear_current_poweron_memory_search_index(0);
|
||||||
|
case BT_STATUS_FIRST_CONNECTED:
|
||||||
|
xlog("BT_STATUS_CONNECTED\n");
|
||||||
|
xtell_bl_state = 1; //蓝牙连接成功 置1
|
||||||
|
if(strcmp(xt_ble_new_name,"CM-11111") != 0){
|
||||||
|
//蓝牙连接成功
|
||||||
|
bt_newname =1;
|
||||||
|
u8 temp[5]={0xBB,0xBE,0x02,0x04,0x00};
|
||||||
|
temp[4] = xtell_bl_state; //经典蓝牙连接状态
|
||||||
|
// send_data_to_ble_client(&temp,5);
|
||||||
|
}
|
||||||
|
earphone_change_pwr_mode(PWR_DCDC15, 3000);
|
||||||
|
sys_auto_shut_down_disable();
|
||||||
|
|
||||||
|
ui_update_status(STATUS_BT_CONN); //单台在此处设置连接状态,对耳的连接状态需要同步,在bt_tws.c中去设置
|
||||||
|
|
||||||
|
/* tone_play(TONE_CONN); */
|
||||||
|
/*os_time_dly(40); // for test*/
|
||||||
|
xlog("tone status:%d\n", tone_get_status());
|
||||||
|
if (get_call_status() == BT_CALL_HANGUP) {
|
||||||
|
if (app_var.phone_dly_discon_time) {
|
||||||
|
sys_timeout_del(app_var.phone_dly_discon_time);
|
||||||
|
app_var.phone_dly_discon_time = 0;
|
||||||
|
} else {
|
||||||
|
app_var.wait_timer_do = sys_timeout_add(NULL, play_bt_connect_dly, 1600);
|
||||||
|
/* tone_play_index(p_tone->bt_connect_ok, 1); */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*int timeout = 5000 + rand32() % 10000;
|
||||||
|
sys_timeout_add(NULL, connect_phone_test, timeout);*/
|
||||||
|
break;
|
||||||
|
case BT_STATUS_FIRST_DISCONNECT:
|
||||||
|
case BT_STATUS_SECOND_DISCONNECT:
|
||||||
|
xlog("BT_STATUS_DISCONNECT\n");
|
||||||
|
xtell_bl_state = 0; //断开蓝牙 清0
|
||||||
|
//蓝牙断开连接
|
||||||
|
if(bt_newname){ //已经改成新蓝牙名字,断开才播报
|
||||||
|
bt_newname=0;
|
||||||
|
u8 temp[5]={0xBB,0xBE,0x02,0x04,0x00};
|
||||||
|
temp[4] = xtell_bl_state; //经典蓝牙连接状态
|
||||||
|
// send_data_to_ble_client(&temp,5);
|
||||||
|
}
|
||||||
|
if (app_var.goto_poweroff_flag) {
|
||||||
|
/*关机不播断开提示音*/
|
||||||
|
/*关机时不改UI*/
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// bt_discon_dly_handle(NULL);
|
||||||
|
break;
|
||||||
|
|
||||||
|
//phone status deal
|
||||||
|
case BT_STATUS_PHONE_INCOME:
|
||||||
|
break;
|
||||||
|
case BT_STATUS_PHONE_OUT:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case BT_STATUS_PHONE_ACTIVE:
|
||||||
|
break;
|
||||||
|
case BT_STATUS_PHONE_HANGUP:
|
||||||
|
break;
|
||||||
|
case BT_STATUS_PHONE_NUMBER:
|
||||||
|
break;
|
||||||
|
case BT_STATUS_INBAND_RINGTONE: //铃声
|
||||||
|
break;
|
||||||
|
case BT_STATUS_CALL_VOL_CHANGE:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case BT_STATUS_SNIFF_STATE_UPDATE:
|
||||||
|
xlog(" BT_STATUS_SNIFF_STATE_UPDATE %d\n", bt->value); //0退出SNIFF
|
||||||
|
if (bt->value == 0) {
|
||||||
|
sniff_out = 1;
|
||||||
|
sys_auto_sniff_controle(MY_SNIFF_EN, bt->args);
|
||||||
|
} else {
|
||||||
|
sys_auto_sniff_controle(0, bt->args);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BT_STATUS_LAST_CALL_TYPE_CHANGE:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BT_STATUS_CONN_A2DP_CH:
|
||||||
|
case BT_STATUS_CONN_HFP_CH:
|
||||||
|
|
||||||
|
if ((!is_1t2_connection()) && (get_current_poweron_memory_search_index(NULL))) { //回连下一个device
|
||||||
|
if (get_esco_coder_busy_flag()) {
|
||||||
|
clear_current_poweron_memory_search_index(0);
|
||||||
|
} else {
|
||||||
|
user_send_cmd_prepare(USER_CTRL_START_CONNECTION, 0, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BT_STATUS_PHONE_MANUFACTURER:
|
||||||
|
break;
|
||||||
|
case BT_STATUS_VOICE_RECOGNITION:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case BT_STATUS_AVRCP_INCOME_OPID:
|
||||||
|
xlog("BT_STATUS_AVRCP_INCOME_OPID:%d\n", bt->value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
xlog(" BT STATUS DEFAULT\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int event_handler(struct application *app, struct sys_event *event)
|
||||||
|
{
|
||||||
|
|
||||||
|
le_user_app_event_handler(event);
|
||||||
|
|
||||||
|
if (SYS_EVENT_REMAP(event)) {
|
||||||
|
g_printf("****SYS_EVENT_REMAP**** \n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (event->type) {
|
||||||
|
case SYS_KEY_EVENT:
|
||||||
|
break;
|
||||||
|
case SYS_BT_EVENT:
|
||||||
|
/*
|
||||||
|
* 蓝牙事件处理
|
||||||
|
*/
|
||||||
|
if ((u32)event->arg == SYS_BT_EVENT_TYPE_CON_STATUS) {
|
||||||
|
printf("in event_handler:bt_connction_status_event_handler");
|
||||||
|
bt_connction_status_event_handler(&event->u.bt);
|
||||||
|
} else if ((u32)event->arg == SYS_BT_EVENT_TYPE_HCI_STATUS) {
|
||||||
|
bt_hci_event_handler(&event->u.bt);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SYS_DEVICE_EVENT:
|
||||||
|
/*
|
||||||
|
* 系统设备事件处理
|
||||||
|
*/
|
||||||
|
if ((u32)event->arg == DEVICE_EVENT_FROM_CHARGE) {
|
||||||
|
|
||||||
|
} else if ((u32)event->arg == DEVICE_EVENT_FROM_POWER) {
|
||||||
|
return app_power_event_handler(&event->u.dev);
|
||||||
|
}
|
||||||
|
#if (JL_EARPHONE_APP_EN)
|
||||||
|
else if ((u32)event->arg == DEVICE_EVENT_FROM_RCSP) {
|
||||||
|
xlog("DEVICE_EVENT_FROM_RCSP: %d", event->u.rcsp.event);
|
||||||
|
switch (event->u.rcsp.event) {
|
||||||
|
case MSG_JL_UPDATE_START:
|
||||||
|
xlog(">>> Xtell APP: MSG_JL_UPDATE_START\n");
|
||||||
|
// You can add UI notifications here, like LED blinking or a tone.
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if TCFG_UMIDIGI_BOX_ENABLE
|
||||||
|
else if ((u32)event->arg == DEVICE_EVENT_UMIDIGI_CHARGE_STORE) {
|
||||||
|
app_umidigi_chargestore_event_handler(&event->u.umidigi_chargestore);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if TCFG_TEST_BOX_ENABLE
|
||||||
|
else if ((u32)event->arg == DEVICE_EVENT_TEST_BOX) {
|
||||||
|
app_testbox_event_handler(&event->u.testbox);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SYS_EVENT_HANDLER_SPECIFIC(event);
|
||||||
|
#ifdef CONFIG_BT_BACKGROUND_ENABLE
|
||||||
|
if (app) {
|
||||||
|
default_event_handler(event);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
static const struct application_operation app_handler_ops = {
|
||||||
|
.state_machine = state_machine,
|
||||||
|
.event_handler = event_handler,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 注册earphone模式
|
||||||
|
*/
|
||||||
|
REGISTER_APPLICATION(app_handler) = {
|
||||||
|
.name = "handler",
|
||||||
|
.action = ACTION_EARPHONE_MAIN,
|
||||||
|
.ops = &app_handler_ops,
|
||||||
|
.state = APP_STA_DESTROY,
|
||||||
|
};
|
||||||
Binary file not shown.
Binary file not shown.
@ -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
|
del !bankfiles! common.bin text.bin data.bin bank.bin
|
||||||
copy eq_cfg_hw_less.bin eq_cfg_hw.bin
|
copy eq_cfg_hw_less.bin eq_cfg_hw.bin
|
||||||
call download/earphone/download_app_ota.bat
|
call download/earphone/download.bat
|
||||||
|
|||||||
@ -10,7 +10,7 @@ copy ..\..\ota.bin .
|
|||||||
copy ..\..\anc_coeff.bin .
|
copy ..\..\anc_coeff.bin .
|
||||||
copy ..\..\anc_gains.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
|
@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
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ copy ..\..\anc_coeff.bin .
|
|||||||
copy ..\..\anc_gains.bin .
|
copy ..\..\anc_gains.bin .
|
||||||
|
|
||||||
:: -format all -key AC690X-8029.key
|
:: -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
|
@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
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@ -62,6 +62,12 @@ SPI = 2_3_0_0;
|
|||||||
UTTX = PB02;
|
UTTX = PB02;
|
||||||
UTBD = 1000000;
|
UTBD = 1000000;
|
||||||
UTRX = PP00;
|
UTRX = PP00;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
RESET = PA04_01_0;
|
||||||
[FW_ADDITIONAL]
|
[FW_ADDITIONAL]
|
||||||
FILE_LIST = (file = ota.bin: type = 100);
|
FILE_LIST = (file = ota.bin: type = 100);
|
||||||
[RESERVED_CONFIG]
|
[RESERVED_CONFIG]
|
||||||
|
|||||||
@ -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时,则关闭长按复位功能。) */
|
/* RESET = CAT3(CONFIG_RESET_PIN, CONFIG_RESET_TIME, CONFIG_RESET_LEVEL); //port口_长按时间_有效电平(长按时间有00、01、02、04、08三个值可选,单位为秒,当长按时间为00时,则关闭长按复位功能。) */
|
||||||
|
|
||||||
#ifdef CONFIG_SUPPORT_RESET1
|
#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
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_VDDIO_LVD_LEVEL
|
#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
@ -19,16 +19,17 @@
|
|||||||
#include "ble/ll_config.h"
|
#include "ble/ll_config.h"
|
||||||
|
|
||||||
// #define CONFIG_LE_FEATURES \
|
// #define CONFIG_LE_FEATURES \
|
||||||
(\
|
// (\
|
||||||
LE_ENCRYPTION | \
|
// LE_ENCRYPTION | \
|
||||||
LE_CORE_V50_FEATURES \
|
// 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|LE_INIT|LE_SLAVE|LE_MASTER)
|
||||||
// #define CONFIG_LE_ROLES (LE_ADV|LE_SCAN)
|
#define CONFIG_LE_ROLES (LE_ADV|LE_SCAN)
|
||||||
#define CONFIG_LE_ROLES (LE_ADV)
|
// #define CONFIG_LE_ROLES (LE_ADV)
|
||||||
|
|
||||||
#include "classic/lmp_config.h"
|
#include "classic/lmp_config.h"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user