feat(hid): 实现HID通道状态管理和多通道支持

- 将原来的HID传输状态事件替换为新的HID通道状态事件,支持USB键盘、USB消费者和BLE共享通道
- 添加usb_hid_consumer_module.c模块来处理USB消费者HID报告
- 添加usb_hid_keyboard_module.c模块来处理USB键盘HID报告
- 修改CMakeLists.txt以包含新的HID模块源文件
- 更新事件系统中的transport字段为channel字段,并相应修改所有相关处理逻辑
- 在hid_flowctrl_module.c中实现多通道并发处理机制
- 删除过时的hid_transport_state_event相关代码
- 添加新的hid_channel_state_event用于报告各通道就绪状态
This commit is contained in:
2026-04-15 15:47:14 +08:00
parent 6125f04102
commit bd57b00080
16 changed files with 979 additions and 882 deletions

View File

@@ -0,0 +1,51 @@
#include "hid_channel_state_event.h"
static const char *channel_name(enum hid_send_channel channel)
{
switch (channel) {
case HID_SEND_CH_USB_KEYS:
return "usb_keys";
case HID_SEND_CH_USB_CONSUMER:
return "usb_consumer";
case HID_SEND_CH_BLE_SHARED:
return "ble_shared";
default:
return "?";
}
}
static void log_hid_channel_state_event(const struct app_event_header *aeh)
{
const struct hid_channel_state_event *event =
cast_hid_channel_state_event(aeh);
APP_EVENT_MANAGER_LOG(aeh,
"channel:%s ready_bm:0x%02x protocol:%d",
channel_name(event->channel),
event->report_ready_bm,
event->protocol_mode);
}
static void profile_hid_channel_state_event(struct log_event_buf *buf,
const struct app_event_header *aeh)
{
const struct hid_channel_state_event *event =
cast_hid_channel_state_event(aeh);
nrf_profiler_log_encode_uint8(buf, event->channel);
nrf_profiler_log_encode_uint8(buf, event->report_ready_bm);
nrf_profiler_log_encode_uint8(buf, event->protocol_mode);
}
APP_EVENT_INFO_DEFINE(hid_channel_state_event,
ENCODE(NRF_PROFILER_ARG_U8,
NRF_PROFILER_ARG_U8,
NRF_PROFILER_ARG_U8),
ENCODE("channel", "ready_bm", "protocol_mode"),
profile_hid_channel_state_event);
APP_EVENT_TYPE_DEFINE(hid_channel_state_event,
log_hid_channel_state_event,
&hid_channel_state_event_info,
APP_EVENT_FLAGS_CREATE(
APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE));

View File

@@ -1,12 +1,14 @@
#include "hid_report_sent_event.h"
static const char *transport_name(enum hid_transport transport)
static const char *channel_name(enum hid_send_channel channel)
{
switch (transport) {
case HID_TRANSPORT_USB:
return "USB";
case HID_TRANSPORT_BLE:
return "BLE";
switch (channel) {
case HID_SEND_CH_USB_KEYS:
return "usb_keys";
case HID_SEND_CH_USB_CONSUMER:
return "usb_consumer";
case HID_SEND_CH_BLE_SHARED:
return "ble_shared";
default:
return "?";
}
@@ -28,8 +30,8 @@ static void log_hid_report_sent_event(const struct app_event_header *aeh)
{
const struct hid_report_sent_event *event = cast_hid_report_sent_event(aeh);
APP_EVENT_MANAGER_LOG(aeh, "transport:%s type:%s seq:%u error:%u",
transport_name(event->transport),
APP_EVENT_MANAGER_LOG(aeh, "channel:%s type:%s seq:%u error:%u",
channel_name(event->channel),
report_type_name(event->report_type),
event->sequence,
event->error);
@@ -40,7 +42,7 @@ static void profile_hid_report_sent_event(struct log_event_buf *buf,
{
const struct hid_report_sent_event *event = cast_hid_report_sent_event(aeh);
nrf_profiler_log_encode_uint8(buf, event->transport);
nrf_profiler_log_encode_uint8(buf, event->channel);
nrf_profiler_log_encode_uint8(buf, event->report_type);
nrf_profiler_log_encode_uint16(buf, event->sequence);
nrf_profiler_log_encode_uint8(buf, event->error);
@@ -51,7 +53,7 @@ APP_EVENT_INFO_DEFINE(hid_report_sent_event,
NRF_PROFILER_ARG_U8,
NRF_PROFILER_ARG_U16,
NRF_PROFILER_ARG_U8),
ENCODE("transport", "report_type", "sequence", "error"),
ENCODE("channel", "report_type", "sequence", "error"),
profile_hid_report_sent_event);
APP_EVENT_TYPE_DEFINE(hid_report_sent_event,

View File

@@ -1,68 +0,0 @@
#include "hid_transport_state_event.h"
static const char *transport_name(enum hid_transport transport)
{
switch (transport) {
case HID_TRANSPORT_USB:
return "USB";
case HID_TRANSPORT_BLE:
return "BLE";
default:
return "?";
}
}
static const char *protocol_mode_name(enum keyboard_protocol_mode protocol_mode)
{
switch (protocol_mode) {
case KEYBOARD_PROTOCOL_MODE_BOOT:
return "boot";
case KEYBOARD_PROTOCOL_MODE_REPORT:
return "report";
default:
return "?";
}
}
static void log_hid_transport_state_event(const struct app_event_header *aeh)
{
const struct hid_transport_state_event *event =
cast_hid_transport_state_event(aeh);
APP_EVENT_MANAGER_LOG(aeh,
"transport:%s ready:%u keys_ready:%u consumer_ready:%u protocol:%s",
transport_name(event->transport),
event->ready,
event->keys_ready,
event->consumer_ready,
protocol_mode_name(event->protocol_mode));
}
static void profile_hid_transport_state_event(struct log_event_buf *buf,
const struct app_event_header *aeh)
{
const struct hid_transport_state_event *event =
cast_hid_transport_state_event(aeh);
nrf_profiler_log_encode_uint8(buf, event->transport);
nrf_profiler_log_encode_uint8(buf, event->ready);
nrf_profiler_log_encode_uint8(buf, event->keys_ready);
nrf_profiler_log_encode_uint8(buf, event->consumer_ready);
nrf_profiler_log_encode_uint8(buf, event->protocol_mode);
}
APP_EVENT_INFO_DEFINE(hid_transport_state_event,
ENCODE(NRF_PROFILER_ARG_U8,
NRF_PROFILER_ARG_U8,
NRF_PROFILER_ARG_U8,
NRF_PROFILER_ARG_U8,
NRF_PROFILER_ARG_U8),
ENCODE("transport", "ready", "keys_ready", "consumer_ready",
"protocol_mode"),
profile_hid_transport_state_event);
APP_EVENT_TYPE_DEFINE(hid_transport_state_event,
log_hid_transport_state_event,
&hid_transport_state_event_info,
APP_EVENT_FLAGS_CREATE(
APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE));

View File

@@ -4,13 +4,15 @@
#define HID_TX_REPORT_EVENT_LOG_BUF_LEN 192
static const char *transport_name(enum hid_transport transport)
static const char *channel_name(enum hid_send_channel channel)
{
switch (transport) {
case HID_TRANSPORT_USB:
return "USB";
case HID_TRANSPORT_BLE:
return "BLE";
switch (channel) {
case HID_SEND_CH_USB_KEYS:
return "usb_keys";
case HID_SEND_CH_USB_CONSUMER:
return "usb_consumer";
case HID_SEND_CH_BLE_SHARED:
return "ble_shared";
default:
return "?";
}
@@ -47,8 +49,8 @@ static void log_hid_tx_report_event(const struct app_event_header *aeh)
int pos;
pos = snprintf(log_buf, sizeof(log_buf),
"transport:%s type:%s protocol:%s seq:%u len:%zu",
transport_name(event->transport),
"channel:%s type:%s protocol:%s seq:%u len:%zu",
channel_name(event->channel),
report_type_name(event->report_type),
protocol_mode_name(event->protocol_mode),
event->sequence,
@@ -84,7 +86,7 @@ static void profile_hid_tx_report_event(struct log_event_buf *buf,
{
const struct hid_tx_report_event *event = cast_hid_tx_report_event(aeh);
nrf_profiler_log_encode_uint8(buf, event->transport);
nrf_profiler_log_encode_uint8(buf, event->channel);
nrf_profiler_log_encode_uint8(buf, event->report_type);
nrf_profiler_log_encode_uint8(buf, event->protocol_mode);
nrf_profiler_log_encode_uint16(buf, event->sequence);
@@ -97,7 +99,7 @@ APP_EVENT_INFO_DEFINE(hid_tx_report_event,
NRF_PROFILER_ARG_U8,
NRF_PROFILER_ARG_U16,
NRF_PROFILER_ARG_U8),
ENCODE("transport", "report_type", "protocol_mode", "sequence", "len"),
ENCODE("channel", "report_type", "protocol_mode", "sequence", "len"),
profile_hid_tx_report_event);
APP_EVENT_TYPE_DEFINE(hid_tx_report_event,