2024年11月26日 星期二

USB Device Descriptor

Device Descriptor 

 The USB control transfer command you provided appears to be requesting the Device Descriptor from a USB device. Here's a breakdown of the request:


USB Control Transfer Fields

Command:

CTL 80 06 00 01 00 00 12 00

Field Name Value Explanation
bmRequestType 80 0b10000000: Direction = IN (Device-to-Host), Type = Standard, Recipient = Device.
bRequest 06 GET_DESCRIPTOR: Request to retrieve a descriptor.
wValue 00 01 Descriptor Type = 0x01 (Device Descriptor), Index = 0x00.
wIndex 00 00 Index or language ID. Here, 0x0000 means the default language or no index.
wLength 12 00 Length = 0x0012 (18 bytes), which is the size of a USB Device Descriptor.

Interpretation

This control transfer is a Get Descriptor request to retrieve the Device Descriptor from the USB device. The Device Descriptor provides general information about the USB device, such as vendor ID, product ID, device class, and supported USB version.


Expected Response

The device should return an 18-byte Device Descriptor. The structure of the Device Descriptor is as follows:

Byte Offset Field Size (Bytes) Example Value Description
0 bLength 1 18 (0x12) Descriptor length (18 bytes).
1 bDescriptorType 1 01 Descriptor type (Device).
2-3 bcdUSB 2 0x0200 USB version (e.g., 2.0).
4 bDeviceClass 1 00 Device class (e.g., 0 = per interface).
5 bDeviceSubClass 1 00 Subclass (e.g., 0 = none).
6 bDeviceProtocol 1 00 Protocol (e.g., 0 = none).
7 bMaxPacketSize0 1 64 Max packet size for endpoint 0.
8-9 idVendor 2 0xXXXX Vendor ID assigned by USB-IF.
10-11 idProduct 2 0xXXXX Product ID assigned by the vendor.
12-13 bcdDevice 2 0xYYYY Device release number.
14 iManufacturer 1 01 Index of manufacturer string.
15 iProduct 1 02 Index of product string.
16 iSerialNumber 1 03 Index of serial number string.
17 bNumConfigurations 1 01 Number of configurations.

Command Context

This is often the first request issued by a USB host when enumerating a device. It helps the host identify the device and determine the next steps in initialization (e.g., requesting configuration or string descriptors).

If you'd like further help with parsing the response or issuing this command in a program, let me know!

The bDescriptorType field in USB descriptors identifies the type of descriptor being referenced. It is a single byte in the descriptor that helps the host know what kind of data the descriptor contains.


Common Descriptor Types (bDescriptorType)

Value (Hex) Descriptor Type Description
01 Device Contains general information about the device (e.g., USB version, vendor ID).
02 Configuration Contains details about a specific configuration, including power requirements.
03 String Holds human-readable information such as manufacturer or product name (Unicode).
04 Interface Describes the interfaces supported by the device (e.g., HID, audio, etc.).
05 Endpoint Describes an endpoint's attributes (e.g., direction, type, maximum packet size).
21 HID Contains HID-specific information, such as version and descriptor links.
22 HID Report Contains a detailed structure of input, output, and feature reports for HID devices.
23 HID Physical (Optional) Describes the physical properties of the HID device (e.g., button layout).
29 Hub Contains information about a hub device and its ports.

Where bDescriptorType Appears

  1. In the Request (Get Descriptor):

    • The Descriptor Type is specified in the high byte of the wValue field.
    • For example:
      • wValue = 0x0100: Requesting the Device Descriptor.
      • wValue = 0x2200: Requesting the HID Report Descriptor.
  2. In the Descriptor Itself:

    • Each descriptor includes its own bDescriptorType field, which identifies the descriptor's type.

Example in a Device Descriptor

For a typical Device Descriptor:

Byte Offset Field Value (Hex) Description
0 bLength 12 Descriptor length (18 bytes).
1 bDescriptorType 01 Device Descriptor.

In Summary

The bDescriptorType is a key field that tells the host what kind of descriptor is being processed. The value depends on the context of the descriptor or the type requested. If you need more help identifying or using a specific bDescriptorType, feel free to ask!


bcdUSB

Yes, the bcdUSB field in the Device Descriptor indicates the USB specification version that the device supports. This field is a 16-bit value encoded in Binary-Coded Decimal (BCD) format.


How to Interpret bcdUSB

  • Format: 0xMMmm (BCD)
    • MM: Major version number
    • mm: Minor version number
  • For example:
    • 0x0200 = USB version 2.0
    • 0x0110 = USB version 1.1
    • 0x0300 = USB version 3.0
    • 0x0310 = USB version 3.1
    • 0x0320 = USB version 3.2

Why bcdUSB is Important

  • This field informs the USB host (e.g., computer, hub) about the highest USB specification the device supports.
  • It determines which features and speeds the device can use, such as:
    • USB 1.x: Low-speed (1.5 Mbps) or Full-speed (12 Mbps).
    • USB 2.0: High-speed (480 Mbps).
    • USB 3.x: SuperSpeed (5 Gbps or higher, depending on the sub-version).

Example Scenario

If a USB host queries a device and receives bcdUSB = 0x0200 in the Device Descriptor:

  • The device is compliant with USB 2.0.
  • The host can enable USB 2.0 features like high-speed transfers.

Let me know if you need further details!


bDeviceClass

The bDeviceClass field in the USB Device Descriptor specifies the class of the device. This helps the host system identify the device type and determine which driver to use. The value can indicate a specific class or a generic "classless" device, where the class is determined by the interfaces it contains.


Details of bDeviceClass

  • Size: 1 byte
  • Location: Byte 4 of the Device Descriptor
  • Purpose: Defines the primary functionality or category of the device.

Key Values for bDeviceClass

Value (Hex) Device Class Description
00 Defined by Interface The device does not specify a class at the device level. Class is defined by its interfaces.
01 Audio Audio devices (e.g., speakers, microphones).
02 Communications Communication devices (e.g., modems, network adapters).
03 HID Human Interface Devices (e.g., keyboards, mice, game controllers).
05 Physical Physical devices (e.g., force-feedback devices).
06 Image Imaging devices (e.g., scanners, cameras).
07 Printer Printers.
08 Mass Storage Storage devices (e.g., USB flash drives, external hard drives).
09 Hub USB hubs.
0A CDC-Data Data devices used with the Communications Device Class.
0B Smart Card Smart card readers.
0D Content Security Content protection devices.
0E Video Video devices (e.g., webcams).
0F Personal Healthcare Healthcare devices (e.g., thermometers, blood pressure monitors).
10 Audio/Video Multimedia devices (e.g., media players).
DC Diagnostic Device Diagnostic tools.
E0 Wireless Controller Wireless devices (e.g., Bluetooth controllers).
EF Miscellaneous Devices that do not fit into other classes.
FF Vendor-Specific The device class is vendor-defined, requiring custom drivers.

Special Cases

  1. bDeviceClass = 0x00 (Defined by Interface):

    • The device relies on its interfaces to define functionality.
    • Each interface will have its own bInterfaceClass.
  2. bDeviceClass = 0xFF (Vendor-Specific):

    • The device implements a proprietary protocol.
    • Requires a custom driver provided by the manufacturer.

How bDeviceClass Works with bDeviceSubClass and bDeviceProtocol

  • bDeviceClass: General category of the device.
  • bDeviceSubClass: Subcategory within the class (specific to the bDeviceClass).
  • bDeviceProtocol: Protocol within the subclass (specific to bDeviceClass and bDeviceSubClass).

For example:

  • A Mass Storage device (bDeviceClass = 08) with a subClass of SCSI transparent command set (bDeviceSubClass = 06) and a protocol of Bulk-Only Transport (bDeviceProtocol = 50).

Example: Retrieving bDeviceClass

When you fetch the Device Descriptor, the bDeviceClass field is at offset 4:

Byte Offset Field Value Description
4 bDeviceClass 08 Mass Storage Device.

If you’re working with a USB device and want to parse its descriptors, let me know—I can assist further!


idVendor    ==> VID
idProduct  --> PID

bcdDevice Device revision (e.g., 2.01).

iManufacturer Index of manufacturer string.
iProduct Index of product string. 
iSerialNumber Index of serial number string.
bNumConfigurations Number of configurations. 

USB vendor command

 在 USB 通訊中,Vendor Commands (Vendor-Specific Requests) 是為特定裝置設計的指令,並不屬於 USB 標準規範,而是由廠商自定義的操作方式。這些命令通常用於設備的特殊功能,例如設定裝置參數、更新韌體、或執行自訂功能。

以下是 Vendor Command 的範例與解析:


Vendor Command 格式

Vendor Command 通常透過 Control Transfer 傳送,結構如下:

Field Name Size (Bytes) Description
bmRequestType 1 指定方向、類型(Vendor-Specific),以及接收者(Device/Interface/Endpoint)。
bRequest 1 請求代碼,由廠商自定義,例如 0x010xA0
wValue 2 附加數據,通常用於傳遞參數。
wIndex 2 附加數據,可能代表特定端點或功能。
wLength 2 數據傳輸長度(IN 或 OUT)。
Data Variable 傳輸的實際數據(可選)。

Vendor Command 例子 1: 設置設備參數

假設某裝置支持設定亮度的 Vendor Command:

Field Name Example Value Description
bmRequestType 0x40 Host-to-Device, Vendor-Specific, Device
bRequest 0x01 Vendor Command: Set Brightness
wValue 0x0064 Brightness level (e.g., 100)
wIndex 0x0000 Unused
wLength 0x0000 No data phase

Control Transfer (Setup Stage):

40 01 64 00 00 00 00 00

設備會執行亮度設定為 100。


Vendor Command 例子 2: 韌體版本查詢

假設某設備提供查詢韌體版本的 Vendor Command:

Field Name Example Value Description
bmRequestType 0xC0 Device-to-Host, Vendor-Specific, Device
bRequest 0xA0 Vendor Command: Get Firmware Version
wValue 0x0000 Unused
wIndex 0x0000 Unused
wLength 0x0004 Expect 4 bytes of data

Control Transfer (Setup Stage):

C0 A0 00 00 00 00 04 00

Expected Response (Data Stage):

01 00 02 00

解析:

  • 韌體版本:0x0002.0001

Vendor Command 例子 3: 設備重啟

假設某設備支持重啟的 Vendor Command:

Field Name Example Value Description
bmRequestType 0x40 Host-to-Device, Vendor-Specific, Device
bRequest 0x02 Vendor Command: Reboot Device
wValue 0x0000 Unused
wIndex 0x0000 Unused
wLength 0x0000 No data phase

Control Transfer (Setup Stage):

40 02 00 00 00 00 00 00

設備收到指令後立即重啟。


實作工具

  1. 使用 libusb:

    // Example: Sending a vendor-specific command to set brightness
    uint8_t bmRequestType = 0x40;  // Host-to-Device, Vendor-Specific, Device
    uint8_t bRequest = 0x01;       // Set Brightness Command
    uint16_t wValue = 100;         // Brightness level
    uint16_t wIndex = 0x0000;      // Unused
    uint16_t wLength = 0x0000;     // No data phase
    unsigned char *data = NULL;
    int timeout = 1000;
    
    libusb_control_transfer(handle, bmRequestType, bRequest, wValue, wIndex, data, wLength, timeout);
    
  2. 工具如 USBLyzer 或 Wireshark:

    • 可監控 USB 通訊以反向工程 Vendor Commands。

注意事項

  1. 文檔參考:Vendor Command 的定義通常在裝置的技術文檔中提供。
  2. 安全性:避免對未知裝置執行 Vendor Commands,以免導致不可逆的損壞。
  3. 錯誤處理:對不支援的命令,設備通常會回應 STALL

如果你有特定設備或命令需要協助分析,請提供更多細節!

2024年11月19日 星期二

command prompt set sound volume


nircmd https://www.nirsoft.net/utils/sound_volume_view.html


Command line example:

設置 耳機音量 30% 的方式


SoundVolumeView.exe /SetVolume "{0.0.0.00000000}.{eafc99e3-1c45-4027-b923-4ee4c2284cd5}" 30

由於device name 裡面有繁體字 建議最好用 Item ID 來描述. 否則 bat 檔案裡面會有不完整的亂碼

設置某個device as default   可以直接按鼠標右鍵  產生 


也可以做一個捷徑 :

再去看 捷徑裡面的指令 
D:\inst\NirSoft\SoundVolumeView\SoundVolumeView.exe /SetDefault "Realtek(R) Audio\Device\耳機\Render" 1
進去將device name(有中文不好) 改為  Item ID 

Other example:

Here's some examples:

  • SoundVolumeView.exe /GetPercent "Speakers"
  • SoundVolumeView.exe /GetPercentChannel "Speakers" 0
  • SoundVolumeView.exe /GetMute "Speakers"
  • SoundVolumeView.exe /SetVolume "{0.0.0.00000000}.{a77a09b2-1ec6-49c3-860a-68945904a2f1}" 15
  • SoundVolumeView.exe /SetVolume "Speakers" 22.5
  • SoundVolumeView.exe /SetVolume "High Definition Audio Device\Device\Speakers" 50
  • SoundVolumeView.exe /SetVolume "USB*\Device\Speakers\Render" 70 /SetVolume "High Definition Audio Device\Device\Speakers" 35
  • SoundVolumeView.exe /SetVolume AllAppVolume 100
  • SoundVolumeView.exe /SetVolumeDecibel "Speakers" -11
  • SoundVolumeView.exe /ChangeVolume "Front Green In" -10
  • SoundVolumeView.exe /ChangeVolume "{2}.\\?\hdaudio#func_01&ven_10ec&dev_0889&subsys_1458a002&rev_1000#4&3828eb94&0&0201#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\singlelineouttopo/0002000c&" 5
  • SoundVolumeView.exe /ChangeVolumeChannel "vlc.exe" 0 -20
  • SoundVolumeView.exe /Mute "singlelineouttopo/0002000c&"
  • SoundVolumeView.exe /Mute "DefaultRenderDevice"
  • SoundVolumeView.exe /Mute "System Sounds"
  • SoundVolumeView.exe /SetVolumeChannels "Front Pink In" 45 55
  • SoundVolumeView.exe /SetVolumeChannels "Front" * 60 * 40
  • SoundVolumeView.exe /SetVolumeDecibel "Microphone Boost" 20
  • SoundVolumeView.exe /ChangeVolumeDecibel "Microphone Boost" 10
  • SoundVolumeView.exe /Mute "Firefox.exe"
  • SoundVolumeView.exe /Mute "Firefox.exe" /WaitForItem 3600
  • SoundVolumeView.exe /SetVolume "chrome.exe" 75
  • SoundVolumeView.exe /SetVolumeChannels "chrome.exe" 50 100
  • SoundVolumeView.exe /Unmute "VLC media player"
  • SoundVolumeView.exe /Switch "C:\Program Files\Firefox.exe"
  • SoundVolumeView.exe /Switch 3217
  • SoundVolumeView.exe /Switch Focused
  • SoundVolumeView.exe /Switch FocusedName
  • SoundVolumeView.exe /Switch "Realtek High Definition Audio\Device\Speakers"
  • SoundVolumeView.exe /DisableEnable Speakers
  • SoundVolumeView.exe /SetDefault "{0.0.0.00000000}.{a77a09b2-1ec6-49c3-860a-68945904a2f1}" 0
  • SoundVolumeView.exe /SetDefault "{0.0.0.00000000}.{a77a09b2-1ec6-49c3-860a-68945904a2f1}" all
  • SoundVolumeView.exe /SetDefault "DENON-AVAMP" 1
  • SoundVolumeView.exe /SwitchDefault "{0.0.0.00000000}.{a77a09b2-1ec6-49c3-860a-68945904a2f1}" "{0.0.0.00000000}.{7747b192-73b2-47d3-a2c0-168e94af7f9e}" all
  • SoundVolumeView.exe /SetAppDefault "{0.0.0.00000000}.{a77a09b2-1ec6-49c3-860a-68945904a2f1}" all "myapp.exe"
  • SoundVolumeView.exe /SetAppDefault DefaultCaptureDevice 1 1952
  • SoundVolumeView.exe /SaveProfile "C:\Temp\Profile1.spr"
  • SoundVolumeView.exe /LoadProfile "C:\Temp\Profile2.spr"

You can also use the following command-line parameters to export the list of all sound items info a file:

2024年11月5日 星期二

Suno 創作 抖音一響. 父母白養

ChatGPT 

寫一首 英文押韻的 歌詞 .  描述  TikTok ringing, Parents crying.   抖音影響青少年的身心發展. 共 30 句


Verse 1
TikTok ringing, kids all glued,
Scrolling fast, their moods subdued.
Parents crying, eyes so wide,
Wondering where their children hide.
Chorus
In endless loops, they’re losing track,
Can’t pull away, there’s no way back.
Bright screens shine like neon lights,
Stealing hours, stealing nights.
Verse 2
Fifteen seconds, then it’s gone,
Chasing trends till dawn to dawn.
Mind and heart in tangled chains,
Swayed by strangers, likes, and gains.
Chorus
In endless loops, they’re losing track,
Can’t pull away, there’s no way back.
Bright screens shine like neon lights,
Stealing hours, stealing nights.
Bridge
Filters flash, ideals skewed,
Every flaw exposed and viewed.
Faces framed, reality blurred,
Confidence shaken, self-worth deferred.
Verse 3
Parental pleas, unheard cries,
As teenage hearts and spirit dies.
Can’t they see the harm it brings?
Trading truth for viral things.
Chorus
In endless loops, they’re losing track,
Can’t pull away, there’s no way back.
Bright screens shine like neon lights,
Stealing hours, stealing nights.
Outro
TikTok ringing, lives on display,
Teens lost in shadows, night and day.
Silent screams, the truth is plain,
When will they break free of this chain?


ChatGPT

翻譯成中文 也需要押韻


抖音一響. 父母白養
Verse 1
抖音響起,孩子黏,
滑著螢幕情緒淡。
父母哭喊淚滿面,
不知孩子藏哪邊。
Chorus
無盡循環沒盡頭,
拉不回,無處逃。
螢幕亮如霓虹燈,
偷走夜,偷走夢。
Verse 2
十五秒,瞬間過,
追逐熱潮到日破。
心與意念被束縛,
陌生人操控進度。
Chorus
無盡循環沒盡頭,
拉不回,無處逃。
螢幕亮如霓虹燈,
偷走夜,偷走夢。
Bridge
濾鏡閃爍,理想偏,
缺點暴露眾人前。
面容框住真模樣,
信心搖擺,自尊殘。
Verse 3
父母呼喊無人聽,
青少年心靈凋零。
看不清傷害深,
為了熱潮賣真心。
Chorus
無盡循環沒盡頭,
拉不回,無處逃。
螢幕亮如霓虹燈,
偷走夜,偷走夢。
Outro
抖音響起,人生秀,
青春沉迷影裡遊。
無聲尖叫真相現,
何時掙脫這枷鎖?


翻譯成簡體中文: ( 以防止Suno 唱出粵語)

簡體中文:
抖音一响. 父母白养
Verse 1
抖音响起,孩子黏,
滑着荧幕情绪淡。
父母哭喊泪满面,
不知孩子藏哪边。
Chorus
无尽循环没尽头,
拉不回,无处逃。
荧幕亮如霓虹灯,
偷走夜,偷走梦。
Verse 2
十五秒,瞬间过,
追逐热潮到日破。
心与意念被束缚,
陌生人操控进度。
Chorus
无尽循环没尽头,
拉不回,无处逃。
荧幕亮如霓虹灯,
偷走夜,偷走梦。
Bridge
滤镜闪铄,理想偏,
缺点暴露众人前。
面容框住真模样,
信心摇摆,自尊残。
Verse 3
父母呼喊无人听,
青少年心灵凋灵。
看不清伤害深,
为了热潮卖真心。
Chorus
无尽循环没尽头,
拉不回,无处逃。
荧幕亮如霓虹灯,
偷走夜,偷走梦。
Outro
抖音响起,人生秀,
青春沉迷影里游。
无声尖叫真相现,
何时挣脱这枷锁?
music style
electric violin,  modern violin,  electric dance music,  dubstep,  adult female voice,  


最後逐字修飾


抖音一响. 父母白养
Verse 1
抖音一响,父母惊,
滑着荧幕,杀时间。
父母哭喊,泪满面,
不知孩子,藏哪边。
Chorus
无尽循环没尽头,
拉不回,无处逃。
荧幕亮如霓虹灯,
脑残加上熊猫眼。
Verse 2
十五秒,瞬间过,
追逐热潮到日破。
心与意念被约束,
资本家操控进度。
Chorus
无尽循环没尽头,
拉不回,无处逃。
荧幕亮如霓虹灯,
脑残加上熊猫眼。
Bridge
滤镜闪铄,理想偏,
缺点暴露众人前。
浓妆框住真面目,
信心动摇,自尊无。
Verse 3
父母呼喊无人听,
青少年心灵凋灵。
看不清伤害深,
为了热潮卖真心。
Chorus
无尽循环没尽头,
拉不回,无处逃。
荧幕亮如霓虹灯,
脑残加上熊猫眼。
Outro
抖音一响,父母惊,
青春沉迷,虚拟境。
了无自我,难翻天,
何时挣脱,此局面?


music style

electric violin,  modern violin,  electric dance music,  dubstep,  adult female voice,  


好聽的 Suno 創作結果 在這



2024年11月4日 星期一

AI 應用

Stable Diffusion



Music AI: Suno

ChatGPT

7言詩 共20句 描述 美麗和諧的世界需要大家維護

山川靈秀映青天,
日月交輝照四邊。
碧水悠悠千古韻,
繁花似錦萬家歡。

風和日麗心境暖,
鳥語花香人世安。
勞耕共作田間舞,
鄰里相助歲歲繁。

和睦相處無爭怨,
恩愛常留若清泉。
滿園花開無怨色,
同舟共濟此心堅。

仁義之道千年立,
以愛為根樹永年。
萬國齊聲頌和平,
同心協力護家園。

河清海晏民生樂,
世代繁榮無苦寒。
珍惜當下須共護,
萬紫千紅永相伴。

人類心手相牽緊,
共築一方樂土間。
願將美景傳萬代,
維護和諧永世安。

轉簡中

山川灵秀映青天,日月交辉照四边。

碧水悠悠千古韵,繁花似锦万家欢。

风和日丽心境暖,鸟语花香人世安。

劳耕共作田间舞,邻里相助岁岁繁。

和睦相处无争怨,恩爱常留若清泉。

满园花开无怨色,同舟共济此心坚。

仁义之道千年立,以爱为根树永年。

万国齐声颂和平,同心协力护家园。

河清海晏民生乐,世代繁荣无苦寒。

珍惜当下须共护,万紫千红永相伴。

人类心手相牵紧,共筑一方乐土间。

愿将美景传万代,维护和谐永世安。

country rock, 140bpm,

title: 美麗新世界


chatGPT translate to English

Mountains rise high, serene and grand,
Sun and moon light up the land.
Waters flow with timeless grace,
Blossoms bloom in every place.

Gentle breeze and sunlight sweet,
Birds and flowers our joy complete.
Hand in hand, the fields we tend,
Neighbors help, year after end.

In peace and love, we live as one,
Like a stream, pure love runs on.
Gardens thrive without a tear,
Strong together, hearts sincere.

Virtue stands through ages past,
With roots of love, it ever lasts.
Nations sing in praise of peace,
Joined in strength, our care won’t cease.

Rivers clear and seas at rest,
People’s lives in joy are blessed.
Cherish now, protect this land,
In blooming hues, let beauty stand.

Hands united, hearts entwined,
Building joy for humankind.
Let this beauty live on bright,
In harmony, forever right.




CAN FD