Merge pull request #3599 from LegitCamper/custom_bcdusb_version

allow custom bcd usb version
This commit is contained in:
Dario Nieuwenhuis 2024-12-02 23:13:31 +00:00 committed by GitHub
commit 5fabf7d462
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 14 deletions

View File

@ -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]
@ -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.
///
@ -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,

View File

@ -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,
@ -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
]
}