29template <
int16_t LOG_MIN = 0,
int16_t LOG_MAX = 2047, u
int8_t IN_EP_INTERVAL_MS = 1>
31 :
public HID<50 , 9 , 0 >
33 static_assert(LOG_MIN <= LOG_MAX,
"LOG_MIN must be <= LOG_MAX");
34 static_assert(LOG_MIN >= -32768 && LOG_MAX <= 32767,
35 "Axis logical range must fit in int16_t");
47 :
HID<50, 9, 0>(false, IN_EP_INTERVAL_MS, 1, in_ep_num,
48 Endpoint::EPNumber::EP_AUTO, interface_string)
90 static_assert(
sizeof(
Report) == 9,
"Report size must be 9 bytes");
163 static constexpr uint8_t U8(uint16_t v) {
return static_cast<uint8_t
>(v & 0xFF); }
164 static constexpr uint8_t U8H(uint16_t v)
166 return static_cast<uint8_t
>((v >> 8) & 0xFF);
169 static constexpr uint8_t desc_[] = {
184 0x16, U8(
static_cast<uint16_t
>(LOG_MIN)),
185 U8H(
static_cast<uint16_t
>(LOG_MIN)),
186 0x26, U8(
static_cast<uint16_t
>(LOG_MAX)),
187 U8H(
static_cast<uint16_t
>(LOG_MAX)),
207 static_assert(
sizeof(desc_) == 50,
208 "HID report descriptor size changed; update base template arg!");
213 static constexpr int16_t
Clamp(
int v)
215 return (v < LOG_MIN) ? LOG_MIN : (v > LOG_MAX ? LOG_MAX :
static_cast<int16_t
>(v));
221 static constexpr int16_t
Mid()
223 return static_cast<int16_t
>(
224 (
static_cast<int32_t
>(LOG_MIN) +
static_cast<int32_t
>(LOG_MAX)) / 2);
233using HIDGamepad = HIDGamepadT<0, 2047, 1>;
238using HIDGamepadBipolar = HIDGamepadT<-2048, 2047, 1>;
常量原始数据封装类。 A class for encapsulating constant raw data.
USB描述符基类 USB descriptor base class.
Data data_
设备描述符数据实例 / Internal data instance
@ PER_INTERFACE
每个接口自定义类 / Per-interface
USB 端点基类 / USB Endpoint base class.
EPNumber
端点号 Endpoint number
@ EP_AUTO
自动分配端点号 / Auto allocate
模板化 4 轴 + 8 按钮 HID 手柄 / Templated 4-axis + 8-button HID gamepad
Button
按钮位掩码(8 个) / Button bit masks (8 buttons)
ErrorCode SendAxes(int x, int y, int z, int rx)
仅更新轴(保持按钮不变) / Update axes only (buttons unchanged)
HIDGamepadT(Endpoint::EPNumber in_ep_num=Endpoint::EPNumber::EP_AUTO, const char *interface_string=HID< 50, 9, 0 >::DEFAULT_INTERFACE_STRING)
构造函数 / Constructor
ErrorCode SendButtons(uint8_t buttons)
仅更新按钮(保持轴不变) / Update buttons only (axes unchanged)
ErrorCode Send(int x, int y, int z, int rx, uint8_t buttons)
发送完整输入报告(轴 + 按钮) / Send a full input report (axes + buttons)
static constexpr int16_t Mid()
轴逻辑中点 / Logical midpoint of axes
ConstRawData GetReportDesc() override
获取报告描述符 / Get report descriptor
static constexpr int16_t Clamp(int v)
将值夹到 [LOG_MIN, LOG_MAX] / Clamp a value to [LOG_MIN, LOG_MAX]
Report last_
最近一次发送的输入报告 / Last-sent input report
ErrorCode WriteDeviceDescriptor(DeviceDescriptor &header) override
写入设备描述符(Per-Interface) / Write device descriptor (Per-Interface)
USB HID(Human Interface Device)基类,支持可选 OUT 端点、自动生成描述符,适合键盘、鼠标、手柄等扩展。 USB HID (Human Interface Device)...
ErrorCode SendInputReport(ConstRawData report)
@ OK
操作成功 | Operation successful
ClassID bDeviceClass
设备类代码 / Device class code
uint8_t bDeviceSubClass
设备子类代码 / Device subclass code
uint8_t bDeviceProtocol
协议代码 / Protocol code
输入报告结构(9 字节) / Input report structure (9 bytes)
int16_t y
Y 轴 / Y axis (LOG_MIN..LOG_MAX)
int16_t x
X 轴 / X axis (LOG_MIN..LOG_MAX)
int16_t rx
Rx 轴 / Rx axis (LOG_MIN..LOG_MAX)
int16_t z
Z 轴 / Z axis (LOG_MIN..LOG_MAX)
uint8_t buttons
按钮位 / Button bits (8)