libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
desc_dev.hpp
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5#include <functional>
6
7#include "core.hpp"
8#include "desc_str.hpp"
9#include "ep_pool.hpp"
10#include "lockfree_list.hpp"
11
12namespace LibXR::USB
13{
14
19enum class DescriptorType : uint8_t
20{
21 DEVICE = 0x01,
22 CONFIGURATION = 0x02,
23 STRING = 0x03,
24 INTERFACE = 0x04,
25 ENDPOINT = 0x05,
26 IAD = 0x0B,
27 BOS = 0x0F,
28 DEVICE_CAPABILITY = 0x10,
29 CS_INTERFACE = 0x24,
30
31};
32
39{
40 public:
41 enum class ClassID : uint8_t
42 {
43 PER_INTERFACE = 0x00,
44 AUDIO = 0x01,
45 COMM = 0x02,
46 HID = 0x03,
47 PHYSICAL = 0x05,
48 IMAGE = 0x06,
49 PRINTER = 0x07,
50 MASS_STORAGE = 0x08,
51 HUB = 0x09,
52 CDC_DATA = 0x0A,
53 SMART_CARD = 0x0B,
54 CONTENT_SECURITY = 0x0D,
55 VIDEO = 0x0E,
56 PERSONAL_HEALTHCARE = 0x0F,
57 BILLBOARD = 0x11,
58 TYPE_C_BRIDGE = 0x12,
59 BULK_DISPLAY = 0x13,
60 MCTP = 0x14,
61 I3C = 0x3C,
62 DIAGNOSTIC = 0xDC,
63 WIRELESS = 0xE0,
64 MISCELLANEOUS = 0xEF,
66 VENDOR_SPECIFIC = 0xFF
67 };
68
73 enum class PacketSize0 : uint8_t
74 {
75 SIZE_8 = 8,
76 SIZE_16 = 16,
77 SIZE_32 = 32,
78 SIZE_64 = 64,
79 SIZE_512 = 0,
80 };
81
82 static constexpr uint8_t DEVICE_DESC_LENGTH =
83 18;
84
85 LIBXR_PACKED_BEGIN
86 struct Data
87 {
88 uint8_t bLength;
89 DescriptorType bDescriptorType;
91 USBSpec bcdUSB;
96 uint16_t idVendor;
97 uint16_t idProduct;
98 uint16_t bcdDevice;
99 uint8_t iManufacturer;
100 uint8_t iProduct;
103 };
104 LIBXR_PACKED_END
105
106 static_assert(sizeof(Data) == 18, "DeviceDescriptor must be 18 bytes");
107
109
123 DeviceDescriptor(USBSpec spec, PacketSize0 packet_size, uint16_t vid, uint16_t pid,
124 uint16_t bcd, uint8_t num_configs);
131
138 USBSpec GetUSBSpec() const;
139};
140} // namespace LibXR::USB
可写原始数据视图 / Mutable raw data view
USB描述符基类 USB descriptor base class.
Definition desc_dev.hpp:39
Data data_
设备描述符数据实例 / Internal data instance
Definition desc_dev.hpp:108
DeviceDescriptor(USBSpec spec, PacketSize0 packet_size, uint16_t vid, uint16_t pid, uint16_t bcd, uint8_t num_configs)
构造函数,初始化设备描述符 Constructor, initialize device descriptor fields
Definition desc_dev.cpp:5
USBSpec GetUSBSpec() const
获取USB协议版本 Get USB specification
Definition desc_dev.cpp:29
@ VENDOR_SPECIFIC
厂商自定义类 / Vendor Specific
@ APPLICATION_SPECIFIC
应用专用类 / Application Specific
@ DIAGNOSTIC
诊断类 / Diagnostic
@ CONTENT_SECURITY
内容安全类 / Content Security
@ IMAGE
图像/扫描仪类 / Imaging
@ WIRELESS
无线控制类 / Wireless Controller
@ PRINTER
打印机类 / Printer
@ PERSONAL_HEALTHCARE
个人医疗健康类 / Personal Healthcare
@ COMM
通信类 / Communications (CDC)
@ SMART_CARD
智能卡类 / Smart Card
@ CDC_DATA
CDC 数据类 / CDC Data.
@ MISCELLANEOUS
杂项类 / Miscellaneous
@ BILLBOARD
Billboard类(USB Type-C专用)/ Billboard (Type-C)
@ PER_INTERFACE
每个接口自定义类 / Per-interface
@ MASS_STORAGE
大容量存储类 / Mass Storage
@ PHYSICAL
物理设备类 / Physical Device
static constexpr uint8_t DEVICE_DESC_LENGTH
设备描述符长度(固定18字节)/ Device descriptor length (18 bytes)
Definition desc_dev.hpp:82
PacketSize0
控制端点0最大包长度枚举 Packet size for endpoint 0 (bMaxPacketSize0)
Definition desc_dev.hpp:74
@ SIZE_512
512字节 / 512 bytes (SuperSpeed)
@ SIZE_32
32字节 / 32 bytes (Full Speed)
@ SIZE_8
8字节 / 8 bytes (Low Speed / Full Speed)
@ SIZE_16
16字节 / 16 bytes (Full Speed)
@ SIZE_64
64字节 / 64 bytes (Full Speed / High Speed)
RawData GetData()
获取设备描述符的原始数据指针及长度 Get the raw device descriptor data pointer and length
Definition desc_dev.cpp:24
USB HID(Human Interface Device)基类,支持可选 OUT 端点、自动生成描述符,适合键盘、鼠标、手柄等扩展。 USB HID (Human Interface Device)...
Definition hid.hpp:24
uint16_t idProduct
产品ID(PID)/ Product ID
Definition desc_dev.hpp:97
ClassID bDeviceClass
设备类代码 / Device class code
Definition desc_dev.hpp:92
uint8_t bDeviceSubClass
设备子类代码 / Device subclass code
Definition desc_dev.hpp:93
uint8_t bLength
描述符长度(固定18)/ Descriptor length (always 18)
Definition desc_dev.hpp:88
uint16_t idVendor
厂商ID(VID)/ Vendor ID
Definition desc_dev.hpp:96
uint8_t iProduct
产品字符串索引 / Index of product string
Definition desc_dev.hpp:100
uint8_t iSerialNumber
序列号字符串索引 / Index of serial number string
Definition desc_dev.hpp:101
PacketSize0 bMaxPacketSize0
控制端点0最大包长 / Max packet size for endpoint 0
Definition desc_dev.hpp:95
uint8_t bDeviceProtocol
协议代码 / Protocol code
Definition desc_dev.hpp:94
USBSpec bcdUSB
USB协议版本 / USB specification release (e.g. 0x0200 for USB2.0)
Definition desc_dev.hpp:91
uint8_t bNumConfigurations
支持的配置数 / Number of possible configurations
Definition desc_dev.hpp:102
uint8_t iManufacturer
厂商字符串索引 / Index of manufacturer string
Definition desc_dev.hpp:99
uint16_t bcdDevice
设备版本号 / Device release number
Definition desc_dev.hpp:98