diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-02-07 23:45:01 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-02-08 00:30:53 +0100 |
| commit | 86487db5d1773d2a764ab340051d70cfa40e4714 (patch) | |
| tree | d5051ead9e65ea0a51f315a4302c867d07cb2449 | |
| parent | 3af991ab63d14cfad6f50d28bfb944d1895d1c70 (diff) | |
usb: use InterfaceNumber in msos.
| -rw-r--r-- | embassy-usb/src/builder.rs | 2 | ||||
| -rw-r--r-- | embassy-usb/src/msos.rs | 7 | ||||
| -rw-r--r-- | embassy-usb/src/types.rs | 2 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/usb_serial_winusb.rs | 3 |
4 files changed, 9 insertions, 5 deletions
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> { | |||
| 346 | } | 346 | } |
| 347 | 347 | ||
| 348 | if !self.builder.msos_descriptor.is_in_function_subset() { | 348 | if !self.builder.msos_descriptor.is_in_function_subset() { |
| 349 | self.builder.msos_descriptor.function(self.first_interface.0); | 349 | self.builder.msos_descriptor.function(self.first_interface); |
| 350 | } | 350 | } |
| 351 | 351 | ||
| 352 | #[cfg(feature = "msos-descriptor")] | 352 | #[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 @@ | |||
| 7 | use core::mem::size_of; | 7 | use core::mem::size_of; |
| 8 | 8 | ||
| 9 | use super::{capability_type, BosWriter}; | 9 | use super::{capability_type, BosWriter}; |
| 10 | use crate::types::InterfaceNumber; | ||
| 10 | 11 | ||
| 11 | /// A serialized Microsoft OS 2.0 Descriptor set. | 12 | /// A serialized Microsoft OS 2.0 Descriptor set. |
| 12 | /// | 13 | /// |
| @@ -125,7 +126,7 @@ impl<'d> MsOsDescriptorWriter<'d> { | |||
| 125 | } | 126 | } |
| 126 | 127 | ||
| 127 | /// Add a function subset. | 128 | /// Add a function subset. |
| 128 | pub fn function(&mut self, first_interface: u8) { | 129 | pub fn function(&mut self, first_interface: InterfaceNumber) { |
| 129 | assert!( | 130 | assert!( |
| 130 | self.config_mark.is_some(), | 131 | self.config_mark.is_some(), |
| 131 | "MsOsDescriptorWriter: function subset requires a configuration subset" | 132 | "MsOsDescriptorWriter: function subset requires a configuration subset" |
| @@ -376,14 +377,14 @@ impl DescriptorSet for ConfigurationSubsetHeader { | |||
| 376 | pub struct FunctionSubsetHeader { | 377 | pub struct FunctionSubsetHeader { |
| 377 | wLength: u16, | 378 | wLength: u16, |
| 378 | wDescriptorType: u16, | 379 | wDescriptorType: u16, |
| 379 | bFirstInterface: u8, | 380 | bFirstInterface: InterfaceNumber, |
| 380 | bReserved: u8, | 381 | bReserved: u8, |
| 381 | wSubsetLength: u16, | 382 | wSubsetLength: u16, |
| 382 | } | 383 | } |
| 383 | 384 | ||
| 384 | impl FunctionSubsetHeader { | 385 | impl FunctionSubsetHeader { |
| 385 | /// Creates a function subset header | 386 | /// Creates a function subset header |
| 386 | pub fn new(first_interface: u8) -> Self { | 387 | pub fn new(first_interface: InterfaceNumber) -> Self { |
| 387 | FunctionSubsetHeader { | 388 | FunctionSubsetHeader { |
| 388 | wLength: (size_of::<Self>() as u16).to_le(), | 389 | wLength: (size_of::<Self>() as u16).to_le(), |
| 389 | wDescriptorType: (Self::TYPE as u16).to_le(), | 390 | 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 @@ | |||
| 3 | /// A handle for a USB interface that contains its number. | 3 | /// A handle for a USB interface that contains its number. |
| 4 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] | 4 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] |
| 5 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 5 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 6 | #[repr(transparent)] | ||
| 6 | pub struct InterfaceNumber(pub u8); | 7 | pub struct InterfaceNumber(pub u8); |
| 7 | 8 | ||
| 8 | impl InterfaceNumber { | 9 | impl InterfaceNumber { |
| @@ -20,6 +21,7 @@ impl From<InterfaceNumber> for u8 { | |||
| 20 | /// A handle for a USB string descriptor that contains its index. | 21 | /// A handle for a USB string descriptor that contains its index. |
| 21 | #[derive(Copy, Clone, Eq, PartialEq)] | 22 | #[derive(Copy, Clone, Eq, PartialEq)] |
| 22 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 23 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 24 | #[repr(transparent)] | ||
| 23 | pub struct StringIndex(pub u8); | 25 | pub struct StringIndex(pub u8); |
| 24 | 26 | ||
| 25 | impl StringIndex { | 27 | 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}; | |||
| 12 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; | 12 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; |
| 13 | use embassy_usb::driver::EndpointError; | 13 | use embassy_usb::driver::EndpointError; |
| 14 | use embassy_usb::msos::{self, windows_version}; | 14 | use embassy_usb::msos::{self, windows_version}; |
| 15 | use embassy_usb::types::InterfaceNumber; | ||
| 15 | use embassy_usb::{Builder, Config}; | 16 | use embassy_usb::{Builder, Config}; |
| 16 | use {defmt_rtt as _, panic_probe as _}; | 17 | use {defmt_rtt as _, panic_probe as _}; |
| 17 | 18 | ||
| @@ -77,7 +78,7 @@ async fn main(_spawner: Spawner) { | |||
| 77 | // Inside a class constructor, you would just need to call `FunctionBuilder::msos_feature` instead. | 78 | // Inside a class constructor, you would just need to call `FunctionBuilder::msos_feature` instead. |
| 78 | let msos_writer = builder.msos_writer(); | 79 | let msos_writer = builder.msos_writer(); |
| 79 | msos_writer.configuration(0); | 80 | msos_writer.configuration(0); |
| 80 | msos_writer.function(0); | 81 | msos_writer.function(InterfaceNumber(0)); |
| 81 | msos_writer.function_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", "")); | 82 | msos_writer.function_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", "")); |
| 82 | msos_writer.function_feature(msos::RegistryPropertyFeatureDescriptor::new( | 83 | msos_writer.function_feature(msos::RegistryPropertyFeatureDescriptor::new( |
| 83 | "DeviceInterfaceGUIDs", | 84 | "DeviceInterfaceGUIDs", |
