# USB - LPM
USB-IF CV Tool裝置要回應USBD_QualifierDesc_UAC 主機才會問USBD_BosDesc_UAC
https://blog.csdn.net/u012028275/article/details/110293046
USB筆記 USB 2.0擴展描述符(USB 2.0 Extension Descriptor)
USB 2.0擴展描述符(USB 2.0 Extension Descriptor)是設備功能類型碼(Device Capability Type Codes)為USB 2.0 EXTENSION的一個設備功能描述符(Device Capability Descriptor)。USB 2.0擴展描述符(USB 2.0 Extension Descriptor)用於表示設備在以低速(Low Speed),全速(Full Speed)和高速(High Speed)模式運行時,支援USB 2.0 連結電源管理協定(USB 2.0 ECN: Link Power Management (LPM) ) 。
![[Pasted image 20240215133237.png]]
使用USB分析儀抓包可以看到,獲取BOS描述符(BOS Descriptor),而設備功能描述符(Device Capability Descriptor)就包含在其中:

```c
// USB Device Binary Object Store (BOS) Descriptor 中的 Audio Class (UAC)
uint8_t USBD_BosDesc_UAC[] = {
// BOS Descriptor Header
0x05, // bLength: Descriptor size
0x0F, // bDescriptorType: BOS Descriptor Type
0x16, 0x00, // wTotalLength: Total length of BOS Descriptor
// Audio Class Property Section
0x02, // bNumDeviceCaps: Number of capabilities following this descriptor
// Audio Class Specific Device Capability
0x07, // bLength: Descriptor size
0x10, // bDescriptorType: Device Capability Type (USB_DEVICE_CAPABILITY_TYPE)
0x02, // bDevCapabilityType: Capability Type (USB_DEVICE_CAPABILITY_BILLBOARD)
// Audio Class Specific Device Capability
0x06, // bLength: Descriptor size
0x00, // bDescriptorType: Device Capability Type (USB_DEVICE_CAPABILITY_TYPE)
0x00, 0x00, 0x00, 0x0A, // Reserved
// Audio Class Specific Device Capability
0x10, // bLength: Descriptor size
0x03, // bDescriptorType: Device Capability Type (USB_DEVICE_CAPABILITY_TYPE)
0x00, // bDevCapabilityType: Capability Type (UAC2.0_BM_REQ_SET_CUR)
0x0C, 0x00, // bDevCapabilitySubType: Sub-type (UAC2.0_CONTROL_FU)
0x02, // bAttribute: Attribute (UAC2.0_ATTR_ENABLE)
0x04, // bLockDelayUnits: Lock delay units (UAC2.0_UNITS_MS)
0x04, 0x00, // wLockDelay: Lock delay
0x00, // Terminating zero to indicate the end of descriptor array
};
```
https://www.synopsys.com/dw/dwtb.php?a=usb_lpm


進入 L1 的 command
L2 是傳統的 suspend/resume
L3 就斷線 掉電之類
L0 就是正常運作
進入 L0 , L2 跟 L3 不用 command 只有 L0 -> L1 需要
在 Get Device Desc 中有一個 bcdUSB 欄位, 2.0 就是 USB 2.0 最早的規範, 以供電這塊來說, 就是最單純的 suspend/resume, 完全依靠 spec 規定硬體
LPM 是 bcdUSB 2.1 以上才有 把傳統的方式變成有 L0~L3 的區塊
新的 L1, 優點就是可以更快的進入省電模式, 且無須降到 500uA 這類的要求, 只需依照 Device 自身能力盡量節省電力
進入省電的過程也只需要 10us 就可以響應, 無需像傳統每次進入省電前都要花 3ms 以上
