feat(usb_hid): 支持HID供应商报告类型并增加输出报告大小
支持HID供应商特定报告类型的处理,在USB HID模块中添加了对REPORT_ID_VENDOR 的支持,并相应地修改了设备覆盖文件中的输出报告大小配置。 功能变更包括: - 在app.overlay中将out-report-size从8增加到31以支持更大的报告 - 添加hid_vendor_mask_event.h头文件引入 - 实现try_extract_vendor_mask函数用于解析供应商特定掩码数据 - 在hid_stub_set_report和hid_stub_output_report函数中添加供应商掩码处理逻辑 - 更新handle_hid_tx_event函数以允许REPORT_ID_VENDOR类型的报告
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
protocol-code = "none";
|
||||
in-report-size = <31>;
|
||||
in-polling-period-us = <1000>;
|
||||
out-report-size = <8>;
|
||||
out-report-size = <31>;
|
||||
out-polling-period-us = <1000>;
|
||||
};
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "hid_protocol_event.h"
|
||||
#include "hid_tx_done_event.h"
|
||||
#include "hid_tx_event.h"
|
||||
#include "hid_vendor_mask_event.h"
|
||||
#include "keyboard_led_event.h"
|
||||
#include "mode_event.h"
|
||||
|
||||
@@ -164,6 +165,33 @@ static bool try_extract_led_mask(const struct device *dev,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool try_extract_vendor_mask(const struct device *dev,
|
||||
uint16_t len,
|
||||
const uint8_t *buf,
|
||||
const uint8_t **mask_data,
|
||||
size_t *mask_len)
|
||||
{
|
||||
if ((buf == NULL) || (len < 1U)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dev != g_usb_hid.nkro.dev) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (buf[0] != REPORT_ID_VENDOR) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((len - 1U) != HID_VENDOR_PAYLOAD_SIZE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*mask_data = &buf[1];
|
||||
*mask_len = len - 1U;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int hid_stub_get_report(const struct device *dev,
|
||||
uint8_t type, uint8_t id,
|
||||
uint16_t len, uint8_t *buf)
|
||||
@@ -184,6 +212,14 @@ static int hid_stub_set_report(const struct device *dev,
|
||||
ARG_UNUSED(id);
|
||||
|
||||
if (!should_handle_led_input_from_dev(dev)) {
|
||||
const uint8_t *mask_data;
|
||||
size_t mask_len;
|
||||
|
||||
if (try_extract_vendor_mask(dev, len, buf, &mask_data, &mask_len)) {
|
||||
LOG_INF("hid_stub_set_report vendor mask len=%u", mask_len);
|
||||
hid_vendor_mask_event_submit(mask_data, mask_len);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -260,6 +296,14 @@ static void hid_stub_input_done(const struct device *dev, const uint8_t *report)
|
||||
static void hid_stub_output_report(const struct device *dev, uint16_t len, const uint8_t *buf)
|
||||
{
|
||||
if (!should_handle_led_input_from_dev(dev)) {
|
||||
const uint8_t *mask_data;
|
||||
size_t mask_len;
|
||||
|
||||
if (try_extract_vendor_mask(dev, len, buf, &mask_data, &mask_len)) {
|
||||
LOG_INF("hid_stub_output_report vendor mask len=%u", mask_len);
|
||||
hid_vendor_mask_event_submit(mask_data, mask_len);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -668,7 +712,9 @@ static bool handle_hid_tx_event(const struct hid_tx_event *event)
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((report_id != REPORT_ID_KEYBOARD) && (report_id != REPORT_ID_CONSUMER)) {
|
||||
if ((report_id != REPORT_ID_KEYBOARD) &&
|
||||
(report_id != REPORT_ID_CONSUMER) &&
|
||||
(report_id != REPORT_ID_VENDOR)) {
|
||||
submit_usb_tx_done(HID_TX_KIND_REPORT, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user