libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::USB::DeviceClass Class Reference

USB 设备类接口基类 / USB device class interface base. More...

#include <device_class.hpp>

Inheritance diagram for LibXR::USB::DeviceClass:
[legend]
Collaboration diagram for LibXR::USB::DeviceClass:
[legend]

Data Structures

struct  ControlTransferResult
 控制请求(Class/Vendor)处理结果 / Control request (Class/Vendor) handling result More...
 

Public Member Functions

 DeviceClass ()=default
 默认构造 / Default constructor
 
virtual const char * GetInterfaceString (size_t local_interface_index) const
 返回本类暴露的第 N 个接口字符串 Return the string for the Nth local interface exposed by this class.
 
size_t GetBosCapabilityCount () override
 返回本类提供的 BOS capability 数量 Return the number of BOS capabilities exposed by this class.
 
BosCapabilityGetBosCapability (size_t index) override
 返回指定 BOS capability Return the BOS capability at the given index.
 
- Public Member Functions inherited from LibXR::USB::ConfigDescriptorItem
virtual void BindEndpoints (EndpointPool &endpoint_pool, uint8_t start_itf_num, bool in_isr)=0
 绑定端点资源 / Bind endpoint resources
 
virtual void UnbindEndpoints (EndpointPool &endpoint_pool, bool in_isr)=0
 解绑端点资源 / Unbind endpoint resources
 
virtual ErrorCode WriteDeviceDescriptor (DeviceDescriptor &header)
 可选:覆盖设备描述符字段 / Optional: override device descriptor fields
 
virtual ErrorCode SetAltSetting (uint8_t itf, uint8_t alt)
 可选:设置接口备用设置 / Optional: set interface alternate setting
 
virtual ErrorCode GetAltSetting (uint8_t itf, uint8_t &alt)
 可选:获取接口备用设置 / Optional: get interface alternate setting
 
virtual bool OwnsEndpoint (uint8_t ep_addr) const
 可选:端点归属判定 / Optional: endpoint ownership
 
virtual size_t GetMaxConfigSize ()=0
 最大配置描述符占用 / Maximum bytes required in configuration descriptor
 
virtual size_t GetInterfaceCount ()=0
 接口数量 / Number of interfaces contributed
 
virtual bool HasIAD ()=0
 是否包含 IAD / Whether an IAD is used
 
- Public Member Functions inherited from LibXR::USB::BosCapabilityProvider

Protected Member Functions

uint8_t GetInterfaceStringIndex (size_t local_interface_index) const
 返回已分配的接口字符串索引 Return the assigned USB string index for a local interface.
 
virtual ErrorCode OnGetDescriptor (bool in_isr, uint8_t bRequest, uint16_t wValue, uint16_t wLength, ConstRawData &out_data)
 处理标准请求 GET_DESCRIPTOR(类特定描述符) Handle standard GET_DESCRIPTOR request (class-specific descriptors).
 
virtual ErrorCode OnClassRequest (bool in_isr, uint8_t bRequest, uint16_t wValue, uint16_t wLength, uint16_t wIndex, ControlTransferResult &result)
 处理 Class-specific 请求(Setup stage)/ Handle class-specific request (Setup stage)
 
virtual ErrorCode OnClassData (bool in_isr, uint8_t bRequest, LibXR::ConstRawData &data)
 处理 Class request 数据阶段 / Handle class request data stage
 
virtual void OnClassInDataStatusComplete (bool in_isr, uint8_t bRequest)
 类请求的 IN 数据阶段在 STATUS OUT 完成后回调 Called after the STATUS OUT completes for a Class IN data request.
 
virtual ErrorCode OnVendorRequest (bool in_isr, uint8_t bRequest, uint16_t wValue, uint16_t wLength, uint16_t wIndex, ControlTransferResult &result)
 处理 Vendor request(Setup stage)/ Handle vendor request (Setup stage)
 
- Protected Member Functions inherited from LibXR::USB::ConfigDescriptorItem
RawData GetData ()
 获取内部数据缓存 / Get internal data cache
 
void SetData (RawData data)
 设置内部数据缓存 / Set internal data cache
 

Private Member Functions

void SetInterfaceStringBaseIndex (uint8_t string_index)
 

Private Attributes

uint8_t interface_string_base_index_
 首个接口字符串索引 / First interface string index
 

Friends

class DeviceComposition
 
class DeviceCore
 

Detailed Description

USB 设备类接口基类 / USB device class interface base.

所有自定义 USB 类(HID/CDC/MSC 等)应派生自本类。 All custom USB classes (HID/CDC/MSC, etc.) should derive from this class.

Definition at line 20 of file device_class.hpp.

Member Function Documentation

◆ GetBosCapability()

BosCapability * LibXR::USB::DeviceClass::GetBosCapability ( size_t index)
inlineoverridevirtual

返回指定 BOS capability Return the BOS capability at the given index.

Reimplemented from LibXR::USB::BosCapabilityProvider.

Reimplemented in LibXR::USB::DfuInterfaceClassBase.

Definition at line 51 of file device_class.hpp.

52 {
53 UNUSED(index);
54 return nullptr;
55 }

◆ GetBosCapabilityCount()

size_t LibXR::USB::DeviceClass::GetBosCapabilityCount ( )
inlineoverridevirtual

返回本类提供的 BOS capability 数量 Return the number of BOS capabilities exposed by this class.

Reimplemented from LibXR::USB::BosCapabilityProvider.

Reimplemented in LibXR::USB::DfuInterfaceClassBase.

Definition at line 45 of file device_class.hpp.

45{ return 0u; }

◆ GetInterfaceString()

virtual const char * LibXR::USB::DeviceClass::GetInterfaceString ( size_t local_interface_index) const
inlinevirtual

返回本类暴露的第 N 个接口字符串 Return the string for the Nth local interface exposed by this class.

Parameters
local_interface_index类内局部接口序号 / Class-local interface index
Returns
UTF-8 字符串,返回 nullptr 表示不提供 / UTF-8 string, or nullptr if unused

Reimplemented in LibXR::USB::CDCBase, LibXR::USB::DapLinkV2Class< SwdPort, DefaultDapPacketSize, AdvertisedPacketCount, MaxDapPacketSize, QueuedRequestBufferSize, QueuedCommandCountMax >, LibXR::USB::DfuInterfaceClassBase, LibXR::USB::GsUsbClass< CanChNum >, LibXR::USB::HID< REPORT_DESC_LEN, TX_REPORT_LEN, RX_REPORT_LEN >, LibXR::USB::HID< 50, 9, 0 >, LibXR::USB::HID< sizeof(DAPLINK_V1_REPORT_DESC), DapLinkV1Def::MAX_REQUEST_SIZE, DapLinkV1Def::MAX_RESPONSE_SIZE >, LibXR::USB::HID< sizeof(HID_KEYBOARD_REPORT_DESC), 8, 1 >, LibXR::USB::HID< sizeof(HID_MOUSE_REPORT_DESC), 4, 0 >, and LibXR::USB::UAC1MicrophoneQ< CHANNELS, BITS_PER_SAMPLE >.

Definition at line 35 of file device_class.hpp.

36 {
37 UNUSED(local_interface_index);
38 return nullptr;
39 }

◆ GetInterfaceStringIndex()

uint8_t DeviceClass::GetInterfaceStringIndex ( size_t local_interface_index) const
nodiscardprotected

返回已分配的接口字符串索引 Return the assigned USB string index for a local interface.

Parameters
local_interface_index类内局部接口序号 / Class-local interface index
Returns
USB 字符串索引;0 表示未分配 / USB string index; 0 means unassigned

Definition at line 5 of file device_class.cpp.

6{
8 {
9 return 0;
10 }
11 if (GetInterfaceString(local_interface_index) == nullptr)
12 {
13 return 0;
14 }
15
16 uint8_t index = interface_string_base_index_;
17 for (size_t i = 0; i < local_interface_index; ++i)
18 {
19 if (GetInterfaceString(i) != nullptr)
20 {
21 ++index;
22 }
23 }
24 return index;
25}
uint8_t interface_string_base_index_
首个接口字符串索引 / First interface string index
virtual const char * GetInterfaceString(size_t local_interface_index) const
返回本类暴露的第 N 个接口字符串 Return the string for the Nth local interface exposed by this class.

◆ OnClassData()

virtual ErrorCode LibXR::USB::DeviceClass::OnClassData ( bool in_isr,
uint8_t bRequest,
LibXR::ConstRawData & data )
inlineprotectedvirtual

处理 Class request 数据阶段 / Handle class request data stage

Parameters
in_isr是否在 ISR / Whether in ISR context
bRequest请求码 / Request code
data数据阶段数据 / Data stage payload
Returns
错误码 / Error code
Note
当 OnClassRequest 返回需要 OUT/IN data stage 时,数据阶段完成后回调此函数。 When OnClassRequest requires an OUT/IN data stage, this callback is invoked after completion.

Reimplemented in LibXR::USB::CDCBase, LibXR::USB::DFUClass< Backend, MAX_TRANSFER_SIZE >, LibXR::USB::DFUClass< DfuBootloaderBackend, 4096u >, LibXR::USB::GsUsbClass< CanChNum >, LibXR::USB::HID< REPORT_DESC_LEN, TX_REPORT_LEN, RX_REPORT_LEN >, LibXR::USB::HID< 50, 9, 0 >, LibXR::USB::HID< sizeof(DAPLINK_V1_REPORT_DESC), DapLinkV1Def::MAX_REQUEST_SIZE, DapLinkV1Def::MAX_RESPONSE_SIZE >, LibXR::USB::HID< sizeof(HID_KEYBOARD_REPORT_DESC), 8, 1 >, LibXR::USB::HID< sizeof(HID_MOUSE_REPORT_DESC), 4, 0 >, and LibXR::USB::UAC1MicrophoneQ< CHANNELS, BITS_PER_SAMPLE >.

Definition at line 155 of file device_class.hpp.

156 {
157 UNUSED(in_isr);
158 UNUSED(bRequest);
159 UNUSED(data);
161 }
@ NOT_SUPPORT
不支持 | Not supported

◆ OnClassInDataStatusComplete()

virtual void LibXR::USB::DeviceClass::OnClassInDataStatusComplete ( bool in_isr,
uint8_t bRequest )
inlineprotectedvirtual

类请求的 IN 数据阶段在 STATUS OUT 完成后回调 Called after the STATUS OUT completes for a Class IN data request.

Parameters
in_isr是否在 ISR / Whether in ISR context
bRequest请求码 / Request code

Reimplemented in LibXR::USB::DFUClass< Backend, MAX_TRANSFER_SIZE >, and LibXR::USB::DFUClass< DfuBootloaderBackend, 4096u >.

Definition at line 170 of file device_class.hpp.

171 {
172 UNUSED(in_isr);
173 UNUSED(bRequest);
174 }

◆ OnClassRequest()

virtual ErrorCode LibXR::USB::DeviceClass::OnClassRequest ( bool in_isr,
uint8_t bRequest,
uint16_t wValue,
uint16_t wLength,
uint16_t wIndex,
ControlTransferResult & result )
inlineprotectedvirtual

处理 Class-specific 请求(Setup stage)/ Handle class-specific request (Setup stage)

Parameters
in_isr是否在 ISR / Whether in ISR context
bRequest请求码 / Request code
wValuewValue / wValue
wLengthwLength / wLength
wIndexwIndex / wIndex
result输出:控制传输结果 / Output: control transfer result
Returns
错误码 / Error code

Reimplemented in LibXR::USB::CDCBase, LibXR::USB::DFUClass< Backend, MAX_TRANSFER_SIZE >, LibXR::USB::DFUClass< DfuBootloaderBackend, 4096u >, LibXR::USB::DfuRuntimeClass, LibXR::USB::GsUsbClass< CanChNum >, LibXR::USB::HID< REPORT_DESC_LEN, TX_REPORT_LEN, RX_REPORT_LEN >, LibXR::USB::HID< 50, 9, 0 >, LibXR::USB::HID< sizeof(DAPLINK_V1_REPORT_DESC), DapLinkV1Def::MAX_REQUEST_SIZE, DapLinkV1Def::MAX_RESPONSE_SIZE >, LibXR::USB::HID< sizeof(HID_KEYBOARD_REPORT_DESC), 8, 1 >, LibXR::USB::HID< sizeof(HID_MOUSE_REPORT_DESC), 4, 0 >, and LibXR::USB::UAC1MicrophoneQ< CHANNELS, BITS_PER_SAMPLE >.

Definition at line 130 of file device_class.hpp.

133 {
134 UNUSED(in_isr);
135 UNUSED(bRequest);
136 UNUSED(wValue);
137 UNUSED(wLength);
138 UNUSED(wIndex);
139 UNUSED(result);
141 }

◆ OnGetDescriptor()

virtual ErrorCode LibXR::USB::DeviceClass::OnGetDescriptor ( bool in_isr,
uint8_t bRequest,
uint16_t wValue,
uint16_t wLength,
ConstRawData & out_data )
inlineprotectedvirtual

处理标准请求 GET_DESCRIPTOR(类特定描述符) Handle standard GET_DESCRIPTOR request (class-specific descriptors).

Parameters
in_isr是否在 ISR / Whether in ISR context
bRequest请求码 / Request code
wValuewValue / wValue
wLengthwLength / wLength
out_data输出:返回给主机的描述符数据(Device->Host) Output: descriptor data to return (Device->Host)
Returns
错误码 / Error code

Reimplemented in LibXR::USB::DFUClass< Backend, MAX_TRANSFER_SIZE >, LibXR::USB::DFUClass< DfuBootloaderBackend, 4096u >, LibXR::USB::DfuRuntimeClass, LibXR::USB::HID< REPORT_DESC_LEN, TX_REPORT_LEN, RX_REPORT_LEN >, LibXR::USB::HID< 50, 9, 0 >, LibXR::USB::HID< sizeof(DAPLINK_V1_REPORT_DESC), DapLinkV1Def::MAX_REQUEST_SIZE, DapLinkV1Def::MAX_RESPONSE_SIZE >, LibXR::USB::HID< sizeof(HID_KEYBOARD_REPORT_DESC), 8, 1 >, LibXR::USB::HID< sizeof(HID_MOUSE_REPORT_DESC), 4, 0 >, and LibXR::USB::UAC1MicrophoneQ< CHANNELS, BITS_PER_SAMPLE >.

Definition at line 107 of file device_class.hpp.

109 {
110 UNUSED(in_isr);
111 UNUSED(bRequest);
112 UNUSED(wValue);
113 UNUSED(wLength);
114 UNUSED(out_data);
116 }

◆ OnVendorRequest()

virtual ErrorCode LibXR::USB::DeviceClass::OnVendorRequest ( bool in_isr,
uint8_t bRequest,
uint16_t wValue,
uint16_t wLength,
uint16_t wIndex,
ControlTransferResult & result )
inlineprotectedvirtual

处理 Vendor request(Setup stage)/ Handle vendor request (Setup stage)

Parameters
in_isr是否在 ISR / Whether in ISR context
bRequest请求码 / Request code
wValuewValue / wValue
wLengthwLength / wLength
wIndexwIndex / wIndex
result输出:控制传输结果 / Output: control transfer result
Returns
错误码 / Error code

Reimplemented in LibXR::USB::DfuBootloaderClassT< MAX_TRANSFER_SIZE >, and LibXR::USB::GsUsbClass< CanChNum >.

Definition at line 187 of file device_class.hpp.

190 {
191 UNUSED(in_isr);
192 UNUSED(bRequest);
193 UNUSED(wValue);
194 UNUSED(wLength);
195 UNUSED(wIndex);
196 UNUSED(result);
198 }

◆ SetInterfaceStringBaseIndex()

void DeviceClass::SetInterfaceStringBaseIndex ( uint8_t string_index)
private

Definition at line 27 of file device_class.cpp.

28{
29 interface_string_base_index_ = string_index;
30}

Friends And Related Symbol Documentation

◆ DeviceComposition

friend class DeviceComposition
friend

Definition at line 206 of file device_class.hpp.

◆ DeviceCore

friend class DeviceCore
friend

Definition at line 207 of file device_class.hpp.

Field Documentation

◆ interface_string_base_index_

uint8_t LibXR::USB::DeviceClass::interface_string_base_index_
private
Initial value:
=
0u

首个接口字符串索引 / First interface string index

Definition at line 209 of file device_class.hpp.


The documentation for this class was generated from the following files: