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

@@ -1,32 +0,0 @@
#ifndef BLINKY_USB_DEVICE_STATE_EVENT_H_
#define BLINKY_USB_DEVICE_STATE_EVENT_H_
#include <app_event_manager.h>
#include <app_event_manager_profiler_tracer.h>
#include "usb_device_module.h"
#ifdef __cplusplus
extern "C" {
#endif
struct usb_device_state_event {
struct app_event_header header;
enum usb_device_state state;
};
APP_EVENT_TYPE_DECLARE(usb_device_state_event);
static inline void submit_usb_device_state_event(enum usb_device_state state)
{
struct usb_device_state_event *event = new_usb_device_state_event();
event->state = state;
APP_EVENT_SUBMIT(event);
}
#ifdef __cplusplus
}
#endif
#endif /* BLINKY_USB_DEVICE_STATE_EVENT_H_ */

View File

@@ -1,32 +0,0 @@
#ifndef BLINKY_USB_FUNCTION_READY_EVENT_H_
#define BLINKY_USB_FUNCTION_READY_EVENT_H_
#include <app_event_manager.h>
#include <app_event_manager_profiler_tracer.h>
#include "usb_device_module.h"
#ifdef __cplusplus
extern "C" {
#endif
struct usb_function_ready_event {
struct app_event_header header;
uint8_t function_mask;
};
APP_EVENT_TYPE_DECLARE(usb_function_ready_event);
static inline void submit_usb_function_ready_event(uint8_t function_mask)
{
struct usb_function_ready_event *event = new_usb_function_ready_event();
event->function_mask = function_mask;
APP_EVENT_SUBMIT(event);
}
#ifdef __cplusplus
}
#endif
#endif /* BLINKY_USB_FUNCTION_READY_EVENT_H_ */

View File

@@ -1,26 +0,0 @@
#ifndef BLINKY_USB_PREPARE_EVENT_H_
#define BLINKY_USB_PREPARE_EVENT_H_
#include <app_event_manager.h>
#include <app_event_manager_profiler_tracer.h>
#ifdef __cplusplus
extern "C" {
#endif
struct usb_prepare_event {
struct app_event_header header;
};
APP_EVENT_TYPE_DECLARE(usb_prepare_event);
static inline void submit_usb_prepare_event(void)
{
APP_EVENT_SUBMIT(new_usb_prepare_event());
}
#ifdef __cplusplus
}
#endif
#endif /* BLINKY_USB_PREPARE_EVENT_H_ */

View File

@@ -0,0 +1,82 @@
#ifndef BLINKY_USB_STATE_EVENT_H_
#define BLINKY_USB_STATE_EVENT_H_
#include <stdint.h>
#include <app_event_manager.h>
#include <app_event_manager_profiler_tracer.h>
#include <zephyr/sys/util.h>
#ifdef __cplusplus
extern "C" {
#endif
enum usb_state_event_op {
USB_STATE_EVENT_OP_SET_BITS,
USB_STATE_EVENT_OP_CLEAR_BITS,
USB_STATE_EVENT_OP_SNAPSHOT,
};
enum usb_state_flag {
USB_STATEF_PREPARE = BIT(0),
USB_STATEF_HID_READY = BIT(1),
USB_STATEF_CDC_READY = BIT(2),
USB_STATEF_STACK_READY = BIT(3),
USB_STATEF_POWERED = BIT(4),
USB_STATEF_ACTIVE = BIT(5),
USB_STATEF_SUSPENDED = BIT(6),
USB_STATEF_STACK_RUNNING = BIT(31),
};
struct usb_state_event {
struct app_event_header header;
const void *src_module_id;
const void *sink_module_id;
uint8_t op;
uint32_t flags;
};
APP_EVENT_TYPE_DECLARE(usb_state_event);
static inline void submit_usb_state_event(const void *src_module_id,
const void *sink_module_id,
uint8_t op,
uint32_t flags)
{
struct usb_state_event *event = new_usb_state_event();
event->src_module_id = src_module_id;
event->sink_module_id = sink_module_id;
event->op = op;
event->flags = flags;
APP_EVENT_SUBMIT(event);
}
static inline void submit_usb_state_set(const void *src_module_id,
const void *sink_module_id,
uint32_t flags)
{
submit_usb_state_event(src_module_id, sink_module_id,
USB_STATE_EVENT_OP_SET_BITS, flags);
}
static inline void submit_usb_state_clear(const void *src_module_id,
const void *sink_module_id,
uint32_t flags)
{
submit_usb_state_event(src_module_id, sink_module_id,
USB_STATE_EVENT_OP_CLEAR_BITS, flags);
}
static inline void submit_usb_state_snapshot(const void *src_module_id,
uint32_t flags)
{
submit_usb_state_event(src_module_id, NULL,
USB_STATE_EVENT_OP_SNAPSHOT, flags);
}
#ifdef __cplusplus
}
#endif
#endif /* BLINKY_USB_STATE_EVENT_H_ */