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:
@@ -49,13 +49,6 @@ static bool rx_enabled;
|
||||
static uint8_t proto_rx_buf[USB_CDC_PROTO_RX_BUF_SIZE];
|
||||
static size_t proto_rx_len;
|
||||
|
||||
static bool is_usb_owner_snapshot(const struct usb_state_event *event)
|
||||
{
|
||||
return (event->op == USB_STATE_EVENT_OP_SNAPSHOT) &&
|
||||
(event->src_module_id == MODULE_ID(usb_device_module)) &&
|
||||
(event->sink_module_id == NULL);
|
||||
}
|
||||
|
||||
static void reset_ring_buffers(void)
|
||||
{
|
||||
unsigned int key = irq_lock();
|
||||
@@ -315,19 +308,7 @@ static void module_pause(void)
|
||||
|
||||
static bool handle_usb_state_event(const struct usb_state_event *event)
|
||||
{
|
||||
if (!is_usb_owner_snapshot(event)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (running && !usb_function_prepared &&
|
||||
((event->flags & USB_STATEF_PREPARE) != 0U)) {
|
||||
usb_function_prepared = true;
|
||||
submit_usb_state_set(MODULE_ID(MODULE),
|
||||
MODULE_ID(usb_device_module),
|
||||
USB_STATEF_CDC_READY);
|
||||
}
|
||||
|
||||
bool new_usb_active = (event->flags & USB_STATEF_ACTIVE) != 0U;
|
||||
bool new_usb_active = (event->state == USB_STATE_ACTIVE);
|
||||
|
||||
if (new_usb_active == usb_active) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user