diff options
| author | alexmoon <[email protected]> | 2022-03-25 16:46:14 -0400 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-04-06 05:38:11 +0200 |
| commit | bdc6e0481c42d20d5cca19dfc8ec56306e47296e (patch) | |
| tree | 6beb805dd6ffea30877b654aa42e5c83f5a36c0b /embassy-usb/src/builder.rs | |
| parent | 5c0db627feae071182dd9978ffb56b0524558d93 (diff) | |
Add support for USB classes handling control requests.
Diffstat (limited to 'embassy-usb/src/builder.rs')
| -rw-r--r-- | embassy-usb/src/builder.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs index e92cc8ef2..f0f94b932 100644 --- a/embassy-usb/src/builder.rs +++ b/embassy-usb/src/builder.rs | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | use super::class::UsbClass; | ||
| 1 | use super::descriptor::{BosWriter, DescriptorWriter}; | 2 | use super::descriptor::{BosWriter, DescriptorWriter}; |
| 2 | use super::driver::{Driver, EndpointAllocError}; | 3 | use super::driver::{Driver, EndpointAllocError}; |
| 3 | use super::types::*; | 4 | use super::types::*; |
| @@ -174,7 +175,10 @@ impl<'d, D: Driver<'d>> UsbDeviceBuilder<'d, D> { | |||
| 174 | } | 175 | } |
| 175 | 176 | ||
| 176 | /// Creates the [`UsbDevice`] instance with the configuration in this builder. | 177 | /// Creates the [`UsbDevice`] instance with the configuration in this builder. |
| 177 | pub fn build(mut self) -> UsbDevice<'d, D> { | 178 | /// |
| 179 | /// If a device has mutliple [`UsbClass`]es, they can be provided as a tuple list: | ||
| 180 | /// `(class1, (class2, (class3, ()))`. | ||
| 181 | pub fn build<C: UsbClass<'d, D>>(mut self, classes: C) -> UsbDevice<'d, D, C> { | ||
| 178 | self.config_descriptor.end_configuration(); | 182 | self.config_descriptor.end_configuration(); |
| 179 | self.bos_descriptor.end_bos(); | 183 | self.bos_descriptor.end_bos(); |
| 180 | 184 | ||
| @@ -184,6 +188,7 @@ impl<'d, D: Driver<'d>> UsbDeviceBuilder<'d, D> { | |||
| 184 | self.device_descriptor.into_buf(), | 188 | self.device_descriptor.into_buf(), |
| 185 | self.config_descriptor.into_buf(), | 189 | self.config_descriptor.into_buf(), |
| 186 | self.bos_descriptor.writer.into_buf(), | 190 | self.bos_descriptor.writer.into_buf(), |
| 191 | classes, | ||
| 187 | ) | 192 | ) |
| 188 | } | 193 | } |
| 189 | 194 | ||
| @@ -268,9 +273,10 @@ impl<'d, D: Driver<'d>> UsbDeviceBuilder<'d, D> { | |||
| 268 | /// Panics if endpoint allocation fails, because running out of endpoints or memory is not | 273 | /// Panics if endpoint allocation fails, because running out of endpoints or memory is not |
| 269 | /// feasibly recoverable. | 274 | /// feasibly recoverable. |
| 270 | #[inline] | 275 | #[inline] |
| 271 | pub fn alloc_control_endpoint_out(&mut self, max_packet_size: u16) -> D::EndpointOut { | 276 | pub fn alloc_control_pipe(&mut self, max_packet_size: u16) -> D::ControlPipe { |
| 272 | self.alloc_endpoint_out(None, EndpointType::Control, max_packet_size, 0) | 277 | self.bus |
| 273 | .expect("alloc_ep failed") | 278 | .alloc_control_pipe(max_packet_size) |
| 279 | .expect("alloc_control_pipe failed") | ||
| 274 | } | 280 | } |
| 275 | 281 | ||
| 276 | /// Allocates a bulk in endpoint. | 282 | /// Allocates a bulk in endpoint. |
