From 41160c0d8d8478a74759c64301813e39c04eeee6 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 11 Jan 2021 10:40:37 +0100 Subject: [PATCH] nrf/buffered_uarte: add set_baudrate --- embassy-nrf/src/buffered_uarte.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index a6e80a9a..c5f78a56 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs @@ -203,6 +203,19 @@ impl<'a, U: Instance, T: TimerInstance, P1: ConfigurablePpi, P2: ConfigurablePpi } } + pub fn set_baudrate(self: Pin<&mut Self>, baudrate: Baudrate) { + self.inner().with(|state, _irq| { + let timeout = 0x8000_0000 / (baudrate as u32 / 40); + state.timer.cc[0].write(|w| unsafe { w.bits(timeout) }); + state.timer.tasks_clear.write(|w| unsafe { w.bits(1) }); + + state + .uarte + .baudrate + .write(|w| w.baudrate().variant(baudrate)); + }); + } + fn inner(self: Pin<&mut Self>) -> Pin<&mut PeripheralMutex>> { unsafe { Pin::new_unchecked(&mut self.get_unchecked_mut().inner) } }