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,29 @@
#include "cdc_proto_tx_event.h"
static void log_cdc_proto_tx_event(const struct app_event_header *aeh)
{
const struct cdc_proto_tx_event *event = cast_cdc_proto_tx_event(aeh);
APP_EVENT_MANAGER_LOG(aeh, "type:0x%02x len:%zu",
event->type, event->dyndata.size);
}
static void profile_cdc_proto_tx_event(struct log_event_buf *buf,
const struct app_event_header *aeh)
{
const struct cdc_proto_tx_event *event = cast_cdc_proto_tx_event(aeh);
nrf_profiler_log_encode_uint8(buf, event->type);
nrf_profiler_log_encode_uint8(buf, (uint8_t)event->dyndata.size);
}
APP_EVENT_INFO_DEFINE(cdc_proto_tx_event,
ENCODE(NRF_PROFILER_ARG_U8, NRF_PROFILER_ARG_U8),
ENCODE("type", "len"),
profile_cdc_proto_tx_event);
APP_EVENT_TYPE_DEFINE(cdc_proto_tx_event,
log_cdc_proto_tx_event,
&cdc_proto_tx_event_info,
APP_EVENT_FLAGS_CREATE(
APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE));

View File

@@ -0,0 +1,24 @@
#include "function_bitmap_update_event.h"
static void log_function_bitmap_update_event(const struct app_event_header *aeh)
{
APP_EVENT_MANAGER_LOG(aeh, "bitmap updated");
}
static void profile_function_bitmap_update_event(struct log_event_buf *buf,
const struct app_event_header *aeh)
{
ARG_UNUSED(buf);
ARG_UNUSED(aeh);
}
APP_EVENT_INFO_DEFINE(function_bitmap_update_event,
ENCODE(),
ENCODE(),
profile_function_bitmap_update_event);
APP_EVENT_TYPE_DEFINE(function_bitmap_update_event,
log_function_bitmap_update_event,
&function_bitmap_update_event_info,
APP_EVENT_FLAGS_CREATE(
APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE));

View File

@@ -0,0 +1,43 @@
#include "key_function_event.h"
static const char *action_name(uint8_t action)
{
switch (action) {
case KEY_FUNCTION_ACTION_RELEASE:
return "release";
case KEY_FUNCTION_ACTION_PRESS:
return "press";
default:
return "unknown";
}
}
static void log_key_function_event(const struct app_event_header *aeh)
{
const struct key_function_event *event = cast_key_function_event(aeh);
APP_EVENT_MANAGER_LOG(aeh, "usage:0x%04x action:%s",
event->usage, action_name(event->action));
}
static void profile_key_function_event(struct log_event_buf *buf,
const struct app_event_header *aeh)
{
const struct key_function_event *event = cast_key_function_event(aeh);
nrf_profiler_log_encode_uint16(buf, event->usage);
nrf_profiler_log_encode_uint8(buf, event->action);
}
APP_EVENT_INFO_DEFINE(key_function_event,
ENCODE(NRF_PROFILER_ARG_U16, NRF_PROFILER_ARG_U8),
ENCODE("usage", "action"),
profile_key_function_event);
APP_EVENT_TYPE_DEFINE(key_function_event,
log_key_function_event,
&key_function_event_info,
APP_EVENT_FLAGS_CREATE(
APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE));