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#include "lockfree_pool.hpp"
12
13namespace LibXR::USB
14{
15
20enum class DescriptorType : uint8_t
21{
22 DEVICE = 0x01,
23 CONFIGURATION = 0x02,
24 STRING = 0x03,
25 INTERFACE = 0x04,
26 ENDPOINT = 0x05,
27 IAD = 0x0B,
28 CS_INTERFACE = 0x24,
29};
30
37{
38 public:
39 enum class ClassID : uint8_t
40 {
41 PER_INTERFACE = 0x00,
42 AUDIO = 0x01,
43 COMM = 0x02,
44 HID = 0x03,
45 PHYSICAL = 0x05,
46 IMAGE = 0x06,
47 PRINTER = 0x07,
48 MASS_STORAGE = 0x08,
49 HUB = 0x09,
50 CDC_DATA = 0x0A,
51 SMART_CARD = 0x0B,
52 CONTENT_SECURITY = 0x0D,
53 VIDEO = 0x0E,
54 PERSONAL_HEALTHCARE = 0x0F,
55 BILLBOARD = 0x11,
56 TYPE_C_BRIDGE = 0x12,
57 BULK_DISPLAY = 0x13,
58 MCTP = 0x14,
59 I3C = 0x3C,
60 DIAGNOSTIC = 0xDC,
61 WIRELESS = 0xE0,
62 MISCELLANEOUS = 0xEF,
64 VENDOR_SPECIFIC = 0xFF
65 };
66
71 enum class PacketSize0 : uint8_t
72 {
73 SIZE_8 = 8,
74 SIZE_16 = 16,
75 SIZE_32 = 32,
76 SIZE_64 = 64,
77 SIZE_512 = 0,
78 };
79
80 static constexpr uint8_t DEVICE_DESC_LENGTH =
81 18;
82
83#pragma pack(push, 1)
84 struct Data
85 {
86 uint8_t bLength;
87 DescriptorType bDescriptorType;
89 USBSpec bcdUSB;
94 uint16_t idVendor;
95 uint16_t idProduct;
96 uint16_t bcdDevice;
97 uint8_t iManufacturer;
98 uint8_t iProduct;
99 uint8_t iSerialNumber;
101 };
102#pragma pack(pop)
103
104 static_assert(sizeof(Data) == 18, "DeviceDescriptor must be 18 bytes");
105
107
121 DeviceDescriptor(USBSpec spec, PacketSize0 packet_size, uint16_t vid, uint16_t pid,
122 uint16_t bcd, uint8_t num_configs);
129
136 USBSpec GetUSBSpec() const;
137};
138} // namespace LibXR::USB
原始数据封装类。 A class for encapsulating raw data.
USB描述符基类 USB descriptor base class.
Definition desc_dev.hpp:37
Data data_
设备描述符数据实例 / Internal data instance
Definition desc_dev.hpp:106
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:80
PacketSize0
控制端点0最大包长度枚举 Packet size for endpoint 0 (bMaxPacketSize0)
Definition desc_dev.hpp:72
@ 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:23
uint16_t idProduct
产品ID(PID)/ Product ID
Definition desc_dev.hpp:95
ClassID bDeviceClass
设备类代码 / Device class code
Definition desc_dev.hpp:90
uint8_t bDeviceSubClass
设备子类代码 / Device subclass code
Definition desc_dev.hpp:91
uint8_t bLength
描述符长度(固定18)/ Descriptor length (always 18)
Definition desc_dev.hpp:86
uint16_t idVendor
厂商ID(VID)/ Vendor ID
Definition desc_dev.hpp:94
uint8_t iProduct
产品字符串索引 / Index of product string
Definition desc_dev.hpp:98
uint8_t iSerialNumber
序列号字符串索引 / Index of serial number string
Definition desc_dev.hpp:99
PacketSize0 bMaxPacketSize0
控制端点0最大包长 / Max packet size for endpoint 0
Definition desc_dev.hpp:93
uint8_t bDeviceProtocol
协议代码 / Protocol code
Definition desc_dev.hpp:92
USBSpec bcdUSB
USB协议版本 / USB specification release (e.g. 0x0200 for USB2.0)
Definition desc_dev.hpp:89
uint8_t bNumConfigurations
支持的配置数 / Number of possible configurations
Definition desc_dev.hpp:100
uint8_t iManufacturer
厂商字符串索引 / Index of manufacturer string
Definition desc_dev.hpp:97
uint16_t bcdDevice
设备版本号 / Device release number
Definition desc_dev.hpp:96