diff options
| -rw-r--r-- | embassy-usb/src/builder.rs | 15 | ||||
| -rw-r--r-- | embassy-usb/src/descriptor.rs | 28 |
2 files changed, 29 insertions, 14 deletions
diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs index e1bf8041f..6c42b07dc 100644 --- a/embassy-usb/src/builder.rs +++ b/embassy-usb/src/builder.rs | |||
| @@ -10,11 +10,25 @@ use crate::{Handler, Interface, UsbDevice, MAX_INTERFACE_COUNT, STRING_INDEX_CUS | |||
| 10 | #[derive(Debug, Copy, Clone)] | 10 | #[derive(Debug, Copy, Clone)] |
| 11 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 11 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 12 | #[non_exhaustive] | 12 | #[non_exhaustive] |
| 13 | /// Allows Configuring the Bcd USB version below 2.1 | ||
| 14 | pub enum UsbVersion { | ||
| 15 | Two = 0x0200, | ||
| 16 | TwoOne = 0x0210, | ||
| 17 | } | ||
| 18 | |||
| 19 | #[derive(Debug, Copy, Clone)] | ||
| 20 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 21 | #[non_exhaustive] | ||
| 13 | /// Configuration used when creating [`UsbDevice`]. | 22 | /// Configuration used when creating [`UsbDevice`]. |
| 14 | pub struct Config<'a> { | 23 | pub struct Config<'a> { |
| 15 | pub(crate) vendor_id: u16, | 24 | pub(crate) vendor_id: u16, |
| 16 | pub(crate) product_id: u16, | 25 | pub(crate) product_id: u16, |
| 17 | 26 | ||
| 27 | /// Device BCD USB version. | ||
| 28 | /// | ||
| 29 | /// Default: `0x0210` ("2.1") | ||
| 30 | pub bcd_usb: UsbVersion, | ||
| 31 | |||
| 18 | /// Device class code assigned by USB.org. Set to `0xff` for vendor-specific | 32 | /// Device class code assigned by USB.org. Set to `0xff` for vendor-specific |
| 19 | /// devices that do not conform to any class. | 33 | /// devices that do not conform to any class. |
| 20 | /// | 34 | /// |
| @@ -108,6 +122,7 @@ impl<'a> Config<'a> { | |||
| 108 | vendor_id: vid, | 122 | vendor_id: vid, |
| 109 | product_id: pid, | 123 | product_id: pid, |
| 110 | device_release: 0x0010, | 124 | device_release: 0x0010, |
| 125 | bcd_usb: UsbVersion::TwoOne, | ||
| 111 | manufacturer: None, | 126 | manufacturer: None, |
| 112 | product: None, | 127 | product: None, |
| 113 | serial_number: None, | 128 | serial_number: None, |
diff --git a/embassy-usb/src/descriptor.rs b/embassy-usb/src/descriptor.rs index 06ebe0481..e9a6fd79a 100644 --- a/embassy-usb/src/descriptor.rs +++ b/embassy-usb/src/descriptor.rs | |||
| @@ -325,12 +325,12 @@ pub(crate) fn device_descriptor(config: &Config) -> [u8; 18] { | |||
| 325 | [ | 325 | [ |
| 326 | 18, // bLength | 326 | 18, // bLength |
| 327 | 0x01, // bDescriptorType | 327 | 0x01, // bDescriptorType |
| 328 | 0x10, | 328 | config.bcd_usb as u8, |
| 329 | 0x02, // bcdUSB 2.1 | 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, |
| @@ -352,14 +352,14 @@ pub(crate) fn device_qualifier_descriptor(config: &Config) -> [u8; 10] { | |||
| 352 | [ | 352 | [ |
| 353 | 10, // bLength | 353 | 10, // bLength |
| 354 | 0x06, // bDescriptorType | 354 | 0x06, // bDescriptorType |
| 355 | 0x10, | 355 | config.bcd_usb as u8, |
| 356 | 0x02, // bcdUSB 2.1 | 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 | ||
