feat(keyboard): 添加完整的HID键盘功能模块

- 新增keyboard_module.c实现完整的键盘HID功能,包括按键映射、
  协议处理和报告生成
- 添加hid_protocol_event和hid_report_event事件系统支持
- 实现键盘和consumer类型的HID报告处理
- 支持Boot协议和Report协议两种模式
- 添加hid_keymap_def.h定义键盘映射表

refactor(ble_hid): 重构HIDS模块为BLE HID模块

- 将hids_module.c重命名为ble_hid_module.c
- 集成新的hid_protocol_event和hid_report_event事件处理
- 改进协议切换逻辑,添加协议事件发布功能
- 优化BLE HID报告发送机制

refactor(CMakeLists): 更新构建配置

- 添加新的事件模块源文件到构建列表
- 添加keyboard_module.c替换原有的button_map_module.c
- 添加ble_hid_module.c替换原有的hids_module.c
- 配置HID密钥映射定义路径编译选项

refactor(events): 简化USB HID事件结构

- 移除USB HID事件中的冗余状态字段
- 更新事件日志和分析器字段定义

docs(hid): 添加HID报告描述符文档

- 定义REPORT_ID_KEYBOARD和REPORT_ID_CONSUMER枚举值
- 整理HID报告相关的常量定义
This commit is contained in:
2026-03-14 18:00:14 +08:00
parent a3196ef162
commit cd8101428d
13 changed files with 833 additions and 148 deletions

View File

@@ -10,27 +10,17 @@ static const char *const usb_hid_usbd_state_name[] = {
[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",
APP_EVENT_MANAGER_LOG(aeh, "type=%s en=%u usbd=%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]);
usb_hid_usbd_state_name[event->usbd_state]);
}
static void profile_usb_hid_event(struct log_event_buf *buf,
@@ -41,15 +31,13 @@ static void profile_usb_hid_event(struct log_event_buf *buf,
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"),
ENCODE("evt_type", "enable", "usbd"),
profile_usb_hid_event);
APP_EVENT_TYPE_DEFINE(usb_hid_event,