Compare commits
18 Commits
ed475e870f
...
lmx_rfid
| Author | SHA1 | Date | |
|---|---|---|---|
| fe0348bd89 | |||
| 482767064e | |||
| 8cb1ca7701 | |||
| 3fa235d3c2 | |||
| 8775ec8b1a | |||
| 5757f3fb12 | |||
| 01f442d636 | |||
| c856031d2f | |||
| 537cb1f099 | |||
| d029d273f8 | |||
| 0087d2922a | |||
| 141b538bf5 | |||
| 23b14f0142 | |||
| c870b07b02 | |||
| 86199b822e | |||
| 754a529211 | |||
| 2bc443584c | |||
| f63092fe87 |
8
Makefile
8
Makefile
@ -245,8 +245,7 @@ INCLUDES := \
|
||||
-Iinclude_lib/media/aispeech/enc/include \
|
||||
-Icpu/br28/audio_hearing \
|
||||
-Iinclude_lib/media/cvp \
|
||||
-Iapps/earphone/xtell_Sensor \
|
||||
-Iapps/earphone/remote_control/ \
|
||||
-Iapps/earphone/xtell_remote_control \
|
||||
-I$(SYS_INC_DIR) \
|
||||
|
||||
|
||||
@ -611,13 +610,12 @@ c_SRC_FILES := \
|
||||
cpu/br28/uart_dev.c \
|
||||
cpu/br28/umidigi_chargestore.c \
|
||||
apps/common/colorful_lights/colorful_lights.c \
|
||||
apps/earphone/xtell_Sensor/xtell_app_main.c \
|
||||
apps/earphone/xtell_Sensor/xtell_handler.c \
|
||||
|
||||
|
||||
|
||||
# 定义需要自动搜索 .c 文件的目录列表
|
||||
C_SRC_DIRS := \
|
||||
apps/earphone/remote_control \
|
||||
apps/earphone/xtell_remote_control \
|
||||
|
||||
# 使用 shell 的 find 命令递归查找所有 .c 文件
|
||||
# foreach 遍历 C_SRC_DIRS 中的每一个目录
|
||||
|
||||
@ -28,7 +28,7 @@ extern "C" {
|
||||
#include "gpio.h"
|
||||
|
||||
static uint8_t LL_led = 0;
|
||||
#define LLSYNC_SWITCH_PIN IO_PORTA_01
|
||||
#define LLSYNC_SWITCH_PIN IO_PORTA_00
|
||||
static int ble_property_power_switch_set(const char *data, uint16_t len)
|
||||
{
|
||||
printf("ble_property_power_switch_set led to %d\n", data[0]);
|
||||
|
||||
@ -1663,7 +1663,8 @@ void send_version_to_sibling(void)
|
||||
data[2] = ver >> 8;
|
||||
tws_api_send_data_to_sibling(data, sizeof(data), TWS_FUNC_ID_SEQ_RAND_SYNC);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -1690,3 +1691,4 @@ void send_data_to_ble_client(const u8* data, u16 length)
|
||||
// printf("Insufficient buffer space to send data: Length %d\n", length);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -60,7 +60,8 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
//搜索匹配信息
|
||||
const client_match_cfg_t *match_dev_cfg[CLIENT_MATCH_CONN_MAX];
|
||||
// const client_match_cfg_t *match_dev_cfg[CLIENT_MATCH_CONN_MAX]; //xtell
|
||||
client_match_cfg_t *match_dev_cfg[CLIENT_MATCH_CONN_MAX];
|
||||
//加密保定配置 0 or 1
|
||||
u8 security_en;
|
||||
//搜索服务的个数
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
/* EXAMPLE_START(le_counter): LE Peripheral - Heartbeat Counter over GATT
|
||||
*
|
||||
@ -7,7 +9,7 @@
|
||||
* notifications.
|
||||
*/
|
||||
// *****************************************************************************
|
||||
|
||||
#if 0
|
||||
#include "system/app_core.h"
|
||||
#include "system/includes.h"
|
||||
|
||||
@ -27,7 +29,7 @@
|
||||
|
||||
#if (TCFG_BLE_DEMO_SELECT == DEF_BLE_DEMO_WIRELESS_MIC_CLIENT)
|
||||
|
||||
#define SUPPORT_TEST_BOX_BLE_MASTER_TEST_EN 1
|
||||
#define SUPPORT_TEST_BOX_BLE_MASTER_TEST_EN 0
|
||||
#define SHOW_RX_DATA_RATE 1
|
||||
#define SHOW_TX_DATA_RATE 1
|
||||
|
||||
@ -189,8 +191,8 @@ static void default_report_data_deal(att_data_report_t *report_data, target_uuid
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static const u8 test_remoter_name1[] = "AC637N_MX(BLE)";//
|
||||
static const u8 test_remoter_name1[] = "CM-22222";
|
||||
// static const u8 test_remoter_name1[] = "AC637N_MX(BLE)";//
|
||||
/* static const u8 test_remoter_name2[] = "AC630N_HID567(BLE)";// */
|
||||
static u16 default_client_write_handle;
|
||||
static u16 test_client_timer = 0;
|
||||
@ -275,7 +277,7 @@ static const client_conn_cfg_t client_conn_config_default = {
|
||||
#endif
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
static client_conn_cfg_t *client_config = NULL; //(void *) &client_conn_config_default ;
|
||||
static client_conn_cfg_t *client_config = (void *) &client_conn_config_default ;
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
|
||||
@ -729,7 +731,7 @@ static bool resolve_adv_report(u8 *adv_address, u8 data_length, u8 *data, s8 rss
|
||||
log_info_hexdump(adv_address, 6);
|
||||
adv_data_pt[lenght - 1] = tmp32;
|
||||
//-------
|
||||
#if 1 //无线麦产线通过识别特殊字符串进行近距离连接测试
|
||||
#if 0 //无线麦产线通过识别特殊字符串进行近距离连接测试
|
||||
if (0 == memcmp(adv_data_pt, SPECIFIC_STRING, strlen(SPECIFIC_STRING))) {
|
||||
flag_specific_adv_name = 1;
|
||||
flag_need_judge_rssi = 1;
|
||||
@ -1483,12 +1485,12 @@ void bt_ble_init(void)
|
||||
put_buf(match_name, config_name_len);
|
||||
printf("%s", match_name);
|
||||
#endif
|
||||
if (0 == memcmp(match_name, SPECIFIC_STRING, strlen(SPECIFIC_STRING))) {
|
||||
match_name = &match_name[strlen(SPECIFIC_STRING)];
|
||||
printf("specific scan%s", match_name);
|
||||
flag_specific_sacn = 1;
|
||||
// if (0 == memcmp(match_name, SPECIFIC_STRING, strlen(SPECIFIC_STRING))) {
|
||||
// match_name = &match_name[strlen(SPECIFIC_STRING)];
|
||||
// printf("specific scan%s", match_name);
|
||||
// flag_specific_sacn = 1;
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
set_ble_work_state(BLE_ST_INIT_OK);
|
||||
conn_pair_vm_do(&conn_pair_info, 0);
|
||||
@ -1557,10 +1559,25 @@ void client_send_conn_param_update(void)
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
//lmx
|
||||
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
|
||||
@ -496,7 +496,7 @@ const struct soft_iic_config soft_iic_cfg[] = {
|
||||
.scl = TCFG_SW_I2C0_CLK_PORT, //IIC CLK脚
|
||||
.sda = TCFG_SW_I2C0_DAT_PORT, //IIC DAT脚
|
||||
.delay = TCFG_SW_I2C0_DELAY_CNT, //软件IIC延时参数,影响通讯时钟频率
|
||||
.io_pu = 1, //是否打开上拉电阻,如果外部电路没有焊接上拉电阻需要置1
|
||||
.io_pu = 0, //是否打开上拉电阻,如果外部电路没有焊接上拉电阻需要置1
|
||||
},
|
||||
#if 0
|
||||
//iic1 data
|
||||
|
||||
@ -32,8 +32,8 @@
|
||||
// IIC配置 //
|
||||
//*********************************************************************************//
|
||||
/*软件IIC设置*/ //xtell
|
||||
#define TCFG_SW_I2C0_CLK_PORT IO_PORTB_04 //软件IIC CLK脚选择 XTELL
|
||||
#define TCFG_SW_I2C0_DAT_PORT IO_PORTB_05 //软件IIC DAT脚选择
|
||||
#define TCFG_SW_I2C0_CLK_PORT IO_PORTA_05//IO_PORTB_04 //软件IIC CLK脚选择 XTELL
|
||||
#define TCFG_SW_I2C0_DAT_PORT IO_PORTA_06//IO_PORTB_05 //软件IIC DAT脚选择
|
||||
#define TCFG_SW_I2C0_DELAY_CNT 0 //IIC延时参数,影响通讯时钟频率
|
||||
|
||||
/*硬件IIC端口选择 -- 具体看手册,这里写的不准 -- lmx
|
||||
@ -44,7 +44,6 @@
|
||||
'D': IO_PORTA_05 IO_PORTA_06
|
||||
|
||||
具体要选择哪个iic口,去board_jl701n_demo.c中设置:hw_iic_cfg
|
||||
|
||||
*/
|
||||
#define TCFG_HW_I2C0_PORTS 'B'
|
||||
#define TCFG_HW_I2C0_CLK 100000
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
/* Following Macros Affect Periods Of Both Code Compiling And Post-build */
|
||||
|
||||
#define CONFIG_DOUBLE_BANK_ENABLE 1 //单双备份选择(若打开了改宏,FLASH结构变为双备份结构,适用于接入第三方协议的OTA, PS: JL-OTA同样支持双备份升级, 需要根据实际FLASH大小同时配置CONFIG_FLASH_SIZE)
|
||||
#define CONFIG_DOUBLE_BANK_ENABLE 0 //单双备份选择(若打开了改宏,FLASH结构变为双备份结构,适用于接入第三方协议的OTA, PS: JL-OTA同样支持双备份升级, 需要根据实际FLASH大小同时配置CONFIG_FLASH_SIZE)
|
||||
#define CONFIG_APP_OTA_ENABLE 1 //是否支持RCSP升级(JL-OTA)
|
||||
|
||||
#define CONFIG_UPDATE_JUMP_TO_MASK 0 //配置升级到loader的方式0为直接reset,1为跳转(适用于芯片电源由IO口KEEP住的方案,需要注意检查跳转前是否将使用DMA的硬件模块全部关闭)
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
#include "pbg_user.h"
|
||||
#include "btstack/bluetooth.h"
|
||||
#include "colorful_lights/colorful_lights.h"
|
||||
|
||||
#if 0
|
||||
#if TCFG_AUDIO_ANC_ENABLE
|
||||
#include "audio_anc.h"
|
||||
#endif/*TCFG_AUDIO_ANC_ENABLE*/
|
||||
@ -2792,3 +2792,4 @@ static int state_machine(struct application *app, enum app_state state, struct i
|
||||
// .state = APP_STA_DESTROY,
|
||||
// };
|
||||
|
||||
#endif
|
||||
@ -14,7 +14,7 @@
|
||||
//#define CONFIG_DEBUG_LITE_ENABLE //轻量级打印开关, 默认关闭
|
||||
#endif
|
||||
|
||||
|
||||
#define BLE_WIRELESS_CLIENT_EN 1 //开启则作为主设备,lmx
|
||||
//*********************************************************************************//
|
||||
// AI配置 //
|
||||
//*********************************************************************************//
|
||||
@ -23,12 +23,16 @@
|
||||
#ifdef CONFIG_APP_BT_ENABLE
|
||||
#define TRANS_DATA_EN 0
|
||||
#define RCSP_BTMATE_EN 0
|
||||
#if BLE_WIRELESS_CLIENT_EN == 0
|
||||
#define RCSP_ADV_EN 1
|
||||
#else
|
||||
#define RCSP_ADV_EN 0
|
||||
#endif
|
||||
#define AI_APP_PROTOCOL 0
|
||||
#define LL_SYNC_EN 0
|
||||
#define TUYA_DEMO_EN 0
|
||||
#else
|
||||
#define TRANS_DATA_EN 1
|
||||
#define TRANS_DATA_EN 0
|
||||
#define RCSP_BTMATE_EN 0
|
||||
#define RCSP_ADV_EN 0
|
||||
#define AI_APP_PROTOCOL 0
|
||||
|
||||
@ -204,31 +204,31 @@ int app_protocol_sys_event_handler(struct sys_event *event);
|
||||
#define EARPHONE_STATE_SNIFF(a)
|
||||
#define EARPHONE_STATE_ROLE_SWITCH(a)
|
||||
|
||||
#else
|
||||
int adv_earphone_state_init();
|
||||
int adv_earphone_state_set_page_scan_enable();
|
||||
int adv_earphone_state_get_connect_mac_addr();
|
||||
int adv_earphone_state_cancel_page_scan();
|
||||
int adv_earphone_state_enter_soft_poweroff();
|
||||
int adv_earphone_state_tws_init(int paired);
|
||||
int adv_earphone_state_tws_connected(int first_pair, u8 *comm_addr);
|
||||
int adv_sys_event_handler_specific(struct sys_event *event);
|
||||
int adv_earphone_state_sniff(u8 state);
|
||||
int adv_earphone_state_role_switch(u8 role);
|
||||
// #else
|
||||
// int adv_earphone_state_init();
|
||||
// int adv_earphone_state_set_page_scan_enable();
|
||||
// int adv_earphone_state_get_connect_mac_addr();
|
||||
// int adv_earphone_state_cancel_page_scan();
|
||||
// int adv_earphone_state_enter_soft_poweroff();
|
||||
// int adv_earphone_state_tws_init(int paired);
|
||||
// int adv_earphone_state_tws_connected(int first_pair, u8 *comm_addr);
|
||||
// int adv_sys_event_handler_specific(struct sys_event *event);
|
||||
// int adv_earphone_state_sniff(u8 state);
|
||||
// int adv_earphone_state_role_switch(u8 role);
|
||||
|
||||
#define EARPHONE_STATE_INIT() adv_earphone_state_init()
|
||||
#define EARPHONE_STATE_SET_PAGE_SCAN_ENABLE() adv_earphone_state_set_page_scan_enable()
|
||||
#define EARPHONE_STATE_GET_CONNECT_MAC_ADDR() adv_earphone_state_get_connect_mac_addr()
|
||||
#define EARPHONE_STATE_CANCEL_PAGE_SCAN() adv_earphone_state_cancel_page_scan()
|
||||
#define EARPHONE_STATE_ENTER_SOFT_POWEROFF() adv_earphone_state_enter_soft_poweroff()
|
||||
#define EARPHONE_STATE_TWS_INIT(a) adv_earphone_state_tws_init(a)
|
||||
#define EARPHONE_STATE_TWS_CONNECTED(a, b) adv_earphone_state_tws_connected(a,b)
|
||||
#define SYS_EVENT_HANDLER_SPECIFIC(a) adv_sys_event_handler_specific(a)
|
||||
#define SYS_EVENT_REMAP(a) 0
|
||||
#define EARPHONE_STATE_SNIFF(a) adv_earphone_state_sniff(a)
|
||||
#define EARPHONE_STATE_ROLE_SWITCH(a) adv_earphone_state_role_switch(a)
|
||||
// #define EARPHONE_STATE_INIT() adv_earphone_state_init()
|
||||
// #define EARPHONE_STATE_SET_PAGE_SCAN_ENABLE() adv_earphone_state_set_page_scan_enable()
|
||||
// #define EARPHONE_STATE_GET_CONNECT_MAC_ADDR() adv_earphone_state_get_connect_mac_addr()
|
||||
// #define EARPHONE_STATE_CANCEL_PAGE_SCAN() adv_earphone_state_cancel_page_scan()
|
||||
// #define EARPHONE_STATE_ENTER_SOFT_POWEROFF() adv_earphone_state_enter_soft_poweroff()
|
||||
// #define EARPHONE_STATE_TWS_INIT(a) adv_earphone_state_tws_init(a)
|
||||
// #define EARPHONE_STATE_TWS_CONNECTED(a, b) adv_earphone_state_tws_connected(a,b)
|
||||
// #define SYS_EVENT_HANDLER_SPECIFIC(a) adv_sys_event_handler_specific(a)
|
||||
// #define SYS_EVENT_REMAP(a) 0
|
||||
// #define EARPHONE_STATE_SNIFF(a) adv_earphone_state_sniff(a)
|
||||
// #define EARPHONE_STATE_ROLE_SWITCH(a) adv_earphone_state_role_switch(a)
|
||||
|
||||
#endif
|
||||
// #endif
|
||||
|
||||
|
||||
#else
|
||||
@ -246,6 +246,7 @@ int adv_earphone_state_role_switch(u8 role);
|
||||
#define EARPHONE_STATE_ROLE_SWITCH(a)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@ -231,6 +231,7 @@ const int config_btctler_le_roles = (LE_ADV | LE_SLAVE);
|
||||
const uint64_t config_btctler_le_features = LE_ENCRYPTION;
|
||||
|
||||
#else
|
||||
|
||||
const int config_btctler_le_roles = (LE_ADV | LE_SLAVE);
|
||||
const uint64_t config_btctler_le_features = 0;
|
||||
#endif
|
||||
|
||||
@ -1,113 +0,0 @@
|
||||
#include "system/includes.h"
|
||||
#include "system/syscfg_id.h"
|
||||
#include "nvs.h"
|
||||
|
||||
// 2. 定义一个唯一的配置项ID (必须在1-49之间)
|
||||
#define CFG_FACTORY_INFO_ID 10
|
||||
|
||||
/**
|
||||
* @brief 将出厂信息写入Flash
|
||||
*
|
||||
* @param info 指向要写入的出厂信息结构体的指针
|
||||
* @return 实际写入的长度, <0: 失败
|
||||
*/
|
||||
int nvs_write_factory_info(const factory_info_t *info)
|
||||
{
|
||||
if (!info) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("--> Writing factory info to flash...\n");
|
||||
int ret = syscfg_write(CFG_FACTORY_INFO_ID, (void*)info, sizeof(factory_info_t));
|
||||
if (ret != sizeof(factory_info_t)) {
|
||||
printf("!!! syscfg_write factory info failed, ret = %d\n", ret);
|
||||
} else {
|
||||
printf("--> syscfg_write factory info success.\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从Flash读取出厂信息
|
||||
*
|
||||
* @param info 指向用于存储读取数据的出厂信息结构体的指针
|
||||
* @return 实际读取的长度, <0: 失败 (例如尚未写入过)
|
||||
*/
|
||||
int nvs_read_factory_info(factory_info_t *info)
|
||||
{
|
||||
if (!info) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("--> Reading factory info from flash...\n");
|
||||
int ret = syscfg_read(CFG_FACTORY_INFO_ID, (void*)info, sizeof(factory_info_t));
|
||||
if (ret != sizeof(factory_info_t)) {
|
||||
printf("!!! syscfg_read factory info failed, ret = %d. Maybe not set yet.\n", ret);
|
||||
// 如果读取失败,清空结构体以避免使用脏数据
|
||||
memset(info, 0, sizeof(factory_info_t));
|
||||
} else {
|
||||
printf("--> syscfg_read factory info success.\n");
|
||||
// 可以在这里打印读取到的信息以供调试
|
||||
printf(" Product ID: %s\n", info->product_id);
|
||||
printf(" Serial No: %s\n", info->serial_number);
|
||||
printf(" HW Version: 0x%x\n", info->hw_version);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 清空Flash中的出厂信息
|
||||
*
|
||||
* @return 0: 成功, <0: 失败
|
||||
*/
|
||||
int nvs_clear_factory_info(void)
|
||||
{
|
||||
printf("--> Clearing factory info from flash...\n");
|
||||
// 写入长度为0的数据即可实现删除效果
|
||||
int ret = syscfg_write(CFG_FACTORY_INFO_ID, NULL, 0);
|
||||
if (ret != 0) {
|
||||
printf("!!! syscfg_write clear factory info failed, ret = %d\n", ret);
|
||||
} else {
|
||||
printf("--> syscfg_write clear factory info success.\n");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// 可以在这里添加一个测试函数
|
||||
void nvs_test_factory_info(void)
|
||||
{
|
||||
factory_info_t write_info = {
|
||||
.product_id = "RC_V2",
|
||||
.serial_number = "SN202511260002",
|
||||
.hw_version = 0x0102, // v1.1
|
||||
.cal_data = 1234,
|
||||
.manufacture_date = 1764080400, // 2025-11-26
|
||||
};
|
||||
factory_info_t read_info;
|
||||
|
||||
printf("\n\n--- NVS WRITE TEST ---\n");
|
||||
nvs_write_factory_info(&write_info);
|
||||
|
||||
os_time_dly(10);
|
||||
|
||||
printf("\n--- NVS READ TEST ---\n");
|
||||
nvs_read_factory_info(&read_info);
|
||||
|
||||
// ASSERT(memcmp(&write_info, &read_info, sizeof(factory_info_t)) == 0, "NVS Read/Write Check Failed!");
|
||||
|
||||
// printf("\n--- NVS CLEAR TEST ---\n");
|
||||
// nvs_clear_factory_info();
|
||||
|
||||
os_time_dly(10);
|
||||
|
||||
printf("\n--- NVS READ AFTER CLEAR TEST ---\n");
|
||||
int ret = nvs_read_factory_info(&read_info);
|
||||
if(ret < 0){
|
||||
printf("--- nvs read error ---\n");
|
||||
}
|
||||
|
||||
printf("\n\n--- NVS TEST COMPLETE ---\n\n");
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
#ifndef __NVS_H__
|
||||
#define __NVS_H__
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
// 定义出厂信息数据结构
|
||||
typedef struct {
|
||||
char product_id[16]; // 产品ID
|
||||
char serial_number[32]; // 序列号
|
||||
u16 hw_version; // 硬件版本
|
||||
u16 cal_data; // 某个校准数据
|
||||
u32 manufacture_date; // 生产日期 (Unix时间戳)
|
||||
} factory_info_t;
|
||||
|
||||
/**
|
||||
* @brief 将出厂信息写入Flash
|
||||
*
|
||||
* @param info 指向要写入的出厂信息结构体的指针
|
||||
* @return 实际写入的长度, <0: 失败
|
||||
*/
|
||||
int nvs_write_factory_info(const factory_info_t *info);
|
||||
|
||||
/**
|
||||
* @brief 从Flash读取出厂信息
|
||||
*
|
||||
* @param info 指向用于存储读取数据的出厂信息结构体的指针
|
||||
* @return 实际读取的长度, <0: 失败 (例如尚未写入过)
|
||||
*/
|
||||
int nvs_read_factory_info(factory_info_t *info);
|
||||
|
||||
/**
|
||||
* @brief 清空Flash中的出厂信息
|
||||
*
|
||||
* @return 0: 成功, <0: 失败
|
||||
*/
|
||||
int nvs_clear_factory_info(void);
|
||||
|
||||
/**
|
||||
* @brief 用于测试NVS读写功能的函数
|
||||
*
|
||||
*/
|
||||
void nvs_test_factory_info(void);
|
||||
|
||||
#endif // __NVS_H__
|
||||
@ -169,6 +169,7 @@ static const struct sin_param *get_sine_param_by_index(u8 index, u8 *num)
|
||||
__BANK_TONE_ENTRY
|
||||
int tone_play_index(u8 index, u8 preemption)
|
||||
{
|
||||
return 0; //xtell
|
||||
printf("tone_play_index:%d,preemption:%d", index, preemption);
|
||||
if (index >= IDEX_TONE_NONE) {
|
||||
return 0;
|
||||
@ -202,6 +203,7 @@ int tone_play_index_no_tws(u8 index, u8 preemption)
|
||||
/* __BANK_TONE_ENTRY */
|
||||
int tone_play_index_with_callback(u8 index, u8 preemption, void (*user_evt_handler)(void *priv), void *priv)
|
||||
{
|
||||
return 0; //xtell
|
||||
printf("tone_play_index:%d,preemption:%d", index, preemption);
|
||||
if (index >= IDEX_TONE_NONE) {
|
||||
return 0;
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
#include "asm/pwm_led.h"
|
||||
#include "aec_user.h"
|
||||
#include "app_power_manage.h"
|
||||
|
||||
#include "avctp_user.h"
|
||||
#define LOG_TAG_CONST USER_CFG
|
||||
#define LOG_TAG "[USER_CFG]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
@ -203,8 +203,8 @@ void cfg_file_parse(u8 idx)
|
||||
} else if (ret >= LOCAL_NAME_LEN) {
|
||||
memset(bt_cfg.edr_name, 0x00, LOCAL_NAME_LEN);
|
||||
// memcpy(bt_cfg.edr_name, tmp, LOCAL_NAME_LEN);
|
||||
extern char xt_ble_new_name[9];
|
||||
memcpy(bt_cfg.edr_name, xt_ble_new_name, LOCAL_NAME_LEN);
|
||||
// extern char xt_ble_new_name[9];
|
||||
// memcpy(bt_cfg.edr_name, xt_ble_new_name, LOCAL_NAME_LEN);
|
||||
bt_cfg.edr_name[LOCAL_NAME_LEN - 1] = 0;
|
||||
} else {
|
||||
memset(bt_cfg.edr_name, 0x00, LOCAL_NAME_LEN);
|
||||
@ -581,5 +581,33 @@ int bt_modify_name(u8 *new_name)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
extern void lmp_hci_write_local_name(const char *name);
|
||||
int xtell_bt_newname(u8 *new_name){
|
||||
u8 new_len = strlen(new_name);
|
||||
if(new_len >= LOCAL_NAME_LEN){
|
||||
new_name[LOCAL_NAME_LEN -1] = 0;
|
||||
}
|
||||
|
||||
if(strcmp(new_name,bt_cfg.edr_name)){
|
||||
user_send_cmd_prepare(USER_CTRL_DISCONNECTION_HCI, 0, NULL); //断开此时经典蓝牙的连接,但经典蓝牙还是可以被发现
|
||||
user_send_cmd_prepare(USER_CTRL_WRITE_SCAN_DISABLE, 0, NULL); //关闭蓝牙可发现,已连接时不能操作
|
||||
user_send_cmd_prepare(USER_CTRL_WRITE_CONN_DISABLE, 0, NULL); //关闭蓝牙可连接
|
||||
|
||||
syscfg_write(CFG_BT_NAME,new_name,LOCAL_NAME_LEN);
|
||||
memcpy(bt_cfg.edr_name,new_name,LOCAL_NAME_LEN);
|
||||
lmp_hci_write_local_name(bt_get_local_name());
|
||||
printf("xtell set new name sucess\n");
|
||||
|
||||
delay_2ms(25);
|
||||
bt_ble_init();
|
||||
user_send_cmd_prepare(USER_CTRL_WRITE_SCAN_ENABLE, 0, NULL); //打开蓝牙可发现,已连接时不能操作
|
||||
user_send_cmd_prepare(USER_CTRL_WRITE_CONN_ENABLE, 0, NULL); //打开蓝牙可连接
|
||||
connect_last_device_from_vm();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -94,6 +94,7 @@
|
||||
#define REG_VERSION 0x7F
|
||||
|
||||
#define CMD_MASK 0x1F
|
||||
// #define CMD_MASK 0x0F
|
||||
|
||||
#define CMD_IDLE 0x00
|
||||
#define CMD_LPCD 0x01
|
||||
@ -21,7 +21,7 @@ struct CPU_CARD_STR CPU_CARD;
|
||||
static unsigned char FM176XX_TPDU(transmission_struct *tpdu);
|
||||
|
||||
/**
|
||||
* @brief CPU卡事件处理函数(示例)。
|
||||
* @brief CPU卡事件处理函数。
|
||||
* @details
|
||||
* 1. 发送RATS (Request for Answer to Select) 命令以激活卡片并获取ATS (Answer to Select)。
|
||||
* 2. 解析ATS,获取卡片能力信息(如FSC, FWI等)。
|
||||
@ -67,9 +67,9 @@ void Mifare_Clear_Crypto(void)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Mifare卡事件处理函数(示例)。
|
||||
* @brief Mifare卡事件处理函数。
|
||||
* @details
|
||||
* 这是一个示例函数,演示了对Mifare Classic卡进行读写操作的完整流程:
|
||||
* Mifare Classic卡进行读写操作的完整流程:
|
||||
* 1. 清除加密状态。
|
||||
* 2. 对指定的扇区(例如扇区1)使用密钥A进行认证。
|
||||
* 3. 如果认证成功,则遍历该扇区的数据块(块0到块2)。
|
||||
@ -19,9 +19,9 @@
|
||||
unsigned char PAGE_DATA[16];
|
||||
|
||||
/**
|
||||
* @brief NTAG卡事件处理函数(示例)。
|
||||
* @brief NTAG卡事件处理函数。
|
||||
* @details
|
||||
* 这是一个示例函数,演示了对NTAG系列卡片进行读写操作的流程:
|
||||
* 对NTAG系列卡片进行读写操作的流程:
|
||||
* 1. 准备要写入的数据(4字节)。
|
||||
* 2. 调用 `Write_Page()` 函数将数据写入第8页。
|
||||
* 3. 调用 `Read_Page()` 函数从第8页读回数据并打印,以进行验证。
|
||||
@ -230,6 +230,7 @@ unsigned char ReaderV_Initial(void)
|
||||
{
|
||||
LoadProtocol(RX_TYPEV_26, RX_TYPEV_26);
|
||||
ModifyReg(REG_RXANA, MASK_RCV_GAIN | MASK_RCV_HPCF, FUN_DISABLE);
|
||||
// ModifyReg(REG_RXANA,BIT3|BIT2|BIT1|BIT0, FUN_DISABLE);
|
||||
ModifyReg(REG_RXANA, (HPCF_V << 3) | GAIN_V, FUN_ENABLE);
|
||||
SetParity(FUN_DISABLE);
|
||||
SetReg(REG_TXAMP, AMPLITUDE_V);
|
||||
@ -590,7 +591,7 @@ unsigned char ReaderB_Get_SN(struct picc_b_struct *picc_b)
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
extern void debug_command(u8 index);
|
||||
/**
|
||||
* @brief 向Type V (ISO15693) 卡片发送Inventory命令。
|
||||
* @param picc_v [out] 指向存储卡片信息的结构体。
|
||||
@ -599,8 +600,14 @@ unsigned char ReaderB_Get_SN(struct picc_b_struct *picc_b)
|
||||
unsigned char ReaderV_Inventory(struct picc_v_struct *picc_v)
|
||||
{
|
||||
unsigned char reg_data, i, result; // 新增 result 变量
|
||||
SetCommand(CMD_IDLE);
|
||||
unsigned char command = 0;
|
||||
|
||||
// debug_command(0);
|
||||
|
||||
SetCommand(CMD_IDLE);
|
||||
//对于command,可以在发送第二条指令之前读取一次command寄存器判断是否回到idle再发送第二条,这里直接采用长延迟
|
||||
rfid_delay_ms(100);
|
||||
// debug_command(1);
|
||||
|
||||
SetReg(REG_TXDATANUM, 0x08);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE);
|
||||
@ -612,7 +619,8 @@ unsigned char ReaderV_Inventory(struct picc_v_struct *picc_v)
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(50);
|
||||
// debug_command(2);
|
||||
rfid_delay_ms(100);
|
||||
|
||||
GetReg(REG_ERROR, ®_data);
|
||||
if ((reg_data & 0x0F) != 0){
|
||||
@ -622,6 +630,7 @@ unsigned char ReaderV_Inventory(struct picc_v_struct *picc_v)
|
||||
|
||||
GetReg(REG_FIFOLENGTH, ®_data);
|
||||
if (reg_data != 10){
|
||||
// debug_command(3);
|
||||
xlog("FIFO Length is %d, expected 10.\n", reg_data);
|
||||
return FAIL;
|
||||
}
|
||||
@ -24,7 +24,7 @@
|
||||
|
||||
|
||||
/**
|
||||
* @brief 处理Type A卡片事件。
|
||||
* @brief 处理Type A卡片事件。uid:8位数组
|
||||
* @details
|
||||
* 该函数执行ISO/IEC 14443 Type A卡片的完整激活流程,包括:
|
||||
* 1. 初始化读卡器以支持Type A协议。
|
||||
@ -34,7 +34,7 @@
|
||||
* 5. 操作结束后关闭RF场。
|
||||
* @return 无。
|
||||
*/
|
||||
void TYPE_A_EVENT(void)
|
||||
void TYPE_A_EVENT(char* uid)
|
||||
{
|
||||
unsigned char result;
|
||||
int i;
|
||||
@ -75,14 +75,16 @@ void TYPE_A_EVENT(void)
|
||||
xlog("-> UID = ");
|
||||
for (i = 0; i < PICC_A.UID_Length; i++)
|
||||
{
|
||||
uid[i] = PICC_A.UID[i];
|
||||
xlog("%02X", PICC_A.UID[i]);
|
||||
}
|
||||
xlog("\r\n");
|
||||
}
|
||||
xlog("-> SAK = %02X\r\n", PICC_A.SAK[0]);
|
||||
|
||||
// 根据SAK值判断卡片类型
|
||||
if (PICC_A.SAK[0] == 0x08)
|
||||
// 根据SAK值判断卡片类型,并进行写入要存储的数据,目前客户使用的是mifare的卡
|
||||
#if 0
|
||||
if (PICC_A.SAK[0] == 0x08) //
|
||||
{
|
||||
xlog("************* Mifare CARD ************* \r\n");
|
||||
result = MIFARE_CARD_EVENT();
|
||||
@ -97,6 +99,7 @@ void TYPE_A_EVENT(void)
|
||||
xlog("************* NTAG CARD ************* \r\n");
|
||||
result = NTAG_EVENT();
|
||||
}
|
||||
#endif
|
||||
|
||||
SetCW(FUN_DISABLE); // 关闭RF场
|
||||
}
|
||||
@ -168,7 +171,7 @@ void TYPE_B_EVENT(void)
|
||||
* 6. 操作结束后关闭RF场。
|
||||
* @return 无。
|
||||
*/
|
||||
void TYPE_V_EVENT(void)
|
||||
void TYPE_V_EVENT(char* uid)
|
||||
{
|
||||
unsigned char result, i;
|
||||
xlog("TYPE_V_EVENT begin\n");
|
||||
@ -188,6 +191,7 @@ void TYPE_V_EVENT(void)
|
||||
xlog("UID=");
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
uid[i] = PICC_V.UID[i];
|
||||
xlog("%02X", PICC_V.UID[i]);
|
||||
}
|
||||
xlog("\r\n");
|
||||
@ -298,6 +302,6 @@ void rfid_task_fuc(void)
|
||||
|
||||
// TYPE_A_EVENT();
|
||||
// TYPE_B_EVENT();
|
||||
TYPE_V_EVENT();
|
||||
// TYPE_V_EVENT();
|
||||
// TYPE_F_EVENT();
|
||||
}
|
||||
@ -52,6 +52,12 @@ unsigned char FM176XX_HardInit(void){
|
||||
#else
|
||||
int ret = soft_iic_init(0);
|
||||
#endif
|
||||
|
||||
//PowerDown脚,初始化要确保其是置为0
|
||||
gpio_set_direction(IO_PORTC_04, 0);
|
||||
gpio_write(IO_PORTC_04, 1);
|
||||
mdelay(5);
|
||||
gpio_write(IO_PORTC_04, 0);
|
||||
xlog("init iic result:%d\n", ret); //返回0成功
|
||||
}
|
||||
|
||||
@ -67,15 +73,18 @@ unsigned char GetReg(unsigned char address, unsigned char *reg_data){
|
||||
soft_iic_start(0);
|
||||
if (0 == soft_iic_tx_byte(0, FM176_WRITE_ADDR)) {
|
||||
soft_iic_stop(0);
|
||||
xlog("GetReg: 【write】 addr write error:%x\n", FM176_WRITE_ADDR);
|
||||
return FAIL;
|
||||
}
|
||||
if (0 == soft_iic_tx_byte(0, address)) {
|
||||
soft_iic_stop(0);
|
||||
xlog("GetReg: 【reg】 addr write error: %x\n", address);
|
||||
return FAIL;
|
||||
}
|
||||
soft_iic_start(0);
|
||||
if (0 == soft_iic_tx_byte(0, FM176_READ_ADDR)) {
|
||||
soft_iic_stop(0);
|
||||
xlog("GetReg: 【read】 addr read error: %x\n", FM176_READ_ADDR);
|
||||
return FAIL;
|
||||
}
|
||||
*reg_data = soft_iic_rx_byte(0, 0);
|
||||
@ -96,14 +105,17 @@ unsigned char SetReg(unsigned char address, unsigned char reg_data){
|
||||
soft_iic_start(0);
|
||||
if (0 == soft_iic_tx_byte(0, FM176_WRITE_ADDR)) {
|
||||
soft_iic_stop(0);
|
||||
xlog("SetReg: 【write】 addr write error: %x \n", FM176_WRITE_ADDR);
|
||||
return FAIL;
|
||||
}
|
||||
if (0 == soft_iic_tx_byte(0, address)) {
|
||||
soft_iic_stop(0);
|
||||
xlog("SetReg: 【reg】 addr write error: %x\n", address);
|
||||
return FAIL;
|
||||
}
|
||||
if (0 == soft_iic_tx_byte(0, reg_data)) {
|
||||
soft_iic_stop(0);
|
||||
xlog("SetReg: 【reg】 data write error\n");
|
||||
return FAIL;
|
||||
}
|
||||
soft_iic_stop(0);
|
||||
@ -118,6 +130,13 @@ unsigned char SetReg(unsigned char address, unsigned char reg_data){
|
||||
*/
|
||||
unsigned char FM176XX_SoftReset(void){
|
||||
return SetReg(REG_COMMAND, 0x1F);
|
||||
|
||||
//
|
||||
// gpio_set_direction(IO_PORTC_04, 0);
|
||||
// gpio_write(IO_PORTC_04, 1);
|
||||
// mdelay(5);
|
||||
// gpio_write(IO_PORTC_04, 0);
|
||||
|
||||
}
|
||||
|
||||
#elif INTERFACE_TYPE == 1 //spi
|
||||
@ -216,5 +235,14 @@ unsigned char FM176XX_SoftReset(void){
|
||||
|
||||
void rfid_delay_ms(unsigned int ms){
|
||||
// delay(ms);
|
||||
os_time_dly(ms/10);
|
||||
mdelay(ms);
|
||||
}
|
||||
|
||||
|
||||
void debug_command(u8 index){
|
||||
unsigned char reg_data;
|
||||
unsigned char command = 0;
|
||||
GetReg(REG_ERROR, ®_data);
|
||||
GetReg(REG_COMMAND, &command);
|
||||
xlog("debug %d -- REG_ERROR = 0x%02X. command = 0x%02X\n",index, reg_data, command);
|
||||
}
|
||||
2830
apps/earphone/xtell_remote_control/ble_handler/ble_handler.c
Normal file
2830
apps/earphone/xtell_remote_control/ble_handler/ble_handler.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -45,7 +45,7 @@
|
||||
#include "default_event_handler.h"
|
||||
#include "debug.h"
|
||||
#include "system/event.h"
|
||||
#include "../remote_control/nvs.h"
|
||||
#include "../nvs/nvs.h"
|
||||
#if (JL_EARPHONE_APP_EN)
|
||||
#include "rcsp_adv_bluetooth.h"
|
||||
#endif
|
||||
@ -82,7 +82,7 @@ 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";
|
||||
unsigned char xt_ble_new_name[9] = "tws";
|
||||
static u16 play_poweron_ok_timer_id = 0;
|
||||
|
||||
// -- 初始化标志位 --
|
||||
@ -102,6 +102,7 @@ extern void create_process(u16* pid, const char* name, void *priv, void (*func)(
|
||||
extern void close_process(u16* pid,char* name);
|
||||
extern void start_collect_fuc(void);
|
||||
extern void BLE_send_fuc(void);
|
||||
extern void xtell_ble_central_test_start(void);
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
* 模式状态机, 通过start_app()控制状态切换
|
||||
@ -301,7 +302,8 @@ static int bt_connction_status_event_handler(struct bt_event *bt)
|
||||
ble_bqb_test_thread_init();
|
||||
} else {
|
||||
#if !TCFG_WIRELESS_MIC_ENABLE
|
||||
bt_ble_init();
|
||||
bt_ble_init(); // lmx,初始化完,初始化ble,决定ble是作为主设备还是从设备
|
||||
// xtell_ble_central_test_start(); //xtell
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@ -335,7 +337,7 @@ static int bt_connction_status_event_handler(struct bt_event *bt)
|
||||
bt_newname =1;
|
||||
u8 temp[5]={0xBB,0xBE,0x02,0x04,0x00};
|
||||
temp[4] = xtell_bl_state; //经典蓝牙连接状态
|
||||
send_data_to_ble_client(&temp,5);
|
||||
// send_data_to_ble_client(&temp,5);
|
||||
}
|
||||
earphone_change_pwr_mode(PWR_DCDC15, 3000);
|
||||
sys_auto_shut_down_disable();
|
||||
@ -368,7 +370,7 @@ static int bt_connction_status_event_handler(struct bt_event *bt)
|
||||
bt_newname=0;
|
||||
u8 temp[5]={0xBB,0xBE,0x02,0x04,0x00};
|
||||
temp[4] = xtell_bl_state; //经典蓝牙连接状态
|
||||
send_data_to_ble_client(&temp,5);
|
||||
// send_data_to_ble_client(&temp,5);
|
||||
}
|
||||
if (app_var.goto_poweroff_flag) {
|
||||
/*关机不播断开提示音*/
|
||||
273
apps/earphone/xtell_remote_control/ble_handler/ble_test.c
Normal file
273
apps/earphone/xtell_remote_control/ble_handler/ble_test.c
Normal file
@ -0,0 +1,273 @@
|
||||
|
||||
#include "system/app_core.h"
|
||||
#include "system/includes.h"
|
||||
#include "btstack/btstack_task.h"
|
||||
#include "btstack/bluetooth.h"
|
||||
#include "le_common.h"
|
||||
#include "ble_user.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if 0 //ENABLE_THIS_TEST
|
||||
|
||||
#define LOG_TAG_CONST EARPHONE
|
||||
#define LOG_TAG "[BLE_TEST]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
// =================== 配置区 START ===================
|
||||
|
||||
// 1. 设置要连接的目标从机设备蓝牙名称
|
||||
#define TARGET_BLE_NAME "CM-22222"
|
||||
|
||||
// 2. 设置要搜索的 Service UUID 和 Characteristic UUID
|
||||
// Service UUID: 0x180D
|
||||
#define TARGET_SERVICE_UUID16 0x180D
|
||||
// Characteristic UUID: 0x2A37 (Notify)
|
||||
#define TARGET_CHARACTERISTIC_UUID16 0x2A37
|
||||
#define TARGET_CHARACTERISTIC_OPT_TYPE ATT_PROPERTY_NOTIFY
|
||||
|
||||
// =================== 配置区 END =====================
|
||||
|
||||
// ATT RAM buffer
|
||||
#define ATT_LOCAL_MTU_SIZE (517)
|
||||
#define ATT_SEND_CBUF_SIZE (256)
|
||||
#define ATT_RAM_BUFSIZE (ATT_CTRL_BLOCK_SIZE + ATT_LOCAL_MTU_SIZE + ATT_SEND_CBUF_SIZE)
|
||||
static u8 att_ram_buffer[ATT_RAM_BUFSIZE] __attribute__((aligned(4)));
|
||||
|
||||
// Profile 搜索 buffer
|
||||
#define SEARCH_PROFILE_BUFSIZE (512)
|
||||
static u8 search_ram_buffer[SEARCH_PROFILE_BUFSIZE] __attribute__((aligned(4)));
|
||||
|
||||
// BLE 工作状态
|
||||
static u8 ble_work_state = 0;
|
||||
static hci_con_handle_t con_handle;
|
||||
|
||||
// 搜索到的目标特征值句柄
|
||||
static u16 target_write_handle = 0;
|
||||
static u16 target_notify_handle = 0;
|
||||
|
||||
// 函数前向声明
|
||||
static int ble_central_test_scan_enable(u32 en);
|
||||
static void cbk_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
|
||||
|
||||
// 设置 BLE 工作状态
|
||||
static void set_ble_work_state(u8 state) {
|
||||
if (state != ble_work_state) {
|
||||
log_info("ble_work_state: %d -> %d\n", ble_work_state, state);
|
||||
ble_work_state = state;
|
||||
}
|
||||
}
|
||||
|
||||
// 解析广播数据,寻找目标设备
|
||||
static bool resolve_adv_report(u8 *adv_address, u8 data_length, u8 *data) {
|
||||
u8 i, length, ad_type;
|
||||
u8 *adv_data_ptr = data;
|
||||
|
||||
for (i = 0; i < data_length;) {
|
||||
if (*adv_data_ptr == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
length = *adv_data_ptr++;
|
||||
ad_type = *adv_data_ptr++;
|
||||
i += (length + 1);
|
||||
|
||||
if (ad_type == HCI_EIR_DATATYPE_COMPLETE_LOCAL_NAME || ad_type == HCI_EIR_DATATYPE_SHORTENED_LOCAL_NAME) {
|
||||
if (length > 1 && (0 == memcmp(adv_data_ptr, TARGET_BLE_NAME, strlen(TARGET_BLE_NAME)))) {
|
||||
log_info("Found target device: %s", TARGET_BLE_NAME);
|
||||
log_info_hexdump(adv_address, 6);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
adv_data_ptr += (length - 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 创建连接
|
||||
static void central_test_create_connection(u8 *addr, u8 addr_type) {
|
||||
if (ble_work_state >= BLE_ST_CREATE_CONN) {
|
||||
return;
|
||||
}
|
||||
log_info("Stopping scan...");
|
||||
ble_central_test_scan_enable(0);
|
||||
|
||||
struct create_conn_param_t conn_param = {0};
|
||||
conn_param.conn_interval = 24;
|
||||
conn_param.conn_latency = 0;
|
||||
conn_param.supervision_timeout = 600;
|
||||
conn_param.peer_address_type = addr_type;
|
||||
memcpy(conn_param.peer_address, addr, 6);
|
||||
|
||||
set_ble_work_state(BLE_ST_CREATE_CONN);
|
||||
ble_op_create_connection(&conn_param);
|
||||
}
|
||||
|
||||
// 开始搜索 Profile
|
||||
static void central_test_search_profile() {
|
||||
target_write_handle = 0;
|
||||
target_notify_handle = 0;
|
||||
user_client_init(con_handle, search_ram_buffer, SEARCH_PROFILE_BUFSIZE);
|
||||
ble_op_search_profile_all();
|
||||
}
|
||||
|
||||
// 搜索 Profile 结果回调
|
||||
void user_client_report_search_result(search_result_t *result_info) {
|
||||
if (result_info == (void *)-1) {
|
||||
log_info("Search profile complete.");
|
||||
set_ble_work_state(BLE_ST_SEARCH_COMPLETE);
|
||||
// 如果找到了 NOTIFY 特征,使能它
|
||||
if (target_notify_handle) {
|
||||
log_info("Enabling notification for handle 0x%04x", target_notify_handle);
|
||||
u16 val = 0x0001;
|
||||
ble_op_att_send_data(target_notify_handle + 1, &val, 2, ATT_OP_WRITE);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (result_info->services.uuid16 == TARGET_SERVICE_UUID16 &&
|
||||
result_info->characteristic.uuid16 == TARGET_CHARACTERISTIC_UUID16) {
|
||||
log_info("Found target characteristic UUID 0x%04x", TARGET_CHARACTERISTIC_UUID16);
|
||||
if ((result_info->characteristic.properties & ATT_PROPERTY_WRITE_WITHOUT_RESPONSE) ||
|
||||
(result_info->characteristic.properties & ATT_PROPERTY_WRITE)) {
|
||||
target_write_handle = result_info->characteristic.value_handle;
|
||||
log_info("Found write handle: 0x%04x", target_write_handle);
|
||||
}
|
||||
if (result_info->characteristic.properties & ATT_PROPERTY_NOTIFY) {
|
||||
target_notify_handle = result_info->characteristic.value_handle;
|
||||
log_info("Found notify handle: 0x%04x", target_notify_handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 接收到数据回调
|
||||
void user_client_report_data_callback(att_data_report_t *report_data) {
|
||||
log_info("RX data, handle=0x%04x, len=%d:", report_data->value_handle, report_data->blob_length);
|
||||
log_info_hexdump(report_data->blob, report_data->blob_length);
|
||||
}
|
||||
|
||||
// BLE 事件回调处理
|
||||
static void cbk_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) {
|
||||
switch (packet_type) {
|
||||
case HCI_EVENT_PACKET:
|
||||
switch (hci_event_packet_get_type(packet)) {
|
||||
case HCI_EVENT_LE_META:
|
||||
switch (hci_event_le_meta_get_subevent_code(packet)) {
|
||||
case HCI_SUBEVENT_LE_ENHANCED_CONNECTION_COMPLETE:
|
||||
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
|
||||
if (hci_subevent_le_connection_complete_get_status(packet)) {
|
||||
log_error("Connection failed, status: 0x%x", hci_subevent_le_connection_complete_get_status(packet));
|
||||
set_ble_work_state(BLE_ST_CONNECT_FAIL);
|
||||
ble_central_test_scan_enable(1); // 重新开始扫描
|
||||
} else {
|
||||
con_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
||||
log_info("Connection established, handle: 0x%04x", con_handle);
|
||||
ble_op_att_send_init(con_handle, att_ram_buffer, ATT_RAM_BUFSIZE, ATT_LOCAL_MTU_SIZE);
|
||||
set_ble_work_state(BLE_ST_CONNECT);
|
||||
central_test_search_profile();
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
||||
log_info("Disconnected, reason: 0x%x", hci_event_disconnection_complete_get_reason(packet));
|
||||
con_handle = 0;
|
||||
ble_op_att_send_init(0, NULL, 0, 0);
|
||||
set_ble_work_state(BLE_ST_DISCONN);
|
||||
ble_central_test_scan_enable(1); // 断开后重新扫描
|
||||
break;
|
||||
|
||||
case GAP_EVENT_ADVERTISING_REPORT:
|
||||
if (ble_work_state != BLE_ST_SCAN) {
|
||||
break;
|
||||
}
|
||||
adv_report_t *report = (void *)&packet[2];
|
||||
if (resolve_adv_report(report->address, report->length, report->data)) {
|
||||
central_test_create_connection(report->address, report->address_type);
|
||||
}
|
||||
break;
|
||||
|
||||
case ATT_EVENT_MTU_EXCHANGE_COMPLETE:
|
||||
log_info("MTU exchange complete, MTU = %d", att_event_mtu_exchange_complete_get_MTU(packet));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 启动或停止扫描
|
||||
static int ble_central_test_scan_enable(u32 en) {
|
||||
if (en) {
|
||||
if (ble_work_state >= BLE_ST_SCAN) {
|
||||
return 0; // 已经在扫描或连接中
|
||||
}
|
||||
log_info("Starting scan...");
|
||||
set_ble_work_state(BLE_ST_SCAN);
|
||||
ble_op_set_scan_param(SCAN_ACTIVE, 48, 48);
|
||||
ble_op_scan_enable2(1, 0);
|
||||
} else {
|
||||
if (ble_work_state < BLE_ST_SCAN) {
|
||||
return 0; // 已经停止
|
||||
}
|
||||
log_info("Stopping scan...");
|
||||
set_ble_work_state(BLE_ST_IDLE);
|
||||
ble_op_scan_enable2(0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 发送数据接口
|
||||
int xtell_ble_central_test_send_data(u8 *data, u16 len) {
|
||||
if (!con_handle || ble_work_state != BLE_ST_SEARCH_COMPLETE) {
|
||||
log_error("Not connected or profile search not complete.");
|
||||
return -1;
|
||||
}
|
||||
if (!target_write_handle) {
|
||||
log_error("No writable characteristic found.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = ble_op_att_send_data(target_write_handle, data, len, ATT_OP_WRITE_WITHOUT_RESPOND);
|
||||
if (ret == 0) {
|
||||
log_info("TX data, len=%d:", len);
|
||||
log_info_hexdump(data, len);
|
||||
} else {
|
||||
log_error("Failed to send data, ret=%d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// 注册 BLE central 模式需要的回调
|
||||
static void ble_central_test_register_handlers(void) {
|
||||
log_info("Registering BLE central test handlers...");
|
||||
// 注意:le_device_db_init() 和 ble_stack_gatt_role() 可能已被RCSP的profile_init调用
|
||||
// 这里我们只覆盖 packet handlers
|
||||
gatt_client_init(); // 确保 gatt client 被初始化
|
||||
gatt_client_register_packet_handler(cbk_packet_handler);
|
||||
hci_event_callback_set(cbk_packet_handler);
|
||||
le_l2cap_register_packet_handler(cbk_packet_handler);
|
||||
ble_vendor_set_default_att_mtu(ATT_LOCAL_MTU_SIZE);
|
||||
}
|
||||
|
||||
// 测试总开关和初始化
|
||||
void xtell_ble_central_test_start(void) {
|
||||
if (ble_work_state != 0) {
|
||||
log_info("Test is already running.");
|
||||
return;
|
||||
}
|
||||
log_info("======== Xtell BLE Central Test Start ========");
|
||||
set_ble_work_state(BLE_ST_INIT_OK);
|
||||
ble_module_enable(1); // 使能 BLE 模块
|
||||
ble_central_test_register_handlers(); // 注册我们的回调
|
||||
ble_central_test_scan_enable(1); // 开始扫描
|
||||
}
|
||||
|
||||
#endif
|
||||
2144
apps/earphone/xtell_remote_control/ble_handler/client_handler.c
Normal file
2144
apps/earphone/xtell_remote_control/ble_handler/client_handler.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,60 @@
|
||||
#ifndef __CLIENT_HANDLER_H__
|
||||
#define __CLIENT_HANDLER_H__
|
||||
|
||||
#include "app_config.h"
|
||||
#include "ble_user.h"
|
||||
/**
|
||||
* @brief BLE客户端退出
|
||||
*/
|
||||
extern void bt_ble_exit(void);
|
||||
|
||||
/**
|
||||
* @brief 应用层调用的断开连接接口
|
||||
*/
|
||||
extern void ble_app_disconnect(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief BLE模块使能/禁止 (兼容旧接口)
|
||||
* @param enable 1:使能, 0:禁止
|
||||
*/
|
||||
extern void bt_ble_adv_enable(u8 enable);
|
||||
|
||||
/**
|
||||
* @brief BLE模块使能/禁止
|
||||
* @param en 1:使能, 0:禁止
|
||||
*/
|
||||
extern void ble_module_enable(u8 en);
|
||||
|
||||
/**
|
||||
* @brief 客户端发起连接参数更新请求
|
||||
*/
|
||||
extern void client_send_conn_param_update(void);
|
||||
|
||||
/**
|
||||
* @brief 清除绑定信息
|
||||
*/
|
||||
extern void clear_bonding_info(void);
|
||||
|
||||
/**
|
||||
* @brief 连接新的设备
|
||||
*
|
||||
* @param name 设备的名称
|
||||
*/
|
||||
extern void g_ble_connect_new_device(char* name);
|
||||
|
||||
/**
|
||||
* @brief 获取当前ble连接状态
|
||||
*
|
||||
* @return //0:连接断开; 1:连接成功
|
||||
*/
|
||||
extern u8 g_ble_get_state(void);
|
||||
|
||||
/**
|
||||
* @brief 发送数据给server
|
||||
*
|
||||
* @param data
|
||||
* @param length
|
||||
*/
|
||||
void g_send_data_to_ble_server(const u8* data, u16 length);
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
147
apps/earphone/xtell_remote_control/nvs/nvs.c
Normal file
147
apps/earphone/xtell_remote_control/nvs/nvs.c
Normal file
@ -0,0 +1,147 @@
|
||||
#include "system/includes.h"
|
||||
#include "system/syscfg_id.h"
|
||||
#include "nvs.h"
|
||||
|
||||
// 2. 定义唯一的配置项ID
|
||||
|
||||
#define CFG_RC_MAC_ADDR_ID 11 // 配置项id
|
||||
|
||||
/**
|
||||
* @brief 将主板MAC地址写入Flash
|
||||
*/
|
||||
int nvs_write_main_board_mac(const u8 *mac_addr)
|
||||
{
|
||||
if (!mac_addr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc_nvs_data_t nvs_data;
|
||||
memcpy(nvs_data.main_board_mac, mac_addr, MAIN_BOARD_MAC_ADDR_LENGTH);
|
||||
|
||||
printf("--> Writing main board MAC to flash...\n");
|
||||
int ret = syscfg_write(CFG_RC_MAC_ADDR_ID, &nvs_data, sizeof(rc_nvs_data_t));
|
||||
if (ret != sizeof(rc_nvs_data_t)) {
|
||||
printf("!!! syscfg_write main board MAC failed, ret = %d\n", ret);
|
||||
} else {
|
||||
printf("--> syscfg_write main board MAC success.\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从Flash读取主板MAC地址
|
||||
*/
|
||||
int nvs_read_main_board_mac(u8 *mac_addr)
|
||||
{
|
||||
if (!mac_addr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc_nvs_data_t nvs_data;
|
||||
printf("--> Reading main board MAC from flash...\n");
|
||||
int ret = syscfg_read(CFG_RC_MAC_ADDR_ID, &nvs_data, sizeof(rc_nvs_data_t));
|
||||
|
||||
if (ret != sizeof(rc_nvs_data_t)) {
|
||||
printf("!!! syscfg_read main board MAC failed, ret = %d. Maybe not set yet.\n", ret);
|
||||
memset(mac_addr, 0, MAIN_BOARD_MAC_ADDR_LENGTH);
|
||||
} else {
|
||||
printf("--> syscfg_read main board MAC success.\n");
|
||||
memcpy(mac_addr, nvs_data.main_board_mac, MAIN_BOARD_MAC_ADDR_LENGTH);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 清空Flash中的出厂信息
|
||||
*
|
||||
* @return 0: 成功, <0: 失败
|
||||
*/
|
||||
int nvs_clear_info(void)
|
||||
{
|
||||
rc_nvs_data_t nvs_data;
|
||||
for(int i = 0 ; i < MAIN_BOARD_MAC_ADDR_LENGTH; i++){
|
||||
nvs_data.main_board_mac[i] = 0;
|
||||
}
|
||||
printf("--> Clearing factory info from flash...\n");
|
||||
// 写入长度为0的数据即可实现删除效果
|
||||
int ret = syscfg_write(CFG_RC_MAC_ADDR_ID, &nvs_data, sizeof(rc_nvs_data_t));
|
||||
if (ret != 0) {
|
||||
printf("!!! syscfg_write clear factory info failed, ret = %d\n", ret);
|
||||
} else {
|
||||
printf("--> syscfg_write clear factory info success.\n");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// =================================================================================
|
||||
// 以下为旧的通用出厂信息API,已废弃
|
||||
// =================================================================================
|
||||
#define CFG_FACTORY_INFO_ID 10 // 旧的、通用的出厂信息ID (已废弃)
|
||||
int nvs_write_factory_info(const factory_info_t *info)
|
||||
{
|
||||
printf("WARNING: nvs_write_factory_info is deprecated.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int nvs_read_factory_info(factory_info_t *info)
|
||||
{
|
||||
printf("WARNING: nvs_read_factory_info is deprecated.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 清空Flash中的出厂信息
|
||||
*
|
||||
* @return 0: 成功, <0: 失败
|
||||
*/
|
||||
int nvs_clear_factory_info(void)
|
||||
{
|
||||
printf("--> Clearing factory info from flash...\n");
|
||||
// 写入长度为0的数据即可实现删除效果
|
||||
int ret = syscfg_write(CFG_FACTORY_INFO_ID, NULL, 0);
|
||||
if (ret != 0) {
|
||||
printf("!!! syscfg_write clear factory info failed, ret = %d\n", ret);
|
||||
} else {
|
||||
printf("--> syscfg_write clear factory info success.\n");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// 可以在这里添加一个测试函数
|
||||
void nvs_test_factory_info(void)
|
||||
{
|
||||
factory_info_t write_info = {
|
||||
.product_id = "RC_V2",
|
||||
.serial_number = "SN202511260002",
|
||||
.hw_version = 0x0102, // v1.1
|
||||
.cal_data = 1234,
|
||||
.manufacture_date = 1764080400, // 2025-11-26
|
||||
};
|
||||
factory_info_t read_info;
|
||||
|
||||
printf("\n\n--- NVS WRITE TEST ---\n");
|
||||
nvs_write_factory_info(&write_info);
|
||||
|
||||
os_time_dly(10);
|
||||
|
||||
printf("\n--- NVS READ TEST ---\n");
|
||||
nvs_read_factory_info(&read_info);
|
||||
|
||||
// ASSERT(memcmp(&write_info, &read_info, sizeof(factory_info_t)) == 0, "NVS Read/Write Check Failed!");
|
||||
|
||||
// printf("\n--- NVS CLEAR TEST ---\n");
|
||||
// nvs_clear_factory_info();
|
||||
|
||||
os_time_dly(10);
|
||||
|
||||
printf("\n--- NVS READ AFTER CLEAR TEST ---\n");
|
||||
int ret = nvs_read_factory_info(&read_info);
|
||||
if(ret < 0){
|
||||
printf("--- nvs read error ---\n");
|
||||
}
|
||||
|
||||
printf("\n\n--- NVS TEST COMPLETE ---\n\n");
|
||||
}
|
||||
58
apps/earphone/xtell_remote_control/nvs/nvs.h
Normal file
58
apps/earphone/xtell_remote_control/nvs/nvs.h
Normal file
@ -0,0 +1,58 @@
|
||||
#ifndef __NVS_H__
|
||||
#define __NVS_H__
|
||||
|
||||
#include "typedef.h"
|
||||
#include "../task_func.h"
|
||||
|
||||
#define MAIN_BOARD_MAC_ADDR_LENGTH UID_LENGTH
|
||||
|
||||
/**
|
||||
* @brief 定义用于存储遥控器配对信息的数据结构
|
||||
*/
|
||||
typedef struct {
|
||||
u8 main_board_mac[MAIN_BOARD_MAC_ADDR_LENGTH]; // 配对的主板MAC地址
|
||||
// u8 reserved[2]; // 可选的保留字节,用于对齐或未来扩展
|
||||
} rc_nvs_data_t;
|
||||
|
||||
/**
|
||||
* @brief 将主板MAC地址写入Flash
|
||||
*
|
||||
* @param mac_addr 指向要写入的MAC地址数组的指针
|
||||
* @return 实际写入的长度, <0: 失败
|
||||
*/
|
||||
int nvs_write_main_board_mac(const u8 *mac_addr);
|
||||
|
||||
/**
|
||||
* @brief 从Flash读取主板MAC地址
|
||||
*
|
||||
* @param mac_addr 指向用于存储读取数据的MAC地址数组的指针
|
||||
* @return 实际读取的长度, <0: 失败 (例如尚未写入过)
|
||||
*/
|
||||
int nvs_read_main_board_mac(u8 *mac_addr);
|
||||
|
||||
int nvs_clear_info(void);
|
||||
// =================================================================================
|
||||
// 以下为旧的通用出厂信息API,已废弃,不建议在新代码中使用
|
||||
// =================================================================================
|
||||
|
||||
typedef struct {
|
||||
char product_id[16];
|
||||
char serial_number[32];
|
||||
u16 hw_version;
|
||||
u16 cal_data;
|
||||
u32 manufacture_date;
|
||||
} factory_info_t;
|
||||
|
||||
__attribute__((deprecated("Use nvs_write_main_board_mac instead")))
|
||||
int nvs_write_factory_info(const factory_info_t *info);
|
||||
|
||||
__attribute__((deprecated("Use nvs_read_main_board_mac instead")))
|
||||
int nvs_read_factory_info(factory_info_t *info);
|
||||
|
||||
__attribute__((deprecated("This function is no longer needed")))
|
||||
int nvs_clear_factory_info(void);
|
||||
|
||||
__attribute__((deprecated("This function is no longer needed")))
|
||||
void nvs_test_factory_info(void);
|
||||
|
||||
#endif // __NVS_H__
|
||||
89
apps/earphone/xtell_remote_control/pwm_test.c
Normal file
89
apps/earphone/xtell_remote_control/pwm_test.c
Normal file
@ -0,0 +1,89 @@
|
||||
#include "asm/mcpwm.h"
|
||||
#include "asm/gpio.h"
|
||||
#include "task_func.h"
|
||||
#include "./nvs/nvs.h"
|
||||
#include "timer.h"
|
||||
#include "system/includes.h"
|
||||
#include "user_cfg.h"
|
||||
#include "earphone.h" // 宏定义 EARPHONE_STATE_...
|
||||
#include "ble_user.h"
|
||||
#include "le_client_demo.h"
|
||||
#include "le_common.h"
|
||||
#include "./ble_handler/client_handler.h"
|
||||
#include "./RFID/include/rfid_main.h"
|
||||
#include "./RFID/include/READER_REG.h"
|
||||
/*
|
||||
* PWM配置参数:
|
||||
* - 周期: 50ms (20Hz)
|
||||
* - 最小脉宽: 500us (1%占空比)
|
||||
* - 最大脉宽: 2.5ms (5%占空比)
|
||||
* - PWM引脚: PA1 (IO_PORTA_01)
|
||||
*/
|
||||
|
||||
void pwm_test_init(void)
|
||||
{
|
||||
struct pwm_platform_data pwm_data = {0};
|
||||
|
||||
// 配置PWM参数
|
||||
pwm_data.pwm_aligned_mode = pwm_edge_aligned; // 边沿对齐模式
|
||||
pwm_data.pwm_ch_num = pwm_ch0; // 使用PWM通道0
|
||||
pwm_data.frequency = 50; // 20Hz (周期50ms)
|
||||
pwm_data.duty = 100; // 初始占空比1% (500us/50ms = 1%)
|
||||
pwm_data.h_pin = IO_PORTA_01; // PWM输出引脚PA1
|
||||
pwm_data.l_pin = -1; // 不使用互补引脚
|
||||
pwm_data.complementary_en = 0; // 非互补模式
|
||||
|
||||
// 初始化PWM
|
||||
mcpwm_init(&pwm_data);
|
||||
|
||||
// 启用PWM通道
|
||||
mcpwm_open(pwm_ch0);
|
||||
}
|
||||
|
||||
// 设置PWM占空比 (脉宽范围: 500us-2.5ms)
|
||||
void pwm_test_set_pulse_width_us(u32 pulse_width_us)
|
||||
{
|
||||
u16 duty;
|
||||
|
||||
// 限制脉宽范围: 500us - 2500us
|
||||
if (pulse_width_us < 500) {
|
||||
pulse_width_us = 500;
|
||||
} else if (pulse_width_us > 2500) {
|
||||
pulse_width_us = 2500;
|
||||
}
|
||||
|
||||
// 计算占空比: (脉宽/周期) * 10000
|
||||
// 周期20ms = 20000us
|
||||
duty = (pulse_width_us * 10000) / 20000;
|
||||
|
||||
// 设置占空比
|
||||
mcpwm_set_duty(pwm_ch0, duty);
|
||||
}
|
||||
|
||||
// 测试函数: 从最小脉宽到最大脉宽循环变化
|
||||
void pwm_test_sweep(void)
|
||||
{
|
||||
u32 pulse_width;
|
||||
|
||||
pwm_test_set_pulse_width_us(500);
|
||||
mdelay(1000);
|
||||
pwm_test_set_pulse_width_us(2500);
|
||||
mdelay(50);
|
||||
|
||||
}
|
||||
|
||||
// 主测试函数
|
||||
void pwm_test_main(void)
|
||||
{
|
||||
// 初始化PWM
|
||||
pwm_test_init();
|
||||
|
||||
// 设置最小脉宽500us
|
||||
pwm_test_set_pulse_width_us(500);
|
||||
|
||||
// 运行脉宽扫描测试
|
||||
while (1) {
|
||||
pwm_test_sweep();
|
||||
os_time_dly(100);
|
||||
}
|
||||
}
|
||||
494
apps/earphone/xtell_remote_control/task_func.c
Normal file
494
apps/earphone/xtell_remote_control/task_func.c
Normal file
@ -0,0 +1,494 @@
|
||||
#include "task_func.h"
|
||||
#include "./nvs/nvs.h"
|
||||
#include "timer.h"
|
||||
#include "system/includes.h"
|
||||
#include "user_cfg.h"
|
||||
#include "earphone.h" // 宏定义 EARPHONE_STATE_...
|
||||
#include "ble_user.h"
|
||||
#include "le_client_demo.h"
|
||||
#include "le_common.h"
|
||||
#include "./ble_handler/client_handler.h"
|
||||
#include "./RFID/include/rfid_main.h"
|
||||
#include "./RFID/include/READER_REG.h"
|
||||
// ==================================================================================================================================================================
|
||||
// 宏定义与日志
|
||||
// ==================================================================================================================================================================
|
||||
|
||||
#define RC_LOG_ENABLE 1
|
||||
#if RC_LOG_ENABLE
|
||||
#define rc_log(format, ...) printf("[RC_APP] " format, ##__VA_ARGS__)
|
||||
#else
|
||||
#define rc_log(format, ...)
|
||||
#endif
|
||||
|
||||
// ==================================================================================================================================================================
|
||||
// 外部函数声明
|
||||
// ==================================================================================================================================================================
|
||||
extern void TYPE_V_EVENT(char* uid);
|
||||
extern void TYPE_A_EVENT(char* uid);
|
||||
// ==================================================================================================================================================================
|
||||
// 静态函数声明
|
||||
// ==================================================================================================================================================================
|
||||
|
||||
static RFID_Device_Type_t get_rfid_device_type(const u8* uid);
|
||||
|
||||
// BLE 状态转换的辅助函数
|
||||
static void rc_ble_state_set_connecting(void);
|
||||
static void rc_ble_state_set_connected(void);
|
||||
static void rc_ble_state_set_disconnected(void);
|
||||
|
||||
//进程名称
|
||||
static char control_key_task_name[] = "control_key";
|
||||
|
||||
//进程运行中标志
|
||||
static u8 key_detect_sign = 0; //为1表示正在运行
|
||||
|
||||
// ==================================================================================================================================================================
|
||||
// 全局变量
|
||||
// ==================================================================================================================================================================
|
||||
|
||||
static RC_Context_t g_rc_context; // 全局上下文实例
|
||||
static u16 g_rfid_timer_id = 0; // RFID 定时器ID
|
||||
static u16 g_ble_timer_id = 0; // BLE 定时器ID
|
||||
static u8 current_board_mac[MAIN_BOARD_MAC_ADDR_LENGTH] = {0}; //当前连接主板的名称 -- mac
|
||||
|
||||
|
||||
|
||||
// ==================================================================================================================================================================
|
||||
// rfid功能相关
|
||||
// ==================================================================================================================================================================
|
||||
|
||||
/**
|
||||
* @brief RFID回调处理函数 (由定时器周期性调用)
|
||||
*/
|
||||
void rc_rfid_callback_handler(void *priv)
|
||||
{
|
||||
u8 uid[UID_LENGTH] = {0};
|
||||
|
||||
//读id卡
|
||||
// TYPE_V_EVENT((char *)uid);
|
||||
TYPE_A_EVENT((char *)uid);
|
||||
|
||||
//是否有rfid卡靠近
|
||||
u8 is_new_data = 0;
|
||||
for (int i = 0; i < UID_LENGTH; i++) {
|
||||
if (uid[i] != 0x00) {
|
||||
is_new_data = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_new_data) {
|
||||
return; //没有rfid卡靠近,返回
|
||||
}
|
||||
|
||||
|
||||
rc_log("New RFID card detected.\n");
|
||||
|
||||
RFID_Device_Type_t device_type = get_rfid_device_type(uid);
|
||||
|
||||
switch (device_type) {
|
||||
case RFID_DEVICE_TYPE_MAIN_BOARD: //船主板上的rfid卡
|
||||
if(strncmp(uid, current_board_mac, UID_LENGTH) == 0){
|
||||
// 扫到的rfid卡的uid和当前连接的主板mac相同
|
||||
return;
|
||||
}
|
||||
//扫到新的主板
|
||||
rc_log("Device is Main Board. Storing MAC...\n");
|
||||
// 将新的MAC地址写入Flash
|
||||
nvs_write_main_board_mac(uid);
|
||||
|
||||
// memset(current_board_mac, uid, sizeof(current_board_mac));
|
||||
|
||||
// TODO:发送指令,让主板断开经典蓝牙连接
|
||||
// TODO: 切断BLE
|
||||
|
||||
// g_ble_connect_new_device(current_board_mac); //连接新主板
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case RFID_DEVICE_TYPE_REMOTE_CONTROL: //扫的是遥控器
|
||||
rc_log("Device is another Remote Control.\n");
|
||||
if(g_rc_context.team != TEAM_YES){
|
||||
nvs_clear_info(); //清楚nfc数据
|
||||
return; //非组队状态
|
||||
}
|
||||
if (g_ble_get_state() == BLE_ST_NOTIFY_IDICATE) {
|
||||
rc_log("Sending teaming request to main board...\n");
|
||||
//TODO:
|
||||
//向主板发送新的遥控器rfid uid
|
||||
} else {
|
||||
rc_log("Not connected to main board, ignoring teaming request.\n");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
rc_log("Unknown RFID device type.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ==================================================================================================================================================================
|
||||
// ble功能相关
|
||||
// ==================================================================================================================================================================
|
||||
|
||||
/**
|
||||
* @brief BLE回调处理函数 (由定时器周期性调用)s
|
||||
*/
|
||||
void rc_ble_callback_handler(void *priv)
|
||||
{
|
||||
u8 read_uid[UID_LENGTH] = {0};
|
||||
nvs_read_main_board_mac(read_uid); //读nvs
|
||||
|
||||
//读到的是当前连接的主板uid
|
||||
if((strncmp(read_uid, current_board_mac, UID_LENGTH) == 0) && g_ble_get_state()){
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
|
||||
// bool is_connected = ble_hid_is_connected();
|
||||
|
||||
// // 状态机转换
|
||||
// if (is_connected && g_rc_context.state != RC_STATE_CONNECTED) {
|
||||
// rc_ble_state_set_connected();
|
||||
// } else if (!is_connected && g_rc_context.state != RC_STATE_DISCONNECTED) {
|
||||
// rc_ble_state_set_disconnected();
|
||||
// }
|
||||
|
||||
// // 状态机行为
|
||||
// switch (g_rc_context.state) {
|
||||
// case RC_STATE_DISCONNECTED:
|
||||
// {
|
||||
// u8 target_mac[MAC_ADDR_LENGTH] = {0};
|
||||
// // 检查Flash中是否有已配对的MAC
|
||||
// if (nvs_read_main_board_mac(target_mac) > 0) {
|
||||
// rc_log("Found paired MAC. Start scanning...\n");
|
||||
// // 启动扫描和连接。SDK的HID实现会自动连接到已配对的设备。
|
||||
// EARPHONE_STATE_SET_PAGE_SCAN_ENABLE();
|
||||
// } else {
|
||||
// rc_log("No paired MAC found. Waiting for RFID pairing...\n");
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
|
||||
// case RC_STATE_CONNECTING:
|
||||
// // 在这个状态下,我们只是等待 is_connected 变为 true
|
||||
// rc_log("Waiting for connection result...\n");
|
||||
// break;
|
||||
|
||||
// case RC_STATE_CONNECTED:
|
||||
// // 已连接,目前无需周期性操作
|
||||
// // rc_log("BLE is connected.\n");
|
||||
// break;
|
||||
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 根据UID前缀判断设备类型
|
||||
*/
|
||||
static RFID_Device_Type_t get_rfid_device_type(const u8* uid)
|
||||
{
|
||||
if (uid == NULL) {
|
||||
return RFID_DEVICE_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
// 根据 RC_app_main.h 中定义的UID前缀进行判断
|
||||
if (uid[0] == UID_PREFIX_MAIN_BOARD) {
|
||||
return RFID_DEVICE_TYPE_MAIN_BOARD;
|
||||
} else if (uid[0] == UID_PREFIX_REMOTE_CONTROL) {
|
||||
return RFID_DEVICE_TYPE_REMOTE_CONTROL;
|
||||
}
|
||||
|
||||
return RFID_DEVICE_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
// ==================================================================================================================================================================
|
||||
// 遥感按键相关
|
||||
// ==================================================================================================================================================================
|
||||
/**
|
||||
* @brief 遥感按键初始化
|
||||
*
|
||||
*/
|
||||
void control_key_init(void){
|
||||
//Yout
|
||||
adc_add_sample_ch(AD_CH_PG5);
|
||||
gpio_set_die(IO_PORTG_05, 0);
|
||||
gpio_set_direction(IO_PORTG_05, 1);
|
||||
gpio_set_pull_down(IO_PORTG_05, 0);
|
||||
gpio_set_pull_up(IO_PORTG_05, 0);
|
||||
|
||||
//Xout
|
||||
adc_add_sample_ch(AD_CH_PG7);
|
||||
gpio_set_die(IO_PORTG_07, 0);
|
||||
gpio_set_direction(IO_PORTG_07, 1);
|
||||
gpio_set_pull_down(IO_PORTG_07, 0);
|
||||
gpio_set_pull_up(IO_PORTG_07, 0);
|
||||
|
||||
//key 1:默认为高,按下为低
|
||||
gpio_set_die(IO_PORTG_06, 1);
|
||||
gpio_set_direction(IO_PORTG_06, 1);
|
||||
gpio_set_pull_down(IO_PORTG_06, 0);
|
||||
gpio_set_pull_up(IO_PORTG_06, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 获取遥感按键值
|
||||
*
|
||||
* @param Xout_adc x轴遥感adc
|
||||
* @param Yout_adc y轴遥感adc
|
||||
* @param key1_state 按键1值
|
||||
* @param key2_state 按键2值
|
||||
*/
|
||||
void control_key_get_value(u16* Xout_adc, u16* Yout_adc, u8* key1_state, u8* key2_state){
|
||||
*Xout_adc = (u16)adc_get_value(AD_CH_PG5) * 64;
|
||||
*Yout_adc = (u16)adc_get_value(AD_CH_PG7) * 64;
|
||||
|
||||
if(*Yout_adc >= 65535){
|
||||
*Yout_adc = 65535;
|
||||
}
|
||||
if(*Xout_adc >= 65535){
|
||||
*Xout_adc = 65535;
|
||||
}
|
||||
|
||||
*key1_state = gpio_read(IO_PORTG_06);
|
||||
rc_log("adc_get_value: Xout = %d, Yout = %d, key1_state = %d, key2_state = %d\n", *Xout_adc , *Yout_adc, *key1_state, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 按键的处理任务
|
||||
*
|
||||
*/
|
||||
void contol_key_task(void){
|
||||
static u16 vbat_value = 0; //当前剩余电量
|
||||
static u16 Xout_adc = 0;
|
||||
static u16 Yout_adc = 0;
|
||||
static u8 key1_state = 1;
|
||||
u8 ble_data_buff[12] = {0xBE, 0xBB, 0x09, 0x01, //0-3
|
||||
0x00, 0x00, 0x00, 0x00, //4-7 遥感值:上下、左右
|
||||
0x00, 0x00, //8、9 两个按键
|
||||
0x00, //10 电量百分比
|
||||
0x00}; //11 校验和
|
||||
|
||||
control_key_init(); //遥感按键初始化
|
||||
|
||||
while(1){
|
||||
extern u16 get_vbat_level(void);
|
||||
vbat_value = get_vbat_level(); //当前电量
|
||||
control_key_get_value(&Xout_adc, &Yout_adc, &key1_state, NULL); //遥感值
|
||||
ble_data_buff[4] = (u8)(Yout_adc & 0xFF);
|
||||
ble_data_buff[5] = (u8)((Yout_adc >> 8) & 0xFF);
|
||||
|
||||
ble_data_buff[6] = (u8)(Xout_adc & 0xFF);
|
||||
ble_data_buff[7] = (u8)((Xout_adc >> 8) & 0xFF);
|
||||
|
||||
ble_data_buff[8] = key1_state;
|
||||
ble_data_buff[9] = 0x01;
|
||||
|
||||
ble_data_buff[10] = get_vbat_percent();
|
||||
|
||||
ble_data_buff[11] = 0;
|
||||
for(int i = 0 ;i < 11; i++){
|
||||
ble_data_buff[11] += ble_data_buff[i];
|
||||
}
|
||||
|
||||
// u8 test_buff[12] = {0xBE,0xBB,0x09,0x01,0x50,0x50,0x50,0x50,0x01,0x01,0x50,0x15};
|
||||
g_send_data_to_ble_server(ble_data_buff, sizeof(ble_data_buff));
|
||||
/*
|
||||
1000
|
||||
700
|
||||
500
|
||||
*/
|
||||
os_time_dly(10); //10ms为单位
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 和主板ble连接上后会被调用
|
||||
*
|
||||
*/
|
||||
void create_key_detect_thread(void){
|
||||
key_detect_sign = 1;
|
||||
os_task_create(contol_key_task, NULL, 1, 2048, 128, control_key_task_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 和主板ble断连后会被调用
|
||||
*
|
||||
*/
|
||||
void destroy_key_detect_thread(void){
|
||||
if(key_detect_sign == 1){
|
||||
key_detect_sign = 0;
|
||||
os_task_del(control_key_task_name);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================================================================================================================================================================
|
||||
// 辅助函数
|
||||
// ==================================================================================================================================================================
|
||||
|
||||
/**
|
||||
* @brief 进入 CONNECTING 状态的逻辑
|
||||
*/
|
||||
static void rc_ble_state_set_connecting(void)
|
||||
{
|
||||
rc_log("State transition to -> CONNECTING\n");
|
||||
g_rc_context.state = RC_STATE_CONNECTING;
|
||||
// 可以在这里控制LED灯效,例如黄灯呼吸闪烁
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 进入 CONNECTED 状态的逻辑
|
||||
*/
|
||||
static void rc_ble_state_set_connected(void)
|
||||
{
|
||||
rc_log("State transition to -> CONNECTED\n");
|
||||
g_rc_context.state = RC_STATE_CONNECTED;
|
||||
// 停止扫描以省电
|
||||
EARPHONE_STATE_CANCEL_PAGE_SCAN();
|
||||
|
||||
// 发送指令,要求主板连接遥控器的经典蓝牙
|
||||
u8 classic_conn_req_payload[] = {0x01, 0x02, 0x03};
|
||||
rc_log("Sending request for classic BT connection.\n");
|
||||
ble_hid_data_send(0xFE, classic_conn_req_payload, sizeof(classic_conn_req_payload));
|
||||
|
||||
// 在这里控制LED灯效,例如蓝灯呼吸闪烁三次后熄灭
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 进入 DISCONNECTED 状态的逻辑
|
||||
*/
|
||||
static void rc_ble_state_set_disconnected(void)
|
||||
{
|
||||
rc_log("State transition to -> DISCONNECTED\n");
|
||||
g_rc_context.state = RC_STATE_DISCONNECTED;
|
||||
// 在这里控制LED灯效,例如黄灯呼吸闪烁
|
||||
}
|
||||
|
||||
// ==================================================================================================================================================================
|
||||
// 初始化函数
|
||||
// ==================================================================================================================================================================
|
||||
|
||||
/**
|
||||
* @brief 遥控器应用主初始化函数
|
||||
*/
|
||||
void rc_app_main_init(void)
|
||||
{
|
||||
rc_log("Initializing Remote Control App...\n");
|
||||
|
||||
// 初始化全局上下文
|
||||
memset(&g_rc_context, 0, sizeof(RC_Context_t));
|
||||
g_rc_context.state = RC_STATE_DISCONNECTED; // 初始状态为未连接
|
||||
g_rc_context.team = TEAM_NO;
|
||||
FM176XX_HardInit();
|
||||
|
||||
// 检查并启动RFID处理定时器
|
||||
if (g_rfid_timer_id == 0) {
|
||||
// g_rfid_timer_id = sys_timer_add(NULL, rc_rfid_callback_handler, RC_RFID_CALLBACK_INTERVAL_MS);
|
||||
rc_log("RFID handler timer started (ID: %d).\n", g_rfid_timer_id);
|
||||
}
|
||||
|
||||
// 检查并启动BLE处理定时器
|
||||
if (g_ble_timer_id == 0) {
|
||||
// g_ble_timer_id = sys_timer_add(NULL, rc_ble_callback_handler, RC_BLE_CALLBACK_INTERVAL_MS);
|
||||
rc_log("BLE handler timer started (ID: %d).\n", g_ble_timer_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//test
|
||||
#define TEST_FUNCTION 1
|
||||
|
||||
void g_i2c_scanner_probe(u8* device_addr, u8* found_number)
|
||||
{
|
||||
printf("Starting I2C bus scan...\n");
|
||||
int devices_found = 0;
|
||||
|
||||
// I2C地址范围是 0x08 到 0x77
|
||||
for (uint8_t addr_7bit = 0x00; addr_7bit < 0x7F; addr_7bit++)
|
||||
{
|
||||
// 构建8位的写地址
|
||||
uint8_t write_addr_8bit = (addr_7bit << 1);
|
||||
|
||||
//传入使用的iic句柄编号
|
||||
soft_iic_start(0);
|
||||
|
||||
// 尝试发送写地址,并检查返回值
|
||||
// iic_tx_byte 返回 1 表示收到了 ACK
|
||||
if (soft_iic_tx_byte(0, write_addr_8bit))
|
||||
{
|
||||
printf("=====================================================================\n");
|
||||
printf("I2C device found at 7-bit address: 0x%02X\n", addr_7bit);
|
||||
printf("I2C device found at 8-bit address: 0x%02X\n", write_addr_8bit);
|
||||
printf("=====================================================================\n");
|
||||
devices_found++;
|
||||
}
|
||||
|
||||
//传入使用的iic句柄编号
|
||||
soft_iic_stop(0);
|
||||
mdelay(2); // 短暂延时
|
||||
}
|
||||
|
||||
if (devices_found == 0) {
|
||||
printf("Scan finished. No I2C devices found.\n");
|
||||
} else {
|
||||
printf("Scan finished. Found %d device(s).\n", devices_found);
|
||||
}
|
||||
}
|
||||
|
||||
void test_task(void){
|
||||
|
||||
|
||||
#if TEST_FUNCTION == 1
|
||||
unsigned char reg_data = 0;
|
||||
unsigned char command = 0;
|
||||
FM176XX_HardInit();
|
||||
rfid_delay_ms(5); // 硬件初始化后增加一个短暂延时,确保芯片稳定
|
||||
int result = FM176XX_SoftReset();
|
||||
// if (result != SUCCESS)
|
||||
// {
|
||||
// rc_log("FM176XX HardReset FAIL\r\n");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// rc_log("FM176XX HardReset SUCCESS\r\n");
|
||||
// }
|
||||
|
||||
rfid_delay_ms(10); // 复位后延时
|
||||
|
||||
// 读取芯片版本号,确认通信是否正常
|
||||
GetReg(REG_VERSION, ®_data);
|
||||
rc_log("REG_VERSION = %02X\r\n", reg_data);
|
||||
|
||||
|
||||
u8 device_buff[10];
|
||||
u8 founds = 0;
|
||||
extern void g_i2c_scanner_probe(u8* device_addr, u8* found_number);
|
||||
g_i2c_scanner_probe(device_buff,&founds);
|
||||
|
||||
while(1){
|
||||
u8 uid[UID_LENGTH] = {0};
|
||||
//读id卡
|
||||
// TYPE_V_EVENT((char *)uid);
|
||||
TYPE_A_EVENT((char *)uid);
|
||||
os_time_dly(500);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
void test_func_main(void){
|
||||
#if TEST_FUNCTION == 1
|
||||
|
||||
os_task_create(test_task, NULL, 1, 1024, 128, "rfid_test");
|
||||
extern void pwm_test_main(void);
|
||||
// os_task_create(pwm_test_main, NULL, 1, 1024, 128, "pwm_test"); //pwm测试
|
||||
// os_task_create(contol_key_task, NULL, 1, 2048, 128, control_key_task_name);
|
||||
|
||||
#endif
|
||||
}
|
||||
101
apps/earphone/xtell_remote_control/task_func.h
Normal file
101
apps/earphone/xtell_remote_control/task_func.h
Normal file
@ -0,0 +1,101 @@
|
||||
#ifndef __RC_APP_MAIN_H__
|
||||
#define __RC_APP_MAIN_H__
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
// =================================================================================
|
||||
// 常量定义 (Constants)
|
||||
// =================================================================================
|
||||
|
||||
// 假设UID的前1个字节用于区分设备类型
|
||||
#define UID_PREFIX_MAIN_BOARD 0xA1 // 主板UID前缀
|
||||
#define UID_PREFIX_REMOTE_CONTROL 0xA2 // 遥控器UID前缀
|
||||
|
||||
#define UID_LENGTH 8 // RFID UID 的标准长度
|
||||
|
||||
// 定时器调用间隔 (ms)
|
||||
#define RC_RFID_CALLBACK_INTERVAL_MS 500 // RFID轮询间隔,500ms
|
||||
#define RC_BLE_CALLBACK_INTERVAL_MS 1000 // BLE状态机处理间隔, 1s
|
||||
|
||||
// =================================================================================
|
||||
// 枚举与结构体定义 (Enums & Structs)
|
||||
// =================================================================================
|
||||
|
||||
/**
|
||||
* @brief 遥控器核心状态机
|
||||
*/
|
||||
typedef enum {
|
||||
RC_STATE_IDLE, // 空闲状态,等待初始化
|
||||
RC_STATE_DISCONNECTED, // 未连接主板 (正在扫描或等待)
|
||||
RC_STATE_CONNECTING, // 正在连接主板
|
||||
RC_STATE_CONNECTED, // 已连接主板
|
||||
} RC_State_t;
|
||||
|
||||
/**
|
||||
* @brief 当前是否处于组队状态
|
||||
*/
|
||||
typedef enum {
|
||||
TEAM_NO, //未组队
|
||||
TEAM_YES,
|
||||
} RC_Team_t;
|
||||
|
||||
/**
|
||||
* @brief RFID读取到的设备类型
|
||||
*/
|
||||
typedef enum {
|
||||
RFID_DEVICE_TYPE_UNKNOWN, // 未知设备
|
||||
RFID_DEVICE_TYPE_MAIN_BOARD, // 船体主板
|
||||
RFID_DEVICE_TYPE_REMOTE_CONTROL // 其他遥控器
|
||||
} RFID_Device_Type_t;
|
||||
|
||||
/**
|
||||
* @brief 遥控器应用全局上下文
|
||||
*/
|
||||
typedef struct {
|
||||
RC_State_t state; // 当前状态机状态
|
||||
RC_Team_t team; //当前是否组队
|
||||
u8 paired_mac_addr[UID_LENGTH]; // 已配对主板的MAC地址(包含前缀)
|
||||
// ... 可在此处添加更多运行时需要管理的数据
|
||||
} RC_Context_t;
|
||||
|
||||
|
||||
// =================================================================================
|
||||
// 公共函数声明 (Public Function Prototypes)
|
||||
// =================================================================================
|
||||
|
||||
/**
|
||||
* @brief 遥控器应用主初始化函数
|
||||
* @details
|
||||
* - 初始化全局上下文
|
||||
* - 设置并启动RFID和BLE处理定时器
|
||||
*/
|
||||
void rc_app_main_init(void);
|
||||
|
||||
/**
|
||||
* @brief RFID回调处理函数 (由定时器周期性调用)
|
||||
* @details
|
||||
* - 调用RFID读取函数
|
||||
* - 分析UID并执行相应逻辑 (配对/组队)
|
||||
*/
|
||||
void rc_rfid_callback_handler(void *priv);
|
||||
|
||||
/**
|
||||
* @brief BLE回调处理函数 (由定时器周期性调用)
|
||||
* @details
|
||||
* - 维护与主板的BLE连接状态
|
||||
* - 处理断线重连等
|
||||
*/
|
||||
void rc_ble_callback_handler(void *priv);
|
||||
|
||||
/**
|
||||
* @brief BLE连接状态回调 (由蓝牙协议栈调用)
|
||||
* @param status 0: 成功, 其他: 失败
|
||||
* @param addr 连接或断开的设备地址
|
||||
* @details
|
||||
* - 在BLE连接成功后,请求主板连接经典蓝牙
|
||||
* - 更新连接状态
|
||||
*/
|
||||
// void rc_ble_connection_status_callback(u8 status, u8 *addr); // No longer needed
|
||||
|
||||
|
||||
#endif // __RC_APP_MAIN_H__
|
||||
@ -7,4 +7,6 @@
|
||||
|
||||
#define ACC_RANGE 16 //g,加速度满量程:2、4、8、16
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@ -1,23 +1,14 @@
|
||||
#include "system/includes.h"
|
||||
/*#include "btcontroller_config.h"*/
|
||||
#include "btstack/btstack_task.h"
|
||||
#include "app_config.h"
|
||||
#include "app_action.h"
|
||||
#include "asm/pwm_led.h"
|
||||
#include "tone_player.h"
|
||||
#include "gpio.h"
|
||||
#include "app_main.h"
|
||||
#include "asm/charge.h"
|
||||
#include "update.h"
|
||||
#include "update_loader_download.h"
|
||||
#include "app_power_manage.h"
|
||||
#include "app_charge.h"
|
||||
#include "bt_profile_cfg.h"
|
||||
#include "dev_manager/dev_manager.h"
|
||||
#include "update_loader_download.h"
|
||||
#include "avctp_user.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
#include "avctp_user.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//宏定义
|
||||
@ -41,45 +32,35 @@
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//变量
|
||||
|
||||
//-------------------------------------------------------------------------------------------------//
|
||||
// 外部函数/变量声明
|
||||
//-------------------------------------------------------------------------------------------------//
|
||||
extern APP_VAR app_var;
|
||||
u16 close_BL_number=0;
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//函数定义
|
||||
extern void timer_2ms_handler();
|
||||
extern void app_var_init(void);
|
||||
void app_earphone_play_voice_file(const char *name);
|
||||
void clr_wdt(void);
|
||||
extern void check_power_on_key(void);
|
||||
extern int cpu_reset_by_soft();
|
||||
extern int audio_dec_init();
|
||||
extern int audio_enc_init();
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//-------------------------------------------------------------------------------------------------//
|
||||
// 全局变量
|
||||
//-------------------------------------------------------------------------------------------------//
|
||||
unsigned char xt_bt_new_name[13] = "WEBIRD-XXXXX"; //经典蓝牙名称
|
||||
|
||||
//-------------------------------------------------------------------------------------------------//
|
||||
// 系统主函数 app_main
|
||||
//-------------------------------------------------------------------------------------------------//
|
||||
|
||||
|
||||
|
||||
|
||||
/*充电拔出,CPU软件复位, 不检测按键,直接开机*/
|
||||
static void app_poweron_check(int update)
|
||||
{
|
||||
if (!update && cpu_reset_by_soft()) {
|
||||
app_var.play_poweron_tone = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
void create_process(u16* pid,char* name, void *priv, void (*func)(void *priv), u32 msec){
|
||||
/**
|
||||
* @brief 创建一个周期性执行的系统定时器任务
|
||||
*/
|
||||
void create_process(u16* pid, const char* name, void *priv, void (*func)(void *priv), u32 msec){
|
||||
xlog("1 name=%s, pid =%d\n",name,*pid);
|
||||
if (*pid != 0) return;
|
||||
*pid = sys_timer_add(priv, func, msec);
|
||||
xlog("2 name=%s, pid =%d\n",name,*pid);
|
||||
}
|
||||
void close_process(u16* pid,char* name){
|
||||
|
||||
/**
|
||||
* @brief 关闭一个系统定时器任务
|
||||
*/
|
||||
void close_process(u16* pid, const char* name){
|
||||
xlog("name=%s,pid =%d\n",name,*pid);
|
||||
if (*pid == 0) return;
|
||||
sys_timer_del(*pid);
|
||||
@ -87,43 +68,39 @@ void close_process(u16* pid,char* name){
|
||||
}
|
||||
|
||||
|
||||
void close_BL(){
|
||||
/**开机默认关闭 经典蓝牙 */
|
||||
// close_BL_flag++;
|
||||
xlog("xtell Classic Bluetooth off\n");
|
||||
user_send_cmd_prepare(USER_CTRL_DISCONNECTION_HCI, 0, NULL); //断开此时经典蓝牙的连接,经典蓝牙还是可以被发现
|
||||
delay_2ms(50);
|
||||
user_send_cmd_prepare(USER_CTRL_WRITE_SCAN_DISABLE, 0, NULL); //关闭蓝牙可发现,已连接时不能操作
|
||||
delay_2ms(50);
|
||||
user_send_cmd_prepare(USER_CTRL_WRITE_CONN_DISABLE, 0, NULL); //关闭蓝牙可连接,
|
||||
// sys_timer_del(close_BL_number); //删除定时器任务
|
||||
close_process(&close_BL_number,__func__);
|
||||
/*充电拔出,CPU软件复位, 不检测按键,直接开机*/
|
||||
static void app_poweron_check(int update)
|
||||
{
|
||||
extern int cpu_reset_by_soft();
|
||||
if (!update && cpu_reset_by_soft()) {
|
||||
app_var.play_poweron_tone = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void xtell_set_ble_name(char* name){
|
||||
|
||||
}
|
||||
|
||||
|
||||
extern u32 timer_get_ms(void);
|
||||
/**
|
||||
* @brief 应用层主入口
|
||||
*/
|
||||
void xtell_app_main()
|
||||
{
|
||||
int update = 0;
|
||||
u32 addr = 0, size = 0;
|
||||
struct intent it;
|
||||
|
||||
xlog("==============xtell_app_main start================\n");
|
||||
log_info("app_main\n");
|
||||
extern u32 timer_get_ms(void);
|
||||
app_var.start_time = timer_get_ms();
|
||||
|
||||
|
||||
|
||||
// 检查是否有固件升级
|
||||
if (!UPDATE_SUPPORT_DEV_IS_NULL()) {
|
||||
update = update_result_deal();
|
||||
}
|
||||
|
||||
// 初始化应用层变量
|
||||
extern void app_var_init(void);
|
||||
app_var_init();
|
||||
|
||||
// 根据充电状态决定进入 idle 模式还是 handler 模式
|
||||
if (get_charge_online_flag()) {
|
||||
#if(TCFG_SYS_LVD_EN == 1)
|
||||
vbat_check_init();
|
||||
@ -144,30 +121,23 @@ void xtell_app_main()
|
||||
xlog("==============handler end================\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
//开机必须延时关闭经典蓝牙,不然底层代码会再次把蓝牙 打开
|
||||
// create_process(&close_BL_number, "close_BL",NULL, close_BL, 3000);
|
||||
|
||||
|
||||
|
||||
xlog("==============xtell_app_end================\n");
|
||||
|
||||
u8 mac_data[6];
|
||||
extern void rcsp_adv_fill_mac_addr(u8 *mac_addr_buf);
|
||||
rcsp_adv_fill_mac_addr(mac_data); //读取MAC地址
|
||||
xlog("xtell BT mac data:%x:%x:%x:%x:%x:%x",mac_data[0],mac_data[1],mac_data[2],mac_data[3],mac_data[4],mac_data[5]);
|
||||
|
||||
// user_send_cmd_prepare(USER_CTRL_WRITE_SCAN_ENABLE, 0, NULL); //打开蓝牙可发现,已连接时不能操作
|
||||
// delay_2ms(50);
|
||||
// user_send_cmd_prepare(USER_CTRL_WRITE_CONN_ENABLE, 0, NULL); //打开蓝牙可连接
|
||||
// delay_2ms(50);
|
||||
|
||||
user_send_cmd_prepare(USER_CTRL_WRITE_SCAN_ENABLE, 0, NULL); //打开蓝牙可发现,已连接时不能操作
|
||||
delay_2ms(50);
|
||||
user_send_cmd_prepare(USER_CTRL_WRITE_CONN_ENABLE, 0, NULL); //打开蓝牙可连接
|
||||
delay_2ms(50);
|
||||
// soft_iic_init(0);
|
||||
// extern int xtell_bt_newname(u8 *new_name);
|
||||
// xtell_bt_newname(xt_bt_new_name); //设置经典蓝牙名
|
||||
|
||||
|
||||
|
||||
xlog("==============xtell_app_end================\n");
|
||||
|
||||
extern void test_func_main(void);
|
||||
test_func_main();
|
||||
}
|
||||
|
||||
@ -13,6 +13,11 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -13,6 +13,11 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
sdfile_vfs_ops
|
||||
|
||||
@ -113,7 +113,7 @@ int lp_vad_mic_data_init(struct vad_mic_platform_data *mic_data)
|
||||
if (vbg_trim != 0xf) {
|
||||
data->power_data.acm_select = get_vad_vbg_trim();
|
||||
}
|
||||
lp_vad_mic_in_enable(mic_data);
|
||||
// lp_vad_mic_in_enable(mic_data); //xtell mic
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,6 +13,11 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -61,4 +66,4 @@ copy /b text.bin + data.bin + mov_slot.bin + data_code.bin + aec.bin + aac.bin +
|
||||
|
||||
del !bankfiles! common.bin text.bin data.bin bank.bin
|
||||
copy eq_cfg_hw_less.bin eq_cfg_hw.bin
|
||||
call download/earphone/download_app_ota.bat
|
||||
call download/earphone/download.bat
|
||||
|
||||
@ -10,7 +10,7 @@ copy ..\..\ota.bin .
|
||||
copy ..\..\anc_coeff.bin .
|
||||
copy ..\..\anc_gains.bin .
|
||||
|
||||
..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin -res ..\..\cfg_tool.bin tone.cfg p11_code.bin ..\..\eq_cfg_hw.bin -uboot_compress -key AC69.key -format all -key 646-AC690X-7603.key
|
||||
..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin -res ..\..\cfg_tool.bin tone.cfg p11_code.bin ..\..\eq_cfg_hw.bin -uboot_compress -format all -key 646-AC690X-7603.key
|
||||
|
||||
@REM..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br34 -boot 0x20000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin ..\..\cfg_tool.bin -res tone.cfg kws_command.bin p11_code.bin -uboot_compress
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ copy ..\..\ota.bin .
|
||||
copy ..\..\anc_coeff.bin .
|
||||
copy ..\..\anc_gains.bin .
|
||||
|
||||
..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin -res ..\..\cfg_tool.bin tone.cfg p11_code.bin ..\..\eq_cfg_hw.bin -uboot_compress -key 646-AC690X-7603.key
|
||||
..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin -res ..\..\cfg_tool.bin tone.cfg p11_code.bin ..\..\eq_cfg_hw.bin -uboot_compress
|
||||
|
||||
@REM..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br34 -boot 0x20000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin ..\..\cfg_tool.bin -res tone.cfg kws_command.bin p11_code.bin -uboot_compress
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ copy ..\..\anc_coeff.bin .
|
||||
copy ..\..\anc_gains.bin .
|
||||
|
||||
:: -format all -key AC690X-8029.key
|
||||
..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin -res ..\..\cfg_tool.bin tone.cfg p11_code.bin ..\..\eq_cfg_hw.bin -uboot_compress -key AC690X-8029.key
|
||||
..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin -res ..\..\cfg_tool.bin tone.cfg p11_code.bin ..\..\eq_cfg_hw.bin -uboot_compress
|
||||
|
||||
@REM..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br34 -boot 0x20000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin ..\..\cfg_tool.bin -res tone.cfg kws_command.bin p11_code.bin -uboot_compress
|
||||
|
||||
|
||||
Binary file not shown.
@ -13,13 +13,19 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[EXTRA_CFG_PARAM]
|
||||
NEW_FLASH_FS = YES;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BR22_TWS_DB = YES;
|
||||
FLASH_SIZE = 0x100000;
|
||||
BR22_TWS_VERSION = 0;
|
||||
FORCE_4K_ALIGN = YES;
|
||||
SPECIAL_OPT = 0;
|
||||
CHIP_NAME = AC701N;
|
||||
ENTRY = 0x6000100;
|
||||
PID = AC701N;
|
||||
@ -68,6 +74,18 @@ FILE_LIST = (file = ota.bin: type = 100);
|
||||
BTIF_ADR = AUTO;
|
||||
BTIF_LEN = 0x1000;
|
||||
BTIF_OPT = 1;
|
||||
|
||||
|
||||
EXIF_ADR = AUTO;
|
||||
EXIF_LEN = 0x1000;
|
||||
EXIF_OPT = 1;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
PRCT_ADR = 0;
|
||||
PRCT_LEN = CODE_LEN;
|
||||
PRCT_OPT = 2;
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
0
objs/apps/common/device/usb/device/cdc.c.o-826e812c
Normal file
0
objs/apps/common/device/usb/device/cdc.c.o-826e812c
Normal file
Reference in New Issue
Block a user