This commit is contained in:
lmx
2025-10-30 17:53:59 +08:00
parent a6919c7e43
commit 1d0eaa037b
174 changed files with 196655 additions and 223635 deletions

View File

@ -236,8 +236,13 @@ static void app_poweron_check(int update)
}
extern u32 timer_get_ms(void);
void app_main()
{
void xtell_app_main();
xtell_app_main();
#if 0
int update = 0;
u32 addr = 0, size = 0;
struct intent it;
@ -316,8 +321,10 @@ void app_main()
xtell_main();
#endif
}
int __attribute__((weak)) eSystemConfirmStopStatus(void)
{
/* 系统进入在未来时间里,无任务超时唤醒,可根据用户选择系统停止,或者系统定时唤醒(100ms),或自己指定唤醒时间 */

View File

@ -133,13 +133,14 @@ void __set_sbc_cap_bitpool(u8 sbc_cap_bitpoola);
static u16 power_mode_timer = 0;
u8 init_ok = 0;
u8 get_bt_init_status(void)
{
return init_ok;
}
static u8 sniff_out = 0;
u8 sniff_out = 0;
u8 get_sniff_out_status()
{
return sniff_out;
@ -149,6 +150,7 @@ void clear_sniff_out_status()
sniff_out = 0;
}
void earphone_change_pwr_mode(int mode, int msec)
{
#if TCFG_POWER_MODE_QUIET_ENABLE
@ -2236,7 +2238,7 @@ static void bt_vendor_meta_event_handle(u8 sub_evt, u8 *arg, u8 len)
extern void set_remote_test_flag(u8 own_remote_test);
static int bt_hci_event_handler(struct bt_event *bt)
int bt_hci_event_handler(struct bt_event *bt)
{
//对应原来的蓝牙连接上断开处理函数 ,bt->value=reason
log_info("------------------------bt_hci_event_handler reason %x %x", bt->event, bt->value);
@ -2774,17 +2776,17 @@ static int state_machine(struct application *app, enum app_state state, struct i
return error;
}
static const struct application_operation app_earphone_ops = {
.state_machine = state_machine,
.event_handler = event_handler,
};
// static const struct application_operation app_earphone_ops = {
// .state_machine = state_machine,
// .event_handler = event_handler,
// };
/*
* 注册earphone模式
*/
REGISTER_APPLICATION(app_earphone) = {
.name = "earphone",
.action = ACTION_EARPHONE_MAIN,
.ops = &app_earphone_ops,
.state = APP_STA_DESTROY,
};
// /*
// * 注册earphone模式
// */
// REGISTER_APPLICATION(app_earphone) = {
// .name = "earphone",
// .action = ACTION_EARPHONE_MAIN,
// .ops = &app_earphone_ops,
// .state = APP_STA_DESTROY,
// };

View File

@ -86,7 +86,7 @@ void rcsp_adv_fill_mac_addr(u8 *mac_addr_buf) //by xtell
swapX(bt_get_mac_addr(), mac_addr_buf, 6);
}
void xtell_main(void){
void xtell_task_create(void){
u8 mac_data[6];

View File

@ -0,0 +1,117 @@
#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 "app_power_manage.h"
#include "app_charge.h"
#include "bt_profile_cfg.h"
#include "dev_manager/dev_manager.h"
#include "update_loader_download.h"
#define xlog(format, ...) printf("[%s] " format, __func__, ##__VA_ARGS__)
#define LOG_TAG_CONST APP
#define LOG_TAG "[APP]"
#define LOG_ERROR_ENABLE
#define LOG_DEBUG_ENABLE
#define LOG_INFO_ENABLE
/* #define LOG_DUMP_ENABLE */
#define LOG_CLI_ENABLE
#include "debug.h"
#ifdef CONFIG_BOARD_AISPEECH_VAD_ASR
u8 user_at_cmd_send_support = 1;
#endif
extern APP_VAR app_var;
/*
* 2ms timer中断回调函数
*/
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();
/*充电拔出,CPU软件复位, 不检测按键,直接开机*/
static void app_poweron_check(int update)
{
#if (CONFIG_BT_MODE == BT_NORMAL)
if (!update && cpu_reset_by_soft()) {
app_var.play_poweron_tone = 0;
return;
}
#if TCFG_CHARGE_OFF_POWERON_NE
if (is_ldo5v_wakeup()) {
app_var.play_poweron_tone = 0;
return;
}
#endif
//#ifdef CONFIG_RELEASE_ENABLE
#if TCFG_POWER_ON_NEED_KEY
check_power_on_key();
#endif
//#endif
#endif
}
extern u32 timer_get_ms(void);
void xtell_app_main()
{
int update = 0;
u32 addr = 0, size = 0;
struct intent it;
xlog("==============xtell_app_main================\n");
if (!UPDATE_SUPPORT_DEV_IS_NULL()) {
update = update_result_deal();
}
app_var_init();
// if (get_charge_online_flag()) {
#if(TCFG_SYS_LVD_EN == 1)
vbat_check_init();
#endif
// init_intent(&it);
// it.name = "idle";
// it.action = ACTION_IDLE_MAIN;
// start_app(&it);
// } else {
check_power_on_voltage();
app_poweron_check(update);
init_intent(&it);
it.name = "handler";
it.action = ACTION_EARPHONE_MAIN;
start_app(&it);
// }
log_info("app_main\n");
app_var.start_time = timer_get_ms();
extern void xtell_task_create(void);
xtell_task_create();
}

View File

@ -0,0 +1,424 @@
#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"
#define LOG_TAG_CONST EARPHONE
#define LOG_TAG "[EARPHONE]"
#define LOG_ERROR_ENABLE
#define LOG_DEBUG_ENABLE
#define LOG_INFO_ENABLE
#include "debug.h"
#if(USE_DMA_UART_TEST) //使用dm串口测试时不能同时打开
#define MY_SNIFF_EN 0
#else
#define MY_SNIFF_EN 1 //默认打开
#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-11111";
static u16 play_poweron_ok_timer_id = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////
// u8 get_bt_init_status(void)
// {
// return init_ok;
// }
// u8 get_sniff_out_status()
// {
// return sniff_out;
// }
// void clear_sniff_out_status()
// {
// sniff_out = 0;
// }
extern int bt_hci_event_handler(struct bt_event *bt);
///////////////////////////////////////////////////////////////////////////////////////////////////
/*
* 模式状态机, 通过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;
r_printf("bt_state_machine=%d\n", state);
switch (state) {
case APP_STA_CREATE:
/* set_adjust_conn_dac_check(0); */
STATUS *p_tone = get_tone_config();
tone_play_index(p_tone->bt_init_ok, 1);
break;
case APP_STA_START:
if (!it) {
break;
}
switch (it->action) {
case ACTION_EARPHONE_MAIN:
/*
* earphone 模式初始化
*/
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: //蓝牙音频传输协议
break;
case ACTION_BY_KEY_MODE:
break;
case ACTION_TONE_PLAY:
STATUS *p_tone = get_tone_config();
tone_play_index(p_tone->bt_init_ok, 1);
break;
case ACTION_DO_NOTHING:
break;
}
break;
case APP_STA_PAUSE:
break;
case APP_STA_RESUME:
//恢复前台运行
sys_auto_shut_down_disable();
sys_key_event_enable();
break;
case APP_STA_STOP:
break;
case APP_STA_DESTROY:
r_printf("APP_STA_DESTROY\n");
if (!app_var.goto_poweroff_flag) {
bt_app_exit(NULL);
}
break;
}
return error;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//handle
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:
/*
* 蓝牙初始化完成
*/
log_info("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();
#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:
log_info("BT_STATUS_CONNECTED\n");
xtell_bl_state = 1; //蓝牙连接成功 置1
if(strcmp(xt_ble_new_name,"CM-1111") != 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*/
log_info("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:
log_info("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:
log_info(" 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:
#define AVC_VOLUME_UP 0x41
#define AVC_VOLUME_DOWN 0x42
log_info("BT_STATUS_AVRCP_INCOME_OPID:%d\n", bt->value);
if (bt->value == AVC_VOLUME_UP) {
}
if (bt->value == AVC_VOLUME_DOWN) {
}
break;
default:
log_info(" BT STATUS DEFAULT\n");
break;
}
return 0;
}
static int event_handler(struct application *app, struct sys_event *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 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,
};