diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-09-27 21:17:54 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2025-09-28 21:05:37 +0200 |
| commit | 6a262521811a435f2cfedd7e25fb70a1aab957ca (patch) | |
| tree | 74a3ad8bb301c660bf631f7bec54103fe1a0081b | |
| parent | 6ee0d15f4975daa52a22c42e57c673f5ecc86b9d (diff) | |
nrf/qdec: erase instance generics
| -rw-r--r-- | embassy-nrf/src/qdec.rs | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/embassy-nrf/src/qdec.rs b/embassy-nrf/src/qdec.rs index 69bfab0bb..0ebd7afb8 100644 --- a/embassy-nrf/src/qdec.rs +++ b/embassy-nrf/src/qdec.rs | |||
| @@ -16,8 +16,10 @@ use crate::pac::qdec::vals; | |||
| 16 | use crate::{interrupt, pac}; | 16 | use crate::{interrupt, pac}; |
| 17 | 17 | ||
| 18 | /// Quadrature decoder driver. | 18 | /// Quadrature decoder driver. |
| 19 | pub struct Qdec<'d, T: Instance> { | 19 | pub struct Qdec<'d> { |
| 20 | _p: Peri<'d, T>, | 20 | r: pac::qdec::Qdec, |
| 21 | state: &'static State, | ||
| 22 | _phantom: PhantomData<&'d ()>, | ||
| 21 | } | 23 | } |
| 22 | 24 | ||
| 23 | /// QDEC config | 25 | /// QDEC config |
| @@ -59,9 +61,9 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl | |||
| 59 | } | 61 | } |
| 60 | } | 62 | } |
| 61 | 63 | ||
| 62 | impl<'d, T: Instance> Qdec<'d, T> { | 64 | impl<'d> Qdec<'d> { |
| 63 | /// Create a new QDEC. | 65 | /// Create a new QDEC. |
| 64 | pub fn new( | 66 | pub fn new<T: Instance>( |
| 65 | qdec: Peri<'d, T>, | 67 | qdec: Peri<'d, T>, |
| 66 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 68 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 67 | a: Peri<'d, impl GpioPin>, | 69 | a: Peri<'d, impl GpioPin>, |
| @@ -72,7 +74,7 @@ impl<'d, T: Instance> Qdec<'d, T> { | |||
| 72 | } | 74 | } |
| 73 | 75 | ||
| 74 | /// Create a new QDEC, with a pin for LED output. | 76 | /// Create a new QDEC, with a pin for LED output. |
| 75 | pub fn new_with_led( | 77 | pub fn new_with_led<T: Instance>( |
| 76 | qdec: Peri<'d, T>, | 78 | qdec: Peri<'d, T>, |
| 77 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 79 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 78 | a: Peri<'d, impl GpioPin>, | 80 | a: Peri<'d, impl GpioPin>, |
| @@ -83,8 +85,8 @@ impl<'d, T: Instance> Qdec<'d, T> { | |||
| 83 | Self::new_inner(qdec, a.into(), b.into(), Some(led.into()), config) | 85 | Self::new_inner(qdec, a.into(), b.into(), Some(led.into()), config) |
| 84 | } | 86 | } |
| 85 | 87 | ||
| 86 | fn new_inner( | 88 | fn new_inner<T: Instance>( |
| 87 | p: Peri<'d, T>, | 89 | _p: Peri<'d, T>, |
| 88 | a: Peri<'d, AnyPin>, | 90 | a: Peri<'d, AnyPin>, |
| 89 | b: Peri<'d, AnyPin>, | 91 | b: Peri<'d, AnyPin>, |
| 90 | led: Option<Peri<'d, AnyPin>>, | 92 | led: Option<Peri<'d, AnyPin>>, |
| @@ -147,7 +149,11 @@ impl<'d, T: Instance> Qdec<'d, T> { | |||
| 147 | // Start sampling | 149 | // Start sampling |
| 148 | r.tasks_start().write_value(1); | 150 | r.tasks_start().write_value(1); |
| 149 | 151 | ||
| 150 | Self { _p: p } | 152 | Self { |
| 153 | r: T::regs(), | ||
| 154 | state: T::state(), | ||
| 155 | _phantom: PhantomData, | ||
| 156 | } | ||
| 151 | } | 157 | } |
| 152 | 158 | ||
| 153 | /// Perform an asynchronous read of the decoder. | 159 | /// Perform an asynchronous read of the decoder. |
| @@ -173,17 +179,18 @@ impl<'d, T: Instance> Qdec<'d, T> { | |||
| 173 | /// # }; | 179 | /// # }; |
| 174 | /// ``` | 180 | /// ``` |
| 175 | pub async fn read(&mut self) -> i16 { | 181 | pub async fn read(&mut self) -> i16 { |
| 176 | let t = T::regs(); | 182 | self.r.intenset().write(|w| w.set_reportrdy(true)); |
| 177 | t.intenset().write(|w| w.set_reportrdy(true)); | 183 | self.r.tasks_readclracc().write_value(1); |
| 178 | t.tasks_readclracc().write_value(1); | ||
| 179 | 184 | ||
| 180 | poll_fn(|cx| { | 185 | let state = self.state; |
| 181 | T::state().waker.register(cx.waker()); | 186 | let r = self.r; |
| 182 | if t.events_reportrdy().read() == 0 { | 187 | poll_fn(move |cx| { |
| 188 | state.waker.register(cx.waker()); | ||
| 189 | if r.events_reportrdy().read() == 0 { | ||
| 183 | Poll::Pending | 190 | Poll::Pending |
| 184 | } else { | 191 | } else { |
| 185 | t.events_reportrdy().write_value(0); | 192 | r.events_reportrdy().write_value(0); |
| 186 | let acc = t.accread().read(); | 193 | let acc = r.accread().read(); |
| 187 | Poll::Ready(acc as i16) | 194 | Poll::Ready(acc as i16) |
| 188 | } | 195 | } |
| 189 | }) | 196 | }) |
