diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-04-02 04:53:42 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-04-06 05:38:11 +0200 |
| commit | 522a87ae429a8ca0444aee5724e10789564d8229 (patch) | |
| tree | 7fc03274d924684f4e2be4b0115560d225ce809b | |
| parent | d7d199f2acfc7c11f83dc10fbcf74641f879b0e9 (diff) | |
usb: centralize all control logging in control.rs
| -rw-r--r-- | embassy-nrf/src/usb.rs | 2 | ||||
| -rw-r--r-- | embassy-usb/src/control.rs | 16 | ||||
| -rw-r--r-- | embassy-usb/src/lib.rs | 12 |
3 files changed, 17 insertions, 13 deletions
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs index 4614389f0..124316a29 100644 --- a/embassy-nrf/src/usb.rs +++ b/embassy-nrf/src/usb.rs | |||
| @@ -615,14 +615,12 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 615 | } | 615 | } |
| 616 | 616 | ||
| 617 | fn accept(&mut self) { | 617 | fn accept(&mut self) { |
| 618 | debug!("control accept"); | ||
| 619 | let regs = T::regs(); | 618 | let regs = T::regs(); |
| 620 | regs.tasks_ep0status | 619 | regs.tasks_ep0status |
| 621 | .write(|w| w.tasks_ep0status().bit(true)); | 620 | .write(|w| w.tasks_ep0status().bit(true)); |
| 622 | } | 621 | } |
| 623 | 622 | ||
| 624 | fn reject(&mut self) { | 623 | fn reject(&mut self) { |
| 625 | debug!("control reject"); | ||
| 626 | let regs = T::regs(); | 624 | let regs = T::regs(); |
| 627 | regs.tasks_ep0stall.write(|w| w.tasks_ep0stall().bit(true)); | 625 | regs.tasks_ep0stall.write(|w| w.tasks_ep0stall().bit(true)); |
| 628 | } | 626 | } |
diff --git a/embassy-usb/src/control.rs b/embassy-usb/src/control.rs index 9f1115ff2..da48dccaf 100644 --- a/embassy-usb/src/control.rs +++ b/embassy-usb/src/control.rs | |||
| @@ -231,6 +231,8 @@ impl<C: driver::ControlPipe> ControlPipe<C> { | |||
| 231 | 231 | ||
| 232 | pub(crate) async fn setup(&mut self) -> Setup { | 232 | pub(crate) async fn setup(&mut self) -> Setup { |
| 233 | let req = self.control.setup().await; | 233 | let req = self.control.setup().await; |
| 234 | trace!("control request: {:02x}", req); | ||
| 235 | |||
| 234 | match (req.direction, req.length) { | 236 | match (req.direction, req.length) { |
| 235 | (UsbDirection::Out, n) => Setup::DataOut( | 237 | (UsbDirection::Out, n) => Setup::DataOut( |
| 236 | req, | 238 | req, |
| @@ -267,15 +269,21 @@ impl<C: driver::ControlPipe> ControlPipe<C> { | |||
| 267 | } | 269 | } |
| 268 | } | 270 | } |
| 269 | 271 | ||
| 270 | Ok((&buf[0..total], StatusStage {})) | 272 | let res = &buf[0..total]; |
| 273 | #[cfg(feature = "defmt")] | ||
| 274 | trace!(" control out data: {:02x}", buf); | ||
| 275 | #[cfg(not(feature = "defmt"))] | ||
| 276 | trace!(" control out data: {:02x?}", buf); | ||
| 277 | |||
| 278 | Ok((res, StatusStage {})) | ||
| 271 | } | 279 | } |
| 272 | } | 280 | } |
| 273 | 281 | ||
| 274 | pub(crate) async fn accept_in(&mut self, buf: &[u8], stage: DataInStage) { | 282 | pub(crate) async fn accept_in(&mut self, buf: &[u8], stage: DataInStage) { |
| 275 | #[cfg(feature = "defmt")] | 283 | #[cfg(feature = "defmt")] |
| 276 | debug!("control in accept {:x}", buf); | 284 | trace!(" control in accept {:02x}", buf); |
| 277 | #[cfg(not(feature = "defmt"))] | 285 | #[cfg(not(feature = "defmt"))] |
| 278 | debug!("control in accept {:x?}", buf); | 286 | trace!(" control in accept {:02x?}", buf); |
| 279 | 287 | ||
| 280 | let req_len = stage.length; | 288 | let req_len = stage.length; |
| 281 | let len = buf.len().min(req_len); | 289 | let len = buf.len().min(req_len); |
| @@ -305,10 +313,12 @@ impl<C: driver::ControlPipe> ControlPipe<C> { | |||
| 305 | } | 313 | } |
| 306 | 314 | ||
| 307 | pub(crate) fn accept(&mut self, _: StatusStage) { | 315 | pub(crate) fn accept(&mut self, _: StatusStage) { |
| 316 | trace!(" control accept"); | ||
| 308 | self.control.accept(); | 317 | self.control.accept(); |
| 309 | } | 318 | } |
| 310 | 319 | ||
| 311 | pub(crate) fn reject(&mut self) { | 320 | pub(crate) fn reject(&mut self) { |
| 321 | trace!(" control reject"); | ||
| 312 | self.control.reject(); | 322 | self.control.reject(); |
| 313 | } | 323 | } |
| 314 | } | 324 | } |
diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs index 067b5b07f..1b189383e 100644 --- a/embassy-usb/src/lib.rs +++ b/embassy-usb/src/lib.rs | |||
| @@ -128,14 +128,10 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> { | |||
| 128 | self.device_state = UsbDeviceState::Suspend; | 128 | self.device_state = UsbDeviceState::Suspend; |
| 129 | } | 129 | } |
| 130 | }, | 130 | }, |
| 131 | Either::Right(req) => { | 131 | Either::Right(req) => match req { |
| 132 | debug!("control request: {:x}", req); | 132 | Setup::DataIn(req, stage) => self.handle_control_in(req, stage).await, |
| 133 | 133 | Setup::DataOut(req, stage) => self.handle_control_out(req, stage).await, | |
| 134 | match req { | 134 | }, |
| 135 | Setup::DataIn(req, stage) => self.handle_control_in(req, stage).await, | ||
| 136 | Setup::DataOut(req, stage) => self.handle_control_out(req, stage).await, | ||
| 137 | } | ||
| 138 | } | ||
| 139 | } | 135 | } |
| 140 | } | 136 | } |
| 141 | } | 137 | } |
