diff options
| author | sawyer bristol <[email protected]> | 2024-12-02 15:57:58 -0700 |
|---|---|---|
| committer | sawyer bristol <[email protected]> | 2024-12-02 15:57:58 -0700 |
| commit | 34899491e56db35a1b7e045a7854d10c0ca05457 (patch) | |
| tree | 3d90bd84edfe38f597af5162cbe747219da2a066 /embassy-usb | |
| parent | 8068f7092efcc8f42fa2031d3977dcade74981d2 (diff) | |
add named bcd versions
Diffstat (limited to 'embassy-usb')
| -rw-r--r-- | embassy-usb/src/builder.rs | 11 | ||||
| -rw-r--r-- | embassy-usb/src/descriptor.rs | 24 |
2 files changed, 21 insertions, 14 deletions
diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs index 28a449a9f..8d6d06a6b 100644 --- a/embassy-usb/src/builder.rs +++ b/embassy-usb/src/builder.rs | |||
| @@ -8,6 +8,13 @@ use crate::types::{InterfaceNumber, StringIndex}; | |||
| 8 | use crate::{Handler, Interface, UsbDevice, MAX_INTERFACE_COUNT, STRING_INDEX_CUSTOM_START}; | 8 | use crate::{Handler, Interface, UsbDevice, MAX_INTERFACE_COUNT, STRING_INDEX_CUSTOM_START}; |
| 9 | 9 | ||
| 10 | #[derive(Debug, Copy, Clone)] | 10 | #[derive(Debug, Copy, Clone)] |
| 11 | /// Allows Configuring the Bcd USB version below 2.1 | ||
| 12 | pub enum BcdUsbVersion { | ||
| 13 | Two = 0x0200, | ||
| 14 | TwoOne = 0x0210, | ||
| 15 | } | ||
| 16 | |||
| 17 | #[derive(Debug, Copy, Clone)] | ||
| 11 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 18 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 12 | #[non_exhaustive] | 19 | #[non_exhaustive] |
| 13 | /// Configuration used when creating [`UsbDevice`]. | 20 | /// Configuration used when creating [`UsbDevice`]. |
| @@ -18,7 +25,7 @@ pub struct Config<'a> { | |||
| 18 | /// Device BCD USB version. | 25 | /// Device BCD USB version. |
| 19 | /// | 26 | /// |
| 20 | /// Default: `0x0210` ("2.1") | 27 | /// Default: `0x0210` ("2.1") |
| 21 | pub bcd_usb: u16, | 28 | pub bcd_usb: BcdUsbVersion, |
| 22 | 29 | ||
| 23 | /// Device class code assigned by USB.org. Set to `0xff` for vendor-specific | 30 | /// Device class code assigned by USB.org. Set to `0xff` for vendor-specific |
| 24 | /// devices that do not conform to any class. | 31 | /// devices that do not conform to any class. |
| @@ -113,7 +120,7 @@ impl<'a> Config<'a> { | |||
| 113 | vendor_id: vid, | 120 | vendor_id: vid, |
| 114 | product_id: pid, | 121 | product_id: pid, |
| 115 | device_release: 0x0010, | 122 | device_release: 0x0010, |
| 116 | bcd_usb: 0x0210, | 123 | bcd_usb: BcdUsbVersion::TwoOne, |
| 117 | manufacturer: None, | 124 | manufacturer: None, |
| 118 | product: None, | 125 | product: None, |
| 119 | serial_number: None, | 126 | serial_number: None, |
diff --git a/embassy-usb/src/descriptor.rs b/embassy-usb/src/descriptor.rs index 09ce50951..51cd2b39a 100644 --- a/embassy-usb/src/descriptor.rs +++ b/embassy-usb/src/descriptor.rs | |||
| @@ -326,11 +326,11 @@ pub(crate) fn device_descriptor(config: &Config) -> [u8; 18] { | |||
| 326 | 18, // bLength | 326 | 18, // bLength |
| 327 | 0x01, // bDescriptorType | 327 | 0x01, // bDescriptorType |
| 328 | config.bcd_usb as u8, | 328 | config.bcd_usb as u8, |
| 329 | (config.bcd_usb >> 8) as u8, // bcdUSB | 329 | (config.bcd_usb as u16 >> 8) as u8, // bcdUSB |
| 330 | config.device_class, // bDeviceClass | 330 | config.device_class, // bDeviceClass |
| 331 | config.device_sub_class, // bDeviceSubClass | 331 | config.device_sub_class, // bDeviceSubClass |
| 332 | config.device_protocol, // bDeviceProtocol | 332 | config.device_protocol, // bDeviceProtocol |
| 333 | config.max_packet_size_0, // bMaxPacketSize0 | 333 | config.max_packet_size_0, // bMaxPacketSize0 |
| 334 | config.vendor_id as u8, | 334 | config.vendor_id as u8, |
| 335 | (config.vendor_id >> 8) as u8, // idVendor | 335 | (config.vendor_id >> 8) as u8, // idVendor |
| 336 | config.product_id as u8, | 336 | config.product_id as u8, |
| @@ -353,13 +353,13 @@ pub(crate) fn device_qualifier_descriptor(config: &Config) -> [u8; 10] { | |||
| 353 | 10, // bLength | 353 | 10, // bLength |
| 354 | 0x06, // bDescriptorType | 354 | 0x06, // bDescriptorType |
| 355 | 0x10, | 355 | 0x10, |
| 356 | (config.bcd_usb >> 8) as u8, // bcdUSB | 356 | (config.bcd_usb as u16 >> 8) as u8, // bcdUSB |
| 357 | config.device_class, // bDeviceClass | 357 | config.device_class, // bDeviceClass |
| 358 | config.device_sub_class, // bDeviceSubClass | 358 | config.device_sub_class, // bDeviceSubClass |
| 359 | config.device_protocol, // bDeviceProtocol | 359 | config.device_protocol, // bDeviceProtocol |
| 360 | config.max_packet_size_0, // bMaxPacketSize0 | 360 | config.max_packet_size_0, // bMaxPacketSize0 |
| 361 | 1, // bNumConfigurations | 361 | 1, // bNumConfigurations |
| 362 | 0, // Reserved | 362 | 0, // Reserved |
| 363 | ] | 363 | ] |
| 364 | } | 364 | } |
| 365 | 365 | ||
