Skip to content

Commit

Permalink
Merge pull request #3599 from LegitCamper/custom_bcdusb_version
Browse files Browse the repository at this point in the history
allow custom bcd usb version
  • Loading branch information
Dirbaio authored Dec 2, 2024
2 parents 3332845 + fe2c82e commit 5fabf7d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
15 changes: 15 additions & 0 deletions embassy-usb/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ 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)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive]
/// Allows Configuring the Bcd USB version below 2.1
pub enum UsbVersion {
Two = 0x0200,
TwoOne = 0x0210,
}

#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive]
Expand All @@ -15,6 +24,11 @@ pub struct Config<'a> {
pub(crate) vendor_id: u16,
pub(crate) product_id: u16,

/// Device BCD USB version.
///
/// Default: `0x0210` ("2.1")
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.
///
Expand Down Expand Up @@ -108,6 +122,7 @@ impl<'a> Config<'a> {
vendor_id: vid,
product_id: pid,
device_release: 0x0010,
bcd_usb: UsbVersion::TwoOne,
manufacturer: None,
product: None,
serial_number: None,
Expand Down
28 changes: 14 additions & 14 deletions embassy-usb/src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,12 @@ 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 as u8,
(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,
Expand All @@ -352,14 +352,14 @@ 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 as u8,
(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
]
}

Expand Down

0 comments on commit 5fabf7d

Please sign in to comment.