From d0b1819aa52666a4fca37211ddab82b01eea84ce Mon Sep 17 00:00:00 2001 From: sawyer bristol Date: Fri, 29 Nov 2024 20:29:43 -0700 Subject: [PATCH 1/7] custom bcd usb version --- embassy-usb/src/builder.rs | 6 ++++++ embassy-usb/src/descriptor.rs | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs index e1bf8041f..c7d83e710 100644 --- a/embassy-usb/src/builder.rs +++ b/embassy-usb/src/builder.rs @@ -15,6 +15,11 @@ pub struct Config<'a> { pub(crate) vendor_id: u16, pub(crate) product_id: u16, + /// Device BCD USB version. + /// + /// Default: `0x02` ("2.1") + pub bcd_usb: u16, + /// Device class code assigned by USB.org. Set to `0xff` for vendor-specific /// devices that do not conform to any class. /// @@ -108,6 +113,7 @@ impl<'a> Config<'a> { vendor_id: vid, product_id: pid, device_release: 0x0010, + bcd_usb: 0x02, manufacturer: None, product: None, serial_number: None, diff --git a/embassy-usb/src/descriptor.rs b/embassy-usb/src/descriptor.rs index 06ebe0481..8824a0355 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] { 18, // bLength 0x01, // bDescriptorType 0x10, - 0x02, // bcdUSB 2.1 - config.device_class, // bDeviceClass - config.device_sub_class, // bDeviceSubClass - config.device_protocol, // bDeviceProtocol - config.max_packet_size_0, // bMaxPacketSize0 + (config.bcd_usb >> 8) as u8, // bcdUSB + config.device_class, // bDeviceClass + config.device_sub_class, // bDeviceSubClass + config.device_protocol, // bDeviceProtocol + config.max_packet_size_0, // bMaxPacketSize0 config.vendor_id as u8, (config.vendor_id >> 8) as u8, // idVendor config.product_id as u8, @@ -353,13 +353,13 @@ pub(crate) fn device_qualifier_descriptor(config: &Config) -> [u8; 10] { 10, // bLength 0x06, // bDescriptorType 0x10, - 0x02, // bcdUSB 2.1 - config.device_class, // bDeviceClass - config.device_sub_class, // bDeviceSubClass - config.device_protocol, // bDeviceProtocol - config.max_packet_size_0, // bMaxPacketSize0 - 1, // bNumConfigurations - 0, // Reserved + (config.bcd_usb >> 8) as u8, // bcdUSB + config.device_class, // bDeviceClass + config.device_sub_class, // bDeviceSubClass + config.device_protocol, // bDeviceProtocol + config.max_packet_size_0, // bMaxPacketSize0 + 1, // bNumConfigurations + 0, // Reserved ] } From f25830a5b67caad4a89eeed2cd602ac12198f6c5 Mon Sep 17 00:00:00 2001 From: sawyer bristol Date: Mon, 2 Dec 2024 15:44:01 -0700 Subject: [PATCH 2/7] bcd default to 2.1 --- embassy-usb/src/builder.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs index c7d83e710..28a449a9f 100644 --- a/embassy-usb/src/builder.rs +++ b/embassy-usb/src/builder.rs @@ -17,7 +17,7 @@ pub struct Config<'a> { /// Device BCD USB version. /// - /// Default: `0x02` ("2.1") + /// Default: `0x0210` ("2.1") pub bcd_usb: u16, /// Device class code assigned by USB.org. Set to `0xff` for vendor-specific @@ -113,7 +113,7 @@ impl<'a> Config<'a> { vendor_id: vid, product_id: pid, device_release: 0x0010, - bcd_usb: 0x02, + bcd_usb: 0x0210, manufacturer: None, product: None, serial_number: None, From 8068f7092efcc8f42fa2031d3977dcade74981d2 Mon Sep 17 00:00:00 2001 From: sawyer bristol Date: Mon, 2 Dec 2024 15:44:29 -0700 Subject: [PATCH 3/7] fix bug and allow bcd to be .0 --- embassy-usb/src/descriptor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-usb/src/descriptor.rs b/embassy-usb/src/descriptor.rs index 8824a0355..09ce50951 100644 --- a/embassy-usb/src/descriptor.rs +++ b/embassy-usb/src/descriptor.rs @@ -325,7 +325,7 @@ pub(crate) fn device_descriptor(config: &Config) -> [u8; 18] { [ 18, // bLength 0x01, // bDescriptorType - 0x10, + config.bcd_usb as u8, (config.bcd_usb >> 8) as u8, // bcdUSB config.device_class, // bDeviceClass config.device_sub_class, // bDeviceSubClass From 34899491e56db35a1b7e045a7854d10c0ca05457 Mon Sep 17 00:00:00 2001 From: sawyer bristol Date: Mon, 2 Dec 2024 15:57:58 -0700 Subject: [PATCH 4/7] add named bcd versions --- embassy-usb/src/builder.rs | 11 +++++++++-- 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 @@ -7,6 +7,13 @@ use crate::msos::{DeviceLevelDescriptor, FunctionLevelDescriptor, MsOsDescriptor use crate::types::{InterfaceNumber, StringIndex}; use crate::{Handler, Interface, UsbDevice, MAX_INTERFACE_COUNT, STRING_INDEX_CUSTOM_START}; +#[derive(Debug, Copy, Clone)] +/// Allows Configuring the Bcd USB version below 2.1 +pub enum BcdUsbVersion { + Two = 0x0200, + TwoOne = 0x0210, +} + #[derive(Debug, Copy, Clone)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[non_exhaustive] @@ -18,7 +25,7 @@ pub struct Config<'a> { /// Device BCD USB version. /// /// Default: `0x0210` ("2.1") - pub bcd_usb: u16, + pub bcd_usb: BcdUsbVersion, /// Device class code assigned by USB.org. Set to `0xff` for vendor-specific /// devices that do not conform to any class. @@ -113,7 +120,7 @@ impl<'a> Config<'a> { vendor_id: vid, product_id: pid, device_release: 0x0010, - bcd_usb: 0x0210, + bcd_usb: BcdUsbVersion::TwoOne, manufacturer: None, product: None, 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] { 18, // bLength 0x01, // bDescriptorType config.bcd_usb as u8, - (config.bcd_usb >> 8) as u8, // bcdUSB - config.device_class, // bDeviceClass - config.device_sub_class, // bDeviceSubClass - config.device_protocol, // bDeviceProtocol - config.max_packet_size_0, // bMaxPacketSize0 + (config.bcd_usb as u16 >> 8) as u8, // bcdUSB + config.device_class, // bDeviceClass + config.device_sub_class, // bDeviceSubClass + config.device_protocol, // bDeviceProtocol + config.max_packet_size_0, // bMaxPacketSize0 config.vendor_id as u8, (config.vendor_id >> 8) as u8, // idVendor config.product_id as u8, @@ -353,13 +353,13 @@ pub(crate) fn device_qualifier_descriptor(config: &Config) -> [u8; 10] { 10, // bLength 0x06, // bDescriptorType 0x10, - (config.bcd_usb >> 8) as u8, // bcdUSB - config.device_class, // bDeviceClass - config.device_sub_class, // bDeviceSubClass - config.device_protocol, // bDeviceProtocol - config.max_packet_size_0, // bMaxPacketSize0 - 1, // bNumConfigurations - 0, // Reserved + (config.bcd_usb as u16 >> 8) as u8, // bcdUSB + config.device_class, // bDeviceClass + config.device_sub_class, // bDeviceSubClass + config.device_protocol, // bDeviceProtocol + config.max_packet_size_0, // bMaxPacketSize0 + 1, // bNumConfigurations + 0, // Reserved ] } From 4d9ee16f3c25241337a4ec730ed3079f7ded19bc Mon Sep 17 00:00:00 2001 From: sawyer bristol Date: Mon, 2 Dec 2024 15:58:39 -0700 Subject: [PATCH 5/7] fix device_qualifier_descriptor with custom bcd version --- embassy-usb/src/descriptor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-usb/src/descriptor.rs b/embassy-usb/src/descriptor.rs index 51cd2b39a..e9a6fd79a 100644 --- a/embassy-usb/src/descriptor.rs +++ b/embassy-usb/src/descriptor.rs @@ -352,7 +352,7 @@ pub(crate) fn device_qualifier_descriptor(config: &Config) -> [u8; 10] { [ 10, // bLength 0x06, // bDescriptorType - 0x10, + config.bcd_usb as u8, (config.bcd_usb as u16 >> 8) as u8, // bcdUSB config.device_class, // bDeviceClass config.device_sub_class, // bDeviceSubClass From 180d816e00a9575da95682782da25409eb7deb68 Mon Sep 17 00:00:00 2001 From: sawyer bristol Date: Mon, 2 Dec 2024 16:03:38 -0700 Subject: [PATCH 6/7] add fmt --- embassy-usb/src/builder.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs index 8d6d06a6b..9e5aa0574 100644 --- a/embassy-usb/src/builder.rs +++ b/embassy-usb/src/builder.rs @@ -8,6 +8,8 @@ use crate::types::{InterfaceNumber, StringIndex}; use crate::{Handler, Interface, UsbDevice, MAX_INTERFACE_COUNT, STRING_INDEX_CUSTOM_START}; #[derive(Debug, Copy, Clone)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[non_exhaustive] /// Allows Configuring the Bcd USB version below 2.1 pub enum BcdUsbVersion { Two = 0x0200, From fe2c82e98cfe843eeb01196e3fc19fac61b6e6bf Mon Sep 17 00:00:00 2001 From: sawyer bristol Date: Mon, 2 Dec 2024 16:07:10 -0700 Subject: [PATCH 7/7] rename BcdUsbVersion -> UsbVersion --- embassy-usb/src/builder.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs index 9e5aa0574..6c42b07dc 100644 --- a/embassy-usb/src/builder.rs +++ b/embassy-usb/src/builder.rs @@ -11,7 +11,7 @@ use crate::{Handler, Interface, UsbDevice, MAX_INTERFACE_COUNT, STRING_INDEX_CUS #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[non_exhaustive] /// Allows Configuring the Bcd USB version below 2.1 -pub enum BcdUsbVersion { +pub enum UsbVersion { Two = 0x0200, TwoOne = 0x0210, } @@ -27,7 +27,7 @@ pub struct Config<'a> { /// Device BCD USB version. /// /// Default: `0x0210` ("2.1") - pub bcd_usb: BcdUsbVersion, + pub bcd_usb: UsbVersion, /// Device class code assigned by USB.org. Set to `0xff` for vendor-specific /// devices that do not conform to any class. @@ -122,7 +122,7 @@ impl<'a> Config<'a> { vendor_id: vid, product_id: pid, device_release: 0x0010, - bcd_usb: BcdUsbVersion::TwoOne, + bcd_usb: UsbVersion::TwoOne, manufacturer: None, product: None, serial_number: None,