diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs index 07b2a177c..305dfa02e 100644 --- a/embassy-usb/src/builder.rs +++ b/embassy-usb/src/builder.rs @@ -346,7 +346,7 @@ impl<'a, 'd, D: Driver<'d>> FunctionBuilder<'a, 'd, D> { } if !self.builder.msos_descriptor.is_in_function_subset() { - self.builder.msos_descriptor.function(self.first_interface.0); + self.builder.msos_descriptor.function(self.first_interface); } #[cfg(feature = "msos-descriptor")] diff --git a/embassy-usb/src/msos.rs b/embassy-usb/src/msos.rs index 19ed34979..b1e0335ee 100644 --- a/embassy-usb/src/msos.rs +++ b/embassy-usb/src/msos.rs @@ -7,6 +7,7 @@ use core::mem::size_of; use super::{capability_type, BosWriter}; +use crate::types::InterfaceNumber; /// A serialized Microsoft OS 2.0 Descriptor set. /// @@ -125,7 +126,7 @@ impl<'d> MsOsDescriptorWriter<'d> { } /// Add a function subset. - pub fn function(&mut self, first_interface: u8) { + pub fn function(&mut self, first_interface: InterfaceNumber) { assert!( self.config_mark.is_some(), "MsOsDescriptorWriter: function subset requires a configuration subset" @@ -376,14 +377,14 @@ impl DescriptorSet for ConfigurationSubsetHeader { pub struct FunctionSubsetHeader { wLength: u16, wDescriptorType: u16, - bFirstInterface: u8, + bFirstInterface: InterfaceNumber, bReserved: u8, wSubsetLength: u16, } impl FunctionSubsetHeader { /// Creates a function subset header - pub fn new(first_interface: u8) -> Self { + pub fn new(first_interface: InterfaceNumber) -> Self { FunctionSubsetHeader { wLength: (size_of::() as u16).to_le(), wDescriptorType: (Self::TYPE as u16).to_le(), diff --git a/embassy-usb/src/types.rs b/embassy-usb/src/types.rs index 15d195002..c7a47f7e4 100644 --- a/embassy-usb/src/types.rs +++ b/embassy-usb/src/types.rs @@ -3,6 +3,7 @@ /// A handle for a USB interface that contains its number. #[derive(Debug, Copy, Clone, Eq, PartialEq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[repr(transparent)] pub struct InterfaceNumber(pub u8); impl InterfaceNumber { @@ -20,6 +21,7 @@ impl From for u8 { /// A handle for a USB string descriptor that contains its index. #[derive(Copy, Clone, Eq, PartialEq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[repr(transparent)] pub struct StringIndex(pub u8); impl StringIndex { diff --git a/examples/nrf52840/src/bin/usb_serial_winusb.rs b/examples/nrf52840/src/bin/usb_serial_winusb.rs index ade6af527..6561fc3b4 100644 --- a/examples/nrf52840/src/bin/usb_serial_winusb.rs +++ b/examples/nrf52840/src/bin/usb_serial_winusb.rs @@ -12,6 +12,7 @@ use embassy_nrf::{interrupt, pac}; use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; use embassy_usb::driver::EndpointError; use embassy_usb::msos::{self, windows_version}; +use embassy_usb::types::InterfaceNumber; use embassy_usb::{Builder, Config}; use {defmt_rtt as _, panic_probe as _}; @@ -77,7 +78,7 @@ async fn main(_spawner: Spawner) { // Inside a class constructor, you would just need to call `FunctionBuilder::msos_feature` instead. let msos_writer = builder.msos_writer(); msos_writer.configuration(0); - msos_writer.function(0); + msos_writer.function(InterfaceNumber(0)); msos_writer.function_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", "")); msos_writer.function_feature(msos::RegistryPropertyFeatureDescriptor::new( "DeviceInterfaceGUIDs",