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 <dev_core.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 (std::initializer_list< BosCapability * > bos_caps={})
 构造:传入本类提供的 BOS capabilities(对象指针列表) Constructor: pass BOS capabilities provided by this class (pointer list).
 
 ~DeviceClass () override
 析构函数 / Destructor
 
- 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
virtual size_t GetBosCapabilityCount ()
 获取 BOS 能力数量 / Get BOS capability count
 
virtual BosCapabilityGetBosCapability (size_t index)
 获取指定索引的 BOS 能力 / Get BOS capability at index
 

Protected Member Functions

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 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 Attributes

BosCapability ** bos_caps_
 BOS capability 指针表 / BOS capability pointer table.
 
size_t bos_cap_num_ = 0
 BOS capability 数量 / BOS capability count.
 

Friends

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.

Note
该类主要供 DeviceCore 驱动及派生类扩展使用。 This class is mainly used by DeviceCore and derived-class extensions.

Definition at line 25 of file dev_core.hpp.

Constructor & Destructor Documentation

◆ DeviceClass()

DeviceClass::DeviceClass ( std::initializer_list< BosCapability * > bos_caps = {})
explicit

构造:传入本类提供的 BOS capabilities(对象指针列表) Constructor: pass BOS capabilities provided by this class (pointer list).

Parameters
bos_capsBOS capability 指针列表 / BOS capability pointer list
Note
基类会动态分配一个指针数组保存这些 capability 指针。 capability 对象本身生命周期应由派生类成员/静态对象管理。

Definition at line 12 of file dev_core.cpp.

13 : bos_cap_num_(bos_caps.size())
14{
15 if (bos_cap_num_ > 0)
16 {
18 size_t i = 0;
19 for (auto* cap : bos_caps)
20 {
21 bos_caps_[i++] = cap;
22 }
23 }
24}
BOS 能力接口 / BOS capability interface.
Definition bos.hpp:56
size_t bos_cap_num_
BOS capability 数量 / BOS capability count.
Definition dev_core.hpp:170
BosCapability ** bos_caps_
BOS capability 指针表 / BOS capability pointer table.
Definition dev_core.hpp:168

◆ ~DeviceClass()

DeviceClass::~DeviceClass ( )
override

析构函数 / Destructor

Definition at line 26 of file dev_core.cpp.

27{
28 // 仅释放指针数组本身(capability 对象生命周期由派生类成员管理)
29 // Only free the pointer array itself (capability objects are owned by derived class
30 // members).
31 delete[] bos_caps_;
32 bos_caps_ = nullptr;
33 bos_cap_num_ = 0;
34}

Member Function Documentation

◆ 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::GsUsbClass< CanChNum >, LibXR::USB::HID< REPORT_DESC_LEN, TX_REPORT_LEN, RX_REPORT_LEN >, LibXR::USB::HID< 50, 9, 0 >, 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 133 of file dev_core.hpp.

134 {
135 UNUSED(in_isr);
136 UNUSED(bRequest);
137 UNUSED(data);
138 return ErrorCode::NOT_SUPPORT;
139 }

◆ 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::GsUsbClass< CanChNum >, LibXR::USB::HID< REPORT_DESC_LEN, TX_REPORT_LEN, RX_REPORT_LEN >, LibXR::USB::HID< 50, 9, 0 >, 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 108 of file dev_core.hpp.

111 {
112 UNUSED(in_isr);
113 UNUSED(bRequest);
114 UNUSED(wValue);
115 UNUSED(wLength);
116 UNUSED(wIndex);
117 UNUSED(result);
118 return ErrorCode::NOT_SUPPORT;
119 }

◆ 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::HID< REPORT_DESC_LEN, TX_REPORT_LEN, RX_REPORT_LEN >, LibXR::USB::HID< 50, 9, 0 >, 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 85 of file dev_core.hpp.

87 {
88 UNUSED(in_isr);
89 UNUSED(bRequest);
90 UNUSED(wValue);
91 UNUSED(wLength);
92 UNUSED(out_data);
93 return ErrorCode::NOT_SUPPORT;
94 }

◆ 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::GsUsbClass< CanChNum >.

Definition at line 152 of file dev_core.hpp.

155 {
156 UNUSED(in_isr);
157 UNUSED(bRequest);
158 UNUSED(wValue);
159 UNUSED(wLength);
160 UNUSED(wIndex);
161 UNUSED(result);
162 return ErrorCode::NOT_SUPPORT;
163 }

Friends And Related Symbol Documentation

◆ DeviceCore

friend class DeviceCore
friend

Definition at line 165 of file dev_core.hpp.

Field Documentation

◆ bos_cap_num_

size_t LibXR::USB::DeviceClass::bos_cap_num_ = 0
private

BOS capability 数量 / BOS capability count.

Definition at line 170 of file dev_core.hpp.

◆ bos_caps_

BosCapability** LibXR::USB::DeviceClass::bos_caps_
private
Initial value:
=
nullptr

BOS capability 指针表 / BOS capability pointer table.

Definition at line 168 of file dev_core.hpp.


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