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

@@ -14,8 +14,8 @@
#include <zephyr/logging/log.h>
#include "hid_led_event.h"
#include "hid_channel_state_event.h"
#include "hid_report_sent_event.h"
#include "hid_transport_state_event.h"
#include "hid_tx_report_event.h"
#include "keyboard_core.h"
#include "set_protocol_event.h"
@@ -101,15 +101,22 @@ static const uint8_t hid_report_desc[] = {
static void submit_ble_transport_state_event(void)
{
bool ready = running && secured && (active_conn != NULL);
uint8_t report_ready_bm = 0U;
submit_hid_transport_state_event(
HID_TRANSPORT_BLE,
ready,
ready && ((protocol_mode == KEYBOARD_PROTOCOL_MODE_BOOT) ?
boot_keyboard_notify_enabled :
keyboard_report_notify_enabled),
ready && (protocol_mode == KEYBOARD_PROTOCOL_MODE_REPORT) &&
consumer_report_notify_enabled,
if (ready && ((protocol_mode == KEYBOARD_PROTOCOL_MODE_BOOT) ?
boot_keyboard_notify_enabled :
keyboard_report_notify_enabled)) {
report_ready_bm |= BIT(KEYBOARD_REPORT_TYPE_KEYS);
}
if (ready && (protocol_mode == KEYBOARD_PROTOCOL_MODE_REPORT) &&
consumer_report_notify_enabled) {
report_ready_bm |= BIT(KEYBOARD_REPORT_TYPE_CONSUMER);
}
submit_hid_channel_state_event(
HID_SEND_CH_BLE_SHARED,
report_ready_bm,
protocol_mode);
}
@@ -141,7 +148,8 @@ static void hid_report_complete_cb(struct bt_conn *conn, void *user_data)
return;
}
submit_hid_report_sent_event(HID_TRANSPORT_BLE, in_flight.report_type,
submit_hid_report_sent_event(HID_SEND_CH_BLE_SHARED,
in_flight.report_type,
in_flight.sequence, false);
in_flight.active = false;
}
@@ -317,7 +325,8 @@ static bool handle_hid_tx_report_event(const struct hid_tx_report_event *event)
{
int err;
if (!running || (event->transport != HID_TRANSPORT_BLE) || in_flight.active) {
if (!running || (event->channel != HID_SEND_CH_BLE_SHARED) ||
in_flight.active) {
return false;
}
@@ -353,7 +362,7 @@ static bool handle_hid_tx_report_event(const struct hid_tx_report_event *event)
if (err) {
in_flight.active = false;
LOG_WRN("BLE keyboard report submit failed (%d)", err);
submit_hid_report_sent_event(HID_TRANSPORT_BLE,
submit_hid_report_sent_event(HID_SEND_CH_BLE_SHARED,
KEYBOARD_REPORT_TYPE_KEYS,
event->sequence, true);
}
@@ -380,7 +389,7 @@ static bool handle_hid_tx_report_event(const struct hid_tx_report_event *event)
if (err) {
in_flight.active = false;
LOG_WRN("BLE consumer report submit failed (%d)", err);
submit_hid_report_sent_event(HID_TRANSPORT_BLE,
submit_hid_report_sent_event(HID_SEND_CH_BLE_SHARED,
KEYBOARD_REPORT_TYPE_CONSUMER,
event->sequence, true);
}