diff options
| author | chemicstry <[email protected]> | 2023-01-18 02:29:49 +0200 |
|---|---|---|
| committer | chemicstry <[email protected]> | 2023-01-18 02:29:49 +0200 |
| commit | d2f2b451d084448d442c6f9cb1c6b9f94a4fd447 (patch) | |
| tree | a74a7d0294b3710697e927acf80b23c5aba293e1 | |
| parent | 15e3f42b7c9fa542844e1f8bc5b1e5c67faf7837 (diff) | |
stm32/usb_otg: implement endpoint wait_enabled
| -rw-r--r-- | embassy-stm32/src/usb_otg/usb.rs | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/embassy-stm32/src/usb_otg/usb.rs b/embassy-stm32/src/usb_otg/usb.rs index 2d9b613ea..504a90f25 100644 --- a/embassy-stm32/src/usb_otg/usb.rs +++ b/embassy-stm32/src/usb_otg/usb.rs | |||
| @@ -791,6 +791,9 @@ impl<'d, T: Instance> embassy_usb_driver::Bus for Bus<'d, T> { | |||
| 791 | w.set_usbaep(enabled); | 791 | w.set_usbaep(enabled); |
| 792 | }) | 792 | }) |
| 793 | }); | 793 | }); |
| 794 | |||
| 795 | // Wake `Endpoint::wait_enabled()` | ||
| 796 | T::state().ep_out_wakers[ep_addr.index()].wake(); | ||
| 794 | } | 797 | } |
| 795 | Direction::In => { | 798 | Direction::In => { |
| 796 | // SAFETY: DIEPCTL is shared with `Endpoint` so critical section is needed for RMW | 799 | // SAFETY: DIEPCTL is shared with `Endpoint` so critical section is needed for RMW |
| @@ -807,6 +810,9 @@ impl<'d, T: Instance> embassy_usb_driver::Bus for Bus<'d, T> { | |||
| 807 | w.set_usbaep(enabled); | 810 | w.set_usbaep(enabled); |
| 808 | }) | 811 | }) |
| 809 | }); | 812 | }); |
| 813 | |||
| 814 | // Wake `Endpoint::wait_enabled()` | ||
| 815 | T::state().ep_in_wakers[ep_addr.index()].wake(); | ||
| 810 | } | 816 | } |
| 811 | } | 817 | } |
| 812 | } | 818 | } |
| @@ -1031,7 +1037,21 @@ impl<'d, T: Instance> embassy_usb_driver::Endpoint for Endpoint<'d, T, In> { | |||
| 1031 | &self.info | 1037 | &self.info |
| 1032 | } | 1038 | } |
| 1033 | 1039 | ||
| 1034 | async fn wait_enabled(&mut self) {} | 1040 | async fn wait_enabled(&mut self) { |
| 1041 | poll_fn(|cx| { | ||
| 1042 | let ep_index = self.info.addr.index(); | ||
| 1043 | |||
| 1044 | T::state().ep_in_wakers[ep_index].register(cx.waker()); | ||
| 1045 | |||
| 1046 | // SAFETY: atomic read without side effects | ||
| 1047 | if unsafe { T::regs().diepctl(ep_index).read().usbaep() } { | ||
| 1048 | Poll::Ready(()) | ||
| 1049 | } else { | ||
| 1050 | Poll::Pending | ||
| 1051 | } | ||
| 1052 | }) | ||
| 1053 | .await | ||
| 1054 | } | ||
| 1035 | } | 1055 | } |
| 1036 | 1056 | ||
| 1037 | impl<'d, T: Instance> embassy_usb_driver::Endpoint for Endpoint<'d, T, Out> { | 1057 | impl<'d, T: Instance> embassy_usb_driver::Endpoint for Endpoint<'d, T, Out> { |
| @@ -1039,7 +1059,21 @@ impl<'d, T: Instance> embassy_usb_driver::Endpoint for Endpoint<'d, T, Out> { | |||
| 1039 | &self.info | 1059 | &self.info |
| 1040 | } | 1060 | } |
| 1041 | 1061 | ||
| 1042 | async fn wait_enabled(&mut self) {} | 1062 | async fn wait_enabled(&mut self) { |
| 1063 | poll_fn(|cx| { | ||
| 1064 | let ep_index = self.info.addr.index(); | ||
| 1065 | |||
| 1066 | T::state().ep_out_wakers[ep_index].register(cx.waker()); | ||
| 1067 | |||
| 1068 | // SAFETY: atomic read without side effects | ||
| 1069 | if unsafe { T::regs().doepctl(ep_index).read().usbaep() } { | ||
| 1070 | Poll::Ready(()) | ||
| 1071 | } else { | ||
| 1072 | Poll::Pending | ||
| 1073 | } | ||
| 1074 | }) | ||
| 1075 | .await | ||
| 1076 | } | ||
| 1043 | } | 1077 | } |
| 1044 | 1078 | ||
| 1045 | impl<'d, T: Instance> embassy_usb_driver::EndpointOut for Endpoint<'d, T, Out> { | 1079 | impl<'d, T: Instance> embassy_usb_driver::EndpointOut for Endpoint<'d, T, Out> { |
