diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-06-12 22:15:44 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-06-12 22:22:31 +0200 |
| commit | a8703b75988e1e700af701116464025679d2feb8 (patch) | |
| tree | f4ec5de70ec05e793a774049e010935ac45853ed /embassy-usb/src/builder.rs | |
| parent | 6199bdea710cde33e5d5381b6d6abfc8af46df19 (diff) | |
Run rustfmt.
Diffstat (limited to 'embassy-usb/src/builder.rs')
| -rw-r--r-- | embassy-usb/src/builder.rs | 54 |
1 files changed, 11 insertions, 43 deletions
diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs index 09904949f..1ca24cc08 100644 --- a/embassy-usb/src/builder.rs +++ b/embassy-usb/src/builder.rs | |||
| @@ -1,14 +1,11 @@ | |||
| 1 | use heapless::Vec; | 1 | use heapless::Vec; |
| 2 | 2 | ||
| 3 | use crate::{Interface, STRING_INDEX_CUSTOM_START}; | ||
| 4 | |||
| 5 | use super::control::ControlHandler; | 3 | use super::control::ControlHandler; |
| 6 | use super::descriptor::{BosWriter, DescriptorWriter}; | 4 | use super::descriptor::{BosWriter, DescriptorWriter}; |
| 7 | use super::driver::{Driver, Endpoint}; | 5 | use super::driver::{Driver, Endpoint}; |
| 8 | use super::types::*; | 6 | use super::types::*; |
| 9 | use super::DeviceStateHandler; | 7 | use super::{DeviceStateHandler, UsbDevice, MAX_INTERFACE_COUNT}; |
| 10 | use super::UsbDevice; | 8 | use crate::{Interface, STRING_INDEX_CUSTOM_START}; |
| 11 | use super::MAX_INTERFACE_COUNT; | ||
| 12 | 9 | ||
| 13 | #[derive(Debug, Copy, Clone)] | 10 | #[derive(Debug, Copy, Clone)] |
| 14 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 11 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| @@ -151,9 +148,7 @@ impl<'d, D: Driver<'d>> Builder<'d, D> { | |||
| 151 | ) -> Self { | 148 | ) -> Self { |
| 152 | // Magic values specified in USB-IF ECN on IADs. | 149 | // Magic values specified in USB-IF ECN on IADs. |
| 153 | if config.composite_with_iads | 150 | if config.composite_with_iads |
| 154 | && (config.device_class != 0xEF | 151 | && (config.device_class != 0xEF || config.device_sub_class != 0x02 || config.device_protocol != 0x01) |
| 155 | || config.device_sub_class != 0x02 | ||
| 156 | || config.device_protocol != 0x01) | ||
| 157 | { | 152 | { |
| 158 | panic!("if composite_with_iads is set, you must set device_class = 0xEF, device_sub_class = 0x02, device_protocol = 0x01"); | 153 | panic!("if composite_with_iads is set, you must set device_class = 0xEF, device_sub_class = 0x02, device_protocol = 0x01"); |
| 159 | } | 154 | } |
| @@ -218,12 +213,7 @@ impl<'d, D: Driver<'d>> Builder<'d, D> { | |||
| 218 | /// with the given class/subclass/protocol, associating all the child interfaces. | 213 | /// with the given class/subclass/protocol, associating all the child interfaces. |
| 219 | /// | 214 | /// |
| 220 | /// If it's not set, no IAD descriptor is added. | 215 | /// If it's not set, no IAD descriptor is added. |
| 221 | pub fn function( | 216 | pub fn function(&mut self, class: u8, subclass: u8, protocol: u8) -> FunctionBuilder<'_, 'd, D> { |
| 222 | &mut self, | ||
| 223 | class: u8, | ||
| 224 | subclass: u8, | ||
| 225 | protocol: u8, | ||
| 226 | ) -> FunctionBuilder<'_, 'd, D> { | ||
| 227 | let iface_count_index = if self.config.composite_with_iads { | 217 | let iface_count_index = if self.config.composite_with_iads { |
| 228 | self.config_descriptor.iad( | 218 | self.config_descriptor.iad( |
| 229 | InterfaceNumber::new(self.interfaces.len() as _), | 219 | InterfaceNumber::new(self.interfaces.len() as _), |
| @@ -315,24 +305,14 @@ impl<'a, 'd, D: Driver<'d>> InterfaceBuilder<'a, 'd, D> { | |||
| 315 | /// Alternate setting numbers are guaranteed to be allocated consecutively, starting from 0. | 305 | /// Alternate setting numbers are guaranteed to be allocated consecutively, starting from 0. |
| 316 | /// | 306 | /// |
| 317 | /// The first alternate setting, with number 0, is the default one. | 307 | /// The first alternate setting, with number 0, is the default one. |
| 318 | pub fn alt_setting( | 308 | pub fn alt_setting(&mut self, class: u8, subclass: u8, protocol: u8) -> InterfaceAltBuilder<'_, 'd, D> { |
| 319 | &mut self, | ||
| 320 | class: u8, | ||
| 321 | subclass: u8, | ||
| 322 | protocol: u8, | ||
| 323 | ) -> InterfaceAltBuilder<'_, 'd, D> { | ||
| 324 | let number = self.next_alt_setting_number; | 309 | let number = self.next_alt_setting_number; |
| 325 | self.next_alt_setting_number += 1; | 310 | self.next_alt_setting_number += 1; |
| 326 | self.builder.interfaces[self.interface_number.0 as usize].num_alt_settings += 1; | 311 | self.builder.interfaces[self.interface_number.0 as usize].num_alt_settings += 1; |
| 327 | 312 | ||
| 328 | self.builder.config_descriptor.interface_alt( | 313 | self.builder |
| 329 | self.interface_number, | 314 | .config_descriptor |
| 330 | number, | 315 | .interface_alt(self.interface_number, number, class, subclass, protocol, None); |
| 331 | class, | ||
| 332 | subclass, | ||
| 333 | protocol, | ||
| 334 | None, | ||
| 335 | ); | ||
| 336 | 316 | ||
| 337 | InterfaceAltBuilder { | 317 | InterfaceAltBuilder { |
| 338 | builder: self.builder, | 318 | builder: self.builder, |
| @@ -365,17 +345,10 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> { | |||
| 365 | /// Descriptors are written in the order builder functions are called. Note that some | 345 | /// Descriptors are written in the order builder functions are called. Note that some |
| 366 | /// classes care about the order. | 346 | /// classes care about the order. |
| 367 | pub fn descriptor(&mut self, descriptor_type: u8, descriptor: &[u8]) { | 347 | pub fn descriptor(&mut self, descriptor_type: u8, descriptor: &[u8]) { |
| 368 | self.builder | 348 | self.builder.config_descriptor.write(descriptor_type, descriptor) |
| 369 | .config_descriptor | ||
| 370 | .write(descriptor_type, descriptor) | ||
| 371 | } | 349 | } |
| 372 | 350 | ||
| 373 | fn endpoint_in( | 351 | fn endpoint_in(&mut self, ep_type: EndpointType, max_packet_size: u16, interval: u8) -> D::EndpointIn { |
| 374 | &mut self, | ||
| 375 | ep_type: EndpointType, | ||
| 376 | max_packet_size: u16, | ||
| 377 | interval: u8, | ||
| 378 | ) -> D::EndpointIn { | ||
| 379 | let ep = self | 352 | let ep = self |
| 380 | .builder | 353 | .builder |
| 381 | .driver | 354 | .driver |
| @@ -387,12 +360,7 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> { | |||
| 387 | ep | 360 | ep |
| 388 | } | 361 | } |
| 389 | 362 | ||
| 390 | fn endpoint_out( | 363 | fn endpoint_out(&mut self, ep_type: EndpointType, max_packet_size: u16, interval: u8) -> D::EndpointOut { |
| 391 | &mut self, | ||
| 392 | ep_type: EndpointType, | ||
| 393 | max_packet_size: u16, | ||
| 394 | interval: u8, | ||
| 395 | ) -> D::EndpointOut { | ||
| 396 | let ep = self | 364 | let ep = self |
| 397 | .builder | 365 | .builder |
| 398 | .driver | 366 | .driver |
