|
libxr
1.0
Want to be the best embedded framework
|
USB 组合管理器:class 列表、字符串、BOS、配置切换 USB composition manager: class list, strings, BOS, and configuration switching. More...
#include <device_composition.hpp>
Data Structures | |
| struct | ConfigItems |
| 单个 configuration 的扁平 item 表 Flattened item table for one configuration. More... | |
Public Member Functions | |
| DeviceComposition (EndpointPool &endpoint_pool, const std::initializer_list< const DescriptorStrings::LanguagePack * > &lang_list, const std::initializer_list< const std::initializer_list< ConfigDescriptorItem * > > &configs, ConstRawData uid={nullptr, 0}, uint8_t bmAttributes=CFG_BUS_POWERED, uint8_t bMaxPower=50) | |
| 构造 USB 组合管理器 Construct the USB composition manager. | |
| DeviceComposition (const DeviceComposition &)=delete | |
| DeviceComposition & | operator= (const DeviceComposition &)=delete |
| DeviceComposition (DeviceComposition &&)=delete | |
| DeviceComposition & | operator= (DeviceComposition &&)=delete |
| void | Init (bool in_isr) |
| 初始化当前 configuration 的运行态资源 Initialize runtime resources for the active configuration. | |
| void | Deinit (bool in_isr) |
| 释放当前 configuration 的运行态资源 Release runtime resources for the active configuration. | |
| ErrorCode | SwitchConfig (size_t index, bool in_isr) |
| 切换到指定 configuration value Switch to the given configuration value. | |
| ErrorCode | BuildConfigDescriptor () |
| 生成当前 configuration 描述符缓存 Build the current configuration descriptor cache. | |
| RawData | GetConfigDescriptor () const |
| 获取当前 configuration 描述符缓存 Get the current configuration descriptor cache. | |
| ConstRawData | GetBosDescriptor () |
| 获取当前 BOS 描述符缓存 / Get the current BOS descriptor cache | |
| ErrorCode | ProcessBosVendorRequest (bool in_isr, const SetupPacket *setup, BosVendorResult &result) |
| 分发 BOS vendor request / Dispatch BOS vendor requests | |
| ErrorCode | GetStringDescriptor (uint8_t string_index, uint16_t lang, ConstRawData &data) |
| 获取字符串描述符(含 interface string) Get a string descriptor, including runtime-generated interface strings. | |
| bool | IsComposite () const |
| 是否为复合设备 / Whether this is a composite device | |
| ErrorCode | TryOverrideDeviceDescriptor (DeviceDescriptor &descriptor) |
| 用当前配置覆盖 device descriptor 的类字段 Try to override device-descriptor class fields from the current configuration. | |
| size_t | GetConfigNum () const |
| 配置数量 / Number of configurations | |
| size_t | GetCurrentConfig () const |
| 当前 configuration value / Current configuration value | |
| uint16_t | GetDeviceStatus () const |
| 设备 GET_STATUS 返回值 / Device-level GET_STATUS value | |
| DeviceClass * | FindClassByInterfaceNumber (size_t index) const |
| 按接口号查找所属 class Find the owning class by interface number. | |
| DeviceClass * | FindClassByEndpointAddress (uint8_t addr) const |
| 按端点地址查找所属 class Find the owning class by endpoint address. | |
Private Member Functions | |
| const ConfigItems & | CurrentConfigItems () const |
| 获取当前激活 configuration 的扁平 item 表 Get the flattened item table of the active configuration. | |
| void | BindEndpoints (bool in_isr) |
| 绑定当前配置的全部端点 / Bind all endpoints for the active configuration | |
| void | UnbindEndpoints (bool in_isr) |
| 解绑当前配置的全部端点 / Unbind all endpoints for the active configuration | |
| void | RebuildBosCache () |
| 按当前配置重建 BOS capability 缓存 Rebuild the BOS capability cache from the active configuration. | |
| void | RegisterInterfaceStrings () |
| 为所有 class 分配并登记 interface string 索引 Allocate and register interface-string indices for all classes. | |
| ErrorCode | GenerateInterfaceString (uint8_t string_index, ConstRawData &data) |
| 运行时生成 interface string 描述符 Generate one interface-string descriptor at runtime. | |
Private Attributes | |
| bool | configured_ = false |
| 是否已进入非 0 配置态 / Whether a non-zero config is active | |
| bool | ep_assigned_ = false |
| 端点是否已绑定 / Whether endpoints are assigned | |
| EndpointPool & | endpoint_pool_ |
| 端点池引用 / Endpoint pool reference | |
| uint8_t | current_cfg_ = 0 |
| 当前配置索引 / Current configuration index | |
| uint8_t | i_configuration_ = 0 |
| 配置字符串索引 / Configuration string index | |
| uint8_t | bm_attributes_ = CFG_BUS_POWERED |
| 配置属性 / bmAttributes | |
| const bool | composite_ = false |
| 是否为复合设备 / Whether composite device | |
| const size_t | config_num_ = 0 |
| 配置数量 / Configuration count | |
| ConfigItems * | items_ = nullptr |
| 配置项集合 / Configuration item set | |
| DeviceClass ** | classes_ = nullptr |
| 唯一 class 表 / Unique class table | |
| size_t | class_count_ = 0 |
| 唯一 class 数量 / Unique class count | |
| DescriptorStrings | strings_ |
| 字符串描述符管理 / String descriptor manager | |
| const char ** | interface_strings_ |
| 接口字符串源表 / Interface string source table | |
| size_t | interface_string_count_ |
| 接口字符串总数量 / Total interface string count | |
| RawData | interface_string_buffer_ |
| 临时字符串描述符缓冲区 / Temp interface string descriptor buffer | |
| BosManager | bos_ |
| BOS 聚合管理 / BOS aggregation manager. | |
| ConfigDescriptor | config_desc_ |
| 配置描述符构造器 / Configuration descriptor builder | |
USB 组合管理器:class 列表、字符串、BOS、配置切换 USB composition manager: class list, strings, BOS, and configuration switching.
Definition at line 20 of file device_composition.hpp.
| DeviceComposition::DeviceComposition | ( | EndpointPool & | endpoint_pool, |
| const std::initializer_list< const DescriptorStrings::LanguagePack * > & | lang_list, | ||
| const std::initializer_list< const std::initializer_list< ConfigDescriptorItem * > > & | configs, | ||
| ConstRawData | uid = {nullptr, 0}, | ||
| uint8_t | bmAttributes = CFG_BUS_POWERED, | ||
| uint8_t | bMaxPower = 50 ) |
构造 USB 组合管理器 Construct the USB composition manager.
负责把 class/config/string/BOS 相关静态信息整理成 DeviceCore 可直接使用的形态。 This flattens class/config/string/BOS metadata into the shape consumed by DeviceCore.
Definition at line 345 of file device_composition.cpp.
|
private |
绑定当前配置的全部端点 / Bind all endpoints for the active configuration
Definition at line 599 of file device_composition.cpp.
| LibXR::ErrorCode DeviceComposition::BuildConfigDescriptor | ( | ) |
生成当前 configuration 描述符缓存 Build the current configuration descriptor cache.
Definition at line 454 of file device_composition.cpp.
|
nodiscardprivate |
获取当前激活 configuration 的扁平 item 表 Get the flattened item table of the active configuration.
Definition at line 405 of file device_composition.cpp.
| void DeviceComposition::Deinit | ( | bool | in_isr | ) |
释放当前 configuration 的运行态资源 Release runtime resources for the active configuration.
Definition at line 421 of file device_composition.cpp.
|
nodiscard |
按端点地址查找所属 class Find the owning class by endpoint address.
Definition at line 573 of file device_composition.cpp.
|
nodiscard |
按接口号查找所属 class Find the owning class by interface number.
Definition at line 541 of file device_composition.cpp.
|
private |
运行时生成 interface string 描述符 Generate one interface-string descriptor at runtime.
Definition at line 676 of file device_composition.cpp.
|
nodiscard |
获取当前 BOS 描述符缓存 / Get the current BOS descriptor cache
Definition at line 469 of file device_composition.cpp.
|
nodiscard |
获取当前 configuration 描述符缓存 Get the current configuration descriptor cache.
Definition at line 467 of file device_composition.cpp.
|
nodiscard |
|
nodiscard |
当前 configuration value / Current configuration value
Definition at line 530 of file device_composition.cpp.
|
nodiscard |
设备 GET_STATUS 返回值 / Device-level GET_STATUS value
Definition at line 535 of file device_composition.cpp.
| LibXR::ErrorCode DeviceComposition::GetStringDescriptor | ( | uint8_t | string_index, |
| uint16_t | lang, | ||
| ConstRawData & | data ) |
获取字符串描述符(含 interface string) Get a string descriptor, including runtime-generated interface strings.
Definition at line 478 of file device_composition.cpp.
| void DeviceComposition::Init | ( | bool | in_isr | ) |
初始化当前 configuration 的运行态资源 Initialize runtime resources for the active configuration.
Definition at line 412 of file device_composition.cpp.
|
nodiscard |
| LibXR::ErrorCode DeviceComposition::ProcessBosVendorRequest | ( | bool | in_isr, |
| const SetupPacket * | setup, | ||
| BosVendorResult & | result ) |
分发 BOS vendor request / Dispatch BOS vendor requests
Definition at line 471 of file device_composition.cpp.
|
private |
按当前配置重建 BOS capability 缓存 Rebuild the BOS capability cache from the active configuration.
Definition at line 648 of file device_composition.cpp.
|
private |
为所有 class 分配并登记 interface string 索引 Allocate and register interface-string indices for all classes.
Definition at line 708 of file device_composition.cpp.
| LibXR::ErrorCode DeviceComposition::SwitchConfig | ( | size_t | index, |
| bool | in_isr ) |
切换到指定 configuration value Switch to the given configuration value.
Definition at line 428 of file device_composition.cpp.
| LibXR::ErrorCode DeviceComposition::TryOverrideDeviceDescriptor | ( | DeviceDescriptor & | descriptor | ) |
用当前配置覆盖 device descriptor 的类字段 Try to override device-descriptor class fields from the current configuration.
Definition at line 511 of file device_composition.cpp.
|
private |
解绑当前配置的全部端点 / Unbind all endpoints for the active configuration
Definition at line 625 of file device_composition.cpp.
|
private |
配置属性 / bmAttributes
Definition at line 179 of file device_composition.hpp.
|
private |
BOS 聚合管理 / BOS aggregation manager.
Definition at line 194 of file device_composition.hpp.
|
private |
唯一 class 数量 / Unique class count
Definition at line 185 of file device_composition.hpp.
|
private |
唯一 class 表 / Unique class table
Definition at line 184 of file device_composition.hpp.
|
private |
是否为复合设备 / Whether composite device
Definition at line 181 of file device_composition.hpp.
|
private |
配置描述符构造器 / Configuration descriptor builder
Definition at line 195 of file device_composition.hpp.
|
private |
配置数量 / Configuration count
Definition at line 182 of file device_composition.hpp.
|
private |
是否已进入非 0 配置态 / Whether a non-zero config is active
Definition at line 173 of file device_composition.hpp.
|
private |
当前配置索引 / Current configuration index
Definition at line 177 of file device_composition.hpp.
|
private |
端点池引用 / Endpoint pool reference
Definition at line 176 of file device_composition.hpp.
|
private |
端点是否已绑定 / Whether endpoints are assigned
Definition at line 174 of file device_composition.hpp.
|
private |
配置字符串索引 / Configuration string index
Definition at line 178 of file device_composition.hpp.
|
private |
临时字符串描述符缓冲区 / Temp interface string descriptor buffer
Definition at line 192 of file device_composition.hpp.
|
private |
接口字符串总数量 / Total interface string count
Definition at line 190 of file device_composition.hpp.
|
private |
接口字符串源表 / Interface string source table
Definition at line 188 of file device_composition.hpp.
|
private |
配置项集合 / Configuration item set
Definition at line 183 of file device_composition.hpp.
|
private |
字符串描述符管理 / String descriptor manager
Definition at line 187 of file device_composition.hpp.