Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions embassy-stm32/src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use crate::peripherals;
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Flex<'d> {
pub(crate) pin: Peri<'d, AnyPin>,
borrowed: bool,
}

impl<'d> Flex<'d> {
Expand All @@ -30,27 +29,24 @@ impl<'d> Flex<'d> {
#[inline]
pub fn new(pin: Peri<'d, impl Pin>) -> Self {
// Pin will be in disconnected state.
Self {
pin: pin.into(),
borrowed: false,
}
Self { pin: pin.into() }
}

/// Reborrow into a "child" Flex.
///
/// `self` will stay borrowed until the child Peripheral is dropped.
///
/// When the child is dropped, the parent must call set_as to set the Mode again.
pub fn reborrow(&mut self) -> Flex<'_> {
Flex {
pin: self.pin.reborrow(),
borrowed: true,
}
}

/// Unsafely clone (duplicate) a Flex.
pub unsafe fn clone_unchecked(&self) -> Flex<'d> {
Flex {
pin: self.pin.clone_unchecked(),
borrowed: self.borrowed,
}
}

Expand Down Expand Up @@ -257,9 +253,6 @@ impl<'d> Flex<'d> {
impl<'d> Drop for Flex<'d> {
#[inline]
fn drop(&mut self) {
if self.borrowed {
return;
}
trace!("gpio: dropping {}", self.pin);
critical_section::with(|_| {
self.pin.set_as_disconnected();
Expand Down
9 changes: 8 additions & 1 deletion embassy-stm32/src/usart/buffered.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use core::future::poll_fn;
use core::marker::PhantomData;
use core::slice;
use core::sync::atomic::{AtomicBool, AtomicU8, AtomicUsize, Ordering};
use core::task::Poll;
use core::{mem, slice};

use embassy_embedded_hal::SetConfig;
use embassy_hal_internal::Peri;
Expand Down Expand Up @@ -869,6 +869,9 @@ impl<'d> Drop for BufferedUartRx<'d> {
}

drop_tx_rx(self.info, state);
} else {
mem::forget(self.rts.take());
mem::forget(self.rx.take());
}
}
}
Expand All @@ -887,6 +890,10 @@ impl<'d> Drop for BufferedUartTx<'d> {
}
}
drop_tx_rx(self.info, state);
} else {
mem::forget(self.tx.take());
mem::forget(self.cts.take());
mem::forget(self.de.take());
}
}
}
Expand Down