diff options
| -rw-r--r-- | embassy-stm32/build.rs | 12 | ||||
| -rw-r--r-- | embassy-stm32/src/usart/buffered.rs | 28 | ||||
| -rw-r--r-- | embassy-stm32/src/usart/mod.rs | 119 | ||||
| m--------- | stm32-data | 0 |
4 files changed, 97 insertions, 62 deletions
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index c892007a3..a4709f4ca 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs | |||
| @@ -244,11 +244,11 @@ fn main() { | |||
| 244 | (("usart", "CTS"), quote!(crate::usart::CtsPin)), | 244 | (("usart", "CTS"), quote!(crate::usart::CtsPin)), |
| 245 | (("usart", "RTS"), quote!(crate::usart::RtsPin)), | 245 | (("usart", "RTS"), quote!(crate::usart::RtsPin)), |
| 246 | (("usart", "CK"), quote!(crate::usart::CkPin)), | 246 | (("usart", "CK"), quote!(crate::usart::CkPin)), |
| 247 | (("usart", "TX"), quote!(crate::usart::TxPin)), | 247 | (("lpuart", "TX"), quote!(crate::usart::TxPin)), |
| 248 | (("usart", "RX"), quote!(crate::usart::RxPin)), | 248 | (("lpuart", "RX"), quote!(crate::usart::RxPin)), |
| 249 | (("usart", "CTS"), quote!(crate::usart::CtsPin)), | 249 | (("lpuart", "CTS"), quote!(crate::usart::CtsPin)), |
| 250 | (("usart", "RTS"), quote!(crate::usart::RtsPin)), | 250 | (("lpuart", "RTS"), quote!(crate::usart::RtsPin)), |
| 251 | (("usart", "CK"), quote!(crate::usart::CkPin)), | 251 | (("lpuart", "CK"), quote!(crate::usart::CkPin)), |
| 252 | (("spi", "SCK"), quote!(crate::spi::SckPin)), | 252 | (("spi", "SCK"), quote!(crate::spi::SckPin)), |
| 253 | (("spi", "MOSI"), quote!(crate::spi::MosiPin)), | 253 | (("spi", "MOSI"), quote!(crate::spi::MosiPin)), |
| 254 | (("spi", "MISO"), quote!(crate::spi::MisoPin)), | 254 | (("spi", "MISO"), quote!(crate::spi::MisoPin)), |
| @@ -497,6 +497,8 @@ fn main() { | |||
| 497 | // (kind, signal) => trait | 497 | // (kind, signal) => trait |
| 498 | (("usart", "RX"), quote!(crate::usart::RxDma)), | 498 | (("usart", "RX"), quote!(crate::usart::RxDma)), |
| 499 | (("usart", "TX"), quote!(crate::usart::TxDma)), | 499 | (("usart", "TX"), quote!(crate::usart::TxDma)), |
| 500 | (("lpuart", "RX"), quote!(crate::usart::RxDma)), | ||
| 501 | (("lpuart", "TX"), quote!(crate::usart::TxDma)), | ||
| 500 | (("spi", "RX"), quote!(crate::spi::RxDma)), | 502 | (("spi", "RX"), quote!(crate::spi::RxDma)), |
| 501 | (("spi", "TX"), quote!(crate::spi::TxDma)), | 503 | (("spi", "TX"), quote!(crate::spi::TxDma)), |
| 502 | (("i2c", "RX"), quote!(crate::i2c::RxDma)), | 504 | (("i2c", "RX"), quote!(crate::i2c::RxDma)), |
diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index 0e8d0d682..ec2231e43 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs | |||
| @@ -9,14 +9,14 @@ use futures::future::poll_fn; | |||
| 9 | 9 | ||
| 10 | use super::*; | 10 | use super::*; |
| 11 | 11 | ||
| 12 | pub struct State<'d, T: Instance>(StateStorage<StateInner<'d, T>>); | 12 | pub struct State<'d, T: BasicInstance>(StateStorage<StateInner<'d, T>>); |
| 13 | impl<'d, T: Instance> State<'d, T> { | 13 | impl<'d, T: BasicInstance> State<'d, T> { |
| 14 | pub fn new() -> Self { | 14 | pub fn new() -> Self { |
| 15 | Self(StateStorage::new()) | 15 | Self(StateStorage::new()) |
| 16 | } | 16 | } |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | struct StateInner<'d, T: Instance> { | 19 | struct StateInner<'d, T: BasicInstance> { |
| 20 | phantom: PhantomData<&'d mut T>, | 20 | phantom: PhantomData<&'d mut T>, |
| 21 | 21 | ||
| 22 | rx_waker: WakerRegistration, | 22 | rx_waker: WakerRegistration, |
| @@ -26,16 +26,16 @@ struct StateInner<'d, T: Instance> { | |||
| 26 | tx: RingBuffer<'d>, | 26 | tx: RingBuffer<'d>, |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | unsafe impl<'d, T: Instance> Send for StateInner<'d, T> {} | 29 | unsafe impl<'d, T: BasicInstance> Send for StateInner<'d, T> {} |
| 30 | unsafe impl<'d, T: Instance> Sync for StateInner<'d, T> {} | 30 | unsafe impl<'d, T: BasicInstance> Sync for StateInner<'d, T> {} |
| 31 | 31 | ||
| 32 | pub struct BufferedUart<'d, T: Instance> { | 32 | pub struct BufferedUart<'d, T: BasicInstance> { |
| 33 | inner: PeripheralMutex<'d, StateInner<'d, T>>, | 33 | inner: PeripheralMutex<'d, StateInner<'d, T>>, |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | impl<'d, T: Instance> Unpin for BufferedUart<'d, T> {} | 36 | impl<'d, T: BasicInstance> Unpin for BufferedUart<'d, T> {} |
| 37 | 37 | ||
| 38 | impl<'d, T: Instance> BufferedUart<'d, T> { | 38 | impl<'d, T: BasicInstance> BufferedUart<'d, T> { |
| 39 | pub fn new( | 39 | pub fn new( |
| 40 | state: &'d mut State<'d, T>, | 40 | state: &'d mut State<'d, T>, |
| 41 | _uart: Uart<'d, T, NoDma, NoDma>, | 41 | _uart: Uart<'d, T, NoDma, NoDma>, |
| @@ -66,7 +66,7 @@ impl<'d, T: Instance> BufferedUart<'d, T> { | |||
| 66 | } | 66 | } |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | impl<'d, T: Instance> StateInner<'d, T> | 69 | impl<'d, T: BasicInstance> StateInner<'d, T> |
| 70 | where | 70 | where |
| 71 | Self: 'd, | 71 | Self: 'd, |
| 72 | { | 72 | { |
| @@ -135,7 +135,7 @@ where | |||
| 135 | } | 135 | } |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | impl<'d, T: Instance> PeripheralState for StateInner<'d, T> | 138 | impl<'d, T: BasicInstance> PeripheralState for StateInner<'d, T> |
| 139 | where | 139 | where |
| 140 | Self: 'd, | 140 | Self: 'd, |
| 141 | { | 141 | { |
| @@ -152,11 +152,11 @@ impl embedded_io::Error for Error { | |||
| 152 | } | 152 | } |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | impl<'d, T: Instance> embedded_io::Io for BufferedUart<'d, T> { | 155 | impl<'d, T: BasicInstance> embedded_io::Io for BufferedUart<'d, T> { |
| 156 | type Error = Error; | 156 | type Error = Error; |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | impl<'d, T: Instance> embedded_io::asynch::Read for BufferedUart<'d, T> { | 159 | impl<'d, T: BasicInstance> embedded_io::asynch::Read for BufferedUart<'d, T> { |
| 160 | type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>> | 160 | type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>> |
| 161 | where | 161 | where |
| 162 | Self: 'a; | 162 | Self: 'a; |
| @@ -194,7 +194,7 @@ impl<'d, T: Instance> embedded_io::asynch::Read for BufferedUart<'d, T> { | |||
| 194 | } | 194 | } |
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | impl<'d, T: Instance> embedded_io::asynch::BufRead for BufferedUart<'d, T> { | 197 | impl<'d, T: BasicInstance> embedded_io::asynch::BufRead for BufferedUart<'d, T> { |
| 198 | type FillBufFuture<'a> = impl Future<Output = Result<&'a [u8], Self::Error>> | 198 | type FillBufFuture<'a> = impl Future<Output = Result<&'a [u8], Self::Error>> |
| 199 | where | 199 | where |
| 200 | Self: 'a; | 200 | Self: 'a; |
| @@ -231,7 +231,7 @@ impl<'d, T: Instance> embedded_io::asynch::BufRead for BufferedUart<'d, T> { | |||
| 231 | } | 231 | } |
| 232 | } | 232 | } |
| 233 | 233 | ||
| 234 | impl<'d, T: Instance> embedded_io::asynch::Write for BufferedUart<'d, T> { | 234 | impl<'d, T: BasicInstance> embedded_io::asynch::Write for BufferedUart<'d, T> { |
| 235 | type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>> | 235 | type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>> |
| 236 | where | 236 | where |
| 237 | Self: 'a; | 237 | Self: 'a; |
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index ca75bab41..511850971 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs | |||
| @@ -6,9 +6,7 @@ use embassy_hal_common::{into_ref, PeripheralRef}; | |||
| 6 | 6 | ||
| 7 | use crate::dma::NoDma; | 7 | use crate::dma::NoDma; |
| 8 | use crate::gpio::sealed::AFType; | 8 | use crate::gpio::sealed::AFType; |
| 9 | use crate::interrupt::Interrupt; | 9 | use crate::pac::lpuart::{regs, vals}; |
| 10 | use crate::pac::usart::{regs, vals}; | ||
| 11 | use crate::rcc::RccPeripheral; | ||
| 12 | use crate::{peripherals, Peripheral}; | 10 | use crate::{peripherals, Peripheral}; |
| 13 | 11 | ||
| 14 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] | 12 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] |
| @@ -71,22 +69,23 @@ pub enum Error { | |||
| 71 | Parity, | 69 | Parity, |
| 72 | } | 70 | } |
| 73 | 71 | ||
| 74 | pub struct Uart<'d, T: Instance, TxDma = NoDma, RxDma = NoDma> { | 72 | pub struct Uart<'d, T: BasicInstance, TxDma = NoDma, RxDma = NoDma> { |
| 73 | phantom: PhantomData<&'d mut T>, | ||
| 75 | tx: UartTx<'d, T, TxDma>, | 74 | tx: UartTx<'d, T, TxDma>, |
| 76 | rx: UartRx<'d, T, RxDma>, | 75 | rx: UartRx<'d, T, RxDma>, |
| 77 | } | 76 | } |
| 78 | 77 | ||
| 79 | pub struct UartTx<'d, T: Instance, TxDma = NoDma> { | 78 | pub struct UartTx<'d, T: BasicInstance, TxDma = NoDma> { |
| 80 | phantom: PhantomData<&'d mut T>, | 79 | phantom: PhantomData<&'d mut T>, |
| 81 | tx_dma: PeripheralRef<'d, TxDma>, | 80 | tx_dma: PeripheralRef<'d, TxDma>, |
| 82 | } | 81 | } |
| 83 | 82 | ||
| 84 | pub struct UartRx<'d, T: Instance, RxDma = NoDma> { | 83 | pub struct UartRx<'d, T: BasicInstance, RxDma = NoDma> { |
| 85 | phantom: PhantomData<&'d mut T>, | 84 | phantom: PhantomData<&'d mut T>, |
| 86 | rx_dma: PeripheralRef<'d, RxDma>, | 85 | rx_dma: PeripheralRef<'d, RxDma>, |
| 87 | } | 86 | } |
| 88 | 87 | ||
| 89 | impl<'d, T: Instance, TxDma> UartTx<'d, T, TxDma> { | 88 | impl<'d, T: BasicInstance, TxDma> UartTx<'d, T, TxDma> { |
| 90 | fn new(tx_dma: PeripheralRef<'d, TxDma>) -> Self { | 89 | fn new(tx_dma: PeripheralRef<'d, TxDma>) -> Self { |
| 91 | Self { | 90 | Self { |
| 92 | tx_dma, | 91 | tx_dma, |
| @@ -132,7 +131,7 @@ impl<'d, T: Instance, TxDma> UartTx<'d, T, TxDma> { | |||
| 132 | } | 131 | } |
| 133 | } | 132 | } |
| 134 | 133 | ||
| 135 | impl<'d, T: Instance, RxDma> UartRx<'d, T, RxDma> { | 134 | impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> { |
| 136 | fn new(rx_dma: PeripheralRef<'d, RxDma>) -> Self { | 135 | fn new(rx_dma: PeripheralRef<'d, RxDma>) -> Self { |
| 137 | Self { | 136 | Self { |
| 138 | rx_dma, | 137 | rx_dma, |
| @@ -187,7 +186,7 @@ impl<'d, T: Instance, RxDma> UartRx<'d, T, RxDma> { | |||
| 187 | } | 186 | } |
| 188 | } | 187 | } |
| 189 | 188 | ||
| 190 | impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { | 189 | impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { |
| 191 | pub fn new( | 190 | pub fn new( |
| 192 | _inner: impl Peripheral<P = T> + 'd, | 191 | _inner: impl Peripheral<P = T> + 'd, |
| 193 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 192 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, |
| @@ -203,7 +202,7 @@ impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { | |||
| 203 | let pclk_freq = T::frequency(); | 202 | let pclk_freq = T::frequency(); |
| 204 | 203 | ||
| 205 | // TODO: better calculation, including error checking and OVER8 if possible. | 204 | // TODO: better calculation, including error checking and OVER8 if possible. |
| 206 | let div = (pclk_freq.0 + (config.baudrate / 2)) / config.baudrate; | 205 | let div = (pclk_freq.0 + (config.baudrate / 2)) / config.baudrate * T::MULTIPLIER; |
| 207 | 206 | ||
| 208 | let r = T::regs(); | 207 | let r = T::regs(); |
| 209 | 208 | ||
| @@ -235,6 +234,7 @@ impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { | |||
| 235 | Self { | 234 | Self { |
| 236 | tx: UartTx::new(tx_dma), | 235 | tx: UartTx::new(tx_dma), |
| 237 | rx: UartRx::new(rx_dma), | 236 | rx: UartRx::new(rx_dma), |
| 237 | phantom: PhantomData {}, | ||
| 238 | } | 238 | } |
| 239 | } | 239 | } |
| 240 | 240 | ||
| @@ -275,7 +275,7 @@ impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { | |||
| 275 | mod eh02 { | 275 | mod eh02 { |
| 276 | use super::*; | 276 | use super::*; |
| 277 | 277 | ||
| 278 | impl<'d, T: Instance, RxDma> embedded_hal_02::serial::Read<u8> for UartRx<'d, T, RxDma> { | 278 | impl<'d, T: BasicInstance, RxDma> embedded_hal_02::serial::Read<u8> for UartRx<'d, T, RxDma> { |
| 279 | type Error = Error; | 279 | type Error = Error; |
| 280 | fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> { | 280 | fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> { |
| 281 | let r = T::regs(); | 281 | let r = T::regs(); |
| @@ -302,7 +302,7 @@ mod eh02 { | |||
| 302 | } | 302 | } |
| 303 | } | 303 | } |
| 304 | 304 | ||
| 305 | impl<'d, T: Instance, TxDma> embedded_hal_02::blocking::serial::Write<u8> for UartTx<'d, T, TxDma> { | 305 | impl<'d, T: BasicInstance, TxDma> embedded_hal_02::blocking::serial::Write<u8> for UartTx<'d, T, TxDma> { |
| 306 | type Error = Error; | 306 | type Error = Error; |
| 307 | fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { | 307 | fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { |
| 308 | self.blocking_write(buffer) | 308 | self.blocking_write(buffer) |
| @@ -312,14 +312,14 @@ mod eh02 { | |||
| 312 | } | 312 | } |
| 313 | } | 313 | } |
| 314 | 314 | ||
| 315 | impl<'d, T: Instance, TxDma, RxDma> embedded_hal_02::serial::Read<u8> for Uart<'d, T, TxDma, RxDma> { | 315 | impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_02::serial::Read<u8> for Uart<'d, T, TxDma, RxDma> { |
| 316 | type Error = Error; | 316 | type Error = Error; |
| 317 | fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> { | 317 | fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> { |
| 318 | embedded_hal_02::serial::Read::read(&mut self.rx) | 318 | embedded_hal_02::serial::Read::read(&mut self.rx) |
| 319 | } | 319 | } |
| 320 | } | 320 | } |
| 321 | 321 | ||
| 322 | impl<'d, T: Instance, TxDma, RxDma> embedded_hal_02::blocking::serial::Write<u8> for Uart<'d, T, TxDma, RxDma> { | 322 | impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_02::blocking::serial::Write<u8> for Uart<'d, T, TxDma, RxDma> { |
| 323 | type Error = Error; | 323 | type Error = Error; |
| 324 | fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { | 324 | fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { |
| 325 | self.blocking_write(buffer) | 325 | self.blocking_write(buffer) |
| @@ -345,15 +345,15 @@ mod eh1 { | |||
| 345 | } | 345 | } |
| 346 | } | 346 | } |
| 347 | 347 | ||
| 348 | impl<'d, T: Instance, TxDma, RxDma> embedded_hal_1::serial::ErrorType for Uart<'d, T, TxDma, RxDma> { | 348 | impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_1::serial::ErrorType for Uart<'d, T, TxDma, RxDma> { |
| 349 | type Error = Error; | 349 | type Error = Error; |
| 350 | } | 350 | } |
| 351 | 351 | ||
| 352 | impl<'d, T: Instance, TxDma> embedded_hal_1::serial::ErrorType for UartTx<'d, T, TxDma> { | 352 | impl<'d, T: BasicInstance, TxDma> embedded_hal_1::serial::ErrorType for UartTx<'d, T, TxDma> { |
| 353 | type Error = Error; | 353 | type Error = Error; |
| 354 | } | 354 | } |
| 355 | 355 | ||
| 356 | impl<'d, T: Instance, RxDma> embedded_hal_1::serial::ErrorType for UartRx<'d, T, RxDma> { | 356 | impl<'d, T: BasicInstance, RxDma> embedded_hal_1::serial::ErrorType for UartRx<'d, T, RxDma> { |
| 357 | type Error = Error; | 357 | type Error = Error; |
| 358 | } | 358 | } |
| 359 | } | 359 | } |
| @@ -362,7 +362,7 @@ cfg_if::cfg_if! { | |||
| 362 | if #[cfg(all(feature = "unstable-traits", feature = "nightly", feature = "_todo_embedded_hal_serial"))] { | 362 | if #[cfg(all(feature = "unstable-traits", feature = "nightly", feature = "_todo_embedded_hal_serial"))] { |
| 363 | use core::future::Future; | 363 | use core::future::Future; |
| 364 | 364 | ||
| 365 | impl<'d, T: Instance, TxDma> embedded_hal_async::serial::Write for UartTx<'d, T, TxDma> | 365 | impl<'d, T: UartInstance, TxDma> embedded_hal_async::serial::Write for UartTx<'d, T, TxDma> |
| 366 | where | 366 | where |
| 367 | TxDma: crate::usart::TxDma<T>, | 367 | TxDma: crate::usart::TxDma<T>, |
| 368 | { | 368 | { |
| @@ -379,7 +379,7 @@ cfg_if::cfg_if! { | |||
| 379 | } | 379 | } |
| 380 | } | 380 | } |
| 381 | 381 | ||
| 382 | impl<'d, T: Instance, RxDma> embedded_hal_async::serial::Read for UartRx<'d, T, RxDma> | 382 | impl<'d, T: UartInstance, RxDma> embedded_hal_async::serial::Read for UartRx<'d, T, RxDma> |
| 383 | where | 383 | where |
| 384 | RxDma: crate::usart::RxDma<T>, | 384 | RxDma: crate::usart::RxDma<T>, |
| 385 | { | 385 | { |
| @@ -390,7 +390,7 @@ cfg_if::cfg_if! { | |||
| 390 | } | 390 | } |
| 391 | } | 391 | } |
| 392 | 392 | ||
| 393 | impl<'d, T: Instance, TxDma, RxDma> embedded_hal_async::serial::Write for Uart<'d, T, TxDma, RxDma> | 393 | impl<'d, T: UartInstance, TxDma, RxDma> embedded_hal_async::serial::Write for Uart<'d, T, TxDma, RxDma> |
| 394 | where | 394 | where |
| 395 | TxDma: crate::usart::TxDma<T>, | 395 | TxDma: crate::usart::TxDma<T>, |
| 396 | { | 396 | { |
| @@ -407,7 +407,7 @@ cfg_if::cfg_if! { | |||
| 407 | } | 407 | } |
| 408 | } | 408 | } |
| 409 | 409 | ||
| 410 | impl<'d, T: Instance, TxDma, RxDma> embedded_hal_async::serial::Read for Uart<'d, T, TxDma, RxDma> | 410 | impl<'d, T: UartInstance, TxDma, RxDma> embedded_hal_async::serial::Read for Uart<'d, T, TxDma, RxDma> |
| 411 | where | 411 | where |
| 412 | RxDma: crate::usart::RxDma<T>, | 412 | RxDma: crate::usart::RxDma<T>, |
| 413 | { | 413 | { |
| @@ -447,55 +447,88 @@ unsafe fn clear_interrupt_flags(_r: crate::pac::usart::Usart, _sr: regs::Sr) { | |||
| 447 | } | 447 | } |
| 448 | 448 | ||
| 449 | #[cfg(usart_v2)] | 449 | #[cfg(usart_v2)] |
| 450 | fn tdr(r: crate::pac::usart::Usart) -> *mut u8 { | 450 | fn tdr(r: crate::pac::lpuart::Lpuart) -> *mut u8 { |
| 451 | r.tdr().ptr() as _ | 451 | r.tdr().ptr() as _ |
| 452 | } | 452 | } |
| 453 | 453 | ||
| 454 | #[cfg(usart_v2)] | 454 | #[cfg(usart_v2)] |
| 455 | fn rdr(r: crate::pac::usart::Usart) -> *mut u8 { | 455 | fn rdr(r: crate::pac::lpuart::Lpuart) -> *mut u8 { |
| 456 | r.rdr().ptr() as _ | 456 | r.rdr().ptr() as _ |
| 457 | } | 457 | } |
| 458 | 458 | ||
| 459 | #[cfg(usart_v2)] | 459 | #[cfg(usart_v2)] |
| 460 | fn sr(r: crate::pac::usart::Usart) -> crate::pac::common::Reg<regs::Ixr, crate::pac::common::R> { | 460 | fn sr(r: crate::pac::lpuart::Lpuart) -> crate::pac::common::Reg<regs::Isr, crate::pac::common::R> { |
| 461 | r.isr() | 461 | r.isr() |
| 462 | } | 462 | } |
| 463 | 463 | ||
| 464 | #[cfg(usart_v2)] | 464 | #[cfg(usart_v2)] |
| 465 | #[allow(unused)] | 465 | #[allow(unused)] |
| 466 | unsafe fn clear_interrupt_flags(r: crate::pac::usart::Usart, sr: regs::Ixr) { | 466 | unsafe fn clear_interrupt_flags(r: crate::pac::lpuart::Lpuart, sr: regs::Isr) { |
| 467 | r.icr().write(|w| *w = sr); | 467 | r.icr().write(|w| *w = regs::Icr(sr.0)); |
| 468 | } | 468 | } |
| 469 | 469 | ||
| 470 | pub(crate) mod sealed { | 470 | pub(crate) mod sealed { |
| 471 | pub trait Instance { | 471 | |
| 472 | fn regs() -> crate::pac::usart::Usart; | 472 | pub trait BasicInstance: crate::rcc::RccPeripheral { |
| 473 | const MULTIPLIER: u32; | ||
| 474 | type Interrupt: crate::interrupt::Interrupt; | ||
| 475 | |||
| 476 | fn regs() -> crate::pac::lpuart::Lpuart; | ||
| 473 | } | 477 | } |
| 474 | } | ||
| 475 | 478 | ||
| 476 | pub trait Instance: sealed::Instance + RccPeripheral { | 479 | pub trait FullInstance: BasicInstance { |
| 477 | type Interrupt: Interrupt; | 480 | fn regs_uart() -> crate::pac::usart::Usart; |
| 481 | } | ||
| 478 | } | 482 | } |
| 479 | 483 | ||
| 480 | pin_trait!(RxPin, Instance); | 484 | pub trait BasicInstance: sealed::BasicInstance {} |
| 481 | pin_trait!(TxPin, Instance); | ||
| 482 | pin_trait!(CtsPin, Instance); | ||
| 483 | pin_trait!(RtsPin, Instance); | ||
| 484 | pin_trait!(CkPin, Instance); | ||
| 485 | 485 | ||
| 486 | dma_trait!(TxDma, Instance); | 486 | pub trait FullInstance: sealed::FullInstance {} |
| 487 | dma_trait!(RxDma, Instance); | 487 | |
| 488 | pin_trait!(RxPin, BasicInstance); | ||
| 489 | pin_trait!(TxPin, BasicInstance); | ||
| 490 | pin_trait!(CtsPin, BasicInstance); | ||
| 491 | pin_trait!(RtsPin, BasicInstance); | ||
| 492 | pin_trait!(CkPin, BasicInstance); | ||
| 493 | |||
| 494 | dma_trait!(TxDma, BasicInstance); | ||
| 495 | dma_trait!(RxDma, BasicInstance); | ||
| 496 | |||
| 497 | macro_rules! impl_lpuart { | ||
| 498 | ($inst:ident, $irq:ident, $mul:expr) => { | ||
| 499 | impl sealed::BasicInstance for crate::peripherals::$inst { | ||
| 500 | const MULTIPLIER: u32 = $mul; | ||
| 501 | type Interrupt = crate::interrupt::$irq; | ||
| 502 | |||
| 503 | fn regs() -> crate::pac::lpuart::Lpuart { | ||
| 504 | crate::pac::lpuart::Lpuart(crate::pac::$inst.0) | ||
| 505 | } | ||
| 506 | } | ||
| 507 | }; | ||
| 508 | } | ||
| 488 | 509 | ||
| 489 | foreach_interrupt!( | 510 | foreach_interrupt!( |
| 490 | ($inst:ident, usart, $block:ident, $signal_name:ident, $irq:ident) => { | 511 | ($inst:ident, lpuart, LPUART, $signal_name:ident, $irq:ident) => { |
| 491 | impl sealed::Instance for peripherals::$inst { | 512 | impl_lpuart!($inst, $irq, 255); |
| 492 | fn regs() -> crate::pac::usart::Usart { | 513 | |
| 514 | impl BasicInstance for peripherals::$inst { | ||
| 515 | } | ||
| 516 | }; | ||
| 517 | |||
| 518 | ($inst:ident, usart, USART, $signal_name:ident, $irq:ident) => { | ||
| 519 | impl_lpuart!($inst, $irq, 1); | ||
| 520 | |||
| 521 | impl BasicInstance for peripherals::$inst { | ||
| 522 | } | ||
| 523 | |||
| 524 | impl sealed::FullInstance for peripherals::$inst { | ||
| 525 | |||
| 526 | fn regs_uart() -> crate::pac::usart::Usart { | ||
| 493 | crate::pac::$inst | 527 | crate::pac::$inst |
| 494 | } | 528 | } |
| 495 | } | 529 | } |
| 496 | 530 | ||
| 497 | impl Instance for peripherals::$inst { | 531 | impl FullInstance for peripherals::$inst { |
| 498 | type Interrupt = crate::interrupt::$irq; | ||
| 499 | } | 532 | } |
| 500 | }; | 533 | }; |
| 501 | ); | 534 | ); |
diff --git a/stm32-data b/stm32-data | |||
| Subproject 758c9e74625c68bc23d66ced8bfeb5643c63cec | Subproject f47995849a1a66cc92143ff94c84b11dc2701cc | ||
