diff options
| author | Mathias <[email protected]> | 2022-10-26 11:51:37 +0200 |
|---|---|---|
| committer | Mathias <[email protected]> | 2022-10-26 11:51:37 +0200 |
| commit | 66611a80caea216241d58cc3b848fe55b8865b49 (patch) | |
| tree | 018ff5573b4adc4ec3bbadf371522d8dee32578b | |
| parent | d1eee5262580f4bb9f8ce357d8315ca7f4064900 (diff) | |
Introduce shared new_inner for uart instantiation
| -rw-r--r-- | embassy-stm32/src/usart/mod.rs | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 074061218..3f5b99523 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs | |||
| @@ -222,10 +222,48 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { | |||
| 222 | rx_dma: impl Peripheral<P = RxDma> + 'd, | 222 | rx_dma: impl Peripheral<P = RxDma> + 'd, |
| 223 | config: Config, | 223 | config: Config, |
| 224 | ) -> Self { | 224 | ) -> Self { |
| 225 | into_ref!(_inner, rx, tx, tx_dma, rx_dma); | 225 | T::enable(); |
| 226 | T::reset(); | ||
| 227 | |||
| 228 | Self::new_inner(_inner, rx, tx, tx_dma, rx_dma, config) | ||
| 229 | } | ||
| 230 | |||
| 231 | pub fn new_with_rtscts( | ||
| 232 | _inner: impl Peripheral<P = T> + 'd, | ||
| 233 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | ||
| 234 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | ||
| 235 | rts: impl Peripheral<P = impl RtsPin<T>> + 'd, | ||
| 236 | cts: impl Peripheral<P = impl CtsPin<T>> + 'd, | ||
| 237 | tx_dma: impl Peripheral<P = TxDma> + 'd, | ||
| 238 | rx_dma: impl Peripheral<P = RxDma> + 'd, | ||
| 239 | config: Config, | ||
| 240 | ) -> Self { | ||
| 241 | into_ref!(cts, rts); | ||
| 226 | 242 | ||
| 227 | T::enable(); | 243 | T::enable(); |
| 228 | T::reset(); | 244 | T::reset(); |
| 245 | |||
| 246 | unsafe { | ||
| 247 | rts.set_as_af(rts.af_num(), AFType::OutputPushPull); | ||
| 248 | cts.set_as_af(cts.af_num(), AFType::Input); | ||
| 249 | T::regs().cr3().write(|w| { | ||
| 250 | w.set_rtse(true); | ||
| 251 | w.set_ctse(true); | ||
| 252 | }); | ||
| 253 | } | ||
| 254 | Self::new_inner(_inner, rx, tx, tx_dma, rx_dma, config) | ||
| 255 | } | ||
| 256 | |||
| 257 | fn new_inner( | ||
| 258 | _inner: impl Peripheral<P = T> + 'd, | ||
| 259 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | ||
| 260 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | ||
| 261 | tx_dma: impl Peripheral<P = TxDma> + 'd, | ||
| 262 | rx_dma: impl Peripheral<P = RxDma> + 'd, | ||
| 263 | config: Config, | ||
| 264 | ) -> Self { | ||
| 265 | into_ref!(_inner, rx, tx, tx_dma, rx_dma); | ||
| 266 | |||
| 229 | let pclk_freq = T::frequency(); | 267 | let pclk_freq = T::frequency(); |
| 230 | 268 | ||
| 231 | // TODO: better calculation, including error checking and OVER8 if possible. | 269 | // TODO: better calculation, including error checking and OVER8 if possible. |
| @@ -264,29 +302,6 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { | |||
| 264 | } | 302 | } |
| 265 | } | 303 | } |
| 266 | 304 | ||
| 267 | pub fn new_with_rtscts( | ||
| 268 | _inner: impl Peripheral<P = T> + 'd, | ||
| 269 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | ||
| 270 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | ||
| 271 | rts: impl Peripheral<P = impl RtsPin<T>> + 'd, | ||
| 272 | cts: impl Peripheral<P = impl CtsPin<T>> + 'd, | ||
| 273 | tx_dma: impl Peripheral<P = TxDma> + 'd, | ||
| 274 | rx_dma: impl Peripheral<P = RxDma> + 'd, | ||
| 275 | config: Config, | ||
| 276 | ) -> Self { | ||
| 277 | into_ref!(cts, rts); | ||
| 278 | |||
| 279 | unsafe { | ||
| 280 | rts.set_as_af(rts.af_num(), AFType::OutputPushPull); | ||
| 281 | cts.set_as_af(cts.af_num(), AFType::Input); | ||
| 282 | T::regs().cr3().write(|w| { | ||
| 283 | w.set_rtse(true); | ||
| 284 | w.set_ctse(true); | ||
| 285 | }); | ||
| 286 | } | ||
| 287 | Self::new(_inner, rx, tx, tx_dma, rx_dma, config) | ||
| 288 | } | ||
| 289 | |||
| 290 | pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> | 305 | pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> |
| 291 | where | 306 | where |
| 292 | TxDma: crate::usart::TxDma<T>, | 307 | TxDma: crate::usart::TxDma<T>, |
