diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-05-09 02:11:02 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-05-09 02:11:02 +0200 |
| commit | 7ed462a6575cba95e8f07d2d9516d5e7b33d7196 (patch) | |
| tree | ae0e68faea70a907bfb4488876ee179068f38f64 /embassy-usb/src/control.rs | |
| parent | 2e104170de36295243608fbbebebdc6f52e8f8d0 (diff) | |
usb: simplify control in/out handlng, calling response from a single place.
Diffstat (limited to 'embassy-usb/src/control.rs')
| -rw-r--r-- | embassy-usb/src/control.rs | 29 |
1 files changed, 3 insertions, 26 deletions
diff --git a/embassy-usb/src/control.rs b/embassy-usb/src/control.rs index ff42f9d78..4fc65b6a5 100644 --- a/embassy-usb/src/control.rs +++ b/embassy-usb/src/control.rs | |||
| @@ -1,9 +1,7 @@ | |||
| 1 | use core::mem; | 1 | use core::mem; |
| 2 | 2 | ||
| 3 | use crate::descriptor::DescriptorWriter; | ||
| 4 | use crate::driver::{self, EndpointError}; | ||
| 5 | |||
| 6 | use super::types::*; | 3 | use super::types::*; |
| 4 | use crate::driver::{self, EndpointError}; | ||
| 7 | 5 | ||
| 8 | /// Control request type. | 6 | /// Control request type. |
| 9 | #[repr(u8)] | 7 | #[repr(u8)] |
| @@ -191,16 +189,8 @@ pub trait ControlHandler { | |||
| 191 | } | 189 | } |
| 192 | 190 | ||
| 193 | /// Called when a GET_DESCRIPTOR STRING control request is received. | 191 | /// Called when a GET_DESCRIPTOR STRING control request is received. |
| 194 | /// | 192 | fn get_string(&mut self, index: StringIndex, lang_id: u16) -> Option<&str> { |
| 195 | /// Write the response string somewhere (usually to `buf`, but you may use another buffer | 193 | let _ = (index, lang_id); |
| 196 | /// owned by yourself, or a static buffer), then return it. | ||
| 197 | fn get_string<'a>( | ||
| 198 | &'a mut self, | ||
| 199 | index: StringIndex, | ||
| 200 | lang_id: u16, | ||
| 201 | buf: &'a mut [u8], | ||
| 202 | ) -> Option<&'a str> { | ||
| 203 | let _ = (index, lang_id, buf); | ||
| 204 | None | 194 | None |
| 205 | } | 195 | } |
| 206 | } | 196 | } |
| @@ -316,19 +306,6 @@ impl<C: driver::ControlPipe> ControlPipe<C> { | |||
| 316 | } | 306 | } |
| 317 | } | 307 | } |
| 318 | 308 | ||
| 319 | pub(crate) async fn accept_in_writer( | ||
| 320 | &mut self, | ||
| 321 | req: Request, | ||
| 322 | stage: DataInStage, | ||
| 323 | f: impl FnOnce(&mut DescriptorWriter), | ||
| 324 | ) { | ||
| 325 | let mut buf = [0; 256]; | ||
| 326 | let mut w = DescriptorWriter::new(&mut buf); | ||
| 327 | f(&mut w); | ||
| 328 | let pos = w.position().min(usize::from(req.length)); | ||
| 329 | self.accept_in(&buf[..pos], stage).await | ||
| 330 | } | ||
| 331 | |||
| 332 | pub(crate) fn accept(&mut self, _: StatusStage) { | 309 | pub(crate) fn accept(&mut self, _: StatusStage) { |
| 333 | trace!(" control accept"); | 310 | trace!(" control accept"); |
| 334 | self.control.accept(); | 311 | self.control.accept(); |
