diff options
| -rw-r--r-- | embassy-rp/src/uart/mod.rs | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/embassy-rp/src/uart/mod.rs b/embassy-rp/src/uart/mod.rs index d36884109..c3a15fda5 100644 --- a/embassy-rp/src/uart/mod.rs +++ b/embassy-rp/src/uart/mod.rs | |||
| @@ -165,12 +165,12 @@ impl<'d, M: Mode> UartTx<'d, M> { | |||
| 165 | config: Config, | 165 | config: Config, |
| 166 | ) -> Self { | 166 | ) -> Self { |
| 167 | Uart::<M>::init(T::info(), Some(tx.into()), None, None, None, config); | 167 | Uart::<M>::init(T::info(), Some(tx.into()), None, None, None, config); |
| 168 | Self::new_inner::<T>(Some(tx_dma.into())) | 168 | Self::new_inner(T::info(), Some(tx_dma.into())) |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | fn new_inner<T: Instance>(tx_dma: Option<Peri<'d, AnyChannel>>) -> Self { | 171 | fn new_inner(info: &'static Info, tx_dma: Option<Peri<'d, AnyChannel>>) -> Self { |
| 172 | Self { | 172 | Self { |
| 173 | info: T::info(), | 173 | info, |
| 174 | tx_dma, | 174 | tx_dma, |
| 175 | phantom: PhantomData, | 175 | phantom: PhantomData, |
| 176 | } | 176 | } |
| @@ -230,7 +230,7 @@ impl<'d> UartTx<'d, Blocking> { | |||
| 230 | /// Create a new UART TX instance for blocking mode operations. | 230 | /// Create a new UART TX instance for blocking mode operations. |
| 231 | pub fn new_blocking<T: Instance>(_uart: Peri<'d, T>, tx: Peri<'d, impl TxPin<T>>, config: Config) -> Self { | 231 | pub fn new_blocking<T: Instance>(_uart: Peri<'d, T>, tx: Peri<'d, impl TxPin<T>>, config: Config) -> Self { |
| 232 | Uart::<Blocking>::init(T::info(), Some(tx.into()), None, None, None, config); | 232 | Uart::<Blocking>::init(T::info(), Some(tx.into()), None, None, None, config); |
| 233 | Self::new_inner::<T>(None) | 233 | Self::new_inner(T::info(), None) |
| 234 | } | 234 | } |
| 235 | 235 | ||
| 236 | /// Convert this uart TX instance into a buffered uart using the provided | 236 | /// Convert this uart TX instance into a buffered uart using the provided |
| @@ -281,20 +281,25 @@ impl<'d, M: Mode> UartRx<'d, M> { | |||
| 281 | config: Config, | 281 | config: Config, |
| 282 | ) -> Self { | 282 | ) -> Self { |
| 283 | Uart::<M>::init(T::info(), None, Some(rx.into()), None, None, config); | 283 | Uart::<M>::init(T::info(), None, Some(rx.into()), None, None, config); |
| 284 | Self::new_inner::<T>(true, Some(rx_dma.into())) | 284 | Self::new_inner(T::info(), T::dma_state(), true, Some(rx_dma.into())) |
| 285 | } | 285 | } |
| 286 | 286 | ||
| 287 | fn new_inner<T: Instance>(has_irq: bool, rx_dma: Option<Peri<'d, AnyChannel>>) -> Self { | 287 | fn new_inner( |
| 288 | info: &'static Info, | ||
| 289 | dma_state: &'static DmaState, | ||
| 290 | has_irq: bool, | ||
| 291 | rx_dma: Option<Peri<'d, AnyChannel>>, | ||
| 292 | ) -> Self { | ||
| 288 | debug_assert_eq!(has_irq, rx_dma.is_some()); | 293 | debug_assert_eq!(has_irq, rx_dma.is_some()); |
| 289 | if has_irq { | 294 | if has_irq { |
| 290 | // disable all error interrupts initially | 295 | // disable all error interrupts initially |
| 291 | T::info().regs.uartimsc().write(|w| w.0 = 0); | 296 | info.regs.uartimsc().write(|w| w.0 = 0); |
| 292 | T::Interrupt::unpend(); | 297 | info.interrupt.unpend(); |
| 293 | unsafe { T::Interrupt::enable() }; | 298 | unsafe { info.interrupt.enable() }; |
| 294 | } | 299 | } |
| 295 | Self { | 300 | Self { |
| 296 | info: T::info(), | 301 | info, |
| 297 | dma_state: T::dma_state(), | 302 | dma_state, |
| 298 | rx_dma, | 303 | rx_dma, |
| 299 | phantom: PhantomData, | 304 | phantom: PhantomData, |
| 300 | } | 305 | } |
| @@ -355,7 +360,7 @@ impl<'d> UartRx<'d, Blocking> { | |||
| 355 | /// Create a new UART RX instance for blocking mode operations. | 360 | /// Create a new UART RX instance for blocking mode operations. |
| 356 | pub fn new_blocking<T: Instance>(_uart: Peri<'d, T>, rx: Peri<'d, impl RxPin<T>>, config: Config) -> Self { | 361 | pub fn new_blocking<T: Instance>(_uart: Peri<'d, T>, rx: Peri<'d, impl RxPin<T>>, config: Config) -> Self { |
| 357 | Uart::<Blocking>::init(T::info(), None, Some(rx.into()), None, None, config); | 362 | Uart::<Blocking>::init(T::info(), None, Some(rx.into()), None, None, config); |
| 358 | Self::new_inner::<T>(false, None) | 363 | Self::new_inner(T::info(), T::dma_state(), false, None) |
| 359 | } | 364 | } |
| 360 | 365 | ||
| 361 | /// Convert this uart RX instance into a buffered uart using the provided | 366 | /// Convert this uart RX instance into a buffered uart using the provided |
| @@ -835,8 +840,8 @@ impl<'d, M: Mode> Uart<'d, M> { | |||
| 835 | ); | 840 | ); |
| 836 | 841 | ||
| 837 | Self { | 842 | Self { |
| 838 | tx: UartTx::new_inner::<T>(tx_dma), | 843 | tx: UartTx::new_inner(T::info(), tx_dma), |
| 839 | rx: UartRx::new_inner::<T>(has_irq, rx_dma), | 844 | rx: UartRx::new_inner(T::info(), T::dma_state(), has_irq, rx_dma), |
| 840 | } | 845 | } |
| 841 | } | 846 | } |
| 842 | 847 | ||
