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 | |
| parent | 6199bdea710cde33e5d5381b6d6abfc8af46df19 (diff) | |
Run rustfmt.
Diffstat (limited to 'embassy-usb')
| -rw-r--r-- | embassy-usb/src/builder.rs | 54 | ||||
| -rw-r--r-- | embassy-usb/src/descriptor.rs | 9 | ||||
| -rw-r--r-- | embassy-usb/src/driver.rs | 10 | ||||
| -rw-r--r-- | embassy-usb/src/lib.rs | 21 |
4 files changed, 23 insertions, 71 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 |
diff --git a/embassy-usb/src/descriptor.rs b/embassy-usb/src/descriptor.rs index 7f23fd921..b94a4b161 100644 --- a/embassy-usb/src/descriptor.rs +++ b/embassy-usb/src/descriptor.rs | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | use super::builder::Config; | 1 | use super::builder::Config; |
| 2 | use super::{types::*, CONFIGURATION_VALUE}; | 2 | use super::types::*; |
| 3 | use super::CONFIGURATION_VALUE; | ||
| 3 | 4 | ||
| 4 | /// Standard descriptor types | 5 | /// Standard descriptor types |
| 5 | #[allow(missing_docs)] | 6 | #[allow(missing_docs)] |
| @@ -113,11 +114,7 @@ impl<'a> DescriptorWriter<'a> { | |||
| 113 | CONFIGURATION_VALUE, // bConfigurationValue | 114 | CONFIGURATION_VALUE, // bConfigurationValue |
| 114 | 0, // iConfiguration | 115 | 0, // iConfiguration |
| 115 | 0x80 | if config.self_powered { 0x40 } else { 0x00 } | 116 | 0x80 | if config.self_powered { 0x40 } else { 0x00 } |
| 116 | | if config.supports_remote_wakeup { | 117 | | if config.supports_remote_wakeup { 0x20 } else { 0x00 }, // bmAttributes |
| 117 | 0x20 | ||
| 118 | } else { | ||
| 119 | 0x00 | ||
| 120 | }, // bmAttributes | ||
| 121 | (config.max_power / 2) as u8, // bMaxPower | 118 | (config.max_power / 2) as u8, // bMaxPower |
| 122 | ], | 119 | ], |
| 123 | ) | 120 | ) |
diff --git a/embassy-usb/src/driver.rs b/embassy-usb/src/driver.rs index 0680df7a5..bfe44d627 100644 --- a/embassy-usb/src/driver.rs +++ b/embassy-usb/src/driver.rs | |||
| @@ -161,18 +161,12 @@ pub trait ControlPipe { | |||
| 161 | /// | 161 | /// |
| 162 | /// Must be called after `setup()` for requests with `direction` of `Out` | 162 | /// Must be called after `setup()` for requests with `direction` of `Out` |
| 163 | /// and `length` greater than zero. | 163 | /// and `length` greater than zero. |
| 164 | fn data_out<'a>( | 164 | fn data_out<'a>(&'a mut self, buf: &'a mut [u8], first: bool, last: bool) -> Self::DataOutFuture<'a>; |
| 165 | &'a mut self, | ||
| 166 | buf: &'a mut [u8], | ||
| 167 | first: bool, | ||
| 168 | last: bool, | ||
| 169 | ) -> Self::DataOutFuture<'a>; | ||
| 170 | 165 | ||
| 171 | /// Sends a DATA IN packet with `data` in response to a control read request. | 166 | /// Sends a DATA IN packet with `data` in response to a control read request. |
| 172 | /// | 167 | /// |
| 173 | /// If `last_packet` is true, the STATUS packet will be ACKed following the transfer of `data`. | 168 | /// If `last_packet` is true, the STATUS packet will be ACKed following the transfer of `data`. |
| 174 | fn data_in<'a>(&'a mut self, data: &'a [u8], first: bool, last: bool) | 169 | fn data_in<'a>(&'a mut self, data: &'a [u8], first: bool, last: bool) -> Self::DataInFuture<'a>; |
| 175 | -> Self::DataInFuture<'a>; | ||
| 176 | 170 | ||
| 177 | /// Accepts a control request. | 171 | /// Accepts a control request. |
| 178 | /// | 172 | /// |
diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs index b691bf11e..f2577d4fc 100644 --- a/embassy-usb/src/lib.rs +++ b/embassy-usb/src/lib.rs | |||
| @@ -15,16 +15,13 @@ pub mod types; | |||
| 15 | use embassy::util::{select, Either}; | 15 | use embassy::util::{select, Either}; |
| 16 | use heapless::Vec; | 16 | use heapless::Vec; |
| 17 | 17 | ||
| 18 | use crate::descriptor_reader::foreach_endpoint; | 18 | pub use self::builder::{Builder, Config}; |
| 19 | use crate::driver::ControlPipe; | ||
| 20 | |||
| 21 | use self::control::*; | 19 | use self::control::*; |
| 22 | use self::descriptor::*; | 20 | use self::descriptor::*; |
| 23 | use self::driver::{Bus, Driver, Event}; | 21 | use self::driver::{Bus, Driver, Event}; |
| 24 | use self::types::*; | 22 | use self::types::*; |
| 25 | 23 | use crate::descriptor_reader::foreach_endpoint; | |
| 26 | pub use self::builder::Builder; | 24 | use crate::driver::ControlPipe; |
| 27 | pub use self::builder::Config; | ||
| 28 | 25 | ||
| 29 | /// The global state of the USB device. | 26 | /// The global state of the USB device. |
| 30 | /// | 27 | /// |
| @@ -418,10 +415,8 @@ impl<'d, D: Driver<'d>> Inner<'d, D> { | |||
| 418 | // Enable all endpoints of selected alt settings. | 415 | // Enable all endpoints of selected alt settings. |
| 419 | foreach_endpoint(self.config_descriptor, |ep| { | 416 | foreach_endpoint(self.config_descriptor, |ep| { |
| 420 | let iface = &self.interfaces[ep.interface as usize]; | 417 | let iface = &self.interfaces[ep.interface as usize]; |
| 421 | self.bus.endpoint_set_enabled( | 418 | self.bus |
| 422 | ep.ep_address, | 419 | .endpoint_set_enabled(ep.ep_address, iface.current_alt_setting == ep.interface_alt); |
| 423 | iface.current_alt_setting == ep.interface_alt, | ||
| 424 | ); | ||
| 425 | }) | 420 | }) |
| 426 | .unwrap(); | 421 | .unwrap(); |
| 427 | 422 | ||
| @@ -474,10 +469,8 @@ impl<'d, D: Driver<'d>> Inner<'d, D> { | |||
| 474 | // Enable/disable EPs of this interface as needed. | 469 | // Enable/disable EPs of this interface as needed. |
| 475 | foreach_endpoint(self.config_descriptor, |ep| { | 470 | foreach_endpoint(self.config_descriptor, |ep| { |
| 476 | if ep.interface == req.index as u8 { | 471 | if ep.interface == req.index as u8 { |
| 477 | self.bus.endpoint_set_enabled( | 472 | self.bus |
| 478 | ep.ep_address, | 473 | .endpoint_set_enabled(ep.ep_address, iface.current_alt_setting == ep.interface_alt); |
| 479 | iface.current_alt_setting == ep.interface_alt, | ||
| 480 | ); | ||
| 481 | } | 474 | } |
| 482 | }) | 475 | }) |
| 483 | .unwrap(); | 476 | .unwrap(); |
