feat(protocol): 添加键盘协议功能支持

添加了完整的键盘协议功能,包括:
- 新增多个事件类型:cdc_proto_tx_event、function_bitmap_update_event、key_function_event
- 在CMakeLists.txt中注册新的事件源文件
- 扩展keyboard_core.h定义键盘协议相关宏
- 增强protocol_module.h定义协议消息类型常量
- 更新protobuf定义device_comm.proto添加Bitmap、FunctionKeyEvent、Ack、Error消息
- 实现CDC协议包装器模块处理协议消息传输
- 改进键盘核心模块实现按键功能映射和位图管理
- 添加协议模块处理Hello、Bitmap、FunctionKeyEvent等协议消息
- 实现USB设备状态管理和错误响应机制
This commit is contained in:
2026-04-13 11:55:59 +08:00
parent d86f0d6b78
commit 30bc314698
14 changed files with 690 additions and 46 deletions

View File

@@ -0,0 +1,23 @@
#ifndef BLINKY_CDC_PROTO_TX_EVENT_H_
#define BLINKY_CDC_PROTO_TX_EVENT_H_
#include <app_event_manager.h>
#include <app_event_manager_profiler_tracer.h>
#ifdef __cplusplus
extern "C" {
#endif
struct cdc_proto_tx_event {
struct app_event_header header;
uint8_t type;
struct event_dyndata dyndata;
};
APP_EVENT_TYPE_DYNDATA_DECLARE(cdc_proto_tx_event);
#ifdef __cplusplus
}
#endif
#endif /* BLINKY_CDC_PROTO_TX_EVENT_H_ */

View File

@@ -0,0 +1,24 @@
#ifndef BLINKY_FUNCTION_BITMAP_UPDATE_EVENT_H_
#define BLINKY_FUNCTION_BITMAP_UPDATE_EVENT_H_
#include <app_event_manager.h>
#include <app_event_manager_profiler_tracer.h>
#include "keyboard_core.h"
#ifdef __cplusplus
extern "C" {
#endif
struct function_bitmap_update_event {
struct app_event_header header;
uint8_t bitmap[KEYBOARD_PROTOCOL_BITMAP_BYTES];
};
APP_EVENT_TYPE_DECLARE(function_bitmap_update_event);
#ifdef __cplusplus
}
#endif
#endif /* BLINKY_FUNCTION_BITMAP_UPDATE_EVENT_H_ */

View File

@@ -0,0 +1,28 @@
#ifndef BLINKY_KEY_FUNCTION_EVENT_H_
#define BLINKY_KEY_FUNCTION_EVENT_H_
#include <app_event_manager.h>
#include <app_event_manager_profiler_tracer.h>
#ifdef __cplusplus
extern "C" {
#endif
enum key_function_action {
KEY_FUNCTION_ACTION_RELEASE = 0U,
KEY_FUNCTION_ACTION_PRESS = 1U,
};
struct key_function_event {
struct app_event_header header;
uint16_t usage;
uint8_t action;
};
APP_EVENT_TYPE_DECLARE(key_function_event);
#ifdef __cplusplus
}
#endif
#endif /* BLINKY_KEY_FUNCTION_EVENT_H_ */

View File

@@ -8,6 +8,8 @@ extern "C" {
#endif
#define KEYBOARD_BOOT_REPORT_SIZE 8U
#define KEYBOARD_PROTOCOL_USAGE_MAX 0xE7U
#define KEYBOARD_PROTOCOL_BITMAP_BYTES ((KEYBOARD_PROTOCOL_USAGE_MAX + 8U) / 8U)
#define KEYBOARD_NKRO_USAGE_MAX 0xDFU
#define KEYBOARD_NKRO_BITMAP_BYTES ((KEYBOARD_NKRO_USAGE_MAX + 8U) / 8U)
#define KEYBOARD_NKRO_REPORT_SIZE (1U + KEYBOARD_NKRO_BITMAP_BYTES)

View File

@@ -10,6 +10,10 @@ extern "C" {
#define CDC_PROTO_TYPE_HELLO_REQ 0x01U
#define CDC_PROTO_TYPE_HELLO_RSP 0x02U
#define CDC_PROTO_TYPE_BITMAP 0x10U
#define CDC_PROTO_TYPE_FUNCTION_KEY_EVENT 0x20U
#define CDC_PROTO_TYPE_ACK 0x7EU
#define CDC_PROTO_TYPE_ERROR 0x7FU
int protocol_module_process_cdc_packet(uint8_t req_type,
const uint8_t *req_payload,