Files
blinky/src/events/usb_state_event.c
skiinder 6125f04102 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
2026-04-15 15:13:44 +08:00

48 lines
1.1 KiB
C

#include <caf/events/module_state_event.h>
#include "usb_state_event.h"
static const char *usb_state_name(enum usb_state state)
{
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 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, "state:%s", usb_state_name(event->state));
}
static void profile_usb_state_event(struct log_event_buf *buf,
const struct app_event_header *aeh)
{
const struct usb_state_event *event = cast_usb_state_event(aeh);
nrf_profiler_log_encode_uint8(buf, event->state);
}
APP_EVENT_INFO_DEFINE(usb_state_event,
ENCODE(NRF_PROFILER_ARG_U8),
ENCODE("state"),
profile_usb_state_event);
APP_EVENT_TYPE_DEFINE(usb_state_event,
log_usb_state_event,
&usb_state_event_info,
APP_EVENT_FLAGS_CREATE(
APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE));