aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/buffered_uarte.rs
diff options
context:
space:
mode:
authorZoey Riordan <[email protected]>2022-09-21 10:47:49 +0200
committerZoey Riordan <[email protected]>2022-09-21 10:48:02 +0200
commit3d708a459c9c5f18ddd5c63a06f272371b6225c8 (patch)
tree1dfb3761c616f6b61122dcd2c9fe364861d06554 /embassy-nrf/src/buffered_uarte.rs
parent11da25800bce338e39082e9d35b1af8db3e5875d (diff)
Implement proper `Drop` for `BufferedUarte`
Diffstat (limited to 'embassy-nrf/src/buffered_uarte.rs')
-rw-r--r--embassy-nrf/src/buffered_uarte.rs31
1 files changed, 17 insertions, 14 deletions
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs
index c3cba2470..84ef86c96 100644
--- a/embassy-nrf/src/buffered_uarte.rs
+++ b/embassy-nrf/src/buffered_uarte.rs
@@ -27,7 +27,7 @@ use futures::future::poll_fn;
27// Re-export SVD variants to allow user to directly set values 27// Re-export SVD variants to allow user to directly set values
28pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; 28pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity};
29 29
30use crate::gpio::Pin as GpioPin; 30use crate::gpio::{self, Pin as GpioPin};
31use crate::interrupt::InterruptExt; 31use crate::interrupt::InterruptExt;
32use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; 32use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task};
33use crate::timer::{Frequency, Instance as TimerInstance, Timer}; 33use crate::timer::{Frequency, Instance as TimerInstance, Timer};
@@ -427,23 +427,26 @@ impl<'u, 'd: 'u, U: UarteInstance, T: TimerInstance> embedded_io::asynch::Write
427 427
428impl<'a, U: UarteInstance, T: TimerInstance> Drop for StateInner<'a, U, T> { 428impl<'a, U: UarteInstance, T: TimerInstance> Drop for StateInner<'a, U, T> {
429 fn drop(&mut self) { 429 fn drop(&mut self) {
430 debug!("oh no, dropping uarte");
430 let r = U::regs(); 431 let r = U::regs();
431 432
432 // TODO this probably deadlocks. do like Uarte instead. 433 // TODO this probably deadlocks. do like Uarte instead.
434 r.inten.reset();
435 r.events_rxto.reset();
436 r.tasks_stoprx.write(|w| w.tasks_stoprx().set_bit());
433 437
434 self.timer.stop(); 438 r.events_txstopped.reset();
435 if let RxState::Receiving = self.rx_state { 439 r.tasks_stoptx.write(|w| w.tasks_stoptx().set_bit());
436 r.tasks_stoprx.write(|w| unsafe { w.bits(1) }); 440 while !r.events_txstopped.read().events_txstopped().bit_is_set() {}
437 } 441
438 if let TxState::Transmitting(_) = self.tx_state { 442 while !r.events_rxto.read().events_rxto().bit_is_set() {}
439 r.tasks_stoptx.write(|w| unsafe { w.bits(1) }); 443
440 } 444 r.enable.write(|w| w.enable().disabled());
441 if let RxState::Receiving = self.rx_state { 445
442 low_power_wait_until(|| r.events_endrx.read().bits() == 1); 446 gpio::deconfigure_pin(r.psel.rxd.read().bits());
443 } 447 gpio::deconfigure_pin(r.psel.txd.read().bits());
444 if let TxState::Transmitting(_) = self.tx_state { 448 gpio::deconfigure_pin(r.psel.rts.read().bits());
445 low_power_wait_until(|| r.events_endtx.read().bits() == 1); 449 gpio::deconfigure_pin(r.psel.cts.read().bits());
446 }
447 } 450 }
448} 451}
449 452