aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-01-06 17:09:42 +0100
committerDario Nieuwenhuis <[email protected]>2021-01-06 20:21:03 +0100
commit77bdb5428ee47c50fc1cd24aa9005494a6f37e12 (patch)
treeb355507ac17dd0dbf2b5d7e4a7fb0fb7ccac40ae
parent896eb0ed5246a5888dda0c3985fc9147e83ba8f0 (diff)
buffered_uarte naming cleanup
-rw-r--r--embassy-nrf/src/buffered_uarte.rs36
1 files changed, 18 insertions, 18 deletions
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs
index 2e29da25a..030fecf87 100644
--- a/embassy-nrf/src/buffered_uarte.rs
+++ b/embassy-nrf/src/buffered_uarte.rs
@@ -40,8 +40,8 @@ enum TxState {
40 Transmitting(usize), 40 Transmitting(usize),
41} 41}
42 42
43struct State<'a, T: Instance> { 43struct State<'a, U: Instance> {
44 inner: T, 44 inner: U,
45 45
46 rx: RingBuffer<'a>, 46 rx: RingBuffer<'a>,
47 rx_state: RxState, 47 rx_state: RxState,
@@ -60,11 +60,11 @@ struct State<'a, T: Instance> {
60/// are disabled before using `Uarte`. See product specification: 60/// are disabled before using `Uarte`. See product specification:
61/// - nrf52832: Section 15.2 61/// - nrf52832: Section 15.2
62/// - nrf52840: Section 6.1.2 62/// - nrf52840: Section 6.1.2
63pub struct BufferedUarte<'a, T: Instance> { 63pub struct BufferedUarte<'a, U: Instance> {
64 inner: PeripheralMutex<T::Interrupt, State<'a, T>>, 64 inner: PeripheralMutex<U::Interrupt, State<'a, U>>,
65} 65}
66 66
67impl<'a, T: Instance> Unpin for BufferedUarte<'a, T> {} 67impl<'a, U: Instance> Unpin for BufferedUarte<'a, U> {}
68 68
69#[cfg(any(feature = "52833", feature = "52840"))] 69#[cfg(any(feature = "52833", feature = "52840"))]
70fn port_bit(port: GpioPort) -> bool { 70fn port_bit(port: GpioPort) -> bool {
@@ -74,10 +74,10 @@ fn port_bit(port: GpioPort) -> bool {
74 } 74 }
75} 75}
76 76
77impl<'a, T: Instance> BufferedUarte<'a, T> { 77impl<'a, U: Instance> BufferedUarte<'a, U> {
78 pub fn new( 78 pub fn new(
79 uarte: T, 79 uarte: U,
80 irq: T::Interrupt, 80 irq: U::Interrupt,
81 rx_buffer: &'a mut [u8], 81 rx_buffer: &'a mut [u8],
82 tx_buffer: &'a mut [u8], 82 tx_buffer: &'a mut [u8],
83 mut pins: Pins, 83 mut pins: Pins,
@@ -159,19 +159,19 @@ impl<'a, T: Instance> BufferedUarte<'a, T> {
159 } 159 }
160 } 160 }
161 161
162 fn inner(self: Pin<&mut Self>) -> Pin<&mut PeripheralMutex<T::Interrupt, State<'a, T>>> { 162 fn inner(self: Pin<&mut Self>) -> Pin<&mut PeripheralMutex<U::Interrupt, State<'a, U>>> {
163 unsafe { Pin::new_unchecked(&mut self.get_unchecked_mut().inner) } 163 unsafe { Pin::new_unchecked(&mut self.get_unchecked_mut().inner) }
164 } 164 }
165} 165}
166 166
167impl<'a, T: Instance> Drop for BufferedUarte<'a, T> { 167impl<'a, U: Instance> Drop for BufferedUarte<'a, U> {
168 fn drop(&mut self) { 168 fn drop(&mut self) {
169 // stop DMA before dropping, because DMA is using the buffer in `self`. 169 // stop DMA before dropping, because DMA is using the buffer in `self`.
170 todo!() 170 todo!()
171 } 171 }
172} 172}
173 173
174impl<'a, T: Instance> AsyncBufRead for BufferedUarte<'a, T> { 174impl<'a, U: Instance> AsyncBufRead for BufferedUarte<'a, U> {
175 fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<&[u8]>> { 175 fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<&[u8]>> {
176 self.inner().with(|_irq, state| { 176 self.inner().with(|_irq, state| {
177 // Conservative compiler fence to prevent optimizations that do not 177 // Conservative compiler fence to prevent optimizations that do not
@@ -211,7 +211,7 @@ impl<'a, T: Instance> AsyncBufRead for BufferedUarte<'a, T> {
211 } 211 }
212} 212}
213 213
214impl<'a, T: Instance> AsyncWrite for BufferedUarte<'a, T> { 214impl<'a, U: Instance> AsyncWrite for BufferedUarte<'a, U> {
215 fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize>> { 215 fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize>> {
216 self.inner().with(|irq, state| { 216 self.inner().with(|irq, state| {
217 trace!("poll_write: {:?}", buf.len()); 217 trace!("poll_write: {:?}", buf.len());
@@ -241,7 +241,7 @@ impl<'a, T: Instance> AsyncWrite for BufferedUarte<'a, T> {
241 } 241 }
242} 242}
243 243
244impl<'a, T: Instance> PeripheralState for State<'a, T> { 244impl<'a, U: Instance> PeripheralState for State<'a, U> {
245 fn on_interrupt(&mut self) { 245 fn on_interrupt(&mut self) {
246 trace!("irq: start"); 246 trace!("irq: start");
247 let mut more_work = true; 247 let mut more_work = true;
@@ -380,15 +380,15 @@ impl<'a, T: Instance> PeripheralState for State<'a, T> {
380 } 380 }
381} 381}
382 382
383mod private { 383mod sealed {
384 pub trait Sealed {} 384 pub trait Instance {}
385 385
386 impl Sealed for crate::pac::UARTE0 {} 386 impl Instance for crate::pac::UARTE0 {}
387 #[cfg(any(feature = "52833", feature = "52840", feature = "9160"))] 387 #[cfg(any(feature = "52833", feature = "52840", feature = "9160"))]
388 impl Sealed for crate::pac::UARTE1 {} 388 impl Instance for crate::pac::UARTE1 {}
389} 389}
390 390
391pub trait Instance: Deref<Target = uarte0::RegisterBlock> + private::Sealed { 391pub trait Instance: Deref<Target = uarte0::RegisterBlock> + sealed::Instance {
392 type Interrupt: OwnedInterrupt; 392 type Interrupt: OwnedInterrupt;
393} 393}
394 394