初版
This commit is contained in:
@@ -0,0 +1,260 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".a2dp_play.data.bss")
|
||||
#pragma data_seg(".a2dp_play.data")
|
||||
#pragma const_seg(".a2dp_play.text.const")
|
||||
#pragma code_seg(".a2dp_play.text")
|
||||
#endif
|
||||
#include "btstack/avctp_user.h"
|
||||
#include "btstack/btstack_task.h"
|
||||
#include "os/os_api.h"
|
||||
#include "bt_slience_detect.h"
|
||||
#include "a2dp_player.h"
|
||||
#include "esco_player.h"
|
||||
#include "app_tone.h"
|
||||
#include "app_main.h"
|
||||
#include "vol_sync.h"
|
||||
#include "audio_config.h"
|
||||
#include "btstack/a2dp_media_codec.h"
|
||||
#include "bt.h"
|
||||
#include "effect/effects_default_param.h"
|
||||
#include "scene_switch.h"
|
||||
|
||||
#if TCFG_APP_BT_EN
|
||||
#if(TCFG_USER_TWS_ENABLE == 0)
|
||||
//开关a2dp后,是否保持变调状态
|
||||
#define A2DP_PLAYBACK_PITCH_KEEP 0
|
||||
|
||||
enum {
|
||||
CMD_A2DP_PLAY = 1,
|
||||
CMD_A2DP_SLIENCE_DETECT,
|
||||
CMD_A2DP_CLOSE,
|
||||
CMD_SET_A2DP_VOL,
|
||||
};
|
||||
|
||||
static u8 g_play_addr[6];
|
||||
static u8 g_slience_addr[6];
|
||||
|
||||
|
||||
|
||||
/**@brief a2dp
|
||||
@param
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
u8 bt_get_a2dp_en_status()
|
||||
{
|
||||
return g_bt_hdl.a2dp_en;
|
||||
}
|
||||
|
||||
|
||||
void bt_set_a2dp_en_status(u8 on)
|
||||
{
|
||||
printf("%s need todo \n", __FUNCTION__);
|
||||
g_bt_hdl.a2dp_en = !!on;
|
||||
}
|
||||
|
||||
static int bt_init_a2dp_en_status(void)
|
||||
{
|
||||
/* #if TCFG_USER_EMITTER_ENABLE */
|
||||
/* g_bt_hdl.a2dp_en = 0; */
|
||||
/* #else */
|
||||
g_bt_hdl.a2dp_en = 1;
|
||||
/* #endif */
|
||||
return 0;
|
||||
}
|
||||
platform_initcall(bt_init_a2dp_en_status);
|
||||
|
||||
void a2dp_play_close(u8 *bt_addr)
|
||||
{
|
||||
puts("a2dp_play_close\n");
|
||||
put_buf(bt_addr, 6);
|
||||
a2dp_player_close(bt_addr);
|
||||
bt_stop_a2dp_slience_detect(bt_addr);
|
||||
a2dp_media_close(bt_addr);
|
||||
}
|
||||
|
||||
static void a2dp_play_in_task(u8 *data)
|
||||
{
|
||||
u8 btaddr[6];
|
||||
u8 dev_vol;
|
||||
u8 *bt_addr = data + 2;
|
||||
|
||||
switch (data[0]) {
|
||||
case CMD_A2DP_SLIENCE_DETECT:
|
||||
puts("CMD_A2DP_SLIENCT_DETECE\n");
|
||||
put_buf(bt_addr, 6);
|
||||
a2dp_play_close(bt_addr);
|
||||
bt_start_a2dp_slience_detect(bt_addr, 50); //丢掉50包(约1s)之后才开始能量检测,过滤掉提示音,避免提示音引起抢占
|
||||
memset(g_slience_addr, 0xff, 6);
|
||||
break;
|
||||
case CMD_A2DP_PLAY:
|
||||
puts("app_msg_bt_a2dp_play\n");
|
||||
put_buf(bt_addr, 6);
|
||||
#if (TCFG_BT_A2DP_PLAYER_ENABLE == 0)
|
||||
break;
|
||||
#endif
|
||||
app_audio_state_switch(APP_AUDIO_STATE_MUSIC, app_audio_volume_max_query(AppVol_BT_MUSIC), NULL);
|
||||
dev_vol = data[8];
|
||||
//更新一下音量再开始播放
|
||||
if (dev_vol > 127) { //返回值0xff说明不支持音量同步
|
||||
y_printf("device no support sync vol, use sys volume:%d\n", app_var.music_volume);
|
||||
app_audio_set_volume(APP_AUDIO_STATE_MUSIC, app_var.music_volume, 1);
|
||||
app_audio_set_volume_def_state(0);
|
||||
} else {
|
||||
set_music_device_volume(dev_vol);
|
||||
}
|
||||
bt_stop_a2dp_slience_detect(bt_addr);
|
||||
int err = a2dp_player_open(bt_addr);
|
||||
if (err == -EBUSY) {
|
||||
bt_start_a2dp_slience_detect(bt_addr, 50); //丢掉50包(约1s)之后才开始能量检测,过滤掉提示音,避免提示音引起抢占
|
||||
}
|
||||
memset(g_play_addr, 0xff, 6);
|
||||
music_vocal_remover_update_parm();
|
||||
break;
|
||||
case CMD_A2DP_CLOSE:
|
||||
a2dp_play_close(bt_addr);
|
||||
break;
|
||||
case CMD_SET_A2DP_VOL:
|
||||
dev_vol = data[8];
|
||||
set_music_device_volume(dev_vol);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void a2dp_play_send_cmd(u8 cmd, u8 *_data, u8 len, u8 tx_do_action)
|
||||
{
|
||||
u8 data[16];
|
||||
data[0] = cmd;
|
||||
data[1] = 2;
|
||||
memcpy(data + 2, _data, len);
|
||||
a2dp_play_in_task(data);
|
||||
}
|
||||
|
||||
static void a2dp_play(u8 *bt_addr, bool tx_do_action)
|
||||
{
|
||||
u8 data[8];
|
||||
memcpy(data, bt_addr, 6);
|
||||
data[6] = bt_get_music_volume(bt_addr);
|
||||
/* if (data[6] > 127) { */
|
||||
/* data[6] = app_audio_bt_volume_update(bt_addr, APP_AUDIO_STATE_MUSIC); */
|
||||
/* } */
|
||||
a2dp_play_send_cmd(CMD_A2DP_PLAY, data, 7, tx_do_action);
|
||||
}
|
||||
|
||||
static void a2dp_play_slience_detect(u8 *bt_addr, bool tx_do_action)
|
||||
{
|
||||
a2dp_play_send_cmd(CMD_A2DP_SLIENCE_DETECT, bt_addr, 6, tx_do_action);
|
||||
}
|
||||
|
||||
|
||||
static int a2dp_bt_status_event_handler(int *event)
|
||||
{
|
||||
int ret;
|
||||
u8 data[8];
|
||||
u8 btaddr[6];
|
||||
struct bt_event *bt = (struct bt_event *)event;
|
||||
|
||||
switch (bt->event) {
|
||||
case BT_STATUS_A2DP_MEDIA_START:
|
||||
puts("BT_STATUS_A2DP_MEDIA_START\n");
|
||||
put_buf(bt->args, 6);
|
||||
if (app_var.goto_poweroff_flag) {
|
||||
break;
|
||||
}
|
||||
void *file = a2dp_open_media_file(bt->args);
|
||||
if (file == NULL) {
|
||||
printf("open a2dp file error \n");
|
||||
break;
|
||||
}
|
||||
a2dp_close_media_file(file);
|
||||
if (bt_get_call_status_for_addr(bt->args) == BT_CALL_INCOMING) {
|
||||
//小米11来电挂断偶现没有hungup过来,hfp链路异常,重新断开hfp再连接
|
||||
puts("<<<<<<<<waring a2dp start hfp_incoming\n");
|
||||
bt_cmd_prepare_for_addr(bt->args, USER_CTRL_HFP_DISCONNECT, 0, NULL);
|
||||
bt_cmd_prepare_for_addr(bt->args, USER_CTRL_HFP_CMD_CONN, 0, NULL);
|
||||
}
|
||||
if (esco_player_runing()) {
|
||||
a2dp_media_close(bt->args);
|
||||
break;
|
||||
}
|
||||
if (a2dp_player_get_btaddr(btaddr)) {
|
||||
if (memcmp(btaddr, bt->args, 6) == 0) {
|
||||
a2dp_play(bt->args, 1);
|
||||
} else {
|
||||
a2dp_play_slience_detect(bt->args, 1);
|
||||
}
|
||||
} else {
|
||||
a2dp_play(bt->args, 1);
|
||||
}
|
||||
#if (TCFG_PITCH_SPEED_NODE_ENABLE && A2DP_PLAYBACK_PITCH_KEEP)
|
||||
audio_pitch_default_parm_set(app_var.pitch_mode);
|
||||
a2dp_file_pitch_mode_init(app_var.pitch_mode);
|
||||
#endif
|
||||
break;
|
||||
case BT_STATUS_A2DP_MEDIA_STOP:
|
||||
puts("BT_STATUS_A2DP_MEDIA_STOP\n");
|
||||
a2dp_play_send_cmd(CMD_A2DP_CLOSE, bt->args, 6, 1);
|
||||
break;
|
||||
case BT_STATUS_AVRCP_VOL_CHANGE:
|
||||
//判断是当前地址的音量值才更新
|
||||
ret = a2dp_player_get_btaddr(data);
|
||||
if (ret && memcmp(data, bt->args, 6) == 0) {
|
||||
data[6] = bt->value;
|
||||
a2dp_play_send_cmd(CMD_SET_A2DP_VOL, data, 7, 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
APP_MSG_HANDLER(a2dp_stack_msg_handler) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_BT_STACK,
|
||||
.handler = a2dp_bt_status_event_handler,
|
||||
};
|
||||
|
||||
|
||||
static int a2dp_bt_hci_event_handler(int *event)
|
||||
{
|
||||
struct bt_event *bt = (struct bt_event *)event;
|
||||
|
||||
switch (bt->event) {
|
||||
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
||||
a2dp_play_close(bt->args);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
APP_MSG_HANDLER(a2dp_hci_msg_handler) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_BT_HCI,
|
||||
.handler = a2dp_bt_hci_event_handler,
|
||||
};
|
||||
|
||||
static int a2dp_app_msg_handler(int *msg)
|
||||
{
|
||||
u8 *bt_addr = (u8 *)(msg + 1);
|
||||
|
||||
switch (msg[0]) {
|
||||
case APP_MSG_BT_A2DP_PAUSE:
|
||||
puts("app_msg_bt_a2dp_pause\n");
|
||||
if (a2dp_player_is_playing(bt_addr)) {
|
||||
a2dp_play_slience_detect(bt_addr, 1);
|
||||
}
|
||||
break;
|
||||
case APP_MSG_BT_A2DP_PLAY:
|
||||
puts("app_msg_bt_a2dp_play\n");
|
||||
a2dp_play(bt_addr, 1);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
APP_MSG_HANDLER(a2dp_app_msg_handler_stub) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_APP,
|
||||
.handler = a2dp_app_msg_handler,
|
||||
};
|
||||
#endif
|
||||
#endif /* #if TCFG_APP_BT_EN */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,160 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".bt_app_msg_handler.data.bss")
|
||||
#pragma data_seg(".bt_app_msg_handler.data")
|
||||
#pragma const_seg(".bt_app_msg_handler.text.const")
|
||||
#pragma code_seg(".bt_app_msg_handler.text")
|
||||
#endif
|
||||
#include "key_driver.h"
|
||||
#include "app_main.h"
|
||||
#include "init.h"
|
||||
#include "bt_key_func.h"
|
||||
#include "low_latency.h"
|
||||
#include "a2dp_player.h"
|
||||
#include "linein_player.h"
|
||||
#include "app_tone.h"
|
||||
#include "audio_config.h"
|
||||
#include "vol_sync.h"
|
||||
#include "bt.h"
|
||||
#include "classic/tws_api.h"
|
||||
|
||||
#if TCFG_APP_BT_EN
|
||||
|
||||
int bt_app_msg_handler(int *msg)
|
||||
{
|
||||
if (false == app_in_mode(APP_MODE_BT)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
u8 msg_type = msg[0];
|
||||
|
||||
printf("bt_app_msg type:0x%x", msg[0]);
|
||||
switch (msg_type) {
|
||||
case APP_MSG_CHANGE_MODE:
|
||||
puts("app msg key change mode\n");
|
||||
/*一些情况不希望退出蓝牙模式*/
|
||||
if (bt_app_exit_check() == 0) {
|
||||
puts("bt_background can not enter\n");
|
||||
return 0;
|
||||
}
|
||||
#if TCFG_USER_TWS_ENABLE && !TCFG_BT_BACKGROUND_ENABLE
|
||||
#if CONFIG_TWS_USE_COMMMON_ADDR == 0
|
||||
if (tws_api_get_role() == TWS_ROLE_SLAVE) {
|
||||
tws_api_detach(TWS_DETACH_BY_POWEROFF, 5000); //这里从机用TWS_DETACH_BY_POWEROFF断开不会进行主从切换
|
||||
g_bt_hdl.ignore_discon_tone = 1;
|
||||
}
|
||||
#endif
|
||||
if (msg[1] == APP_KEY_MSG_FROM_TWS) { //非后台不响应来自tws的切换模式消息
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
app_send_message(APP_MSG_GOTO_NEXT_MODE, 0);
|
||||
break;
|
||||
case APP_MSG_MUSIC_PP:
|
||||
puts("app msg music pp\n");
|
||||
bt_key_music_pp();
|
||||
break;
|
||||
case APP_MSG_MUSIC_NEXT:
|
||||
puts("app msg music next\n");
|
||||
bt_key_music_next();
|
||||
break;
|
||||
case APP_MSG_MUSIC_PREV:
|
||||
puts("app msg music prev\n");
|
||||
bt_key_music_prev();
|
||||
break;
|
||||
case APP_MSG_VOL_UP:
|
||||
puts("app msg vol up\n");
|
||||
bt_key_vol_up();
|
||||
break;
|
||||
case APP_MSG_VOL_DOWN:
|
||||
puts("app msg vol down\n");
|
||||
bt_key_vol_down();
|
||||
break;
|
||||
case APP_MSG_CALL_HANGUP:
|
||||
puts("app msg call HangUp\n");
|
||||
bt_key_call_hang_up();
|
||||
break;
|
||||
case APP_MSG_CALL_LAST_NO:
|
||||
puts("app msg call last on\n");
|
||||
bt_key_call_last_on();
|
||||
break;
|
||||
case APP_MSG_OPEN_SIRI:
|
||||
puts("app msg open siri\n");
|
||||
bt_key_call_siri();
|
||||
break;
|
||||
case APP_MSG_HID_CONTROL:
|
||||
puts("app msg hid control\n");
|
||||
bt_key_hid_control();
|
||||
break;
|
||||
case APP_MSG_LOW_LANTECY:
|
||||
puts("app msg low lantecy\n");
|
||||
int state = bt_get_low_latency_mode();
|
||||
bt_set_low_latency_mode(!state);
|
||||
break;
|
||||
case APP_MSG_ADD_LINEIN_STREAM:
|
||||
#if TCFG_APP_LINEIN_EN
|
||||
//工具的蓝牙流程图需要添加对应的linein数据流!!
|
||||
puts("app msg add linein stream\n");
|
||||
if (linein_player_runing()) {
|
||||
linein_player_close();
|
||||
} else {
|
||||
linein_player_open();
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case APP_MSG_BT_A2DP_START:
|
||||
#if TCFG_BT_BACKGROUND_ENABLE
|
||||
/*这里处理有些设备切到后台一直不推a2dp stop,手动切到蓝牙模式后能量检测还在跑,这时候点击设备播放按钮之后,
|
||||
能量检测有数据之后结束推APP_MSG_BT_A2DP_START,这种情况需要在这里打开解码*/
|
||||
u8 *bt_addr = (u8 *)&msg[1];
|
||||
ASSERT(bt_addr);
|
||||
u8 dev_vol = bt_get_music_volume(bt_addr);
|
||||
app_audio_state_switch(APP_AUDIO_STATE_MUSIC, app_audio_volume_max_query(AppVol_BT_MUSIC), NULL);
|
||||
if (dev_vol > 127) {
|
||||
dev_vol = app_audio_bt_volume_update(bt_addr, APP_AUDIO_STATE_MUSIC);
|
||||
}
|
||||
set_music_device_volume(dev_vol);
|
||||
int err = a2dp_player_open(bt_addr);
|
||||
if (err == -EBUSY) {
|
||||
printf("bt_app_msg_handler open a2dp_player failed\n");
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case APP_MSG_CALL_THREE_WAY_ANSWER1:
|
||||
bt_key_call_three_way_answer1();
|
||||
break;
|
||||
|
||||
case APP_MSG_CALL_THREE_WAY_ANSWER2:
|
||||
bt_key_call_three_way_answer2();
|
||||
break;
|
||||
|
||||
case APP_MSG_CALL_SWITCH:
|
||||
bt_key_call_switch();
|
||||
break;
|
||||
|
||||
case APP_MSG_PITCH_UP:
|
||||
#if TCFG_PITCH_SPEED_NODE_ENABLE
|
||||
printf("app msg a2dp pitch up\n");
|
||||
if (a2dp_player_runing()) {
|
||||
app_var.pitch_mode = a2dp_file_pitch_up(); //返回当前变调模式
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case APP_MSG_PITCH_DOWN:
|
||||
#if TCFG_PITCH_SPEED_NODE_ENABLE
|
||||
printf("app msg a2dp pitch down\n");
|
||||
if (a2dp_player_runing()) {
|
||||
app_var.pitch_mode = a2dp_file_pitch_down();
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
app_common_key_msg_handler(msg);
|
||||
printf("unknow msg type:%d", msg_type);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* #if TCFG_APP_BT_EN */
|
||||
@@ -0,0 +1,542 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".bt_background.data.bss")
|
||||
#pragma data_seg(".bt_background.data")
|
||||
#pragma const_seg(".bt_background.text.const")
|
||||
#pragma code_seg(".bt_background.text")
|
||||
#endif
|
||||
#include "system/includes.h"
|
||||
#include "btstack/avctp_user.h"
|
||||
#include "btstack/bluetooth.h"
|
||||
#include "btctrler/btctrler_task.h"
|
||||
#include "app_config.h"
|
||||
#include "bt_background.h"
|
||||
#include "bt_slience_detect.h"
|
||||
#include "app_main.h"
|
||||
#include "app_msg.h"
|
||||
#include "a2dp_player.h"
|
||||
#include "app_tone.h"
|
||||
#include "classic/tws_api.h"
|
||||
#include "dual_conn.h"
|
||||
#include "btstack/a2dp_media_codec.h"
|
||||
|
||||
#if TCFG_APP_BT_EN
|
||||
#if (TCFG_BT_BACKGROUND_ENABLE)
|
||||
|
||||
#define LOG_TAG "[BACKGROUND]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
#define LOG_CLI_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
#define TWS_FUNC_ID_BACKGROUND_SYNC TWS_FUNC_ID('B', 'A', 'C', 'K')
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙后台模式初始化
|
||||
@param
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void bt_background_init(int (*hci_handler)(struct bt_event *), int (*status_handler)(struct bt_event *))
|
||||
{
|
||||
g_bt_hdl.background.background_working = 0;
|
||||
g_bt_hdl.background.goback_timer = 0xff;
|
||||
g_bt_hdl.background.original_hci_handler = hci_handler;
|
||||
g_bt_hdl.background.original_status_handler = status_handler;
|
||||
INIT_LIST_HEAD(&g_bt_hdl.background.forward_msg_head);
|
||||
}
|
||||
|
||||
static void background_add_forward_msg(int msg_from, int *msg)
|
||||
{
|
||||
struct forward_msg *_forward_msg = zalloc(sizeof(struct forward_msg));
|
||||
if (_forward_msg) {
|
||||
_forward_msg->msg_from = msg_from;
|
||||
memcpy(_forward_msg->msg, msg, sizeof(struct bt_event));
|
||||
list_add_tail(&_forward_msg->entry, &g_bt_hdl.background.forward_msg_head);
|
||||
}
|
||||
}
|
||||
static void background_wait_phone_end(void *priv)
|
||||
{
|
||||
|
||||
if ((app_var.siri_stu) && (app_var.siri_stu != 3)) {
|
||||
// siri不退出
|
||||
return;
|
||||
}
|
||||
|
||||
if ((bt_get_call_status() == BT_CALL_OUTGOING)
|
||||
|| (bt_get_call_status() == BT_CALL_ALERT)
|
||||
|| (bt_get_call_status() == BT_CALL_INCOMING)
|
||||
|| (bt_get_call_status() == BT_CALL_ACTIVE)
|
||||
) {
|
||||
// 通话不退出
|
||||
return;
|
||||
}
|
||||
|
||||
if (bt_get_esco_coder_busy_flag()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_bt_hdl.background.goback_timer != 0xff) {
|
||||
sys_timer_del(g_bt_hdl.background.goback_timer);
|
||||
}
|
||||
g_bt_hdl.background.goback_timer = 0xff;
|
||||
|
||||
app_send_message(APP_MSG_GOTO_MODE, g_bt_hdl.background.goback_mode);
|
||||
}
|
||||
|
||||
static void background_goback_with_phone(void)
|
||||
{
|
||||
if (g_bt_hdl.background.goback_timer == 0xff) {
|
||||
g_bt_hdl.background.goback_timer = sys_timer_add(NULL, background_wait_phone_end, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙后台模式退出蓝牙
|
||||
@param
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void bt_background_suspend()
|
||||
{
|
||||
u8 suepend_rx_bulk = 0;
|
||||
g_bt_hdl.exiting = 0;
|
||||
g_bt_hdl.background.background_working = 1;
|
||||
g_bt_hdl.background.backmode = BACKGROUND_GOBACK_WITH_MODE_SWITCH;
|
||||
|
||||
#if (TCFG_DEC2TWS_ENABLE)
|
||||
suepend_rx_bulk = 0;
|
||||
__this->exiting = 0;
|
||||
#endif
|
||||
|
||||
sys_auto_shut_down_disable();
|
||||
|
||||
btctrler_suspend(suepend_rx_bulk);
|
||||
btstack_suspend();
|
||||
|
||||
/*关掉解码, 打开能量检测,处理暂停之后又播歌的情况,能跳回蓝牙模式*/
|
||||
u8 addr[6];
|
||||
if (a2dp_player_get_btaddr(addr)) {
|
||||
a2dp_player_close(addr);
|
||||
bt_start_a2dp_slience_detect(addr, 50); //这里处理能跳回蓝牙模式外也处理后台丢包功能,如果手机一直没有发stop过来,这里会一直丢静音数据
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙后台模式返回蓝牙
|
||||
@param
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void bt_background_resume(void)
|
||||
{
|
||||
g_bt_hdl.background.background_working = 0;
|
||||
g_bt_hdl.background.goback_fitler = 0;
|
||||
|
||||
btstack_resume();
|
||||
btctrler_resume();
|
||||
|
||||
void *devices[2];
|
||||
if (btstack_get_conn_devices(devices, 2) < 1) { //无设备连接才打开自动关机
|
||||
sys_auto_shut_down_enable();
|
||||
}
|
||||
|
||||
log_info("bt_background_resume\n");
|
||||
if (g_bt_hdl.background.backmode == BACKGROUND_GOBACK_WITH_PHONE) {
|
||||
log_info("bt_background_goback_with_phone\n");
|
||||
background_goback_with_phone();
|
||||
}
|
||||
/*除切模式触发的后台返回的消息需要重新处理*/
|
||||
if (g_bt_hdl.background.backmode != BACKGROUND_GOBACK_WITH_MODE_SWITCH) {
|
||||
struct forward_msg *p, *n;
|
||||
list_for_each_entry_safe(p, n, &g_bt_hdl.background.forward_msg_head, entry) {
|
||||
os_taskq_post_type("app_core", p->msg_from, \
|
||||
sizeof(struct bt_event) / 4, p->msg);
|
||||
__list_del_entry(&(p->entry));
|
||||
free(p);
|
||||
}
|
||||
r_printf("list_emtry:%d\n", list_empty(&g_bt_hdl.background.forward_msg_head));
|
||||
}
|
||||
}
|
||||
|
||||
int bt_background_check_if_can_enter()
|
||||
{
|
||||
int esco_state;
|
||||
|
||||
if (app_var.siri_stu && app_var.siri_stu != 3 && bt_get_esco_coder_busy_flag()) {
|
||||
// siri不退出
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
esco_state = bt_get_call_status();
|
||||
if (esco_state == BT_CALL_OUTGOING ||
|
||||
esco_state == BT_CALL_ALERT ||
|
||||
esco_state == BT_CALL_INCOMING ||
|
||||
esco_state == BT_CALL_ACTIVE) {
|
||||
// 通话不退出
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙后台HCI事件过滤处理
|
||||
@param event: 事件
|
||||
@return 0:不需要切换模式 1:需要切换模式 2:通话导致需要切换 3:需要走原来的消息处理流程
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int bt_background_hci_event_filter(struct bt_event *event)
|
||||
{
|
||||
log_info("bt hci event: %d \n", event->event);
|
||||
int ret = BACKGROUND_EVENT_NO_MACTH;
|
||||
switch (event->event) {
|
||||
case HCI_EVENT_IO_CAPABILITY_REQUEST:
|
||||
/* clock_add_set(BT_CONN_CLK); To Do?*/
|
||||
#if TCFG_BT_BACKGROUND_GOBACK && !USER_SUPPORT_DUAL_A2DP_SOURCE
|
||||
ret = BACKGROUND_SWITCH_TO_BT;
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
ret = BACKGROUND_EVENT_ORIGINAL_DEAL;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙后台BTSTACK事件过滤处理
|
||||
@param event: 事件
|
||||
@return 0:不需要切换模式 1:需要切换模式 2:通话导致需要切换 3:需要走原来的消息处理流程
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int bt_background_btstack_event_filter(struct bt_event *event)
|
||||
{
|
||||
u8 ret = BACKGROUND_EVENT_NO_MACTH;
|
||||
log_info("btstack event: %d \n", event->event);
|
||||
switch (event->event) {
|
||||
// 需要切换蓝牙的命令
|
||||
case BT_STATUS_FIRST_DISCONNECT:
|
||||
case BT_STATUS_SECOND_DISCONNECT:
|
||||
//关机导致的断开不可以回去蓝牙,否则后台关机会有问题
|
||||
if (app_var.goto_poweroff_flag) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (g_bt_hdl.background.close_bt_hw_in_background) {
|
||||
//需要后台关闭蓝牙硬件的就不返回蓝牙了
|
||||
printf("close_bt_hw_in_background not go back\n");
|
||||
break;
|
||||
}
|
||||
#if TCFG_BT_BACKGROUND_GOBACK
|
||||
#if !USER_SUPPORT_DUAL_A2DP_SOURCE
|
||||
ret = BACKGROUND_SWITCH_TO_BT;
|
||||
#endif
|
||||
#else
|
||||
//判断断开的是sink设备,默认切换蓝牙
|
||||
if (event->value) {
|
||||
ret = BACKGROUND_SWITCH_TO_BT;
|
||||
}
|
||||
if (ret == 0) {
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
if (tws_api_get_role() == TWS_ROLE_SLAVE) {
|
||||
break;
|
||||
}
|
||||
tws_play_tone_file(get_tone_files()->bt_disconnect, 400);
|
||||
#else
|
||||
play_tone_file(get_tone_files()->bt_disconnect);
|
||||
#endif
|
||||
//bt_status_disconnect_background(&event->u.bt);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case BT_STATUS_SECOND_CONNECTED:
|
||||
case BT_STATUS_FIRST_CONNECTED:
|
||||
#if TCFG_BT_BACKGROUND_GOBACK
|
||||
#if !USER_SUPPORT_DUAL_A2DP_SOURCE
|
||||
if (!check_page_mode_active()) { //如果是回连过程中不返回
|
||||
ret = BACKGROUND_SWITCH_TO_BT;
|
||||
} else {
|
||||
ret = BACKGROUND_EVENT_ORIGINAL_DEAL;
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
ret = BACKGROUND_EVENT_ORIGINAL_DEAL;
|
||||
/* bt_status_connect_background(&event->u.bt); */
|
||||
#endif
|
||||
break;
|
||||
|
||||
case BT_STATUS_START_CONNECTED:
|
||||
#if TCFG_BT_BACKGROUND_GOBACK && !USER_SUPPORT_DUAL_A2DP_SOURCE
|
||||
ret = BACKGROUND_SWITCH_TO_BT;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case BT_STATUS_ENCRY_COMPLETE:
|
||||
break;
|
||||
case BT_STATUS_SCO_STATUS_CHANGE:
|
||||
ret = BACKGROUND_SWITCH_TO_BT;
|
||||
break;
|
||||
case BT_STATUS_LAST_CALL_TYPE_CHANGE:
|
||||
/* bt_status_last_call_type_change(&event->u.bt); */
|
||||
case BT_STATUS_VOICE_RECOGNITION:
|
||||
case BT_STATUS_PHONE_INCOME:
|
||||
case BT_STATUS_PHONE_NUMBER:
|
||||
/* case BT_STATUS_PHONE_MANUFACTURER: */
|
||||
case BT_STATUS_PHONE_OUT:
|
||||
case BT_STATUS_PHONE_ACTIVE:
|
||||
/* case BT_STATUS_PHONE_HANGUP: */
|
||||
ret = BACKGROUND_PHONE_CALL_SWITCH_TO_BT;
|
||||
break;
|
||||
// 不需要处理的命令
|
||||
/* case BT_STATUS_INIT_OK: 这里目前看了暂时不需要区分?*/
|
||||
/* bt_status_init_ok_background(&event->u.bt); */
|
||||
/* break; */
|
||||
case BT_STATUS_A2DP_MEDIA_START:
|
||||
log_info("BT_STATUS_A2DP_MEDIA_START start slience detect\n");
|
||||
bt_start_a2dp_slience_detect(event->args, 50); //丢掉50包(约1s)之后才开始能量检测,过滤掉提示音,避免提示音引起抢占
|
||||
ret = BACKGROUND_A2DP_SLIENCE_DETECT;
|
||||
break;
|
||||
case BT_STATUS_A2DP_MEDIA_STOP:
|
||||
bt_stop_a2dp_slience_detect(event->args);
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
void tws_a2dp_player_close(u8 * bt_addr);
|
||||
tws_a2dp_player_close(event->args);
|
||||
#else
|
||||
a2dp_play_close(event->args);
|
||||
#endif
|
||||
break;
|
||||
case BT_STATUS_CALL_VOL_CHANGE:
|
||||
break;
|
||||
// 按原方式处理的命令
|
||||
default:
|
||||
ret = BACKGROUND_EVENT_ORIGINAL_DEAL;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 判断是否处于蓝牙后台
|
||||
@param void
|
||||
@return TURE:处于蓝牙后台 FALSE:不处于蓝牙后台
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
bool bt_background_active(void)
|
||||
{
|
||||
return (g_bt_hdl.background.background_working) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙后台返回蓝牙模式
|
||||
@param *msg_type:返回蓝牙模式的消息类型
|
||||
*msg:返回蓝牙模式的消息内容
|
||||
*mode:返回蓝牙模式的类型
|
||||
@return void
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void bt_background_goback(int msg_type, int *msg, BACKGROUND_GOBACK_MODE mode)
|
||||
{
|
||||
//返回蓝牙模式消息还需要走原本的消息处理函数
|
||||
background_add_forward_msg(msg_type, msg);
|
||||
if (g_bt_hdl.background.goback_fitler == 0) { //处理通话时可能触发多次goback导致重复切换任务
|
||||
g_bt_hdl.background.goback_fitler = 1;
|
||||
g_bt_hdl.background.backmode = mode;
|
||||
if (g_bt_hdl.background.backmode == BACKGROUND_GOBACK_WITH_PHONE) { //由通话返回蓝牙模式需要记录当前模式,在通话结束之后返回
|
||||
g_bt_hdl.background.goback_mode = app_get_current_mode()->name;
|
||||
}
|
||||
app_send_message(APP_MSG_GOTO_MODE, APP_MODE_BT);
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
if (tws_api_get_role() == TWS_ROLE_MASTER) {
|
||||
tws_api_send_data_to_slave(&(g_bt_hdl.background), sizeof(g_bt_hdl.background), TWS_FUNC_ID_BACKGROUND_SYNC);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙后台消息分发
|
||||
@param *msg_from:消息类型
|
||||
*msg:消息内容
|
||||
@return void
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void background_msg_forward(int msg_from, int *msg)
|
||||
{
|
||||
|
||||
const struct app_msg_handler *handler;
|
||||
|
||||
for_each_app_msg_handler(handler) {
|
||||
if (handler->from != msg_from) {
|
||||
continue;
|
||||
}
|
||||
|
||||
handler->handler(msg);
|
||||
}
|
||||
}
|
||||
|
||||
static int background_btstack_event_handler(int *event)
|
||||
{
|
||||
u8 ret = bt_background_btstack_event_filter((struct bt_event *)event);
|
||||
switch (ret) {
|
||||
case BACKGROUND_A2DP_SLIENCE_DETECT:
|
||||
/* g_bt_hdl.background.forward_msg_from = MSG_FROM_BT_STACK; */
|
||||
/* memcpy(g_bt_hdl.background.forward_msg, event, sizeof(struct bt_event)); */
|
||||
background_add_forward_msg(MSG_FROM_BT_STACK, event);
|
||||
break;
|
||||
case BACKGROUND_PHONE_CALL_SWITCH_TO_BT:
|
||||
g_printf("BACKGROUND_SWITCH_TO_BT_WITH_PHONE\n");
|
||||
bt_background_goback(MSG_FROM_BT_STACK, event, BACKGROUND_GOBACK_WITH_PHONE);
|
||||
break;
|
||||
case BACKGROUND_SWITCH_TO_BT:
|
||||
if (!check_page_mode_active()) { //如果是回连过程中不返回
|
||||
g_printf("BACKGROUND_SWITCH_TO_BT\n");
|
||||
bt_background_goback(MSG_FROM_BT_STACK, event, BACKGROUND_GOBACK_WITH_OTHER);
|
||||
}
|
||||
break;
|
||||
case BACKGROUND_EVENT_ORIGINAL_DEAL:
|
||||
g_printf("BACKGROUND_ORIGINAL_DEAL\n");
|
||||
if (g_bt_hdl.background.original_status_handler) {
|
||||
g_bt_hdl.background.original_status_handler((struct bt_event *)event);
|
||||
}
|
||||
background_msg_forward(MSG_FROM_BT_STACK, event);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int background_hci_event_handler(int *event)
|
||||
{
|
||||
u8 ret = bt_background_hci_event_filter((struct bt_event *)event);
|
||||
switch (ret) {
|
||||
case BACKGROUND_PHONE_CALL_SWITCH_TO_BT:
|
||||
g_printf("BACKGROUND_SWITCH_TO_BT_WITH_PHONE\n");
|
||||
bt_background_goback(MSG_FROM_BT_HCI, event, BACKGROUND_GOBACK_WITH_PHONE);
|
||||
break;
|
||||
case BACKGROUND_SWITCH_TO_BT:
|
||||
g_printf("BACKGROUND_SWITCH_TO_BT\n");
|
||||
bt_background_goback(MSG_FROM_BT_HCI, event, BACKGROUND_GOBACK_WITH_OTHER);
|
||||
break;
|
||||
case BACKGROUND_EVENT_ORIGINAL_DEAL:
|
||||
g_printf("BACKGROUND_ORIGINAL_DEAL\n");
|
||||
if (g_bt_hdl.background.original_hci_handler) {
|
||||
g_bt_hdl.background.original_hci_handler((struct bt_event *)event);
|
||||
}
|
||||
background_msg_forward(MSG_FROM_BT_HCI, event);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int background_app_msg_handler(int *msg)
|
||||
{
|
||||
int ret = TRUE;
|
||||
switch (msg[0]) {
|
||||
case APP_MSG_BT_A2DP_START:
|
||||
g_printf("BACKGROUND_SWITCH_TO_BT A2DP_START\n");
|
||||
struct bt_event event;
|
||||
event.event = BT_STATUS_A2DP_MEDIA_START; //这里需要触发流程去打开解码
|
||||
memcpy(event.args, msg + 1, 6);
|
||||
void *file = a2dp_open_media_file(event.args);
|
||||
if (file == NULL) {
|
||||
log_error("open a2dp file error \n");
|
||||
break;
|
||||
}
|
||||
a2dp_close_media_file(file);
|
||||
background_add_forward_msg(MSG_FROM_BT_STACK, (int *)&event);
|
||||
g_bt_hdl.background.backmode = BACKGROUND_GOBACK_WITH_MUSIC;
|
||||
app_send_message(APP_MSG_GOTO_MODE, APP_MODE_BT);
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
if (tws_api_get_role() == TWS_ROLE_MASTER) {
|
||||
tws_api_send_data_to_slave(&(g_bt_hdl.background), sizeof(g_bt_hdl.background), TWS_FUNC_ID_BACKGROUND_SYNC);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
ret = FALSE; //APP_MSG没有match上需要走消息转发流程
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 后台过滤消息,如果处于后台模式且消息类型属于后台处理的,由后台来处理
|
||||
@param msg: 需要处理的消息内容
|
||||
@return TRUE: 消息由后台处理,无需再转发 FALSE:消息需要转发
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
bool bt_background_msg_forward_filter(int *msg)
|
||||
{
|
||||
bool ret = TRUE;
|
||||
if (g_bt_hdl.background.background_working) {
|
||||
switch (msg[0]) {
|
||||
case MSG_FROM_BT_HCI:
|
||||
background_hci_event_handler(msg + 1);
|
||||
break;
|
||||
case MSG_FROM_BT_STACK:
|
||||
background_btstack_event_handler(msg + 1);
|
||||
break;
|
||||
case MSG_FROM_APP:
|
||||
ret = background_app_msg_handler(msg + 1);
|
||||
break;
|
||||
default:
|
||||
ret = FALSE;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
ret = FALSE;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void bt_background_set_switch_mode(u8 mode)
|
||||
{
|
||||
g_printf("bt_background_set_switch_mode:%d\n", mode);
|
||||
g_bt_hdl.background.poweron_need_switch_mode = TRUE;
|
||||
g_bt_hdl.background.poweron_mode = mode;
|
||||
}
|
||||
|
||||
bool bt_background_switch_mode_check(void)
|
||||
{
|
||||
return g_bt_hdl.background.poweron_need_switch_mode;
|
||||
}
|
||||
|
||||
void bt_background_switch_mode_after_initializes(void)
|
||||
{
|
||||
if (g_bt_hdl.background.poweron_need_switch_mode) {
|
||||
g_printf(" bt_background_switch_mode_after_initializes:%d\n", g_bt_hdl.background.poweron_need_switch_mode);
|
||||
app_send_message(APP_MSG_GOTO_MODE, g_bt_hdl.background.poweron_mode);
|
||||
g_bt_hdl.background.poweron_need_switch_mode = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
|
||||
static void bt_background_sync(void *_data, u16 len, bool rx)
|
||||
{
|
||||
if (rx) {
|
||||
u8 *data = (u8 *)_data;
|
||||
memcpy(&(g_bt_hdl.background), data, sizeof(g_bt_hdl.background));
|
||||
app_send_message(APP_MSG_GOTO_MODE, APP_MODE_BT);
|
||||
}
|
||||
}
|
||||
|
||||
REGISTER_TWS_FUNC_STUB(app_anc_sync_stub) = {
|
||||
.func_id = TWS_FUNC_ID_BACKGROUND_SYNC,
|
||||
.func = bt_background_sync,
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif /* #if TCFG_APP_BT_EN */
|
||||
@@ -0,0 +1,86 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".bt_call_kws_handler.data.bss")
|
||||
#pragma data_seg(".bt_call_kws_handler.data")
|
||||
#pragma const_seg(".bt_call_kws_handler.text.const")
|
||||
#pragma code_seg(".bt_call_kws_handler.text")
|
||||
#endif
|
||||
#include "btstack/avctp_user.h"
|
||||
#include "app_main.h"
|
||||
#include "jl_kws/jl_kws_api.h"
|
||||
#include "app_config.h"
|
||||
#include "audio_cvp.h"
|
||||
#include "smart_voice.h"
|
||||
#include "esco_player.h"
|
||||
#include "media/asr/jl_kws.h"
|
||||
|
||||
#if (TCFG_KWS_VOICE_RECOGNITION_ENABLE || TCFG_CALL_KWS_SWITCH_ENABLE) && !TCFG_AUDIO_ASR_DEVELOP
|
||||
static void jl_call_kws_handler(int event)
|
||||
{
|
||||
if (event == BT_STATUS_PHONE_INCOME) {
|
||||
printf("BT_STATUS_PHONE_INCOME");
|
||||
#if TCFG_KWS_VOICE_RECOGNITION_ENABLE
|
||||
audio_aec_reboot(1);
|
||||
jl_kws_speech_recognition_open();
|
||||
jl_kws_speech_recognition_start();
|
||||
#endif
|
||||
|
||||
#if TCFG_CALL_KWS_SWITCH_ENABLE
|
||||
audio_aec_reboot(1);
|
||||
/* audio_phone_call_kws_start(); */
|
||||
audio_smart_voice_detect_open(JL_KWS_COMMAND_KEYWORD);
|
||||
#endif /* #if TCFG_CALL_KWS_SWITCH_ENABLE */
|
||||
} else if (event == BT_STATUS_PHONE_ACTIVE) {
|
||||
printf("BT_STATUS_PHONE_ACTIVE");
|
||||
#if TCFG_KWS_VOICE_RECOGNITION_ENABLE
|
||||
jl_kws_speech_recognition_close();
|
||||
audio_aec_reboot(0);
|
||||
#endif
|
||||
#ifdef CONFIG_BOARD_AISPEECH_VAD_ASR
|
||||
printf("----aispeech_state phone active");
|
||||
ais_platform_asr_close();
|
||||
esco_mic_reset();
|
||||
#endif /*CONFIG_BOARD_AISPEECH_VAD_ASR*/
|
||||
#if TCFG_CALL_KWS_SWITCH_ENABLE
|
||||
audio_smart_voice_detect_close();
|
||||
audio_aec_reboot(0);
|
||||
#endif /* TCFG_CALL_KWS_SWITCH_ENABLE */
|
||||
} else if (event == BT_STATUS_PHONE_HANGUP) {
|
||||
printf("BT_STATUS_PHONE_HANGUP");
|
||||
#if TCFG_KWS_VOICE_RECOGNITION_ENABLE
|
||||
jl_kws_speech_recognition_close();
|
||||
#endif
|
||||
#if TCFG_CALL_KWS_SWITCH_ENABLE
|
||||
if (!esco_player_runing()) {
|
||||
audio_phone_call_kws_close();
|
||||
}
|
||||
#endif /* TCFG_CALL_KWS_SWITCH_ENABLE */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int kws_btstack_msg_handler(int *msg)
|
||||
{
|
||||
struct bt_event *bt = (struct bt_event *)msg;
|
||||
|
||||
switch (bt->event) {
|
||||
case BT_STATUS_PHONE_INCOME:
|
||||
jl_call_kws_handler(BT_STATUS_PHONE_INCOME);
|
||||
break;
|
||||
case BT_STATUS_PHONE_ACTIVE:
|
||||
jl_call_kws_handler(BT_STATUS_PHONE_ACTIVE);
|
||||
break;
|
||||
case BT_STATUS_PHONE_HANGUP:
|
||||
jl_call_kws_handler(BT_STATUS_PHONE_HANGUP);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
APP_MSG_PROB_HANDLER(call_kws_btstack_msg_entry) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_BT_STACK,
|
||||
.handler = kws_btstack_msg_handler,
|
||||
};
|
||||
#endif /* #if (TCFG_KWS_VOICE_RECOGNITION_ENABLE || TCFG_CALL_KWS_SWITCH_ENABLE) && !TCFG_AUDIO_ASR_DEVELOP */
|
||||
@@ -0,0 +1,512 @@
|
||||
#include "bt.h"
|
||||
#include "app_config.h"
|
||||
#include "app_main.h"
|
||||
#include "app_msg.h"
|
||||
#include "btstack/avctp_user.h"
|
||||
#include "dual_conn.h"
|
||||
#include "jlui_app/ui_api.h"
|
||||
#include "file_player.h"
|
||||
|
||||
#define LOG_TAG "[EMITTER]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
#define LOG_CLI_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
#if TCFG_USER_EMITTER_ENABLE
|
||||
|
||||
#define BT_EMITTER_TEST 0
|
||||
|
||||
#define SEARCH_BD_ADDR_LIMITED 0
|
||||
#define SEARCH_BD_NAME_LIMITED 1
|
||||
#define SEARCH_CUSTOM_LIMITED 2
|
||||
#define SEARCH_NULL_LIMITED 3
|
||||
|
||||
#define SEARCH_LIMITED_MODE SEARCH_BD_NAME_LIMITED
|
||||
|
||||
struct list_head inquiry_noname_list;
|
||||
struct inquiry_noname_remote {
|
||||
struct list_head entry;
|
||||
u8 match;
|
||||
s8 rssi;
|
||||
u8 addr[6];
|
||||
u32 class;
|
||||
};
|
||||
|
||||
u8 restore_remote_device_info_profile(bd_addr_t mac_addr, u8 device_num, u8 id, u8 profile);
|
||||
|
||||
static u8 read_name_start = 0;
|
||||
static u8 search_spp_device = 0;
|
||||
|
||||
extern struct file_player *get_music_file_player(void); //返回第一个打开的音乐播放器指针
|
||||
extern int music_file_get_player_status(struct file_player *music_player);
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙发射发起搜索设备
|
||||
@param 无
|
||||
@return 无
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void bt_search_device(void)
|
||||
{
|
||||
if (is_bredr_close() == 1) {
|
||||
ASSERT(0, "bt close should user bt_emitter_start_search_device()");
|
||||
}
|
||||
if (!bt_check_already_initializes()) {
|
||||
log_info("bt on init >>>>>>>>>>>>>>>>>>>>>>>\n");
|
||||
return;
|
||||
}
|
||||
u8 inquiry_length = 20; // inquiry_length * 1.28s
|
||||
bt_cmd_prepare(USER_CTRL_SEARCH_DEVICE, 1, &inquiry_length);
|
||||
log_info("bt_search_start >>>>>>>>>>>>>>>>>>>>>>>\n");
|
||||
}
|
||||
void bt_search_stop(void)
|
||||
{
|
||||
bt_cmd_prepare(USER_CTRL_INQUIRY_CANCEL, 0, NULL);
|
||||
log_info("bt_search_stop >>>>>>>>>>>>>>>>>>>>>>>\n");
|
||||
}
|
||||
|
||||
void emitter_bt_connect(u8 *mac)
|
||||
{
|
||||
if (is_bredr_close() == 1) {
|
||||
bredr_conn_dev(mac);
|
||||
} else {
|
||||
dual_conn_user_bt_connect(mac);
|
||||
}
|
||||
}
|
||||
|
||||
void bt_emitter_start_search_device()
|
||||
{
|
||||
if (g_bt_hdl.emitter_or_receiver != BT_EMITTER_EN) {
|
||||
return ;
|
||||
}
|
||||
if (is_bredr_close() == 1) {
|
||||
bredr_search_device();
|
||||
} else {
|
||||
/* user_send_cmd_prepare(USER_CTRL_PAGE_CANCEL, 0, NULL); */
|
||||
/* 关闭可发现 */
|
||||
bt_cmd_prepare(USER_CTRL_WRITE_CONN_DISABLE, 0, NULL);
|
||||
bt_cmd_prepare(USER_CTRL_WRITE_SCAN_DISABLE, 0, NULL);
|
||||
////发起扫描
|
||||
bt_search_device();
|
||||
}
|
||||
}
|
||||
|
||||
#if (SEARCH_LIMITED_MODE == SEARCH_BD_ADDR_LIMITED)
|
||||
u8 bd_addr_filt[][6] = {
|
||||
{0x8E, 0xA7, 0xCA, 0x0A, 0x5E, 0xC8}, /*S10_H*/
|
||||
{0xA7, 0xDD, 0x05, 0xDD, 0x1F, 0x00}, /*ST-001*/
|
||||
{0xE9, 0x73, 0x13, 0xC0, 0x1F, 0x00}, /*HBS 730*/
|
||||
{0x38, 0x7C, 0x78, 0x1C, 0xFC, 0x02}, /*Bluetooth*/
|
||||
};
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙发射搜索通过地址过滤
|
||||
@param 无
|
||||
@return 无
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
u8 search_bd_addr_filt(u8 *addr)
|
||||
{
|
||||
u8 i;
|
||||
log_info("bd_addr:");
|
||||
log_info_hexdump(addr, 6);
|
||||
for (i = 0; i < (sizeof(bd_addr_filt) / sizeof(bd_addr_filt[0])); i++) {
|
||||
if (memcmp(addr, bd_addr_filt[i], 6) == 0) {
|
||||
/* printf("bd_addr match:%d\n", i); */
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
/*log_info("bd_addr not match\n"); */
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (SEARCH_LIMITED_MODE == SEARCH_BD_NAME_LIMITED)
|
||||
u8 bd_name_filt[][32] = {
|
||||
"TG-294",
|
||||
"JL709_VOL_ADAP",
|
||||
};
|
||||
|
||||
u8 bd_spp_name_filt[20][30] = {
|
||||
"AC69_BT_SDK",
|
||||
};
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙发射搜索通过名字过滤
|
||||
@param 无
|
||||
@return 无
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
u8 search_bd_name_filt(char *data, u8 len, u32 dev_class, char rssi)
|
||||
{
|
||||
char bd_name[64] = {0};
|
||||
u8 i;
|
||||
char *targe_name = NULL;
|
||||
|
||||
if ((len > (sizeof(bd_name))) || (len == 0) || !data) {
|
||||
//printf("bd_name_len error:%d\n", len);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
memset(bd_name, 0, sizeof(bd_name));
|
||||
memcpy(bd_name, data, len);
|
||||
log_info("name:%s,len:%d,class %x ,rssi %d\n", bd_name, len, dev_class, rssi);
|
||||
if (search_spp_device) {
|
||||
for (i = 0; i < (sizeof(bd_spp_name_filt) / sizeof(bd_spp_name_filt[0])); i++) {
|
||||
if (memcmp(data, bd_spp_name_filt[i], len) == 0) {
|
||||
puts("\n*****find dev ok******\n");
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < (sizeof(bd_name_filt) / sizeof(bd_name_filt[0])); i++) {
|
||||
if (memcmp(data, bd_name_filt[i], len) == 0) {
|
||||
puts("\n*****find dev ok******\n");
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
#endif
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙发射搜索结果回调处理
|
||||
@param name : 设备名字
|
||||
name_len: 设备名字长度
|
||||
addr: 设备地址
|
||||
dev_class: 设备类型
|
||||
rssi: 设备信号强度
|
||||
@return 无
|
||||
@note
|
||||
蓝牙设备搜索结果,可以做名字/地址过滤,也可以保存搜到的所有设备
|
||||
在选择一个进行连接,获取其他你想要的操作。
|
||||
返回TRUE,表示搜到指定的想要的设备,搜索结束,直接连接当前设备
|
||||
返回FALSE,则继续搜索,直到搜索完成或者超时
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
u8 emitter_search_result(char *name, u8 name_len, u8 *addr, u32 dev_class, char rssi)
|
||||
{
|
||||
log_info("name:%s,len:%d,class %x ,rssi %d\n", name, name_len, dev_class, rssi);
|
||||
if (name == NULL) {
|
||||
struct inquiry_noname_remote *remote = malloc(sizeof(struct inquiry_noname_remote));
|
||||
ASSERT(remote);
|
||||
remote->match = 0;
|
||||
remote->class = dev_class;
|
||||
remote->rssi = rssi;
|
||||
memcpy(remote->addr, addr, 6);
|
||||
local_irq_disable();
|
||||
list_add_tail(&remote->entry, &inquiry_noname_list);
|
||||
local_irq_enable();
|
||||
if (read_name_start == 0) {
|
||||
read_name_start = 1;
|
||||
bt_cmd_prepare(USER_CTRL_READ_REMOTE_NAME, 6, addr);
|
||||
}
|
||||
}
|
||||
|
||||
if (name) {
|
||||
extern void bt_menu_list_add(char *name, u8 * mac, u8 rssi);
|
||||
bt_menu_list_add(name, addr, rssi);
|
||||
log_info("name:%s,len:%d,class %x ,rssi %d\n", name, name_len, dev_class, rssi);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
#if (SEARCH_LIMITED_MODE == SEARCH_BD_NAME_LIMITED)
|
||||
return search_bd_name_filt(name, name_len, dev_class, rssi);
|
||||
#endif
|
||||
|
||||
#if (SEARCH_LIMITED_MODE == SEARCH_BD_ADDR_LIMITED)
|
||||
return search_bd_addr_filt(addr);
|
||||
#endif
|
||||
|
||||
#if (SEARCH_LIMITED_MODE == SEARCH_CUSTOM_LIMITED)
|
||||
/*以下为搜索结果自定义处理*/
|
||||
char bt_name[63] = {0};
|
||||
u8 len;
|
||||
if (name_len == 0) {
|
||||
log_info("No_eir\n");
|
||||
} else {
|
||||
len = (name_len > 63) ? 63 : name_len;
|
||||
/* display bd_name */
|
||||
memcpy(bt_name, name, len);
|
||||
log_info("name:%s,len:%d,class %x ,rssi %d\n", bt_name, name_len, dev_class, rssi);
|
||||
}
|
||||
|
||||
/* display bd_addr */
|
||||
log_debug_hexdump(addr, 6);
|
||||
|
||||
/* You can connect the specified bd_addr by below api */
|
||||
/* dual_conn_user_bt_connect(addr); */
|
||||
|
||||
return FALSE;
|
||||
#endif
|
||||
|
||||
#if (SEARCH_LIMITED_MODE == SEARCH_NULL_LIMITED)
|
||||
/*没有指定限制,则搜到什么就连接什么*/
|
||||
return TRUE;
|
||||
#endif
|
||||
return FALSE;
|
||||
}
|
||||
void bt_emitter_init()
|
||||
{
|
||||
/* bt_emitter_start = 1; */
|
||||
INIT_LIST_HEAD(&inquiry_noname_list);
|
||||
bt_inquiry_result_handle_register(emitter_search_result);
|
||||
lmp_set_sniff_establish_by_remote(1);
|
||||
bt_emitter_set_enable_flag(1);
|
||||
g_bt_hdl.emitter_or_receiver = BT_EMITTER_EN;
|
||||
bt_a2dp_source_init(NULL, 0, 1);
|
||||
#if (TCFG_BT_SUPPORT_HFP_AG==1)
|
||||
bt_hfp_ag_buf_init(NULL, 0, 1);
|
||||
#endif
|
||||
|
||||
#if BT_EMITTER_TEST
|
||||
bt_emitter_start_search_device();
|
||||
#endif
|
||||
}
|
||||
|
||||
void emitter_search_stop_handle(u8 result)
|
||||
{
|
||||
log_info("%s == %d", __func__, result);
|
||||
struct inquiry_noname_remote *remote, *n;
|
||||
u8 wait_connect_flag = 1;
|
||||
if (!list_empty(&inquiry_noname_list)) {
|
||||
bt_cmd_prepare(USER_CTRL_PAGE_CANCEL, 0, NULL);
|
||||
}
|
||||
if (!result) {
|
||||
list_for_each_entry_safe(remote, n, &inquiry_noname_list, entry) {
|
||||
if (remote->match) {
|
||||
dual_conn_user_bt_connect(remote->addr);
|
||||
wait_connect_flag = 0;
|
||||
}
|
||||
list_del(&remote->entry);
|
||||
free(remote);
|
||||
}
|
||||
}
|
||||
read_name_start = 0;
|
||||
if (wait_connect_flag) {
|
||||
/* log_info("wait conenct\n"); */
|
||||
/* if (bt_get_total_connect_dev() == 2) { */
|
||||
/* write_scan_conn_enable(0, 0); */
|
||||
/* } else if (bt_get_total_connect_dev() == 1 && bt_get_connect_status() != BT_STATUS_WAITINT_CONN) { */
|
||||
/* write_scan_conn_enable(0, 1); */
|
||||
/* } else { */
|
||||
/* write_scan_conn_enable(1, 1); */
|
||||
/* } */
|
||||
}
|
||||
}
|
||||
|
||||
void printf_malloc(void *pive)
|
||||
{
|
||||
int count = 10000;
|
||||
/* malloc_list_status_printf_all(count); */
|
||||
}
|
||||
u8 bt_emitter_stu_set(u8 *addr, u8 pp)
|
||||
{
|
||||
log_info("total con dev:%d ", bt_get_total_connect_dev());
|
||||
if (pp && (bt_get_total_connect_dev() == 0) && !(bt_emitter_get_curr_channel_state() & A2DP_SRC_CH)) {
|
||||
pp = 0;
|
||||
}
|
||||
if (pp) {
|
||||
//开音频编码
|
||||
app_var.a2dp_source_open_flag = 1;
|
||||
/* sys_timer_add(NULL, printf_malloc, 300); */
|
||||
bt_emitter_cmd_prepare(USER_CTRL_AVCTP_OPID_SEND_VOL, 0, NULL);
|
||||
} else {
|
||||
//关音频编码
|
||||
app_var.a2dp_source_open_flag = 0;
|
||||
}
|
||||
bt_emitter_send_media_toggle(NULL, pp);
|
||||
return pp;
|
||||
}
|
||||
|
||||
u8 bt_emitter_pp(u8 pp)
|
||||
{
|
||||
return bt_emitter_stu_set(NULL, pp);
|
||||
}
|
||||
|
||||
void emitter_open(u8 source)
|
||||
{
|
||||
bt_emitter_pp(1);
|
||||
}
|
||||
|
||||
void emitter_close(u8 source)
|
||||
{
|
||||
bt_emitter_pp(0);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙发射接收到设备按键消息
|
||||
@param cmd:按键命令
|
||||
@return 无
|
||||
@note
|
||||
发射器收到接收器发过来的控制命令处理
|
||||
根据实际需求可以在收到控制命令之后做相应的处理
|
||||
蓝牙库里面定义的是weak函数,直接再定义一个同名可获取信息
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void emitter_rx_avctp_opid_deal(u8 cmd, u8 id) //属于库的弱函数重写
|
||||
{
|
||||
log_debug("avctp_rx_cmd:%x\n", cmd);
|
||||
|
||||
|
||||
switch (cmd) {
|
||||
case AVCTP_OPID_NEXT:
|
||||
log_info("AVCTP_OPID_NEXT\n");
|
||||
app_send_message(APP_MSG_MUSIC_NEXT, 0);
|
||||
break;
|
||||
case AVCTP_OPID_PREV:
|
||||
log_info("AVCTP_OPID_PREV\n");
|
||||
app_send_message(APP_MSG_MUSIC_PREV, 0);
|
||||
break;
|
||||
case AVCTP_OPID_PAUSE:
|
||||
case AVCTP_OPID_STOP:
|
||||
log_info("AVCTP_OPID_PAUSE\n");
|
||||
app_send_message(APP_MSG_BT_EMITTER_PAUSE, 0);
|
||||
break;
|
||||
case AVCTP_OPID_PLAY:
|
||||
log_info("AVCTP_OPID_PP\n");
|
||||
app_send_message(APP_MSG_BT_EMITTER_PLAY, 0);
|
||||
break;
|
||||
case AVCTP_OPID_VOLUME_UP:
|
||||
log_info("AVCTP_OPID_VOLUME_UP\n");
|
||||
app_send_message(APP_MSG_VOL_UP, 0);
|
||||
break;
|
||||
case AVCTP_OPID_VOLUME_DOWN:
|
||||
log_info("AVCTP_OPID_VOLUME_DOWN\n");
|
||||
app_send_message(APP_MSG_VOL_DOWN, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙发射接收设备同步音量
|
||||
@param vol:接收到设备同步音量
|
||||
@return 无
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void emitter_rx_vol_change(u8 vol) //属于库的弱函数重写
|
||||
{
|
||||
log_info("vol_change:%d \n", vol);
|
||||
}
|
||||
|
||||
////回链手机
|
||||
u8 connect_last_source_device_from_vm()
|
||||
{
|
||||
u8 mac_addr[6];
|
||||
u8 flag = 0;
|
||||
flag = restore_remote_device_info_profile((u8 *)&mac_addr, 1, get_remote_dev_info_index(), REMOTE_SOURCE);
|
||||
if (flag) {
|
||||
//connect last conn
|
||||
printf("last source device addr from vm:");
|
||||
put_buf(mac_addr, 6);
|
||||
dual_conn_user_bt_connect(mac_addr);
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
static int bt_emitter_btstack_event_handler(int *msg)
|
||||
{
|
||||
struct bt_event *bt = (struct bt_event *)msg;
|
||||
|
||||
switch (bt->event) {
|
||||
case BT_STATUS_INIT_OK:
|
||||
log_info(" BT_STATUS_INIT_OK \n");
|
||||
bt_emitter_init();
|
||||
break;
|
||||
case BT_STATUS_CONN_A2DP_CH:
|
||||
log_info("++++++++ BT_STATUS_CONN_A2DP_CH +++++++++ 0x%x \n", bt->value);
|
||||
if (bt->value & A2DP_SRC_CH) {
|
||||
#if BT_EMITTER_TEST
|
||||
bt_emitter_pp(1);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
APP_MSG_HANDLER(emitter_stack_msg_entry) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_BT_STACK,
|
||||
.handler = bt_emitter_btstack_event_handler,
|
||||
};
|
||||
|
||||
static int bt_emitter_hci_event_handler(struct bt_event *bt)
|
||||
{
|
||||
//对应原来的蓝牙连接上断开处理函数 ,bt->value=reason
|
||||
log_info("-----------bt_hci_event_handler reason %x %x", bt->event, bt->value);
|
||||
switch (bt->event) {
|
||||
case HCI_EVENT_INQUIRY_COMPLETE:
|
||||
log_info(" HCI_EVENT_INQUIRY_COMPLETE \n");
|
||||
emitter_search_stop_handle(bt->value);
|
||||
UI_MSG_POST("bt_emitter_status:hci_event=%4", bt->event);
|
||||
break;
|
||||
case HCI_EVENT_CONNECTION_COMPLETE:
|
||||
UI_MSG_POST("bt_emitter_status:hci_value=%4", bt->value);
|
||||
break;
|
||||
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
||||
#if !TCFG_COLOR_SCREEN_CHARGING_CASE_ENABLE
|
||||
UI_MSG_POST("bt_emitter_status:hci_event=%4", bt->event);
|
||||
#else
|
||||
UI_MSG_POST("bt_emitter_status:hci_event=%4:hci_value=%4", bt->event, bt->value);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bt_emitter_hci_msg_handler(int *msg)
|
||||
{
|
||||
struct bt_event *event = (struct bt_event *)msg;
|
||||
bt_emitter_hci_event_handler(event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
APP_MSG_HANDLER(emitter_hci_msg_handler) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_BT_HCI,
|
||||
.handler = bt_emitter_hci_msg_handler,
|
||||
};
|
||||
|
||||
static int bt_emitter_app_msg_handler(int *msg)
|
||||
{
|
||||
struct file_player *file_player = NULL;
|
||||
switch (msg[0]) {
|
||||
case APP_MSG_BT_EMITTER_PLAY:
|
||||
#if TCFG_APP_MUSIC_EN
|
||||
file_player = get_music_file_player();
|
||||
if (music_file_get_player_status(file_player) != FILE_PLAYER_START) {
|
||||
app_send_message(APP_MSG_MUSIC_PP, 0);
|
||||
}
|
||||
#endif
|
||||
bt_emitter_pp(1);
|
||||
break;
|
||||
case APP_MSG_BT_EMITTER_PAUSE:
|
||||
#if TCFG_APP_MUSIC_EN
|
||||
file_player = get_music_file_player();
|
||||
if (music_file_get_player_status(file_player) == FILE_PLAYER_START) {
|
||||
app_send_message(APP_MSG_MUSIC_PP, 0);
|
||||
}
|
||||
#endif
|
||||
bt_emitter_pp(0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
APP_MSG_HANDLER(bt_emitter_app_msg_entry) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_APP,
|
||||
.handler = bt_emitter_app_msg_handler,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,570 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".bt_event_func.data.bss")
|
||||
#pragma data_seg(".bt_event_func.data")
|
||||
#pragma const_seg(".bt_event_func.text.const")
|
||||
#pragma code_seg(".bt_event_func.text")
|
||||
#endif
|
||||
#include "classic/hci_lmp.h"
|
||||
#include "btstack/btstack_task.h"
|
||||
#include "btstack/avctp_user.h"
|
||||
#include "app_main.h"
|
||||
#include "app_testbox.h"
|
||||
#include "tone_player.h"
|
||||
#include "clock_manager/clock_manager.h"
|
||||
#include "audio_config.h"
|
||||
#include "audio_cvp.h"
|
||||
#if TCFG_AUDIO_ANC_ENABLE
|
||||
#include "audio_anc.h"
|
||||
#endif/*TCFG_AUDIO_ANC_ENABLE*/
|
||||
#include "battery_manager.h"
|
||||
#include "bt_common.h"
|
||||
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
#include "bt_tws.h"
|
||||
#endif
|
||||
#include "bt_event_func.h"
|
||||
|
||||
#include "ui_api.h"
|
||||
|
||||
#if TCFG_APP_BT_EN
|
||||
|
||||
/*************************************************************
|
||||
此文件函数主要是蓝牙模式各种状态处理
|
||||
|
||||
蓝牙播歌通话各种状态处理
|
||||
|
||||
蓝牙协议栈事件处理
|
||||
**************************************************************/
|
||||
|
||||
u8 get_bt_init_status()
|
||||
{
|
||||
return g_bt_hdl.init_ok;
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief 蓝牙连接配置,提供app层用户可以输入配对鉴定key
|
||||
*
|
||||
* \param key :配对需要输入的数字
|
||||
*
|
||||
* \return
|
||||
*
|
||||
* \note 配对需要输入6位数字的时候,按照顺序从左到右一个个输入
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void bt_send_keypress(u8 key)
|
||||
{
|
||||
printf("bt_send_keypress:%d", key);
|
||||
bt_cmd_prepare(USER_CTRL_KEYPRESS, 1, &key);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief 蓝牙连接配置,提供app层用户可以输入确定或者否定
|
||||
*
|
||||
* \param en 0:否定 1:确定
|
||||
*
|
||||
* \return
|
||||
*
|
||||
* \note 在连接过程中类似手机弹出 确定和否定 按键,可以供用户界面设置
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void bt_send_pair(u8 en)
|
||||
{
|
||||
bt_cmd_prepare(USER_CTRL_PAIR, 1, &en);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief 蓝牙获取vm连接记录信息
|
||||
*
|
||||
* \param [in]
|
||||
*
|
||||
* \return
|
||||
*
|
||||
* \note
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void bt_init_ok_search_index(void)
|
||||
{
|
||||
if (bt_get_current_poweron_memory_search_index(g_bt_hdl.auto_connection_addr)) {
|
||||
printf("bt_wait_connect_and_phone_connect_switch\n");
|
||||
bt_clear_current_poweron_memory_search_index(1);
|
||||
app_send_message(APP_MSG_BT_GET_CONNECT_ADDR, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief 蓝牙初始化完成
|
||||
*
|
||||
* \param [in]
|
||||
*
|
||||
* \return
|
||||
*
|
||||
* \note
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void bt_status_init_ok(void)
|
||||
{
|
||||
g_bt_hdl.init_ok = 1;
|
||||
|
||||
#if TCFG_NORMAL_SET_DUT_MODE
|
||||
printf("edr set dut mode\n");
|
||||
bredr_set_dut_enble(1, 1);
|
||||
#if TCFG_USER_BLE_ENABLE
|
||||
printf("ble set dut mode\n");
|
||||
extern void ble_standard_dut_test_init(void);
|
||||
ble_standard_dut_test_init();
|
||||
return;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (TCFG_USER_BLE_ENABLE || TCFG_BT_BLE_ADV_ENABLE)
|
||||
if (BT_MODE_IS(BT_BQB)) {
|
||||
ble_bqb_test_thread_init();
|
||||
} else {
|
||||
bt_ble_init();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (BT_AI_SEL_PROTOCOL & (RCSP_MODE_EN | GFPS_EN | MMA_EN | FMNA_EN | REALME_EN | SWIFT_PAIR_EN | DMA_EN | ONLINE_DEBUG_EN | CUSTOM_DEMO_EN))
|
||||
void multi_protocol_bt_init(void);
|
||||
multi_protocol_bt_init();
|
||||
#endif
|
||||
|
||||
bt_init_ok_search_index();
|
||||
|
||||
#if ((CONFIG_BT_MODE == BT_BQB)||(CONFIG_BT_MODE == BT_PER))
|
||||
return;
|
||||
#endif
|
||||
|
||||
#if TCFG_TWS_INIT_AFTER_POWERON_TONE_PLAY_END
|
||||
if (tone_player_runing()) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
bt_tws_poweron();
|
||||
#endif
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙获取在连接设备名字回调
|
||||
@param status : 1:获取失败 0:获取成功
|
||||
addr : 配对设备地址
|
||||
name :配对设备名字
|
||||
@return
|
||||
@note 需要连接上设备后发起USER_CTRL_READ_REMOTE_NAME
|
||||
命令来
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void bt_read_remote_name(u8 status, u8 *addr, u8 *name)
|
||||
{
|
||||
if (status) {
|
||||
printf("remote_name fail \n");
|
||||
} else {
|
||||
printf("remote_name : %s \n", name);
|
||||
}
|
||||
put_buf(addr, 6);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙歌曲信息获取回调
|
||||
@param
|
||||
@return
|
||||
@note
|
||||
const u8 more_avctp_cmd_support = 1;置上1
|
||||
需要在void bredr_handle_register()注册回调函数
|
||||
要动态获取播放时间的,可以发送USER_CTRL_AVCTP_OPID_GET_PLAY_TIME命令就可以了
|
||||
要半秒或者1秒获取就做个定时发这个命令
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
static bt_lrc_cb_t lrc_cb = NULL;
|
||||
|
||||
static int pow(int x, int y)
|
||||
{
|
||||
u8 i;
|
||||
int ret = 1;
|
||||
for (i = 0; i < y; i++) {
|
||||
ret *= x;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void bt_register_lyric_callback(bt_lrc_cb_t cb)
|
||||
{
|
||||
lrc_cb = cb;
|
||||
}
|
||||
|
||||
static void ms_to_time(u8 *info, u16 len)
|
||||
{
|
||||
//毫秒转换成分:秒
|
||||
u32 time = 0;
|
||||
u16 cnt;
|
||||
for (cnt = 0; cnt < len; cnt ++) {
|
||||
time += (info[len - 1 - cnt] - '0') * pow(10, cnt);
|
||||
}
|
||||
printf("music_time: %02d : %02d", time / 1000 / 60, (time % 60000) / 1000);
|
||||
}
|
||||
void user_get_bt_music_info(u8 type, u32 time, u8 *info, u16 len)
|
||||
{
|
||||
//profile define type:
|
||||
//1-title 2-artist name 3-album names 4-track number
|
||||
//5-total number of tracks 6-genre 7-playing time
|
||||
//JL define 0x10-total time , 0x11 current play position
|
||||
u8 min, sec;
|
||||
//printf("type %d\n", type );
|
||||
if ((info != NULL) && (len != 0) && (type != 7)) {
|
||||
printf(" %s \n", info);
|
||||
}
|
||||
|
||||
if (type == 7) {
|
||||
ms_to_time(info, len);
|
||||
}
|
||||
if (time != 0) {
|
||||
min = time / 1000 / 60;
|
||||
sec = time / 1000 - (min * 60);
|
||||
printf(" time %02d : %02d\n ", min, sec);
|
||||
}
|
||||
|
||||
if (lrc_cb) {
|
||||
lrc_cb(type, time, info, len);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void bt_music_player_time_deal(void *priv)
|
||||
{
|
||||
if (BT_STATUS_PLAYING_MUSIC == bt_get_connect_status()) {
|
||||
bt_cmd_prepare(USER_CTRL_AVCTP_OPID_GET_PLAY_TIME, 0, NULL);
|
||||
}
|
||||
}
|
||||
//播歌时配置为1
|
||||
void bt_music_player_time_timer_deal(u8 en)
|
||||
{
|
||||
#if TCFG_BT_MUSIC_INFO_ENABLE
|
||||
if (en) {
|
||||
if (g_bt_hdl.get_music_player_timer == 0) {
|
||||
g_bt_hdl.get_music_player_timer = sys_timer_add(NULL, bt_music_player_time_deal, 800);
|
||||
}
|
||||
} else {
|
||||
if (g_bt_hdl.get_music_player_timer) {
|
||||
sys_timer_del(g_bt_hdl.get_music_player_timer);
|
||||
g_bt_hdl.get_music_player_timer = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙spp 协议数据 回调
|
||||
@param packet_type:数据类型
|
||||
ch :区分spp链路的连接号
|
||||
packet :数据缓存
|
||||
size :数据长度
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void spp_data_handler(u8 packet_type, u16 ch, u8 *packet, u16 size)
|
||||
{
|
||||
switch (packet_type) {
|
||||
case 1:
|
||||
printf("---spp connect:%x\n", ch);
|
||||
break;
|
||||
case 2:
|
||||
printf("---spp disconnect:%x\n", ch);
|
||||
break;
|
||||
case 7:
|
||||
//puts("spp_rx:");
|
||||
//put_buf(packet,size);
|
||||
#if AEC_DEBUG_ONLINE
|
||||
aec_debug_online(packet, size);
|
||||
#endif
|
||||
|
||||
#if TCFG_USER_RSSI_TEST_EN
|
||||
int spp_get_rssi_handler(u8 * packet, u16 size);
|
||||
spp_get_rssi_handler(packet, size);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙获取样机当前电量
|
||||
@param
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int bt_get_battery_value()
|
||||
{
|
||||
//取消默认蓝牙定时发送电量给手机,需要更新电量给手机使用USER_CTRL_HFP_CMD_UPDATE_BATTARY命令
|
||||
/*电量协议的是0-9个等级,请比例换算*/
|
||||
return get_cur_battery_level();
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙快速测试
|
||||
@param
|
||||
@return
|
||||
@note 样机和蓝牙测试盒链接开启快速测试,开启mic扩音功能,
|
||||
按键就播放按键音来检测硬件是否焊接正常
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void bt_fast_test_api(void)
|
||||
{
|
||||
/*
|
||||
* 进入快速测试模式,用户根据此标志判断测试,
|
||||
* 如测试按键-开按键音 、测试mic-开扩音 、
|
||||
* 根据fast_test_mode根据改变led闪烁方式、关闭可发现可连接
|
||||
*/
|
||||
puts("------------bt_fast_test_api---------\n");
|
||||
if (g_bt_hdl.fast_test_mode == 0) {
|
||||
g_bt_hdl.fast_test_mode = 1;
|
||||
audio_fast_mode_test();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙模式样机被测试仪链接上的回调函数,把其他状态关闭
|
||||
@param
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void bt_dut_api(u8 param)
|
||||
{
|
||||
printf("bt in dut \n");
|
||||
sys_auto_shut_down_disable();
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
tws_cancle_all_noconn() ;
|
||||
#endif
|
||||
|
||||
if (g_bt_hdl.auto_connection_timer) {
|
||||
sys_timeout_del(g_bt_hdl.auto_connection_timer);
|
||||
g_bt_hdl.auto_connection_timer = 0;
|
||||
}
|
||||
|
||||
#if TCFG_BT_BLE_ADV_ENABLE
|
||||
#if (CONFIG_BT_MODE == BT_NORMAL)
|
||||
bt_ble_adv_enable(0);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙模式进入定频状态
|
||||
@param
|
||||
@return
|
||||
@note 量产的时候可以通过按键等来触发进入定频状态,这时候蓝牙会在一个通道里
|
||||
发送信号,可以通过设置下面变量来设置定频的频点
|
||||
const int config_bredr_fcc_fix_fre = 0;
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void bt_fix_fre_api(u8 fre)
|
||||
{
|
||||
bt_dut_api(0);
|
||||
|
||||
bit_clr_ie(IRQ_BREDR_IDX);
|
||||
bit_clr_ie(IRQ_BT_CLKN_IDX);
|
||||
|
||||
bredr_fcc_init(BT_FRE, fre);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙模式进入定频测试接收发射
|
||||
@param mode :0 测试发射 1:测试接收
|
||||
mac_addr:测试设置的地址
|
||||
fre:定频的频点 0=2402 1=2403
|
||||
packet_type:数据包类型
|
||||
|
||||
#define DH1_1 0
|
||||
#define DH3_1 1
|
||||
#define DH5_1 2
|
||||
#define DH1_2 3
|
||||
#define DH3_2 4
|
||||
#define DH5_2 5
|
||||
|
||||
payload:数据包内容 0x0000 0x0055 0x00aa 0x00ff
|
||||
0xffff:prbs9
|
||||
payload_len:数据包长度,不可以超过包类型最大长度,0:底层按照最大包发送
|
||||
pwr: 发送功率
|
||||
@return
|
||||
@note 量产的时候通过串口,发送设置的参数,设置发送接收的参数
|
||||
|
||||
关闭定频接收发射测试
|
||||
void link_fix_txrx_disable();
|
||||
|
||||
更新接收结果
|
||||
void bt_updata_fix_rx_result()
|
||||
|
||||
struct link_fix_rx_result {
|
||||
u32 rx_err_b; //接收到err bit
|
||||
u32 rx_sum_b; //接收到正确bit
|
||||
u32 rx_perr_p; //接收到crc 错误 包数
|
||||
u32 rx_herr_p; //接收到crc 以外其他错误包数
|
||||
u32 rx_invail_p; //接收到crc错误bit太多的包数,丢弃不统计到err bit中
|
||||
};*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void bt_fix_txrx_api(u8 mode, u8 *mac_addr, u8 fre, u8 packet_type, u16 payload)
|
||||
{
|
||||
bt_dut_api(0);
|
||||
local_irq_disable();
|
||||
link_fix_txrx_disable();
|
||||
if (mode) {
|
||||
link_fix_rx_enable(mac_addr, fre, packet_type, 0xffff, 0, 9);
|
||||
} else {
|
||||
link_fix_tx_enable(mac_addr, fre, packet_type, 0xffff, 0, 9);
|
||||
}
|
||||
local_irq_enable();
|
||||
}
|
||||
|
||||
void bt_updata_fix_rx_result()
|
||||
{
|
||||
struct link_fix_rx_result fix_rx_result;
|
||||
link_fix_rx_update_result(&fix_rx_result);
|
||||
printf("err_b:%d sum_b:%d perr:%d herr_b:%d invaile:%d \n",
|
||||
fix_rx_result.rx_err_b,
|
||||
fix_rx_result.rx_sum_b,
|
||||
fix_rx_result.rx_perr_p,
|
||||
fix_rx_result.rx_herr_p,
|
||||
fix_rx_result.rx_invail_p
|
||||
);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙event 退出dut模式
|
||||
@param
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void bt_bredr_exit_dut_mode()
|
||||
{
|
||||
bredr_set_dut_enble(0, 1);
|
||||
clock_free("DUT");
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙event 搜索结束
|
||||
@param
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void bt_hci_event_inquiry(struct bt_event *bt)
|
||||
{
|
||||
#if TCFG_USER_EMITTER_ENABLE
|
||||
/* if (g_bt_hdl.emitter_or_receiver == BT_EMITTER_EN) { */
|
||||
//以后扩展,暂时注释
|
||||
//emitter_search_stop();
|
||||
/* } */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void bt_discovery_and_connectable_using_loca_mac_addr(u8 inquiry_scan_en, u8 page_scan_en)
|
||||
{
|
||||
u8 local_addr[6];
|
||||
|
||||
bt_get_vm_mac_addr(local_addr);
|
||||
lmp_hci_write_local_address(local_addr);
|
||||
if (page_scan_en) {
|
||||
bt_cmd_prepare(USER_CTRL_WRITE_CONN_ENABLE, 0, NULL);
|
||||
}
|
||||
if (inquiry_scan_en) {
|
||||
bt_cmd_prepare(USER_CTRL_WRITE_SCAN_ENABLE, 0, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙event链接断开,实际流程处理位于dual_conn.c中,此处预留做状态更新
|
||||
@param
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void bt_hci_event_disconnect(struct bt_event *bt)
|
||||
{
|
||||
if (app_var.goto_poweroff_flag) {
|
||||
return;
|
||||
}
|
||||
|
||||
printf("<<<<<<<<<<<<<<total_dev: %d>>>>>>>>>>>>>\n", bt_get_total_connect_dev());
|
||||
|
||||
#if TCFG_TEST_BOX_ENABLE
|
||||
if (testbox_get_ex_enter_dut_flag()) {
|
||||
bt_discovery_and_connectable_using_loca_mac_addr(1, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (testbox_get_status()) {
|
||||
bt_discovery_and_connectable_using_loca_mac_addr(0, 1);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙event 链接超时
|
||||
@param
|
||||
@return
|
||||
@note 回链超时内没有连接上设备
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void bt_hci_event_connection_timeout(struct bt_event *bt)
|
||||
{
|
||||
#if TCFG_TEST_BOX_ENABLE
|
||||
if (testbox_get_ex_enter_dut_flag()) {
|
||||
bt_discovery_and_connectable_using_loca_mac_addr(1, 1);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙event 获取sco状态
|
||||
@param
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
u8 bt_sco_state(void)
|
||||
{
|
||||
return g_bt_hdl.phone_call_dec_begin;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 蓝牙weak函数重新定义,蓝牙获取到的电话本信息反馈给用户层
|
||||
@param
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void bt_phonebook_packet_handler(u8 type, const u8 *name, const u8 *number, const u8 *date)
|
||||
{
|
||||
static u16 number_cnt = 0;
|
||||
printf("NO.%d:", number_cnt);
|
||||
number_cnt++;
|
||||
printf("type:%d ", type);
|
||||
if (type == 0xff) {
|
||||
number_cnt = 0;
|
||||
}
|
||||
if (name) {
|
||||
printf(" NAME:%s ", name);
|
||||
}
|
||||
if (number) {
|
||||
printf("number:%s ", number);
|
||||
}
|
||||
if (date) {
|
||||
printf("date:%s ", date);
|
||||
}
|
||||
}
|
||||
#endif /* #if TCFG_APP_BT_EN */
|
||||
@@ -0,0 +1,426 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".bt_key_func.data.bss")
|
||||
#pragma data_seg(".bt_key_func.data")
|
||||
#pragma const_seg(".bt_key_func.text.const")
|
||||
#pragma code_seg(".bt_key_func.text")
|
||||
#endif
|
||||
#include "btstack/avctp_user.h"
|
||||
#include "key_driver.h"
|
||||
#include "audio_manager.h"
|
||||
#include "vol_sync.h"
|
||||
#include "app_main.h"
|
||||
#include "audio_config.h"
|
||||
#include "bt_key_func.h"
|
||||
#include "ui/ui_api.h"
|
||||
#include "ui_manage.h"
|
||||
|
||||
#include "bt_event_func.h"
|
||||
#include "app_tone.h"
|
||||
#include "app_common.h"
|
||||
|
||||
#if TCFG_APP_BT_EN
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief 音量加
|
||||
*
|
||||
* \param [in]
|
||||
*
|
||||
* \return
|
||||
*
|
||||
* \note 加音量
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void volume_up(void)
|
||||
{
|
||||
u8 test_box_vol_up = 0x41;
|
||||
s8 cur_vol = 0;
|
||||
u8 call_status = bt_get_call_status();
|
||||
|
||||
if ((tone_player_runing() || ring_player_runing())) {
|
||||
if (bt_get_call_status() == BT_CALL_INCOMING) {
|
||||
volume_up_down_direct(1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*打电话出去彩铃要可以调音量大小*/
|
||||
if ((call_status == BT_CALL_ACTIVE) || (call_status == BT_CALL_OUTGOING)) {
|
||||
cur_vol = app_audio_get_volume(APP_AUDIO_STATE_CALL);
|
||||
} else {
|
||||
cur_vol = app_audio_get_volume(APP_AUDIO_STATE_MUSIC);
|
||||
}
|
||||
if (bt_get_remote_test_flag()) {
|
||||
bt_cmd_prepare(USER_CTRL_TEST_KEY, 1, &test_box_vol_up); //音量加
|
||||
}
|
||||
|
||||
if (cur_vol >= app_audio_get_max_volume()) {
|
||||
audio_event_to_user(AUDIO_EVENT_VOL_MAX); //触发vol max事件
|
||||
|
||||
#if TCFG_MAX_VOL_PROMPT
|
||||
play_tone_file(get_tone_files()->max_vol);
|
||||
#endif
|
||||
if (bt_get_call_status() != BT_CALL_HANGUP) {
|
||||
/*本地音量最大,如果手机音量还没最大,继续加,以防显示不同步*/
|
||||
if (g_bt_hdl.phone_vol < 15) {
|
||||
bt_cmd_prepare(USER_CTRL_HFP_CALL_VOLUME_UP, 0, NULL);
|
||||
}
|
||||
return;
|
||||
}
|
||||
#if TCFG_BT_VOL_SYNC_ENABLE
|
||||
if (bt_get_call_status() == BT_CALL_HANGUP) {
|
||||
opid_play_vol_sync_fun(&app_var.music_volume, 1);
|
||||
bt_cmd_prepare(USER_CTRL_CMD_SYNC_VOL_INC, 0, NULL);
|
||||
}
|
||||
#endif/* TCFG_BT_VOL_SYNC_ENABLE */
|
||||
return;
|
||||
}
|
||||
|
||||
#if TCFG_BT_VOL_SYNC_ENABLE
|
||||
if (bt_get_call_status() == BT_CALL_HANGUP) {
|
||||
opid_play_vol_sync_fun(&app_var.music_volume, 1);
|
||||
app_audio_set_volume(APP_AUDIO_STATE_MUSIC, app_var.music_volume, 1);
|
||||
}
|
||||
#else
|
||||
if (app_audio_get_state() == APP_AUDIO_STATE_IDLE) {
|
||||
app_audio_state_switch(APP_AUDIO_STATE_MUSIC, app_audio_volume_max_query(AppVol_BT_MUSIC), NULL);
|
||||
}
|
||||
app_audio_volume_up(1);
|
||||
#endif/*TCFG_BT_VOL_SYNC_ENABLE*/
|
||||
printf("vol+: %d", app_audio_get_volume(APP_AUDIO_CURRENT_STATE));
|
||||
if (bt_get_call_status() != BT_CALL_HANGUP) {
|
||||
bt_cmd_prepare(USER_CTRL_HFP_CALL_VOLUME_UP, 0, NULL);
|
||||
} else {
|
||||
#if TCFG_BT_VOL_SYNC_ENABLE
|
||||
bt_cmd_prepare(USER_CTRL_CMD_SYNC_VOL_INC, 0, NULL);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief 音量减
|
||||
*
|
||||
* \param [in]
|
||||
*
|
||||
* \return
|
||||
*
|
||||
* \note 减音量
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void volume_down(void)
|
||||
{
|
||||
u8 test_box_vol_down = 0x42;
|
||||
if ((tone_player_runing() || ring_player_runing())) {
|
||||
if (bt_get_call_status() == BT_CALL_INCOMING) {
|
||||
volume_up_down_direct(-1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (bt_get_remote_test_flag()) {
|
||||
bt_cmd_prepare(USER_CTRL_TEST_KEY, 1, &test_box_vol_down); //音量减
|
||||
}
|
||||
|
||||
if (app_audio_get_volume(APP_AUDIO_CURRENT_STATE) <= 0) {
|
||||
audio_event_to_user(AUDIO_EVENT_VOL_MIN); //触发vol mix事件
|
||||
if (bt_get_call_status() != BT_CALL_HANGUP) {
|
||||
/*
|
||||
*本地音量最小,如果手机音量还没最小,继续减
|
||||
*注意:有些手机通话最小音量是1(GREE G0245D)
|
||||
*/
|
||||
if (g_bt_hdl.phone_vol > 1) {
|
||||
bt_cmd_prepare(USER_CTRL_HFP_CALL_VOLUME_DOWN, 0, NULL);
|
||||
}
|
||||
return;
|
||||
}
|
||||
#if TCFG_BT_VOL_SYNC_ENABLE
|
||||
if (bt_get_call_status() == BT_CALL_HANGUP) {
|
||||
opid_play_vol_sync_fun(&app_var.music_volume, 0);
|
||||
bt_cmd_prepare(USER_CTRL_CMD_SYNC_VOL_DEC, 0, NULL);
|
||||
}
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
#if TCFG_BT_VOL_SYNC_ENABLE
|
||||
if (bt_get_call_status() == BT_CALL_HANGUP) {
|
||||
opid_play_vol_sync_fun(&app_var.music_volume, 0);
|
||||
app_audio_set_volume(APP_AUDIO_STATE_MUSIC, app_var.music_volume, 1);
|
||||
}
|
||||
#else
|
||||
if (app_audio_get_state() == APP_AUDIO_STATE_IDLE) {
|
||||
app_audio_state_switch(APP_AUDIO_STATE_MUSIC, app_audio_volume_max_query(AppVol_BT_MUSIC), NULL);
|
||||
}
|
||||
app_audio_volume_down(1);
|
||||
#endif/*TCFG_BT_VOL_SYNC_ENABLE*/
|
||||
printf("vol-: %d", app_audio_get_volume(APP_AUDIO_CURRENT_STATE));
|
||||
if (bt_get_call_status() != BT_CALL_HANGUP) {
|
||||
bt_cmd_prepare(USER_CTRL_HFP_CALL_VOLUME_DOWN, 0, NULL);
|
||||
} else {
|
||||
#if TCFG_BT_VOL_SYNC_ENABLE
|
||||
/* opid_play_vol_sync_fun(&app_var.music_volume, 0); */
|
||||
if (app_audio_get_volume(APP_AUDIO_CURRENT_STATE) == 0) {
|
||||
app_audio_volume_down(0);
|
||||
}
|
||||
bt_cmd_prepare(USER_CTRL_CMD_SYNC_VOL_DEC, 0, NULL);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief 蓝牙模式 pp 按键处理
|
||||
*
|
||||
* \param [in]
|
||||
*
|
||||
* \return
|
||||
*
|
||||
* \note
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void bt_key_music_pp(void)
|
||||
{
|
||||
if ((bt_get_call_status() == BT_CALL_OUTGOING) ||
|
||||
(bt_get_call_status() == BT_CALL_ALERT)) {
|
||||
bt_cmd_prepare(USER_CTRL_HFP_CALL_HANGUP, 0, NULL);
|
||||
} else if (bt_get_call_status() == BT_CALL_INCOMING) {
|
||||
#if TCFG_BT_CALL_PHONE_BY_WATCH
|
||||
set_bt_esco_by_watch(1);
|
||||
#endif
|
||||
bt_cmd_prepare(USER_CTRL_HFP_CALL_ANSWER, 0, NULL);
|
||||
} else if (bt_get_call_status() == BT_CALL_ACTIVE) {
|
||||
bt_cmd_prepare(USER_CTRL_HFP_CALL_HANGUP, 0, NULL);
|
||||
} else {
|
||||
bt_cmd_prepare(USER_CTRL_AVCTP_OPID_PLAY, 0, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief 蓝牙模式 prev 按键处理
|
||||
*
|
||||
* \param [in]
|
||||
*
|
||||
* \return
|
||||
*
|
||||
* \note 播放音乐上一曲
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void bt_key_music_prev(void)
|
||||
{
|
||||
bt_cmd_prepare(USER_CTRL_AVCTP_OPID_PREV, 0, NULL);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief 蓝牙模式 next 按键处理
|
||||
*
|
||||
* \param [in]
|
||||
*
|
||||
* \return
|
||||
*
|
||||
* \note 播放音乐下一曲
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void bt_key_music_next(void)
|
||||
{
|
||||
if (bt_get_call_status() == BT_CALL_INCOMING) {
|
||||
bt_cmd_prepare(USER_CTRL_HFP_CALL_HANGUP, 0, NULL);
|
||||
return;
|
||||
}
|
||||
bt_cmd_prepare(USER_CTRL_AVCTP_OPID_NEXT, 0, NULL);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief 蓝牙模式 vol up 按键处理
|
||||
*
|
||||
* \param [in]
|
||||
*
|
||||
* \return
|
||||
*
|
||||
* \note 加音量
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void bt_key_vol_up(void)
|
||||
{
|
||||
u8 vol;
|
||||
u8 call_status;
|
||||
if (bt_get_call_status() == BT_CALL_ACTIVE && bt_sco_state() == 0) {
|
||||
return;
|
||||
}
|
||||
volume_up();
|
||||
call_status = bt_get_call_status();
|
||||
if ((call_status == BT_CALL_ACTIVE) || (call_status == BT_CALL_OUTGOING)) {
|
||||
vol = app_audio_get_volume(APP_AUDIO_STATE_CALL);
|
||||
} else {
|
||||
vol = app_audio_get_volume(APP_AUDIO_STATE_MUSIC);
|
||||
}
|
||||
printf("music_vol:vol=%d, state:%d", vol, app_audio_get_state());
|
||||
app_send_message(APP_MSG_VOL_CHANGED, vol);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief 蓝牙模式 vol down 按键处理
|
||||
*
|
||||
* \param [in]
|
||||
*
|
||||
* \return
|
||||
*
|
||||
* \note 减音量
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void bt_key_vol_down(void)
|
||||
{
|
||||
u8 vol;
|
||||
u8 call_status;
|
||||
if (bt_get_call_status() == BT_CALL_ACTIVE && bt_sco_state() == 0) {
|
||||
return;
|
||||
}
|
||||
volume_down();
|
||||
call_status = bt_get_call_status();
|
||||
if ((call_status == BT_CALL_ACTIVE) || (call_status == BT_CALL_OUTGOING)) {
|
||||
vol = app_audio_get_volume(APP_AUDIO_STATE_CALL);
|
||||
} else {
|
||||
vol = app_audio_get_volume(APP_AUDIO_STATE_MUSIC);
|
||||
}
|
||||
printf("music_vol:vol=%d, state:%d", vol, app_audio_get_state());
|
||||
app_send_message(APP_MSG_VOL_CHANGED, vol);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief 蓝牙模式 回拨最后一个号码 来电拒听
|
||||
*
|
||||
* \param [in]
|
||||
*
|
||||
* \return
|
||||
*
|
||||
* \note
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void bt_key_call_last_on(void)
|
||||
{
|
||||
if (bt_get_call_status() == BT_CALL_INCOMING) {
|
||||
bt_cmd_prepare(USER_CTRL_HFP_CALL_HANGUP, 0, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((bt_get_call_status() == BT_CALL_ACTIVE) ||
|
||||
(bt_get_call_status() == BT_CALL_OUTGOING) ||
|
||||
(bt_get_call_status() == BT_CALL_ALERT) ||
|
||||
(bt_get_call_status() == BT_CALL_INCOMING)) {
|
||||
return;//通话过程不允许回拨
|
||||
}
|
||||
|
||||
if (g_bt_hdl.last_call_type == BT_STATUS_PHONE_INCOME) {
|
||||
bt_cmd_prepare(USER_CTRL_HFP_DIAL_NUMBER, g_bt_hdl.income_phone_len,
|
||||
g_bt_hdl.income_phone_num);
|
||||
} else {
|
||||
bt_cmd_prepare(USER_CTRL_HFP_CALL_LAST_NO, 0, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief 蓝牙模式 通话挂断
|
||||
*
|
||||
* \param [in]
|
||||
*
|
||||
* \return
|
||||
*
|
||||
* \note
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void bt_key_call_hang_up(void)
|
||||
{
|
||||
bt_cmd_prepare(USER_CTRL_HFP_CALL_HANGUP, 0, NULL);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief 蓝牙模式 siri开启
|
||||
*
|
||||
* \param [in]
|
||||
*
|
||||
* \return
|
||||
*
|
||||
* \note
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void bt_key_call_siri(void)
|
||||
{
|
||||
bt_cmd_prepare(USER_CTRL_HFP_GET_SIRI_OPEN, 0, NULL);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief 蓝牙模式 hid 发起拍照命令
|
||||
*
|
||||
* \param [in]
|
||||
*
|
||||
* \return
|
||||
*
|
||||
* \note
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void bt_key_hid_control(void)
|
||||
{
|
||||
/* log_info("bt_get_curr_channel_state:%x\n", bt_get_curr_channel_state()); */
|
||||
if (bt_get_curr_channel_state() & HID_CH) {
|
||||
printf("KEY_HID_CONTROL\n");
|
||||
bt_cmd_prepare(USER_CTRL_HID_IOS, 0, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief 蓝牙模式 三方通话 挂断当前去听另一个(未接听或者在保留状态都可以)
|
||||
*
|
||||
* \param [in]
|
||||
*
|
||||
* \return
|
||||
*
|
||||
* \note
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void bt_key_call_three_way_answer1(void)
|
||||
{
|
||||
bt_cmd_prepare(USER_CTRL_HFP_THREE_WAY_ANSWER1, 0, NULL);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief 蓝牙模式 三方通话 保留当前去接听, 或者用于两个通话的切换
|
||||
*
|
||||
* \param [in]
|
||||
*
|
||||
* \return
|
||||
*
|
||||
* \note
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void bt_key_call_three_way_answer2(void)
|
||||
{
|
||||
bt_cmd_prepare(USER_CTRL_HFP_THREE_WAY_ANSWER2, 0, NULL);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief 蓝牙模式 通话声卡切换
|
||||
*
|
||||
* \param [in]
|
||||
*
|
||||
* \return
|
||||
*
|
||||
* \note
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void bt_key_call_switch(void)
|
||||
{
|
||||
if (bt_get_call_status() == BT_CALL_ACTIVE) {
|
||||
bt_cmd_prepare(USER_CTRL_SCO_LINK, 0, NULL);
|
||||
}
|
||||
}
|
||||
#endif /* #if TCFG_APP_BT_EN */
|
||||
|
||||
@@ -0,0 +1,287 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".bt_key_msg_table.data.bss")
|
||||
#pragma data_seg(".bt_key_msg_table.data")
|
||||
#pragma const_seg(".bt_key_msg_table.text.const")
|
||||
#pragma code_seg(".bt_key_msg_table.text")
|
||||
#endif
|
||||
#include "key_driver.h"
|
||||
#include "app_main.h"
|
||||
#include "init.h"
|
||||
|
||||
#if TCFG_APP_BT_EN
|
||||
|
||||
#if TCFG_ADKEY_ENABLE
|
||||
//短按 //长按 //hold i
|
||||
//长按抬起 //双击 //三击
|
||||
#if (CONFIG_UI_STYLE != STYLE_JL_SOUNDBOX)
|
||||
const int key_bt_ad_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_CHANGE_MODE, APP_MSG_KEY_POWER_OFF, APP_MSG_KEY_POWER_OFF_HOLD,
|
||||
APP_MSG_KEY_POWER_OFF_RELEASE, APP_MSG_MIC_EFFECT_ON_OFF, APP_MSG_VOCAL_REMOVE,
|
||||
};
|
||||
const int key_bt_ad_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_PP, APP_MSG_CALL_HANGUP, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_CALL_LAST_NO, APP_MSG_TWS_START_REMOVE_PAIR,
|
||||
};
|
||||
const int key_bt_ad_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_NEXT, APP_MSG_VOL_UP, APP_MSG_VOL_UP,
|
||||
APP_MSG_NULL, APP_MSG_OPEN_SIRI, APP_MSG_CALL_SWITCH,
|
||||
};
|
||||
const int key_bt_ad_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_PREV, APP_MSG_VOL_DOWN, APP_MSG_VOL_DOWN,
|
||||
APP_MSG_NULL, APP_MSG_CALL_THREE_WAY_ANSWER1, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ad_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_CALL_THREE_WAY_ANSWER2, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ad_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_SWITCH_SOUND_EFFECT, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ad_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_SWITCH_MIC_EFFECT, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_MIC_EFFECT_ON_OFF, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ad_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_VOCAL_REMOVE, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ad_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MIC_VOL_UP, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ad_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MIC_VOL_DOWN, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
#else /*LCD按键*/
|
||||
const int key_bt_ad_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_CHANGE_MODE, APP_MSG_KEY_POWER_OFF, APP_MSG_KEY_POWER_OFF_HOLD,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ad_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_LCD_OK, APP_MSG_LCD_MENU, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ad_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_LCD_DOWN, APP_MSG_LCD_VOL_DEC, APP_MSG_LCD_VOL_DEC,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ad_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_LCD_UP, APP_MSG_LCD_VOL_INC, APP_MSG_LCD_VOL_INC,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ad_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_LCD_MODE, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ad_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ad_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ad_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ad_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ad_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if TCFG_IRKEY_ENABLE
|
||||
//短按 //长按 //hold
|
||||
//长按抬起 //双击 //三击
|
||||
const int key_bt_ir_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_KEY_POWER_OFF_INSTANTLY, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ir_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_CHANGE_MODE, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ir_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_SYS_MUTE, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ir_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_PP, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_OPEN_SIRI, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ir_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_PREV, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ir_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_NEXT, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ir_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_CHANGE_EQ, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ir_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_VOL_DOWN, APP_MSG_VOL_DOWN, APP_MSG_VOL_DOWN,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ir_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_VOL_UP, APP_MSG_VOL_UP, APP_MSG_VOL_UP,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ir_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ir_num10_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ir_num11_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ir_num12_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ir_num13_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ir_num14_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ir_num15_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ir_num16_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ir_num17_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ir_num18_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ir_num19_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_ir_num20_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
#endif
|
||||
|
||||
#if TCFG_IOKEY_ENABLE
|
||||
//短按 //长按 //hold
|
||||
//长按抬起 //双击 //三击
|
||||
const int key_bt_io_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_JL_UI_HOME, APP_MSG_JL_UI_POWEROFF, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_io_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_PP, APP_MSG_CALL_HANGUP, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_CALL_LAST_NO, APP_MSG_LOW_LANTECY,
|
||||
};
|
||||
const int key_bt_io_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_NEXT, APP_MSG_VOL_UP, APP_MSG_VOL_UP,
|
||||
APP_MSG_NULL, APP_MSG_OPEN_SIRI, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_io_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_PREV, APP_MSG_VOL_DOWN, APP_MSG_VOL_DOWN,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_io_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_io_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_io_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_io_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_io_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_bt_io_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
#endif
|
||||
|
||||
const struct key_remap_table bt_mode_key_table[] = {
|
||||
#if TCFG_ADKEY_ENABLE
|
||||
{ .key_value = KEY_AD_NUM0, .remap_table = key_bt_ad_num0_msg_table },
|
||||
{ .key_value = KEY_AD_NUM1, .remap_table = key_bt_ad_num1_msg_table },
|
||||
{ .key_value = KEY_AD_NUM2, .remap_table = key_bt_ad_num2_msg_table },
|
||||
{ .key_value = KEY_AD_NUM3, .remap_table = key_bt_ad_num3_msg_table },
|
||||
{ .key_value = KEY_AD_NUM4, .remap_table = key_bt_ad_num4_msg_table },
|
||||
{ .key_value = KEY_AD_NUM5, .remap_table = key_bt_ad_num5_msg_table },
|
||||
{ .key_value = KEY_AD_NUM6, .remap_table = key_bt_ad_num6_msg_table },
|
||||
{ .key_value = KEY_AD_NUM7, .remap_table = key_bt_ad_num7_msg_table },
|
||||
{ .key_value = KEY_AD_NUM8, .remap_table = key_bt_ad_num8_msg_table },
|
||||
{ .key_value = KEY_AD_NUM9, .remap_table = key_bt_ad_num9_msg_table },
|
||||
#endif
|
||||
#if TCFG_IRKEY_ENABLE
|
||||
{ .key_value = KEY_IR_NUM0, .remap_table = key_bt_ir_num0_msg_table },
|
||||
{ .key_value = KEY_IR_NUM1, .remap_table = key_bt_ir_num1_msg_table },
|
||||
{ .key_value = KEY_IR_NUM2, .remap_table = key_bt_ir_num2_msg_table },
|
||||
{ .key_value = KEY_IR_NUM3, .remap_table = key_bt_ir_num3_msg_table },
|
||||
{ .key_value = KEY_IR_NUM4, .remap_table = key_bt_ir_num4_msg_table },
|
||||
{ .key_value = KEY_IR_NUM5, .remap_table = key_bt_ir_num5_msg_table },
|
||||
{ .key_value = KEY_IR_NUM6, .remap_table = key_bt_ir_num6_msg_table },
|
||||
{ .key_value = KEY_IR_NUM7, .remap_table = key_bt_ir_num7_msg_table },
|
||||
{ .key_value = KEY_IR_NUM8, .remap_table = key_bt_ir_num8_msg_table },
|
||||
{ .key_value = KEY_IR_NUM9, .remap_table = key_bt_ir_num9_msg_table },
|
||||
{ .key_value = KEY_IR_NUM10, .remap_table = key_bt_ir_num10_msg_table },
|
||||
{ .key_value = KEY_IR_NUM11, .remap_table = key_bt_ir_num11_msg_table },
|
||||
{ .key_value = KEY_IR_NUM12, .remap_table = key_bt_ir_num12_msg_table },
|
||||
{ .key_value = KEY_IR_NUM13, .remap_table = key_bt_ir_num13_msg_table },
|
||||
{ .key_value = KEY_IR_NUM14, .remap_table = key_bt_ir_num14_msg_table },
|
||||
{ .key_value = KEY_IR_NUM15, .remap_table = key_bt_ir_num15_msg_table },
|
||||
{ .key_value = KEY_IR_NUM16, .remap_table = key_bt_ir_num16_msg_table },
|
||||
{ .key_value = KEY_IR_NUM17, .remap_table = key_bt_ir_num17_msg_table },
|
||||
{ .key_value = KEY_IR_NUM18, .remap_table = key_bt_ir_num18_msg_table },
|
||||
{ .key_value = KEY_IR_NUM19, .remap_table = key_bt_ir_num19_msg_table },
|
||||
{ .key_value = KEY_IR_NUM20, .remap_table = key_bt_ir_num20_msg_table },
|
||||
#endif
|
||||
#if TCFG_IOKEY_ENABLE
|
||||
{ .key_value = KEY_IO_WATCH_UPPER_LEFT, .remap_table = key_bt_io_num0_msg_table },
|
||||
{ .key_value = KEY_IO_NUM1, .remap_table = key_bt_io_num1_msg_table },
|
||||
{ .key_value = KEY_IO_NUM2, .remap_table = key_bt_io_num2_msg_table },
|
||||
{ .key_value = KEY_IO_NUM3, .remap_table = key_bt_io_num3_msg_table },
|
||||
{ .key_value = KEY_IO_NUM4, .remap_table = key_bt_io_num4_msg_table },
|
||||
{ .key_value = KEY_IO_NUM5, .remap_table = key_bt_io_num5_msg_table },
|
||||
{ .key_value = KEY_IO_NUM6, .remap_table = key_bt_io_num6_msg_table },
|
||||
{ .key_value = KEY_IO_NUM7, .remap_table = key_bt_io_num7_msg_table },
|
||||
{ .key_value = KEY_IO_NUM8, .remap_table = key_bt_io_num8_msg_table },
|
||||
{ .key_value = KEY_IO_NUM9, .remap_table = key_bt_io_num9_msg_table },
|
||||
#endif
|
||||
{ .key_value = 0xff }
|
||||
};
|
||||
|
||||
#endif /* #if TCFG_APP_BT_EN */
|
||||
|
||||
@@ -0,0 +1,300 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".bt_slience_detect.data.bss")
|
||||
#pragma data_seg(".bt_slience_detect.data")
|
||||
#pragma const_seg(".bt_slience_detect.text.const")
|
||||
#pragma code_seg(".bt_slience_detect.text")
|
||||
#endif
|
||||
#include "system/includes.h"
|
||||
#include "classic/tws_api.h"
|
||||
#include "btstack/avctp_user.h"
|
||||
#include "btstack/a2dp_media_codec.h"
|
||||
#include "bt_slience_detect.h"
|
||||
#include "bt_audio_energy_detection.h"
|
||||
|
||||
#include "app_config.h"
|
||||
#include "app_main.h"
|
||||
|
||||
#if TCFG_APP_BT_EN
|
||||
|
||||
struct detect_handler {
|
||||
u8 codec_type;
|
||||
u8 unmute_packet_cnt;
|
||||
u8 energy_check_stop;
|
||||
u8 ingore_packet_num;
|
||||
u8 bt_addr[6];
|
||||
u16 ingore_to_seqn;
|
||||
u16 slience_timer;
|
||||
void *file;
|
||||
};
|
||||
|
||||
static struct detect_handler *g_detect_hdl[2] = {NULL, NULL};
|
||||
|
||||
static struct detect_handler *get_detect_handler(u8 *bt_addr)
|
||||
{
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (g_detect_hdl[i] && memcmp(g_detect_hdl[i]->bt_addr, bt_addr, 6) == 0) {
|
||||
return g_detect_hdl[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct detect_handler *create_detect_handler()
|
||||
{
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (!g_detect_hdl[i]) {
|
||||
g_detect_hdl[i] = zalloc(sizeof(struct detect_handler));
|
||||
return g_detect_hdl[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void close_energy_detect(u8 codec_type)
|
||||
{
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (g_detect_hdl[i] && g_detect_hdl[i]->codec_type == codec_type) { //判断要关闭的类型是否还在使用
|
||||
return;
|
||||
}
|
||||
}
|
||||
bt_audio_energy_detect_close(codec_type);//关闭对应类型的能量检测
|
||||
}
|
||||
|
||||
static void a2dp_slience_detect(void *_detect)
|
||||
{
|
||||
int len;
|
||||
struct a2dp_media_frame frame;
|
||||
int seqn = -1;
|
||||
struct detect_handler *detect = (struct detect_handler *)_detect;
|
||||
|
||||
if (tws_api_get_role() == TWS_ROLE_SLAVE) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (detect == g_detect_hdl[i]) {
|
||||
goto __check;
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
__check:
|
||||
if (!detect->file) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
len = a2dp_media_try_get_packet(detect->file, &frame);
|
||||
|
||||
if (len <= 0) {
|
||||
break;
|
||||
}
|
||||
u8 *packet = frame.packet;
|
||||
|
||||
seqn = (packet[2] << 8) | packet[3];
|
||||
|
||||
/*
|
||||
* 不检测,一直丢包
|
||||
*/
|
||||
#if 0//TCFG_A2DP_PREEMPTED_ENABLE == 0
|
||||
seqn += 10;
|
||||
if ((seqn & 0xffff) == 0) {
|
||||
seqn = 1;
|
||||
}
|
||||
a2dp_media_free_packet(detect->file, packet);
|
||||
break;
|
||||
#endif
|
||||
|
||||
extern u8 bt_get_a2dp_en_status();
|
||||
if (!bt_get_a2dp_en_status()) {
|
||||
a2dp_media_free_packet(detect->file, packet);
|
||||
detect->ingore_to_seqn = 0;
|
||||
detect->unmute_packet_cnt = 0;
|
||||
detect->energy_check_stop = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (detect->ingore_to_seqn == 0) {
|
||||
detect->ingore_to_seqn = seqn + detect->ingore_packet_num;
|
||||
if (detect->ingore_to_seqn == 0) {
|
||||
detect->ingore_to_seqn = 1;
|
||||
}
|
||||
a2dp_media_free_packet(detect->file, packet);
|
||||
seqn = detect->ingore_to_seqn;
|
||||
break;
|
||||
}
|
||||
|
||||
//能量检测
|
||||
int energy = 0;
|
||||
int unmute_packet_num = 0;
|
||||
if (detect->codec_type == A2DP_CODEC_SBC) { //20ms
|
||||
energy = bt_audio_energy_detect_run(detect->codec_type, packet, len);
|
||||
unmute_packet_num = TCFG_BT_BACKGROUND_DETECT_TIME / 20;
|
||||
} else if (detect->codec_type == A2DP_CODEC_MPEG24) { //25ms
|
||||
energy = bt_audio_energy_detect_run(detect->codec_type, packet, len);
|
||||
unmute_packet_num = TCFG_BT_BACKGROUND_DETECT_TIME / 25;
|
||||
} else if (detect->codec_type == A2DP_CODEC_LDAC) {
|
||||
energy = bt_audio_energy_detect_run(detect->codec_type, packet, len);
|
||||
unmute_packet_num = TCFG_BT_BACKGROUND_DETECT_TIME / 25;
|
||||
}
|
||||
|
||||
printf("-energy: %d, %d, %d\n", seqn, energy, detect->unmute_packet_cnt);
|
||||
|
||||
if (energy >= 10) {
|
||||
if (++detect->unmute_packet_cnt < unmute_packet_num) {
|
||||
a2dp_media_free_packet(detect->file, packet);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (energy >= 0) {
|
||||
detect->unmute_packet_cnt >>= 1;
|
||||
}
|
||||
a2dp_media_free_packet(detect->file, packet);
|
||||
continue;
|
||||
}
|
||||
|
||||
a2dp_media_free_packet(detect->file, packet);
|
||||
|
||||
sys_timer_del(detect->slience_timer);
|
||||
detect->slience_timer = 0;
|
||||
|
||||
seqn += 10;
|
||||
if ((seqn & 0xffff) == 0) {
|
||||
seqn = 1;
|
||||
}
|
||||
a2dp_media_clear_packet_before_seqn(detect->file, seqn);
|
||||
printf("slience_detect_over: clear_to_seqn: %d\n", seqn);
|
||||
|
||||
a2dp_close_media_file(detect->file);
|
||||
detect->file = NULL;
|
||||
|
||||
u8 codec_type = detect->codec_type;
|
||||
|
||||
if (detect->codec_type == A2DP_CODEC_MPEG24) {
|
||||
detect->codec_type = 0xff;
|
||||
}
|
||||
close_energy_detect(codec_type);
|
||||
|
||||
int msg[4];
|
||||
msg[0] = APP_MSG_BT_A2DP_START;
|
||||
memcpy(msg + 1, detect->bt_addr, 6);
|
||||
app_send_message_from(MSG_FROM_APP, 12, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (seqn > 0) {
|
||||
a2dp_media_clear_packet_before_seqn(detect->file, seqn);
|
||||
}
|
||||
}
|
||||
|
||||
void bt_start_a2dp_slience_detect(u8 *bt_addr, int ingore_packet_num)
|
||||
{
|
||||
void *file = a2dp_open_media_file(bt_addr);
|
||||
if (!file) {
|
||||
puts("open_a2dp_file_faild\n");
|
||||
return;
|
||||
}
|
||||
|
||||
struct detect_handler *detect = get_detect_handler(bt_addr);
|
||||
if (!detect) {
|
||||
detect = create_detect_handler();
|
||||
if (!detect) {
|
||||
a2dp_close_media_file(file);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (detect->slience_timer) {
|
||||
sys_timer_del(detect->slience_timer);
|
||||
}
|
||||
|
||||
detect->file = file;
|
||||
detect->codec_type = a2dp_media_get_codec_type(detect->file);
|
||||
|
||||
detect->ingore_packet_num = ingore_packet_num;
|
||||
detect->ingore_to_seqn = 0;
|
||||
detect->unmute_packet_cnt = 0;
|
||||
detect->energy_check_stop = 0;
|
||||
memcpy(detect->bt_addr, bt_addr, 6);
|
||||
|
||||
detect->slience_timer = sys_timer_add(detect, a2dp_slience_detect, 80);
|
||||
g_printf("bt_start_a2dp_slience_detect:");
|
||||
put_buf(bt_addr, 6);
|
||||
}
|
||||
|
||||
void bt_stop_a2dp_slience_detect(u8 *bt_addr)
|
||||
{
|
||||
struct detect_handler *detect;
|
||||
u8 codec_type = 0;
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
detect = g_detect_hdl[i];
|
||||
if (!detect) {
|
||||
continue;
|
||||
}
|
||||
if (bt_addr && memcmp(detect->bt_addr, bt_addr, 6)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
codec_type = g_detect_hdl[i]->codec_type;
|
||||
|
||||
g_detect_hdl[i] = NULL;
|
||||
|
||||
if (detect->slience_timer) {
|
||||
sys_timer_del(detect->slience_timer);
|
||||
detect->slience_timer = 0;
|
||||
g_printf("bt_stop_a2dp_slience_detect");
|
||||
}
|
||||
if (detect->file) {
|
||||
a2dp_close_media_file(detect->file);
|
||||
detect->file = NULL;
|
||||
}
|
||||
|
||||
free(detect);
|
||||
detect = NULL;
|
||||
}
|
||||
|
||||
close_energy_detect(codec_type);
|
||||
}
|
||||
|
||||
void bt_reset_a2dp_slience_detect()
|
||||
{
|
||||
struct detect_handler *detect;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
detect = g_detect_hdl[i];
|
||||
if (!detect || detect->slience_timer == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
detect->ingore_to_seqn = 0;
|
||||
detect->unmute_packet_cnt = 0;
|
||||
detect->energy_check_stop = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int bt_slience_detect_get_result(u8 *bt_addr)
|
||||
{
|
||||
struct detect_handler *detect = get_detect_handler(bt_addr);
|
||||
if (!detect) {
|
||||
return BT_SLIENCE_NO_DETECTING;
|
||||
}
|
||||
if (detect->unmute_packet_cnt) {
|
||||
return BT_SLIENCE_HAVE_ENERGY;
|
||||
}
|
||||
return BT_SLIENCE_NO_ENERGY;
|
||||
}
|
||||
|
||||
int bt_slience_get_detect_addr(u8 *bt_addr)
|
||||
{
|
||||
struct detect_handler *detect;
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
detect = g_detect_hdl[i];
|
||||
if (!detect) {
|
||||
continue;
|
||||
}
|
||||
memcpy(bt_addr, detect->bt_addr, 6);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif /* #if TCFG_APP_BT_EN */
|
||||
|
||||
@@ -0,0 +1,633 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".dual_conn.data.bss")
|
||||
#pragma data_seg(".dual_conn.data")
|
||||
#pragma const_seg(".dual_conn.text.const")
|
||||
#pragma code_seg(".dual_conn.text")
|
||||
#endif
|
||||
#include "btstack/avctp_user.h"
|
||||
#include "app_main.h"
|
||||
#include "bt.h"
|
||||
#include "app_config.h"
|
||||
#include "user_cfg.h"
|
||||
#include "bt_background.h"
|
||||
#include "bt_event_func.h"
|
||||
#include "btstack/third_party/rcsp/btstack_rcsp_user.h"
|
||||
|
||||
#if TCFG_APP_BT_EN
|
||||
#if(TCFG_USER_TWS_ENABLE == 0)
|
||||
|
||||
#define MAX_PAGE_DEVICE_NUM 2
|
||||
|
||||
#define TIMEOUT_CONN_DEVICE_OPEN_PAGE 1 //第二台设备超时断开回连一直开启page
|
||||
|
||||
static void page_next_device(void *p);
|
||||
extern u8 get_role_type_by_addr(u8 *addr);
|
||||
extern u8 check_conn_by_addr(u8 *addr);
|
||||
|
||||
struct page_device_info {
|
||||
struct list_head entry;
|
||||
u32 timeout;
|
||||
u16 timer;
|
||||
u8 mac_addr[6];
|
||||
};
|
||||
|
||||
struct dual_conn_handle {
|
||||
u16 timer;
|
||||
u16 page_scan_timer;
|
||||
u16 close_inquiry_scan_timer;
|
||||
u8 device_num_recorded;
|
||||
u8 remote_addr[3][6];
|
||||
u8 remote_type[3];
|
||||
u8 page_head_inited;
|
||||
u8 page_scan_auto_disable;
|
||||
u8 inquiry_scan_disable;
|
||||
struct list_head page_head;
|
||||
};
|
||||
|
||||
static struct dual_conn_handle g_dual_conn;
|
||||
static u8 page_mode_active = 0;
|
||||
|
||||
static void dual_conn_page_device();
|
||||
|
||||
static bool page_list_empty()
|
||||
{
|
||||
return list_empty(&g_dual_conn.page_head);
|
||||
}
|
||||
|
||||
static void auto_close_page_scan(void *p)
|
||||
{
|
||||
puts("auto_close_page_scan\n");
|
||||
g_dual_conn.page_scan_timer = 0;
|
||||
g_dual_conn.page_scan_auto_disable = 1;
|
||||
lmp_hci_write_scan_enable((0 << 1) | 0);
|
||||
}
|
||||
|
||||
static void write_scan_conn_enable(bool scan_enable, bool conn_enable)
|
||||
{
|
||||
if (g_dual_conn.page_scan_auto_disable) {
|
||||
if (!scan_enable && conn_enable) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
lmp_hci_write_scan_enable((conn_enable << 1) | scan_enable);
|
||||
|
||||
if ((scan_enable || conn_enable) && page_list_empty()) {
|
||||
int connect_device = bt_get_total_connect_dev();
|
||||
app_send_message(APP_MSG_BT_IN_PAIRING_MODE, connect_device);
|
||||
}
|
||||
|
||||
#if TCFG_DUAL_CONN_PAGE_SCAN_TIME
|
||||
if (conn_enable && !scan_enable) {
|
||||
if (g_dual_conn.page_scan_timer) {
|
||||
sys_timer_modify(g_dual_conn.page_scan_timer,
|
||||
TCFG_DUAL_CONN_PAGE_SCAN_TIME * 1000);
|
||||
} else {
|
||||
g_dual_conn.page_scan_timer = sys_timeout_add(NULL, auto_close_page_scan,
|
||||
TCFG_DUAL_CONN_PAGE_SCAN_TIME * 1000);
|
||||
}
|
||||
} else {
|
||||
if (g_dual_conn.page_scan_timer) {
|
||||
sys_timeout_del(g_dual_conn.page_scan_timer);
|
||||
g_dual_conn.page_scan_timer = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void close_inquiry_scan(void *p)
|
||||
{
|
||||
g_dual_conn.inquiry_scan_disable = 1;
|
||||
if (g_dual_conn.device_num_recorded == 1 && bt_get_total_connect_dev() == 1) {
|
||||
write_scan_conn_enable(0, 0);
|
||||
}
|
||||
g_dual_conn.close_inquiry_scan_timer = 0;
|
||||
}
|
||||
|
||||
static int dual_conn_try_open_inquiry_scan()
|
||||
{
|
||||
#if TCFG_DUAL_CONN_INQUIRY_SCAN_TIME
|
||||
if (g_dual_conn.inquiry_scan_disable) {
|
||||
return 0;
|
||||
}
|
||||
write_scan_conn_enable(1, 1);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int add_device_2_page_list(u8 *mac_addr, u32 timeout)
|
||||
{
|
||||
struct page_device_info *info;
|
||||
|
||||
printf("add_device_2_page_list: %d\n", timeout);
|
||||
put_buf(mac_addr, 6);
|
||||
|
||||
if (!g_dual_conn.page_head_inited) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
list_for_each_entry(info, &g_dual_conn.page_head, entry) {
|
||||
if (memcmp(info->mac_addr, mac_addr, 6) == 0) {
|
||||
if (info->timer) {
|
||||
sys_timeout_del(info->timer);
|
||||
info->timer = 0;
|
||||
}
|
||||
info->timeout = jiffies + msecs_to_jiffies(timeout);
|
||||
|
||||
__list_del_entry(&info->entry);
|
||||
list_add_tail(&info->entry, &g_dual_conn.page_head);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
info = malloc(sizeof(*info));
|
||||
ASSERT(info);
|
||||
info->timer = 0;
|
||||
info->timeout = jiffies + msecs_to_jiffies(timeout);
|
||||
memcpy(info->mac_addr, mac_addr, 6);
|
||||
list_add_tail(&info->entry, &g_dual_conn.page_head);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void del_device_from_page_list(u8 *mac_addr)
|
||||
{
|
||||
struct page_device_info *info;
|
||||
|
||||
if (!g_dual_conn.page_head_inited) {
|
||||
return;
|
||||
}
|
||||
|
||||
list_for_each_entry(info, &g_dual_conn.page_head, entry) {
|
||||
if (memcmp(info->mac_addr, mac_addr, 6) == 0) {
|
||||
puts("del_device\n");
|
||||
put_buf(mac_addr, 6);
|
||||
__list_del_entry(&info->entry);
|
||||
if (info->timer) {
|
||||
sys_timeout_del(info->timer);
|
||||
}
|
||||
free(info);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void clr_device_in_page_list()
|
||||
{
|
||||
struct page_device_info *info, *n;
|
||||
|
||||
if (!g_dual_conn.page_head_inited) {
|
||||
return;
|
||||
}
|
||||
|
||||
list_for_each_entry_safe(info, n, &g_dual_conn.page_head, entry) {
|
||||
__list_del_entry(&info->entry);
|
||||
if (info->timer) {
|
||||
sys_timeout_del(info->timer);
|
||||
}
|
||||
free(info);
|
||||
}
|
||||
}
|
||||
|
||||
static u8 *get_device_addr_in_page_list()
|
||||
{
|
||||
struct page_device_info *info, *n;
|
||||
list_for_each_entry_safe(info, n, &g_dual_conn.page_head, entry) {
|
||||
return info->mac_addr;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void dual_conn_state_handler()
|
||||
{
|
||||
int connect_device = bt_get_total_connect_dev();
|
||||
int have_page_device = page_list_empty() ? false : true;
|
||||
printf("page_state: %d, %d\n", connect_device, have_page_device);
|
||||
if (g_dual_conn.timer) {
|
||||
sys_timeout_del(g_dual_conn.timer);
|
||||
g_dual_conn.timer = 0;
|
||||
}
|
||||
if (connect_device == 0) {
|
||||
#if TCFG_EDR_SCAN_CONN_CTRL
|
||||
u8 rcsp_get_ble_disconnect_by_app_flag(void);
|
||||
void rcsp_set_ble_disconnect_by_app_flag(u8 flag);
|
||||
u8 ble_disconnect = rcsp_get_ble_disconnect_by_app_flag();
|
||||
u8 bredr_state = is_bredr_close();
|
||||
printf("%s ble_disconnect:%d is_bredr_close:%d", __func__, ble_disconnect, is_bredr_close());
|
||||
if (is_bredr_close() == 0) {
|
||||
if (ble_disconnect == 1) {
|
||||
/*一键连接时候, 由app发指令断连*/
|
||||
write_scan_conn_enable(0, 1);
|
||||
} else {
|
||||
write_scan_conn_enable(0, 0);
|
||||
}
|
||||
}
|
||||
rcsp_set_ble_disconnect_by_app_flag(0);
|
||||
#else
|
||||
write_scan_conn_enable(1, 1);
|
||||
#endif
|
||||
} else if (connect_device == 1) {
|
||||
#if TCFG_BT_DUAL_CONN_ENABLE
|
||||
if (g_dual_conn.device_num_recorded > 1) {
|
||||
write_scan_conn_enable(0, 1);
|
||||
}
|
||||
#endif
|
||||
#if TCFG_USER_EMITTER_ENABLE
|
||||
if (bt_emitter_get_curr_channel_state()) {
|
||||
write_scan_conn_enable(0, 1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void dual_conn_page_device_timeout(void *p)
|
||||
{
|
||||
struct page_device_info *info;
|
||||
|
||||
if (!g_dual_conn.page_head_inited) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* 参数有效性检查 */
|
||||
list_for_each_entry(info, &g_dual_conn.page_head, entry) {
|
||||
if (info == p) {
|
||||
printf("page_device_timeout: %lu, %d\n", jiffies, info->timeout);
|
||||
info->timer = 0;
|
||||
list_del(&info->entry);
|
||||
if (time_after(jiffies, info->timeout)) {
|
||||
del_device_from_page_list(info->mac_addr);
|
||||
free(info);
|
||||
} else {
|
||||
list_add_tail(&info->entry, &g_dual_conn.page_head);
|
||||
}
|
||||
bt_cmd_prepare(USER_CTRL_PAGE_CANCEL, 0, NULL);
|
||||
if (!page_list_empty()) {
|
||||
if (g_dual_conn.timer) {
|
||||
sys_timeout_del(g_dual_conn.timer);
|
||||
g_dual_conn.timer = 0;
|
||||
}
|
||||
g_dual_conn.timer = sys_timeout_add(NULL, page_next_device, 2000);
|
||||
#if TCFG_EDR_SCAN_CONN_CTRL
|
||||
bt_discovery_and_connectable_using_loca_mac_addr(0, 1);
|
||||
#else
|
||||
//增加2s可发现可连接
|
||||
bt_discovery_and_connectable_using_loca_mac_addr(1, 1);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
page_mode_active = 0;
|
||||
dual_conn_state_handler();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void dual_conn_page_device()
|
||||
{
|
||||
struct page_device_info *info, *n;
|
||||
|
||||
if (!g_dual_conn.page_head_inited) {
|
||||
return;
|
||||
}
|
||||
|
||||
list_for_each_entry_safe(info, n, &g_dual_conn.page_head, entry) {
|
||||
if (info->timer) {
|
||||
return;
|
||||
}
|
||||
printf("start_page_device: %lu, %d\n", jiffies, info->timeout);
|
||||
put_buf(info->mac_addr, 6);
|
||||
info->timer = sys_timeout_add(info, dual_conn_page_device_timeout,
|
||||
TCFG_BT_PAGE_TIMEOUT * 1000);
|
||||
bt_cmd_prepare(USER_CTRL_START_CONNEC_VIA_ADDR, 6, info->mac_addr);
|
||||
page_mode_active = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
dual_conn_state_handler();
|
||||
}
|
||||
|
||||
|
||||
static void dual_conn_page_devices_init()
|
||||
{
|
||||
u8 mac_addr[6];
|
||||
|
||||
INIT_LIST_HEAD(&g_dual_conn.page_head);
|
||||
g_dual_conn.page_head_inited = 1;
|
||||
g_dual_conn.page_scan_auto_disable = 0;
|
||||
|
||||
int num = btstack_get_num_of_remote_device_recorded();
|
||||
for (int i = num - 1; i >= 0 && i + 2 >= num ; i--) {
|
||||
btstack_get_remote_addr(mac_addr, i);
|
||||
add_device_2_page_list(mac_addr, TCFG_BT_POWERON_PAGE_TIME * 1000);
|
||||
}
|
||||
g_dual_conn.device_num_recorded = num;
|
||||
if (num == 1) {
|
||||
memcpy(g_dual_conn.remote_addr[2], mac_addr, 6);
|
||||
}
|
||||
|
||||
#if TCFG_DUAL_CONN_INQUIRY_SCAN_TIME
|
||||
g_dual_conn.inquiry_scan_disable = 0;
|
||||
g_dual_conn.close_inquiry_scan_timer = sys_timeout_add(NULL, close_inquiry_scan, TCFG_DUAL_CONN_INQUIRY_SCAN_TIME * 1000);
|
||||
#else
|
||||
g_dual_conn.inquiry_scan_disable = 1;
|
||||
#endif
|
||||
|
||||
#if (TCFG_LP_NFC_TAG_ENABLE && TCFG_LP_NFC_TAG_TYPE == JL_BT_TAG)
|
||||
static u8 nfc_wakeup_disable_page = 1;
|
||||
if ((is_reset_source(MSYS_P2M_RST)) && (is_wakeup_source(PWR_WK_REASON_LPNFC)) && nfc_wakeup_disable_page) {
|
||||
nfc_wakeup_disable_page = 0;
|
||||
write_scan_conn_enable(1, 1);
|
||||
} else { //非nfc唤醒
|
||||
dual_conn_page_device();
|
||||
}
|
||||
#else
|
||||
dual_conn_page_device();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void page_next_device(void *p)
|
||||
{
|
||||
g_dual_conn.timer = 0;
|
||||
dual_conn_page_device();
|
||||
}
|
||||
|
||||
void dual_conn_user_bt_connect(u8 *addr)
|
||||
{
|
||||
add_device_2_page_list(addr, 0);
|
||||
if (g_dual_conn.timer) {
|
||||
sys_timeout_del(g_dual_conn.timer);
|
||||
g_dual_conn.timer = 0;
|
||||
}
|
||||
dual_conn_page_device();
|
||||
}
|
||||
|
||||
static void dual_conn_bt_connect_timeout(struct bt_event *bt)
|
||||
{
|
||||
add_device_2_page_list(bt->args, TCFG_BT_TIMEOUT_PAGE_TIME * 1000);
|
||||
|
||||
if (g_dual_conn.timer) {
|
||||
sys_timeout_del(g_dual_conn.timer);
|
||||
g_dual_conn.timer = 0;
|
||||
}
|
||||
dual_conn_page_device();
|
||||
}
|
||||
|
||||
static int dual_conn_btstack_event_handler(int *_event)
|
||||
{
|
||||
struct bt_event *event = (struct bt_event *)_event;
|
||||
|
||||
switch (event->event) {
|
||||
case BT_STATUS_INIT_OK:
|
||||
puts("dual_conn BT_STATUS_INIT_OK");
|
||||
dual_conn_page_devices_init();
|
||||
#if (TCFG_BT_BACKGROUND_ENABLE)
|
||||
bt_background_switch_mode_after_initializes();
|
||||
#endif
|
||||
return 0;
|
||||
case BT_STATUS_FIRST_CONNECTED:
|
||||
puts("dual_conn BT_STATUS_FIRST_CONNECTED");
|
||||
if (g_dual_conn.timer) {
|
||||
sys_timeout_del(g_dual_conn.timer);
|
||||
g_dual_conn.timer = 0;
|
||||
}
|
||||
del_device_from_page_list(event->args);
|
||||
memcpy(g_dual_conn.remote_addr[0], event->args, 6);
|
||||
if (!check_conn_by_addr(g_dual_conn.remote_addr[0])) {
|
||||
printf("no conn!");
|
||||
break;
|
||||
}
|
||||
|
||||
g_dual_conn.remote_type[0] = get_role_type_by_addr(g_dual_conn.remote_addr[0]);
|
||||
if (!page_list_empty()) {
|
||||
g_dual_conn.timer = sys_timeout_add(NULL, page_next_device, 500);
|
||||
return 0;
|
||||
}
|
||||
|
||||
page_mode_active = 0;
|
||||
if (g_dual_conn.device_num_recorded == 0) {
|
||||
g_dual_conn.device_num_recorded++;
|
||||
memcpy(g_dual_conn.remote_addr[2], event->args, 6);
|
||||
break;
|
||||
}
|
||||
if (g_dual_conn.device_num_recorded == 1) {
|
||||
if (memcmp(event->args, g_dual_conn.remote_addr[2], 6) == 0) {
|
||||
break;
|
||||
}
|
||||
g_dual_conn.device_num_recorded++;
|
||||
}
|
||||
#if TCFG_BT_DUAL_CONN_ENABLE
|
||||
write_scan_conn_enable(0, 1);
|
||||
#else
|
||||
#if !TCFG_USER_BLE_CTRL_BREDR_EN && TCFG_USER_EMITTER_ENABLE
|
||||
if (get_role_type_by_addr(g_dual_conn.remote_addr[0]) == ROLE_EMITTER) {
|
||||
write_scan_conn_enable(1, 1);
|
||||
} else {
|
||||
write_scan_conn_enable(0, 1);
|
||||
}
|
||||
#else
|
||||
write_scan_conn_enable(0, 0);
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
case BT_STATUS_SECOND_CONNECTED:
|
||||
puts("dual_conn BT_STATUS_SECOND_CONNECTED");
|
||||
if (g_dual_conn.device_num_recorded == 1) {
|
||||
g_dual_conn.device_num_recorded++;
|
||||
}
|
||||
if (g_dual_conn.timer) {
|
||||
sys_timeout_del(g_dual_conn.timer);
|
||||
g_dual_conn.timer = 0;
|
||||
}
|
||||
clr_device_in_page_list();
|
||||
memcpy(g_dual_conn.remote_addr[1], event->args, 6);
|
||||
if (!check_conn_by_addr(g_dual_conn.remote_addr[1])) {
|
||||
printf("no conn!");
|
||||
break;
|
||||
}
|
||||
g_dual_conn.remote_type[1] = get_role_type_by_addr(g_dual_conn.remote_addr[1]);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
APP_MSG_HANDLER(dual_conn_stack_msg_entry) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_BT_STACK,
|
||||
.handler = dual_conn_btstack_event_handler,
|
||||
};
|
||||
|
||||
|
||||
static int dual_conn_hci_event_handler(int *_event)
|
||||
{
|
||||
struct bt_event *event = (struct bt_event *)_event;
|
||||
|
||||
if (app_var.goto_poweroff_flag) {
|
||||
return 0;
|
||||
}
|
||||
int is_remote_test = bt_get_remote_test_flag();
|
||||
|
||||
switch (event->event) {
|
||||
case HCI_EVENT_VENDOR_NO_RECONN_ADDR:
|
||||
break;
|
||||
case HCI_EVENT_DISCONNECTION_COMPLETE :
|
||||
if (event->value == ERROR_CODE_CONNECTION_TIMEOUT) {
|
||||
printf("dual_conn ERROR_CODE_CONNECTION_TIMEOUT");
|
||||
put_buf(event->args, 7);
|
||||
if (is_remote_test == 0) {
|
||||
dual_conn_bt_connect_timeout(event);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case HCI_EVENT_CONNECTION_COMPLETE:
|
||||
switch (event->value) {
|
||||
case ERROR_CODE_SUCCESS :
|
||||
if (g_dual_conn.timer) {
|
||||
sys_timeout_del(g_dual_conn.timer);
|
||||
g_dual_conn.timer = 0;
|
||||
}
|
||||
del_device_from_page_list(event->args);
|
||||
return 0;
|
||||
case ERROR_CODE_CONNECTION_REJECTED_DUE_TO_UNACCEPTABLE_BD_ADDR:
|
||||
case ERROR_CODE_CONNECTION_ACCEPT_TIMEOUT_EXCEEDED:
|
||||
case ERROR_CODE_CONNECTION_REJECTED_DUE_TO_LIMITED_RESOURCES:
|
||||
if (!list_empty(&g_dual_conn.page_head)) {
|
||||
struct page_device_info *info;
|
||||
info = list_first_entry(&g_dual_conn.page_head,
|
||||
struct page_device_info, entry);
|
||||
list_del(&info->entry);
|
||||
list_add_tail(&info->entry, &g_dual_conn.page_head);
|
||||
}
|
||||
break;
|
||||
case ERROR_CODE_PIN_OR_KEY_MISSING:
|
||||
case ERROR_CODE_SYNCHRONOUS_CONNECTION_LIMIT_TO_A_DEVICE_EXCEEDED :
|
||||
case ERROR_CODE_REMOTE_USER_TERMINATED_CONNECTION:
|
||||
case ERROR_CODE_CONNECTION_TERMINATED_BY_LOCAL_HOST :
|
||||
case ERROR_CODE_AUTHENTICATION_FAILURE :
|
||||
break;
|
||||
case ERROR_CODE_PAGE_TIMEOUT:
|
||||
break;
|
||||
case ERROR_CODE_CONNECTION_TIMEOUT:
|
||||
printf("dual_conn ERROR_CODE_CONNECTION_TIMEOUT 2");
|
||||
put_buf(event->args, 7);
|
||||
dual_conn_bt_connect_timeout(event);
|
||||
break;
|
||||
case ERROR_CODE_ACL_CONNECTION_ALREADY_EXISTS :
|
||||
if (is_remote_test == 0) {
|
||||
add_device_2_page_list(event->args, TCFG_BT_TIMEOUT_PAGE_TIME * 1000);
|
||||
if (g_dual_conn.timer) {
|
||||
sys_timeout_del(g_dual_conn.timer);
|
||||
g_dual_conn.timer = 0;
|
||||
}
|
||||
dual_conn_page_device();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
g_dual_conn.page_scan_auto_disable = 0;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (memcmp(event->args, g_dual_conn.remote_addr[i], 6) == 0) {
|
||||
memset(g_dual_conn.remote_addr[i], 0xff, 6);
|
||||
g_dual_conn.remote_type[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
dual_conn_state_handler();
|
||||
|
||||
return 0;
|
||||
}
|
||||
APP_MSG_HANDLER(dual_conn_hci_msg_entry) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_BT_HCI,
|
||||
.handler = dual_conn_hci_event_handler,
|
||||
};
|
||||
|
||||
static void page_device_msg_handler()
|
||||
{
|
||||
u8 mac_addr[6];
|
||||
struct page_device_info *info;
|
||||
int device_num = bt_get_total_connect_dev();
|
||||
|
||||
if (!g_dual_conn.page_head_inited) {
|
||||
return;
|
||||
}
|
||||
|
||||
list_for_each_entry(info, &g_dual_conn.page_head, entry) {
|
||||
device_num++;
|
||||
}
|
||||
if (device_num >= 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
int num = btstack_get_num_of_remote_device_recorded();
|
||||
for (int i = num - 1; i >= 0; i--) {
|
||||
btstack_get_remote_addr(mac_addr, i);
|
||||
if (memcmp(mac_addr, g_dual_conn.remote_addr[0], 6) == 0) {
|
||||
continue;
|
||||
}
|
||||
if (memcmp(mac_addr, g_dual_conn.remote_addr[1], 6) == 0) {
|
||||
continue;
|
||||
}
|
||||
int ret = add_device_2_page_list(mac_addr, TCFG_BT_POWERON_PAGE_TIME * 1000);
|
||||
if (ret == 0) {
|
||||
if (++device_num >= 2) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (g_dual_conn.timer) {
|
||||
sys_timeout_del(g_dual_conn.timer);
|
||||
g_dual_conn.timer = 0;
|
||||
}
|
||||
write_scan_conn_enable(0, 0);
|
||||
dual_conn_page_device();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int dual_conn_app_event_handler(int *msg)
|
||||
{
|
||||
switch (msg[0]) {
|
||||
case APP_MSG_BT_PAGE_DEVICE:
|
||||
page_device_msg_handler();
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
APP_MSG_HANDLER(dual_conn_app_msg_entry) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_APP,
|
||||
.handler = dual_conn_app_event_handler,
|
||||
};
|
||||
|
||||
|
||||
void dual_conn_close()
|
||||
{
|
||||
if (g_dual_conn.timer) {
|
||||
sys_timeout_del(g_dual_conn.timer);
|
||||
g_dual_conn.timer = 0;
|
||||
}
|
||||
#if TCFG_DUAL_CONN_INQUIRY_SCAN_TIME
|
||||
if (g_dual_conn.close_inquiry_scan_timer) {
|
||||
sys_timeout_del(g_dual_conn.close_inquiry_scan_timer);
|
||||
g_dual_conn.close_inquiry_scan_timer = 0;
|
||||
}
|
||||
#endif
|
||||
clr_device_in_page_list();
|
||||
write_scan_conn_enable(0, 0);
|
||||
bt_cmd_prepare(USER_CTRL_PAGE_CANCEL, 0, NULL);
|
||||
}
|
||||
|
||||
bool check_page_mode_active(void)
|
||||
{
|
||||
return (page_mode_active) ? TRUE : FALSE;
|
||||
}
|
||||
#endif
|
||||
#endif /* #if TCFG_APP_BT_EN */
|
||||
@@ -0,0 +1,731 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".kws_voice_event_deal.data.bss")
|
||||
#pragma data_seg(".kws_voice_event_deal.data")
|
||||
#pragma const_seg(".kws_voice_event_deal.text.const")
|
||||
#pragma code_seg(".kws_voice_event_deal.text")
|
||||
#endif
|
||||
#include "event.h"
|
||||
#include "app_config.h"
|
||||
#include "btstack/avctp_user.h"
|
||||
#include "asr/kws_event.h"
|
||||
#include "key_driver.h"
|
||||
#include "app_msg.h"
|
||||
#include "bt_key_func.h"
|
||||
#include "ui/ui_api.h"
|
||||
#include "jlui_app/ui_sys_param.h"
|
||||
#include "app_mode_manager/app_mode_manager.h"
|
||||
#include "app_task.h"
|
||||
#include "esco_player.h"
|
||||
#include "app_common.h"
|
||||
#include "music/music_player.h"
|
||||
#include "media/file_decoder.h"
|
||||
#include "data_storage.h"
|
||||
#include "audio_config.h"
|
||||
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
#include "bt_tws.h"
|
||||
#endif
|
||||
#if TCFG_AUDIO_ANC_ENABLE
|
||||
#include "audio_anc.h"
|
||||
#endif/*TCFG_AUDIO_ANC_ENABLE*/
|
||||
|
||||
#define LOG_TAG "[KWS_VOICE_EVENT]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
#define LOG_CLI_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
#if ((defined TCFG_KWS_VOICE_EVENT_HANDLE_ENABLE) && (TCFG_KWS_VOICE_EVENT_HANDLE_ENABLE))
|
||||
|
||||
#define KWS_CHECK_EVENT BIT(0)
|
||||
#define KWS_CHECK_ID BIT(1)
|
||||
#define KWS_CHECK_MODE BIT(2)
|
||||
#define KWS_CHECK_BT BIT(3)
|
||||
#define KWS_CHECK_PHONE_BT BIT(4)
|
||||
#define KWS_CHECK_UI BIT(5)
|
||||
|
||||
#define KWS_EVENT_ERR_CHECK_EVENT (-1)
|
||||
#define KWS_EVENT_ERR_CHECK_ID (-2)
|
||||
#define KWS_EVENT_ERR_CHECK_MODE (-3)
|
||||
#define KWS_EVENT_ERR_CHECK_BT (-4)
|
||||
#define KWS_EVENT_ERR_CHECK_UI (-5)
|
||||
#define KWS_EVENT_ERR_UI_SHOW (-6)
|
||||
|
||||
|
||||
extern u8 is_bredr_close();
|
||||
extern void bt_init_bredr();
|
||||
extern void bredr_conn_last_dev();
|
||||
extern void bt_close_bredr();
|
||||
extern void set_call_log_type(u8 type);
|
||||
|
||||
extern int music_pp(void);
|
||||
extern int music_prev(void);
|
||||
extern int music_next(void);
|
||||
|
||||
extern void volume_up();
|
||||
extern void volume_down();
|
||||
extern void volume_set(u8 vol);
|
||||
|
||||
extern int watch_set_style(int style);
|
||||
extern int watch_get_items_num();
|
||||
extern char *watch_get_item(int style);
|
||||
extern int watch_version_juge(char *watch_item);
|
||||
extern int watch_get_style();
|
||||
|
||||
extern void kws_hold_time_enable(void);
|
||||
extern int bt_must_work(void);
|
||||
extern void music_set_start_auto_play(u8 on);
|
||||
extern u8 create_control_by_menu_set(u8 en);
|
||||
extern void ui_auto_shut_down_re_run(void);
|
||||
extern void setting_write_UIInfo_to_vm(void *info);
|
||||
extern void save_ui_info_to_vm();
|
||||
|
||||
static int kws_event_common_deal(u16 event, u32 id);
|
||||
static int kws_event_app_list_deal(u16 event, u32 id);
|
||||
static int kws_event_music_deal(u16 event, u32 id);
|
||||
static int kws_event_call_deal(u16 event, u32 id);
|
||||
static int kws_event_volume_deal(u16 event, u32 id);
|
||||
static int kws_event_brightness_deal(u16 event, u32 id);
|
||||
static int kws_event_bt_setting_deal(u16 event, u32 id);
|
||||
static int kws_event_start_photos_deal(u16 event, u32 id);
|
||||
static int kws_event_switch_dial_deal(u16 event, u32 id);
|
||||
static int kws_event_switch_style_deal(u16 event, u32 id);
|
||||
static int kws_event_ui_show_ID(u32 id, u8 checkid);
|
||||
|
||||
extern int UIInfo_w_vm_timer;
|
||||
|
||||
struct jl_kws_event_hdl {
|
||||
u32 last_event;
|
||||
u32 last_event_jiffies;
|
||||
u32 last_ui_id;
|
||||
};
|
||||
|
||||
static struct jl_kws_event_hdl kws_hdl = {
|
||||
.last_event = 0,
|
||||
.last_event_jiffies = 0,
|
||||
.last_ui_id = 0,
|
||||
};
|
||||
|
||||
#define __this (&kws_hdl)
|
||||
|
||||
|
||||
struct jl_kws_event_ui_key {
|
||||
u16 event; // 事件
|
||||
u32 ui_id; // UI界面
|
||||
int (*deal)(u16 event, u32 ui_id); // 执行处理
|
||||
};
|
||||
|
||||
#if (defined(CONFIG_UI_STYLE_JL_PUBLIC_MODLS_ENABLE) || defined(CONFIG_UI_STYLE_JL_CSC_PUBLIC_MODLS_ENABLE))
|
||||
static const struct jl_kws_event_ui_key kws_event_tab[] = {
|
||||
/*音乐关键词*/
|
||||
{KWS_EVENT_PLAY_MUSIC, ID_WINDOW_MUSIC_PLAYER, kws_event_music_deal},
|
||||
{KWS_EVENT_STOP_MUSIC, 0, kws_event_music_deal},
|
||||
{KWS_EVENT_PAUSE_MUSIC, 0, kws_event_music_deal},
|
||||
{KWS_EVENT_PREV_SONG, 0, kws_event_music_deal},
|
||||
{KWS_EVENT_NEXT_SONG, 0, kws_event_music_deal},
|
||||
|
||||
/*通话关键词*/
|
||||
{KWS_EVENT_CALL_ACTIVE, 0, kws_event_call_deal},
|
||||
{KWS_EVENT_CALL_HANGUP, 0, kws_event_call_deal},
|
||||
|
||||
/*音量关键词*/
|
||||
{KWS_EVENT_VOLUME_UP, 0, kws_event_volume_deal},
|
||||
{KWS_EVENT_VOLUME_DOWN, 0, kws_event_volume_deal},
|
||||
{KWS_EVENT_VOLUME_MUTE, 0, kws_event_volume_deal},
|
||||
{KWS_EVENT_VOLUME_UNMUTE, 0, kws_event_volume_deal},
|
||||
{KWS_EVENT_VOLUME_MAX, 0, kws_event_volume_deal},
|
||||
|
||||
/*亮度调整关键词*/
|
||||
{KWS_EVENT_BRIGHTNESS_ALWAYS, 0, kws_event_brightness_deal},
|
||||
{KWS_EVENT_BRIGHTNESS_UP, 0, kws_event_brightness_deal},
|
||||
{KWS_EVENT_BRIGHTNESS_DOWN, 0, kws_event_brightness_deal},
|
||||
{KWS_EVENT_BRIGHTNESS_AUTO, 0, kws_event_brightness_deal},
|
||||
|
||||
/*健康测量关键词*/
|
||||
{KWS_EVENT_DETECTION_HEART, ID_WINDOW_HEART, kws_event_common_deal},
|
||||
{KWS_EVENT_DETECTION_OXYGEN, ID_WINDOW_OXYGEN, kws_event_common_deal},
|
||||
|
||||
/*蓝牙应用关键词*/
|
||||
{KWS_EVENT_OPEN_EDR, 0, kws_event_bt_setting_deal},
|
||||
{KWS_EVENT_FIND_PHONE, ID_WINDOW_FINDPHONE, kws_event_common_deal},
|
||||
{KWS_EVENT_START_PHOTOS, ID_WINDOW_PHOTOGRAGH, kws_event_common_deal},
|
||||
|
||||
/*表盘应用关键词*/
|
||||
{KWS_EVENT_SWITCH_DIAL, ID_WINDOW_DIAL, kws_event_switch_dial_deal},
|
||||
{KWS_EVENT_SWITCH_STYLE, 0, kws_event_switch_style_deal},
|
||||
|
||||
/*记录查看关键词*/
|
||||
{KWS_EVENT_SEE_SPORT_RECORD, ID_WINDOW_SPORT_RESULT, kws_event_common_deal},
|
||||
{KWS_EVENT_SEE_ACTION_RECORD, ID_WINDOW_MOMENTUM, kws_event_common_deal},
|
||||
{KWS_EVENT_SEE_SLEEP_RECORD, ID_WINDOW_SLEEP, kws_event_common_deal},
|
||||
{KWS_EVENT_SEE_CALL_REDORD, ID_WINDOW_PHONE, kws_event_common_deal},
|
||||
{KWS_EVENT_SEE_TRAIN_RECORD, ID_WINDOW_SPORTING, kws_event_common_deal},
|
||||
{KWS_EVENT_SEE_HEAT, ID_WINDOW_HEAT, kws_event_common_deal},
|
||||
|
||||
/*打开功能页面关键词*/
|
||||
{KWS_EVENT_OPEN_SPORT, ID_WINDOW_OUTDOOR_SPORTS, kws_event_common_deal},
|
||||
{KWS_EVENT_OPEN_TRAIN, ID_WINDOW_SPORT_TARGET, kws_event_common_deal},
|
||||
{KWS_EVENT_OPEN_CALCULAGRAPH, ID_WINDOW_TIMER, kws_event_common_deal},
|
||||
{KWS_EVENT_OPEN_CALL_DIAL, ID_WINDOW_PHONE_KEYPAD, kws_event_common_deal},
|
||||
{KWS_EVENT_OPEN_PHONEBOOK, ID_WINDOW_PHONE, kws_event_common_deal},
|
||||
{KWS_EVENT_OPEN_ALARM, ID_WINDOW_ALARM, kws_event_common_deal},
|
||||
{KWS_EVENT_OPEN_STOPWATCH, ID_WINDOW_STOPWATCH, kws_event_common_deal},
|
||||
{KWS_EVENT_OPEN_WEATHER, ID_WINDOW_WEATHER, kws_event_common_deal},
|
||||
{KWS_EVENT_OPEN_MESS, ID_WINDOW_NOTICE, kws_event_common_deal},
|
||||
{KWS_EVENT_OPEN_SET, ID_WINDOW_SETTING, kws_event_common_deal},
|
||||
{KWS_EVENT_OPEN_APP_LIST, 0, kws_event_app_list_deal},
|
||||
{KWS_EVENT_OPEN_BREATH_TRAIN, ID_WINDOW_BREATH_TRAIN, kws_event_common_deal},
|
||||
{KWS_EVENT_OPEN_BARO, 0, kws_event_common_deal},
|
||||
{KWS_EVENT_OPEN_COMPASS, ID_WINDOW_COMPASS, kws_event_common_deal},
|
||||
{KWS_EVENT_OPEN_CARD_BAG, 0, kws_event_common_deal},
|
||||
{KWS_EVENT_OPEN_ALIPAY, ID_WINDOW_ALIPAY, kws_event_common_deal},
|
||||
{KWS_EVENT_OPEN_FLASHLIGHT, ID_WINDOW_FLASHLIGHT, kws_event_common_deal},
|
||||
{KWS_EVENT_OPEN_CALENDAR, ID_WINDOW_CALENDAR, kws_event_common_deal},
|
||||
{KWS_EVENT_OPEN_CALCULATOR, ID_WINDOW_CALCULATOR, kws_event_common_deal},
|
||||
|
||||
{0, 0, 0},
|
||||
};
|
||||
#else
|
||||
static const struct jl_kws_event_ui_key kws_event_tab[] = {
|
||||
};
|
||||
#endif
|
||||
static int kws_get_event_index(u16 event)
|
||||
{
|
||||
int index = -1;
|
||||
for (int i = 0; i < ARRAY_SIZE(kws_event_tab); i++) {
|
||||
if (kws_event_tab[i].event == event) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
static int kws_admittance_check_mode(void)
|
||||
{
|
||||
u8 cur_task = app_get_current_mode_name();
|
||||
switch (cur_task) {
|
||||
case APP_MODE_POWERON:
|
||||
case APP_MODE_UPDATE:
|
||||
case APP_MODE_SMARTBOX:
|
||||
// 这些模式不支持跳转
|
||||
log_e("cur task:%d no support swtich \n", cur_task);
|
||||
return false;
|
||||
/* break; */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int kws_admittance_check_phone_bt(void)
|
||||
{
|
||||
if (bt_must_work()) {
|
||||
log_e("phone bt busy \n");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int kws_admittance_check_bt(void)
|
||||
{
|
||||
if (esco_player_runing()) {
|
||||
log_e("bt busy \n");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int kws_admittance_check_ui(void)
|
||||
{
|
||||
if (UI_WINDOW_PREEMPTION_CHECK()) {
|
||||
log_e("ui busy \n");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int kws_admittance_check(u16 event, u32 id, u32 check_type)
|
||||
{
|
||||
int index = 0;
|
||||
if (check_type & KWS_CHECK_EVENT) {
|
||||
index = kws_get_event_index(event);
|
||||
if (index < 0) {
|
||||
log_e("event index err \n");
|
||||
return KWS_EVENT_ERR_CHECK_EVENT;
|
||||
}
|
||||
}
|
||||
if ((check_type & KWS_CHECK_ID) && (id == 0)) {
|
||||
return KWS_EVENT_ERR_CHECK_ID;
|
||||
}
|
||||
if ((check_type & KWS_CHECK_MODE) && (!kws_admittance_check_mode())) {
|
||||
return KWS_EVENT_ERR_CHECK_MODE;
|
||||
}
|
||||
if ((check_type & KWS_CHECK_BT) && (!kws_admittance_check_bt())) {
|
||||
return KWS_EVENT_ERR_CHECK_BT;
|
||||
}
|
||||
if ((check_type & KWS_CHECK_PHONE_BT) && (!kws_admittance_check_phone_bt())) {
|
||||
return KWS_EVENT_ERR_CHECK_BT;
|
||||
}
|
||||
if (((check_type & KWS_CHECK_UI) && !kws_admittance_check_ui())) {
|
||||
return KWS_EVENT_ERR_CHECK_UI;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
static void kws_event_ui_show_push(int (*callback)(int))
|
||||
{
|
||||
int argv[3];
|
||||
argv[0] = (int)callback;
|
||||
argv[1] = 1;
|
||||
argv[2] = (int)0;
|
||||
os_taskq_post_type("ui", Q_CALLBACK, ARRAY_SIZE(argv), argv);
|
||||
}
|
||||
|
||||
#if (defined(CONFIG_UI_STYLE_JL_PUBLIC_MODLS_ENABLE) || defined(CONFIG_UI_STYLE_JL_CSC_PUBLIC_MODLS_ENABLE))
|
||||
static int kws_event_ui_show_ID(u32 id, u8 checkid)
|
||||
{
|
||||
if (__this->last_ui_id) {
|
||||
UI_WINDOW_BACK_DEL(__this->last_ui_id);
|
||||
}
|
||||
__this->last_ui_id = id;
|
||||
|
||||
if (get_screen_saver_status()) {
|
||||
/* ui_screen_recover(0); */
|
||||
ui_auto_shut_down_enable();
|
||||
/* UI_HIDE_CURR_WINDOW(); */
|
||||
if (id == ID_WINDOW_NOTICE) {
|
||||
create_control_by_menu_set(1);
|
||||
}
|
||||
UI_SHOW_WINDOW(id);
|
||||
} else {
|
||||
ui_auto_shut_down_re_run();
|
||||
if ((UI_GET_WINDOW_ID() != id) || (!checkid)) {
|
||||
UI_HIDE_CURR_WINDOW();
|
||||
if (id == ID_WINDOW_NOTICE) {
|
||||
create_control_by_menu_set(1);
|
||||
}
|
||||
UI_SHOW_WINDOW(id);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
static int kws_event_ui_show_ID(u32 id, u8 checkid)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int kws_event_common_deal(u16 event, u32 id)
|
||||
{
|
||||
int ret = kws_admittance_check(event, id, KWS_CHECK_ID | KWS_CHECK_MODE | KWS_CHECK_BT | KWS_CHECK_UI);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
kws_event_ui_show_ID(id, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int kws_event_app_list_deal(u16 event, u32 id)
|
||||
{
|
||||
int ret = kws_admittance_check(event, id, KWS_CHECK_MODE | KWS_CHECK_BT | KWS_CHECK_UI);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
if (false == ui_check_list_tyep(UI_GET_WINDOW_ID())) {
|
||||
ret = ui_show_menu_page();
|
||||
if (ret == false) {
|
||||
return KWS_EVENT_ERR_UI_SHOW;
|
||||
}
|
||||
ui_auto_shut_down_re_run();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int kws_event_music_deal(u16 event, u32 id)
|
||||
{
|
||||
int ret = kws_admittance_check(event, id, KWS_CHECK_MODE | KWS_CHECK_BT | KWS_CHECK_PHONE_BT);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
u8 cur_task = app_get_curr_task();
|
||||
if (0) {
|
||||
#if TCFG_APP_MUSIC_EN
|
||||
} else if (cur_task == APP_MUSIC_TASK) {
|
||||
switch (event) {
|
||||
case KWS_EVENT_PLAY_MUSIC:
|
||||
if (music_player_get_play_status() != FILE_DEC_STATUS_PLAY) {
|
||||
app_send_message(APP_MSG_MUSIC_PP, 0);
|
||||
}
|
||||
break;
|
||||
case KWS_EVENT_STOP_MUSIC:
|
||||
case KWS_EVENT_PAUSE_MUSIC:
|
||||
if (music_player_get_play_status() == FILE_DEC_STATUS_PLAY) {
|
||||
app_send_message(APP_MSG_MUSIC_PP, 0);
|
||||
}
|
||||
break;
|
||||
case KWS_EVENT_PREV_SONG:
|
||||
app_send_message(APP_MSG_MUSIC_PREV, 0);
|
||||
break;
|
||||
case KWS_EVENT_NEXT_SONG:
|
||||
app_send_message(APP_MSG_MUSIC_NEXT, 0);
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
#endif /* #if TCFG_APP_MUSIC_EN */
|
||||
} else if (cur_task == APP_BT_TASK) {
|
||||
u8 a2dp_state = bt_a2dp_get_status();
|
||||
switch (event) {
|
||||
case KWS_EVENT_PLAY_MUSIC:
|
||||
if (a2dp_state != BT_MUSIC_STATUS_STARTING) {
|
||||
#if TCFG_APP_MUSIC_EN
|
||||
if (bt_get_connect_status() == BT_STATUS_WAITINT_CONN) {
|
||||
log_info("switch music mode\n");
|
||||
music_set_start_auto_play(1);
|
||||
app_task_switch_to(APP_MODE_MUSIC, 0);
|
||||
break;
|
||||
}
|
||||
#endif /* #if TCFG_APP_MUSIC_EN */
|
||||
log_info("send PLAY cmd\n");
|
||||
bt_cmd_prepare(USER_CTRL_AVCTP_OPID_PLAY, 0, NULL);
|
||||
}
|
||||
break;
|
||||
case KWS_EVENT_STOP_MUSIC:
|
||||
if (a2dp_state == BT_MUSIC_STATUS_STARTING) {
|
||||
log_info("send STOP cmd\n");
|
||||
bt_cmd_prepare(USER_CTRL_AVCTP_OPID_STOP, 0, NULL);
|
||||
}
|
||||
break;
|
||||
case KWS_EVENT_PAUSE_MUSIC:
|
||||
if (a2dp_state == BT_MUSIC_STATUS_STARTING) {
|
||||
log_info("send PAUSE cmd\n");
|
||||
bt_cmd_prepare(USER_CTRL_AVCTP_OPID_PAUSE, 0, NULL);
|
||||
}
|
||||
break;
|
||||
case KWS_EVENT_PREV_SONG:
|
||||
log_info("Send PREV cmd");
|
||||
bt_cmd_prepare(USER_CTRL_AVCTP_OPID_PREV, 0, NULL);
|
||||
break;
|
||||
case KWS_EVENT_NEXT_SONG:
|
||||
log_info("Send NEXT cmd");
|
||||
bt_cmd_prepare(USER_CTRL_AVCTP_OPID_NEXT, 0, NULL);
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (event == KWS_EVENT_PLAY_MUSIC) {
|
||||
#if TCFG_APP_MUSIC_EN
|
||||
if (app_get_current_mode_name() == APP_MODE_BT) {
|
||||
log_info("switch music mode\n");
|
||||
music_set_start_auto_play(1);
|
||||
app_task_switch_to(APP_MODE_MUSIC, 0);
|
||||
}
|
||||
#endif /* #if TCFG_APP_MUSIC_EN */
|
||||
if (app_get_current_mode_name() == APP_MODE_MUSIC) {
|
||||
log_info("switch bt mode, send PLAY cmd\n");
|
||||
app_task_switch_to(APP_MODE_BT, 0);
|
||||
bt_cmd_prepare(USER_CTRL_AVCTP_OPID_PLAY, 0, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((event == KWS_EVENT_PLAY_MUSIC) && id) {
|
||||
ret = kws_admittance_check(event, id, KWS_CHECK_UI);
|
||||
if (ret == 0) {
|
||||
kws_event_ui_show_ID(id, 1);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int kws_event_call_deal(u16 event, u32 id)
|
||||
{
|
||||
int ret = kws_admittance_check(event, id, KWS_CHECK_MODE);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
switch (event) {
|
||||
case KWS_EVENT_CALL_ACTIVE:
|
||||
if (bt_get_call_status() == BT_CALL_INCOMING) {
|
||||
log_info("Send ANSWER cmd");
|
||||
call_ctrl_answer();
|
||||
}
|
||||
break;
|
||||
|
||||
case KWS_EVENT_CALL_HANGUP:
|
||||
log_info("Send HANG UP cmd");
|
||||
if ((bt_get_call_status() >= BT_CALL_INCOMING) && (bt_get_call_status() <= BT_CALL_ALERT)) {
|
||||
small_file_call_log_set_type(CALL_INCOME_REJECT);
|
||||
call_ctrl_hangup();
|
||||
}
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int kws_event_volume_deal(u16 event, u32 id)
|
||||
{
|
||||
/* int ret = kws_admittance_check(event, id, KWS_CHECK_MODE | KWS_CHECK_BT); */
|
||||
/* if (ret) { */
|
||||
/* return ret; */
|
||||
/* } */
|
||||
switch (event) {
|
||||
case KWS_EVENT_VOLUME_UP:
|
||||
log_info("volume up\n");
|
||||
volume_up();
|
||||
break;
|
||||
case KWS_EVENT_VOLUME_DOWN:
|
||||
log_info("volume down\n");
|
||||
volume_down();
|
||||
break;
|
||||
case KWS_EVENT_VOLUME_MUTE:
|
||||
log_info("volume mute\n");
|
||||
if (!ui_get_voice_mute()) {
|
||||
ui_set_voice_mute(1);
|
||||
}
|
||||
break;
|
||||
case KWS_EVENT_VOLUME_UNMUTE:
|
||||
log_info("volume unmute\n");
|
||||
if (ui_get_voice_mute()) {
|
||||
ui_set_voice_mute(0);
|
||||
}
|
||||
break;
|
||||
case KWS_EVENT_VOLUME_MAX:
|
||||
log_info("volume max\n");
|
||||
app_audio_set_volume(APP_AUDIO_STATE_WTONE, app_audio_volume_max_query(SysVol_TONE), 1);
|
||||
#if (defined(CONFIG_UI_STYLE_JL_PUBLIC_MODLS_ENABLE) || defined(CONFIG_UI_STYLE_JL_CSC_PUBLIC_MODLS_ENABLE))
|
||||
set_ui_sys_param(LastSysVol, 100);
|
||||
save_ui_info_to_vm();
|
||||
#endif
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int kws_event_brightness_deal(u16 event, u32 id)
|
||||
{
|
||||
int level;
|
||||
/* int ret = kws_admittance_check(event, id, KWS_CHECK_MODE | KWS_CHECK_BT); */
|
||||
/* if (ret) { */
|
||||
/* return ret; */
|
||||
/* } */
|
||||
switch (event) {
|
||||
case KWS_EVENT_BRIGHTNESS_ALWAYS:
|
||||
screen_light_alway_switch(1);
|
||||
break;
|
||||
case KWS_EVENT_BRIGHTNESS_UP:
|
||||
level = get_light_level();
|
||||
if (level < 10) {
|
||||
level ++;
|
||||
}
|
||||
set_ui_sys_param(LightLevel, level);
|
||||
ui_ajust_light(level);
|
||||
break;
|
||||
case KWS_EVENT_BRIGHTNESS_DOWN:
|
||||
level = get_light_level();
|
||||
if (level) {
|
||||
level--;
|
||||
}
|
||||
set_ui_sys_param(LightLevel, level);
|
||||
ui_ajust_light(level);
|
||||
break;
|
||||
case KWS_EVENT_BRIGHTNESS_AUTO:
|
||||
level = 10;
|
||||
set_ui_sys_param(LightLevel, level);
|
||||
ui_ajust_light(level);
|
||||
break;
|
||||
default :
|
||||
return 0;
|
||||
/* break; */
|
||||
}
|
||||
write_UIInfo_to_vm(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int kws_event_bt_setting_ui_reshow(int priv)
|
||||
{
|
||||
/* ui_pic_show_image_by_id(PIC_EDR_SWITCH, 1); */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int kws_event_bt_setting_deal(u16 event, u32 id)
|
||||
{
|
||||
/* int ret = kws_event_common_deal(event, id); */
|
||||
/* if (ret) { */
|
||||
/* return ret; */
|
||||
/* } */
|
||||
if (is_bredr_close()) {
|
||||
#if 1
|
||||
bredr_conn_last_dev();
|
||||
#else
|
||||
bt_init_bredr();
|
||||
#endif//自动回连
|
||||
/* ui_pic_show_image_by_id(PIC_EDR_SWITCH, 1); */
|
||||
kws_event_ui_show_push(kws_event_bt_setting_ui_reshow);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int kws_event_switch_dial_deal(u16 event, u32 id)
|
||||
{
|
||||
int ret = kws_admittance_check(event, id, KWS_CHECK_MODE);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
int items = watch_get_items_num();
|
||||
int sel_item = watch_get_style();
|
||||
sel_item ++;
|
||||
if (sel_item >= items) {
|
||||
sel_item = 0;
|
||||
}
|
||||
ret = watch_version_juge(watch_get_item(sel_item));
|
||||
if (ret != 0) {
|
||||
log_error("watch_version_juge err %d, %d\n", sel_item, ret);
|
||||
return KWS_EVENT_ERR_UI_SHOW;
|
||||
}
|
||||
ret = watch_set_style(sel_item);
|
||||
if (ret != true) {
|
||||
log_error("watch_set_style err %d\n", sel_item);
|
||||
return KWS_EVENT_ERR_UI_SHOW;
|
||||
}
|
||||
|
||||
ret = kws_admittance_check(event, id, KWS_CHECK_BT | KWS_CHECK_UI);
|
||||
if (ret == 0) {
|
||||
kws_event_ui_show_ID(id, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int kws_event_switch_style_deal(u16 event, u32 id)
|
||||
{
|
||||
int ret = kws_admittance_check(event, id, KWS_CHECK_MODE);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
u8 menu_style = get_ui_sys_param(MenuStyle);
|
||||
menu_style ++;
|
||||
if (menu_style > (ui_show_menu_total_num() - 1)) {
|
||||
menu_style = 0;
|
||||
}
|
||||
set_ui_sys_param(MenuStyle, menu_style);
|
||||
write_UIInfo_to_vm(NULL);
|
||||
ret = kws_admittance_check(event, id, KWS_CHECK_BT | KWS_CHECK_UI);
|
||||
if (ret == 0) {
|
||||
ret = ui_show_menu_page();
|
||||
if (ret == false) {
|
||||
return KWS_EVENT_ERR_UI_SHOW;
|
||||
}
|
||||
ui_auto_shut_down_re_run();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @brief: 关键词唤醒语音事件处理流程
|
||||
*
|
||||
* @param event: 系统事件
|
||||
*
|
||||
* @return : true: 处理该事件; false: 不处理该事件, 由
|
||||
*/
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
int jl_kws_voice_event_handle(int event)
|
||||
{
|
||||
u32 cur_jiffies = jiffies;
|
||||
u32 voice_event = event;
|
||||
|
||||
log_info("%s: event: %d", __func__, voice_event);
|
||||
|
||||
if (voice_event == __this->last_event) {
|
||||
if (jiffies_to_msecs(cur_jiffies - __this->last_event_jiffies) < 1000) {
|
||||
log_info("voice event %d same, ignore", voice_event);
|
||||
__this->last_event_jiffies = cur_jiffies;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
__this->last_event_jiffies = cur_jiffies;
|
||||
__this->last_event = voice_event;
|
||||
|
||||
switch (voice_event) {
|
||||
case KWS_EVENT_HEY_KEYWORD:
|
||||
case KWS_EVENT_XIAOJIE:
|
||||
//主唤醒词:
|
||||
log_info("send SIRI cmd");
|
||||
bt_cmd_prepare(USER_CTRL_HFP_GET_SIRI_OPEN, 0, NULL);
|
||||
break;
|
||||
|
||||
case KWS_EVENT_XIAODU:
|
||||
//主唤醒词:
|
||||
log_info("send SIRI cmd");
|
||||
bt_cmd_prepare(USER_CTRL_HFP_GET_SIRI_OPEN, 0, NULL);
|
||||
break;
|
||||
|
||||
#if TCFG_AUDIO_ANC_ENABLE
|
||||
case KWS_EVENT_ANC_ON:
|
||||
anc_mode_switch(ANC_ON, 1);
|
||||
break;
|
||||
case KWS_EVENT_TRANSARENT_ON:
|
||||
anc_mode_switch(ANC_TRANSPARENCY, 1);
|
||||
break;
|
||||
case KWS_EVENT_ANC_OFF:
|
||||
anc_mode_switch(ANC_OFF, 1);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case KWS_EVENT_NULL:
|
||||
log_info("KWS_EVENT_NULL");
|
||||
break;
|
||||
|
||||
default: {
|
||||
int index = kws_get_event_index(voice_event);
|
||||
if (index < 0) {
|
||||
log_error("event index err \n");
|
||||
break;
|
||||
}
|
||||
if (kws_event_tab[index].deal) {
|
||||
int ret = kws_event_tab[index].deal(voice_event, kws_event_tab[index].ui_id);
|
||||
log_info("event deal index:%d, ret:%d \n", index, ret);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static int kws_voice_event_msg_handler(int *msg)
|
||||
{
|
||||
int type = msg[0];
|
||||
|
||||
switch (type) {
|
||||
case APP_MSG_SMART_VOICE_EVENT:
|
||||
int event = msg[1];
|
||||
jl_kws_voice_event_handle(event);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
APP_MSG_HANDLER(kws_voice_event_msg_entry) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_APP,
|
||||
.handler = kws_voice_event_msg_handler,
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,91 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".low_latency.data.bss")
|
||||
#pragma data_seg(".low_latency.data")
|
||||
#pragma const_seg(".low_latency.text.const")
|
||||
#pragma code_seg(".low_latency.text")
|
||||
#endif
|
||||
#include "system/includes.h"
|
||||
#include "btstack/a2dp_media_codec.h"
|
||||
#include "a2dp_player.h"
|
||||
#include "app_tone.h"
|
||||
#include "low_latency.h"
|
||||
#include "app_config.h"
|
||||
|
||||
#if TCFG_APP_BT_EN
|
||||
#if(TCFG_USER_TWS_ENABLE == 0)
|
||||
|
||||
enum {
|
||||
API_ENTER_LOW_LATENCY,
|
||||
API_EXIT_LOW_LATENCY,
|
||||
API_RESTART_A2DP_DEC,
|
||||
};
|
||||
|
||||
static u8 low_latency_mode = 0;
|
||||
static u16 low_latency_timer = 0;
|
||||
static u8 g_btaddr[6];
|
||||
static void *g_a2dp_file = NULL;
|
||||
|
||||
static void get_a2dp_packet_timer(void *p)
|
||||
{
|
||||
struct a2dp_media_frame frame;
|
||||
|
||||
if (!g_a2dp_file) {
|
||||
return;
|
||||
}
|
||||
|
||||
int len = a2dp_media_try_get_packet(g_a2dp_file, &frame);
|
||||
if (len == 0) {
|
||||
return;
|
||||
}
|
||||
u16 seqn = (frame.packet[2] << 8) | frame.packet[3];
|
||||
int type = a2dp_media_get_codec_type(g_a2dp_file);
|
||||
if (type == A2DP_CODEC_SBC) {
|
||||
seqn += 200 / 15;
|
||||
} else {
|
||||
seqn += 200 / 20;
|
||||
}
|
||||
a2dp_media_clear_packet_before_seqn(g_a2dp_file, seqn);
|
||||
|
||||
if (!tone_player_runing()) {
|
||||
sys_timer_del(low_latency_timer);
|
||||
low_latency_timer = 0;
|
||||
a2dp_player_open(g_btaddr);
|
||||
}
|
||||
}
|
||||
|
||||
static void set_low_latency_mode(int enable)
|
||||
{
|
||||
if (low_latency_timer) {
|
||||
return;
|
||||
}
|
||||
|
||||
printf("set_low_latency: enable = %d\n", enable);
|
||||
|
||||
a2dp_player_low_latency_enable(enable);
|
||||
if (a2dp_player_runing()) {
|
||||
a2dp_player_get_btaddr(g_btaddr);
|
||||
a2dp_player_close(g_btaddr);
|
||||
g_a2dp_file = a2dp_open_media_file(g_btaddr);
|
||||
low_latency_timer = sys_timer_add(NULL, get_a2dp_packet_timer, 100);
|
||||
}
|
||||
|
||||
if (enable) {
|
||||
play_tone_file(get_tone_files()->low_latency_in);
|
||||
} else {
|
||||
play_tone_file(get_tone_files()->low_latency_out);
|
||||
}
|
||||
low_latency_mode = enable;
|
||||
}
|
||||
|
||||
void bt_set_low_latency_mode(int enable)
|
||||
{
|
||||
set_low_latency_mode(enable);
|
||||
}
|
||||
|
||||
int bt_get_low_latency_mode()
|
||||
{
|
||||
return low_latency_mode;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* #if TCFG_APP_BT_EN */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,183 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".poweroff.data.bss")
|
||||
#pragma data_seg(".poweroff.data")
|
||||
#pragma const_seg(".poweroff.text.const")
|
||||
#pragma code_seg(".poweroff.text")
|
||||
#endif
|
||||
#include "classic/hci_lmp.h"
|
||||
#include "btstack/avctp_user.h"
|
||||
|
||||
#include "app_config.h"
|
||||
#include "app_tone.h"
|
||||
#include "app_main.h"
|
||||
#include "bt.h"
|
||||
#include "a2dp_player.h"
|
||||
#include "esco_player.h"
|
||||
#include "idle.h"
|
||||
#include "app_charge.h"
|
||||
#include "bt_slience_detect.h"
|
||||
#include "poweroff.h"
|
||||
#include "bt_background.h"
|
||||
|
||||
#if(TCFG_USER_TWS_ENABLE == 0)
|
||||
|
||||
#define LOG_TAG "[POWEROFF]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
#define LOG_CLI_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
|
||||
|
||||
static u16 g_poweroff_timer = 0;
|
||||
static u16 g_bt_detach_timer = 0;
|
||||
|
||||
|
||||
static void sys_auto_shut_down_deal(void *priv);
|
||||
|
||||
|
||||
void sys_auto_shut_down_disable(void)
|
||||
{
|
||||
#if TCFG_AUTO_SHUT_DOWN_TIME
|
||||
log_info("sys_auto_shut_down_disable\n");
|
||||
if (g_poweroff_timer) {
|
||||
sys_timeout_del(g_poweroff_timer);
|
||||
g_poweroff_timer = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void sys_auto_shut_down_enable(void)
|
||||
{
|
||||
#if TCFG_AUTO_SHUT_DOWN_TIME
|
||||
#if TCFG_BT_BACKGROUND_ENABLE
|
||||
if (bt_background_active()) {
|
||||
log_info("sys_auto_shut_down_enable cannot in background\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
log_info("sys_auto_shut_down_enable\n");
|
||||
|
||||
if (g_poweroff_timer == 0) {
|
||||
g_poweroff_timer = sys_timeout_add(NULL, sys_auto_shut_down_deal,
|
||||
app_var.auto_off_time * 1000);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void sys_auto_shut_down_deal(void *priv)
|
||||
{
|
||||
sys_enter_soft_poweroff(POWEROFF_NORMAL);
|
||||
}
|
||||
|
||||
|
||||
static int poweroff_app_event_handler(int *msg)
|
||||
{
|
||||
switch (msg[0]) {
|
||||
case APP_MSG_BT_IN_PAIRING_MODE:
|
||||
if (msg[1] == 0) {
|
||||
sys_auto_shut_down_enable();
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
APP_MSG_HANDLER(poweroff_app_msg_entry) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_APP,
|
||||
.handler = poweroff_app_event_handler,
|
||||
};
|
||||
|
||||
|
||||
static int poweroff_btstack_event_handler(int *_event)
|
||||
{
|
||||
struct bt_event *bt = (struct bt_event *)_event;
|
||||
|
||||
switch (bt->event) {
|
||||
case BT_STATUS_SECOND_CONNECTED:
|
||||
case BT_STATUS_FIRST_CONNECTED:
|
||||
sys_auto_shut_down_disable();
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
APP_MSG_HANDLER(poweroff_btstack_msg_stub) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_BT_STACK,
|
||||
.handler = poweroff_btstack_event_handler,
|
||||
};
|
||||
|
||||
static void wait_exit_btstack_flag(void *_reason)
|
||||
{
|
||||
int reason = (int)_reason;
|
||||
#if TCFG_USER_BT_CLASSIC_ENABLE
|
||||
if (a2dp_player_runing() || esco_player_runing()) {
|
||||
if (++app_var.goto_poweroff_cnt > 200) {
|
||||
log_info("cpu_reset!!!\n");
|
||||
cpu_reset();
|
||||
}
|
||||
printf("wait_poweroff_cnt: %d\n", app_var.goto_poweroff_cnt);
|
||||
return ;
|
||||
}
|
||||
|
||||
lmp_hci_reset();
|
||||
os_time_dly(2);
|
||||
|
||||
#endif
|
||||
|
||||
sys_timer_del(g_bt_detach_timer);
|
||||
|
||||
switch (reason) {
|
||||
case POWEROFF_NORMAL:
|
||||
log_info("task_switch to idle...\n");
|
||||
app_send_message2(APP_MSG_GOTO_MODE, APP_MODE_IDLE, IDLE_MODE_PLAY_POWEROFF);
|
||||
break;
|
||||
case POWEROFF_RESET:
|
||||
log_info("cpu_reset!!!\n");
|
||||
cpu_reset();
|
||||
break;
|
||||
case POWEROFF_POWER_KEEP:
|
||||
#if TCFG_CHARGE_ENABLE
|
||||
app_charge_power_off_keep_mode();
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void sys_enter_soft_poweroff(enum poweroff_reason reason)
|
||||
{
|
||||
log_info("sys_enter_soft_poweroff: %d flag:%d \n", reason, app_var.goto_poweroff_flag);
|
||||
|
||||
if (app_var.goto_poweroff_flag) {
|
||||
return;
|
||||
}
|
||||
|
||||
app_var.goto_poweroff_flag = 1;
|
||||
app_var.goto_poweroff_cnt = 0;
|
||||
sys_auto_shut_down_disable();
|
||||
|
||||
#if TCFG_APP_BT_EN
|
||||
void bt_sniff_disable();
|
||||
bt_sniff_disable();
|
||||
#endif
|
||||
|
||||
#if TCFG_USER_BT_CLASSIC_ENABLE
|
||||
bt_stop_a2dp_slience_detect(NULL);
|
||||
#endif
|
||||
|
||||
app_send_message(APP_MSG_POWER_OFF, 0);
|
||||
|
||||
#if TCFG_USER_BT_CLASSIC_ENABLE
|
||||
bt_cmd_prepare(USER_CTRL_POWER_OFF, 0, NULL);
|
||||
#endif
|
||||
|
||||
#if (SYS_DEFAULT_VOL == 0)
|
||||
syscfg_write(CFG_SYS_VOL, &app_var.music_volume, 2);
|
||||
#endif
|
||||
|
||||
g_bt_detach_timer = sys_timer_add((void *)reason, wait_exit_btstack_flag, 50);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,247 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".sniff.data.bss")
|
||||
#pragma data_seg(".sniff.data")
|
||||
#pragma const_seg(".sniff.text.const")
|
||||
#pragma code_seg(".sniff.text")
|
||||
#endif
|
||||
#include "btstack/avctp_user.h"
|
||||
|
||||
#include "app_config.h"
|
||||
#include "app_main.h"
|
||||
#include "bt.h"
|
||||
#include "bt_tws.h"
|
||||
#if TCFG_AUDIO_ANC_ENABLE
|
||||
#include "audio_anc.h"
|
||||
#endif
|
||||
#if (RCSP_ADV_EN)
|
||||
#include "ble_rcsp_adv.h"
|
||||
#endif
|
||||
|
||||
#define LOG_TAG "[SNIFF]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
#define LOG_CLI_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
#if TCFG_APP_BT_EN
|
||||
|
||||
/*
|
||||
*以下情况,关闭sniff
|
||||
*(1)通过spp在线调试eq
|
||||
*(2)通过spp导出数据
|
||||
*/
|
||||
#if APP_ONLINE_DEBUG
|
||||
#if ((TCFG_AUDIO_DATA_EXPORT_DEFINE == AUDIO_DATA_EXPORT_VIA_SPP) || \
|
||||
TCFG_LP_TOUCH_KEY_BT_TOOL_ENABLE || USE_DMA_UART_TEST )
|
||||
/*!!! 不要使用MY_SNIFF_EN宏去控制sniff开关,这样会导致协议栈状态错误!!!*/
|
||||
static u8 sniff_enable = 0;
|
||||
#else
|
||||
static u8 sniff_enable = 1;
|
||||
#endif
|
||||
#else
|
||||
static u8 sniff_enable = 1;
|
||||
#endif
|
||||
|
||||
#define SNIFF_CNT_TIME TCFG_SNIFF_CHECK_TIME //空闲6S之后进入sniff模式
|
||||
#define SNIFF_MAX_INTERVALSLOT 800
|
||||
#define SNIFF_MIN_INTERVALSLOT 100
|
||||
#define SNIFF_ATTEMPT_SLOT 4
|
||||
#define SNIFF_TIMEOUT_SLOT 1
|
||||
|
||||
|
||||
u8 sniff_ready_status = 0; //0:sniff_ready 1:sniff_not_ready
|
||||
|
||||
bool bt_is_sniff_close(void)
|
||||
{
|
||||
return (g_bt_hdl.sniff_timer == 0);
|
||||
}
|
||||
|
||||
void bt_check_exit_sniff()
|
||||
{
|
||||
if (tws_api_get_role() == TWS_ROLE_SLAVE) {
|
||||
return;
|
||||
}
|
||||
bt_cmd_prepare(USER_CTRL_ALL_SNIFF_EXIT, 0, NULL);
|
||||
}
|
||||
|
||||
void bt_sniff_ready_clean(void)
|
||||
{
|
||||
sniff_ready_status = 1;
|
||||
}
|
||||
|
||||
void bt_check_enter_sniff()
|
||||
{
|
||||
u8 addr[12];
|
||||
#if TCFG_BT_SNIFF_ENABLE
|
||||
|
||||
#if TCFG_USER_EMITTER_ENABLE
|
||||
if (app_var.a2dp_source_open_flag) { // 如果蓝牙发射a2dp_tx模块开启则不进入SNIFF
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if TCFG_AUDIO_ANC_ENABLE
|
||||
if (anc_train_open_query() || anc_online_busy_get()) { //如果ANC训练则不进入SNIFF
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (RCSP_ADV_EN)
|
||||
if (get_ble_adv_modify() || get_ble_adv_notify()) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (sniff_ready_status) {
|
||||
sniff_ready_status = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
#if TCFG_BT_DUAL_CONN_ENABLE
|
||||
if (bt_get_esco_coder_busy_flag()) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (app_get_current_mode_name() == APP_MODE_UPDATE ||
|
||||
app_get_current_mode_name() == APP_MODE_RCSP) {
|
||||
return; // 传输的时候不进sniff
|
||||
}
|
||||
|
||||
struct sniff_ctrl_config_t config;
|
||||
int conn_cnt = bt_api_enter_sniff_status_check(SNIFF_CNT_TIME, addr);
|
||||
ASSERT(conn_cnt <= 2);
|
||||
for (int i = 0; i < conn_cnt; i++) {
|
||||
log_info("-----USER SEND SNIFF IN %d %d\n", i, conn_cnt);
|
||||
config.sniff_max_interval = SNIFF_MAX_INTERVALSLOT;
|
||||
config.sniff_mix_interval = SNIFF_MIN_INTERVALSLOT;
|
||||
config.sniff_attemp = SNIFF_ATTEMPT_SLOT;
|
||||
config.sniff_timeout = SNIFF_TIMEOUT_SLOT;
|
||||
memcpy(config.sniff_addr, addr + i * 6, 6);
|
||||
bt_cmd_prepare(USER_CTRL_SNIFF_IN, sizeof(config), (u8 *)&config);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void sys_auto_sniff_controle(u8 enable, u8 *addr)
|
||||
{
|
||||
if (addr) {
|
||||
if (bt_api_conn_mode_check(enable, addr) == 0) {
|
||||
log_info("sniff ctr not change\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (enable) {
|
||||
|
||||
if (!sniff_enable) {
|
||||
//sniff_enable为0时不启动定时器去检测进入sniff
|
||||
return;
|
||||
}
|
||||
|
||||
if (tws_api_get_role_async() == TWS_ROLE_SLAVE) {
|
||||
return;
|
||||
}
|
||||
if (g_bt_hdl.sniff_timer == 0) {
|
||||
log_info("check_sniff_enable\n");
|
||||
g_bt_hdl.sniff_timer = sys_timer_add(NULL, bt_check_enter_sniff, 1000);
|
||||
}
|
||||
} else {
|
||||
if (g_bt_hdl.sniff_timer) {
|
||||
log_info("check_sniff_disable\n");
|
||||
sys_timeout_del(g_bt_hdl.sniff_timer);
|
||||
g_bt_hdl.sniff_timer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void bt_sniff_enable()
|
||||
{
|
||||
sniff_enable = 1;
|
||||
sys_auto_sniff_controle(1, NULL);
|
||||
}
|
||||
|
||||
void bt_sniff_disable()
|
||||
{
|
||||
sys_auto_sniff_controle(0, NULL);
|
||||
bt_check_exit_sniff();
|
||||
sniff_enable = 0;
|
||||
}
|
||||
|
||||
void bt_sniff_feature_init()
|
||||
{
|
||||
#if TCFG_BT_SNIFF_ENABLE == 0
|
||||
u8 feature = lmp_hci_read_local_supported_features(0);
|
||||
feature &= ~BIT(7); //BIT_SNIFF_MODE;
|
||||
lmp_hci_write_local_supported_features(feature, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int sniff_btstack_event_handler(int *_event)
|
||||
{
|
||||
struct bt_event *bt = (struct bt_event *)_event;
|
||||
|
||||
switch (bt->event) {
|
||||
case BT_STATUS_SECOND_CONNECTED:
|
||||
case BT_STATUS_FIRST_CONNECTED:
|
||||
sys_auto_sniff_controle(1, bt->args);
|
||||
break;
|
||||
case BT_STATUS_SNIFF_STATE_UPDATE:
|
||||
log_info(" BT_STATUS_SNIFF_STATE_UPDATE %d\n", bt->value); //0退出SNIFF
|
||||
if (bt->value == 0) {
|
||||
sys_auto_sniff_controle(1, bt->args);
|
||||
app_send_message(APP_MSG_BT_EXIT_SNIFF, 0);
|
||||
} else {
|
||||
sys_auto_sniff_controle(0, bt->args);
|
||||
app_send_message(APP_MSG_BT_ENTER_SNIFF, 0);
|
||||
}
|
||||
break;
|
||||
case BT_STATUS_FIRST_DISCONNECT:
|
||||
case BT_STATUS_SECOND_DISCONNECT:
|
||||
sys_auto_sniff_controle(0, bt->args);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
APP_MSG_HANDLER(sniff_btstack_msg_stub) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_BT_STACK,
|
||||
.handler = sniff_btstack_event_handler,
|
||||
};
|
||||
|
||||
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
static int sniff_tws_event_handler(int *_event)
|
||||
{
|
||||
struct tws_event *event = (struct tws_event *)_event;
|
||||
int role = event->args[0];
|
||||
int reason = event->args[2];
|
||||
|
||||
if (app_var.goto_poweroff_flag) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (event->event) {
|
||||
case TWS_EVENT_CONNECTION_DETACH:
|
||||
break;
|
||||
case TWS_EVENT_ROLE_SWITCH:
|
||||
if (role == TWS_ROLE_MASTER) {
|
||||
sys_auto_sniff_controle(1, NULL);
|
||||
} else {
|
||||
sys_auto_sniff_controle(0, NULL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
APP_MSG_HANDLER(sniff_tws_msg_entry) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_TWS,
|
||||
.handler = sniff_tws_event_handler,
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,172 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".tone.data.bss")
|
||||
#pragma data_seg(".tone.data")
|
||||
#pragma const_seg(".tone.text.const")
|
||||
#pragma code_seg(".tone.text")
|
||||
#endif
|
||||
#include "btstack/avctp_user.h"
|
||||
#include "classic/tws_api.h"
|
||||
#include "app_main.h"
|
||||
#include "bt.h"
|
||||
#include "app_config.h"
|
||||
#include "bt_tws.h"
|
||||
#include "app_tone.h"
|
||||
#include "app_testbox.h"
|
||||
|
||||
#if TCFG_APP_BT_EN
|
||||
|
||||
#define TWS_DLY_DISCONN_TIME 0//2000 //TWS超时断开,快速连接上不播提示音
|
||||
|
||||
static u8 g_tws_connected = 0;
|
||||
static u16 tws_dly_discon_time = 0;
|
||||
|
||||
|
||||
static int tone_btstack_event_handler(int *_event)
|
||||
{
|
||||
struct bt_event *event = (struct bt_event *)_event;
|
||||
|
||||
switch (event->event) {
|
||||
case BT_STATUS_FIRST_CONNECTED:
|
||||
case BT_STATUS_SECOND_CONNECTED:
|
||||
#if TCFG_TEST_BOX_ENABLE
|
||||
if (testbox_get_status()) {
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 获取tws状态,如果正在播歌或打电话则返回1,不播连接成功提示音
|
||||
*/
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
if (tws_api_get_role() == TWS_ROLE_SLAVE) {
|
||||
break;
|
||||
}
|
||||
|
||||
int state = tws_api_get_lmp_state(event->args);
|
||||
if (state & TWS_STA_ESCO_OPEN) {
|
||||
break;
|
||||
}
|
||||
tws_play_tone_file(get_tone_files()->bt_connect, 400);
|
||||
#else
|
||||
play_tone_file(get_tone_files()->bt_connect);
|
||||
#endif
|
||||
break;
|
||||
case BT_STATUS_FIRST_DISCONNECT:
|
||||
case BT_STATUS_SECOND_DISCONNECT:
|
||||
/*
|
||||
* 关机、重启不播断开提示音
|
||||
*/
|
||||
if (app_var.goto_poweroff_flag || app_var.goto_reboot_flag) {
|
||||
break;
|
||||
}
|
||||
if (!g_bt_hdl.ignore_discon_tone) {
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
if (tws_api_get_role() == TWS_ROLE_SLAVE) {
|
||||
break;
|
||||
}
|
||||
tws_play_tone_file(get_tone_files()->bt_disconnect, 400);
|
||||
#else
|
||||
play_tone_file(get_tone_files()->bt_disconnect);
|
||||
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
APP_MSG_HANDLER(tone_stack_msg_entry) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_BT_STACK,
|
||||
.handler = tone_btstack_event_handler,
|
||||
};
|
||||
|
||||
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
|
||||
void tws_disconn_dly_deal(void *priv)
|
||||
{
|
||||
if (tws_dly_discon_time == 0) {
|
||||
return;
|
||||
}
|
||||
tws_dly_discon_time = 0;
|
||||
|
||||
if (app_var.goto_poweroff_flag) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!g_bt_hdl.ignore_discon_tone) {
|
||||
tone_player_stop();
|
||||
play_tone_file(get_tone_files()->tws_disconnect);
|
||||
}
|
||||
}
|
||||
|
||||
static int tone_tws_event_handler(int *_event)
|
||||
{
|
||||
struct tws_event *event = (struct tws_event *)_event;
|
||||
int role = event->args[0];
|
||||
int reason = event->args[2];
|
||||
|
||||
switch (event->event) {
|
||||
case TWS_EVENT_CONNECTED:
|
||||
g_tws_connected = 1;
|
||||
if (tws_dly_discon_time) {
|
||||
sys_timeout_del(tws_dly_discon_time);
|
||||
tws_dly_discon_time = 0;
|
||||
break;
|
||||
}
|
||||
tone_player_stop();
|
||||
if (role == TWS_ROLE_MASTER) {
|
||||
int state = tws_api_get_tws_state();
|
||||
if (state & (TWS_STA_SBC_OPEN | TWS_STA_ESCO_OPEN)) {
|
||||
break;
|
||||
}
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
tws_play_tone_file(get_tone_files()->tws_connect, 400);
|
||||
#else
|
||||
play_tone_file(get_tone_files()->tws_connect);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case TWS_EVENT_CONNECTION_DETACH:
|
||||
if (app_var.goto_poweroff_flag) {
|
||||
break;
|
||||
}
|
||||
if (!g_tws_connected) {
|
||||
break;
|
||||
}
|
||||
g_tws_connected = 0;
|
||||
|
||||
if (reason == (TWS_DETACH_BY_REMOTE | TWS_DETACH_BY_POWEROFF)) {
|
||||
break;
|
||||
}
|
||||
|
||||
#if TWS_DLY_DISCONN_TIME
|
||||
if (reason & TWS_DETACH_BY_SUPER_TIMEOUT) {
|
||||
tws_dly_discon_time = sys_timeout_add(NULL, tws_disconn_dly_deal,
|
||||
TWS_DLY_DISCONN_TIME);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if (!g_bt_hdl.ignore_discon_tone) {
|
||||
tone_player_stop();
|
||||
play_tone_file(get_tone_files()->tws_disconnect);
|
||||
}
|
||||
break;
|
||||
case TWS_EVENT_REMOVE_PAIRS:
|
||||
//play_tone_file(get_tone_files()->tws_disconnect);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
APP_MSG_HANDLER(tone_tws_msg_entry) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_TWS,
|
||||
.handler = tone_tws_event_handler,
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,392 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".app_default_msg_handler.data.bss")
|
||||
#pragma data_seg(".app_default_msg_handler.data")
|
||||
#pragma const_seg(".app_default_msg_handler.text.const")
|
||||
#pragma code_seg(".app_default_msg_handler.text")
|
||||
#endif
|
||||
#include "app_main.h"
|
||||
#include "init.h"
|
||||
#include "app_config.h"
|
||||
#include "app_default_msg_handler.h"
|
||||
#include "dev_status.h"
|
||||
#include "alarm.h"
|
||||
#include "idle.h"
|
||||
#include "audio_config.h"
|
||||
#include "app_tone.h"
|
||||
#include "ui/ui_api.h"
|
||||
#include "ui_manage.h"
|
||||
#include "scene_switch.h"
|
||||
#include "mic_effect.h"
|
||||
#include "bt.h"
|
||||
#include "node_param_update.h"
|
||||
#include "bass_treble.h"
|
||||
#include "usb/device/usb_stack.h"
|
||||
#include "asm/charge.h"
|
||||
#include "record.h"
|
||||
#include "mix_record_api.h"
|
||||
|
||||
static u32 input_number = 0;
|
||||
static u16 input_number_timer = 0;
|
||||
static void input_number_timeout(void *p)
|
||||
{
|
||||
#if TCFG_APP_MUSIC_EN
|
||||
input_number_timer = 0;
|
||||
printf("input_number = %d\n", input_number);
|
||||
if (app_in_mode(APP_MODE_MUSIC)) {
|
||||
app_send_message(APP_MSG_MUSIC_PLAY_BY_NUM, (int)input_number);
|
||||
}
|
||||
input_number = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void input_number_deal(u32 num)
|
||||
{
|
||||
#if TCFG_APP_MUSIC_EN
|
||||
input_number = input_number * 10 + num;
|
||||
if (input_number > 9999) {
|
||||
input_number = num;
|
||||
}
|
||||
printf("num = %d, input_number = %d, input_number_timer = %d\n", num, input_number, input_number_timer);
|
||||
if (input_number_timer == 0) {
|
||||
input_number_timer = sys_timeout_add(NULL, input_number_timeout, 1000);
|
||||
} else {
|
||||
sys_timer_modify(input_number_timer, 1000);
|
||||
}
|
||||
app_send_message(APP_MSG_INPUT_FILE_NUM, input_number);
|
||||
#endif
|
||||
}
|
||||
static u8 sys_audio_mute_statu = 0;//记录 audio dac mute
|
||||
|
||||
u8 get_sys_aduio_mute_statu(void)
|
||||
{
|
||||
return app_audio_get_dac_digital_mute();
|
||||
}
|
||||
void app_common_key_msg_handler(int *msg)
|
||||
{
|
||||
|
||||
|
||||
int from_tws = msg[1];
|
||||
|
||||
switch (msg[0]) {
|
||||
case APP_MSG_VOL_UP:
|
||||
app_audio_volume_up(1);
|
||||
if (app_audio_get_volume(APP_AUDIO_CURRENT_STATE) == app_audio_get_max_volume()) {
|
||||
if (tone_player_runing() == 0) {
|
||||
#if TCFG_MAX_VOL_PROMPT
|
||||
play_tone_file(get_tone_files()->max_vol);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
app_send_message(APP_MSG_VOL_CHANGED, app_audio_get_volume(APP_AUDIO_STATE_MUSIC));
|
||||
break;
|
||||
case APP_MSG_VOL_DOWN:
|
||||
app_audio_volume_down(1);
|
||||
app_send_message(APP_MSG_VOL_CHANGED, app_audio_get_volume(APP_AUDIO_STATE_MUSIC));
|
||||
break;
|
||||
#if AUD_MEDIA_EFx_SCENE_SWITCH_ENABLE
|
||||
case APP_MSG_SWITCH_SOUND_EFFECT:
|
||||
effect_scene_switch();
|
||||
break;
|
||||
#endif
|
||||
#if TCFG_MIC_EFFECT_ENABLE
|
||||
case APP_MSG_MIC_EFFECT_ON_OFF://混响开关
|
||||
|
||||
if (from_tws == APP_KEY_MSG_FROM_TWS) {
|
||||
break;
|
||||
}
|
||||
|
||||
#if TCFG_APP_BT_EN
|
||||
if (bt_get_call_status() != BT_CALL_HANGUP) {//通话中
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if (mic_effect_player_runing()) {
|
||||
mic_effect_player_close();
|
||||
} else {
|
||||
mic_effect_player_open();
|
||||
}
|
||||
break;
|
||||
#if AUD_MIC_EFx_SCENE_SWITCH_ENABLE
|
||||
case APP_MSG_SWITCH_MIC_EFFECT://混响音效场景切换
|
||||
mic_effect_scene_switch();
|
||||
break;
|
||||
#endif
|
||||
case APP_MSG_MIC_VOL_UP:
|
||||
mic_effect_dvol_up();
|
||||
break;
|
||||
case APP_MSG_MIC_VOL_DOWN:
|
||||
mic_effect_dvol_down();
|
||||
break;
|
||||
case APP_MSG_MIC_BASS_UP:
|
||||
puts("\n APP_MSG_MIC_BASS_UP \n");
|
||||
mic_bass_treble_eq_udpate("BassTreEff", BASS_TREBLE_LOW, 20);
|
||||
break;
|
||||
case APP_MSG_MIC_BASS_DOWN:
|
||||
puts("\n APP_MSG_MIC_BASS_DOWN \n");
|
||||
mic_bass_treble_eq_udpate("BassTreEff", BASS_TREBLE_LOW, -20);
|
||||
break;
|
||||
case APP_MSG_MIC_TREBLE_UP:
|
||||
puts("\n APP_MSG_MIC_TREBLE_UP \n");
|
||||
mic_bass_treble_eq_udpate("BassTreEff", BASS_TREBLE_HIGH, 20);
|
||||
break;
|
||||
case APP_MSG_MIC_TREBLE_DOWN:
|
||||
puts("\n APP_MSG_MIC_TREBLE_DOWN \n");
|
||||
mic_bass_treble_eq_udpate("BassTreEff", BASS_TREBLE_HIGH, -20);
|
||||
break;
|
||||
#endif
|
||||
case APP_MSG_VOCAL_REMOVE:
|
||||
#if TCFG_APP_BT_EN
|
||||
if (bt_get_call_status() != BT_CALL_HANGUP) {//通话中
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
music_vocal_remover_switch();
|
||||
break;
|
||||
case APP_MSG_MUSIC_CHANGE_EQ:
|
||||
// for test eq切换接口,工具上需要配置多份EQ配置
|
||||
u8 music_eq_preset_index = get_music_eq_preset_index();
|
||||
music_eq_preset_index ^= 1;
|
||||
set_music_eq_preset_index(music_eq_preset_index);
|
||||
eq_update_parm(get_current_scene(), "Eq0Media", music_eq_preset_index);
|
||||
app_send_message(APP_MSG_EQ_CHANGED, get_music_eq_preset_index() + 1); //显示EQ从1开始
|
||||
printf("APP_MSG_MUSIC_CHANGE_EQ:%d\n", music_eq_preset_index);
|
||||
break;
|
||||
|
||||
case APP_MSG_SYS_MUTE:
|
||||
sys_audio_mute_statu = app_audio_get_dac_digital_mute() ^ 1;
|
||||
if (sys_audio_mute_statu) {
|
||||
app_audio_mute(AUDIO_MUTE_DEFAULT);
|
||||
} else {
|
||||
app_audio_mute(AUDIO_UNMUTE_DEFAULT);
|
||||
}
|
||||
app_send_message(APP_MSG_MUTE_CHANGED, sys_audio_mute_statu);
|
||||
break;
|
||||
case APP_MSG_REC_PP:
|
||||
#if TCFG_MIX_RECORD_ENABLE
|
||||
if (app_get_current_mode()->name == APP_MODE_MUSIC) {
|
||||
r_printf("[Error]Music Mode no support record!\n");
|
||||
break;
|
||||
} else if (app_get_current_mode()->name == APP_MODE_PC) {
|
||||
r_printf("[Error]PC Mode no support record!\n");
|
||||
break;
|
||||
}
|
||||
|
||||
printf("\n APP_MSG_REC_PP \n");
|
||||
if (get_mix_recorder_status()) {
|
||||
mix_recorder_stop();
|
||||
} else {
|
||||
mix_recorder_start();
|
||||
}
|
||||
#endif // TCFG_MIX_RECORD_ENABLE
|
||||
break;
|
||||
case APP_MSG_IR_NUM0:
|
||||
case APP_MSG_IR_NUM1:
|
||||
case APP_MSG_IR_NUM2:
|
||||
case APP_MSG_IR_NUM3:
|
||||
case APP_MSG_IR_NUM4:
|
||||
case APP_MSG_IR_NUM5:
|
||||
case APP_MSG_IR_NUM6:
|
||||
case APP_MSG_IR_NUM7:
|
||||
case APP_MSG_IR_NUM8:
|
||||
case APP_MSG_IR_NUM9:
|
||||
input_number_deal(msg[0] - APP_MSG_IR_NUM0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void app_common_device_event_handler(int *msg)
|
||||
{
|
||||
int ret = 0;
|
||||
const char *logo = NULL;
|
||||
const char *usb_msg = NULL;
|
||||
u8 app = 0xff ;
|
||||
u8 alarm_flag = 0;
|
||||
switch (msg[0]) {
|
||||
case DEVICE_EVENT_FROM_OTG:
|
||||
usb_msg = (const char *)msg[2];
|
||||
if (usb_msg[0] == 's') {
|
||||
#if TCFG_USB_SLAVE_ENABLE
|
||||
ret = pc_device_event_handler(msg);
|
||||
if (ret == 1) {
|
||||
if (true != app_in_mode(APP_MODE_PC)) {
|
||||
app = APP_MODE_PC;
|
||||
}
|
||||
} else if (ret == 2) {
|
||||
app_send_message(APP_MSG_GOTO_NEXT_MODE, 0);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
} else if (usb_msg[0] == 'h') {
|
||||
///是主机, 统一于SD卡等响应主机处理,这里不break
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
case DRIVER_EVENT_FROM_SD0:
|
||||
case DRIVER_EVENT_FROM_SD1:
|
||||
case DRIVER_EVENT_FROM_SD2:
|
||||
case DEVICE_EVENT_FROM_USB_HOST:
|
||||
#if TCFG_APP_MUSIC_EN
|
||||
if (true == app_in_mode(APP_MODE_MUSIC)) {
|
||||
music_device_msg_handler(msg);
|
||||
}
|
||||
ret = dev_status_event_filter(msg);///解码设备上下线, 设备挂载等处理
|
||||
if (ret == true) {
|
||||
if (msg[1] == DEVICE_EVENT_IN) {
|
||||
///设备上线, 非解码模式切换到解码模式播放
|
||||
if (true != app_in_mode(APP_MODE_MUSIC)) {
|
||||
app = APP_MODE_MUSIC;
|
||||
}
|
||||
}
|
||||
}
|
||||
#if (TCFG_SD_ALWAY_ONLINE_ENABLE && (TCFG_SD0_ENABLE || TCFG_SD1_ENABLE))
|
||||
extern void sdx_dev_detect_timer_del();
|
||||
sdx_dev_detect_timer_del();
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
case DEVICE_EVENT_FROM_LINEIN:
|
||||
#if TCFG_APP_LINEIN_EN
|
||||
if (msg[1] == DEVICE_EVENT_IN) {
|
||||
printf("LINEIN ONLINE");
|
||||
if (true != app_in_mode(APP_MODE_LINEIN)) {
|
||||
app = APP_MODE_LINEIN;
|
||||
}
|
||||
} else if (msg[1] == DEVICE_EVENT_OUT) {
|
||||
printf("LINEIN OFFLINE");
|
||||
if (true == app_in_mode(APP_MODE_LINEIN)) {
|
||||
app_send_message(APP_MSG_CHANGE_MODE, 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case DEVICE_EVENT_FROM_ALM:
|
||||
#if TCFG_APP_RTC_EN
|
||||
if (msg[1] == DEVICE_EVENT_IN) {
|
||||
printf("ALM ONLINE");
|
||||
alarm_update_info_after_isr();
|
||||
if (true != app_in_mode(APP_MODE_RTC)) {
|
||||
app = APP_MODE_RTC;
|
||||
} else {
|
||||
alarm_ring_start();
|
||||
}
|
||||
} else if (msg[1] == DEVICE_EVENT_OUT) {
|
||||
printf("ALM OFFLINE");
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
/* printf("unknow SYS_DEVICE_EVENT!!, %x\n", (u32)event->arg); */
|
||||
break;
|
||||
}
|
||||
|
||||
if (app != 0xff) {
|
||||
/*一些情况不希望退出蓝牙模式*/
|
||||
#if TCFG_APP_BT_EN
|
||||
if (bt_app_exit_check() == 0) {
|
||||
puts("bt_background can not enter\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
//PC 不响应因为设备上线引发的模式切换
|
||||
if ((true != app_in_mode(APP_MODE_PC)) || alarm_flag) {
|
||||
//闹钟响起直接切到rtc模式
|
||||
if (alarm_flag) {
|
||||
app_send_message2(APP_MSG_GOTO_MODE, app, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
#if (TCFG_CHARGE_ENABLE && (!TCFG_CHARGE_POWERON_ENABLE))
|
||||
if (get_charge_online_flag()) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if TWFG_APP_POWERON_IGNORE_DEV
|
||||
int msec = jiffies_msec2offset(app_var.start_time, jiffies_msec());
|
||||
if (msec > TWFG_APP_POWERON_IGNORE_DEV)
|
||||
#endif
|
||||
{
|
||||
#if 0//defined(TCFG_BROADCAST_ENABLE) && (TCFG_BROADCAST_ENABLE)
|
||||
if (get_broadcast_role() != BROADCAST_ROLE_RECEIVER) {
|
||||
app_send_message2(APP_MSG_GOTO_MODE, app, 0);
|
||||
}
|
||||
#else
|
||||
app_send_message2(APP_MSG_GOTO_MODE, app, 0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void app_common_app_event_handler(int *msg)
|
||||
{
|
||||
switch (msg[0]) {
|
||||
case APP_MSG_KEY_POWER_OFF:
|
||||
case APP_MSG_KEY_POWER_OFF_HOLD:
|
||||
if (msg[1] == APP_KEY_MSG_FROM_TWS) { //来自tws的按键关机消息不响应
|
||||
break;
|
||||
}
|
||||
power_off_deal(APP_MSG_KEY_POWER_OFF);
|
||||
break;
|
||||
case APP_MSG_KEY_POWER_OFF_RELEASE:
|
||||
goto_poweroff_first_flag = 0;
|
||||
break;
|
||||
case APP_MSG_KEY_POWER_OFF_INSTANTLY:
|
||||
power_off_instantly();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void app_default_msg_handler(int *msg)
|
||||
{
|
||||
const struct app_msg_handler *handler;
|
||||
struct app_mode *mode;
|
||||
|
||||
mode = app_get_current_mode();
|
||||
//消息继续分发
|
||||
|
||||
#if (TCFG_BT_BACKGROUND_ENABLE)
|
||||
if (!bt_background_msg_forward_filter(msg))
|
||||
#endif
|
||||
{
|
||||
for_each_app_msg_handler(handler) {
|
||||
if (handler->from != msg[0]) {
|
||||
continue;
|
||||
}
|
||||
if (mode && mode->name == handler->owner) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/*蓝牙后台情况下,消息仅转发给后台处理*/
|
||||
handler->handler(msg + 1);
|
||||
}
|
||||
}
|
||||
|
||||
switch (msg[0]) {
|
||||
case MSG_FROM_DEVICE:
|
||||
app_common_device_event_handler(msg + 1);
|
||||
break;
|
||||
case MSG_FROM_APP:
|
||||
app_common_app_event_handler(msg + 1);
|
||||
break;
|
||||
#if (defined TCFG_COLOR_SCREEN_CHARGING_CASE_ENABLE) && TCFG_COLOR_SCREEN_CHARGING_CASE_ENABLE
|
||||
#if (defined TCFG_CHARGE_BOX_ENABLE && TCFG_CHARGE_BOX_ENABLE)
|
||||
case MSG_FROM_CHGBOX: {
|
||||
extern int charge_box_ctrl_event_handler(int *msg);
|
||||
charge_box_ctrl_event_handler(msg + 1);
|
||||
}
|
||||
break;
|
||||
case MSG_FROM_CHGBOX_EAR: {
|
||||
extern void app_chargebox_task_handler(int *msg);
|
||||
app_chargebox_task_handler(msg + 1);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,407 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".dev_multiplex_api.data.bss")
|
||||
#pragma data_seg(".dev_multiplex_api.data")
|
||||
#pragma const_seg(".dev_multiplex_api.text.const")
|
||||
#pragma code_seg(".dev_multiplex_api.text")
|
||||
#endif
|
||||
#include "system/includes.h"
|
||||
#include "app_main.h"
|
||||
#include "dev_multiplex_api.h"
|
||||
#include "usb/otg.h"
|
||||
#include "usb/host/usb_host.h"
|
||||
#include "usb/usb_task.h"
|
||||
#include "asm/sdmmc.h"
|
||||
#include "dev_manager.h"
|
||||
#include "music/music_player.h"
|
||||
|
||||
|
||||
#define LOG_TAG_CONST APP_ACTION
|
||||
#define LOG_TAG "[APP_ACTION]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
/* #define LOG_DUMP_ENABLE */
|
||||
#define LOG_CLI_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
static u8 msg_notify_enable = 0xff;
|
||||
|
||||
|
||||
static u8 sd_first_online = 0;
|
||||
static u16 resume = 0;
|
||||
|
||||
#define USB_ACTIVE 0x1
|
||||
#define SD_ACTIVE 0x2
|
||||
|
||||
#define MULT_IO_IDLE (0)
|
||||
#define MULT_IO_ACTIVE (BIT(0))
|
||||
#define MULT_IO_SUSPEND (BIT(1))
|
||||
|
||||
#define USB_RESET_DELAY 20
|
||||
|
||||
struct mult_io {
|
||||
u8 sd_status: 3;
|
||||
u8 usb_status: 3;
|
||||
u8 active: 2;
|
||||
};
|
||||
|
||||
struct mult_io mult_flag = {0};
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 库的调用函数 重载了库驱动 如果返回真则可以发送sd卡的上下线消息
|
||||
@param 无
|
||||
@return 无
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
|
||||
int sd_notify_enable(int sd_id)
|
||||
{
|
||||
return msg_notify_enable & BIT(sd_id);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 设置是否 sd卡可以推上下线消息
|
||||
@param 1:可以推 0:不推
|
||||
@return 无
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void set_sd_notify_enable(int sd_id, u8 en)
|
||||
{
|
||||
if (en) {
|
||||
msg_notify_enable |= BIT(sd_id);
|
||||
} else {
|
||||
msg_notify_enable &= ~BIT(sd_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mult_sdio_resume_clean()
|
||||
{
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
if (resume) {
|
||||
sd_io_resume(TCFG_DM_MULTIPLEX_WITH_SD_PORT, 2);//sd_data0 io 状态会被还原
|
||||
resume = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void mult_sdio_resume()
|
||||
{
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
if (resume) {
|
||||
resume--;
|
||||
if (!resume) {
|
||||
sd_io_resume(TCFG_DM_MULTIPLEX_WITH_SD_PORT, 2);//sd_data0 io 状态会被还原
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int mult_sdio_suspend()
|
||||
{
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
if (resume) {
|
||||
printf("%s resume count = %d\n", __FUNCTION__, resume);
|
||||
return 0;
|
||||
}
|
||||
__try_t:
|
||||
if (sd_io_suspend(TCFG_DM_MULTIPLEX_WITH_SD_PORT, 2)) {
|
||||
os_time_dly(1);
|
||||
printf("wait %s\n", __FUNCTION__);
|
||||
goto __try_t;
|
||||
}
|
||||
resume++;
|
||||
//配置绑定的sd_data0 io 为高阻
|
||||
gpio_set_mode(IO_PORT_SPILT(TCFG_USB_SD_MULTIPLEX_IO), PORT_HIGHZ);
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mult_usb_suspend(usb_dev id)
|
||||
{
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
if (id != (usb_dev) - 1 && usb_otg_online(id) == HOST_MODE) {
|
||||
printf("mult_usb_suspend\n");
|
||||
usb_otg_io_suspend(id);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
int mult_usb_resume(usb_dev id, u8 mount, u32 delay)
|
||||
{
|
||||
int err = -1;
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
if (id != (usb_dev) - 1 && usb_otg_online(id) == HOST_MODE) {
|
||||
usb_otg_io_resume(id);
|
||||
/*
|
||||
* 有一部分U盘在DM和SD DAT0复用时,插入U盘或者模式切到播U盘,
|
||||
* 需要把DPDM拉低一段时间,让U盘自己认为插入了主机
|
||||
*/
|
||||
if (delay) {
|
||||
usb_otg_suspend(id, 0);
|
||||
os_time_dly(delay);
|
||||
usb_otg_resume(id);
|
||||
}
|
||||
|
||||
if (mount) {
|
||||
if (dev_manager_online_check_by_logo("udisk0", 0)) {
|
||||
dev_manager_unmount("udisk0");
|
||||
}
|
||||
int msg[2];
|
||||
msg[0] = id;
|
||||
msg[1] = (int)&ret;
|
||||
usb_message_to_stack(USBSTACK_HOST_REMOUNT, msg, 1);
|
||||
if (/*usb_host_remount(id, MOUNT_RETRY, MOUNT_RESET, MOUNT_TIMEOUT, 0)*/ret) {
|
||||
log_error("udisk remount fail\n");
|
||||
} else {
|
||||
err = dev_manager_mount("udisk0");
|
||||
return err;
|
||||
}
|
||||
} else {
|
||||
err = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int dev_sd_change_usb()
|
||||
{
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
if ((mult_flag.sd_status == MULT_IO_ACTIVE) ||
|
||||
(mult_flag.usb_status == MULT_IO_SUSPEND)) {
|
||||
printf("sd_change_usb start \n");
|
||||
mult_sdio_suspend();
|
||||
mult_flag.sd_status = MULT_IO_SUSPEND;
|
||||
mult_usb_resume(g_usb_id, 1, USB_RESET_DELAY);
|
||||
mult_flag.usb_status = MULT_IO_ACTIVE;
|
||||
mult_flag.active = USB_ACTIVE;
|
||||
printf("sd_change_usb finsh \n");
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int dev_usb_change_sd()
|
||||
{
|
||||
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
if ((mult_flag.usb_status == MULT_IO_ACTIVE) ||
|
||||
(mult_flag.sd_status == MULT_IO_SUSPEND)) {
|
||||
printf("dev_usb_change_sd start \n");
|
||||
mult_usb_suspend(g_usb_id);
|
||||
os_time_dly(1);//
|
||||
mult_flag.usb_status = MULT_IO_SUSPEND;
|
||||
mult_sdio_resume();
|
||||
mult_flag.sd_status = MULT_IO_ACTIVE;
|
||||
mult_flag.active = SD_ACTIVE;
|
||||
printf("dev_usb_change_sd finsh \n");
|
||||
}
|
||||
return 0;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int mult_sd_online_mount_before(int sd_dev, usb_dev usb_id)
|
||||
{
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
if (TCFG_DM_MULTIPLEX_WITH_SD_PORT != sd_dev) {
|
||||
return 0;
|
||||
}
|
||||
sd_first_online = 1;
|
||||
music_player_stop(1);//停止解码
|
||||
if (mult_flag.active == USB_ACTIVE) {
|
||||
mult_usb_suspend(g_usb_id);
|
||||
}
|
||||
mult_sdio_resume_clean();
|
||||
mult_flag.usb_status = MULT_IO_SUSPEND;
|
||||
mult_flag.sd_status = MULT_IO_ACTIVE;
|
||||
mult_flag.active = SD_ACTIVE;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int mult_sd_online_mount_after(int sd_dev, usb_dev usb_id, int err)
|
||||
{
|
||||
int ret = 0;
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
if (TCFG_DM_MULTIPLEX_WITH_SD_PORT != sd_dev) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (err) {
|
||||
mult_flag.sd_status = MULT_IO_SUSPEND;
|
||||
mult_sdio_suspend();
|
||||
mult_usb_resume(usb_id, 1, USB_RESET_DELAY);
|
||||
mult_flag.usb_status = MULT_IO_ACTIVE;
|
||||
mult_flag.active = USB_ACTIVE;
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
int mult_sd_offline_before(void *logo, usb_dev usb_id)
|
||||
{
|
||||
int ret = 0 ;
|
||||
/* u8 dev_logo[16]; */
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
int str_len = 0;
|
||||
if (!sd_first_online) { //没有收到过上线消息不处理下线
|
||||
return 0;
|
||||
}
|
||||
if ((TCFG_DM_MULTIPLEX_WITH_SD_PORT == 0) && strcmp("sd0", (char *)logo)) {
|
||||
return 0;
|
||||
}
|
||||
if ((TCFG_DM_MULTIPLEX_WITH_SD_PORT == 1) && strcmp("sd1", (char *)logo)) {
|
||||
return 0;
|
||||
}
|
||||
printf("MULT_SD_OFFLINE_BEFORE\n");
|
||||
if (mult_flag.active == SD_ACTIVE) {
|
||||
const char *cur_logo = music_player_get_phy_dev(&str_len);
|
||||
|
||||
#if (TCFG_DM_MULTIPLEX_WITH_SD_PORT == 0)
|
||||
if (cur_logo && (0 == strncmp(cur_logo, "sd0", str_len))) {
|
||||
printf("SD0 STOP FIRST !!!");
|
||||
music_player_stop(1);//停止解码
|
||||
}
|
||||
|
||||
#else
|
||||
if (cur_logo && (0 == strncmp(cur_logo, "sd1", str_len))) {
|
||||
printf("SD1 STOP FIRST !!!");
|
||||
music_player_stop(1);//停止解码
|
||||
}
|
||||
#endif
|
||||
|
||||
if (dev_manager_check_by_logo((char *)logo)) {
|
||||
dev_manager_del((char *)logo);
|
||||
}
|
||||
/* sprintf(dev_logo, "%s%s", logo, "_rec"); */
|
||||
/* if (dev_manager_check_by_logo(dev_logo)) { */
|
||||
/* dev_manager_del(dev_logo); */
|
||||
/* } */
|
||||
mult_flag.sd_status = MULT_IO_IDLE;
|
||||
mult_sdio_suspend();
|
||||
mult_usb_resume(usb_id, 1, USB_RESET_DELAY);
|
||||
mult_flag.usb_status = MULT_IO_ACTIVE;
|
||||
mult_flag.active = USB_ACTIVE;
|
||||
|
||||
} else if (mult_flag.active == USB_ACTIVE) {
|
||||
if (dev_manager_check_by_logo((char *)logo)) {
|
||||
dev_manager_del((char *)logo);
|
||||
}
|
||||
/* sprintf(dev_logo, "%s%s", logo, "_rec"); */
|
||||
/* if (dev_manager_check_by_logo(dev_logo)) { */
|
||||
/* dev_manager_del(dev_logo); */
|
||||
/* } */
|
||||
mult_sdio_resume();
|
||||
mult_flag.sd_status = MULT_IO_SUSPEND;
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
int mult_usb_mount_before(usb_dev usb_id)
|
||||
{
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
u32 reset_delay = 0;;
|
||||
music_player_stop(1);//停止解码
|
||||
mult_sdio_suspend();
|
||||
reset_delay = USB_RESET_DELAY;
|
||||
mult_usb_resume(usb_id, 0, reset_delay);
|
||||
mult_flag.sd_status = MULT_IO_SUSPEND;
|
||||
mult_flag.usb_status = MULT_IO_ACTIVE;
|
||||
mult_flag.active = USB_ACTIVE;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int mult_usb_online_mount_after(usb_dev usb_id, int err)
|
||||
{
|
||||
int ret = 0;
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
if (err) {
|
||||
mult_flag.usb_status = MULT_IO_SUSPEND;
|
||||
mult_usb_suspend(usb_id);
|
||||
mult_sdio_resume();
|
||||
mult_flag.sd_status = MULT_IO_ACTIVE;
|
||||
mult_flag.active = SD_ACTIVE;
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
int mult_usb_mount_offline(usb_dev usb_id)
|
||||
{
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
mult_usb_suspend(usb_id);
|
||||
mult_sdio_resume();
|
||||
mult_flag.usb_status = MULT_IO_SUSPEND;
|
||||
if (mult_flag.active == USB_ACTIVE) {
|
||||
mult_flag.sd_status = MULT_IO_SUSPEND;
|
||||
mult_flag.active = 0;
|
||||
} else {
|
||||
mult_flag.sd_status = MULT_IO_ACTIVE;
|
||||
mult_flag.active = SD_ACTIVE;
|
||||
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///*----------------------------------------------------------------------------*/
|
||||
/**@brief pc模式 usb和sd卡 io 复用初始化
|
||||
@param 无
|
||||
@return 无
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void pc_dm_multiplex_init()
|
||||
{
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
mult_sdio_suspend();//supend sd卡总线
|
||||
set_sd_notify_enable(TCFG_DM_MULTIPLEX_WITH_SD_PORT, 0); //sd卡不允许发出上下线消息
|
||||
gpio_set_mode(IO_PORT_SPILT(TCFG_USB_SD_MULTIPLEX_IO), PORT_OUTPUT_LOW);
|
||||
os_time_dly(2);
|
||||
gpio_set_mode(IO_PORT_SPILT(TCFG_USB_SD_MULTIPLEX_IO), PORT_HIGHZ);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void pc_dm_multiplex_exit()
|
||||
{
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
mult_sdio_resume();//resume sd卡总线
|
||||
usb_otg_resume(0);
|
||||
set_sd_notify_enable(TCFG_DM_MULTIPLEX_WITH_SD_PORT, 1); //sd卡允许发出上下线消息
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,255 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".dev_status.data.bss")
|
||||
#pragma data_seg(".dev_status.data")
|
||||
#pragma const_seg(".dev_status.text.const")
|
||||
#pragma code_seg(".dev_status.text")
|
||||
#endif
|
||||
#include "app_main.h"
|
||||
#include "app_default_msg_handler.h"
|
||||
#include "dev_status.h"
|
||||
#include "dev_update.h"
|
||||
#include "dev_multiplex_api.h"
|
||||
#include "dev_manager.h"
|
||||
#include "usb/host/usb_host.h"
|
||||
#include "usb/usb_task.h"
|
||||
#include "app_config.h"
|
||||
|
||||
#if RCSP_MODE
|
||||
#include "rcsp.h"
|
||||
#endif
|
||||
|
||||
usb_dev g_usb_id = (usb_dev) - 1;
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief 设备上线预处理
|
||||
@param
|
||||
event:设备事件
|
||||
@return
|
||||
@note 根据特殊情景,这里可以处理一些例如io复用处理
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int dev_manager_add_prepare(int *msg)
|
||||
{
|
||||
int ret = 0;
|
||||
switch (msg[0]) {
|
||||
case DRIVER_EVENT_FROM_SD0:
|
||||
case DRIVER_EVENT_FROM_SD1:
|
||||
case DRIVER_EVENT_FROM_SD2:
|
||||
//传入0 sd0 1:sd1
|
||||
mult_sd_online_mount_before(!!(msg[0] - DRIVER_EVENT_FROM_SD0), g_usb_id);
|
||||
break;
|
||||
//#if TCFG_UDISK_ENABLE || TCFG_HOST_AUDIO_ENABLE
|
||||
// case DEVICE_EVENT_FROM_OTG:
|
||||
// ///host mount
|
||||
// mult_usb_mount_before(g_usb_id);
|
||||
//
|
||||
// ret = usb_host_mount(g_usb_id,
|
||||
// MOUNT_RETRY,
|
||||
// MOUNT_RESET,
|
||||
// MOUNT_TIMEOUT);
|
||||
// break;
|
||||
//#endif
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief 设备上线后处理
|
||||
@param
|
||||
event:设备事件
|
||||
err:设备上线错误码
|
||||
@return
|
||||
@note 根据特殊情景,这里可以处理一些例如io复用处理
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int dev_manager_add_after(int *msg, int err)
|
||||
{
|
||||
int ret = 0;
|
||||
switch (msg[0]) {
|
||||
case DRIVER_EVENT_FROM_SD0:
|
||||
case DRIVER_EVENT_FROM_SD1:
|
||||
case DRIVER_EVENT_FROM_SD2:
|
||||
//传入0 sd0 1:sd1
|
||||
mult_sd_online_mount_after(!!(msg[0] - DRIVER_EVENT_FROM_SD0), g_usb_id, err);
|
||||
break;
|
||||
//#if TCFG_UDISK_ENABLE
|
||||
// case DEVICE_EVENT_FROM_OTG:
|
||||
// mult_usb_online_mount_after(g_usb_id, err);
|
||||
// break;
|
||||
//#endif
|
||||
#if TCFG_UDISK_ENABLE
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
case DEVICE_EVENT_FROM_USB_HOST:
|
||||
int msg2[4];
|
||||
msg2[0] = g_usb_id;
|
||||
msg2[1] = err;
|
||||
usb_message_to_stack(USBSTACK_HOST_MOUNT_AFTER, msg2, 1);
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief 设备下线预处理
|
||||
@param
|
||||
event:设备事件
|
||||
@return
|
||||
@note 根据特殊情景,这里可以处理一些例如io复用处理
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int dev_manager_del_prepare(int *msg)
|
||||
{
|
||||
int ret = 0;
|
||||
switch (msg[0]) {
|
||||
case DRIVER_EVENT_FROM_SD0:
|
||||
case DRIVER_EVENT_FROM_SD1:
|
||||
case DRIVER_EVENT_FROM_SD2:
|
||||
mult_sd_offline_before((char *)msg[2], g_usb_id);
|
||||
break;
|
||||
//#if TCFG_UDISK_ENABLE || TCFG_HOST_AUDIO_ENABLE
|
||||
// case DEVICE_EVENT_FROM_OTG:
|
||||
// ///host umount
|
||||
// usb_host_unmount(g_usb_id);
|
||||
// break;
|
||||
//#endif
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief 设备下线后处理
|
||||
@param
|
||||
event:设备事件
|
||||
err:设备下线错误码
|
||||
@return
|
||||
@note 根据特殊情景,这里可以处理一些例如io复用处理
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int dev_manager_del_after(int *msg, int err)
|
||||
{
|
||||
int ret = 0;
|
||||
switch (msg[0]) {
|
||||
case DRIVER_EVENT_FROM_SD0:
|
||||
case DRIVER_EVENT_FROM_SD1:
|
||||
case DRIVER_EVENT_FROM_SD2:
|
||||
break;
|
||||
//#if TCFG_UDISK_ENABLE
|
||||
// case DEVICE_EVENT_FROM_OTG:
|
||||
// mult_usb_mount_offline(g_usb_id);
|
||||
// g_usb_id = (usb_dev) - 1;
|
||||
// break;
|
||||
//#endif
|
||||
#if TCFG_UDISK_ENABLE
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
case DEVICE_EVENT_FROM_USB_HOST:
|
||||
int msg2[4];
|
||||
msg2[0] = g_usb_id;
|
||||
msg2[1] = err;
|
||||
usb_message_to_stack(USBSTACK_HOST_UNMOUNT_AFTER, msg2, 1);
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief 设备事件响应处理
|
||||
@param
|
||||
event:设备事件
|
||||
@return
|
||||
@note 设备上线和下线会动态添加到设备管理链表中,
|
||||
通过dev_manager系列接口可以进行设备操作,例如:例如查找、检查在线等
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int dev_status_event_filter(int *msg)
|
||||
{
|
||||
int ret = true;
|
||||
int err = 0;
|
||||
char *add = NULL;
|
||||
char *del = NULL;
|
||||
static u32 sdx_mount_err_cnt = 0;
|
||||
switch (msg[0]) {
|
||||
case DRIVER_EVENT_FROM_SD0:
|
||||
case DRIVER_EVENT_FROM_SD1:
|
||||
case DRIVER_EVENT_FROM_SD2:
|
||||
printf("DEVICE_EVENT_FROM_SD%d\n", msg[0] - DRIVER_EVENT_FROM_SD0);
|
||||
if (msg[1] == DEVICE_EVENT_IN) {
|
||||
///上线处理, 设备管理挂载
|
||||
printf("DEVICE_EVENT_IN\n");
|
||||
add = (char *)msg[2];
|
||||
} else {
|
||||
///下线处理,设备管理卸载
|
||||
printf("DEVICE_EVENT_OUT\n");
|
||||
del = (char *)msg[2];
|
||||
}
|
||||
break;
|
||||
#if TCFG_UDISK_ENABLE
|
||||
case DEVICE_EVENT_FROM_USB_HOST:
|
||||
char *usb_msg = (char *)msg[2];
|
||||
printf("DEVICE_EVENT_FROM_USB_HOST %s\n", usb_msg);
|
||||
g_usb_id = usb_msg[strlen(usb_msg) - 1] - '0';
|
||||
if (!strncmp(usb_msg, "udisk", 5)) {
|
||||
///是host, 准备挂载设备, usb host mount/umout
|
||||
if (msg[1] == DEVICE_EVENT_IN) {
|
||||
///加入到设备管理列表
|
||||
printf("DEVICE_EVENT_IN\n");
|
||||
add = usb_msg;
|
||||
} else {
|
||||
printf("DEVICE_EVENT_OUT\n");
|
||||
del = usb_msg;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
|
||||
////dev manager add/del操作
|
||||
if (add) {
|
||||
err = dev_manager_add_prepare(msg);
|
||||
if (!err) {
|
||||
err = dev_manager_add(add);
|
||||
if (!err) {
|
||||
sdx_mount_err_cnt = 0;
|
||||
#if (MUSIC_DEV_ONLINE_START_AFTER_MOUNT_EN)
|
||||
music_task_dev_online_start(add);
|
||||
#endif
|
||||
#if (TCFG_DEV_UPDATE_IF_NOFILE_ENABLE == 0)
|
||||
if (app_in_mode(APP_MODE_PC) == false) {
|
||||
///检查设备升级
|
||||
dev_update_check(add);
|
||||
}
|
||||
#endif/* TCFG_DEV_UPDATE_IF_NOFILE_ENABLE*/
|
||||
} else {
|
||||
#if 0//(defined(TCFG_SD_ALWAY_ONLINE_ENABLE) && (TCFG_SD_ALWAY_ONLINE_ENABLE == DISABLE))
|
||||
sdx_mount_err_cnt++;
|
||||
if (sdx_mount_err_cnt < 3) { // 挂载失败会重试 3 次。由于重新挂载的问题,SD IN/OUT 的消息不成对
|
||||
if (((!strncmp(add, "sd0", strlen("sd0"))) || (!strncmp(add, "sd1", strlen("sd1"))))) {
|
||||
dev_manager_del(add); // 添加设备失败,删除
|
||||
sd_dev_ops.ioctl(NULL, IOCTL_RESET_DET_STATUS, (u32)event->arg - DRIVER_EVENT_FROM_SD0); // 复位 sd 的检测状态
|
||||
printf("mount sd err, try mount again %d \n", sdx_mount_err_cnt);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
ret = false;
|
||||
}
|
||||
} else {
|
||||
ret = false;
|
||||
}
|
||||
dev_manager_add_after(msg, err);
|
||||
}
|
||||
if (del) {
|
||||
dev_manager_del_prepare(msg);
|
||||
dev_manager_del(del);
|
||||
dev_manager_del_after(msg, 0);
|
||||
}
|
||||
#if RCSP_MODE
|
||||
RCSP_UPDATE(COMMON_FUNCTION, BIT(RCSP_DEVICE_STATUS_ATTR_TYPE_DEV_INFO));
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,568 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".idle.data.bss")
|
||||
#pragma data_seg(".idle.data")
|
||||
#pragma const_seg(".idle.text.const")
|
||||
#pragma code_seg(".idle.text")
|
||||
#endif
|
||||
#include "idle.h"
|
||||
#include "system/includes.h"
|
||||
#include "media/includes.h"
|
||||
#include "app_config.h"
|
||||
#include "app_action.h"
|
||||
#include "app_tone.h"
|
||||
#include "asm/charge.h"
|
||||
#include "app_charge.h"
|
||||
#include "app_main.h"
|
||||
#include "app_chargestore.h"
|
||||
#include "app_testbox.h"
|
||||
#include "user_cfg.h"
|
||||
#include "ui/ui_api.h"
|
||||
#include "ui_manage.h"
|
||||
#include "avctp_user.h"
|
||||
#include "mic_effect.h"
|
||||
#include "linein_dev.h"
|
||||
#include "asm/wdt.h"
|
||||
#include "audio_config.h"
|
||||
#if TCFG_SMART_VOICE_ENABLE
|
||||
#include "smart_voice.h"
|
||||
#endif
|
||||
|
||||
#if TCFG_ANC_BOX_ENABLE
|
||||
#include "app_ancbox.h"
|
||||
#endif
|
||||
|
||||
#define LOG_TAG "[APP_IDLE]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
#define LOG_CLI_ENABLE
|
||||
#include "debug.h"
|
||||
#include "bt_tws.h"
|
||||
|
||||
static int app_idle_init(int param);
|
||||
void app_idle_exit();
|
||||
extern uint32_t timer_get_ms(void);
|
||||
|
||||
#define LOW_POWER_IN_IDLE 0// idle 是否关闭不用的模块,减少功耗
|
||||
#define POWER_OFF_TIME 2//最小开机时间
|
||||
#define POWER_OFF_CNT 10
|
||||
#define POWER_ON_CNT 10
|
||||
|
||||
static u32 ui_logo_time = 0;
|
||||
static u8 goto_poweron_cnt = 0;
|
||||
static u8 goto_poweron_flag = 0;
|
||||
static u8 goto_poweroff_cnt = 0;
|
||||
static u8 goto_poweroff_flag = 0;
|
||||
static u8 idle_sub_mode = 0;
|
||||
static u8 power_off_tone_play_flag = 0;
|
||||
u8 goto_poweroff_first_flag = 0;
|
||||
static void power_off_ui_enter()
|
||||
{
|
||||
UI_SHOW_WINDOW(ID_WINDOW_POWER_OFF);
|
||||
ui_logo_time = timer_get_ms();
|
||||
|
||||
}
|
||||
static void power_off_ui_exit()
|
||||
{
|
||||
while (timer_get_ms() - ui_logo_time <= POWER_OFF_TIME * 1000) { //显示开机logo
|
||||
os_time_dly(2);
|
||||
}
|
||||
UI_HIDE_CURR_WINDOW();
|
||||
}
|
||||
#if LOW_POWER_IN_IDLE
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 下面处理是为了关闭不需要用的模块,减少系统功耗
|
||||
@param
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#include "usb/otg.h"
|
||||
#include "usb/host/usb_host.h"
|
||||
#include "usb/device/usb_stack.h"
|
||||
#include "asm/power/p33.h"
|
||||
#include "asm/sdmmc.h"
|
||||
#include "dev_manager/dev_manager.h"
|
||||
|
||||
static u8 suspend_flag = 0;
|
||||
static u8 is_idle_flag = 0;
|
||||
|
||||
u32 regs_buf[11] = {0};
|
||||
void resume_some_peripheral()
|
||||
{
|
||||
u32 *regs_ptr = regs_buf;
|
||||
|
||||
if (!suspend_flag) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
here need to add
|
||||
*/
|
||||
|
||||
suspend_flag = 0;
|
||||
}
|
||||
|
||||
void suspend_some_peripheral()
|
||||
{
|
||||
u32 *regs_ptr = regs_buf;
|
||||
|
||||
if (suspend_flag) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
here need to add
|
||||
*/
|
||||
|
||||
suspend_flag = 1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static u8 is_idle_query(void)
|
||||
{
|
||||
return is_idle_flag;
|
||||
}
|
||||
REGISTER_LP_TARGET(idle_lp_target) = {
|
||||
.name = "not_idle",
|
||||
.is_idle = is_idle_query,
|
||||
};
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief idle 重新打开需要的模块
|
||||
@param 无
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void idle_app_open_module()
|
||||
{
|
||||
#if LOW_POWER_IN_IDLE
|
||||
is_idle_flag = 0;
|
||||
#if (TCFG_LOWPOWER_LOWPOWER_SEL == 0)
|
||||
resume_some_peripheral();
|
||||
#endif
|
||||
|
||||
#if (TCFG_SD0_ENABLE || TCFG_SD1_ENABLE)
|
||||
sdx_dev_detect_timer_add();
|
||||
#endif
|
||||
|
||||
#if (TCFG_PC_ENABLE || TCFG_USB_HOST_ENABLE)
|
||||
usb_detect_timer_add();
|
||||
#endif
|
||||
|
||||
#if TCFG_APP_LINEIN_EN
|
||||
linein_detect_timer_add();
|
||||
#endif
|
||||
#endif //LOW_POWER_IN_IDLE
|
||||
}
|
||||
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief idle 关闭不需要的模块
|
||||
@param 无
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void idle_app_close_module()
|
||||
{
|
||||
#if LOW_POWER_IN_IDLE
|
||||
is_idle_flag = 1;
|
||||
|
||||
#if (TCFG_SD0_ENABLE || TCFG_SD1_ENABLE)
|
||||
sdx_dev_detect_timer_del();
|
||||
#endif
|
||||
|
||||
#if (((TCFG_PC_ENABLE) && (!TCFG_USB_PORT_CHARGE)) || ((TCFG_USB_HOST_ENABLE) && (!TCFG_PC_ENABLE)))
|
||||
/* extern int usb_mount_offline(usb_dev usb_id); */
|
||||
usb_detect_timer_del();
|
||||
os_time_dly((TCFG_OTG_DET_INTERVAL + 9) / 10);
|
||||
if (usb_otg_online(0) == HOST_MODE) {
|
||||
#if TCFG_UDISK_ENABLE
|
||||
dev_manager_del("udisk0");
|
||||
usb_host_unmount(0);
|
||||
usb_h_sie_close(0);
|
||||
|
||||
/*
|
||||
经过测试发现,有相当一部分在DP/DM设成高阻状态下U盘的电流仍维持在
|
||||
20 ~ 30mA,需要把DP设成上拉,DM设成下拉,这些U盘的电流才能降到2mA
|
||||
以下。即有部分U盘需要主机维持在空闲时J状态才能进入suspend。
|
||||
*/
|
||||
gpio_set_mode(PORTUSB, PORT_PIN_0, PORT_INPUT_PULLUP_10K);//usb dp
|
||||
gpio_set_mode(PORTUSB, PORT_PIN_1, PORT_INPUT_PULLDOWN_10K);//usb dm
|
||||
|
||||
|
||||
/* usb_mount_offline(0); */
|
||||
#endif
|
||||
} else if (usb_otg_online(0) == SLAVE_MODE) {
|
||||
#if TCFG_PC_ENABLE
|
||||
usb_pause();
|
||||
|
||||
gpio_set_mode(PORTUSB, PORT_PIN_0 | PORT_PIN_1, PORT_HIGHZ);//usb dp |dm
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if TCFG_APP_LINEIN_EN
|
||||
linein_detect_timer_del();
|
||||
#endif
|
||||
|
||||
#if (TCFG_LOWPOWER_LOWPOWER_SEL == 0)
|
||||
suspend_some_peripheral();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /*LOW_POWER_IN_IDLE*/
|
||||
|
||||
|
||||
//power off前的ui处理
|
||||
#if (TCFG_UI_ENABLE)
|
||||
void power_off_wait_ui(void)
|
||||
{
|
||||
printf("[%s] TODO:power off wait ui ", __func__);
|
||||
power_off_ui_exit();
|
||||
}
|
||||
#else
|
||||
void power_off_wait_ui()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void idle_key_poweron_deal(int msg)
|
||||
{
|
||||
switch (msg) {
|
||||
case APP_MSG_KEY_POWER_ON:
|
||||
goto_poweron_cnt = 0;
|
||||
goto_poweron_flag = 1;
|
||||
break;
|
||||
case APP_MSG_KEY_POWER_ON_HOLD:
|
||||
printf("poweron flag:%d cnt:%d\n", goto_poweron_flag, goto_poweron_cnt);
|
||||
if (goto_poweron_flag) {
|
||||
goto_poweron_cnt++;
|
||||
if (goto_poweron_cnt >= POWER_ON_CNT) {
|
||||
goto_poweron_cnt = 0;
|
||||
goto_poweron_flag = 0;
|
||||
app_var.goto_poweroff_flag = 0;
|
||||
#if LOW_POWER_IN_IDLE
|
||||
idle_app_open_module();
|
||||
#endif
|
||||
app_var.play_poweron_tone = 0;
|
||||
app_send_message(APP_MSG_GOTO_MODE, APP_MODE_BT);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
enum {
|
||||
API_POWER_OFF,
|
||||
API_TWS_POWER_OFF,
|
||||
};
|
||||
|
||||
static void call_app_api(int api, int err)
|
||||
{
|
||||
switch (api) {
|
||||
case API_POWER_OFF:
|
||||
sys_enter_soft_poweroff(POWEROFF_NORMAL);
|
||||
break;
|
||||
case API_TWS_POWER_OFF:
|
||||
sys_enter_soft_poweroff(POWEROFF_NORMAL_TWS);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
TWS_SYNC_CALL_REGISTER(app_api_sync_call_entry) = {
|
||||
.uuid = 0x891E7CD3,
|
||||
.func = call_app_api,
|
||||
.task_name = "app_core",
|
||||
};
|
||||
#endif
|
||||
void idle_sub_mode_set(u8 mode)
|
||||
{
|
||||
idle_sub_mode = mode;
|
||||
}
|
||||
u8 idle_sub_mode_get()
|
||||
{
|
||||
return idle_sub_mode;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief poweroff 长按等待 关闭蓝牙
|
||||
@param 无
|
||||
@return 无
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void power_off_deal(int msg)
|
||||
{
|
||||
switch (msg) {
|
||||
case APP_MSG_KEY_POWER_OFF:
|
||||
case APP_MSG_KEY_POWER_OFF_HOLD:
|
||||
if (goto_poweroff_first_flag == 0) {
|
||||
goto_poweroff_first_flag = 1;
|
||||
goto_poweroff_cnt = 0;
|
||||
goto_poweroff_flag = 0;
|
||||
#if TCFG_APP_BT_EN
|
||||
if ((BT_STATUS_CONNECTING == bt_get_connect_status()) ||
|
||||
(BT_STATUS_TAKEING_PHONE == bt_get_connect_status()) ||
|
||||
(BT_STATUS_PLAYING_MUSIC == bt_get_connect_status())) {
|
||||
if ((bt_get_call_status() == BT_CALL_INCOMING) ||
|
||||
(bt_get_call_status() == BT_CALL_OUTGOING)) {
|
||||
log_info("key call reject\n");
|
||||
/* bt_cmd_prepare(USER_CTRL_HFP_CALL_HANGUP, 0, NULL); */
|
||||
goto_poweroff_first_flag = 0;
|
||||
goto_poweroff_flag = 0;
|
||||
break;
|
||||
} else if (bt_get_call_status() == BT_CALL_ACTIVE) {
|
||||
log_info("key call hangup\n");
|
||||
/* bt_cmd_prepare(USER_CTRL_HFP_CALL_HANGUP, 0, NULL); */
|
||||
goto_poweroff_first_flag = 0;
|
||||
goto_poweroff_flag = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bt_cmd_prepare(USER_CTRL_ALL_SNIFF_EXIT, 0, NULL);
|
||||
#endif
|
||||
goto_poweroff_flag = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
log_info("poweroff flag:%d cnt:%d\n", goto_poweroff_flag, goto_poweroff_cnt);
|
||||
|
||||
if (goto_poweroff_flag) {
|
||||
goto_poweroff_cnt++;
|
||||
|
||||
#if CONFIG_TWS_POWEROFF_SAME_TIME
|
||||
if (goto_poweroff_cnt == POWER_OFF_CNT) {
|
||||
#if TCFG_MIC_EFFECT_ENABLE
|
||||
if (mic_effect_player_runing()) {
|
||||
mic_effect_player_close();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
if (get_tws_sibling_connect_state()) {
|
||||
tws_api_sync_call_by_uuid(0x891E7CD3, API_TWS_POWER_OFF, 100);
|
||||
//sys_enter_soft_poweroff(POWEROFF_NORMAL_TWS);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
power_off_tone_play_flag = 1;
|
||||
sys_enter_soft_poweroff(POWEROFF_NORMAL);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (goto_poweroff_cnt >= POWER_OFF_CNT) {
|
||||
goto_poweroff_cnt = 0;
|
||||
#if TCFG_MIC_EFFECT_ENABLE
|
||||
if (mic_effect_player_runing()) {
|
||||
mic_effect_player_close();
|
||||
}
|
||||
#endif
|
||||
#if TCFG_APP_BT_EN
|
||||
sys_enter_soft_poweroff(POWEROFF_NORMAL);
|
||||
#else
|
||||
app_var.goto_poweroff_flag = 1;
|
||||
app_send_message2(APP_MSG_GOTO_MODE, APP_MODE_IDLE, IDLE_MODE_PLAY_POWEROFF);
|
||||
#endif
|
||||
}
|
||||
#endif /*CONFIG_TWS_POWEROFF_SAME_TIME*/
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief poweroff 立刻关机
|
||||
@param 无
|
||||
@return 无
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void power_off_instantly()
|
||||
{
|
||||
if (goto_poweroff_first_flag == 0) {
|
||||
goto_poweroff_first_flag = 1;
|
||||
} else {
|
||||
puts("power_off_instantly had call\n");
|
||||
return;
|
||||
}
|
||||
#if TCFG_APP_BT_EN
|
||||
if ((BT_STATUS_CONNECTING == bt_get_connect_status()) ||
|
||||
(BT_STATUS_TAKEING_PHONE == bt_get_connect_status()) ||
|
||||
(BT_STATUS_PLAYING_MUSIC == bt_get_connect_status())) {
|
||||
if ((bt_get_call_status() == BT_CALL_INCOMING) ||
|
||||
(bt_get_call_status() == BT_CALL_OUTGOING)) {
|
||||
log_info("key call reject\n");
|
||||
/* bt_cmd_prepare(USER_CTRL_HFP_CALL_HANGUP, 0, NULL); */
|
||||
return;
|
||||
} else if (bt_get_call_status() == BT_CALL_ACTIVE) {
|
||||
log_info("key call hangup\n");
|
||||
/* bt_cmd_prepare(USER_CTRL_HFP_CALL_HANGUP, 0, NULL); */
|
||||
return;
|
||||
}
|
||||
}
|
||||
bt_cmd_prepare(USER_CTRL_ALL_SNIFF_EXIT, 0, NULL);
|
||||
#endif
|
||||
|
||||
#if TCFG_USER_TWS_ENABLE && CONFIG_TWS_POWEROFF_SAME_TIME
|
||||
if (get_tws_sibling_connect_state()) {
|
||||
sys_enter_soft_poweroff(POWEROFF_NORMAL_TWS);
|
||||
} else {
|
||||
sys_enter_soft_poweroff(POWEROFF_NORMAL);
|
||||
}
|
||||
#else
|
||||
#if TCFG_APP_BT_EN
|
||||
sys_enter_soft_poweroff(POWEROFF_NORMAL);
|
||||
#else
|
||||
app_var.goto_poweroff_flag = 1;
|
||||
app_send_message2(APP_MSG_GOTO_MODE, APP_MODE_IDLE, IDLE_MODE_PLAY_POWEROFF);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void app_idle_enter_softoff(void)
|
||||
{
|
||||
//power off前的ui处理
|
||||
power_off_wait_ui();
|
||||
//ui_update_status(STATUS_POWEROFF);
|
||||
|
||||
#if TCFG_CHARGE_ENABLE
|
||||
if (get_lvcmp_det() && (0 == get_charge_full_flag())) {
|
||||
log_info("charge inset, system reset!\n");
|
||||
cpu_reset();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if TCFG_SMART_VOICE_ENABLE && !TCFG_AUDIO_ASR_DEVELOP
|
||||
audio_smart_voice_detect_close();
|
||||
#endif
|
||||
|
||||
//关机前先关dac
|
||||
dac_power_off();
|
||||
|
||||
power_set_soft_poweroff();
|
||||
}
|
||||
|
||||
struct app_mode *app_enter_idle_mode(int arg)
|
||||
{
|
||||
int msg[16];
|
||||
struct app_mode *next_mode;
|
||||
|
||||
app_idle_init(arg);
|
||||
|
||||
while (1) {
|
||||
if (!app_get_message(msg, ARRAY_SIZE(msg), idle_mode_key_table)) {
|
||||
continue;
|
||||
}
|
||||
next_mode = app_mode_switch_handler(msg);
|
||||
if (next_mode) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (msg[0]) {
|
||||
case MSG_FROM_APP:
|
||||
idle_app_msg_handler(msg + 1);
|
||||
break;
|
||||
case MSG_FROM_DEVICE:
|
||||
break;
|
||||
}
|
||||
|
||||
app_default_msg_handler(msg);
|
||||
}
|
||||
|
||||
app_idle_exit();
|
||||
|
||||
return next_mode;
|
||||
}
|
||||
|
||||
void app_power_off(void *priv)
|
||||
{
|
||||
app_idle_enter_softoff();
|
||||
}
|
||||
|
||||
static int app_power_off_tone_cb(void *priv, enum stream_event event)
|
||||
{
|
||||
if (event == STREAM_EVENT_STOP) {
|
||||
app_idle_enter_softoff();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int app_idle_init(int param)
|
||||
{
|
||||
/* printf("idle_mode_enter: %d\n", param); */
|
||||
|
||||
#if LOW_POWER_IN_IDLE
|
||||
idle_app_close_module();
|
||||
#endif
|
||||
|
||||
idle_sub_mode_set(param);
|
||||
switch (param) {
|
||||
case IDLE_MODE_PLAY_POWEROFF:
|
||||
#if TCFG_UI_ENABLE
|
||||
power_off_ui_enter();
|
||||
#endif
|
||||
if (app_var.goto_poweroff_flag) {
|
||||
syscfg_write(CFG_MUSIC_VOL, &app_var.music_volume, 2);
|
||||
//如果开启了VM配置项暂存RAM功能则在关机前保存数据到vm_flash
|
||||
if (get_vm_ram_storage_enable() || get_vm_ram_storage_in_irq_enable()) {
|
||||
vm_flush2flash(1);
|
||||
}
|
||||
os_taskq_flush();
|
||||
int ret = play_tone_file_callback(get_tone_files()->power_off, NULL,
|
||||
app_power_off_tone_cb);
|
||||
printf("power_off tone play ret:%d", ret);
|
||||
if (ret) {
|
||||
if (app_var.goto_poweroff_flag) {
|
||||
log_info("power_off tone play err,enter soft poweroff");
|
||||
app_idle_enter_softoff();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IDLE_MODE_WAIT_POWEROFF:
|
||||
os_taskq_flush();
|
||||
syscfg_write(CFG_MUSIC_VOL, &app_var.music_volume, 2);
|
||||
break;
|
||||
case IDLE_MODE_CHARGE:
|
||||
break;
|
||||
}
|
||||
|
||||
app_send_message(APP_MSG_ENTER_MODE, APP_MODE_IDLE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void app_idle_exit()
|
||||
{
|
||||
app_send_message(APP_MSG_EXIT_MODE, APP_MODE_IDLE);
|
||||
}
|
||||
|
||||
static int idle_mode_try_enter(int arg)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int idle_mode_try_exit()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct app_mode_ops idle_mode_ops = {
|
||||
.try_enter = idle_mode_try_enter,
|
||||
.try_exit = idle_mode_try_exit,
|
||||
};
|
||||
|
||||
REGISTER_APP_MODE(idle_mode) = {
|
||||
.name = APP_MODE_IDLE,
|
||||
.index = 0xff,
|
||||
.ops = &idle_mode_ops,
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".idle_app_msg_handler.data.bss")
|
||||
#pragma data_seg(".idle_app_msg_handler.data")
|
||||
#pragma const_seg(".idle_app_msg_handler.text.const")
|
||||
#pragma code_seg(".idle_app_msg_handler.text")
|
||||
#endif
|
||||
#include "key_driver.h"
|
||||
#include "app_main.h"
|
||||
#include "init.h"
|
||||
#include "idle.h"
|
||||
|
||||
int idle_app_msg_handler(int *msg)
|
||||
{
|
||||
if (false == app_in_mode(APP_MODE_IDLE)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (msg[0]) {
|
||||
case APP_MSG_KEY_POWER_ON:
|
||||
case APP_MSG_KEY_POWER_ON_HOLD:
|
||||
idle_key_poweron_deal(msg[0]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".idle_key_msg_table.data.bss")
|
||||
#pragma data_seg(".idle_key_msg_table.data")
|
||||
#pragma const_seg(".idle_key_msg_table.text.const")
|
||||
#pragma code_seg(".idle_key_msg_table.text")
|
||||
#endif
|
||||
#include "key_driver.h"
|
||||
#include "app_main.h"
|
||||
#include "init.h"
|
||||
|
||||
|
||||
#if TCFG_ADKEY_ENABLE
|
||||
//短按 //长按 //hold //长按抬起 //双击 //三击
|
||||
const int key_idle_ad_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_KEY_POWER_ON, APP_MSG_KEY_POWER_ON_HOLD, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ad_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ad_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ad_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ad_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ad_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ad_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ad_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ad_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ad_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
#endif
|
||||
|
||||
#if TCFG_IRKEY_ENABLE
|
||||
//短按 //长按 //hold //长按抬起 //双击 //三击
|
||||
const int key_idle_ir_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_KEY_POWER_ON, APP_MSG_KEY_POWER_ON_HOLD, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ir_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ir_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ir_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ir_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ir_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ir_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ir_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ir_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ir_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ir_num10_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ir_num11_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ir_num12_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ir_num13_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ir_num14_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ir_num15_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ir_num16_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ir_num17_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ir_num18_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ir_num19_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_ir_num20_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
#endif
|
||||
|
||||
#if TCFG_IOKEY_ENABLE
|
||||
//短按 //长按 //hold //长按抬起 //双击 //三击
|
||||
const int key_idle_io_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_KEY_POWER_ON, APP_MSG_KEY_POWER_ON_HOLD, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_io_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_io_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_io_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_io_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_io_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_io_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_io_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_io_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_idle_io_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
#endif
|
||||
|
||||
const struct key_remap_table idle_mode_key_table[] = {
|
||||
#if TCFG_ADKEY_ENABLE
|
||||
{ .key_value = KEY_AD_NUM0, .remap_table = key_idle_ad_num0_msg_table },
|
||||
{ .key_value = KEY_AD_NUM1, .remap_table = key_idle_ad_num1_msg_table },
|
||||
{ .key_value = KEY_AD_NUM2, .remap_table = key_idle_ad_num2_msg_table },
|
||||
{ .key_value = KEY_AD_NUM3, .remap_table = key_idle_ad_num3_msg_table },
|
||||
{ .key_value = KEY_AD_NUM4, .remap_table = key_idle_ad_num4_msg_table },
|
||||
{ .key_value = KEY_AD_NUM5, .remap_table = key_idle_ad_num5_msg_table },
|
||||
{ .key_value = KEY_AD_NUM6, .remap_table = key_idle_ad_num6_msg_table },
|
||||
{ .key_value = KEY_AD_NUM7, .remap_table = key_idle_ad_num7_msg_table },
|
||||
{ .key_value = KEY_AD_NUM8, .remap_table = key_idle_ad_num8_msg_table },
|
||||
{ .key_value = KEY_AD_NUM9, .remap_table = key_idle_ad_num9_msg_table },
|
||||
#endif
|
||||
#if TCFG_IRKEY_ENABLE
|
||||
{ .key_value = KEY_IR_NUM0, .remap_table = key_idle_ir_num0_msg_table },
|
||||
{ .key_value = KEY_IR_NUM1, .remap_table = key_idle_ir_num1_msg_table },
|
||||
{ .key_value = KEY_IR_NUM2, .remap_table = key_idle_ir_num2_msg_table },
|
||||
{ .key_value = KEY_IR_NUM3, .remap_table = key_idle_ir_num3_msg_table },
|
||||
{ .key_value = KEY_IR_NUM4, .remap_table = key_idle_ir_num4_msg_table },
|
||||
{ .key_value = KEY_IR_NUM5, .remap_table = key_idle_ir_num5_msg_table },
|
||||
{ .key_value = KEY_IR_NUM6, .remap_table = key_idle_ir_num6_msg_table },
|
||||
{ .key_value = KEY_IR_NUM7, .remap_table = key_idle_ir_num7_msg_table },
|
||||
{ .key_value = KEY_IR_NUM8, .remap_table = key_idle_ir_num8_msg_table },
|
||||
{ .key_value = KEY_IR_NUM9, .remap_table = key_idle_ir_num9_msg_table },
|
||||
{ .key_value = KEY_IR_NUM10, .remap_table = key_idle_ir_num10_msg_table },
|
||||
{ .key_value = KEY_IR_NUM11, .remap_table = key_idle_ir_num11_msg_table },
|
||||
{ .key_value = KEY_IR_NUM12, .remap_table = key_idle_ir_num12_msg_table },
|
||||
{ .key_value = KEY_IR_NUM13, .remap_table = key_idle_ir_num13_msg_table },
|
||||
{ .key_value = KEY_IR_NUM14, .remap_table = key_idle_ir_num14_msg_table },
|
||||
{ .key_value = KEY_IR_NUM15, .remap_table = key_idle_ir_num15_msg_table },
|
||||
{ .key_value = KEY_IR_NUM16, .remap_table = key_idle_ir_num16_msg_table },
|
||||
{ .key_value = KEY_IR_NUM17, .remap_table = key_idle_ir_num17_msg_table },
|
||||
{ .key_value = KEY_IR_NUM18, .remap_table = key_idle_ir_num18_msg_table },
|
||||
{ .key_value = KEY_IR_NUM19, .remap_table = key_idle_ir_num19_msg_table },
|
||||
{ .key_value = KEY_IR_NUM20, .remap_table = key_idle_ir_num20_msg_table },
|
||||
#endif
|
||||
#if TCFG_IOKEY_ENABLE
|
||||
{ .key_value = KEY_IO_NUM0, .remap_table = key_idle_io_num0_msg_table },
|
||||
{ .key_value = KEY_IO_NUM1, .remap_table = key_idle_io_num1_msg_table },
|
||||
{ .key_value = KEY_IO_NUM2, .remap_table = key_idle_io_num2_msg_table },
|
||||
{ .key_value = KEY_IO_NUM3, .remap_table = key_idle_io_num3_msg_table },
|
||||
{ .key_value = KEY_IO_NUM4, .remap_table = key_idle_io_num4_msg_table },
|
||||
{ .key_value = KEY_IO_NUM5, .remap_table = key_idle_io_num5_msg_table },
|
||||
{ .key_value = KEY_IO_NUM6, .remap_table = key_idle_io_num6_msg_table },
|
||||
{ .key_value = KEY_IO_NUM7, .remap_table = key_idle_io_num7_msg_table },
|
||||
{ .key_value = KEY_IO_NUM8, .remap_table = key_idle_io_num8_msg_table },
|
||||
{ .key_value = KEY_IO_NUM9, .remap_table = key_idle_io_num9_msg_table },
|
||||
#endif
|
||||
{ .key_value = 0xff }
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".key_tone.data.bss")
|
||||
#pragma data_seg(".key_tone.data")
|
||||
#pragma const_seg(".key_tone.text.const")
|
||||
#pragma code_seg(".key_tone.text")
|
||||
#endif
|
||||
#include "fs/resfile.h"
|
||||
#include "app_main.h"
|
||||
#include "app_tone.h"
|
||||
#include "key_driver.h"
|
||||
|
||||
static u8 g_have_key_tone_file = 0;
|
||||
|
||||
static int key_tone_msg_handler(int *msg)
|
||||
{
|
||||
struct key_event *key = (struct key_event *)msg;
|
||||
|
||||
if (app_in_mode(APP_MODE_IDLE)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (g_have_key_tone_file == 0) {
|
||||
char file_path[48];
|
||||
strncpy(file_path, FLASH_RES_PATH, sizeof(file_path) - 1);
|
||||
strncpy(file_path + strlen(FLASH_RES_PATH), get_tone_files()->key_tone, sizeof(file_path) - strlen(FLASH_RES_PATH) - 1);
|
||||
void *file = resfile_open(file_path);
|
||||
if (file) {
|
||||
g_have_key_tone_file = 1;
|
||||
resfile_close(file);
|
||||
} else {
|
||||
g_have_key_tone_file = 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
/*printf("key_tone_msg_handler: %d, %d\n", key->event, g_have_key_tone_file);*/
|
||||
|
||||
switch (key->event) {
|
||||
case KEY_ACTION_HOLD:
|
||||
case KEY_ACTION_HOLD_3SEC:
|
||||
case KEY_ACTION_HOLD_5SEC:
|
||||
break;
|
||||
default:
|
||||
if (g_have_key_tone_file == 1) {
|
||||
play_key_tone_file(get_tone_files()->key_tone);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
APP_MSG_HANDLER(key_tone_msg_entry) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_KEY,
|
||||
.handler = key_tone_msg_handler,
|
||||
};
|
||||
@@ -0,0 +1,297 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".mic_effect.data.bss")
|
||||
#pragma data_seg(".mic_effect.data")
|
||||
#pragma const_seg(".mic_effect.text.const")
|
||||
#pragma code_seg(".mic_effect.text")
|
||||
#endif
|
||||
#include "system/includes.h"
|
||||
#include "jlstream.h"
|
||||
#include "effects/audio_echo.h"
|
||||
#include "effects/effects_adj.h"
|
||||
#include "media/audio_general.h"
|
||||
#include "media/audio_def.h"
|
||||
#include "volume_node.h"
|
||||
#include "app_main.h"
|
||||
#include "mic_effect.h"
|
||||
#include "app_config.h"
|
||||
#include "fm_api.h"
|
||||
|
||||
static void mic_effect_ram_code_load();
|
||||
static void mic_effect_ram_code_unload();
|
||||
struct mic_effect_player {
|
||||
struct jlstream *stream;
|
||||
s16 dvol;
|
||||
u8 dvol_index;
|
||||
unsigned int echo_delay; //回声的延时时间 0-300ms
|
||||
unsigned int echo_decayval; // 0-70%
|
||||
|
||||
};
|
||||
|
||||
u8 vol_table[] = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
|
||||
static struct mic_effect_player *g_mic_effect_player = NULL;
|
||||
|
||||
static u16 mic_irq_point_unit = AUDIO_ADC_IRQ_POINTS;
|
||||
void mic_effect_set_irq_point_unit(u16 point_unit)
|
||||
{
|
||||
mic_irq_point_unit = point_unit;
|
||||
}
|
||||
|
||||
static void mic_effect_player_callback(void *private_data, int event)
|
||||
{
|
||||
struct mic_effect_player *player = g_mic_effect_player;
|
||||
struct jlstream *stream = (struct jlstream *)private_data;
|
||||
|
||||
switch (event) {
|
||||
case STREAM_EVENT_START:
|
||||
char *vol_name = "VolEff";
|
||||
struct volume_cfg cfg = {0};
|
||||
cfg.bypass = VOLUME_NODE_CMD_SET_VOL;
|
||||
cfg.cur_vol = app_var.mic_eff_volume;
|
||||
jlstream_set_node_param(NODE_UUID_VOLUME_CTRLER, vol_name, (void *)&cfg, sizeof(struct volume_cfg));
|
||||
break;
|
||||
}
|
||||
}
|
||||
int mic_effect_player_open()
|
||||
{
|
||||
#if TCFG_APP_FM_EN
|
||||
if (g_mic_effect_player || get_fm_scan_status()) { //fm搜台中不能开混响
|
||||
#else
|
||||
if (g_mic_effect_player) {
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
mic_effect_ram_code_load();
|
||||
int err;
|
||||
struct mic_effect_player *player;
|
||||
|
||||
u16 uuid = jlstream_event_notify(STREAM_EVENT_GET_PIPELINE_UUID, (int)"mic_effect");
|
||||
if (uuid == 0) {
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
player = malloc(sizeof(*player));
|
||||
if (!player) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
player->stream = jlstream_pipeline_parse_by_node_name(uuid, "IIS0_RX1");
|
||||
if (!player->stream) {
|
||||
player->stream = jlstream_pipeline_parse(uuid, NODE_UUID_ADC);
|
||||
}
|
||||
|
||||
if (!player->stream) {
|
||||
err = -ENOMEM;
|
||||
goto __exit0;
|
||||
}
|
||||
|
||||
|
||||
//设置中断点数
|
||||
jlstream_node_ioctl(player->stream, NODE_UUID_SOURCE, NODE_IOC_SET_PRIV_FMT, mic_irq_point_unit);
|
||||
jlstream_node_ioctl(player->stream, NODE_UUID_VOCAL_TRACK_SYNTHESIS, NODE_IOC_SET_PRIV_FMT, mic_irq_point_unit);//四声道时,指定声道合并单个声道的点数
|
||||
jlstream_set_callback(player->stream, player->stream, mic_effect_player_callback);
|
||||
jlstream_set_scene(player->stream, STREAM_SCENE_MIC_EFFECT);
|
||||
jlstream_add_thread(player->stream, "mic_effect1");
|
||||
if (CONFIG_JLSTREAM_MULTI_THREAD_ENABLE) {
|
||||
jlstream_add_thread(player->stream, "mic_effect2");
|
||||
}
|
||||
|
||||
err = jlstream_start(player->stream);
|
||||
if (err) {
|
||||
goto __exit1;
|
||||
}
|
||||
|
||||
//记录echo、Dvol节点的参数 供按键调节使用
|
||||
echo_param_tool_set echo_cfg = {0};
|
||||
char *node_name = "EchoEff"; //节点名称(节点内的第一参数,用户自定义,长度小于等于15byte)
|
||||
int ret = jlstream_read_form_data(0, node_name, 0, &echo_cfg);
|
||||
if (ret) {
|
||||
printf("read echo parm delay %d\n", echo_cfg.parm.delay);
|
||||
player->echo_delay = echo_cfg.parm.delay;
|
||||
player->echo_decayval = echo_cfg.parm.decayval;
|
||||
}
|
||||
|
||||
player->dvol = app_var.mic_eff_volume;
|
||||
player->dvol_index = player->dvol / 10;
|
||||
if (player->dvol_index >= sizeof(vol_table) / sizeof(vol_table[0])) {
|
||||
player->dvol_index = sizeof(vol_table) / sizeof(vol_table[0]) - 1;
|
||||
}
|
||||
printf("\n mic dvol %d \n", player->dvol);
|
||||
g_mic_effect_player = player;
|
||||
return 0;
|
||||
|
||||
__exit1:
|
||||
jlstream_release(player->stream);
|
||||
__exit0:
|
||||
free(player);
|
||||
return err;
|
||||
}
|
||||
|
||||
bool mic_effect_player_runing()
|
||||
{
|
||||
return g_mic_effect_player != NULL;
|
||||
}
|
||||
|
||||
int mic_effect_player_is_playing()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void mic_effect_player_close()
|
||||
{
|
||||
struct mic_effect_player *player = g_mic_effect_player;
|
||||
|
||||
if (!player) {
|
||||
return;
|
||||
}
|
||||
jlstream_stop(player->stream, 0);
|
||||
jlstream_release(player->stream);
|
||||
|
||||
mic_effect_ram_code_unload();
|
||||
free(player);
|
||||
g_mic_effect_player = NULL;
|
||||
|
||||
jlstream_event_notify(STREAM_EVENT_CLOSE_PLAYER, (int)"mic_effect");
|
||||
}
|
||||
|
||||
static u8 pause_mark = 0;
|
||||
//混响暂停恢复接口
|
||||
void mic_effect_player_pause(u8 mark)
|
||||
{
|
||||
if (mark) { //暂停
|
||||
//混响在运行时才暂停(关闭)
|
||||
if (mic_effect_player_runing()) {
|
||||
mic_effect_player_close();
|
||||
pause_mark = 1;
|
||||
}
|
||||
} else {
|
||||
if (pause_mark) {
|
||||
mic_effect_player_open();
|
||||
}
|
||||
pause_mark = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(TCFG_CODE_RUN_RAM_MIC_EFF_CODE) && TCFG_CODE_RUN_RAM_MIC_EFF_CODE
|
||||
static spinlock_t mic_eff_code_ram;
|
||||
static u8 *mic_eff_code_run_addr = NULL;
|
||||
extern u32 __mic_eff_movable_slot_start[];
|
||||
extern u32 __mic_eff_movable_slot_end[];
|
||||
extern u8 __mic_eff_movable_region_start[];
|
||||
extern u8 __mic_eff_movable_region_end[];
|
||||
//代码动态加载
|
||||
static void mic_effect_ram_code_load()
|
||||
{
|
||||
int code_size = __mic_eff_movable_region_end - __mic_eff_movable_region_start;
|
||||
//printf("mic_eff code size %d\n", code_size);
|
||||
//mem_stats();
|
||||
if (code_size && !mic_eff_code_run_addr) {
|
||||
mic_eff_code_run_addr = phy_malloc(code_size);
|
||||
}
|
||||
spin_lock(&mic_eff_code_ram);
|
||||
if (mic_eff_code_run_addr) {
|
||||
//printf("mic_eff_code_run_addr: %x\n", (unsigned int)mic_eff_code_run_addr);
|
||||
code_movable_load(__mic_eff_movable_region_start, code_size, mic_eff_code_run_addr, __mic_eff_movable_slot_start, __mic_eff_movable_slot_end);
|
||||
}
|
||||
spin_unlock(&mic_eff_code_ram);
|
||||
}
|
||||
|
||||
|
||||
static void mic_effect_ram_code_unload()
|
||||
{
|
||||
if (mic_eff_code_run_addr) {
|
||||
//mem_stats();
|
||||
spin_lock(&mic_eff_code_ram);
|
||||
code_movable_unload(__mic_eff_movable_region_start, __mic_eff_movable_slot_start, __mic_eff_movable_slot_end);
|
||||
spin_unlock(&mic_eff_code_ram);
|
||||
phy_free(mic_eff_code_run_addr);
|
||||
|
||||
mic_eff_code_run_addr = NULL;
|
||||
//mem_stats();
|
||||
//printf("mic_eff code unload end\n");
|
||||
}
|
||||
}
|
||||
#else
|
||||
static void mic_effect_ram_code_load()
|
||||
{
|
||||
}
|
||||
|
||||
static void mic_effect_ram_code_unload()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
//echo 调节接口
|
||||
void mic_effect_set_echo_delay(u32 delay)
|
||||
{
|
||||
if (!g_mic_effect_player) {
|
||||
return;
|
||||
}
|
||||
echo_param_tool_set cfg = {0};
|
||||
/*
|
||||
*解析配置文件内效果配置
|
||||
* */
|
||||
char mode_index = 0; //模式序号(当前节点无多参数组,mode_index是0)
|
||||
char *node_name = "EchoEff"; //节点名称(节点内的第一参数,用户自定义,长度小于等于15byte)
|
||||
char cfg_index = 0; //目标配置项序号(当前节点无多参数组,cfg_index是0)
|
||||
int ret = jlstream_read_form_data(mode_index, node_name, cfg_index, &cfg);
|
||||
if (!ret) {
|
||||
printf("read parm err\n");
|
||||
return;
|
||||
}
|
||||
g_mic_effect_player->echo_delay = delay;
|
||||
cfg.parm.delay = g_mic_effect_player->echo_delay;
|
||||
|
||||
/*
|
||||
*将配置文件内获取得到的参数更新到目标节点
|
||||
* */
|
||||
jlstream_set_node_param(NODE_UUID_ECHO, node_name, &cfg, sizeof(cfg));
|
||||
}
|
||||
u32 mic_effect_get_echo_delay(void)
|
||||
{
|
||||
if (g_mic_effect_player) {
|
||||
return g_mic_effect_player->echo_delay;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//mic音量调节接口
|
||||
void mic_effect_set_dvol(u8 vol)
|
||||
{
|
||||
char *vol_name = "VolEff";
|
||||
struct volume_cfg cfg = {0};
|
||||
cfg.bypass = VOLUME_NODE_CMD_SET_VOL;
|
||||
cfg.cur_vol = vol;
|
||||
|
||||
if (g_mic_effect_player) {
|
||||
jlstream_set_node_param(NODE_UUID_VOLUME_CTRLER, vol_name, (void *)&cfg, sizeof(struct volume_cfg));
|
||||
g_mic_effect_player->dvol = vol;
|
||||
app_var.mic_eff_volume = vol;
|
||||
syscfg_write(CFG_MIC_EFF_VOLUME_INDEX, &app_var.mic_eff_volume, 2);
|
||||
}
|
||||
}
|
||||
u8 mic_effect_get_dvol(void)
|
||||
{
|
||||
|
||||
if (g_mic_effect_player) {
|
||||
return g_mic_effect_player->dvol;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
void mic_effect_dvol_up(void)
|
||||
{
|
||||
if (g_mic_effect_player) {
|
||||
if (g_mic_effect_player->dvol_index < sizeof(vol_table) / sizeof(vol_table[0]) - 1) {
|
||||
g_mic_effect_player->dvol_index++;
|
||||
mic_effect_set_dvol(vol_table[g_mic_effect_player->dvol_index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
void mic_effect_dvol_down(void)
|
||||
{
|
||||
if (g_mic_effect_player) {
|
||||
if (g_mic_effect_player->dvol_index) {
|
||||
g_mic_effect_player->dvol_index--;
|
||||
mic_effect_set_dvol(vol_table[g_mic_effect_player->dvol_index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,870 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".music.data.bss")
|
||||
#pragma data_seg(".music.data")
|
||||
#pragma const_seg(".music.text.const")
|
||||
#pragma code_seg(".music.text")
|
||||
#endif
|
||||
#include "system/includes.h"
|
||||
#include "music/music_player.h"
|
||||
#include "music/breakpoint.h"
|
||||
#include "app_action.h"
|
||||
#include "app_main.h"
|
||||
#include "bt.h"
|
||||
#include "tone_player.h"
|
||||
#include "key_event_deal.h"
|
||||
#include "audio_config.h"
|
||||
#include "bt_background.h"
|
||||
#include "default_event_handler.h"
|
||||
#include "app_online_cfg.h"
|
||||
#include "system/event.h"
|
||||
#include "app_music.h"
|
||||
#include "app_tone.h"
|
||||
#include "dev_status.h"
|
||||
#include "effect/effects_default_param.h"
|
||||
#include "scene_switch.h"
|
||||
#include "mic_effect.h"
|
||||
#include "app_config.h"
|
||||
#include "ui/ui_api.h"
|
||||
/* #include "jlui_app/ui_api.h" */
|
||||
#if (TCFG_LRC_LYRICS_ENABLE)
|
||||
#include "ui/jlui_app/lyrics_api.h"
|
||||
#endif
|
||||
|
||||
#if TCFG_APP_MUSIC_EN
|
||||
//切歌切模式是否保持倍速播放的状态
|
||||
#define MUSIC_PLAYBACK_SPEED_KEEP 0
|
||||
|
||||
//切歌切模式是否保持变调的状态
|
||||
#define MUSIC_PLAYBACK_PITCH_KEEP 0
|
||||
|
||||
static u8 music_idle_flag = 1;
|
||||
|
||||
|
||||
|
||||
struct __music music_hdl = {
|
||||
.speed_mode = PLAY_SPEED_1,
|
||||
.pitch_mode = PITCH_0,
|
||||
};
|
||||
#define __this (&music_hdl)
|
||||
|
||||
|
||||
#if LIB_SUPPORT_MULTI_SECTOER_READ
|
||||
OS_MUTEX pre_read_mutex;
|
||||
char *prebuf = NULL;
|
||||
#endif
|
||||
|
||||
|
||||
//设备提示音使能
|
||||
#if (MUSIC_DEVICE_TONE_EN)
|
||||
struct __dev_tone {
|
||||
char *logo;
|
||||
char *phy_logo;
|
||||
u16 index;
|
||||
};
|
||||
|
||||
enum {
|
||||
///0x1000起始为了不要跟提示音的IDEX_TONE_重叠了
|
||||
DEVICE_INDEX_UDISK = 0x1000,
|
||||
DEVICE_INDEX_UDISK_REC,
|
||||
DEVICE_INDEX_SD0,
|
||||
DEVICE_INDEX_SD0_REC,
|
||||
DEVICE_INDEX_SD1,
|
||||
DEVICE_INDEX_SD1_REC,
|
||||
};
|
||||
const struct __dev_tone device_tone[] = {
|
||||
{"udisk0", "udisk0", DEVICE_INDEX_UDISK} ,
|
||||
{"udisk0_rec", "udisk0", DEVICE_INDEX_UDISK_REC} ,
|
||||
{"sd0", "sd0", DEVICE_INDEX_SD0} ,
|
||||
{"sd0_rec", "sd0", DEVICE_INDEX_SD0_REC} ,
|
||||
{"sd1", "sd1", DEVICE_INDEX_SD1} ,
|
||||
{"sd1_rec", "sd1", DEVICE_INDEX_SD1_REC} ,
|
||||
};
|
||||
|
||||
static int music_tone_play_end_callback(void *priv, enum stream_event event);
|
||||
int music_device_tone_play(char *logo)
|
||||
{
|
||||
if (logo == NULL) {
|
||||
return false;
|
||||
}
|
||||
int ret = 0;
|
||||
printf("__this->device_tone_dev = %s, logo =%s\n", __this->device_tone_dev, logo);
|
||||
char *phy_logo = dev_manager_get_phy_logo(dev_manager_find_spec(logo, 0));
|
||||
if (phy_logo && (strcmp(__this->device_tone_dev, phy_logo) == 0)) {
|
||||
log_i("[%s, %d]the same phy dev, no need device tone!!\n", logo, __LINE__);
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < ARRAY_SIZE(device_tone); i++) {
|
||||
if (strcmp(device_tone[i].logo, logo) == 0) {
|
||||
log_i("[%s, %d]device_tone play \n", logo, __LINE__);
|
||||
memset(__this->device_tone_dev, 0, sizeof(__this->device_tone_dev));
|
||||
memcpy(__this->device_tone_dev, device_tone[i].phy_logo, strlen(device_tone[i].phy_logo));
|
||||
#if TCFG_TONE2TWS_ENABLE
|
||||
ret = tws_play_tone_file_callback(device_tone[i].tone_path, 1, music_tone_play_end_callback, (void *)device_tone[i].index, 400);
|
||||
if (ret)
|
||||
#endif
|
||||
{
|
||||
if (device_tone[i].index < DEVICE_INDEX_SD0) {
|
||||
ret = play_tone_file_callback(get_tone_files()->device_udisk, (void *)device_tone[i].index, music_tone_play_end_callback);
|
||||
} else {
|
||||
ret = play_tone_file_callback(get_tone_files()->device_sd, (void *)device_tone[i].index, music_tone_play_end_callback);
|
||||
}
|
||||
if (ret) { //提示音播放失败
|
||||
music_tone_play_end_callback((void *)device_tone[i].index, STREAM_EVENT_NONE);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
log_i("[%s, %d]device_tone play \n", logo, __LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
/* extern const u8 music_key_table[][KEY_EVENT_MAX]; */
|
||||
|
||||
static u8 music_idle_query()
|
||||
{
|
||||
return music_idle_flag;
|
||||
}
|
||||
REGISTER_LP_TARGET(music_lp_target) = {
|
||||
.name = "music",
|
||||
.is_idle = music_idle_query,
|
||||
};
|
||||
|
||||
__attribute__((weak))
|
||||
void music_player_get_sd_music_name(char *src)
|
||||
{
|
||||
}
|
||||
|
||||
static void music_save_breakpoint(int save_dec_bp)
|
||||
{
|
||||
char *logo = NULL;
|
||||
if (__this->player_hd) {
|
||||
logo = dev_manager_get_logo(__this->player_hd->dev);
|
||||
}
|
||||
///save breakpoint, 只保存文件信息
|
||||
if (music_player_get_playing_breakpoint(__this->player_hd, __this->breakpoint, save_dec_bp) == true) {
|
||||
breakpoint_vm_write(__this->breakpoint, logo);
|
||||
}
|
||||
}
|
||||
|
||||
/*获取music app当前播放的设备*/
|
||||
char *music_app_get_dev_cur(void)
|
||||
{
|
||||
if (__this->player_hd && __this->player_hd->dev) {
|
||||
return dev_manager_get_logo(__this->player_hd->dev);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*获取music app当前的断点地址*/
|
||||
struct audio_dec_breakpoint *music_app_get_dbp_addr(void)
|
||||
{
|
||||
if (__this && __this->breakpoint) {
|
||||
return &(__this->breakpoint->dbp);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*获取music app当前播放的句柄*/
|
||||
struct music_player *music_app_get_cur_hdl(void)
|
||||
{
|
||||
return __this->player_hd;
|
||||
}
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief music 模式切换前参数设置
|
||||
@param type:播放方式,暂时支持:
|
||||
MUSIC_TASK_START_BY_NORMAL:首次播放按照正常断点播放
|
||||
MUSIC_TASK_START_BY_SCLUST:首次播放按照簇号播放
|
||||
val:播放参数
|
||||
@return
|
||||
@note 首次播放执行参考music_player_play_start接口
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void music_task_set_parm(u8 type, int val)
|
||||
{
|
||||
__this->task_parm.type = type;
|
||||
__this->task_parm.val = val;
|
||||
}
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief music 模式首次播放
|
||||
@param 无
|
||||
@return
|
||||
@note 切换到音乐模式前可以通过接口music_task_set_parm设置参数,
|
||||
进入音乐模式后会按照对应参数播放
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void music_player_play_start(void)
|
||||
{
|
||||
switch (__this->task_parm.type) {
|
||||
case MUSIC_TASK_START_BY_NORMAL:
|
||||
log_i("MUSIC_TASK_START_BY_NORMAL\n");
|
||||
app_send_message(APP_MSG_MUSIC_PLAY_START, 0);
|
||||
break;
|
||||
case MUSIC_TASK_START_BY_SCLUST:
|
||||
log_i("MUSIC_TASK_START_BY_SCLUST\n");
|
||||
/* app_send_message(APP_MSG_MUSIC_PLAY_START_BY_SCLUST, 0); */
|
||||
app_send_message(APP_MSG_MUSIC_PLAY_START_BY_SCLUST, __this->task_parm.val);
|
||||
break;
|
||||
default:
|
||||
log_i("other MUSIC_TASK_START!!!\n");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief 录音模式提示音结束处理
|
||||
@param 无
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int music_tone_play_end_callback(void *priv, enum stream_event event)
|
||||
{
|
||||
u32 index = (u32)priv;
|
||||
char *logo = NULL;
|
||||
|
||||
if (false == app_in_mode(APP_MODE_MUSIC)) {
|
||||
log_e("tone callback task out \n");
|
||||
return 0;
|
||||
}
|
||||
switch (event) {
|
||||
case STREAM_EVENT_NONE:
|
||||
case STREAM_EVENT_STOP:
|
||||
switch (index) {
|
||||
#if (MUSIC_DEVICE_TONE_EN)
|
||||
case DEVICE_INDEX_UDISK:
|
||||
case DEVICE_INDEX_UDISK_REC:
|
||||
case DEVICE_INDEX_SD0:
|
||||
case DEVICE_INDEX_SD0_REC:
|
||||
case DEVICE_INDEX_SD1:
|
||||
case DEVICE_INDEX_SD1_REC:
|
||||
for (int i = 0; i < ARRAY_SIZE(device_tone); i++) {
|
||||
if (index == device_tone[i].index) {
|
||||
logo = device_tone[i].logo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
app_send_message(APP_MSG_MUSIC_PLAY_START_BY_DEV, (int)logo);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
///提示音播放结束, 启动播放器播放
|
||||
music_player_play_start();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*根据播放文件的格式动态开启SD卡常活动状态*/
|
||||
static void music_set_sd_keep_active(char *logo)
|
||||
{
|
||||
struct imount *mount_hdl = NULL;
|
||||
if (logo) {
|
||||
if ((!memcmp(logo, "sd0", strlen("sd0")))
|
||||
|| (!memcmp(logo, "sd1", strlen("sd1")))) {
|
||||
struct file_player *file_play_hd = get_music_file_player();
|
||||
mount_hdl = dev_manager_get_mount_hdl(dev_manager_find_spec(logo, 0));
|
||||
if (file_play_hd) {
|
||||
if (file_play_hd->stream->coding_type == AUDIO_CODING_WAV
|
||||
|| file_play_hd->stream->coding_type == AUDIO_CODING_DTS
|
||||
|| file_play_hd->stream->coding_type == AUDIO_CODING_FLAC
|
||||
|| file_play_hd->stream->coding_type == AUDIO_CODING_APE) {
|
||||
dev_ioctl(mount_hdl->dev.fd, IOCTL_SET_ACTIVE_STATUS, 1);
|
||||
log_i("sd set active status 1\n");
|
||||
} else {
|
||||
dev_ioctl(mount_hdl->dev.fd, IOCTL_SET_ACTIVE_STATUS, 0);
|
||||
log_i("sd set active status 0\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//非播放状态 关闭sd卡常活动状态
|
||||
mount_hdl = dev_manager_get_mount_hdl(dev_manager_find_spec("sd0", 0));
|
||||
if (mount_hdl) {
|
||||
dev_ioctl(mount_hdl->dev.fd, IOCTL_SET_ACTIVE_STATUS, 0);
|
||||
log_i("sd0 set active status 0\n");
|
||||
}
|
||||
mount_hdl = dev_manager_get_mount_hdl(dev_manager_find_spec("sd1", 0));
|
||||
if (mount_hdl) {
|
||||
dev_ioctl(mount_hdl->dev.fd, IOCTL_SET_ACTIVE_STATUS, 0);
|
||||
log_i("sd1 set active status 0\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief music 解码成功回调
|
||||
@param priv:私有参数, parm:暂时未用
|
||||
@return
|
||||
@note 此处可以做一些用户操作, 如断点保存, 显示, 获取播放信息等
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void music_player_play_success(void *priv, int parm)
|
||||
{
|
||||
char *logo = dev_manager_get_logo(__this->player_hd->dev);
|
||||
#if MUSIC_PLAYBACK_SPEED_KEEP
|
||||
struct file_player *file_player = get_music_file_player();
|
||||
music_file_set_speed(file_player, music_hdl.speed_mode); //设置播放速度
|
||||
#endif
|
||||
|
||||
#if MUSIC_PLAYBACK_PITCH_KEEP
|
||||
struct file_player *file_player = get_music_file_player();
|
||||
music_file_set_pitch(file_player, music_hdl.pitch_mode);
|
||||
#endif
|
||||
music_vocal_remover_update_parm();
|
||||
//播放WAV APE 格式歌曲,需设置SD卡常活动状态,提高读取速度
|
||||
music_set_sd_keep_active(logo);
|
||||
|
||||
log_i("cur filenum = %d\n", __this->player_hd->fsn->file_counter);
|
||||
log_i("totol filenum = %d\n", __this->player_hd->fsn->file_number);
|
||||
/* log_i("totol time = %d\n", music_player_get_dec_total_time()); */
|
||||
int unicode = 0;
|
||||
int name_buf_need_len = 128;
|
||||
u8 *music_file_name = zalloc(name_buf_need_len);
|
||||
int music_file_name_len = fget_name(__this->player_hd->file, music_file_name, name_buf_need_len);
|
||||
if ((music_file_name[0] == '\\') && (music_file_name[1] == 'U')) {
|
||||
unicode = 1;
|
||||
//music_file_name_len -= 2;
|
||||
log_i("cur file(unicode) = %s, len = %d, unicode = %d\n", music_file_name + 2, music_file_name_len - 2, unicode);
|
||||
/* put_buf(music_file_name, music_file_name_len + 2); */
|
||||
char *utf8 = zalloc(2 * name_buf_need_len);
|
||||
int file_len = Unicode2UTF8(utf8, (u16 *)music_file_name + 1, (music_file_name_len - 2) / 2);
|
||||
log_i(">>>[test]:filename = %s, len = %d\n", utf8, file_len);
|
||||
music_player_get_sd_music_name(utf8);
|
||||
UI_MSG_POST("up_music_name");
|
||||
if (utf8) {
|
||||
free(utf8);
|
||||
utf8 = NULL;
|
||||
}
|
||||
} else {
|
||||
log_i("cur file = %s, len = %d, unicode = %d\n", music_file_name, music_file_name_len, unicode);
|
||||
music_player_get_sd_music_name((char *)music_file_name);
|
||||
}
|
||||
log_i("\n");
|
||||
if (music_file_name) {
|
||||
free(music_file_name);
|
||||
}
|
||||
music_save_breakpoint(0);
|
||||
#if TCFG_LRC_LYRICS_ENABLE
|
||||
int analaz = music_player_lrc_analy_start(music_app_get_cur_hdl());
|
||||
#endif
|
||||
app_send_message2(APP_MSG_MUSIC_FILE_NUM_CHANGED, __this->player_hd->fsn->file_counter, __this->player_hd->fsn->file_number);
|
||||
|
||||
}
|
||||
|
||||
static void send_music_player_end_msg(void *parm)
|
||||
{
|
||||
__this->timer = 0;
|
||||
app_send_message(APP_MSG_MUSIC_PLAYER_END, (int)parm);
|
||||
}
|
||||
void ui_music_get_file_name()
|
||||
{
|
||||
int unicode = 0;
|
||||
int name_buf_need_len = 128;
|
||||
u8 *music_file_name = zalloc(name_buf_need_len);
|
||||
int music_file_name_len;
|
||||
if (!__this->player_hd->file) {
|
||||
if (music_file_name) {
|
||||
free(music_file_name);
|
||||
}
|
||||
return;
|
||||
}
|
||||
music_file_name_len = fget_name(__this->player_hd->file, music_file_name, name_buf_need_len);
|
||||
if ((music_file_name[0] == '\\') && (music_file_name[1] == 'U')) {
|
||||
unicode = 1;
|
||||
//music_file_name_len -= 2;
|
||||
log_i("cur file(unicode) = %s, len = %d, unicode = %d\n", music_file_name + 2, music_file_name_len - 2, unicode);
|
||||
/* put_buf(music_file_name, music_file_name_len + 2); */
|
||||
u8 *utf8 = zalloc(2 * name_buf_need_len);
|
||||
int file_len = Unicode2UTF8((char *)utf8, (u16 *)music_file_name + 1, (music_file_name_len - 2) / 2);
|
||||
log_i(">>>[test]:filename = %s, len = %d\n", utf8, file_len);
|
||||
music_player_get_sd_music_name((char *)utf8);
|
||||
/* UI_MSG_POST("UP_MUSIC_NAME:p=%4", utf8); */
|
||||
if (utf8) {
|
||||
free(utf8);
|
||||
utf8 = NULL;
|
||||
}
|
||||
} else {
|
||||
music_player_get_sd_music_name((char *)music_file_name);
|
||||
}
|
||||
|
||||
if (music_file_name) {
|
||||
free(music_file_name);
|
||||
}
|
||||
/* return utf8; */
|
||||
|
||||
}
|
||||
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief music 解码结束回调处理
|
||||
@param
|
||||
@return
|
||||
@note 此处统一将错误通过消息的方式发出, 在key msg中统一响应
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void music_player_play_end(void *priv, int parm)
|
||||
{
|
||||
if (parm) {
|
||||
if (__this->timer == 0) {
|
||||
__this->timer = sys_timeout_add((void *)parm, send_music_player_end_msg, 1000);
|
||||
}
|
||||
} else {
|
||||
app_send_message(APP_MSG_MUSIC_PLAYER_END, parm);
|
||||
}
|
||||
}
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief music 解码错误回调
|
||||
@param
|
||||
@return
|
||||
@note 此处统一将错误通过消息的方式发出, 在key msg中统一响应
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void music_player_decode_err(void *priv, int parm)
|
||||
{
|
||||
log_i("music_player_decode_err\n");
|
||||
///这里推出消息, 目的是在music主流程switch case统一入口
|
||||
/* app_task_put_key_msg(KEY_MUSIC_PLAYER_DEC_ERR, parm); */
|
||||
app_send_message(APP_MSG_MUSIC_DEC_ERR, parm);
|
||||
}
|
||||
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief music 播放器扫盘打断接口
|
||||
@param
|
||||
@return 1:打断当前扫描,0:正常扫描
|
||||
@note 设备扫描耗时长的情况下, 此接口提供打断机制
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int music_player_scandisk_break(void)
|
||||
{
|
||||
///注意:
|
||||
///需要break fsn的事件, 请在这里拦截,
|
||||
///需要结合MUSIC_PLAYER_ERR_FSCAN错误,做相应的处理
|
||||
int msg[32] = {0};
|
||||
const char *logo = NULL;
|
||||
char *evt_logo = NULL;
|
||||
struct key_event *key_evt = NULL;
|
||||
struct bt_event *bt_evt = NULL;
|
||||
int msg_from, msg_argc = 0;
|
||||
int *msg_argv = NULL;
|
||||
if (__this->scandisk_break) {//设备上下线直接打断
|
||||
return 1;
|
||||
}
|
||||
int res = os_taskq_accept(8, msg);
|
||||
if (res != OS_TASKQ) {
|
||||
return 0;
|
||||
}
|
||||
msg_from = msg[0];
|
||||
switch (msg[0]) {
|
||||
case MSG_FROM_DEVICE:
|
||||
switch (msg[1]) {
|
||||
case DRIVER_EVENT_FROM_SD0:
|
||||
case DRIVER_EVENT_FROM_SD1:
|
||||
case DRIVER_EVENT_FROM_SD2:
|
||||
evt_logo = (char *)msg[3];
|
||||
case DEVICE_EVENT_FROM_USB_HOST:
|
||||
if (!strncmp((char *)msg[3], "udisk", 5)) {
|
||||
evt_logo = (char *)msg[3];
|
||||
}
|
||||
msg_argc = 12;
|
||||
msg_argv = msg + 1;
|
||||
///设备上下线底层推出的设备逻辑盘符是跟跟音乐设备一致的(音乐/录音设备, 详细看接口注释)
|
||||
int str_len = 0;
|
||||
logo = music_player_get_phy_dev(__this->player_hd, &str_len);
|
||||
///响应设备插拔打断
|
||||
if (msg[2] == DEVICE_EVENT_OUT) {
|
||||
log_i("__func__ = %s logo=%s evt_logo=%s %d\n", __FUNCTION__, logo, evt_logo, str_len);
|
||||
if (logo && (0 == memcmp(logo, evt_logo, str_len))) {
|
||||
///相同的设备才响应
|
||||
__this->scandisk_break = 1;
|
||||
}
|
||||
} else if (msg[2] == DEVICE_EVENT_IN) {
|
||||
///响应新设备上线
|
||||
__this->scandisk_break = 1;
|
||||
}
|
||||
if (__this->scandisk_break == 0) {
|
||||
log_i("__func__ = %s DEVICE_EVENT_OUT TODO\n", __FUNCTION__);
|
||||
dev_status_event_filter(msg + 1);
|
||||
log_i("__func__ = %s DEVICE_EVENT_OUT OK\n", __FUNCTION__);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case MSG_FROM_BT_STACK:
|
||||
#if (TCFG_BT_BACKGROUND_ENABLE)
|
||||
bt_background_msg_forward_filter(msg);
|
||||
#endif
|
||||
break;
|
||||
case MSG_FROM_APP:
|
||||
msg_argc = 12; //按最大参数个数处理
|
||||
msg_argv = msg + 1;
|
||||
switch (msg[1]) {
|
||||
case APP_MSG_CHANGE_MODE:
|
||||
/* fall-through */
|
||||
case APP_MSG_GOTO_MODE:
|
||||
/* fall-through */
|
||||
case APP_MSG_GOTO_NEXT_MODE:
|
||||
//响应切换模式事件
|
||||
__this->scandisk_break = 1;
|
||||
break;
|
||||
//其他按键case 在这里增加
|
||||
}
|
||||
break;
|
||||
case MSG_FROM_KEY:
|
||||
int key_msg = app_key_event_remap(music_mode_key_table, msg + 1);
|
||||
msg_from = MSG_FROM_APP;
|
||||
msg[1] = key_msg;
|
||||
msg_argv = msg + 1;
|
||||
msg_argc = 12; //按最大参数个数处理
|
||||
switch (key_msg) {
|
||||
case APP_MSG_CHANGE_MODE:
|
||||
//响应切换模式事件
|
||||
__this->scandisk_break = 1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (__this->scandisk_break) {
|
||||
///查询到需要打断的事件, 返回1, 并且重新推送一次该事件,跑主循环处理流程
|
||||
app_send_message_from(msg_from, msg_argc, msg_argv);
|
||||
printf("scandisk_break!!!!!!\n");
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void scan_enter(struct __dev *dev)
|
||||
{
|
||||
__this->scandisk_mark = 1;
|
||||
}
|
||||
|
||||
static void scan_exit(struct __dev *dev)
|
||||
{
|
||||
__this->scandisk_mark = 0;
|
||||
}
|
||||
|
||||
static const struct __player_cb music_player_callback = {
|
||||
.start = music_player_play_success,
|
||||
.end = music_player_play_end,
|
||||
.err = music_player_decode_err,
|
||||
};
|
||||
|
||||
static const struct __scan_callback scan_cb = {
|
||||
.enter = scan_enter,
|
||||
.exit = scan_exit,
|
||||
.scan_break = music_player_scandisk_break,
|
||||
};
|
||||
|
||||
static int app_music_init()
|
||||
{
|
||||
int ret = 0;
|
||||
__this->music_busy = 0;
|
||||
music_idle_flag = 0;
|
||||
/* ui_update_status(STATUS_MUSIC_MODE); */
|
||||
|
||||
#if TCFG_MIC_EFFECT_ENABLE
|
||||
//切换mic eff irq points
|
||||
tone_player_stop();
|
||||
mic_effect_player_pause(1);
|
||||
mic_effect_set_irq_point_unit(AUDIO_ADC_IRQ_POINTS_MUSIC_MODE);
|
||||
mic_effect_player_pause(0);
|
||||
#endif
|
||||
|
||||
#if (TCFG_LRC_LYRICS_ENABLE)
|
||||
lyrics_init();
|
||||
#endif
|
||||
|
||||
///播放器初始化
|
||||
/* struct __player_parm parm = {0}; */
|
||||
/* parm.cb = &music_player_callback; */
|
||||
/* parm.scan_cb = &scan_cb; */
|
||||
/* music_player_creat(NULL, &parm); */
|
||||
__this->player_hd = music_player_creat();
|
||||
music_player_reg_scandisk_callback(__this->player_hd, &scan_cb);
|
||||
music_player_reg_dec_callback(__this->player_hd, &music_player_callback);
|
||||
///获取断点句柄, 后面所有断点读/写都需要用到
|
||||
__this->breakpoint = breakpoint_handle_creat();
|
||||
///初始化一些参数
|
||||
__this->file_err_counter = 0;
|
||||
__this->file_play_direct = 0;
|
||||
__this->scandisk_break = 0;
|
||||
memset(__this->device_tone_dev, 0, sizeof(__this->device_tone_dev));
|
||||
#if (MUSIC_DEVICE_TONE_EN)
|
||||
music_player_play_start();
|
||||
#else
|
||||
#if TCFG_TONE2TWS_ENABLE
|
||||
ret = tws_play_tone_file_callback(tone_table[IDEX_TONE_MUSIC], 1, music_tone_play_end_callback, (void *)IDEX_TONE_MUSIC, 400);
|
||||
if (ret)
|
||||
#endif
|
||||
{
|
||||
tone_player_stop();
|
||||
ret = play_tone_file_callback(get_tone_files()->music_mode, NULL, music_tone_play_end_callback);
|
||||
if (ret) {
|
||||
music_tone_play_end_callback(NULL, STREAM_EVENT_NONE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIB_SUPPORT_MULTI_SECTOER_READ
|
||||
os_mutex_create(&pre_read_mutex);
|
||||
if (!prebuf) {
|
||||
y_printf("\n >>>[test]:func = %s,line= %d\n", __FUNCTION__, __LINE__);
|
||||
prebuf = zalloc(MAX_READ_LEN);
|
||||
ASSERT(prebuf);
|
||||
/* last_pos = 0; */
|
||||
/* PosInBuf = 0; */
|
||||
}
|
||||
#endif
|
||||
|
||||
#if TCFG_USER_EMITTER_ENABLE
|
||||
extern u8 *get_cur_connect_emitter_mac_addr(void);
|
||||
void *bt_addr = get_cur_connect_emitter_mac_addr();
|
||||
if (bt_addr) {
|
||||
extern void emitter_open(u8 source);
|
||||
emitter_open(1); // 开启蓝牙发射
|
||||
}
|
||||
#endif
|
||||
|
||||
app_send_message(APP_MSG_ENTER_MODE, APP_MODE_MUSIC);
|
||||
#if (defined CONFIG_JL_UI_ENABLE)&&CONFIG_JL_UI_ENABLE
|
||||
UI_MSG_POST("up_music_status");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void app_music_exit()
|
||||
{
|
||||
music_save_breakpoint(1);
|
||||
music_player_stop(__this->player_hd, 1);
|
||||
breakpoint_handle_destroy(&__this->breakpoint);
|
||||
music_player_destroy(__this->player_hd);
|
||||
music_set_sd_keep_active(NULL);
|
||||
|
||||
#if TCFG_USER_EMITTER_ENABLE
|
||||
extern u8 *get_cur_connect_emitter_mac_addr(void);
|
||||
void *bt_addr = get_cur_connect_emitter_mac_addr();
|
||||
if (bt_addr) {
|
||||
extern void emitter_close(u8 source);
|
||||
emitter_close(1); // 关闭蓝牙发射
|
||||
}
|
||||
#endif
|
||||
|
||||
if (__this->timer) {
|
||||
sys_timeout_del(__this->timer);
|
||||
__this->timer = 0;
|
||||
}
|
||||
|
||||
__this->player_hd = NULL;
|
||||
music_idle_flag = 1;
|
||||
|
||||
#if LIB_SUPPORT_MULTI_SECTOER_READ
|
||||
os_mutex_del(&pre_read_mutex, 0);
|
||||
if (prebuf) {
|
||||
y_printf("\n >>>[test]:func = %s,line= %d\n", __FUNCTION__, __LINE__);
|
||||
free(prebuf);
|
||||
prebuf = NULL;
|
||||
}
|
||||
#endif
|
||||
#if TCFG_MIC_EFFECT_ENABLE
|
||||
//切换mic eff irq points
|
||||
mic_effect_player_pause(1);
|
||||
mic_effect_set_irq_point_unit(AUDIO_ADC_IRQ_POINTS);
|
||||
mic_effect_player_pause(0);
|
||||
#endif
|
||||
|
||||
app_send_message(APP_MSG_EXIT_MODE, APP_MODE_MUSIC);
|
||||
}
|
||||
|
||||
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief music 模式新设备上线处理
|
||||
@param 无
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void music_task_dev_online_start(char *in_logo)
|
||||
{
|
||||
if (false == app_in_mode(APP_MODE_MUSIC)) {
|
||||
log_e("not music mode \n");
|
||||
return ;
|
||||
}
|
||||
__this->music_busy = 1;
|
||||
u8 save = 0;
|
||||
char *logo = dev_manager_get_logo(__this->player_hd->dev);
|
||||
if (logo && __this->breakpoint) {
|
||||
///新设备上线, 先记录当前设备断点, 然后播放活动设备
|
||||
if (music_player_get_playing_breakpoint(__this->player_hd, __this->breakpoint, 1) == true) {
|
||||
save = 1;
|
||||
//这里不要直接记忆断点, 解码停了之后再记忆
|
||||
//breakpoint_vm_write(__this->breakpoint, logo);
|
||||
}
|
||||
}
|
||||
///停止解码,播放新活动设备
|
||||
music_player_stop(__this->player_hd, 1);
|
||||
if (save && __this->breakpoint) {
|
||||
breakpoint_vm_write(__this->breakpoint, logo);
|
||||
}
|
||||
__this->music_busy = 0;
|
||||
app_send_message(APP_MSG_MUSIC_MOUNT_PLAY_START, (int)in_logo);
|
||||
log_i("APP_MSG_MUSIC_PLAY_START AFTER MOUNT\n");
|
||||
//先挂载了设备再执行
|
||||
}
|
||||
|
||||
void music_set_start_auto_play(u8 on)
|
||||
{
|
||||
__this->auto_play = !!on;
|
||||
}
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief music 设备事件响应接口
|
||||
@param 无
|
||||
@return 1、当前消息已经处理,comomon不再做处理 0、common统一处理
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int music_device_msg_handler(int *msg)
|
||||
{
|
||||
__this->music_busy = 1;
|
||||
int err = 0;
|
||||
char *logo = NULL;
|
||||
char *evt_logo = NULL;
|
||||
switch (msg[0]) {
|
||||
case DRIVER_EVENT_FROM_SD0:
|
||||
case DRIVER_EVENT_FROM_SD1:
|
||||
case DRIVER_EVENT_FROM_SD2:
|
||||
evt_logo = (char *)msg[2];
|
||||
case DEVICE_EVENT_FROM_USB_HOST:
|
||||
if (!strncmp((char *)msg[2], "udisk", 5)) {
|
||||
evt_logo = (char *)msg[2];
|
||||
}
|
||||
int str_len = 0;
|
||||
logo = (char *)music_player_get_phy_dev(__this->player_hd, &str_len);
|
||||
log_i("evt_logo =%s, logo = %s len =%d\n", evt_logo, logo, str_len);
|
||||
if (msg[1] == DEVICE_EVENT_OUT) {
|
||||
if (__this->timer) {
|
||||
sys_timeout_del(__this->timer);
|
||||
__this->timer = 0;
|
||||
}
|
||||
if (logo == NULL) {
|
||||
break;
|
||||
}
|
||||
if (0 == memcmp(logo, evt_logo, str_len)) {
|
||||
///相同的设备才响应
|
||||
if (music_player_get_playing_breakpoint(__this->player_hd, __this->breakpoint, 1) == true) {
|
||||
dev_manager_set_valid_by_logo(logo, 0);///尽快将设备设置为无效设备
|
||||
breakpoint_vm_write(__this->breakpoint, logo);
|
||||
} else {
|
||||
dev_manager_set_valid_by_logo(logo, 0);///将设备设置为无效设备
|
||||
}
|
||||
if (__this->scandisk_mark) {//自己打断自己的扫描推消息出去,重启解码
|
||||
app_send_message(APP_MSG_MUSIC_PLAY_START, 0);
|
||||
__this->scandisk_break = 1;
|
||||
}
|
||||
memset(__this->device_tone_dev, 0, sizeof(__this->device_tone_dev));
|
||||
if (music_player_runing()) {
|
||||
|
||||
///停止解码,防止设备掉线后还继续使用
|
||||
music_player_stop(__this->player_hd, 1);
|
||||
///重新选择活动设备播放
|
||||
/* app_task_put_key_msg(KEY_MUSIC_PLAYER_START, 0);//卸载了设备再执行 */
|
||||
app_send_message(APP_MSG_MUSIC_PLAY_START, 0);
|
||||
log_i("KEY_MUSIC_PLAYER_START AFTER UMOUNT\n");
|
||||
}
|
||||
} else {
|
||||
if (!dev_manager_check_by_logo(evt_logo)) { //未成功的插入,打断原来播放需恢复
|
||||
if (!music_player_runing()) {
|
||||
app_send_message(APP_MSG_MUSIC_PLAY_START, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (__this->scandisk_mark) {
|
||||
__this->scandisk_break = 1;
|
||||
}
|
||||
#if (MUSIC_DEV_ONLINE_START_AFTER_MOUNT_EN == 0)
|
||||
music_task_dev_online_start(evt_logo);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
default://switch((u32)event->arg)
|
||||
break;
|
||||
}
|
||||
|
||||
__this->music_busy = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
struct app_mode *app_enter_music_mode(int arg)
|
||||
{
|
||||
int msg[16];
|
||||
struct app_mode *next_mode;
|
||||
|
||||
app_music_init();
|
||||
|
||||
if (__this->auto_play) {
|
||||
music_player_play_start();
|
||||
__this->auto_play = 0;
|
||||
}
|
||||
while (1) {
|
||||
if (!app_get_message(msg, ARRAY_SIZE(msg), music_mode_key_table)) {
|
||||
continue;
|
||||
}
|
||||
next_mode = app_mode_switch_handler(msg);
|
||||
if (next_mode) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (msg[0]) {
|
||||
case MSG_FROM_APP:
|
||||
music_app_msg_handler(msg + 1);
|
||||
break;
|
||||
case MSG_FROM_DEVICE:
|
||||
break;
|
||||
}
|
||||
|
||||
app_default_msg_handler(msg);
|
||||
}
|
||||
|
||||
app_music_exit();
|
||||
|
||||
return next_mode;
|
||||
}
|
||||
|
||||
static int music_mode_try_enter(int arg)
|
||||
{
|
||||
|
||||
if (dev_manager_get_total(1)) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int music_mode_try_exit()
|
||||
{
|
||||
return __this->music_busy;
|
||||
}
|
||||
|
||||
static const struct app_mode_ops music_mode_ops = {
|
||||
.try_enter = music_mode_try_enter,
|
||||
.try_exit = music_mode_try_exit,
|
||||
};
|
||||
|
||||
/*
|
||||
* 注册music模式
|
||||
*/
|
||||
REGISTER_APP_MODE(music_mode) = {
|
||||
.name = APP_MODE_MUSIC,
|
||||
.index = APP_MODE_MUSIC_INDEX,
|
||||
.ops = &music_mode_ops,
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,342 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".music_app_msg_handler.data.bss")
|
||||
#pragma data_seg(".music_app_msg_handler.data")
|
||||
#pragma const_seg(".music_app_msg_handler.text.const")
|
||||
#pragma code_seg(".music_app_msg_handler.text")
|
||||
#endif
|
||||
#include "key_driver.h"
|
||||
#include "app_main.h"
|
||||
#include "init.h"
|
||||
#include "dev_manager.h"
|
||||
#include "music/music_player.h"
|
||||
#include "music/breakpoint.h"
|
||||
#include "app_music.h"
|
||||
#include "scene_switch.h"
|
||||
#include "node_param_update.h"
|
||||
#include "clock_manager/clock_manager.h"
|
||||
|
||||
extern struct __music music_hdl;
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief music 模式解码错误处理
|
||||
@param err:错误码,详细错误码描述请看MUSIC_PLAYER错误码表枚举
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void music_player_err_deal(int err)
|
||||
{
|
||||
u16 msg = APP_MSG_NULL;
|
||||
char *logo = NULL;
|
||||
if (err != MUSIC_PLAYER_ERR_NULL && err != MUSIC_PLAYER_ERR_DECODE_FAIL) {
|
||||
music_hdl.file_err_counter = 0;///清除错误文件累计
|
||||
}
|
||||
|
||||
if (err != MUSIC_PLAYER_ERR_NULL && err != MUSIC_PLAYER_SUCC) {
|
||||
log_e("music player err = %d\n", err);
|
||||
}
|
||||
|
||||
switch (err) {
|
||||
case MUSIC_PLAYER_SUCC:
|
||||
music_hdl.file_err_counter = 0;
|
||||
break;
|
||||
case MUSIC_PLAYER_ERR_NULL:
|
||||
break;
|
||||
case MUSIC_PLAYER_ERR_POINT:
|
||||
/* fall-through */
|
||||
case MUSIC_PLAYER_ERR_NO_RAM:
|
||||
msg = APP_MSG_GOTO_NEXT_MODE;//退出音乐模式
|
||||
break;
|
||||
case MUSIC_PLAYER_ERR_DECODE_FAIL:
|
||||
if (music_hdl.file_err_counter >= music_hdl.player_hd->fsn->file_number) {
|
||||
music_hdl.file_err_counter = 0;
|
||||
dev_manager_set_valid_by_logo(dev_manager_get_logo(music_hdl.player_hd->dev), 0);///将设备设置为无效设备
|
||||
if (dev_manager_get_total(1) == 0) {//参数为1 :获取所有有效设备 参数0:获取所有设备
|
||||
msg = APP_MSG_GOTO_NEXT_MODE;//没有设备了,退出音乐模式
|
||||
} else {
|
||||
msg = APP_MSG_MUSIC_AUTO_NEXT_DEV;///所有文件都是错误的, 切换到下一个设备
|
||||
}
|
||||
} else {
|
||||
music_hdl.file_err_counter ++;
|
||||
if (music_hdl.file_play_direct == 0) {
|
||||
msg = APP_MSG_MUSIC_NEXT;//播放下一曲
|
||||
} else {
|
||||
msg = APP_MSG_MUSIC_PREV;//播放上一曲
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MUSIC_PLAYER_ERR_DEV_NOFOUND:
|
||||
log_e("MUSIC_PLAYER_ERR_DEV_NOFOUND \n");
|
||||
if (dev_manager_get_total(1) == 0) {//参数为1 :获取所有有效设备 参数0:获取所有设备
|
||||
msg = APP_MSG_GOTO_NEXT_MODE;///没有设备在线, 退出音乐模式
|
||||
} else {
|
||||
msg = APP_MSG_MUSIC_PLAY_FIRST;///没有找到指定设备, 播放之前的活动设备
|
||||
}
|
||||
break;
|
||||
|
||||
case MUSIC_PLAYER_ERR_FSCAN:
|
||||
///需要结合music_player_scandisk_break中处理的标志位处理
|
||||
if (music_hdl.scandisk_break) {
|
||||
music_hdl.scandisk_break = 0;
|
||||
///此处不做任何处理, 打断的事件已经重发, 由重发事件执行后续处理
|
||||
break;
|
||||
}
|
||||
case MUSIC_PLAYER_ERR_DEV_READ:
|
||||
log_e("MUSIC_PLAYER_ERR_DEV_READ \n");
|
||||
/* fall-through */
|
||||
case MUSIC_PLAYER_ERR_DEV_OFFLINE:
|
||||
log_e("MUSIC_PLAYER_ERR_DEV_OFFLINE \n");
|
||||
logo = dev_manager_get_logo(music_hdl.player_hd->dev);
|
||||
if (dev_manager_online_check_by_logo(logo, 1)) {
|
||||
///如果错误失败在线, 并且是播放过程中产生的,先记录下断点
|
||||
if (music_player_get_playing_breakpoint(music_hdl.player_hd, music_hdl.breakpoint, 1) == true) {
|
||||
music_player_stop(music_hdl.player_hd, 0);//先停止,防止下一步操作VM卡顿
|
||||
breakpoint_vm_write(music_hdl.breakpoint, logo);
|
||||
}
|
||||
if (err == MUSIC_PLAYER_ERR_FSCAN) {
|
||||
dev_manager_set_valid_by_logo(logo, 0);///将设备设置为无效设备
|
||||
} else {
|
||||
//针对读错误, 因为时间推到应用层有延时导致下一个模式判断不正常, 此处需要将设备卸载
|
||||
dev_manager_unmount(logo);
|
||||
}
|
||||
}
|
||||
if (dev_manager_get_total(1) == 0) {
|
||||
/* app_status_handler(APP_STATUS_MUSIC_QUIT); */
|
||||
msg = APP_MSG_GOTO_NEXT_MODE;///没有设备在线, 退出音乐模式
|
||||
} else {
|
||||
msg = APP_MSG_MUSIC_AUTO_NEXT_DEV;///切换设备
|
||||
}
|
||||
break;
|
||||
case MUSIC_PLAYER_ERR_FILE_NOFOUND:
|
||||
///查找文件有扫盘的可能,也需要结合music_player_scandisk_break中处理的标志位处理
|
||||
if (music_hdl.scandisk_break) {
|
||||
music_hdl.scandisk_break = 0;
|
||||
///此处不做任何处理, 打断的事件已经重发, 由重发事件执行后续处理
|
||||
break;
|
||||
}
|
||||
case MUSIC_PLAYER_ERR_PARM:
|
||||
logo = dev_manager_get_logo(music_hdl.player_hd->dev);
|
||||
if (dev_manager_online_check_by_logo(logo, 1)) {
|
||||
if (music_hdl.player_hd->fsn->file_number) {
|
||||
msg = APP_MSG_MUSIC_PLAY_FIRST;///有文件,播放第一个文件
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (dev_manager_get_total(1) == 0) {
|
||||
msg = APP_MSG_GOTO_NEXT_MODE;//没有设备了,退出音乐模式
|
||||
} else {
|
||||
msg = APP_MSG_MUSIC_AUTO_NEXT_DEV;
|
||||
}
|
||||
break;
|
||||
case MUSIC_PLAYER_ERR_FILE_READ://文件读错误
|
||||
msg = APP_MSG_MUSIC_NEXT;//播放下一曲
|
||||
break;
|
||||
}
|
||||
if (msg != APP_MSG_NULL) {
|
||||
app_send_message(msg, 0);
|
||||
}
|
||||
}
|
||||
|
||||
int music_app_msg_handler(int *msg)
|
||||
{
|
||||
int err = MUSIC_PLAYER_ERR_NULL;
|
||||
char *logo = NULL;
|
||||
if (false == app_in_mode(APP_MODE_MUSIC)) {
|
||||
return 0;
|
||||
}
|
||||
u8 auto_next_dev;
|
||||
struct file_player *file_player = get_music_file_player();
|
||||
|
||||
|
||||
switch (msg[0]) {
|
||||
case APP_MSG_CHANGE_MODE:
|
||||
printf("app msg key change mode\n");
|
||||
app_send_message(APP_MSG_GOTO_NEXT_MODE, 0);
|
||||
break;
|
||||
case APP_MSG_MUSIC_PP:
|
||||
printf("app msg music pp\n");
|
||||
music_file_player_pp(file_player);
|
||||
app_send_message(APP_MSG_MUSIC_PLAY_STATUS, music_file_get_player_status(file_player));
|
||||
break;
|
||||
case APP_MSG_MUSIC_SPEED_UP:
|
||||
printf("app msg music speed up\n");
|
||||
music_hdl.speed_mode = music_file_speed_up(file_player);
|
||||
clock_refurbish();
|
||||
break;
|
||||
case APP_MSG_MUSIC_SPEED_DOWN:
|
||||
printf("app msg music speed down\n");
|
||||
music_hdl.speed_mode = music_file_speed_down(file_player);
|
||||
clock_refurbish();
|
||||
break;
|
||||
case APP_MSG_PITCH_UP:
|
||||
printf("app msg music pitch up\n");
|
||||
music_hdl.pitch_mode = music_file_pitch_up(file_player);
|
||||
break;
|
||||
case APP_MSG_PITCH_DOWN:
|
||||
printf("app msg music pitch down\n");
|
||||
music_hdl.pitch_mode = music_file_pitch_down(file_player);
|
||||
break;
|
||||
case APP_MSG_MUSIC_CHANGE_REPEAT:
|
||||
music_player_change_repeat_mode(music_hdl.player_hd);
|
||||
app_send_message(APP_MSG_REPEAT_MODE_CHANGED, music_player_get_repeat_mode());
|
||||
break;
|
||||
case APP_MSG_MUSIC_PLAYER_AB_REPEAT_SWITCH:
|
||||
printf("app msg music ab repeat switch\n");
|
||||
#if FILE_DEC_AB_REPEAT_EN
|
||||
music_file_ab_repeat_switch(file_player);
|
||||
#endif
|
||||
break;
|
||||
case APP_MSG_MUSIC_PLAY_FIRST:
|
||||
printf("music_player_play_first_file\n");
|
||||
err = music_player_play_first_file(music_hdl.player_hd, NULL);
|
||||
break;
|
||||
case APP_MSG_MUSIC_NEXT:
|
||||
printf("app msg music next\n");
|
||||
|
||||
mem_stats();
|
||||
/* app_status_handler(APP_STATUS_MUSIC_FFR); */
|
||||
music_hdl.file_play_direct = 0;
|
||||
err = music_player_play_next(music_hdl.player_hd);
|
||||
break;
|
||||
case APP_MSG_MUSIC_PREV:
|
||||
printf("app msg music prev\n");
|
||||
mem_stats();
|
||||
/* app_status_handler(APP_STATUS_MUSIC_FFR); */
|
||||
music_hdl.file_play_direct = 1;
|
||||
err = music_player_play_prev(music_hdl.player_hd);
|
||||
break;
|
||||
|
||||
case APP_MSG_MUSIC_PLAYE_PREV_FOLDER:
|
||||
err = music_player_play_folder_prev(music_hdl.player_hd);
|
||||
break;
|
||||
case APP_MSG_MUSIC_PLAYE_NEXT_FOLDER:
|
||||
err = music_player_play_folder_next(music_hdl.player_hd);
|
||||
break;
|
||||
case APP_MSG_MUSIC_AUTO_NEXT_DEV:
|
||||
/* fall-through */
|
||||
case APP_MSG_MUSIC_CHANGE_DEV:
|
||||
log_i("KEY_MUSIC_CHANGE_DEV\n");
|
||||
auto_next_dev = ((msg[0] == APP_MSG_MUSIC_AUTO_NEXT_DEV) ? 1 : 0);
|
||||
logo = music_player_get_dev_next(music_hdl.player_hd, auto_next_dev);
|
||||
if (logo == NULL) { ///找不到下一个设备,不响应设备切换
|
||||
break;
|
||||
}
|
||||
printf("next dev = %s\n", logo);
|
||||
///切换设备前先保存一下上一个设备的断点信息,包括文件和解码信息
|
||||
if (music_player_get_playing_breakpoint(music_hdl.player_hd, music_hdl.breakpoint, 1) == true) {
|
||||
music_player_stop(music_hdl.player_hd, 0); //先停止,防止下一步操作VM卡顿
|
||||
breakpoint_vm_write(music_hdl.breakpoint, dev_manager_get_logo(music_hdl.player_hd->dev));
|
||||
}
|
||||
#if (MUSIC_DEVICE_TONE_EN)
|
||||
if (music_device_tone_play(logo) == true) {
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if (true == breakpoint_vm_read(music_hdl.breakpoint, logo)) {
|
||||
err = music_player_play_by_breakpoint(music_hdl.player_hd, logo, music_hdl.breakpoint);
|
||||
} else {
|
||||
err = music_player_play_first_file(music_hdl.player_hd, logo);
|
||||
}
|
||||
break;
|
||||
|
||||
case APP_MSG_MUSIC_PLAY_REC_FOLDER_SWITCH:
|
||||
log_i("KEY_MUSIC_PLAYE_REC_FOLDER_SWITCH\n");
|
||||
#if (TCFG_RECORD_FOLDER_DEV_ENABLE)
|
||||
///尝试保存断点
|
||||
if (music_player_get_playing_breakpoint(music_hdl.player_hd, breakpoint, 1) == true) {
|
||||
breakpoint_vm_write(breakpoint, dev_manager_get_logo(music_hdl.player_hd->dev));
|
||||
}
|
||||
if (true == breakpoint_vm_read(breakpoint, music_player_get_cur_music_dev())) {
|
||||
err = music_player_play_record_folder(music_hdl.player_hd, NULL, breakpoint);
|
||||
} else {
|
||||
err = music_player_play_record_folder(music_hdl.player_hd, NULL, NULL);
|
||||
}
|
||||
#endif//TCFG_RECORD_FOLDER_DEV_ENABLE
|
||||
break;
|
||||
case APP_MSG_MUSIC_PLAY_START_BY_DEV:
|
||||
#if (MUSIC_DEVICE_TONE_EN)
|
||||
logo = (char *)msg[1];
|
||||
log_i("KEY_MUSIC_DEVICE_TONE_END %s\n", logo);
|
||||
if (logo) {
|
||||
if (true == breakpoint_vm_read(music_hdl.breakpoint, logo)) {
|
||||
err = music_player_play_by_breakpoint(music_hdl.player_hd, logo, music_hdl.breakpoint);
|
||||
} else {
|
||||
err = music_player_play_first_file(music_hdl.player_hd, logo);
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case APP_MSG_MUSIC_MOUNT_PLAY_START:
|
||||
logo = (char *)msg[1];
|
||||
log_i("APP_MSG_MUSIC_MOUNT_PLAY_START %s\n", logo);
|
||||
dev_manager_set_active_by_logo(logo);
|
||||
/* fall-through */
|
||||
case APP_MSG_MUSIC_PLAY_START:
|
||||
log_i("APP_MSG_MUSIC_PLAY_START !!\n");
|
||||
#if 1
|
||||
/* app_status_handler(APP_STATUS_MUSIC_PLAY); */
|
||||
///断点播放活动设备
|
||||
logo = dev_manager_get_logo(dev_manager_find_active(1));
|
||||
if (music_player_runing()) {
|
||||
if (dev_manager_get_logo(music_hdl.player_hd->dev) && logo) {///播放的设备跟当前活动的设备是同一个设备,不处理
|
||||
if (0 == strcmp(logo, dev_manager_get_logo(music_hdl.player_hd->dev))) {
|
||||
log_w("the same dev!!\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#if (MUSIC_DEVICE_TONE_EN)
|
||||
if (music_device_tone_play(logo) == true) {
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
log_i("APP_MSG_MUSIC_PLAY_START %s\n", logo);
|
||||
if (true == breakpoint_vm_read(music_hdl.breakpoint, logo)) {
|
||||
err = music_player_play_by_breakpoint(music_hdl.player_hd, logo, music_hdl.breakpoint);
|
||||
} else {
|
||||
err = music_player_play_first_file(music_hdl.player_hd, logo);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case APP_MSG_MUSIC_PLAY_START_BY_SCLUST:
|
||||
log_i("KEY_MUSIC_PLAYE_BY_DEV_SCLUST\n");
|
||||
logo = dev_manager_get_logo(dev_manager_find_active(1));
|
||||
err = music_player_play_by_sclust(music_hdl.player_hd, logo, msg[1]);
|
||||
break;
|
||||
case APP_MSG_MUSIC_FR:
|
||||
printf("app msg music fr \n");
|
||||
music_file_player_fr(3, file_player);
|
||||
break;
|
||||
case APP_MSG_MUSIC_FF:
|
||||
printf("app msg music ff\n");
|
||||
music_file_player_ff(3, file_player);
|
||||
break;
|
||||
case APP_MSG_MUSIC_PLAYER_END:
|
||||
err = music_player_end_deal(music_hdl.player_hd, msg[1]);
|
||||
break;
|
||||
case APP_MSG_MUSIC_DEC_ERR:
|
||||
err = music_player_decode_err_deal(music_hdl.player_hd, msg[1]);
|
||||
break;
|
||||
case APP_MSG_MUSIC_PLAY_BY_NUM:
|
||||
printf("APP_MSG_MUSIC_PLAY_BY_NUM:%d\n", msg[1]);
|
||||
logo = dev_manager_get_logo(dev_manager_find_active(1));
|
||||
err = music_player_play_by_number(music_hdl.player_hd, logo, msg[1]);
|
||||
break;
|
||||
case APP_MSG_MUSIC_PLAY_START_AT_DEST_TIME:
|
||||
#if FILE_DEC_DEST_PLAY
|
||||
if (music_player_runing()) {
|
||||
//for test 测试MP3定点播放功能
|
||||
puts("\n play start at 5s \n");
|
||||
file_dec_set_start_play(5000, AUDIO_CODING_MP3);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
app_common_key_msg_handler(msg);
|
||||
break;
|
||||
}
|
||||
music_player_err_deal(err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,231 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".music_key_msg_table.data.bss")
|
||||
#pragma data_seg(".music_key_msg_table.data")
|
||||
#pragma const_seg(".music_key_msg_table.text.const")
|
||||
#pragma code_seg(".music_key_msg_table.text")
|
||||
#endif
|
||||
#include "key_driver.h"
|
||||
#include "app_main.h"
|
||||
#include "init.h"
|
||||
|
||||
|
||||
#if TCFG_ADKEY_ENABLE
|
||||
//短按 //长按 //hold //长按抬起 //双击 //三击
|
||||
#if (CONFIG_UI_STYLE != STYLE_JL_SOUNDBOX)
|
||||
const int key_music_ad_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_CHANGE_MODE, APP_MSG_KEY_POWER_OFF, APP_MSG_KEY_POWER_OFF_HOLD, APP_MSG_KEY_POWER_OFF_RELEASE, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ad_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_PP, APP_MSG_MUSIC_CHANGE_DEV, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ad_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_NEXT, APP_MSG_VOL_UP, APP_MSG_VOL_UP, APP_MSG_NULL, APP_MSG_MUSIC_PLAYE_NEXT_FOLDER, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ad_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_PREV, APP_MSG_VOL_DOWN, APP_MSG_VOL_DOWN, APP_MSG_NULL, APP_MSG_MUSIC_PLAYE_PREV_FOLDER, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ad_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_CHANGE_REPEAT, APP_MSG_NULL, APP_MSG_MUSIC_FF, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ad_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_PLAYER_AB_REPEAT_SWITCH, APP_MSG_NULL, APP_MSG_MUSIC_FR, APP_MSG_NULL, APP_MSG_SWITCH_SOUND_EFFECT, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ad_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_SWITCH_MIC_EFFECT, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_MIC_EFFECT_ON_OFF, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ad_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_VOCAL_REMOVE, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ad_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MIC_VOL_UP, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ad_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MIC_VOL_DOWN, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
#else /*LCD按键*/
|
||||
const int key_music_ad_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_CHANGE_MODE, APP_MSG_KEY_POWER_OFF, APP_MSG_KEY_POWER_OFF_HOLD, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ad_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_LCD_OK, APP_MSG_LCD_MENU, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ad_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_LCD_DOWN, APP_MSG_LCD_VOL_DEC, APP_MSG_LCD_VOL_DEC, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ad_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_LCD_UP, APP_MSG_LCD_VOL_INC, APP_MSG_LCD_VOL_INC, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ad_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_LCD_MODE, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ad_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ad_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ad_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ad_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ad_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if TCFG_IRKEY_ENABLE
|
||||
//短按 //长按 //hold //长按抬起 //双击 //三击
|
||||
const int key_music_ir_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_KEY_POWER_OFF_INSTANTLY, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ir_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_CHANGE_MODE, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ir_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_SYS_MUTE, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ir_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_PP, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ir_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_PREV, APP_MSG_NULL, APP_MSG_MUSIC_FR, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ir_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_NEXT, APP_MSG_NULL, APP_MSG_MUSIC_FF, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ir_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_CHANGE_EQ, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ir_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_VOL_DOWN, APP_MSG_VOL_DOWN, APP_MSG_VOL_DOWN, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ir_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_VOL_UP, APP_MSG_VOL_UP, APP_MSG_VOL_UP, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ir_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_IR_NUM0, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ir_num10_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_CHANGE_REPEAT, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_MUSIC_PLAYE_NEXT_FOLDER, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ir_num11_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_CHANGE_DEV, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ir_num12_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_IR_NUM1, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ir_num13_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_IR_NUM2, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ir_num14_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_IR_NUM3, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ir_num15_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_IR_NUM4, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ir_num16_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_IR_NUM5, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ir_num17_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_IR_NUM6, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ir_num18_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_IR_NUM7, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ir_num19_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_IR_NUM8, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_ir_num20_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_IR_NUM9, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if TCFG_IOKEY_ENABLE
|
||||
//短按 //长按 //hold //长按抬起 //双击 //三击
|
||||
const int key_music_io_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_CHANGE_MODE, APP_MSG_KEY_POWER_OFF, APP_MSG_KEY_POWER_OFF_HOLD, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_io_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_PP, APP_MSG_MUSIC_CHANGE_DEV, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_io_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_NEXT, APP_MSG_VOL_UP, APP_MSG_VOL_UP, APP_MSG_NULL, APP_MSG_MUSIC_PLAYE_NEXT_FOLDER, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_io_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_PREV, APP_MSG_VOL_DOWN, APP_MSG_VOL_DOWN, APP_MSG_NULL, APP_MSG_MUSIC_PLAYE_PREV_FOLDER, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_io_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_io_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_io_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_io_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_io_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_music_io_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
#endif
|
||||
|
||||
const struct key_remap_table music_mode_key_table[] = {
|
||||
#if TCFG_ADKEY_ENABLE
|
||||
{ .key_value = KEY_AD_NUM0, .remap_table = key_music_ad_num0_msg_table },
|
||||
{ .key_value = KEY_AD_NUM1, .remap_table = key_music_ad_num1_msg_table },
|
||||
{ .key_value = KEY_AD_NUM2, .remap_table = key_music_ad_num2_msg_table },
|
||||
{ .key_value = KEY_AD_NUM3, .remap_table = key_music_ad_num3_msg_table },
|
||||
{ .key_value = KEY_AD_NUM4, .remap_table = key_music_ad_num4_msg_table },
|
||||
{ .key_value = KEY_AD_NUM5, .remap_table = key_music_ad_num5_msg_table },
|
||||
{ .key_value = KEY_AD_NUM6, .remap_table = key_music_ad_num6_msg_table },
|
||||
{ .key_value = KEY_AD_NUM7, .remap_table = key_music_ad_num7_msg_table },
|
||||
{ .key_value = KEY_AD_NUM8, .remap_table = key_music_ad_num8_msg_table },
|
||||
{ .key_value = KEY_AD_NUM9, .remap_table = key_music_ad_num9_msg_table },
|
||||
#endif
|
||||
#if TCFG_IRKEY_ENABLE
|
||||
{ .key_value = KEY_IR_NUM0, .remap_table = key_music_ir_num0_msg_table },
|
||||
{ .key_value = KEY_IR_NUM1, .remap_table = key_music_ir_num1_msg_table },
|
||||
{ .key_value = KEY_IR_NUM2, .remap_table = key_music_ir_num2_msg_table },
|
||||
{ .key_value = KEY_IR_NUM3, .remap_table = key_music_ir_num3_msg_table },
|
||||
{ .key_value = KEY_IR_NUM4, .remap_table = key_music_ir_num4_msg_table },
|
||||
{ .key_value = KEY_IR_NUM5, .remap_table = key_music_ir_num5_msg_table },
|
||||
{ .key_value = KEY_IR_NUM6, .remap_table = key_music_ir_num6_msg_table },
|
||||
{ .key_value = KEY_IR_NUM7, .remap_table = key_music_ir_num7_msg_table },
|
||||
{ .key_value = KEY_IR_NUM8, .remap_table = key_music_ir_num8_msg_table },
|
||||
{ .key_value = KEY_IR_NUM9, .remap_table = key_music_ir_num9_msg_table },
|
||||
{ .key_value = KEY_IR_NUM10, .remap_table = key_music_ir_num10_msg_table },
|
||||
{ .key_value = KEY_IR_NUM11, .remap_table = key_music_ir_num11_msg_table },
|
||||
{ .key_value = KEY_IR_NUM12, .remap_table = key_music_ir_num12_msg_table },
|
||||
{ .key_value = KEY_IR_NUM13, .remap_table = key_music_ir_num13_msg_table },
|
||||
{ .key_value = KEY_IR_NUM14, .remap_table = key_music_ir_num14_msg_table },
|
||||
{ .key_value = KEY_IR_NUM15, .remap_table = key_music_ir_num15_msg_table },
|
||||
{ .key_value = KEY_IR_NUM16, .remap_table = key_music_ir_num16_msg_table },
|
||||
{ .key_value = KEY_IR_NUM17, .remap_table = key_music_ir_num17_msg_table },
|
||||
{ .key_value = KEY_IR_NUM18, .remap_table = key_music_ir_num18_msg_table },
|
||||
{ .key_value = KEY_IR_NUM19, .remap_table = key_music_ir_num19_msg_table },
|
||||
{ .key_value = KEY_IR_NUM20, .remap_table = key_music_ir_num20_msg_table },
|
||||
#endif
|
||||
#if TCFG_IOKEY_ENABLE
|
||||
{ .key_value = KEY_IO_NUM0, .remap_table = key_music_io_num0_msg_table },
|
||||
{ .key_value = KEY_IO_NUM1, .remap_table = key_music_io_num1_msg_table },
|
||||
{ .key_value = KEY_IO_NUM2, .remap_table = key_music_io_num2_msg_table },
|
||||
{ .key_value = KEY_IO_NUM3, .remap_table = key_music_io_num3_msg_table },
|
||||
{ .key_value = KEY_IO_NUM4, .remap_table = key_music_io_num4_msg_table },
|
||||
{ .key_value = KEY_IO_NUM5, .remap_table = key_music_io_num5_msg_table },
|
||||
{ .key_value = KEY_IO_NUM6, .remap_table = key_music_io_num6_msg_table },
|
||||
{ .key_value = KEY_IO_NUM7, .remap_table = key_music_io_num7_msg_table },
|
||||
{ .key_value = KEY_IO_NUM8, .remap_table = key_music_io_num8_msg_table },
|
||||
{ .key_value = KEY_IO_NUM9, .remap_table = key_music_io_num9_msg_table },
|
||||
#endif
|
||||
{ .key_value = 0xff }
|
||||
};
|
||||
|
||||
@@ -0,0 +1,260 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".pc.data.bss")
|
||||
#pragma data_seg(".pc.data")
|
||||
#pragma const_seg(".pc.text.const")
|
||||
#pragma code_seg(".pc.text")
|
||||
#endif
|
||||
#include "system/includes.h"
|
||||
#include "app_action.h"
|
||||
#include "audio_config.h"
|
||||
#include "usb/device/usb_stack.h"
|
||||
#include "usb/usb_task.h"
|
||||
#include "usb/device/hid.h"
|
||||
#include "usb/device/msd.h"
|
||||
#include "uac_stream.h"
|
||||
#include "pc.h"
|
||||
#include "tone_player.h"
|
||||
#include "app_tone.h"
|
||||
#include "user_cfg.h"
|
||||
#include "app_task.h"
|
||||
#include "app_main.h"
|
||||
#include "ui/ui_api.h"
|
||||
#include "ui_manage.h"
|
||||
|
||||
#define LOG_TAG_CONST PC
|
||||
#define LOG_TAG "[PC]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
/* #define LOG_DUMP_ENABLE */
|
||||
#define LOG_CLI_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
#if TCFG_APP_PC_EN
|
||||
|
||||
struct pc_opr {
|
||||
u8 volume;
|
||||
u8 onoff : 1;
|
||||
};
|
||||
|
||||
static struct pc_opr pc_hdl = {0};
|
||||
#define __this (&pc_hdl)
|
||||
static u8 pc_idle_flag = 1;
|
||||
|
||||
|
||||
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief pc 在线检测 切换模式判断使用
|
||||
@param 无
|
||||
@return 1 linein设备在线 0 设备不在线
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int app_pc_check(void)
|
||||
{
|
||||
#if ((defined TCFG_PC_BACKMODE_ENABLE) && (TCFG_PC_BACKMODE_ENABLE))
|
||||
return false;
|
||||
#endif//TCFG_PC_BACKMODE_ENABLE
|
||||
|
||||
u32 r = usb_otg_online(0);
|
||||
log_info("pc_app_check %d", r);
|
||||
if ((r == SLAVE_MODE) ||
|
||||
(r == SLAVE_MODE_WAIT_CONFIRMATION)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief pc 打开
|
||||
@param 无
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void pc_task_start(void)
|
||||
{
|
||||
if (__this->onoff) {
|
||||
log_info("PC is start ");
|
||||
return ;
|
||||
}
|
||||
log_info("App Start - PC");
|
||||
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
pc_dm_multiplex_init();
|
||||
#endif
|
||||
/* app_status_handler(APP_STATUS_PC); */
|
||||
#if TCFG_PC_ENABLE
|
||||
usb_message_to_stack(USBSTACK_START, 0, 1);
|
||||
#endif
|
||||
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
usb_otg_resume(0);
|
||||
#endif
|
||||
__this->onoff = 1;
|
||||
}
|
||||
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief pc 关闭
|
||||
@param 无
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void pc_task_stop(void)
|
||||
{
|
||||
if (!__this->onoff) {
|
||||
log_info("PC is stop ");
|
||||
return ;
|
||||
}
|
||||
__this->onoff = 0;
|
||||
u32 state = usb_otg_online(0);
|
||||
if (state != SLAVE_MODE && state != SLAVE_MODE_WAIT_CONFIRMATION) {
|
||||
log_info("App Stop - PC");
|
||||
#if TCFG_PC_ENABLE
|
||||
usb_message_to_stack(USBSTACK_STOP, 0, 1);
|
||||
#endif
|
||||
} else {
|
||||
log_info("App Hold- PC");
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
usb_otg_suspend(0, 0);
|
||||
#endif
|
||||
#if TCFG_PC_ENABLE
|
||||
usb_message_to_stack(USBSTACK_PAUSE, 0, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* tone_play_stop(); */
|
||||
/* tone_play_stop_by_path(tone_table[IDEX_TONE_PC]);//停止播放提示音 */
|
||||
#if TCFG_USB_DM_MULTIPLEX_WITH_SD_DAT0
|
||||
pc_dm_multiplex_exit();
|
||||
#endif
|
||||
|
||||
#if (TCFG_DEV_MANAGER_ENABLE)
|
||||
dev_manager_list_check_mount();
|
||||
#endif/*TCFG_DEV_MANAGER_ENABLE*/
|
||||
|
||||
}
|
||||
|
||||
static int pc_tone_play_end_callback(void *priv, enum stream_event event)
|
||||
{
|
||||
if (false == app_in_mode(APP_MODE_PC)) {
|
||||
return 0;
|
||||
}
|
||||
switch (event) {
|
||||
case STREAM_EVENT_NONE:
|
||||
case STREAM_EVENT_STOP:
|
||||
pc_task_start();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void app_pc_init()
|
||||
{
|
||||
pc_idle_flag = 0;
|
||||
/* ui_update_status(STATUS_PC_MODE); */
|
||||
__this->volume = app_audio_get_volume(APP_AUDIO_STATE_MUSIC);//记录下当前音量
|
||||
tone_player_stop();
|
||||
int ret = play_tone_file_callback(get_tone_files()->pc_mode, NULL, pc_tone_play_end_callback);
|
||||
if (ret) {
|
||||
log_error("pc tone play err!!!");
|
||||
pc_task_start();
|
||||
}
|
||||
app_send_message(APP_MSG_ENTER_MODE, APP_MODE_PC);
|
||||
#if TCFG_PC_MODE_LOCK_UI_ENABLE
|
||||
UI_WINDOW_PREEMPTION_POSH(ID_WINDOW_PC , NULL, NULL, UI_WINDOW_PREEMPTION_TYPE_PC);
|
||||
#endif
|
||||
}
|
||||
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief pc模式 退出
|
||||
@param 无
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void app_pc_exit()
|
||||
{
|
||||
#if TCFG_PC_MODE_LOCK_UI_ENABLE
|
||||
UI_WINDOW_PREEMPTION_POP(ID_WINDOW_PC);
|
||||
#endif
|
||||
pc_task_stop();
|
||||
app_audio_set_volume(APP_AUDIO_STATE_MUSIC, __this->volume, 1);
|
||||
#if (TCFG_DEC2TWS_ENABLE)
|
||||
bt_tws_sync_volume();
|
||||
#endif
|
||||
pc_idle_flag = 1;
|
||||
app_send_message(APP_MSG_EXIT_MODE, APP_MODE_PC);
|
||||
}
|
||||
|
||||
struct app_mode *app_enter_pc_mode(int arg)
|
||||
{
|
||||
int msg[16];
|
||||
struct app_mode *next_mode;
|
||||
|
||||
app_pc_init();
|
||||
|
||||
while (1) {
|
||||
if (!app_get_message(msg, ARRAY_SIZE(msg), pc_mode_key_table)) {
|
||||
continue;
|
||||
}
|
||||
next_mode = app_mode_switch_handler(msg);
|
||||
if (next_mode) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (msg[0]) {
|
||||
case MSG_FROM_APP:
|
||||
pc_app_msg_handler(msg + 1);
|
||||
break;
|
||||
case MSG_FROM_DEVICE:
|
||||
break;
|
||||
}
|
||||
|
||||
app_default_msg_handler(msg);
|
||||
}
|
||||
|
||||
app_pc_exit();
|
||||
|
||||
return next_mode;
|
||||
}
|
||||
|
||||
static int pc_mode_try_enter(int arg)
|
||||
{
|
||||
if (true == app_pc_check()) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int pc_mode_try_exit()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct app_mode_ops pc_mode_ops = {
|
||||
.try_enter = pc_mode_try_enter,
|
||||
.try_exit = pc_mode_try_exit,
|
||||
};
|
||||
|
||||
/* 注册pc模式 */
|
||||
REGISTER_APP_MODE(pc_mode) = {
|
||||
.name = APP_MODE_PC,
|
||||
.index = APP_MODE_PC_INDEX,
|
||||
.ops = &pc_mode_ops,
|
||||
};
|
||||
|
||||
static u8 pc_idle_query(void)
|
||||
{
|
||||
return pc_idle_flag;
|
||||
}
|
||||
|
||||
REGISTER_LP_TARGET(pc_lp_target) = {
|
||||
.name = "pc",
|
||||
.is_idle = pc_idle_query,
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,56 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".pc_app_msg_handler.data.bss")
|
||||
#pragma data_seg(".pc_app_msg_handler.data")
|
||||
#pragma const_seg(".pc_app_msg_handler.text.const")
|
||||
#pragma code_seg(".pc_app_msg_handler.text")
|
||||
#endif
|
||||
#include "key_driver.h"
|
||||
#include "app_main.h"
|
||||
#include "init.h"
|
||||
#include "audio_config.h"
|
||||
#include "usb/device/hid.h"
|
||||
|
||||
#if TCFG_APP_PC_EN
|
||||
int pc_app_msg_handler(int *msg)
|
||||
{
|
||||
if (false == app_in_mode(APP_MODE_PC)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (msg[0]) {
|
||||
case APP_MSG_CHANGE_MODE:
|
||||
printf("app msg key change mode\n");
|
||||
app_send_message(APP_MSG_GOTO_NEXT_MODE, 0);
|
||||
break;
|
||||
#if TCFG_USB_SLAVE_HID_ENABLE
|
||||
case APP_MSG_MUSIC_PP:
|
||||
printf("APP_MSG_MUSIC_PP\n");
|
||||
hid_key_handler(0, USB_AUDIO_PP);
|
||||
break;
|
||||
case APP_MSG_MUSIC_PREV:
|
||||
printf("APP_MSG_MUSIC_PREV\n");
|
||||
hid_key_handler(0, USB_AUDIO_PREFILE);
|
||||
break;
|
||||
case APP_MSG_MUSIC_NEXT:
|
||||
printf("APP_MSG_MUSIC_NEXT\n");
|
||||
hid_key_handler(0, USB_AUDIO_NEXTFILE);
|
||||
break;
|
||||
case APP_MSG_VOL_UP:
|
||||
printf("APP_MSG_VOL_UP\n");
|
||||
hid_key_handler(0, USB_AUDIO_VOLUP);
|
||||
printf(">>>pc vol+: %d", app_audio_get_volume(APP_AUDIO_CURRENT_STATE));
|
||||
break;
|
||||
case APP_MSG_VOL_DOWN:
|
||||
printf("APP_MSG_VOL_DOWN\n");
|
||||
hid_key_handler(0, USB_AUDIO_VOLDOWN);
|
||||
printf(">>>pc vol-: %d", app_audio_get_volume(APP_AUDIO_CURRENT_STATE));
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,231 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".pc_key_msg_table.data.bss")
|
||||
#pragma data_seg(".pc_key_msg_table.data")
|
||||
#pragma const_seg(".pc_key_msg_table.text.const")
|
||||
#pragma code_seg(".pc_key_msg_table.text")
|
||||
#endif
|
||||
#include "key_driver.h"
|
||||
#include "app_main.h"
|
||||
#include "init.h"
|
||||
|
||||
|
||||
#if TCFG_ADKEY_ENABLE
|
||||
//短按 //长按 //hold //长按抬起 //双击 //三击
|
||||
#if (CONFIG_UI_STYLE != STYLE_JL_SOUNDBOX)
|
||||
const int key_pc_ad_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_CHANGE_MODE, APP_MSG_KEY_POWER_OFF, APP_MSG_KEY_POWER_OFF_HOLD, APP_MSG_KEY_POWER_OFF_RELEASE, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ad_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_PP, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ad_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_NEXT, APP_MSG_VOL_UP, APP_MSG_VOL_UP, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ad_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_PREV, APP_MSG_VOL_DOWN, APP_MSG_VOL_DOWN, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ad_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ad_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ad_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_SWITCH_MIC_EFFECT, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_MIC_EFFECT_ON_OFF, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ad_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ad_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ad_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
#else /*LCD按键*/
|
||||
const int key_pc_ad_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_CHANGE_MODE, APP_MSG_KEY_POWER_OFF, APP_MSG_KEY_POWER_OFF_HOLD, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ad_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_LCD_OK, APP_MSG_LCD_MENU, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ad_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_LCD_DOWN, APP_MSG_LCD_VOL_DEC, APP_MSG_LCD_VOL_DEC, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ad_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_LCD_UP, APP_MSG_LCD_VOL_INC, APP_MSG_LCD_VOL_INC, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ad_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_LCD_MODE, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ad_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ad_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ad_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ad_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ad_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if TCFG_IRKEY_ENABLE
|
||||
//短按 //长按 //hold //长按抬起 //双击 //三击
|
||||
const int key_pc_ir_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_KEY_POWER_OFF_INSTANTLY, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ir_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_CHANGE_MODE, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ir_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_MUTE, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ir_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_PP, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_OPEN_SIRI, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ir_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_PREV, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ir_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_NEXT, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ir_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_CHANGE_EQ, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ir_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_VOL_DOWN, APP_MSG_VOL_DOWN, APP_MSG_VOL_DOWN, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ir_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_VOL_UP, APP_MSG_VOL_UP, APP_MSG_VOL_UP, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ir_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ir_num10_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ir_num11_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ir_num12_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ir_num13_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ir_num14_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ir_num15_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ir_num16_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ir_num17_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ir_num18_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ir_num19_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_ir_num20_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if TCFG_IOKEY_ENABLE
|
||||
//短按 //长按 //hold //长按抬起 //双击 //三击
|
||||
const int key_pc_io_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_CHANGE_MODE, APP_MSG_KEY_POWER_OFF, APP_MSG_KEY_POWER_OFF_HOLD, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_io_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_PP, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_io_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_NEXT, APP_MSG_VOL_UP, APP_MSG_VOL_UP, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_io_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_PREV, APP_MSG_VOL_DOWN, APP_MSG_VOL_DOWN, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_io_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_io_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_io_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_io_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_io_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_pc_io_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
#endif
|
||||
|
||||
const struct key_remap_table pc_mode_key_table[] = {
|
||||
#if TCFG_ADKEY_ENABLE
|
||||
{ .key_value = KEY_AD_NUM0, .remap_table = key_pc_ad_num0_msg_table },
|
||||
{ .key_value = KEY_AD_NUM1, .remap_table = key_pc_ad_num1_msg_table },
|
||||
{ .key_value = KEY_AD_NUM2, .remap_table = key_pc_ad_num2_msg_table },
|
||||
{ .key_value = KEY_AD_NUM3, .remap_table = key_pc_ad_num3_msg_table },
|
||||
{ .key_value = KEY_AD_NUM4, .remap_table = key_pc_ad_num4_msg_table },
|
||||
{ .key_value = KEY_AD_NUM5, .remap_table = key_pc_ad_num5_msg_table },
|
||||
{ .key_value = KEY_AD_NUM6, .remap_table = key_pc_ad_num6_msg_table },
|
||||
{ .key_value = KEY_AD_NUM7, .remap_table = key_pc_ad_num7_msg_table },
|
||||
{ .key_value = KEY_AD_NUM8, .remap_table = key_pc_ad_num8_msg_table },
|
||||
{ .key_value = KEY_AD_NUM9, .remap_table = key_pc_ad_num9_msg_table },
|
||||
#endif
|
||||
#if TCFG_IRKEY_ENABLE
|
||||
{ .key_value = KEY_IR_NUM0, .remap_table = key_pc_ir_num0_msg_table },
|
||||
{ .key_value = KEY_IR_NUM1, .remap_table = key_pc_ir_num1_msg_table },
|
||||
{ .key_value = KEY_IR_NUM2, .remap_table = key_pc_ir_num2_msg_table },
|
||||
{ .key_value = KEY_IR_NUM3, .remap_table = key_pc_ir_num3_msg_table },
|
||||
{ .key_value = KEY_IR_NUM4, .remap_table = key_pc_ir_num4_msg_table },
|
||||
{ .key_value = KEY_IR_NUM5, .remap_table = key_pc_ir_num5_msg_table },
|
||||
{ .key_value = KEY_IR_NUM6, .remap_table = key_pc_ir_num6_msg_table },
|
||||
{ .key_value = KEY_IR_NUM7, .remap_table = key_pc_ir_num7_msg_table },
|
||||
{ .key_value = KEY_IR_NUM8, .remap_table = key_pc_ir_num8_msg_table },
|
||||
{ .key_value = KEY_IR_NUM9, .remap_table = key_pc_ir_num9_msg_table },
|
||||
{ .key_value = KEY_IR_NUM10, .remap_table = key_pc_ir_num10_msg_table },
|
||||
{ .key_value = KEY_IR_NUM11, .remap_table = key_pc_ir_num11_msg_table },
|
||||
{ .key_value = KEY_IR_NUM12, .remap_table = key_pc_ir_num12_msg_table },
|
||||
{ .key_value = KEY_IR_NUM13, .remap_table = key_pc_ir_num13_msg_table },
|
||||
{ .key_value = KEY_IR_NUM14, .remap_table = key_pc_ir_num14_msg_table },
|
||||
{ .key_value = KEY_IR_NUM15, .remap_table = key_pc_ir_num15_msg_table },
|
||||
{ .key_value = KEY_IR_NUM16, .remap_table = key_pc_ir_num16_msg_table },
|
||||
{ .key_value = KEY_IR_NUM17, .remap_table = key_pc_ir_num17_msg_table },
|
||||
{ .key_value = KEY_IR_NUM18, .remap_table = key_pc_ir_num18_msg_table },
|
||||
{ .key_value = KEY_IR_NUM19, .remap_table = key_pc_ir_num19_msg_table },
|
||||
{ .key_value = KEY_IR_NUM20, .remap_table = key_pc_ir_num20_msg_table },
|
||||
#endif
|
||||
#if TCFG_IOKEY_ENABLE
|
||||
{ .key_value = KEY_IO_NUM0, .remap_table = key_pc_io_num0_msg_table },
|
||||
{ .key_value = KEY_IO_NUM1, .remap_table = key_pc_io_num1_msg_table },
|
||||
{ .key_value = KEY_IO_NUM2, .remap_table = key_pc_io_num2_msg_table },
|
||||
{ .key_value = KEY_IO_NUM3, .remap_table = key_pc_io_num3_msg_table },
|
||||
{ .key_value = KEY_IO_NUM4, .remap_table = key_pc_io_num4_msg_table },
|
||||
{ .key_value = KEY_IO_NUM5, .remap_table = key_pc_io_num5_msg_table },
|
||||
{ .key_value = KEY_IO_NUM6, .remap_table = key_pc_io_num6_msg_table },
|
||||
{ .key_value = KEY_IO_NUM7, .remap_table = key_pc_io_num7_msg_table },
|
||||
{ .key_value = KEY_IO_NUM8, .remap_table = key_pc_io_num8_msg_table },
|
||||
{ .key_value = KEY_IO_NUM9, .remap_table = key_pc_io_num9_msg_table },
|
||||
#endif
|
||||
{ .key_value = 0xff }
|
||||
};
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".power_on.data.bss")
|
||||
#pragma data_seg(".power_on.data")
|
||||
#pragma const_seg(".power_on.text.const")
|
||||
#pragma code_seg(".power_on.text")
|
||||
#endif
|
||||
#include "system/includes.h"
|
||||
#include "app_action.h"
|
||||
#include "app_main.h"
|
||||
#include "default_event_handler.h"
|
||||
#include "tone_player.h"
|
||||
#include "app_tone.h"
|
||||
#include "power_on.h"
|
||||
#include "ui/ui_api.h"
|
||||
#include "ui_manage.h"
|
||||
#include "jlui_app/ui_style.h"
|
||||
|
||||
#define LOG_TAG "[APP_IDLE]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
/* #define LOG_DUMP_ENABLE */
|
||||
#define LOG_CLI_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
extern u8 get_charge_online_flag(void);
|
||||
extern uint32_t timer_get_ms(void);
|
||||
#define POWER_ON_TIME 2//最小开机时间
|
||||
static u32 ui_logo_time = 0;
|
||||
extern const int JLUI_MULTI_PAGE_OVERLAY_SUPPORT;
|
||||
|
||||
|
||||
static void power_on_ui_enter()
|
||||
{
|
||||
UI_SHOW_WINDOW(ID_WINDOW_POWER_ON);
|
||||
ui_logo_time = timer_get_ms();
|
||||
|
||||
}
|
||||
static void power_on_ui_exit()
|
||||
{
|
||||
while (timer_get_ms() - ui_logo_time <= POWER_ON_TIME * 1000) { //显示开机logo
|
||||
os_time_dly(2);
|
||||
}
|
||||
|
||||
u8 poweron_password = 0;
|
||||
int ret = syscfg_read(USER_PASSWORD_ON, &poweron_password, sizeof(poweron_password));
|
||||
if ((ret == sizeof(poweron_password)) && poweron_password) {
|
||||
#if TCFG_UI_ENABLE
|
||||
#if !CONFIG_LVGL_UI_ENABLE
|
||||
set_need_password(1);
|
||||
#endif
|
||||
#endif
|
||||
UI_SHOW_WINDOW(ID_WINDOW_POWERON_PASSWORD);
|
||||
} else {
|
||||
if (!get_charge_online_flag()) {
|
||||
if (JLUI_MULTI_PAGE_OVERLAY_SUPPORT) {
|
||||
UI_SHOW_MULTI_PAGE();
|
||||
}
|
||||
UI_SHOW_WINDOW(ID_WINDOW_DIAL);
|
||||
}//非充电状态进表盘,充电床头由充电post页面显示
|
||||
}
|
||||
}
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief 开机启动
|
||||
@param 无
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void poweron_task_start()
|
||||
{
|
||||
power_on_ui_exit();
|
||||
|
||||
#if TCFG_APP_BT_EN
|
||||
app_send_message(APP_MSG_GOTO_MODE, APP_MODE_BT);
|
||||
#else
|
||||
/* app_send_message(APP_MSG_GOTO_MODE, APP_MODE_IDLE); */
|
||||
app_send_message(APP_MSG_GOTO_NEXT_MODE, 0);
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
static int poweron_tone_play_end_callback(void *priv, enum stream_event event)
|
||||
{
|
||||
if (!app_in_mode(APP_MODE_POWERON)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (event == STREAM_EVENT_STOP) {
|
||||
poweron_task_start();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int app_poweron_init()
|
||||
{
|
||||
log_info("power on");
|
||||
power_on_ui_enter();
|
||||
|
||||
app_send_message(APP_MSG_ENTER_MODE, APP_MODE_POWERON);
|
||||
|
||||
if (app_var.play_poweron_tone) {
|
||||
int ret = play_tone_file_callback(get_tone_files()->power_on, NULL, poweron_tone_play_end_callback);
|
||||
if (ret) {
|
||||
log_error("power on tone play err!!!");
|
||||
poweron_task_start();
|
||||
}
|
||||
} else {
|
||||
poweron_task_start();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void app_poweron_exit()
|
||||
{
|
||||
log_info("exit power on mode");
|
||||
app_send_message(APP_MSG_EXIT_MODE, APP_MODE_POWERON);
|
||||
}
|
||||
|
||||
struct app_mode *app_enter_poweron_mode(int arg)
|
||||
{
|
||||
int msg[16];
|
||||
struct app_mode *next_mode;
|
||||
|
||||
app_poweron_init();
|
||||
|
||||
while (1) {
|
||||
if (!app_get_message(msg, ARRAY_SIZE(msg), NULL)) {
|
||||
continue;
|
||||
}
|
||||
next_mode = app_mode_switch_handler(msg);
|
||||
if (next_mode) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (msg[0]) {
|
||||
case MSG_FROM_APP:
|
||||
break;
|
||||
case MSG_FROM_DEVICE:
|
||||
break;
|
||||
}
|
||||
|
||||
app_default_msg_handler(msg);
|
||||
}
|
||||
|
||||
app_poweron_exit();
|
||||
|
||||
return next_mode;
|
||||
}
|
||||
|
||||
static int poweron_mode_try_enter(int arg)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int poweron_mode_try_exit()
|
||||
{
|
||||
//上电提示音播放结束前不退出模式
|
||||
#if TCFG_BT_BACKGROUND_ENABLE
|
||||
if (tone_player_runing()) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static const struct app_mode_ops poweron_mode_ops = {
|
||||
.try_enter = poweron_mode_try_enter,
|
||||
.try_exit = poweron_mode_try_exit,
|
||||
};
|
||||
|
||||
/*
|
||||
* 注册power_on模式
|
||||
*/
|
||||
REGISTER_APP_MODE(poweron_mode) = {
|
||||
.name = APP_MODE_POWERON,
|
||||
.index = 0xff,
|
||||
.ops = &poweron_mode_ops,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,880 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".record.data.bss")
|
||||
#pragma data_seg(".record.data")
|
||||
#pragma const_seg(".record.text.const")
|
||||
#pragma code_seg(".record.text")
|
||||
#endif
|
||||
#include "system/includes.h"
|
||||
#include "app_action.h"
|
||||
#include "app_main.h"
|
||||
#include "default_event_handler.h"
|
||||
#include "bt.h"
|
||||
#include "tone_player.h"
|
||||
#include "app_tone.h"
|
||||
#include "dev_manager.h"
|
||||
#include "record.h"
|
||||
#include "file_recorder.h"
|
||||
#include "audio_config.h"
|
||||
|
||||
|
||||
#if TCFG_APP_RECORD_EN
|
||||
|
||||
#define PIPELINE_RECODER 0x49EC
|
||||
|
||||
static OS_MUTEX record_mutex;
|
||||
|
||||
struct app_recode_handle {
|
||||
void *recorder;
|
||||
FILE *file;
|
||||
char logo[20];
|
||||
};
|
||||
|
||||
struct app_recode_file_play_hdl {
|
||||
FILE *file;
|
||||
u8 need_update_fsn_flag; //是否需要重新扫描盘符
|
||||
char path[64];
|
||||
char folder_path[64];
|
||||
char suffix[5];
|
||||
int pause_rec_flag; //暂停录音标志
|
||||
u32 file_index; //用来指定播放的是哪一首
|
||||
struct file_player *player;
|
||||
struct vfscan *fsn;
|
||||
FILE *latest_play_file; //记录下最近的文件, 用于回播下删除最近的文件
|
||||
};
|
||||
static struct app_recode_file_play_hdl g_rec_play_hdl = {0};
|
||||
|
||||
static u8 os_mutex_create_flag = 0;
|
||||
static void get_latest_rec_file_name(void);
|
||||
static void app_recorder_stop();
|
||||
static int recorde_file_play_callback(void *_priv, int parm, enum stream_event event);
|
||||
static void app_recorder_pause(void);
|
||||
static void app_recorder_file_play_next(void);
|
||||
static void app_recorder_file_play_prev(void);
|
||||
static void app_recorder_file_play_vol_down(void);
|
||||
static void app_recorder_file_play_vol_up(void);
|
||||
extern void audio_app_volume_up(u8 value);
|
||||
extern void audio_app_volume_down(u8 value);
|
||||
|
||||
void app_local_record_mutex_create(void);
|
||||
|
||||
static struct app_recode_handle g_rec_hdl;
|
||||
static u8 record_idle_flag = 1;
|
||||
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief 录音模式提示音结束处理
|
||||
@param 无
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int record_tone_play_end_callback(void *priv, enum stream_event event)
|
||||
{
|
||||
return 0;
|
||||
|
||||
}
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief record 模式初始化
|
||||
@param 无
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int app_record_init()
|
||||
{
|
||||
printf("\n--------record start-----------\n");
|
||||
app_local_record_mutex_create();
|
||||
record_idle_flag = 0;
|
||||
tone_player_stop();
|
||||
play_tone_file_callback(get_tone_files()->record_mode, NULL,
|
||||
record_tone_play_end_callback);
|
||||
g_rec_play_hdl.file_index = 1; //默认初始化为1
|
||||
app_send_message(APP_MSG_ENTER_MODE, APP_MODE_RECORD);
|
||||
return 0;
|
||||
}
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief record 退出
|
||||
@param 无
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void app_record_exit()
|
||||
{
|
||||
//停止播放模式提示音
|
||||
//如果有暂停录音,需要先恢复录音
|
||||
if (g_rec_play_hdl.pause_rec_flag == STREAM_STA_PAUSE) {
|
||||
//恢复录音
|
||||
app_recorder_pause();
|
||||
}
|
||||
///停止mic录音
|
||||
app_recorder_stop();
|
||||
#if TCFG_RECORD_AUDIO_REPLAY_EN
|
||||
///停止回放
|
||||
app_recorder_file_play_stop();
|
||||
//释放盘符
|
||||
if (g_rec_play_hdl.fsn) {
|
||||
fscan_release(g_rec_play_hdl.fsn);
|
||||
g_rec_play_hdl.fsn = NULL;
|
||||
g_rec_play_hdl.file_index = 1; //下标重新设置为1
|
||||
g_rec_play_hdl.player = NULL; //播放结束,加上这句防止ui继续访问异常
|
||||
}
|
||||
g_rec_play_hdl.latest_play_file = NULL;
|
||||
#endif
|
||||
record_idle_flag = 1;
|
||||
app_send_message(APP_MSG_EXIT_MODE, APP_MODE_RECORD);
|
||||
}
|
||||
|
||||
void record_ui_del_mutex()
|
||||
{
|
||||
os_mutex_del(&record_mutex, 0);
|
||||
os_mutex_create_flag = 0;
|
||||
}
|
||||
|
||||
|
||||
static void app_recorder_callback(void *priv, enum stream_state state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void record_cut_head_timeout(void *priv)
|
||||
{
|
||||
struct file_recorder *recoder = (struct file_recorder *) priv;
|
||||
if (recoder) {
|
||||
jlstream_node_ioctl(recoder->stream, NODE_UUID_SOURCE, NODE_IOC_FORCE_DUMP_PACKET, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void app_recorder_start()
|
||||
{
|
||||
int err;
|
||||
struct file_recorder *recorder;
|
||||
|
||||
recorder = file_recorder_open(PIPELINE_RECODER, NODE_UUID_ADC);
|
||||
/* recorder = file_recorder_open(PIPELINE_RECODER, NODE_UUID_ZERO_ACTIVE); */
|
||||
if (!recorder) {
|
||||
puts("file_recorder_open_faild\n");
|
||||
return;
|
||||
}
|
||||
|
||||
struct stream_enc_fmt fmt;
|
||||
err = file_recorder_get_fmt(recorder, &fmt);
|
||||
if (err) {
|
||||
file_recorder_close(recorder, 0);
|
||||
return;
|
||||
}
|
||||
printf("recorder_fmt: ch %d, sample rate %d\n", fmt.channel, fmt.sample_rate);
|
||||
|
||||
#if CUT_HEAD_TIME
|
||||
if (CUT_HEAD_TIME) {
|
||||
jlstream_node_ioctl(recorder->stream, NODE_UUID_SOURCE, NODE_IOC_FORCE_DUMP_PACKET, 1);
|
||||
recorder->cut_head_timer = sys_timeout_add(recorder, record_cut_head_timeout, CUT_HEAD_TIME);
|
||||
}
|
||||
#endif
|
||||
#if CUT_TAIL_TIME
|
||||
if (fmt.coding_type == AUDIO_CODING_PCM) {
|
||||
recorder->cut_tail_size = (2 * fmt.sample_rate * fmt.channel) * CUT_TAIL_TIME / 1000 ;
|
||||
recorder->cut_tail_size = ((recorder->cut_tail_size + fmt.bit_rate - 1) / (fmt.bit_rate) * fmt.bit_rate);
|
||||
} else if (fmt.coding_type != AUDIO_CODING_WAV) { //adpcm需要从库里面更新头,且编码数据是成块的,不支持做去尾功能
|
||||
recorder->cut_tail_size = fmt.bit_rate / 1000 * CUT_TAIL_TIME / 8;
|
||||
}
|
||||
jlstream_node_ioctl(recorder->stream, NODE_UUID_FILE_PACKAGE, NODE_IOC_SET_PRIV_FMT, recorder->cut_tail_size);
|
||||
#endif
|
||||
const char *suffix;
|
||||
switch (fmt.coding_type) {
|
||||
case AUDIO_CODING_PCM:
|
||||
suffix = "pcm";
|
||||
break;
|
||||
case AUDIO_CODING_WAV:
|
||||
suffix = "wav";
|
||||
recorder->head_size = WAV_HEAD_SIZE; //pcm 编码的头文件大小
|
||||
break;
|
||||
case AUDIO_CODING_MP3:
|
||||
suffix = "mp3";
|
||||
break;
|
||||
case AUDIO_CODING_AMR:
|
||||
suffix = "amr";
|
||||
break;
|
||||
default:
|
||||
suffix = "bin";
|
||||
break;
|
||||
}
|
||||
char folder[] = {TCFG_REC_FOLDER_NAME}; //录音文件夹名称
|
||||
char filename[] = {TCFG_REC_FILE_NAME}; //录音文件名,不需要加后缀
|
||||
|
||||
#if (TCFG_NOR_REC)
|
||||
char logo[] = {"rec_nor"}; //外挂flash录音
|
||||
#elif (FLASH_INSIDE_REC_ENABLE)
|
||||
char logo[] = {"rec_sdfile"}; //内置flash录音
|
||||
#else
|
||||
// char *logo = dev_manager_get_phy_logo(dev_manager_find_active(0));//普通设备录音,获取最后活动设备
|
||||
char logo[] = {RECODER_DEVICE_LOGO}; //sd卡录音
|
||||
#endif
|
||||
|
||||
char *root_path = dev_manager_get_root_path_by_logo(logo);
|
||||
char path[64] = {};
|
||||
|
||||
snprintf(path, sizeof(path), "%s%s/%s.%s", root_path, folder, filename, suffix);
|
||||
FILE *file = file_recorder_open_file(recorder, path);
|
||||
if (!file) {
|
||||
file_recorder_close(recorder, 0);
|
||||
return;
|
||||
}
|
||||
file_recorder_set_callback(recorder, NULL, app_recorder_callback);
|
||||
|
||||
err = file_recorder_start(recorder);
|
||||
if (err) {
|
||||
printf("file_recorder_err: %d\n", err);
|
||||
file_recorder_close(recorder, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
snprintf(g_rec_hdl.logo, sizeof(g_rec_hdl.logo), "%s", logo);
|
||||
g_rec_hdl.file = file;
|
||||
g_rec_hdl.recorder = recorder;
|
||||
|
||||
//记录播放录音需要的信息
|
||||
memcpy(g_rec_play_hdl.path, path, sizeof(path));
|
||||
memcpy(g_rec_play_hdl.suffix, suffix, strlen(suffix));
|
||||
}
|
||||
|
||||
static void app_recorder_stop()
|
||||
{
|
||||
os_mutex_pend(&record_mutex, 0);
|
||||
file_recorder_close(g_rec_hdl.recorder, 1);
|
||||
g_rec_hdl.recorder = NULL;
|
||||
os_mutex_post(&record_mutex);
|
||||
}
|
||||
|
||||
//获取录音编码时间
|
||||
int app_recorder_get_enc_time(void)
|
||||
{
|
||||
os_mutex_pend(&record_mutex, 0);
|
||||
struct file_recorder *recorder = g_rec_hdl.recorder;
|
||||
int time = 0;
|
||||
if (recorder && recorder->stream) {
|
||||
//录音时候才能获取时间
|
||||
jlstream_ioctl(recorder->stream, NODE_IOC_GET_ENC_TIME, (int)(&time));
|
||||
}
|
||||
os_mutex_post(&record_mutex);
|
||||
return time;
|
||||
}
|
||||
|
||||
//获取播放录音文件的时间
|
||||
int app_recorder_get_play_file_time(void)
|
||||
{
|
||||
int time = -1;
|
||||
os_mutex_pend(&record_mutex, 0);
|
||||
if (g_rec_play_hdl.player && g_rec_play_hdl.player->stream) {
|
||||
time = jlstream_node_ioctl(g_rec_play_hdl.player->stream, NODE_UUID_DECODER, NODE_IOC_GET_CUR_TIME, 0);
|
||||
}
|
||||
os_mutex_post(&record_mutex);
|
||||
return time;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//控制录音暂停
|
||||
static void app_recorder_pause(void)
|
||||
{
|
||||
struct file_recorder *recorder = g_rec_hdl.recorder;
|
||||
if (recorder && recorder->stream) {
|
||||
g_rec_play_hdl.pause_rec_flag = jlstream_pp_toggle(recorder->stream, 50);
|
||||
if (g_rec_play_hdl.pause_rec_flag == STREAM_STA_PAUSE) {
|
||||
y_printf(">>> REC PAUSE!\n");
|
||||
} else if (g_rec_play_hdl.pause_rec_flag == STREAM_STA_PLAY) {
|
||||
y_printf(">>> REC Continue!\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//扫描录音文件夹获取盘符
|
||||
static void app_recorder_fsn_scan(void)
|
||||
{
|
||||
if (g_rec_play_hdl.need_update_fsn_flag) {
|
||||
g_rec_play_hdl.need_update_fsn_flag = 0;
|
||||
if (g_rec_play_hdl.fsn) {
|
||||
fscan_release(g_rec_play_hdl.fsn);
|
||||
g_rec_play_hdl.file_index = 1; //重新update 盘符,file_index 重新赋值
|
||||
g_rec_play_hdl.fsn = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_rec_play_hdl.fsn == NULL) {
|
||||
char folder[] = {TCFG_REC_FOLDER_NAME};
|
||||
#if (TCFG_NOR_REC)
|
||||
char logo[] = {"rec_nor"};
|
||||
#elif (FLASH_INSIDE_REC_ENABLE)
|
||||
char logo[] = {"rec_sdfile"};
|
||||
#else
|
||||
/* char *logo = dev_manager_get_phy_logo(dev_manager_find_active(0)); */
|
||||
char logo[] = {RECODER_DEVICE_LOGO}; //sd卡录音
|
||||
#endif
|
||||
char *root_path = dev_manager_get_root_path_by_logo(logo);
|
||||
sprintf(g_rec_play_hdl.folder_path, "%s%s%s", root_path, folder, "/");
|
||||
/* printf("REC folder_path : %s\n", g_rec_play_hdl.folder_path); */
|
||||
//扫盘获取文件夹
|
||||
const u8 fscan_file_param[] = "-t"
|
||||
"ALL"
|
||||
" -sn -r";
|
||||
struct vfscan *fsn = fscan(g_rec_play_hdl.folder_path, (char *)fscan_file_param, 1);
|
||||
if (fsn == NULL) {
|
||||
printf("error, %s %d, fsn is NULL!\n", __func__, __LINE__);
|
||||
g_rec_play_hdl.fsn = NULL;
|
||||
g_rec_play_hdl.file_index = 1; //扫盘失败
|
||||
return;
|
||||
}
|
||||
g_rec_play_hdl.fsn = fsn;
|
||||
g_printf(">>>>> Scan fsn Success!\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//删除最新的录音文件, 从最后那个文件开始删起
|
||||
static void app_recorder_del_latest_file(void)
|
||||
{
|
||||
if (g_rec_play_hdl.file) {
|
||||
fclose(g_rec_play_hdl.file);
|
||||
g_rec_play_hdl.file = NULL;
|
||||
g_rec_play_hdl.latest_play_file = NULL;
|
||||
}
|
||||
|
||||
app_recorder_fsn_scan();
|
||||
FILE *file = NULL;
|
||||
if (g_rec_play_hdl.fsn && g_rec_play_hdl.fsn->file_number) {
|
||||
y_printf(">>>>>>>>>>>>>>>>>>>>>> g_rec_play_hdl.fsn->file_num:%d", g_rec_play_hdl.fsn->file_number);
|
||||
file = fselect(g_rec_play_hdl.fsn, FSEL_BY_NUMBER, g_rec_play_hdl.fsn->file_number);
|
||||
}
|
||||
if (file) {
|
||||
int err = fdelete(file);
|
||||
if (err) {
|
||||
r_printf("[%s, %d] Recorder file delete failed!\n", __func__, __LINE__);
|
||||
}
|
||||
}
|
||||
//删完后释放盘符
|
||||
if (g_rec_play_hdl.fsn) {
|
||||
fscan_release(g_rec_play_hdl.fsn);
|
||||
g_rec_play_hdl.fsn = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* 获取最新的录音文件名称 */
|
||||
static void get_latest_rec_file_name(void)
|
||||
{
|
||||
char folder[] = {TCFG_REC_FOLDER_NAME}; //录音文件夹名称
|
||||
#if (TCFG_NOR_REC)
|
||||
char logo[] = {"rec_nor"}; //外挂flash录音
|
||||
#elif (FLASH_INSIDE_REC_ENABLE)
|
||||
char logo[] = {"rec_sdfile"}; //内置flash录音
|
||||
#else
|
||||
/* char *logo = dev_manager_get_phy_logo(dev_manager_find_active(0));//普通设备录音,获取最后活动设备 */
|
||||
char logo[] = {RECODER_DEVICE_LOGO}; //sd卡录音
|
||||
#endif
|
||||
char *root_path = dev_manager_get_root_path_by_logo(logo);
|
||||
int index = get_last_num();
|
||||
char index_str[5] = {0};
|
||||
if (index != (u32) - 1) {
|
||||
index_str[0] = index / 1000 + '0';
|
||||
index_str[1] = index % 1000 / 100 + '0';
|
||||
index_str[2] = index % 100 / 10 + '0';
|
||||
index_str[3] = index % 10 + '0';
|
||||
sprintf(g_rec_play_hdl.path, "%s%s%s%s%s%s", root_path, folder, "/"TCFG_REC_FILE_NAME_PREFIX, index_str, ".", g_rec_play_hdl.suffix);
|
||||
} else {
|
||||
r_printf("-- Error, func %s, index is err!! index:%d\n", index);
|
||||
}
|
||||
/* printf("%s, %s, %s, %s\n", root_path, folder, TCFG_REC_FILE_NAME_PREFIX, g_rec_play_hdl.suffix); */
|
||||
printf("Record file path :%s, index:%d\n", g_rec_play_hdl.path, index);
|
||||
}
|
||||
|
||||
static void recorder_device_offline_check(const char *logo)
|
||||
{
|
||||
os_mutex_pend(&record_mutex, 0);
|
||||
if (g_rec_hdl.recorder) {
|
||||
if (!strcmp(g_rec_hdl.logo, logo)) {
|
||||
///当前录音正在使用的设备掉线, 应该停掉录音
|
||||
printf("is the recording dev = %s\n", logo);
|
||||
/* app_recorder_stop(); */
|
||||
file_recorder_close(g_rec_hdl.recorder, 0);
|
||||
g_rec_hdl.recorder = NULL;
|
||||
}
|
||||
}
|
||||
os_mutex_post(&record_mutex);
|
||||
}
|
||||
|
||||
//record录音 设备事件响应接口,return 1代表事件已经处理, 0表示还未处理
|
||||
int record_device_msg_handler(int *msg)
|
||||
{
|
||||
const char *logo = NULL;
|
||||
int err = 0;
|
||||
switch (msg[0]) {
|
||||
case DRIVER_EVENT_FROM_SD0:
|
||||
case DRIVER_EVENT_FROM_SD1:
|
||||
case DRIVER_EVENT_FROM_SD2:
|
||||
logo = (char *)msg[2];
|
||||
case DEVICE_EVENT_FROM_USB_HOST:
|
||||
if (!strncmp((char *)msg[2], "udisk", 5)) {
|
||||
logo = (char *)msg[2];
|
||||
}
|
||||
|
||||
if (msg[1] == DEVICE_EVENT_IN) {
|
||||
} else if (msg[1] == DEVICE_EVENT_OUT) {
|
||||
r_printf("Event Record Device Out!!\n");
|
||||
recorder_device_offline_check(logo);
|
||||
g_rec_play_hdl.need_update_fsn_flag = 1;
|
||||
app_recorder_fsn_scan();
|
||||
if (g_rec_play_hdl.fsn == NULL) {
|
||||
r_printf(">>> Record Device Out!!\n");
|
||||
app_send_message(APP_MSG_GOTO_NEXT_MODE, 0); //推出record 模式
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int record_app_msg_handler(int *msg)
|
||||
{
|
||||
printf("msg == %d", msg[0]);
|
||||
switch (msg[0]) {
|
||||
case APP_MSG_CHANGE_MODE:
|
||||
printf("app msg key change mode\n");
|
||||
app_send_message(APP_MSG_GOTO_NEXT_MODE, 0);
|
||||
break;
|
||||
#if TCFG_RECORD_AUDIO_REPLAY_EN
|
||||
case APP_MSG_MUSIC_PP:
|
||||
printf("app msg record pp\n");
|
||||
break;
|
||||
case APP_MSG_MUSIC_NEXT:
|
||||
printf("app msg record next\n");
|
||||
//如果在录音,则需要先停止录音
|
||||
if (g_rec_hdl.recorder) {
|
||||
r_printf("recording..., need stop record at first!\n");
|
||||
break;
|
||||
}
|
||||
app_recorder_file_play_next();
|
||||
break;
|
||||
case APP_MSG_MUSIC_PREV:
|
||||
printf("app msg record prev\n");
|
||||
if (g_rec_hdl.recorder) {
|
||||
r_printf("recording..., need stop record at first!\n");
|
||||
break;
|
||||
}
|
||||
app_recorder_file_play_prev();
|
||||
break;
|
||||
case APP_MSG_VOL_UP:
|
||||
printf(">>>>> APP MSG Vol Up!!\n");
|
||||
app_recorder_file_play_vol_up();
|
||||
break;
|
||||
case APP_MSG_VOL_DOWN:
|
||||
printf(">>>>> APP MSG Vol Down!!\n");
|
||||
app_recorder_file_play_vol_down();
|
||||
break;
|
||||
#endif
|
||||
case APP_MSG_REC_PP:
|
||||
printf("APP_MSG_REC_PP %d", (int)g_rec_hdl.recorder);
|
||||
if (!g_rec_hdl.recorder) {
|
||||
//没有录音,先停止播放
|
||||
#if TCFG_RECORD_AUDIO_REPLAY_EN
|
||||
app_recorder_file_play_stop();
|
||||
if (g_rec_play_hdl.fsn) {
|
||||
fscan_release(g_rec_play_hdl.fsn);
|
||||
g_rec_play_hdl.fsn = NULL;
|
||||
g_rec_play_hdl.file_index = 1; //下标重新设置为1
|
||||
g_rec_play_hdl.player = NULL; //播放结束,加上这句防止ui继续访问异常
|
||||
}
|
||||
#endif
|
||||
app_recorder_start();
|
||||
} else {
|
||||
if (g_rec_play_hdl.pause_rec_flag == STREAM_STA_PAUSE) {
|
||||
//恢复录音
|
||||
app_recorder_pause();
|
||||
}
|
||||
app_recorder_stop();
|
||||
g_rec_play_hdl.need_update_fsn_flag = 1; //录制完文件,要重新扫描盘符
|
||||
#if TCFG_RECORD_AUDIO_REPLAY_EN
|
||||
app_recorder_file_play_start(); //播录音文件
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case APP_MSG_REC_DEL_CUR_FILE:
|
||||
printf("APP_MSG_REC_DEL_CUR_FILE!!\n");
|
||||
if (!g_rec_hdl.recorder) {
|
||||
//不在录音,直接删
|
||||
#if TCFG_RECORD_AUDIO_REPLAY_EN
|
||||
//回播时,删除最近播放的文件
|
||||
if (music_player_runing()) {
|
||||
os_mutex_pend(&record_mutex, 0); //加pend防止已经释放数据流中app_recorder_get_play_file_time 函数触发的数据流访问异常
|
||||
music_file_player_stop();
|
||||
g_rec_play_hdl.player = NULL;
|
||||
os_mutex_post(&record_mutex);
|
||||
app_recorder_del_cur_play_file();
|
||||
app_recorder_play_record_folder();
|
||||
} else {
|
||||
app_recorder_file_play_stop(); //如果在播歌的话先停止播歌
|
||||
app_recorder_del_latest_file();
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
//在录音,先关闭录音,再删
|
||||
if (g_rec_play_hdl.pause_rec_flag == STREAM_STA_PAUSE) {
|
||||
//恢复录音
|
||||
app_recorder_pause();
|
||||
}
|
||||
app_recorder_stop();
|
||||
//录音时,直接删除录音文件
|
||||
app_recorder_del_latest_file(); //删除录音文件
|
||||
}
|
||||
break;
|
||||
case APP_MSG_REC_PAUSE:
|
||||
y_printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> case APP_MSG_REC_PAUSE!!\n");
|
||||
if (g_rec_hdl.recorder) {
|
||||
//只有在录音时才能控制录音的暂停和恢复
|
||||
app_recorder_pause();
|
||||
} else {
|
||||
#if TCFG_RECORD_AUDIO_REPLAY_EN
|
||||
//如果不是在录音中,如果使能了回播功能,则此按键功能为暂停播放的功能
|
||||
//恢复播放则会从下一个录音文件开始播起
|
||||
if (music_player_runing()) {
|
||||
app_recorder_file_play_stop();
|
||||
} else {
|
||||
app_recorder_play_record_folder();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("default");
|
||||
app_common_key_msg_handler(msg);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//创建互斥量,互斥量给UI使用的,保护UI线程访问临界段代码
|
||||
void app_local_record_mutex_create(void)
|
||||
{
|
||||
if (os_mutex_create_flag == 0) {
|
||||
os_mutex_create(&record_mutex);
|
||||
os_mutex_create_flag = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//是否正在录音
|
||||
u8 is_recorder_runing(void)
|
||||
{
|
||||
app_local_record_mutex_create();
|
||||
os_mutex_pend(&record_mutex, 0);
|
||||
struct file_recorder *recorder = g_rec_hdl.recorder;
|
||||
if (recorder && recorder->stream) {
|
||||
os_mutex_post(&record_mutex);
|
||||
return 1;
|
||||
}
|
||||
os_mutex_post(&record_mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//用来设置录音文件的后缀名称,例如为 .mp3 或者 .wav等等
|
||||
void local_set_record_file_suffix(const char *_suffix)
|
||||
{
|
||||
if (_suffix != NULL) {
|
||||
memcpy(g_rec_play_hdl.suffix, _suffix, strlen(_suffix));
|
||||
y_printf(">>Func:%s, g_rec_play_hdl.suffix:%s\n", __func__, g_rec_play_hdl.suffix);
|
||||
}
|
||||
}
|
||||
|
||||
#if TCFG_RECORD_AUDIO_REPLAY_EN
|
||||
|
||||
static void app_recorder_file_play_vol_up()
|
||||
{
|
||||
if (music_player_runing()) {
|
||||
u8 state = app_audio_get_state();
|
||||
s16 vol = app_audio_get_volume(state);
|
||||
printf(">>>>>>>>> state:%d, vol:%d\n", state, vol);
|
||||
audio_app_volume_up(1);
|
||||
}
|
||||
}
|
||||
|
||||
static void app_recorder_file_play_vol_down()
|
||||
{
|
||||
if (music_player_runing()) {
|
||||
u8 state = app_audio_get_state();
|
||||
s16 vol = app_audio_get_volume(state);
|
||||
printf(">>>>>>>>> state:%d, vol:%d\n", state, vol);
|
||||
audio_app_volume_down(1);
|
||||
}
|
||||
}
|
||||
|
||||
void app_recorder_file_play_start(void)
|
||||
{
|
||||
struct file_player *player = NULL;
|
||||
if (g_rec_play_hdl.file) {
|
||||
fclose(g_rec_play_hdl.file);
|
||||
g_rec_play_hdl.file = NULL;
|
||||
g_rec_play_hdl.latest_play_file = NULL;
|
||||
}
|
||||
//获取最新的录音文件路径
|
||||
get_latest_rec_file_name();
|
||||
g_rec_play_hdl.file = fopen(g_rec_play_hdl.path, "r"); //不能用wr+或者r+参数,这样会导致fclose时截断文件数据
|
||||
|
||||
if (g_rec_play_hdl.file) {
|
||||
/* g_printf("g_rec_play_hdl.file is exist!\n"); */
|
||||
g_rec_play_hdl.latest_play_file = g_rec_play_hdl.file;
|
||||
g_rec_play_hdl.file_index = 2; //回播模式从下一个文件开始播
|
||||
player = music_file_play_callback(g_rec_play_hdl.file, NULL, recorde_file_play_callback, NULL);
|
||||
}
|
||||
|
||||
g_rec_play_hdl.player = player;
|
||||
}
|
||||
|
||||
void app_recorder_file_play_stop(void)
|
||||
{
|
||||
printf("music_player_runing: %d\n", music_player_runing());
|
||||
app_local_record_mutex_create();
|
||||
os_mutex_pend(&record_mutex, 0);
|
||||
if (music_player_runing()) {
|
||||
music_file_player_stop();
|
||||
g_rec_play_hdl.player = NULL;
|
||||
}
|
||||
if (g_rec_play_hdl.file) {
|
||||
fclose(g_rec_play_hdl.file);
|
||||
g_rec_play_hdl.file = NULL;
|
||||
}
|
||||
|
||||
os_mutex_post(&record_mutex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//开始播放文件
|
||||
static struct file_player *recorder_file_play_start(void)
|
||||
{
|
||||
struct file_player *player = NULL;
|
||||
if (g_rec_play_hdl.file) {
|
||||
fclose(g_rec_play_hdl.file);
|
||||
g_rec_play_hdl.file = NULL;
|
||||
}
|
||||
//获取最新的录音文件路径
|
||||
get_latest_rec_file_name();
|
||||
g_rec_play_hdl.file = fopen(g_rec_play_hdl.path, "r"); //不能用wr+或者r+参数,这样会导致fclose时截断文件数据
|
||||
|
||||
if (g_rec_play_hdl.file) {
|
||||
g_printf("g_rec_play_hdl.file is exist!\n");
|
||||
player = music_file_play_callback(g_rec_play_hdl.file, NULL, recorde_file_play_callback, NULL);
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
//是否正在播放录音文件
|
||||
bool is_recorder_file_play_runing(void)
|
||||
{
|
||||
return ((g_rec_play_hdl.player == NULL) ? 0 : 1);
|
||||
}
|
||||
|
||||
static int recorde_file_play_callback(void *_priv, int parm, enum stream_event event)
|
||||
{
|
||||
/* printf(">>>>> recorde_file_play_callback: %x, parm:%d\n!!\n", event, parm); */
|
||||
if (event == STREAM_EVENT_STOP) {
|
||||
/* y_printf(">> STREAM_EVENT_STOP!\n"); */
|
||||
app_recorder_file_play_stop();
|
||||
#if TCFG_RECORD_AUDIO_REPLAY_EN
|
||||
app_recorder_play_record_folder();
|
||||
#endif
|
||||
} else if (event == STREAM_EVENT_START) {
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//需要播放的录音文件夹
|
||||
void app_recorder_play_record_folder(void)
|
||||
{
|
||||
app_local_record_mutex_create();
|
||||
app_recorder_fsn_scan();
|
||||
/* g_rec_play_hdl.file_index = 1; //下标重新设置为1 */
|
||||
FILE *file = NULL;
|
||||
if (g_rec_play_hdl.fsn && g_rec_play_hdl.file_index <= g_rec_play_hdl.fsn->file_number) {
|
||||
g_printf(">>>>> g_rec_play_hdl.file_index:%d, g_rec_play_hdl.fsn->file_number:%d!\n", g_rec_play_hdl.file_index, g_rec_play_hdl.fsn->file_number);
|
||||
file = fselect(g_rec_play_hdl.fsn, FSEL_BY_NUMBER, g_rec_play_hdl.file_index++);
|
||||
} else {
|
||||
r_printf(">>>>> Record Play Ended!! g_rec_play_hdl.file_index:%d, g_rec_play_hdl.fsn->file_number:%d!\n", g_rec_play_hdl.fsn->file_number, g_rec_play_hdl.fsn->file_number);
|
||||
#if 0
|
||||
//录音文件一直循环播放
|
||||
g_rec_play_hdl.file_index = 1;
|
||||
if (g_rec_play_hdl.file_index <= g_rec_play_hdl.fsn->file_number) {
|
||||
file = fselect(g_rec_play_hdl.fsn, FSEL_BY_NUMBER, g_rec_play_hdl.file_index++);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (file) {
|
||||
g_rec_play_hdl.file = file;
|
||||
g_rec_play_hdl.latest_play_file = file;
|
||||
g_rec_play_hdl.player = music_file_play_callback(g_rec_play_hdl.file, NULL, recorde_file_play_callback, NULL);
|
||||
} else {
|
||||
r_printf(">> file is NULL!, release fsn!!\n");
|
||||
g_rec_play_hdl.player = NULL; //播放结束,加上这句防止ui继续访问异常
|
||||
if (g_rec_play_hdl.fsn) {
|
||||
fscan_release(g_rec_play_hdl.fsn);
|
||||
g_rec_play_hdl.fsn = NULL;
|
||||
g_rec_play_hdl.file_index = 1; //已经循环播放了一轮, 下标重新设置为1
|
||||
}
|
||||
//如果当前模式是音乐模式,则继续播放其它音乐
|
||||
if (app_get_current_mode()->name == APP_MODE_MUSIC) {
|
||||
r_printf("#################### play record file ended! will play other music!!\n");
|
||||
app_send_message(APP_MSG_MUSIC_PLAYE_NEXT_FOLDER, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 播放下一首录音文件
|
||||
void app_recorder_file_play_next(void)
|
||||
{
|
||||
if (is_recorder_file_play_runing()) {
|
||||
y_printf(">>> recorder file play next!!\n");
|
||||
app_recorder_file_play_stop();
|
||||
/* g_rec_play_hdl.file_index++; */
|
||||
app_recorder_play_record_folder();
|
||||
}
|
||||
}
|
||||
|
||||
// 播放上一首录音文件
|
||||
void app_recorder_file_play_prev(void)
|
||||
{
|
||||
if (is_recorder_file_play_runing()) {
|
||||
y_printf(">>> recorder file play prev!!\n");
|
||||
app_recorder_file_play_stop();
|
||||
if (g_rec_play_hdl.file_index - 2 >= 1) {
|
||||
g_rec_play_hdl.file_index = g_rec_play_hdl.file_index - 2;
|
||||
} else {
|
||||
app_recorder_fsn_scan();
|
||||
if (g_rec_play_hdl.fsn) {
|
||||
g_rec_play_hdl.file_index = g_rec_play_hdl.fsn->file_number;
|
||||
}
|
||||
}
|
||||
app_recorder_play_record_folder();
|
||||
}
|
||||
}
|
||||
|
||||
//录音模式删除最近播放的文件
|
||||
void app_recorder_del_cur_play_file(void)
|
||||
{
|
||||
if (music_player_runing()) {
|
||||
music_file_player_stop();
|
||||
g_rec_play_hdl.player = NULL;
|
||||
}
|
||||
|
||||
if (g_rec_play_hdl.fsn) {
|
||||
fscan_release(g_rec_play_hdl.fsn);
|
||||
g_rec_play_hdl.fsn = NULL;
|
||||
g_rec_play_hdl.player = NULL; //播放结束,加上这句防止ui继续访问异常
|
||||
}
|
||||
|
||||
if (g_rec_play_hdl.latest_play_file) {
|
||||
int err = fdelete(g_rec_play_hdl.latest_play_file);
|
||||
if (err) {
|
||||
//删除失败
|
||||
r_printf("[%s, %d] Recorder file delete failed!\n", __func__, __LINE__);
|
||||
fclose(g_rec_play_hdl.latest_play_file);
|
||||
if (g_rec_play_hdl.latest_play_file == g_rec_play_hdl.file) {
|
||||
g_rec_play_hdl.file = NULL;
|
||||
g_rec_play_hdl.latest_play_file = NULL;
|
||||
} else {
|
||||
g_rec_play_hdl.latest_play_file = NULL;
|
||||
}
|
||||
} else {
|
||||
printf("%s Delete file success!\n", __func__);
|
||||
if (g_rec_play_hdl.latest_play_file == g_rec_play_hdl.file) {
|
||||
g_rec_play_hdl.file = NULL;
|
||||
g_rec_play_hdl.latest_play_file = NULL;
|
||||
} else {
|
||||
g_rec_play_hdl.latest_play_file = NULL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
r_printf("%s, %d, Delete file Failed!!\n", __func__, __LINE__);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
struct app_mode *app_enter_record_mode(int arg)
|
||||
{
|
||||
int msg[16];
|
||||
struct app_mode *next_mode;
|
||||
|
||||
y_printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>> Enter Record Mode!!\n");
|
||||
app_record_init();
|
||||
|
||||
while (1) {
|
||||
if (!app_get_message(msg, ARRAY_SIZE(msg), record_mode_key_table)) {
|
||||
printf("app_get_message");
|
||||
continue;
|
||||
}
|
||||
next_mode = app_mode_switch_handler(msg);
|
||||
if (next_mode) {
|
||||
printf("next mode %d", next_mode->name);
|
||||
break;
|
||||
}
|
||||
|
||||
printf("msg %x", msg[0]);
|
||||
switch (msg[0]) {
|
||||
case MSG_FROM_APP:
|
||||
record_app_msg_handler(msg + 1);
|
||||
break;
|
||||
case MSG_FROM_DEVICE:
|
||||
break;
|
||||
}
|
||||
|
||||
app_default_msg_handler(msg);
|
||||
}
|
||||
|
||||
app_record_exit();
|
||||
|
||||
return next_mode;
|
||||
}
|
||||
|
||||
static int record_mode_try_enter()
|
||||
{
|
||||
if (dev_manager_get_total(0)) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int record_mode_try_exit()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct app_mode_ops record_mode_ops = {
|
||||
.try_enter = record_mode_try_enter,
|
||||
.try_exit = record_mode_try_exit,
|
||||
};
|
||||
|
||||
/*
|
||||
* 注册record模式
|
||||
*/
|
||||
REGISTER_APP_MODE(record_mode) = {
|
||||
.name = APP_MODE_RECORD,
|
||||
.index = APP_MODE_RECORD_INDEX,
|
||||
.ops = &record_mode_ops,
|
||||
};
|
||||
|
||||
|
||||
static u8 record_idle_query(void)
|
||||
{
|
||||
return record_idle_flag;
|
||||
}
|
||||
|
||||
REGISTER_LP_TARGET(record_lp_target) = {
|
||||
.name = "record",
|
||||
.is_idle = record_idle_query,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".record_app_msg_handler.data.bss")
|
||||
#pragma data_seg(".record_app_msg_handler.data")
|
||||
#pragma const_seg(".record_app_msg_handler.text.const")
|
||||
#pragma code_seg(".record_app_msg_handler.text")
|
||||
#endif
|
||||
#include "key_driver.h"
|
||||
#include "app_main.h"
|
||||
#include "init.h"
|
||||
|
||||
|
||||
|
||||
#if TCFG_APP_RECORD_EN
|
||||
|
||||
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief mic录音启动
|
||||
@param 无
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void record_mic_start(void)
|
||||
{
|
||||
#if 0
|
||||
struct record_file_fmt fmt = {0};
|
||||
/* char logo[] = {"sd0"}; */ //可以指定设备
|
||||
char folder[] = {REC_FOLDER_NAME}; //录音文件夹名称
|
||||
char filename[] = {"AC69****"}; //录音文件名,不需要加后缀,录音接口会根据编码格式添加后缀
|
||||
|
||||
#if (TCFG_NOR_REC)
|
||||
char logo[] = {"rec_nor"}; //外挂flash录音
|
||||
#elif (FLASH_INSIDE_REC_ENABLE)
|
||||
char logo[] = {"rec_sdfile"}; //内置flash录音
|
||||
#else
|
||||
char *logo = dev_manager_get_phy_logo(dev_manager_find_active(0));//普通设备录音,获取最后活动设备
|
||||
#endif
|
||||
|
||||
fmt.dev = logo;
|
||||
fmt.folder = folder;
|
||||
fmt.filename = filename;
|
||||
#if (RECORDER_MIX_EN)
|
||||
//如果开了混合录音这里获取编码类型是为了使得保存的录音文件格式一致,主要指针对695
|
||||
fmt.coding_type = recorder_mix_get_coding_type();
|
||||
#else
|
||||
fmt.coding_type = AUDIO_CODING_MP3; //编码格式:AUDIO_CODING_WAV, AUDIO_CODING_MP3
|
||||
#endif/*RECORDER_MIX_EN*/
|
||||
fmt.channel = 1; //声道数: 1:单声道 2:双声道
|
||||
fmt.cut_head_time = 300; //录音文件去头时间,单位ms
|
||||
fmt.cut_tail_time = 300; //录音文件去尾时间,单位ms
|
||||
fmt.limit_size = 3000; //录音文件大小最小限制, 单位byte
|
||||
fmt.gain = 8;
|
||||
#if (TCFG_MIC_EFFECT_ENABLE && (RECORDER_MIX_EN == 0))
|
||||
fmt.sample_rate = MIC_EFFECT_SAMPLERATE; //采样率:8000,16000,32000,44100
|
||||
fmt.source = ENCODE_SOURCE_MIX; //录音输入源
|
||||
#else
|
||||
fmt.sample_rate = 44100; //采样率:8000,16000,32000,44100
|
||||
fmt.source = ENCODE_SOURCE_MIC; //录音输入源
|
||||
#endif//TCFG_MIC_EFFECT_ENABLE
|
||||
fmt.err_callback = NULL;
|
||||
int ret = recorder_encode_start(&fmt);
|
||||
if (ret) {
|
||||
log_e("record_mic_start fail !!, dev = %s\n", logo);
|
||||
} else {
|
||||
log_i("record_mic_start succ !!, dev = %s\n", logo);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief mic 录音停止
|
||||
@param 无
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void record_mic_stop(void)
|
||||
{
|
||||
/* recorder_encode_stop(); */
|
||||
}
|
||||
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief mic 录音与回放切换
|
||||
@param 无
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void record_key_pp()
|
||||
{
|
||||
#if 0
|
||||
if (recorder_is_encoding()) {
|
||||
log_i("mic record stop && replay\n");
|
||||
record_mic_stop();
|
||||
record_file_play();
|
||||
} else {
|
||||
record_file_close();
|
||||
record_mic_start();
|
||||
log_i("mic record start\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".record_key_msg_table.data.bss")
|
||||
#pragma data_seg(".record_key_msg_table.data")
|
||||
#pragma const_seg(".record_key_msg_table.text.const")
|
||||
#pragma code_seg(".record_key_msg_table.text")
|
||||
#endif
|
||||
#include "key_driver.h"
|
||||
#include "app_main.h"
|
||||
#include "init.h"
|
||||
|
||||
|
||||
#if TCFG_ADKEY_ENABLE
|
||||
//短按 //长按 //hold //长按抬起 //双击 //三击
|
||||
#if (CONFIG_UI_STYLE != STYLE_JL_SOUNDBOX)
|
||||
const int key_record_ad_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_CHANGE_MODE, APP_MSG_KEY_POWER_OFF, APP_MSG_KEY_POWER_OFF_HOLD, APP_MSG_KEY_POWER_OFF_RELEASE, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ad_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_REC_PP, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ad_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_REC_PAUSE, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ad_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_REC_DEL_CUR_FILE, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ad_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_NEXT, APP_MSG_VOL_UP, APP_MSG_VOL_UP, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ad_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MUSIC_PREV, APP_MSG_VOL_DOWN, APP_MSG_VOL_DOWN, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ad_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ad_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ad_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ad_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
#else /*LCD按键*/
|
||||
const int key_record_ad_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_CHANGE_MODE, APP_MSG_KEY_POWER_OFF, APP_MSG_KEY_POWER_OFF_HOLD, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ad_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_LCD_OK, APP_MSG_LCD_MENU, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ad_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_LCD_DOWN, APP_MSG_LCD_VOL_DEC, APP_MSG_LCD_VOL_DEC, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ad_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_LCD_UP, APP_MSG_LCD_VOL_INC, APP_MSG_LCD_VOL_INC, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ad_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_LCD_MODE, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ad_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ad_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ad_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ad_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ad_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if TCFG_IRKEY_ENABLE
|
||||
//短按 //长按 //hold //长按抬起 //双击 //三击
|
||||
const int key_record_ir_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_KEY_POWER_OFF_INSTANTLY, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ir_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_CHANGE_MODE, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ir_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ir_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ir_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ir_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ir_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ir_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ir_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ir_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ir_num10_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ir_num11_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ir_num12_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ir_num13_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ir_num14_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ir_num15_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ir_num16_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ir_num17_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ir_num18_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ir_num19_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_ir_num20_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
#endif
|
||||
|
||||
#if TCFG_IOKEY_ENABLE
|
||||
//短按 //长按 //hold //长按抬起 //双击 //三击
|
||||
const int key_record_io_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_CHANGE_MODE, APP_MSG_KEY_POWER_OFF, APP_MSG_KEY_POWER_OFF_HOLD, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_io_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_io_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_io_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_io_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_io_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_io_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_io_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_io_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_record_io_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
#endif
|
||||
|
||||
const struct key_remap_table record_mode_key_table[] = {
|
||||
#if TCFG_ADKEY_ENABLE
|
||||
{ .key_value = KEY_AD_NUM0, .remap_table = key_record_ad_num0_msg_table },
|
||||
{ .key_value = KEY_AD_NUM1, .remap_table = key_record_ad_num1_msg_table },
|
||||
{ .key_value = KEY_AD_NUM2, .remap_table = key_record_ad_num2_msg_table },
|
||||
{ .key_value = KEY_AD_NUM3, .remap_table = key_record_ad_num3_msg_table },
|
||||
{ .key_value = KEY_AD_NUM4, .remap_table = key_record_ad_num4_msg_table },
|
||||
{ .key_value = KEY_AD_NUM5, .remap_table = key_record_ad_num5_msg_table },
|
||||
{ .key_value = KEY_AD_NUM6, .remap_table = key_record_ad_num6_msg_table },
|
||||
{ .key_value = KEY_AD_NUM7, .remap_table = key_record_ad_num7_msg_table },
|
||||
{ .key_value = KEY_AD_NUM8, .remap_table = key_record_ad_num8_msg_table },
|
||||
{ .key_value = KEY_AD_NUM9, .remap_table = key_record_ad_num9_msg_table },
|
||||
#endif
|
||||
#if TCFG_IRKEY_ENABLE
|
||||
{ .key_value = KEY_IR_NUM0, .remap_table = key_record_ir_num0_msg_table },
|
||||
{ .key_value = KEY_IR_NUM1, .remap_table = key_record_ir_num1_msg_table },
|
||||
{ .key_value = KEY_IR_NUM2, .remap_table = key_record_ir_num2_msg_table },
|
||||
{ .key_value = KEY_IR_NUM3, .remap_table = key_record_ir_num3_msg_table },
|
||||
{ .key_value = KEY_IR_NUM4, .remap_table = key_record_ir_num4_msg_table },
|
||||
{ .key_value = KEY_IR_NUM5, .remap_table = key_record_ir_num5_msg_table },
|
||||
{ .key_value = KEY_IR_NUM6, .remap_table = key_record_ir_num6_msg_table },
|
||||
{ .key_value = KEY_IR_NUM7, .remap_table = key_record_ir_num7_msg_table },
|
||||
{ .key_value = KEY_IR_NUM8, .remap_table = key_record_ir_num8_msg_table },
|
||||
{ .key_value = KEY_IR_NUM9, .remap_table = key_record_ir_num9_msg_table },
|
||||
{ .key_value = KEY_IR_NUM10, .remap_table = key_record_ir_num10_msg_table },
|
||||
{ .key_value = KEY_IR_NUM11, .remap_table = key_record_ir_num11_msg_table },
|
||||
{ .key_value = KEY_IR_NUM12, .remap_table = key_record_ir_num12_msg_table },
|
||||
{ .key_value = KEY_IR_NUM13, .remap_table = key_record_ir_num13_msg_table },
|
||||
{ .key_value = KEY_IR_NUM14, .remap_table = key_record_ir_num14_msg_table },
|
||||
{ .key_value = KEY_IR_NUM15, .remap_table = key_record_ir_num15_msg_table },
|
||||
{ .key_value = KEY_IR_NUM16, .remap_table = key_record_ir_num16_msg_table },
|
||||
{ .key_value = KEY_IR_NUM17, .remap_table = key_record_ir_num17_msg_table },
|
||||
{ .key_value = KEY_IR_NUM18, .remap_table = key_record_ir_num18_msg_table },
|
||||
{ .key_value = KEY_IR_NUM19, .remap_table = key_record_ir_num19_msg_table },
|
||||
{ .key_value = KEY_IR_NUM20, .remap_table = key_record_ir_num20_msg_table },
|
||||
#endif
|
||||
#if TCFG_IOKEY_ENABLE
|
||||
{ .key_value = KEY_IO_NUM0, .remap_table = key_record_io_num0_msg_table },
|
||||
{ .key_value = KEY_IO_NUM1, .remap_table = key_record_io_num1_msg_table },
|
||||
{ .key_value = KEY_IO_NUM2, .remap_table = key_record_io_num2_msg_table },
|
||||
{ .key_value = KEY_IO_NUM3, .remap_table = key_record_io_num3_msg_table },
|
||||
{ .key_value = KEY_IO_NUM4, .remap_table = key_record_io_num4_msg_table },
|
||||
{ .key_value = KEY_IO_NUM5, .remap_table = key_record_io_num5_msg_table },
|
||||
{ .key_value = KEY_IO_NUM6, .remap_table = key_record_io_num6_msg_table },
|
||||
{ .key_value = KEY_IO_NUM7, .remap_table = key_record_io_num7_msg_table },
|
||||
{ .key_value = KEY_IO_NUM8, .remap_table = key_record_io_num8_msg_table },
|
||||
{ .key_value = KEY_IO_NUM9, .remap_table = key_record_io_num9_msg_table },
|
||||
#endif
|
||||
{ .key_value = 0xff }
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,222 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".alarm_user.data.bss")
|
||||
#pragma data_seg(".alarm_user.data")
|
||||
#pragma const_seg(".alarm_user.text.const")
|
||||
#pragma code_seg(".alarm_user.text")
|
||||
#endif
|
||||
#include "system/includes.h"
|
||||
#include "alarm.h"
|
||||
#include "system/timer.h"
|
||||
#include "app_main.h"
|
||||
#include "tone_player.h"
|
||||
#include "app_task.h"
|
||||
#include "app_tone.h"
|
||||
#include "app_config.h"
|
||||
#include "bt.h"
|
||||
#include "ui/ui_api.h"
|
||||
#include "call/call_common.h"
|
||||
#include "rtc.h"
|
||||
#include "smartbox_user_app.h"
|
||||
|
||||
#if TCFG_APP_RTC_EN
|
||||
|
||||
#define ALARM_RING_MAX 50
|
||||
volatile u16 g_alarm_ring_cnt = 0;
|
||||
static u16 g_ring_playing_timer = 0;
|
||||
|
||||
/*************************************************************
|
||||
此文件函数主要是用户主要修改的文件
|
||||
|
||||
void set_rtc_default_time(struct sys_time *t)
|
||||
设置默认时间的函数
|
||||
|
||||
void alm_wakeup_isr(void)
|
||||
闹钟到达的函数
|
||||
|
||||
void alarm_event_handler(struct sys_event *event, void *priv)
|
||||
监听按键消息接口,应用于随意按键停止闹钟
|
||||
|
||||
int alarm_sys_event_handler(struct sys_event *event)
|
||||
闹钟到达响应接口
|
||||
|
||||
void alarm_ring_start()
|
||||
闹钟铃声播放接口
|
||||
|
||||
void alarm_stop(u8 reason)
|
||||
闹钟铃声停止播放接口
|
||||
**************************************************************/
|
||||
|
||||
static u8 rtc_can_run(void)
|
||||
{
|
||||
printf("%s", __func__);
|
||||
u8 call_status = call_ctrl_get_status();
|
||||
if ((call_status == BT_CALL_ACTIVE) ||
|
||||
(call_status == BT_CALL_OUTGOING) ||
|
||||
(call_status == BT_CALL_ALERT) ||
|
||||
(call_status == BT_CALL_INCOMING)) {
|
||||
//通话过程不允许开rtc
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* u8 set_rtc_default_time(struct sys_time *t, struct _rtc_trim *lrc_trim) */
|
||||
/* { */
|
||||
/* #if (defined(CONFIG_CPU_BR28)) */
|
||||
/* if (read_p11_sys_time(t, lrc_trim)) { */
|
||||
/* g_printf("rtc_read_sys_time: %d-%d-%d %d:%d:%d\n", */
|
||||
/* t->year, t->month, t->day, t->hour, t->min, t->sec); */
|
||||
/* return 1; */
|
||||
/* } */
|
||||
/* #else */
|
||||
/* t->year = 2019; */
|
||||
/* t->month = 5; */
|
||||
/* t->day = 5; */
|
||||
/* t->hour = 18; */
|
||||
/* t->min = 18; */
|
||||
/* t->sec = 18; */
|
||||
/* #endif */
|
||||
/* return 0; */
|
||||
/* } */
|
||||
|
||||
__attribute__((weak))
|
||||
u8 rtc_app_alarm_ring_play(u8 alarm_state)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void alarm_ring_cnt_clear(void)
|
||||
{
|
||||
g_alarm_ring_cnt = 0;
|
||||
}
|
||||
|
||||
void alarm_stop(u8 reason)
|
||||
{
|
||||
u32 rets_addr;
|
||||
__asm__ volatile("%0 = rets ;" : "=r"(rets_addr));
|
||||
printf("%s rets:0x%x", __func__, rets_addr);
|
||||
printf("ALARM_STOP !!!\n");
|
||||
UI_MOTO_RUN(0);
|
||||
#if TCFG_EARPHONE_PROTOCOL
|
||||
custom_client_send_alarm_earphone(0x03);
|
||||
#endif
|
||||
|
||||
if (reason == 1) { //闹钟铃声播放超时
|
||||
#if TCFG_UI_ENABLE && CONFIG_JL_UI_ENABLE
|
||||
if (get_need_password() == 1) {
|
||||
UI_WINDOW_PREEMPTION_POP(ID_WINDOW_ALARM_RINGING);
|
||||
UI_SHOW_WINDOW(ID_WINDOW_POWERON_PASSWORD);
|
||||
} else {
|
||||
UI_WINDOW_PREEMPTION_POP(ID_WINDOW_ALARM_RINGING);
|
||||
}
|
||||
#endif
|
||||
alarm_snooze(); // 若播放铃声超时直接设置贪睡模式
|
||||
}
|
||||
#if TCFG_USER_EMITTER_ENABLE
|
||||
emitter_close(1);
|
||||
#endif
|
||||
alarm_active_flag_set(0);
|
||||
alarm_ring_cnt_clear();
|
||||
rtc_app_alarm_ring_play(0);
|
||||
}
|
||||
|
||||
void alarm_play_timer_del(void)
|
||||
{
|
||||
if (g_ring_playing_timer) {
|
||||
sys_timeout_del(g_ring_playing_timer);
|
||||
g_ring_playing_timer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void __alarm_ring_play(void *p)
|
||||
{
|
||||
if (alarm_active_flag_get()) {
|
||||
if (g_alarm_ring_cnt > 0) {
|
||||
if (!tone_player_runing()) {
|
||||
if (!rtc_app_alarm_ring_play(1)) {
|
||||
play_tone_file_alone(get_tone_files()->num[0]);
|
||||
g_alarm_ring_cnt--;
|
||||
}
|
||||
sys_timeout_add(NULL, __alarm_ring_play, 500);
|
||||
} else {
|
||||
sys_timeout_add(NULL, __alarm_ring_play, 500);
|
||||
}
|
||||
} else {
|
||||
alarm_stop(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void alarm_ring_start()
|
||||
{
|
||||
UI_MOTO_RUN(1);
|
||||
#if TCFG_EARPHONE_PROTOCOL
|
||||
custom_client_send_alarm_earphone(0x12);
|
||||
#endif
|
||||
|
||||
printf("ALARM_RING_START !!!\n");
|
||||
if (g_alarm_ring_cnt == 0) {
|
||||
g_alarm_ring_cnt = ALARM_RING_MAX;
|
||||
#if TCFG_USER_EMITTER_ENABLE
|
||||
emitter_open(1);
|
||||
#endif
|
||||
sys_timeout_add(NULL, __alarm_ring_play, 500);
|
||||
}
|
||||
}
|
||||
|
||||
#if TCFG_UI_ENABLE
|
||||
|
||||
static int alarm_ui_entry(int page)
|
||||
{
|
||||
alarm_ring_start();
|
||||
return false;
|
||||
}
|
||||
|
||||
static int alarm_ui_exit(int page)
|
||||
{
|
||||
alarm_stop(0);
|
||||
return false;
|
||||
}
|
||||
#endif /* #if TCFG_UI_ENABLE */
|
||||
|
||||
void alm_wakeup_isr(void)
|
||||
{
|
||||
int msg[2];
|
||||
msg[0] = (u32)DEVICE_EVENT_FROM_ALM;
|
||||
alarm_active_flag_set(true);
|
||||
/*如果关机后由闹钟唤醒,不想立马执行闹钟回调
|
||||
则使用该判断,留到alarm_init()再去判断时间发消息执行*/
|
||||
if (app_var.start_time == 0) {
|
||||
return;
|
||||
}
|
||||
msg[1] = DEVICE_EVENT_IN;
|
||||
app_send_message_from(MSG_FROM_DEVICE, sizeof(msg), msg);
|
||||
}
|
||||
|
||||
static int alarm_event_handler(int *msg)
|
||||
{
|
||||
int ret = 0;
|
||||
if (msg[0] == DEVICE_EVENT_FROM_ALM) {
|
||||
switch (msg[1]) {
|
||||
case DEVICE_EVENT_IN:
|
||||
printf("<%s>", __func__);
|
||||
alarm_update_info_after_isr();
|
||||
UI_WINDOW_PREEMPTION_POSH(ID_WINDOW_ALARM_RINGING, alarm_ui_entry, alarm_ui_exit, UI_WINDOW_PREEMPTION_TYPE_ALARM);
|
||||
ret = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret; /* 1:截获alarm消息,app应用不会收到消息 0:消息继续分发 */
|
||||
}
|
||||
|
||||
APP_MSG_PROB_HANDLER(alarm_msg_entry) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_DEVICE,
|
||||
.handler = alarm_event_handler,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,611 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".rtc.data.bss")
|
||||
#pragma data_seg(".rtc.data")
|
||||
#pragma const_seg(".rtc.text.const")
|
||||
#pragma code_seg(".rtc.text")
|
||||
#endif
|
||||
#include "system/includes.h"
|
||||
#include "app_action.h"
|
||||
#include "app_main.h"
|
||||
#include "default_event_handler.h"
|
||||
#include "bt.h"
|
||||
#include "tone_player.h"
|
||||
#include "app_tone.h"
|
||||
#include "rtc_ui.h"
|
||||
#include "rtc.h"
|
||||
#include "alarm.h"
|
||||
#include "ui/ui_api.h"
|
||||
#include "ui_manage.h"
|
||||
|
||||
#if TCFG_APP_RTC_EN
|
||||
|
||||
#define LOG_TAG "[APP_RTC]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
/* #define LOG_DUMP_ENABLE */
|
||||
#define LOG_CLI_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
#define RTC_SET_MODE 0x55
|
||||
#define ALM_SET_MODE 0xAA
|
||||
|
||||
#define RTC_POS_DEFAULT RTC_POS_YEAR
|
||||
#define RTC_ALM_POS_DEFAULT ALM_POS_HOUR
|
||||
#define RTC_MODE_DEFAULT RTC_SET_MODE
|
||||
|
||||
#define MAX_YEAR 2099
|
||||
#define MIN_YEAR 2000
|
||||
|
||||
enum {
|
||||
RTC_POS_NULL = 0,
|
||||
RTC_POS_YEAR,
|
||||
RTC_POS_MONTH,
|
||||
RTC_POS_DAY,
|
||||
RTC_POS_HOUR,
|
||||
RTC_POS_MIN,
|
||||
/* RTC_POS_SEC, */
|
||||
RTC_POS_MAX,
|
||||
ALM_POS_HOUR,
|
||||
ALM_POS_MIN,
|
||||
ALM_POS_ENABLE,
|
||||
ALM_POS_MAX,
|
||||
};
|
||||
|
||||
struct rtc_opr {
|
||||
u8 rtc_set_mode;
|
||||
u8 rtc_pos;
|
||||
u8 alm_enable;
|
||||
u8 alm_num;
|
||||
struct sys_time set_time;
|
||||
};
|
||||
|
||||
static struct rtc_opr *__this = NULL;
|
||||
|
||||
const char *alm_string[] = {" AL ", " ON ", " OFF"};
|
||||
const char *alm_select[] = {"AL-1", "AL-2", "AL-3", "AL-4", "AL-5"};
|
||||
|
||||
static void ui_set_rtc_timeout(int menu)
|
||||
{
|
||||
if (!__this) {
|
||||
return ;
|
||||
}
|
||||
__this->rtc_set_mode = RTC_SET_MODE;
|
||||
__this->rtc_pos = RTC_POS_NULL;
|
||||
}
|
||||
|
||||
struct ui_rtc_display *__attribute__((weak)) rtc_ui_get_display_buf()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief rtc 闹钟设置 \ 时间设置转换
|
||||
@param 无
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void set_rtc_sw()
|
||||
{
|
||||
#if TCFG_UI_ENABLE
|
||||
if (!__this) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct ui_rtc_display *rtc = rtc_ui_get_display_buf();
|
||||
|
||||
if (!rtc) {
|
||||
return;
|
||||
}
|
||||
switch (__this->rtc_set_mode) {
|
||||
case RTC_SET_MODE:
|
||||
__this->rtc_set_mode = ALM_SET_MODE;
|
||||
__this->rtc_pos = RTC_POS_NULL;
|
||||
__this->alm_num = 0;
|
||||
rtc->rtc_menu = UI_RTC_ACTION_STRING_SET;
|
||||
rtc->str = alm_select[__this->alm_num];
|
||||
|
||||
app_send_message(APP_MSG_RTC_SET, (int)ui_set_rtc_timeout);
|
||||
break;
|
||||
|
||||
case ALM_SET_MODE:
|
||||
__this->alm_num++;
|
||||
__this->rtc_pos = RTC_POS_NULL;
|
||||
if (__this->alm_num >= sizeof(alm_select) / sizeof(alm_select[0])) {
|
||||
__this->rtc_set_mode = RTC_SET_MODE;
|
||||
__this->alm_num = 0;
|
||||
UI_REFLASH_WINDOW(true);
|
||||
break;
|
||||
}
|
||||
rtc->rtc_menu = UI_RTC_ACTION_STRING_SET;
|
||||
rtc->str = alm_select[__this->alm_num];
|
||||
app_send_message(APP_MSG_RTC_SET, (int)ui_set_rtc_timeout);
|
||||
break;
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief rtc 设置调整时钟的位置
|
||||
@param 无
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void set_rtc_pos()
|
||||
{
|
||||
#if TCFG_UI_ENABLE
|
||||
T_ALARM alarm = {0};
|
||||
if (!__this) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct ui_rtc_display *rtc = rtc_ui_get_display_buf();
|
||||
|
||||
if (!rtc) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (__this->rtc_set_mode) {
|
||||
case RTC_SET_MODE:
|
||||
|
||||
if (__this->rtc_pos == RTC_POS_NULL) {
|
||||
__this->rtc_pos = RTC_POS_DEFAULT;
|
||||
rtc_read_time(&__this->set_time);
|
||||
} else {
|
||||
__this->rtc_pos++;
|
||||
if (__this->rtc_pos == RTC_POS_MAX) {
|
||||
__this->rtc_pos = RTC_POS_NULL;
|
||||
rtc_update_time_api(&__this->set_time);
|
||||
UI_REFLASH_WINDOW(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
rtc->rtc_menu = UI_RTC_ACTION_YEAR_SET + (__this->rtc_pos - RTC_POS_YEAR);
|
||||
|
||||
rtc->time.Year = __this->set_time.year;
|
||||
rtc->time.Month = __this->set_time.month;
|
||||
rtc->time.Day = __this->set_time.day;
|
||||
rtc->time.Hour = __this->set_time.hour;
|
||||
rtc->time.Min = __this->set_time.min;
|
||||
rtc->time.Sec = __this->set_time.sec;
|
||||
|
||||
app_send_message(APP_MSG_RTC_SET, (int)ui_set_rtc_timeout);
|
||||
break;
|
||||
|
||||
case ALM_SET_MODE:
|
||||
if (__this->rtc_pos == RTC_POS_NULL) {
|
||||
__this->rtc_pos = RTC_ALM_POS_DEFAULT;
|
||||
if (alarm_get_info(&alarm, __this->alm_num) != 0) {
|
||||
log_error("alarm_get_info \n");
|
||||
}
|
||||
|
||||
__this->set_time.hour = alarm.time.hour;
|
||||
__this->set_time.min = alarm.time.min;
|
||||
__this->alm_enable = alarm.sw;
|
||||
|
||||
} else {
|
||||
__this->rtc_pos++;
|
||||
if (__this->rtc_pos == ALM_POS_MAX) {
|
||||
__this->rtc_pos = RTC_POS_NULL;
|
||||
alarm.time.hour = __this->set_time.hour;
|
||||
alarm.time.min = __this->set_time.min;
|
||||
alarm.time.sec = 0;
|
||||
alarm.sw = __this->alm_enable;
|
||||
alarm.index = __this->alm_num;
|
||||
alarm.mode = 0;
|
||||
alarm_add(&alarm, __this->alm_num);
|
||||
__this->alm_num++;
|
||||
if (__this->alm_num >= sizeof(alm_select) / sizeof(alm_select[0])) {
|
||||
__this->rtc_set_mode = RTC_SET_MODE;
|
||||
__this->alm_num = 0;
|
||||
UI_REFLASH_WINDOW(true);
|
||||
} else {
|
||||
rtc->rtc_menu = UI_RTC_ACTION_STRING_SET;
|
||||
rtc->str = alm_select[__this->alm_num];
|
||||
app_send_message(APP_MSG_RTC_SET, (int)ui_set_rtc_timeout);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ALM_POS_ENABLE == __this->rtc_pos) {
|
||||
rtc->rtc_menu = UI_RTC_ACTION_STRING_SET;
|
||||
if (__this->alm_enable) {
|
||||
rtc->str = " ON ";
|
||||
} else {
|
||||
rtc->str = " OFF";
|
||||
}
|
||||
} else {
|
||||
rtc->rtc_menu = UI_RTC_ACTION_HOUR_SET + (__this->rtc_pos - ALM_POS_HOUR);
|
||||
rtc->time.Year = __this->set_time.year;
|
||||
rtc->time.Month = __this->set_time.month;
|
||||
rtc->time.Day = __this->set_time.day;
|
||||
rtc->time.Hour = __this->set_time.hour;
|
||||
rtc->time.Min = __this->set_time.min;
|
||||
rtc->time.Sec = __this->set_time.sec;
|
||||
}
|
||||
|
||||
app_send_message(APP_MSG_RTC_SET, (int)ui_set_rtc_timeout);
|
||||
break;
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief rtc 调整时钟 加时间
|
||||
@param 无
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void set_rtc_up()
|
||||
{
|
||||
|
||||
#if TCFG_UI_ENABLE
|
||||
if (!__this) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct ui_rtc_display *rtc = rtc_ui_get_display_buf();
|
||||
|
||||
if (!rtc) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (__this->rtc_pos == RTC_POS_NULL) {
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
switch (__this->rtc_set_mode) {
|
||||
case RTC_SET_MODE:
|
||||
switch (__this->rtc_pos) {
|
||||
case RTC_POS_YEAR:
|
||||
__this->set_time.year++;
|
||||
if (__this->set_time.year > MAX_YEAR) {
|
||||
__this->set_time.year = MIN_YEAR;
|
||||
}
|
||||
break;
|
||||
case RTC_POS_MONTH:
|
||||
if (++__this->set_time.month > 12) {
|
||||
__this->set_time.month = 1;
|
||||
}
|
||||
break;
|
||||
case RTC_POS_DAY:
|
||||
if (++__this->set_time.day > month_for_day(__this->set_time.month, __this->set_time.year)) {
|
||||
__this->set_time.day = 1;
|
||||
}
|
||||
break;
|
||||
case RTC_POS_HOUR:
|
||||
if (++__this->set_time.hour >= 24) {
|
||||
__this->set_time.hour = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case RTC_POS_MIN:
|
||||
if (++__this->set_time.min >= 60) {
|
||||
__this->set_time.min = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
rtc->rtc_menu = UI_RTC_ACTION_YEAR_SET + (__this->rtc_pos - RTC_POS_YEAR);
|
||||
rtc->time.Year = __this->set_time.year;
|
||||
rtc->time.Month = __this->set_time.month;
|
||||
rtc->time.Day = __this->set_time.day;
|
||||
rtc->time.Hour = __this->set_time.hour;
|
||||
rtc->time.Min = __this->set_time.min;
|
||||
rtc->time.Sec = __this->set_time.sec;
|
||||
app_send_message(APP_MSG_RTC_SET, (int)ui_set_rtc_timeout);
|
||||
break;
|
||||
case ALM_SET_MODE:
|
||||
|
||||
switch (__this->rtc_pos) {
|
||||
case ALM_POS_HOUR:
|
||||
if (++__this->set_time.hour >= 24) {
|
||||
__this->set_time.hour = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case ALM_POS_MIN:
|
||||
if (++__this->set_time.min >= 60) {
|
||||
__this->set_time.min = 0;
|
||||
}
|
||||
break;
|
||||
case ALM_POS_ENABLE:
|
||||
__this->alm_enable = !__this->alm_enable;
|
||||
break;
|
||||
}
|
||||
|
||||
if (ALM_POS_ENABLE == __this->rtc_pos) {
|
||||
rtc->rtc_menu = UI_RTC_ACTION_STRING_SET;
|
||||
if (__this->alm_enable) {
|
||||
rtc->str = " ON ";
|
||||
} else {
|
||||
rtc->str = " OFF";
|
||||
}
|
||||
} else {
|
||||
rtc->rtc_menu = UI_RTC_ACTION_HOUR_SET + (__this->rtc_pos - ALM_POS_HOUR);
|
||||
rtc->time.Year = __this->set_time.year;
|
||||
rtc->time.Month = __this->set_time.month;
|
||||
rtc->time.Day = __this->set_time.day;
|
||||
rtc->time.Hour = __this->set_time.hour;
|
||||
rtc->time.Min = __this->set_time.min;
|
||||
rtc->time.Sec = __this->set_time.sec;
|
||||
}
|
||||
|
||||
app_send_message(APP_MSG_RTC_SET, (int)ui_set_rtc_timeout);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief rtc 调整时钟 减时间
|
||||
@param 无
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void set_rtc_down()
|
||||
{
|
||||
#if TCFG_UI_ENABLE
|
||||
if (!__this) {
|
||||
return;
|
||||
}
|
||||
struct ui_rtc_display *rtc = rtc_ui_get_display_buf();
|
||||
|
||||
if (!rtc) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (__this->rtc_pos == RTC_POS_NULL) {
|
||||
return ;
|
||||
}
|
||||
|
||||
switch (__this->rtc_set_mode) {
|
||||
case RTC_SET_MODE:
|
||||
switch (__this->rtc_pos) {
|
||||
case RTC_POS_YEAR:
|
||||
__this->set_time.year--;
|
||||
if (__this->set_time.year < MIN_YEAR) {
|
||||
__this->set_time.year = MAX_YEAR;
|
||||
}
|
||||
break;
|
||||
case RTC_POS_MONTH:
|
||||
|
||||
if (__this->set_time.month == 1) {
|
||||
__this->set_time.month = 12;
|
||||
} else {
|
||||
__this->set_time.month--;
|
||||
}
|
||||
|
||||
break;
|
||||
case RTC_POS_DAY:
|
||||
|
||||
if (__this->set_time.day == 1) {
|
||||
__this->set_time.day = month_for_day(__this->set_time.month, __this->set_time.year);
|
||||
} else {
|
||||
__this->set_time.day --;
|
||||
}
|
||||
|
||||
break;
|
||||
case RTC_POS_HOUR:
|
||||
if (__this->set_time.hour == 0) {
|
||||
__this->set_time.hour = 23;
|
||||
} else {
|
||||
__this->set_time.hour--;
|
||||
}
|
||||
break;
|
||||
case RTC_POS_MIN:
|
||||
if (__this->set_time.min == 0) {
|
||||
__this->set_time.min = 59;
|
||||
} else {
|
||||
__this->set_time.min--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
rtc->rtc_menu = UI_RTC_ACTION_YEAR_SET + (__this->rtc_pos - RTC_POS_YEAR);
|
||||
rtc->time.Year = __this->set_time.year;
|
||||
rtc->time.Month = __this->set_time.month;
|
||||
rtc->time.Day = __this->set_time.day;
|
||||
rtc->time.Hour = __this->set_time.hour;
|
||||
rtc->time.Min = __this->set_time.min;
|
||||
rtc->time.Sec = __this->set_time.sec;
|
||||
app_send_message(APP_MSG_RTC_SET, (int)ui_set_rtc_timeout);
|
||||
break;
|
||||
|
||||
case ALM_SET_MODE:
|
||||
switch (__this->rtc_pos) {
|
||||
case ALM_POS_HOUR:
|
||||
if (__this->set_time.hour == 0) {
|
||||
__this->set_time.hour = 23;
|
||||
} else {
|
||||
__this->set_time.hour--;
|
||||
}
|
||||
break;
|
||||
|
||||
case ALM_POS_MIN:
|
||||
if (__this->set_time.min == 0) {
|
||||
__this->set_time.min = 59;
|
||||
} else {
|
||||
__this->set_time.min--;
|
||||
}
|
||||
break;
|
||||
|
||||
case ALM_POS_ENABLE:
|
||||
__this->alm_enable = !__this->alm_enable;
|
||||
break;
|
||||
}
|
||||
|
||||
if (ALM_POS_ENABLE == __this->rtc_pos) {
|
||||
rtc->rtc_menu = UI_RTC_ACTION_STRING_SET;
|
||||
if (__this->alm_enable) {
|
||||
rtc->str = " ON ";
|
||||
} else {
|
||||
rtc->str = " OFF";
|
||||
}
|
||||
} else {
|
||||
rtc->rtc_menu = UI_RTC_ACTION_HOUR_SET + (__this->rtc_pos - ALM_POS_HOUR);
|
||||
rtc->time.Year = __this->set_time.year;
|
||||
rtc->time.Month = __this->set_time.month;
|
||||
rtc->time.Day = __this->set_time.day;
|
||||
rtc->time.Hour = __this->set_time.hour;
|
||||
rtc->time.Min = __this->set_time.min;
|
||||
rtc->time.Sec = __this->set_time.sec;
|
||||
}
|
||||
app_send_message(APP_MSG_RTC_SET, (int)ui_set_rtc_timeout);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief rtc 退出
|
||||
@param 无
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void rtc_task_close()
|
||||
{
|
||||
#if RCSP_MODE
|
||||
extern void rcsp_rtc_mode_exit(void);
|
||||
rcsp_rtc_mode_exit();
|
||||
#endif
|
||||
if (__this) {
|
||||
free(__this);
|
||||
__this = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void rtc_app_init()
|
||||
{
|
||||
if (!__this) {
|
||||
__this = zalloc(sizeof(struct rtc_opr));
|
||||
ASSERT(__this, "%s %di \n", __func__, __LINE__);
|
||||
}
|
||||
__this->rtc_set_mode = RTC_SET_MODE;
|
||||
__this->rtc_pos = RTC_POS_NULL;
|
||||
|
||||
//ui_update_status(STATUS_RTC_MODE);
|
||||
}
|
||||
|
||||
//*----------------------------------------------------------------------------*/
|
||||
/**@brief rtc 启动
|
||||
@param 无
|
||||
@return
|
||||
@note
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void rtc_task_start()
|
||||
{
|
||||
rtc_app_init();
|
||||
if (alarm_active_flag_get()) {
|
||||
alarm_ring_start();
|
||||
}
|
||||
}
|
||||
|
||||
static int rtc_tone_play_end_callback(void *priv, enum stream_event event)
|
||||
{
|
||||
rtc_task_start();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int app_rtc_init()
|
||||
{
|
||||
log_info("rtc start");
|
||||
#if (RCSP_MODE)
|
||||
extern u8 rcsp_rtc_ring_tone(void);
|
||||
if (rcsp_rtc_ring_tone()) {
|
||||
play_tone_file_callback(get_tone_files()->rtc_mode, NULL, rtc_tone_play_end_callback);
|
||||
}
|
||||
#else
|
||||
tone_player_stop();
|
||||
int ret = play_tone_file_callback(get_tone_files()->rtc_mode, NULL, rtc_tone_play_end_callback);
|
||||
if (ret) {
|
||||
log_error("rtc tone play err!!!");
|
||||
rtc_task_start();
|
||||
}
|
||||
#endif
|
||||
app_send_message(APP_MSG_ENTER_MODE, APP_MODE_RTC);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void app_rtc_exit()
|
||||
{
|
||||
rtc_task_close();
|
||||
app_send_message(APP_MSG_EXIT_MODE, APP_MODE_RTC);
|
||||
}
|
||||
|
||||
struct app_mode *app_enter_rtc_mode(int arg)
|
||||
{
|
||||
int msg[16];
|
||||
struct app_mode *next_mode;
|
||||
|
||||
app_rtc_init();
|
||||
|
||||
while (1) {
|
||||
if (!app_get_message(msg, ARRAY_SIZE(msg), rtc_mode_key_table)) {
|
||||
continue;
|
||||
}
|
||||
next_mode = app_mode_switch_handler(msg);
|
||||
if (next_mode) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (msg[0]) {
|
||||
case MSG_FROM_APP:
|
||||
rtc_app_msg_handler(msg + 1);
|
||||
break;
|
||||
case MSG_FROM_DEVICE:
|
||||
break;
|
||||
}
|
||||
|
||||
app_default_msg_handler(msg);
|
||||
}
|
||||
|
||||
app_rtc_exit();
|
||||
|
||||
return next_mode;
|
||||
}
|
||||
|
||||
static int rtc_mode_try_enter(int arg)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rtc_mode_try_exit()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct app_mode_ops rtc_mode_ops = {
|
||||
.try_enter = rtc_mode_try_enter,
|
||||
.try_exit = rtc_mode_try_exit,
|
||||
};
|
||||
|
||||
/*
|
||||
* 注册rtc模式
|
||||
*/
|
||||
REGISTER_APP_MODE(rtc_mode) = {
|
||||
.name = APP_MODE_RTC,
|
||||
.index = APP_MODE_RTC_INDEX,
|
||||
.ops = &rtc_mode_ops,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".rtc_app_msg_handler.data.bss")
|
||||
#pragma data_seg(".rtc_app_msg_handler.data")
|
||||
#pragma const_seg(".rtc_app_msg_handler.text.const")
|
||||
#pragma code_seg(".rtc_app_msg_handler.text")
|
||||
#endif
|
||||
#include "key_driver.h"
|
||||
#include "app_main.h"
|
||||
#include "init.h"
|
||||
#include "rtc.h"
|
||||
|
||||
#if TCFG_APP_RTC_EN
|
||||
|
||||
int rtc_app_msg_handler(int *msg)
|
||||
{
|
||||
if (false == app_in_mode(APP_MODE_RTC)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (msg[0]) {
|
||||
case APP_MSG_CHANGE_MODE:
|
||||
printf("APP_MSG_CHANGE_MODE\n");
|
||||
app_send_message(APP_MSG_GOTO_NEXT_MODE, 0);
|
||||
break;
|
||||
case APP_MSG_RTC_UP:
|
||||
printf("APP_MSG_RTC_UP \n");
|
||||
set_rtc_up();
|
||||
break;
|
||||
case APP_MSG_RTC_DOWN:
|
||||
printf("APP_MSG_RTC_DOWN \n");
|
||||
set_rtc_down();
|
||||
break;
|
||||
case APP_MSG_RTC_SW:
|
||||
printf("APP_MSG_RTC_SW \n");
|
||||
set_rtc_sw();
|
||||
break;
|
||||
case APP_MSG_RTC_SW_POS:
|
||||
printf("APP_MSG_RTC_SW_POS \n");
|
||||
set_rtc_pos();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,231 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".rtc_key_msg_table.data.bss")
|
||||
#pragma data_seg(".rtc_key_msg_table.data")
|
||||
#pragma const_seg(".rtc_key_msg_table.text.const")
|
||||
#pragma code_seg(".rtc_key_msg_table.text")
|
||||
#endif
|
||||
#include "key_driver.h"
|
||||
#include "app_main.h"
|
||||
#include "init.h"
|
||||
|
||||
|
||||
#if TCFG_ADKEY_ENABLE
|
||||
//短按 //长按 //hold //长按抬起 //双击 //三击
|
||||
#if (CONFIG_UI_STYLE != STYLE_JL_SOUNDBOX)
|
||||
const int key_rtc_ad_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_CHANGE_MODE, APP_MSG_KEY_POWER_OFF, APP_MSG_KEY_POWER_OFF_HOLD, APP_MSG_KEY_POWER_OFF_RELEASE, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ad_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_RTC_DOWN, APP_MSG_RTC_DOWN, APP_MSG_RTC_DOWN, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ad_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_RTC_SW_POS, APP_MSG_RTC_SW, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ad_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_RTC_UP, APP_MSG_RTC_UP, APP_MSG_RTC_UP, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ad_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ad_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ad_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_SWITCH_MIC_EFFECT, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_MIC_EFFECT_ON_OFF, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ad_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ad_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MIC_VOL_UP, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ad_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_MIC_VOL_DOWN, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
#else /*LCD按键*/
|
||||
const int key_rtc_ad_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_CHANGE_MODE, APP_MSG_KEY_POWER_OFF, APP_MSG_KEY_POWER_OFF_HOLD, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ad_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_LCD_OK, APP_MSG_LCD_MENU, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ad_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_LCD_DOWN, APP_MSG_LCD_VOL_DEC, APP_MSG_LCD_VOL_DEC, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ad_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_LCD_UP, APP_MSG_LCD_VOL_INC, APP_MSG_LCD_VOL_INC, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ad_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_LCD_MODE, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ad_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ad_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ad_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ad_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ad_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if TCFG_IRKEY_ENABLE
|
||||
//短按 //长按 //hold //长按抬起 //双击 //三击
|
||||
const int key_rtc_ir_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_KEY_POWER_OFF_INSTANTLY, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ir_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_CHANGE_MODE, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ir_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ir_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ir_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ir_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ir_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ir_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ir_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ir_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ir_num10_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ir_num11_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ir_num12_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ir_num13_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ir_num14_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ir_num15_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ir_num16_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ir_num17_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ir_num18_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ir_num19_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_ir_num20_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if TCFG_IOKEY_ENABLE
|
||||
//短按 //长按 //hold //长按抬起 //双击 //三击
|
||||
const int key_rtc_io_num0_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_CHANGE_MODE, APP_MSG_KEY_POWER_OFF, APP_MSG_KEY_POWER_OFF_HOLD, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_io_num1_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_RTC_DOWN, APP_MSG_RTC_DOWN, APP_MSG_RTC_DOWN, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_io_num2_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_RTC_SW_POS, APP_MSG_RTC_SW, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_io_num3_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_RTC_UP, APP_MSG_RTC_UP, APP_MSG_RTC_UP, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_io_num4_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_io_num5_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_io_num6_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_io_num7_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_io_num8_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
const int key_rtc_io_num9_msg_table[KEY_ACTION_MAX] = {
|
||||
APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL, APP_MSG_NULL,
|
||||
};
|
||||
#endif
|
||||
|
||||
const struct key_remap_table rtc_mode_key_table[] = {
|
||||
#if TCFG_ADKEY_ENABLE
|
||||
{ .key_value = KEY_AD_NUM0, .remap_table = key_rtc_ad_num0_msg_table },
|
||||
{ .key_value = KEY_AD_NUM1, .remap_table = key_rtc_ad_num1_msg_table },
|
||||
{ .key_value = KEY_AD_NUM2, .remap_table = key_rtc_ad_num2_msg_table },
|
||||
{ .key_value = KEY_AD_NUM3, .remap_table = key_rtc_ad_num3_msg_table },
|
||||
{ .key_value = KEY_AD_NUM4, .remap_table = key_rtc_ad_num4_msg_table },
|
||||
{ .key_value = KEY_AD_NUM5, .remap_table = key_rtc_ad_num5_msg_table },
|
||||
{ .key_value = KEY_AD_NUM6, .remap_table = key_rtc_ad_num6_msg_table },
|
||||
{ .key_value = KEY_AD_NUM7, .remap_table = key_rtc_ad_num7_msg_table },
|
||||
{ .key_value = KEY_AD_NUM8, .remap_table = key_rtc_ad_num8_msg_table },
|
||||
{ .key_value = KEY_AD_NUM9, .remap_table = key_rtc_ad_num9_msg_table },
|
||||
#endif
|
||||
#if TCFG_IRKEY_ENABLE
|
||||
{ .key_value = KEY_IR_NUM0, .remap_table = key_rtc_ir_num0_msg_table },
|
||||
{ .key_value = KEY_IR_NUM1, .remap_table = key_rtc_ir_num1_msg_table },
|
||||
{ .key_value = KEY_IR_NUM2, .remap_table = key_rtc_ir_num2_msg_table },
|
||||
{ .key_value = KEY_IR_NUM3, .remap_table = key_rtc_ir_num3_msg_table },
|
||||
{ .key_value = KEY_IR_NUM4, .remap_table = key_rtc_ir_num4_msg_table },
|
||||
{ .key_value = KEY_IR_NUM5, .remap_table = key_rtc_ir_num5_msg_table },
|
||||
{ .key_value = KEY_IR_NUM6, .remap_table = key_rtc_ir_num6_msg_table },
|
||||
{ .key_value = KEY_IR_NUM7, .remap_table = key_rtc_ir_num7_msg_table },
|
||||
{ .key_value = KEY_IR_NUM8, .remap_table = key_rtc_ir_num8_msg_table },
|
||||
{ .key_value = KEY_IR_NUM9, .remap_table = key_rtc_ir_num9_msg_table },
|
||||
{ .key_value = KEY_IR_NUM10, .remap_table = key_rtc_ir_num10_msg_table },
|
||||
{ .key_value = KEY_IR_NUM11, .remap_table = key_rtc_ir_num11_msg_table },
|
||||
{ .key_value = KEY_IR_NUM12, .remap_table = key_rtc_ir_num12_msg_table },
|
||||
{ .key_value = KEY_IR_NUM13, .remap_table = key_rtc_ir_num13_msg_table },
|
||||
{ .key_value = KEY_IR_NUM14, .remap_table = key_rtc_ir_num14_msg_table },
|
||||
{ .key_value = KEY_IR_NUM15, .remap_table = key_rtc_ir_num15_msg_table },
|
||||
{ .key_value = KEY_IR_NUM16, .remap_table = key_rtc_ir_num16_msg_table },
|
||||
{ .key_value = KEY_IR_NUM17, .remap_table = key_rtc_ir_num17_msg_table },
|
||||
{ .key_value = KEY_IR_NUM18, .remap_table = key_rtc_ir_num18_msg_table },
|
||||
{ .key_value = KEY_IR_NUM19, .remap_table = key_rtc_ir_num19_msg_table },
|
||||
{ .key_value = KEY_IR_NUM20, .remap_table = key_rtc_ir_num20_msg_table },
|
||||
#endif
|
||||
#if TCFG_IOKEY_ENABLE
|
||||
{ .key_value = KEY_IO_NUM0, .remap_table = key_rtc_io_num0_msg_table },
|
||||
{ .key_value = KEY_IO_NUM1, .remap_table = key_rtc_io_num1_msg_table },
|
||||
{ .key_value = KEY_IO_NUM2, .remap_table = key_rtc_io_num2_msg_table },
|
||||
{ .key_value = KEY_IO_NUM3, .remap_table = key_rtc_io_num3_msg_table },
|
||||
{ .key_value = KEY_IO_NUM4, .remap_table = key_rtc_io_num4_msg_table },
|
||||
{ .key_value = KEY_IO_NUM5, .remap_table = key_rtc_io_num5_msg_table },
|
||||
{ .key_value = KEY_IO_NUM6, .remap_table = key_rtc_io_num6_msg_table },
|
||||
{ .key_value = KEY_IO_NUM7, .remap_table = key_rtc_io_num7_msg_table },
|
||||
{ .key_value = KEY_IO_NUM8, .remap_table = key_rtc_io_num8_msg_table },
|
||||
{ .key_value = KEY_IO_NUM9, .remap_table = key_rtc_io_num9_msg_table },
|
||||
#endif
|
||||
{ .key_value = 0xff }
|
||||
};
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".update.data.bss")
|
||||
#pragma data_seg(".update.data")
|
||||
#pragma const_seg(".update.text.const")
|
||||
#pragma code_seg(".update.text")
|
||||
#endif
|
||||
#include "system/includes.h"
|
||||
#include "app_action.h"
|
||||
#include "app_main.h"
|
||||
#include "default_event_handler.h"
|
||||
#include "bt.h"
|
||||
#include "app_tone.h"
|
||||
#include "audio_config.h"
|
||||
#include "media/includes.h"
|
||||
#include "mic_effect.h"
|
||||
|
||||
|
||||
#if 1
|
||||
|
||||
static u8 g_resfile_writing = 0;
|
||||
|
||||
struct app_mode *app_enter_update_mode(int arg)
|
||||
{
|
||||
int msg[16];
|
||||
struct app_mode *next_mode;
|
||||
|
||||
r_printf("app_enter_update_mode\n");
|
||||
|
||||
#if TCFG_MIC_EFFECT_ENABLE
|
||||
mic_effect_player_pause(1);
|
||||
#endif
|
||||
jlstream_global_lock();
|
||||
|
||||
|
||||
while (1) {
|
||||
if (!app_get_message(msg, ARRAY_SIZE(msg), NULL)) {
|
||||
continue;
|
||||
}
|
||||
next_mode = app_mode_switch_handler(msg);
|
||||
if (next_mode) {
|
||||
if (g_resfile_writing) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
switch (msg[0]) {
|
||||
case MSG_FROM_APP:
|
||||
break;
|
||||
case MSG_FROM_DEVICE:
|
||||
break;
|
||||
}
|
||||
|
||||
app_default_msg_handler(msg);
|
||||
}
|
||||
|
||||
r_printf("app_exit_update_mode\n");
|
||||
|
||||
jlstream_global_unlock();
|
||||
|
||||
#if TCFG_MIC_EFFECT_ENABLE
|
||||
mic_effect_player_pause(0);
|
||||
#endif
|
||||
|
||||
return next_mode;
|
||||
}
|
||||
|
||||
static int update_mode_try_enter()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int update_mode_try_exit()
|
||||
{
|
||||
if (g_resfile_writing) {
|
||||
return -EBUSY;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct app_mode_ops update_mode_ops = {
|
||||
.try_enter = update_mode_try_enter,
|
||||
.try_exit = update_mode_try_exit,
|
||||
};
|
||||
|
||||
/*
|
||||
* 注册spdif模式
|
||||
*/
|
||||
REGISTER_APP_MODE(update_mode) = {
|
||||
.name = APP_MODE_UPDATE,
|
||||
.index = 0xff,
|
||||
.ops = &update_mode_ops,
|
||||
};
|
||||
|
||||
|
||||
static int app_update_prob_handler(int *msg)
|
||||
{
|
||||
if (msg[0] == APP_MSG_WRITE_RESFILE_START) {
|
||||
g_resfile_writing = 1;
|
||||
struct app_mode *mode = app_get_current_mode();
|
||||
if (mode) {
|
||||
app_push_mode(mode->name);
|
||||
}
|
||||
app_send_message2(APP_MSG_GOTO_MODE, APP_MODE_UPDATE, 0);
|
||||
} else if (msg[0] == APP_MSG_WRITE_RESFILE_STOP) {
|
||||
g_resfile_writing = 0;
|
||||
int name = app_pop_mode();
|
||||
if (name != 0xff) {
|
||||
app_send_message2(APP_MSG_GOTO_MODE, name, 0);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
APP_MSG_PROB_HANDLER(app_update_handler_entry) = {
|
||||
.owner = 0xff,
|
||||
.from = MSG_FROM_APP,
|
||||
.handler = app_update_prob_handler,
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user