add named bcd versions

This commit is contained in:
sawyer bristol 2024-12-02 15:57:58 -07:00
parent 8068f7092e
commit 34899491e5
2 changed files with 21 additions and 14 deletions

View File

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

View File

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