feat(usb): 引入统一的USB状态事件系统
重构USB事件管理,将原有的多个专用事件(usb_device_state_event、 usb_function_ready_event、usb_prepare_event)合并为统一的 usb_state_event。新的事件系统采用位标志方式管理USB状态, 提供更灵活的状态跟踪机制。 BREAKING CHANGE: 移除了旧的USB相关事件类型,需要更新依赖这些 事件的模块代码。
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
#include "hid_led_event.h"
|
||||
#include "key_function_event.h"
|
||||
#include "protocol_module.h"
|
||||
#include "usb_device_state_event.h"
|
||||
#include "usb_state_event.h"
|
||||
|
||||
LOG_MODULE_REGISTER(MODULE, LOG_LEVEL_INF);
|
||||
|
||||
@@ -430,9 +430,14 @@ static bool handle_hid_led_event(const struct hid_led_event *event)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool handle_usb_device_state_event(const struct usb_device_state_event *event)
|
||||
static bool handle_usb_state_event(const struct usb_state_event *event)
|
||||
{
|
||||
usb_active = (event->state == USB_DEVICE_STATE_ACTIVE);
|
||||
if ((event->op != USB_STATE_EVENT_OP_SNAPSHOT) ||
|
||||
(event->src_module_id != MODULE_ID(usb_device_module))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
usb_active = (event->flags & USB_STATEF_ACTIVE) != 0U;
|
||||
if (!usb_active) {
|
||||
hello_done = false;
|
||||
}
|
||||
@@ -450,8 +455,8 @@ static bool app_event_handler(const struct app_event_header *aeh)
|
||||
return handle_hid_led_event(cast_hid_led_event(aeh));
|
||||
}
|
||||
|
||||
if (is_usb_device_state_event(aeh)) {
|
||||
return handle_usb_device_state_event(cast_usb_device_state_event(aeh));
|
||||
if (is_usb_state_event(aeh)) {
|
||||
return handle_usb_state_event(cast_usb_state_event(aeh));
|
||||
}
|
||||
|
||||
if (is_module_state_event(aeh)) {
|
||||
@@ -517,6 +522,6 @@ APP_EVENT_LISTENER(MODULE, app_event_handler);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, hid_led_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, key_function_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, module_state_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, usb_device_state_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, usb_state_event);
|
||||
APP_EVENT_SUBSCRIBE_EARLY(MODULE, power_down_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, wake_up_event);
|
||||
|
||||
Reference in New Issue
Block a user