Introduce shared new_inner for uart instantiation

This commit is contained in:
Mathias 2022-10-26 11:51:37 +02:00
parent d1eee52625
commit 66611a80ca

View File

@ -222,10 +222,48 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
rx_dma: impl Peripheral<P = RxDma> + 'd, rx_dma: impl Peripheral<P = RxDma> + 'd,
config: Config, config: Config,
) -> Self { ) -> Self {
into_ref!(_inner, rx, tx, tx_dma, rx_dma); T::enable();
T::reset();
Self::new_inner(_inner, rx, tx, tx_dma, rx_dma, config)
}
pub fn new_with_rtscts(
_inner: impl Peripheral<P = T> + 'd,
rx: impl Peripheral<P = impl RxPin<T>> + 'd,
tx: impl Peripheral<P = impl TxPin<T>> + 'd,
rts: impl Peripheral<P = impl RtsPin<T>> + 'd,
cts: impl Peripheral<P = impl CtsPin<T>> + 'd,
tx_dma: impl Peripheral<P = TxDma> + 'd,
rx_dma: impl Peripheral<P = RxDma> + 'd,
config: Config,
) -> Self {
into_ref!(cts, rts);
T::enable(); T::enable();
T::reset(); T::reset();
unsafe {
rts.set_as_af(rts.af_num(), AFType::OutputPushPull);
cts.set_as_af(cts.af_num(), AFType::Input);
T::regs().cr3().write(|w| {
w.set_rtse(true);
w.set_ctse(true);
});
}
Self::new_inner(_inner, rx, tx, tx_dma, rx_dma, config)
}
fn new_inner(
_inner: impl Peripheral<P = T> + 'd,
rx: impl Peripheral<P = impl RxPin<T>> + 'd,
tx: impl Peripheral<P = impl TxPin<T>> + 'd,
tx_dma: impl Peripheral<P = TxDma> + 'd,
rx_dma: impl Peripheral<P = RxDma> + 'd,
config: Config,
) -> Self {
into_ref!(_inner, rx, tx, tx_dma, rx_dma);
let pclk_freq = T::frequency(); let pclk_freq = T::frequency();
// TODO: better calculation, including error checking and OVER8 if possible. // 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> {
} }
} }
pub fn new_with_rtscts(
_inner: impl Peripheral<P = T> + 'd,
rx: impl Peripheral<P = impl RxPin<T>> + 'd,
tx: impl Peripheral<P = impl TxPin<T>> + 'd,
rts: impl Peripheral<P = impl RtsPin<T>> + 'd,
cts: impl Peripheral<P = impl CtsPin<T>> + 'd,
tx_dma: impl Peripheral<P = TxDma> + 'd,
rx_dma: impl Peripheral<P = RxDma> + 'd,
config: Config,
) -> Self {
into_ref!(cts, rts);
unsafe {
rts.set_as_af(rts.af_num(), AFType::OutputPushPull);
cts.set_as_af(cts.af_num(), AFType::Input);
T::regs().cr3().write(|w| {
w.set_rtse(true);
w.set_ctse(true);
});
}
Self::new(_inner, rx, tx, tx_dma, rx_dma, config)
}
pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error>
where where
TxDma: crate::usart::TxDma<T>, TxDma: crate::usart::TxDma<T>,