feat(usb): 简化USB状态管理并引入模式策略模块

- 修改usb_state_event结构,将复杂的flag操作简化为单一的state枚举值
- 新增usb_function_hook机制用于USB功能预初始化
- 将ble_adv_ctrl_module重命名为mode_policy_module以更好地反映其功能
- 在mode_policy_module中添加USB设备启用/暂停控制逻辑
- 添加对电源事件的处理支持休眠/唤醒功能
- 更新CMakeLists.txt添加必要的链接器脚本和源文件
- 移除不再需要的ble_adv_ctrl_module并添加新的mode_policy_module
This commit is contained in:
2026-04-15 15:13:44 +08:00
parent 0a905d280d
commit 6125f04102
9 changed files with 300 additions and 250 deletions

View File

@@ -2,35 +2,29 @@
#include "usb_state_event.h"
static const char *usb_state_event_op_name(uint8_t op)
static const char *usb_state_name(enum usb_state state)
{
switch ((enum usb_state_event_op)op) {
case USB_STATE_EVENT_OP_SET_BITS:
return "set_bits";
case USB_STATE_EVENT_OP_CLEAR_BITS:
return "clear_bits";
case USB_STATE_EVENT_OP_SNAPSHOT:
return "snapshot";
switch (state) {
case USB_STATE_DISABLED:
return "disabled";
case USB_STATE_DISCONNECTED:
return "disconnected";
case USB_STATE_POWERED:
return "powered";
case USB_STATE_ACTIVE:
return "active";
case USB_STATE_SUSPENDED:
return "suspended";
default:
return "?";
}
}
static const char *module_name_or_any(const void *module_id)
{
return (module_id != NULL) ? module_name_get(module_id) : "*";
}
static void log_usb_state_event(const struct app_event_header *aeh)
{
const struct usb_state_event *event = cast_usb_state_event(aeh);
APP_EVENT_MANAGER_LOG(aeh,
"src:%s sink:%s op:%s flags:0x%08x",
module_name_or_any(event->src_module_id),
module_name_or_any(event->sink_module_id),
usb_state_event_op_name(event->op),
event->flags);
APP_EVENT_MANAGER_LOG(aeh, "state:%s", usb_state_name(event->state));
}
static void profile_usb_state_event(struct log_event_buf *buf,
@@ -38,13 +32,12 @@ static void profile_usb_state_event(struct log_event_buf *buf,
{
const struct usb_state_event *event = cast_usb_state_event(aeh);
nrf_profiler_log_encode_uint8(buf, event->op);
nrf_profiler_log_encode_uint32(buf, event->flags);
nrf_profiler_log_encode_uint8(buf, event->state);
}
APP_EVENT_INFO_DEFINE(usb_state_event,
ENCODE(NRF_PROFILER_ARG_U8, NRF_PROFILER_ARG_U32),
ENCODE("op", "flags"),
ENCODE(NRF_PROFILER_ARG_U8),
ENCODE("state"),
profile_usb_state_event);
APP_EVENT_TYPE_DEFINE(usb_state_event,