CDC SetUnitParameter
2025-07-11
0
0
1. 请求用途
SetUnitParameter 用于设置由Unit Parameter Structure标识的Unit的参数值。
主机通过此请求配置特定Unit的参数,新参数生效的时机取决于协议或厂商特定功能。
2. USB 控制传输格式
字段 | 值/说明 |
---|---|
bmRequestType | 0x21 (00100001B) 方向:主机到设备,类型:类,接收者:接口 |
bRequest | 0x37 (SET_UNIT_PARAMETER) |
wValue | Unit Parameter Structure(见下表) |
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 = 0x12345678; // 参数值
USB_SETUP_PACKET setup = {
.bmRequestType = 0x21, // 主机到设备,类,接口
.bRequest = 0x37, // SET_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参数 |