diff options
| author | alexmoon <[email protected]> | 2022-03-28 20:10:13 -0400 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-04-06 05:38:11 +0200 |
| commit | c53bb7394a20e180e2ac7e81cc468025018bd1da (patch) | |
| tree | 8457402aeda554b448391ccc6d6fd409c10390d1 /embassy-usb/src | |
| parent | a22639ad920fccfd909602f5c69147be911650eb (diff) | |
Switch to ControlHandler owned bufs for control_in()
Diffstat (limited to 'embassy-usb/src')
| -rw-r--r-- | embassy-usb/src/control.rs | 7 | ||||
| -rw-r--r-- | embassy-usb/src/lib.rs | 11 |
2 files changed, 7 insertions, 11 deletions
diff --git a/embassy-usb/src/control.rs b/embassy-usb/src/control.rs index cdae2d977..195b218dc 100644 --- a/embassy-usb/src/control.rs +++ b/embassy-usb/src/control.rs | |||
| @@ -133,8 +133,8 @@ pub enum OutResponse { | |||
| 133 | 133 | ||
| 134 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] | 134 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] |
| 135 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 135 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 136 | pub enum InResponse { | 136 | pub enum InResponse<'a> { |
| 137 | Accepted(usize), | 137 | Accepted(&'a [u8]), |
| 138 | Rejected, | 138 | Rejected, |
| 139 | } | 139 | } |
| 140 | 140 | ||
| @@ -164,8 +164,7 @@ pub trait ControlHandler { | |||
| 164 | /// # Arguments | 164 | /// # Arguments |
| 165 | /// | 165 | /// |
| 166 | /// * `req` - The request from the SETUP packet. | 166 | /// * `req` - The request from the SETUP packet. |
| 167 | /// * `resp` - The buffer for you to write the response. | 167 | fn control_in(&mut self, req: Request) -> InResponse<'_> { |
| 168 | fn control_in(&mut self, req: Request, resp: &mut [u8]) -> InResponse { | ||
| 169 | InResponse::Rejected | 168 | InResponse::Rejected |
| 170 | } | 169 | } |
| 171 | } | 170 | } |
diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs index 9ac55db78..5a82f5cae 100644 --- a/embassy-usb/src/lib.rs +++ b/embassy-usb/src/lib.rs | |||
| @@ -284,13 +284,10 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> { | |||
| 284 | .find(|(i, _)| req.index == *i as _) | 284 | .find(|(i, _)| req.index == *i as _) |
| 285 | .map(|(_, h)| h); | 285 | .map(|(_, h)| h); |
| 286 | match handler { | 286 | match handler { |
| 287 | Some(handler) => { | 287 | Some(handler) => match handler.control_in(req) { |
| 288 | let mut buf = [0; 128]; | 288 | InResponse::Accepted(data) => self.control.accept_in(data).await, |
| 289 | match handler.control_in(req, &mut buf) { | 289 | InResponse::Rejected => self.control.reject(), |
| 290 | InResponse::Accepted(len) => self.control.accept_in(&buf[..len]).await, | 290 | }, |
| 291 | InResponse::Rejected => self.control.reject(), | ||
| 292 | } | ||
| 293 | } | ||
| 294 | None => self.control.reject(), | 291 | None => self.control.reject(), |
| 295 | } | 292 | } |
| 296 | } | 293 | } |
