CDC GetUnitParameter
2025-07-11
0
0
1. GetUnitParameter 请求用途
GetUnitParameter 用于返回由Unit Parameter Structure指向的Unit参数的当前值。
主机通过此请求查询特定Unit的当前参数值,用于状态监控和参数验证。
2. USB 控制传输格式
字段 | 值/说明 |
---|---|
bmRequestType | 0xA1 (10100001B) 方向:设备到主机,类型:类,接收者:接口 |
bRequest | 0x38 (GET_UNIT_PARAMETER) |
wValue | Unit Parameter Structure(见Table 60) |
wIndex | 接口号 |
wLength | Unit Parameter的长度 |
Data | Unit Parameter数据(设备返回) |
3. Unit Parameter Structure(Table 60)
偏移量 | 字段名 | 大小 | 值/说明 |
---|---|---|---|
0 | bEntityId | 1 | Unit ID |
1 | bParameterIndex | 1 | 基于零的值,指示Unit参数索引 |
C 结构体定义:
typedef struct _UNIT_PARAMETER_STRUCTURE {
uint8_t bEntityId; // Unit ID
uint8_t bParameterIndex; // 参数索引(从0开始)
} UNIT_PARAMETER_STRUCTURE;
4. 典型主机端请求示例
C 结构体示例:
UNIT_PARAMETER_STRUCTURE unit_param = {
.bEntityId = 0x01, // Unit ID 1
.bParameterIndex = 0x00 // 参数索引 0
};
uint32_t parameter_value; // 参数值
USB_SETUP_PACKET setup = {
.bmRequestType = 0xA1, // 设备到主机,类,接口
.bRequest = 0x38, // GET_UNIT_PARAMETER
.wValue = *(uint16_t*)&unit_param, // Unit Parameter Structure
.wIndex = interface_number, // 通信接口号
.wLength = sizeof(parameter_value)
};
// 发送setup包,读取parameter_value数据
5. 设备端处理要点
- 解析wValue中的Unit Parameter Structure。
- 根据bEntityId和bParameterIndex确定目标参数。
- 返回当前参数值到Data阶段。
- 完成后通过状态阶段(Status Stage)ACK主机。
6. 常见应用场景
场景 | bEntityId | bParameterIndex | 说明 |
---|---|---|---|
音频Unit | 0x01 | 0x00 | 获取音频Unit参数 |
控制Unit | 0x02 | 0x01 | 获取控制Unit参数 |
厂商特定Unit | 0xFF | 0x00 | 获取厂商特定Unit参数 |
7. 参考
- USB CDC 规范 6.2.17](https://www.usb.org/document-library/class-definitions-communication-devices-12)
- SetUnitParameter 6.2.16](https://www.usb.org/document-library/class-definitions-communication-devices-12)