Skip to content

Commit 342fca7

Browse files
committed
instance
1 parent 6dbd539 commit 342fca7

File tree

2 files changed

+45
-56
lines changed

2 files changed

+45
-56
lines changed

src/gpio/alt/g4.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,16 @@ pub mod lpuart1 {
787787
PG7<8>,
788788
],
789789
}
790+
791+
use crate::pac::LPUART1 as UART;
792+
impl SerialAsync for UART {
793+
type Rx<Otype> = Rx<Otype>;
794+
type Tx<Otype> = Tx<Otype>;
795+
}
796+
impl SerialFlowControl for UART {
797+
type Cts = Cts;
798+
type Rts = Rts;
799+
}
790800
}
791801

792802
#[cfg(any(feature = "gpio-g47x", feature = "gpio-g49x"))]

src/serial/usart.rs

Lines changed: 35 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ impl Event {
8686
}
8787
}
8888

89+
pub use gpio::alt::SerialAsync as CommonPins;
90+
91+
// Implemented by all USART/UART instances
92+
pub trait Instance: crate::Sealed + crate::Ptr + Enable + Reset + CommonPins {}
93+
8994
/// Serial receiver
9095
pub struct Rx<USART, Pin, Dma> {
9196
pin: Pin,
@@ -182,6 +187,8 @@ macro_rules! uart_shared {
182187
}
183188
)+
184189

190+
impl Instance for $USARTX {}
191+
185192
impl<Pin, Dma> Rx<$USARTX, Pin, Dma> {
186193
/// Starts listening for an interrupt event
187194
pub fn listen(&mut self) {
@@ -579,41 +586,27 @@ macro_rules! uart_lp {
579586
usart.cr3().reset();
580587

581588
usart.cr2().write(|w| unsafe {
582-
w.stop()
583-
.bits(config.stopbits.bits())
584-
.swap()
585-
.bit(config.swap)
589+
w.stop().bits(config.stopbits.bits());
590+
w.swap().bit(config.swap)
586591
});
587592

588593
usart.cr3().write(|w| unsafe {
589-
w.txftcfg()
590-
.bits(config.tx_fifo_threshold.bits())
591-
.rxftcfg()
592-
.bits(config.rx_fifo_threshold.bits())
593-
.txftie()
594-
.bit(config.tx_fifo_interrupt)
595-
.rxftie()
596-
.bit(config.rx_fifo_interrupt)
594+
w.txftcfg().bits(config.tx_fifo_threshold.bits());
595+
w.rxftcfg().bits(config.rx_fifo_threshold.bits());
596+
w.txftie().bit(config.tx_fifo_interrupt);
597+
w.rxftie().bit(config.rx_fifo_interrupt)
597598
});
598599

599600
// Enable the UART and perform remaining configuration.
600601
usart.cr1().write(|w| {
601-
w.ue()
602-
.set_bit()
603-
.te()
604-
.set_bit()
605-
.re()
606-
.set_bit()
607-
.m0()
608-
.bit(config.wordlength == WordLength::DataBits9)
609-
.m1()
610-
.bit(config.wordlength == WordLength::DataBits7)
611-
.pce()
612-
.bit(config.parity != Parity::ParityNone)
613-
.ps()
614-
.bit(config.parity == Parity::ParityOdd)
615-
.fifoen()
616-
.bit(config.fifo_enable)
602+
w.ue().set_bit();
603+
w.te().set_bit();
604+
w.re().set_bit();
605+
w.m0().bit(config.wordlength == WordLength::DataBits9);
606+
w.m1().bit(config.wordlength == WordLength::DataBits7);
607+
w.pce().bit(config.parity != Parity::ParityNone);
608+
w.ps().bit(config.parity == Parity::ParityOdd);
609+
w.fifoen().bit(config.fifo_enable)
617610
});
618611

619612
Ok(Serial {
@@ -726,10 +719,8 @@ macro_rules! uart_full {
726719
usart.cr3().reset();
727720

728721
usart.cr2().write(|w| unsafe {
729-
w.stop()
730-
.bits(config.stopbits.bits())
731-
.swap()
732-
.bit(config.swap)
722+
w.stop().bits(config.stopbits.bits());
723+
w.swap().bit(config.swap)
733724
});
734725

735726
if let Some(timeout) = config.receiver_timeout {
@@ -739,34 +730,22 @@ macro_rules! uart_full {
739730
}
740731

741732
usart.cr3().write(|w| unsafe {
742-
w.txftcfg()
743-
.bits(config.tx_fifo_threshold.bits())
744-
.rxftcfg()
745-
.bits(config.rx_fifo_threshold.bits())
746-
.txftie()
747-
.bit(config.tx_fifo_interrupt)
748-
.rxftie()
749-
.bit(config.rx_fifo_interrupt)
733+
w.txftcfg().bits(config.tx_fifo_threshold.bits());
734+
w.rxftcfg().bits(config.rx_fifo_threshold.bits());
735+
w.txftie().bit(config.tx_fifo_interrupt);
736+
w.rxftie().bit(config.rx_fifo_interrupt)
750737
});
751738

752739
// Enable the UART and perform remaining configuration.
753740
usart.cr1().modify(|_, w| {
754-
w.ue()
755-
.set_bit()
756-
.te()
757-
.set_bit()
758-
.re()
759-
.set_bit()
760-
.m0()
761-
.bit(config.wordlength == WordLength::DataBits7)
762-
.m1()
763-
.bit(config.wordlength == WordLength::DataBits9)
764-
.pce()
765-
.bit(config.parity != Parity::ParityNone)
766-
.ps()
767-
.bit(config.parity == Parity::ParityOdd)
768-
.fifoen()
769-
.bit(config.fifo_enable)
741+
w.ue().set_bit();
742+
w.te().set_bit();
743+
w.re().set_bit();
744+
w.m0().bit(config.wordlength == WordLength::DataBits7);
745+
w.m1().bit(config.wordlength == WordLength::DataBits9);
746+
w.pce().bit(config.parity != Parity::ParityNone);
747+
w.ps().bit(config.parity == Parity::ParityOdd);
748+
w.fifoen().bit(config.fifo_enable)
770749
});
771750

772751
Ok(Serial {

0 commit comments

Comments
 (0)