aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-04-02 04:42:20 +0200
committerDario Nieuwenhuis <[email protected]>2022-04-06 05:38:11 +0200
commitd7d199f2acfc7c11f83dc10fbcf74641f879b0e9 (patch)
treed0dba90bf6c9d9ffc7adc1ffed7dbbebde9a684a /embassy-nrf/src
parentf5ba022257ccd9ddd371f1dcd10c0775cc5a3110 (diff)
nrf/usb: unify in/out wakers for ep0
Diffstat (limited to 'embassy-nrf/src')
-rw-r--r--embassy-nrf/src/usb.rs23
1 files changed, 12 insertions, 11 deletions
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs
index 570d1c95b..4614389f0 100644
--- a/embassy-nrf/src/usb.rs
+++ b/embassy-nrf/src/usb.rs
@@ -24,8 +24,9 @@ use crate::util::slice_in_ram;
24 24
25const NEW_AW: AtomicWaker = AtomicWaker::new(); 25const NEW_AW: AtomicWaker = AtomicWaker::new();
26static BUS_WAKER: AtomicWaker = NEW_AW; 26static BUS_WAKER: AtomicWaker = NEW_AW;
27static EP_IN_WAKERS: [AtomicWaker; 9] = [NEW_AW; 9]; 27static EP0_WAKER: AtomicWaker = NEW_AW;
28static EP_OUT_WAKERS: [AtomicWaker; 9] = [NEW_AW; 9]; 28static EP_IN_WAKERS: [AtomicWaker; 8] = [NEW_AW; 8];
29static EP_OUT_WAKERS: [AtomicWaker; 8] = [NEW_AW; 8];
29static READY_ENDPOINTS: AtomicU32 = AtomicU32::new(0); 30static READY_ENDPOINTS: AtomicU32 = AtomicU32::new(0);
30 31
31pub struct Driver<'d, T: Instance> { 32pub struct Driver<'d, T: Instance> {
@@ -61,12 +62,12 @@ impl<'d, T: Instance> Driver<'d, T> {
61 62
62 if regs.events_ep0setup.read().bits() != 0 { 63 if regs.events_ep0setup.read().bits() != 0 {
63 regs.intenclr.write(|w| w.ep0setup().clear()); 64 regs.intenclr.write(|w| w.ep0setup().clear());
64 EP_OUT_WAKERS[0].wake(); 65 EP0_WAKER.wake();
65 } 66 }
66 67
67 if regs.events_ep0datadone.read().bits() != 0 { 68 if regs.events_ep0datadone.read().bits() != 0 {
68 regs.intenclr.write(|w| w.ep0datadone().clear()); 69 regs.intenclr.write(|w| w.ep0datadone().clear());
69 EP_IN_WAKERS[0].wake(); 70 EP0_WAKER.wake();
70 } 71 }
71 72
72 // USBEVENT and EPDATA events are weird. They're the "aggregate" 73 // USBEVENT and EPDATA events are weird. They're the "aggregate"
@@ -92,10 +93,10 @@ impl<'d, T: Instance> Driver<'d, T> {
92 READY_ENDPOINTS.fetch_or(r, Ordering::AcqRel); 93 READY_ENDPOINTS.fetch_or(r, Ordering::AcqRel);
93 for i in 1..=7 { 94 for i in 1..=7 {
94 if r & (1 << i) != 0 { 95 if r & (1 << i) != 0 {
95 EP_IN_WAKERS[i].wake(); 96 EP_IN_WAKERS[i - 1].wake();
96 } 97 }
97 if r & (1 << (i + 16)) != 0 { 98 if r & (1 << (i + 16)) != 0 {
98 EP_OUT_WAKERS[i].wake(); 99 EP_OUT_WAKERS[i - 1].wake();
99 } 100 }
100 } 101 }
101 } 102 }
@@ -450,7 +451,7 @@ impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> {
450 451
451 // Wait until ready 452 // Wait until ready
452 poll_fn(|cx| { 453 poll_fn(|cx| {
453 EP_OUT_WAKERS[i].register(cx.waker()); 454 EP_OUT_WAKERS[i - 1].register(cx.waker());
454 let r = READY_ENDPOINTS.load(Ordering::Acquire); 455 let r = READY_ENDPOINTS.load(Ordering::Acquire);
455 if r & (1 << (i + 16)) != 0 { 456 if r & (1 << (i + 16)) != 0 {
456 Poll::Ready(()) 457 Poll::Ready(())
@@ -478,7 +479,7 @@ impl<'d, T: Instance> driver::EndpointIn for Endpoint<'d, T, In> {
478 479
479 // Wait until ready. 480 // Wait until ready.
480 poll_fn(|cx| { 481 poll_fn(|cx| {
481 EP_IN_WAKERS[i].register(cx.waker()); 482 EP_IN_WAKERS[i - 1].register(cx.waker());
482 let r = READY_ENDPOINTS.load(Ordering::Acquire); 483 let r = READY_ENDPOINTS.load(Ordering::Acquire);
483 if r & (1 << i) != 0 { 484 if r & (1 << i) != 0 {
484 Poll::Ready(()) 485 Poll::Ready(())
@@ -519,7 +520,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
519 // Wait for SETUP packet 520 // Wait for SETUP packet
520 regs.intenset.write(|w| w.ep0setup().set()); 521 regs.intenset.write(|w| w.ep0setup().set());
521 poll_fn(|cx| { 522 poll_fn(|cx| {
522 EP_OUT_WAKERS[0].register(cx.waker()); 523 EP0_WAKER.register(cx.waker());
523 let regs = T::regs(); 524 let regs = T::regs();
524 if regs.events_ep0setup.read().bits() != 0 { 525 if regs.events_ep0setup.read().bits() != 0 {
525 Poll::Ready(()) 526 Poll::Ready(())
@@ -562,7 +563,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
562 // Wait until ready 563 // Wait until ready
563 regs.intenset.write(|w| w.ep0datadone().set()); 564 regs.intenset.write(|w| w.ep0datadone().set());
564 poll_fn(|cx| { 565 poll_fn(|cx| {
565 EP_OUT_WAKERS[0].register(cx.waker()); 566 EP0_WAKER.register(cx.waker());
566 let regs = T::regs(); 567 let regs = T::regs();
567 if regs 568 if regs
568 .events_ep0datadone 569 .events_ep0datadone
@@ -596,7 +597,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
596 let res = with_timeout( 597 let res = with_timeout(
597 Duration::from_millis(10), 598 Duration::from_millis(10),
598 poll_fn(|cx| { 599 poll_fn(|cx| {
599 EP_IN_WAKERS[0].register(cx.waker()); 600 EP0_WAKER.register(cx.waker());
600 let regs = T::regs(); 601 let regs = T::regs();
601 if regs.events_ep0datadone.read().bits() != 0 { 602 if regs.events_ep0datadone.read().bits() != 0 {
602 Poll::Ready(()) 603 Poll::Ready(())