初版
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".app_msg.data.bss")
|
||||
#pragma data_seg(".app_msg.data")
|
||||
#pragma const_seg(".app_msg.text.const")
|
||||
#pragma code_seg(".app_msg.text")
|
||||
#endif
|
||||
#include "app_msg.h"
|
||||
#include "key_driver.h"
|
||||
|
||||
#define LOG_TAG "[APP]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
#define LOG_CLI_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
|
||||
|
||||
int app_send_message(int _msg, int arg)
|
||||
{
|
||||
int msg[2];
|
||||
msg[0] = _msg;
|
||||
msg[1] = arg;
|
||||
int ret = os_taskq_post_type("app_core", MSG_FROM_APP, 2, msg);
|
||||
if (ret) {
|
||||
log_error("%s send err %x\n", __FUNCTION__, ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int app_send_message2(int _msg, int arg1, int arg2)
|
||||
{
|
||||
int msg[3];
|
||||
msg[0] = _msg;
|
||||
msg[1] = arg1;
|
||||
msg[2] = arg2;
|
||||
int ret = os_taskq_post_type("app_core", MSG_FROM_APP, 3, msg);
|
||||
if (ret) {
|
||||
log_error("%s send err %x\n", __FUNCTION__, ret);
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
int app_send_message_from(int from, int argc, int *msg)
|
||||
{
|
||||
int ret = os_taskq_post_type("app_core", from, (argc + 3) / 4, msg);
|
||||
if (ret) {
|
||||
log_error("%s send err %x\n", __FUNCTION__, ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int app_key_event_remap(const struct key_remap_table *table, int *_event)
|
||||
{
|
||||
struct key_event *key = (struct key_event *)_event;
|
||||
|
||||
for (int i = 0; table[i].key_value != 0xff; i++) {
|
||||
if (table[i].key_value == key->value) {
|
||||
if (table[i].remap_table) {
|
||||
return table[i].remap_table[key->event];
|
||||
}
|
||||
if (table[i].remap_func) {
|
||||
return table[i].remap_func((int *)key);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".audio_player.data.bss")
|
||||
#pragma data_seg(".audio_player.data")
|
||||
#pragma const_seg(".audio_player.text.const")
|
||||
#pragma code_seg(".audio_player.text")
|
||||
#endif
|
||||
#include "app_msg.h"
|
||||
#include "audio_manager.h"
|
||||
|
||||
void tone_event_to_user(int event, u16 fname_uuid)
|
||||
{
|
||||
int msg[2];
|
||||
|
||||
msg[0] = event;
|
||||
msg[1] = fname_uuid;
|
||||
os_taskq_post_type("app_core", MSG_FROM_TONE, 2, msg);
|
||||
}
|
||||
|
||||
void tone_event_clear()
|
||||
{
|
||||
os_taskq_del_type("app_core", MSG_FROM_TONE);
|
||||
}
|
||||
|
||||
void update_tone_event_clear()
|
||||
{
|
||||
tone_event_clear();
|
||||
}
|
||||
|
||||
void audio_event_send_msg(int event, int arg)
|
||||
{
|
||||
int msg[2];
|
||||
|
||||
msg[0] = event;
|
||||
msg[1] = arg;
|
||||
os_taskq_post_type("app_core", MSG_FROM_AUDIO, 2, msg);
|
||||
}
|
||||
|
||||
void audio_event_to_user(int event)
|
||||
{
|
||||
audio_event_send_msg(event, 0);
|
||||
}
|
||||
|
||||
void audio_anc_event_to_user(int mode)
|
||||
{
|
||||
/*if (mode == ANC_ON) {
|
||||
audio_event_send_msg(AUDIO_EVENT_ANC_ON, 0);
|
||||
} else if (mode == ANC_TRANSPARENCY) {
|
||||
audio_event_send_msg(AUDIO_EVENT_ANC_TRANS, 0);
|
||||
} else {
|
||||
audio_event_send_msg(AUDIO_EVENT_ANC_OFF, 0);
|
||||
}*/
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".battery.data.bss")
|
||||
#pragma data_seg(".battery.data")
|
||||
#pragma const_seg(".battery.text.const")
|
||||
#pragma code_seg(".battery.text")
|
||||
#endif
|
||||
#include "battery_manager.h"
|
||||
#include "app_msg.h"
|
||||
|
||||
|
||||
void batmgr_send_msg(enum battery_msg _msg, int arg)
|
||||
{
|
||||
int msg[2];
|
||||
|
||||
msg[0] = _msg;
|
||||
msg[1] = arg;
|
||||
int ret = os_taskq_post_type("app_core", MSG_FROM_BATTERY, 2, msg);
|
||||
if (ret) {
|
||||
printf("%s send err %x\n", __FUNCTION__, ret);
|
||||
}
|
||||
}
|
||||
|
||||
void charge_event_to_user(u8 event)
|
||||
{
|
||||
batmgr_send_msg(event, 0);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".btstack.data.bss")
|
||||
#pragma data_seg(".btstack.data")
|
||||
#pragma const_seg(".btstack.text.const")
|
||||
#pragma code_seg(".btstack.text")
|
||||
#endif
|
||||
#include "app_msg.h"
|
||||
#include "classic/tws_api.h"
|
||||
#include "app_config.h"
|
||||
|
||||
#define SYS_BT_EVENT_TYPE_CON_STATUS (('C' << 24) | ('O' << 16) | ('N' << 8) | '\0')
|
||||
#define SYS_BT_EVENT_TYPE_HCI_STATUS (('H' << 24) | ('C' << 16) | ('I' << 8) | '\0')
|
||||
struct _bt_event {
|
||||
u8 event;
|
||||
u8 args[7];
|
||||
u32 value;
|
||||
};
|
||||
|
||||
static void bt_stack_event_update_to_user(u8 *addr, u32 type, u8 event, u32 value)
|
||||
{
|
||||
int msg[4] = {0};
|
||||
struct _bt_event *evt = (struct _bt_event *)msg;
|
||||
|
||||
evt->event = event;
|
||||
if (addr) {
|
||||
memcpy(evt->args, addr, 6);
|
||||
}
|
||||
evt->value = value;
|
||||
|
||||
int from = type == SYS_BT_EVENT_TYPE_CON_STATUS ? MSG_FROM_BT_STACK : MSG_FROM_BT_HCI;
|
||||
os_taskq_post_type("app_core", from, sizeof(*evt) / 4, msg);
|
||||
|
||||
/* 防止短时间内太多事件,app_core处理不过来导致qfull */
|
||||
os_time_dly(1);
|
||||
}
|
||||
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
static void bt_event_rx_handler_in_irq(void *data, u16 len, bool rx)
|
||||
{
|
||||
struct _bt_event *evt = (struct _bt_event *)data;
|
||||
|
||||
if (rx) {
|
||||
int from = evt->args[6] == 0 ? MSG_FROM_BT_STACK : MSG_FROM_BT_HCI;
|
||||
os_taskq_post_type("app_core", from, sizeof(*evt) / 4, data);
|
||||
}
|
||||
}
|
||||
REGISTER_TWS_FUNC_STUB(bt_event_sync_stub) = {
|
||||
.func_id = 0xC9073872,
|
||||
.func = bt_event_rx_handler_in_irq,
|
||||
};
|
||||
#endif
|
||||
|
||||
//从机APP大部分情况不再处理协议栈更新的消息
|
||||
void bt_event_update_to_user(u8 *addr, u32 type, u8 event, u32 value)
|
||||
{
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
int state = tws_api_get_tws_state();
|
||||
if (state & TWS_STA_SIBLING_CONNECTED) {
|
||||
if (tws_api_get_role_async() == TWS_ROLE_SLAVE) {
|
||||
return;
|
||||
}
|
||||
struct _bt_event evt;
|
||||
|
||||
evt.event = event;
|
||||
evt.value = value;
|
||||
evt.args[6] = type == SYS_BT_EVENT_TYPE_CON_STATUS ? 0 : 1;
|
||||
if (addr) {
|
||||
memcpy(evt.args, addr, 6);
|
||||
}
|
||||
tws_api_send_data_to_sibling(&evt, sizeof(evt), 0xC9073872);
|
||||
}
|
||||
#endif
|
||||
bt_stack_event_update_to_user(addr, type, event, value);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".driver.data.bss")
|
||||
#pragma data_seg(".driver.data")
|
||||
#pragma const_seg(".driver.text.const")
|
||||
#pragma code_seg(".driver.text")
|
||||
#endif
|
||||
#include "app_msg.h"
|
||||
#include "system/event.h"
|
||||
#include "usb/usb_task.h"
|
||||
#include "app_config.h"
|
||||
|
||||
void sdx_dev_event_to_user(u32 arg, u8 sdx_status, u8 sdx_index)
|
||||
{
|
||||
|
||||
int msg[3];
|
||||
|
||||
msg[0] = arg;
|
||||
msg[1] = sdx_status;
|
||||
|
||||
if (arg == (u32)DRIVER_EVENT_FROM_SD0) {
|
||||
msg[2] = (int)"sd0";
|
||||
} else {
|
||||
msg[2] = (int)"sd1";
|
||||
}
|
||||
|
||||
printf("sd dev msg %x, %x, %x\n", msg[0], msg[1], msg[2]);
|
||||
|
||||
/* os_taskq_post_msg("test_gpu_task", 2, 0xa5a5, msg); */
|
||||
/* return ; */
|
||||
|
||||
#if (TCFG_DEV_MANAGER_ENABLE)
|
||||
os_taskq_post_type("dev_mg", MSG_FROM_DEVICE, 3, msg);
|
||||
#else
|
||||
os_taskq_post_type("app_core", MSG_FROM_DEVICE, 3, msg);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void usb_driver_event_to_user(u32 from, u32 event, void *arg)
|
||||
{
|
||||
int msg[3] = {0};
|
||||
|
||||
msg[0] = from;
|
||||
msg[1] = event;
|
||||
msg[2] = (int)arg;
|
||||
#if (TCFG_DEV_MANAGER_ENABLE)
|
||||
os_taskq_post_type("dev_mg", MSG_FROM_DEVICE, 3, msg);
|
||||
#else
|
||||
os_taskq_post_type("app_core", MSG_FROM_DEVICE, 3, msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
void usb_driver_event_from_otg(u32 from, u32 event, void *arg)
|
||||
{
|
||||
os_taskq_post_msg("usb_stack", 4, USBSTACK_OTG_MSG, from, event, arg);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".key.data.bss")
|
||||
#pragma data_seg(".key.data")
|
||||
#pragma const_seg(".key.text.const")
|
||||
#pragma code_seg(".key.text")
|
||||
#endif
|
||||
#include "app_msg.h"
|
||||
#include "key_driver.h"
|
||||
#include "system/timer.h"
|
||||
#include "sdk_config.h"
|
||||
|
||||
struct key_hold {
|
||||
u8 send_3s_msg;
|
||||
u8 send_5s_msg;
|
||||
u32 start_time;
|
||||
};
|
||||
|
||||
static struct key_hold key_hold_hdl[3];
|
||||
|
||||
static struct key_hold *get_key_hold(u8 key_value)
|
||||
{
|
||||
if (key_value < ARRAY_SIZE(key_hold_hdl)) {
|
||||
return &key_hold_hdl[key_value];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 多击按键判断
|
||||
*
|
||||
* @param key:基础按键动作(mono_click、long、hold、up)和键值
|
||||
*
|
||||
* @return 0:不拦截按键事件
|
||||
* 1:拦截按键事件
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
static int multi_clicks_translate(struct key_event *key)
|
||||
{
|
||||
static u8 click_cnt;
|
||||
static u8 notify_value = 0xff;
|
||||
struct key_hold *hold = get_key_hold(key->value);
|
||||
|
||||
if (key->event == KEY_ACTION_LONG) {
|
||||
if (hold) {
|
||||
hold->start_time = jiffies;
|
||||
}
|
||||
} else if (key->event == KEY_ACTION_HOLD) {
|
||||
if (hold) {
|
||||
int time_msec = jiffies_offset_to_msec(hold->start_time, jiffies);
|
||||
if (time_msec >= 3000 && hold->send_3s_msg == 0) {
|
||||
hold->send_3s_msg = 1;
|
||||
key->event = KEY_ACTION_HOLD_3SEC;
|
||||
} else if (time_msec >= 5000 && hold->send_5s_msg) {
|
||||
hold->send_5s_msg = 1;
|
||||
key->event = KEY_ACTION_HOLD_5SEC;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (hold) {
|
||||
hold->send_3s_msg = 0;
|
||||
hold->send_5s_msg = 1;
|
||||
hold->start_time = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (key->event == KEY_ACTION_CLICK) {
|
||||
if (key->value != notify_value) {
|
||||
click_cnt = 1;
|
||||
notify_value = key->value;
|
||||
} else {
|
||||
click_cnt++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (key->event == KEY_ACTION_NO_KEY) {
|
||||
if (click_cnt >= 2) {
|
||||
key->event = KEY_ACTION_DOUBLE_CLICK + (click_cnt - 2);
|
||||
} else {
|
||||
key->event = KEY_ACTION_CLICK;
|
||||
}
|
||||
key->value = notify_value;
|
||||
click_cnt = 0;
|
||||
notify_value = NO_KEY;
|
||||
} else if (key->event > KEY_ACTION_CLICK) {
|
||||
click_cnt = 0;
|
||||
notify_value = NO_KEY;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 联合按键判断
|
||||
*
|
||||
* @param key:基础按键动作(mono_click、long、hold、up)和键值
|
||||
*
|
||||
* @return 0:不拦截按键事件
|
||||
* 1:拦截按键事件
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
static int combination_key_translate(struct key_event *key)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 按键事件过滤、检测和发送
|
||||
*
|
||||
* @param key:基础按键动作(mono_click、long、hold、up)和键值
|
||||
*/
|
||||
/* ----------------------------------------------------------------------------*/
|
||||
void key_event_handler(struct key_event *key)
|
||||
{
|
||||
const struct key_callback *p;
|
||||
|
||||
if (multi_clicks_translate(key)) {
|
||||
return;
|
||||
}
|
||||
if (combination_key_translate(key)) {
|
||||
return;
|
||||
}
|
||||
if (key->event == KEY_ACTION_NO_KEY) {
|
||||
return;
|
||||
}
|
||||
|
||||
//外部需要格外做的处理流程,请通过注册的形式在此处回调
|
||||
list_for_each_key_callback(p) {
|
||||
if (p->cb_deal == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (p->cb_deal(key)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
app_send_message_from(MSG_FROM_KEY, sizeof(*key), (int *)key);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user