feat: 添加USB HID模块支持

- 添加usb_hid_event事件定义和实现,用于管理USB HID状态
- 添加usb_hid_module模块,实现USB HID协议栈的完整生命周期管理
- 在CMakeLists.txt中注册新的事件和模块源文件
- 在设备树overlay中配置三个HID设备:HID_BOOT、HID_NKRO、HID_RAW
- 在prj.conf中启用USB设备栈相关配置选项
- 修复电池模块和模式切换模块中的重复挂起问题
- 改进蓝牙绑定模块的错误处理和日志记录
- 在app.overlay中启用usbd节点并添加PMIC配置调整
This commit is contained in:
2026-03-14 12:13:25 +08:00
parent 81846a870f
commit e893ddded6
9 changed files with 765 additions and 14 deletions

View File

@@ -0,0 +1,58 @@
#include "usb_hid_event.h"
static const char *const usb_hid_evt_type_name[] = {
[USB_HID_EVT_STATE_REPORT] = "STATE_REPORT",
};
static const char *const usb_hid_usbd_state_name[] = {
[USB_HID_USBD_DISCONNECTED] = "DISCONNECTED",
[USB_HID_USBD_CONNECTED] = "CONNECTED",
[USB_HID_USBD_SUSPENDED] = "SUSPENDED",
};
static const char *const usb_hid_stack_state_name[] = {
[USB_HID_STACK_OFF] = "OFF",
[USB_HID_STACK_READY] = "READY",
[USB_HID_STACK_ACTIVE] = "ACTIVE",
[USB_HID_STACK_SUSPENDED] = "SUSPENDED",
[USB_HID_STACK_ERROR] = "ERROR",
};
static void log_usb_hid_event(const struct app_event_header *aeh)
{
const struct usb_hid_event *event = cast_usb_hid_event(aeh);
__ASSERT_NO_MSG(event->evt_type < ARRAY_SIZE(usb_hid_evt_type_name));
__ASSERT_NO_MSG(event->usbd_state < ARRAY_SIZE(usb_hid_usbd_state_name));
__ASSERT_NO_MSG(event->hid_state < ARRAY_SIZE(usb_hid_stack_state_name));
APP_EVENT_MANAGER_LOG(aeh, "type=%s en=%u usbd=%s hid=%s",
usb_hid_evt_type_name[event->evt_type],
event->enable,
usb_hid_usbd_state_name[event->usbd_state],
usb_hid_stack_state_name[event->hid_state]);
}
static void profile_usb_hid_event(struct log_event_buf *buf,
const struct app_event_header *aeh)
{
const struct usb_hid_event *event = cast_usb_hid_event(aeh);
nrf_profiler_log_encode_uint8(buf, (uint8_t)event->evt_type);
nrf_profiler_log_encode_uint8(buf, (uint8_t)event->enable);
nrf_profiler_log_encode_uint8(buf, (uint8_t)event->usbd_state);
nrf_profiler_log_encode_uint8(buf, (uint8_t)event->hid_state);
}
APP_EVENT_INFO_DEFINE(usb_hid_event,
ENCODE(NRF_PROFILER_ARG_U8,
NRF_PROFILER_ARG_U8,
NRF_PROFILER_ARG_U8,
NRF_PROFILER_ARG_U8),
ENCODE("evt_type", "enable", "usbd", "hid"),
profile_usb_hid_event);
APP_EVENT_TYPE_DEFINE(usb_hid_event,
log_usb_hid_event,
&usb_hid_event_info,
APP_EVENT_FLAGS_CREATE(APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE));