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:
2026-04-15 09:30:40 +08:00
parent 78a6dc212d
commit c4b205b8a1
13 changed files with 301 additions and 306 deletions

View File

@@ -0,0 +1,54 @@
#include <caf/events/module_state_event.h>
#include "usb_state_event.h"
static const char *usb_state_event_op_name(uint8_t op)
{
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";
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);
}
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->op);
nrf_profiler_log_encode_uint32(buf, event->flags);
}
APP_EVENT_INFO_DEFINE(usb_state_event,
ENCODE(NRF_PROFILER_ARG_U8, NRF_PROFILER_ARG_U32),
ENCODE("op", "flags"),
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));