From 94b38449bd1e6d04a009700689d34ce1adf72c07 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Mon, 22 Apr 2024 22:16:25 +0100 Subject: [PATCH 1/2] rp usb: add stall implementation --- embassy-rp/src/usb.rs | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/embassy-rp/src/usb.rs b/embassy-rp/src/usb.rs index 37d37d6d9..99cba2d82 100644 --- a/embassy-rp/src/usb.rs +++ b/embassy-rp/src/usb.rs @@ -412,12 +412,38 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { .await } - fn endpoint_set_stalled(&mut self, _ep_addr: EndpointAddress, _stalled: bool) { - todo!(); + fn endpoint_set_stalled(&mut self, ep_addr: EndpointAddress, stalled: bool) { + let n = ep_addr.index(); + + if n == 0 { + T::regs().ep_stall_arm().modify(|w| { + if ep_addr.is_in() { + w.set_ep0_in(stalled); + } else { + w.set_ep0_out(stalled); + } + }); + } + + let ctrl = if ep_addr.is_in() { + T::dpram().ep_in_buffer_control(n) + } else { + T::dpram().ep_out_buffer_control(n) + }; + + ctrl.modify(|w| w.set_stall(stalled)); } - fn endpoint_is_stalled(&mut self, _ep_addr: EndpointAddress) -> bool { - todo!(); + fn endpoint_is_stalled(&mut self, ep_addr: EndpointAddress) -> bool { + let n = ep_addr.index(); + + let ctrl = if ep_addr.is_in() { + T::dpram().ep_in_buffer_control(n) + } else { + T::dpram().ep_out_buffer_control(n) + }; + + ctrl.read().stall() } fn endpoint_set_enabled(&mut self, ep_addr: EndpointAddress, enabled: bool) { From 84cd0c672b2dd3754a36ae632bbe25845dbeeabc Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Mon, 29 Apr 2024 16:23:42 +0100 Subject: [PATCH 2/2] rp usb: wake ep-wakers after stalling --- embassy-rp/src/usb.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/embassy-rp/src/usb.rs b/embassy-rp/src/usb.rs index 99cba2d82..512271ae4 100644 --- a/embassy-rp/src/usb.rs +++ b/embassy-rp/src/usb.rs @@ -432,6 +432,9 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { }; ctrl.modify(|w| w.set_stall(stalled)); + + let wakers = if ep_addr.is_in() { &EP_IN_WAKERS } else { &EP_OUT_WAKERS }; + wakers[n].wake(); } fn endpoint_is_stalled(&mut self, ep_addr: EndpointAddress) -> bool {