Implement proper Drop
for BufferedUarte
This commit is contained in:
parent
11da25800b
commit
3d708a459c
1 changed files with 17 additions and 14 deletions
|
@ -27,7 +27,7 @@ use futures::future::poll_fn;
|
|||
// Re-export SVD variants to allow user to directly set values
|
||||
pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity};
|
||||
|
||||
use crate::gpio::Pin as GpioPin;
|
||||
use crate::gpio::{self, Pin as GpioPin};
|
||||
use crate::interrupt::InterruptExt;
|
||||
use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task};
|
||||
use crate::timer::{Frequency, Instance as TimerInstance, Timer};
|
||||
|
@ -427,23 +427,26 @@ impl<'u, 'd: 'u, U: UarteInstance, T: TimerInstance> embedded_io::asynch::Write
|
|||
|
||||
impl<'a, U: UarteInstance, T: TimerInstance> Drop for StateInner<'a, U, T> {
|
||||
fn drop(&mut self) {
|
||||
debug!("oh no, dropping uarte");
|
||||
let r = U::regs();
|
||||
|
||||
// TODO this probably deadlocks. do like Uarte instead.
|
||||
r.inten.reset();
|
||||
r.events_rxto.reset();
|
||||
r.tasks_stoprx.write(|w| w.tasks_stoprx().set_bit());
|
||||
|
||||
self.timer.stop();
|
||||
if let RxState::Receiving = self.rx_state {
|
||||
r.tasks_stoprx.write(|w| unsafe { w.bits(1) });
|
||||
}
|
||||
if let TxState::Transmitting(_) = self.tx_state {
|
||||
r.tasks_stoptx.write(|w| unsafe { w.bits(1) });
|
||||
}
|
||||
if let RxState::Receiving = self.rx_state {
|
||||
low_power_wait_until(|| r.events_endrx.read().bits() == 1);
|
||||
}
|
||||
if let TxState::Transmitting(_) = self.tx_state {
|
||||
low_power_wait_until(|| r.events_endtx.read().bits() == 1);
|
||||
}
|
||||
r.events_txstopped.reset();
|
||||
r.tasks_stoptx.write(|w| w.tasks_stoptx().set_bit());
|
||||
while !r.events_txstopped.read().events_txstopped().bit_is_set() {}
|
||||
|
||||
while !r.events_rxto.read().events_rxto().bit_is_set() {}
|
||||
|
||||
r.enable.write(|w| w.enable().disabled());
|
||||
|
||||
gpio::deconfigure_pin(r.psel.rxd.read().bits());
|
||||
gpio::deconfigure_pin(r.psel.txd.read().bits());
|
||||
gpio::deconfigure_pin(r.psel.rts.read().bits());
|
||||
gpio::deconfigure_pin(r.psel.cts.read().bits());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue