feat(usb): 添加USB HID模块支持键盘和消费设备

- 添加USB HID模块实现键盘和消费控制设备功能
- 在CMakeLists.txt中添加usb_hid_module.c和相关事件文件
- 添加HID LED事件和设置协议事件定义及实现
- 配置设备树添加HID键盘和消费者设备节点
- 启用USB设备堆栈配置选项
- 修改键盘核心模块以处理协议切换事件
- 修复键映射中keypad enter的位置错误
- 注释掉电池模块中的调试日志输出
This commit is contained in:
2026-04-10 09:06:18 +08:00
parent 0da731e59d
commit b9bb326e8b
10 changed files with 818 additions and 3 deletions

View File

@@ -17,6 +17,7 @@
#include "keyboard_core.h"
#include "keyboard_hid_report_event.h"
#include "mode_switch_event.h"
#include "set_protocol_event.h"
LOG_MODULE_REGISTER(MODULE, LOG_LEVEL_INF);
@@ -66,7 +67,7 @@ static const struct keymap_entry keymap[] = {
{ KEY_ID(2, 2), KEY_USAGE_TYPE_KEYBOARD, 0x0061 }, /* keypad 9 */
{ KEY_ID(2, 3), KEY_USAGE_TYPE_KEYBOARD, 0x005E }, /* keypad 6 */
{ KEY_ID(2, 4), KEY_USAGE_TYPE_KEYBOARD, 0x005B }, /* keypad 3 */
{ KEY_ID(2, 5), KEY_USAGE_TYPE_KEYBOARD, 0x0058 }, /* keypad enter */
{ KEY_ID(3, 5), KEY_USAGE_TYPE_KEYBOARD, 0x0058 }, /* keypad enter */
{ KEY_ID(3, 0), KEY_USAGE_TYPE_CONSUMER, KEYBOARD_CONSUMER_CTRL_MUTE },
{ KEY_ID(3, 1), KEY_USAGE_TYPE_KEYBOARD, 0x0056 }, /* keypad - */
{ KEY_ID(3, 3), KEY_USAGE_TYPE_KEYBOARD, 0x0057 }, /* keypad + */
@@ -421,6 +422,20 @@ static bool app_event_handler(const struct app_event_header *aeh)
return handle_button_event(cast_button_event(aeh));
}
if (is_set_protocol_event(aeh)) {
const struct set_protocol_event *event = cast_set_protocol_event(aeh);
if (protocol_mode != event->protocol_mode) {
protocol_mode = event->protocol_mode;
if (running && mode_valid && (current_mode == MODE_SWITCH_USB)) {
emit_keys_report(true);
}
}
return false;
}
if (is_mode_switch_event(aeh)) {
return handle_mode_switch_event(cast_mode_switch_event(aeh));
}
@@ -481,6 +496,7 @@ static bool app_event_handler(const struct app_event_header *aeh)
APP_EVENT_LISTENER(MODULE, app_event_handler);
APP_EVENT_SUBSCRIBE(MODULE, button_event);
APP_EVENT_SUBSCRIBE(MODULE, set_protocol_event);
APP_EVENT_SUBSCRIBE(MODULE, mode_switch_event);
APP_EVENT_SUBSCRIBE(MODULE, module_state_event);
APP_EVENT_SUBSCRIBE_EARLY(MODULE, power_down_event);