stm32/gpio: remove generics.

This commit is contained in:
Dario Nieuwenhuis 2024-01-22 20:12:36 +01:00
parent 9f76dbb93b
commit 3387ee7238
29 changed files with 144 additions and 215 deletions

View File

@ -3,14 +3,14 @@
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::gpio::{Level, Output, Pull, Speed};
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
let mut led = Output::new(p.PB14, Level::Low, Speed::VeryHigh);
let mut button = ExtiInput::new(Input::new(p.PC13, Pull::Up), p.EXTI13);
let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Up);
loop {
button.wait_for_any_edge().await;

View File

@ -6,13 +6,12 @@ use core::cell::RefCell;
use cortex_m::interrupt::Mutex;
use cortex_m::peripheral::NVIC;
use cortex_m_rt::entry;
use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed};
use embassy_stm32::peripherals::{PB14, PC13};
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::{interrupt, pac};
use {defmt_rtt as _, panic_probe as _};
static BUTTON: Mutex<RefCell<Option<Input<'static, PC13>>>> = Mutex::new(RefCell::new(None));
static LED: Mutex<RefCell<Option<Output<'static, PB14>>>> = Mutex::new(RefCell::new(None));
static BUTTON: Mutex<RefCell<Option<Input<'static>>>> = Mutex::new(RefCell::new(None));
static LED: Mutex<RefCell<Option<Output<'static>>>> = Mutex::new(RefCell::new(None));
#[entry]
fn main() -> ! {
@ -62,14 +61,14 @@ fn EXTI15_10() {
const PORT: u8 = 2;
const PIN: usize = 13;
fn check_interrupt<P: Pin>(_pin: &mut Input<'static, P>) -> bool {
fn check_interrupt(_pin: &mut Input<'static>) -> bool {
let exti = pac::EXTI;
let pin = PIN;
let lines = exti.pr(0).read();
lines.line(pin)
}
fn clear_interrupt<P: Pin>(_pin: &mut Input<'static, P>) {
fn clear_interrupt(_pin: &mut Input<'static>) {
let exti = pac::EXTI;
let pin = PIN;
let mut lines = exti.pr(0).read();
@ -77,7 +76,7 @@ fn clear_interrupt<P: Pin>(_pin: &mut Input<'static, P>) {
exti.pr(0).write_value(lines);
}
fn enable_interrupt<P: Pin>(_pin: &mut Input<'static, P>) {
fn enable_interrupt(_pin: &mut Input<'static>) {
cortex_m::interrupt::free(|_| {
let rcc = pac::RCC;
rcc.apb2enr().modify(|w| w.set_syscfgen(true));

View File

@ -5,10 +5,10 @@ use core::marker::PhantomData;
use core::pin::Pin;
use core::task::{Context, Poll};
use embassy_hal_internal::impl_peripheral;
use embassy_hal_internal::{impl_peripheral, into_ref};
use embassy_sync::waitqueue::AtomicWaker;
use crate::gpio::{AnyPin, Input, Level, Pin as GpioPin};
use crate::gpio::{AnyPin, Input, Level, Pin as GpioPin, Pull};
use crate::pac::exti::regs::Lines;
use crate::pac::EXTI;
use crate::{interrupt, pac, peripherals, Peripheral};
@ -93,16 +93,27 @@ impl Iterator for BitIter {
/// EXTI channel, which is a limited resource.
///
/// Pins PA5, PB5, PC5... all use EXTI channel 5, so you can't use EXTI on, say, PA5 and PC5 at the same time.
pub struct ExtiInput<'d, T: GpioPin> {
pin: Input<'d, T>,
pub struct ExtiInput<'d> {
pin: Input<'d>,
}
impl<'d, T: GpioPin> Unpin for ExtiInput<'d, T> {}
impl<'d> Unpin for ExtiInput<'d> {}
impl<'d, T: GpioPin> ExtiInput<'d, T> {
impl<'d> ExtiInput<'d> {
/// Create an EXTI input.
pub fn new(pin: Input<'d, T>, _ch: impl Peripheral<P = T::ExtiChannel> + 'd) -> Self {
Self { pin }
pub fn new<T: GpioPin>(
pin: impl Peripheral<P = T> + 'd,
ch: impl Peripheral<P = T::ExtiChannel> + 'd,
pull: Pull,
) -> Self {
into_ref!(pin, ch);
// Needed if using AnyPin+AnyChannel.
assert_eq!(pin.pin(), ch.number());
Self {
pin: Input::new(pin, pull),
}
}
/// Get whether the pin is high.
@ -162,7 +173,7 @@ impl<'d, T: GpioPin> ExtiInput<'d, T> {
}
}
impl<'d, T: GpioPin> embedded_hal_02::digital::v2::InputPin for ExtiInput<'d, T> {
impl<'d> embedded_hal_02::digital::v2::InputPin for ExtiInput<'d> {
type Error = Infallible;
fn is_high(&self) -> Result<bool, Self::Error> {
@ -174,11 +185,11 @@ impl<'d, T: GpioPin> embedded_hal_02::digital::v2::InputPin for ExtiInput<'d, T>
}
}
impl<'d, T: GpioPin> embedded_hal_1::digital::ErrorType for ExtiInput<'d, T> {
impl<'d> embedded_hal_1::digital::ErrorType for ExtiInput<'d> {
type Error = Infallible;
}
impl<'d, T: GpioPin> embedded_hal_1::digital::InputPin for ExtiInput<'d, T> {
impl<'d> embedded_hal_1::digital::InputPin for ExtiInput<'d> {
fn is_high(&mut self) -> Result<bool, Self::Error> {
Ok((*self).is_high())
}
@ -188,7 +199,7 @@ impl<'d, T: GpioPin> embedded_hal_1::digital::InputPin for ExtiInput<'d, T> {
}
}
impl<'d, T: GpioPin> embedded_hal_async::digital::Wait for ExtiInput<'d, T> {
impl<'d> embedded_hal_async::digital::Wait for ExtiInput<'d> {
async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
self.wait_for_high().await;
Ok(())
@ -326,7 +337,7 @@ pub(crate) mod sealed {
/// EXTI channel trait.
pub trait Channel: sealed::Channel + Sized {
/// Get the EXTI channel number.
fn number(&self) -> usize;
fn number(&self) -> u8;
/// Type-erase (degrade) this channel into an `AnyChannel`.
///
@ -350,8 +361,8 @@ pub struct AnyChannel {
impl_peripheral!(AnyChannel);
impl sealed::Channel for AnyChannel {}
impl Channel for AnyChannel {
fn number(&self) -> usize {
self.number as usize
fn number(&self) -> u8 {
self.number
}
}
@ -359,8 +370,8 @@ macro_rules! impl_exti {
($type:ident, $number:expr) => {
impl sealed::Channel for peripherals::$type {}
impl Channel for peripherals::$type {
fn number(&self) -> usize {
$number as usize
fn number(&self) -> u8 {
$number
}
}
};

View File

@ -6,6 +6,7 @@ use core::convert::Infallible;
use critical_section::CriticalSection;
use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef};
use self::sealed::Pin as _;
use crate::pac::gpio::{self, vals};
use crate::{pac, peripherals, Peripheral};
@ -14,41 +15,21 @@ use crate::{pac, peripherals, Peripheral};
/// This pin can either be a disconnected, input, or output pin, or both. The level register bit will remain
/// set while not in output mode, so the pin's level will be 'remembered' when it is not in output
/// mode.
pub struct Flex<'d, T: Pin> {
pub(crate) pin: PeripheralRef<'d, T>,
pub struct Flex<'d> {
pub(crate) pin: PeripheralRef<'d, AnyPin>,
}
impl<'d, T: Pin> Flex<'d, T> {
impl<'d> Flex<'d> {
/// Wrap the pin in a `Flex`.
///
/// The pin remains disconnected. The initial output level is unspecified, but can be changed
/// before the pin is put into output mode.
///
#[inline]
pub fn new(pin: impl Peripheral<P = T> + 'd) -> Self {
pub fn new(pin: impl Peripheral<P = impl Pin> + 'd) -> Self {
into_ref!(pin);
// Pin will be in disconnected state.
Self { pin }
}
/// Type-erase (degrade) this pin into an `AnyPin`.
///
/// This converts pin singletons (`PA5`, `PB6`, ...), which
/// are all different types, into the same type. It is useful for
/// creating arrays of pins, or avoiding generics.
#[inline]
pub fn degrade(self) -> Flex<'d, AnyPin> {
// Safety: We are about to drop the other copy of this pin, so
// this clone is safe.
let pin = unsafe { self.pin.clone_unchecked() };
// We don't want to run the destructor here, because that would
// deconfigure the pin.
core::mem::forget(self);
Flex {
pin: pin.map_into::<AnyPin>(),
}
Self { pin: pin.map_into() }
}
/// Put the pin into input mode.
@ -218,7 +199,7 @@ impl<'d, T: Pin> Flex<'d, T> {
}
}
impl<'d, T: Pin> Drop for Flex<'d, T> {
impl<'d> Drop for Flex<'d> {
#[inline]
fn drop(&mut self) {
critical_section::with(|_| {
@ -309,31 +290,19 @@ impl From<Speed> for vals::Ospeedr {
}
/// GPIO input driver.
pub struct Input<'d, T: Pin> {
pub(crate) pin: Flex<'d, T>,
pub struct Input<'d> {
pub(crate) pin: Flex<'d>,
}
impl<'d, T: Pin> Input<'d, T> {
impl<'d> Input<'d> {
/// Create GPIO input driver for a [Pin] with the provided [Pull] configuration.
#[inline]
pub fn new(pin: impl Peripheral<P = T> + 'd, pull: Pull) -> Self {
pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, pull: Pull) -> Self {
let mut pin = Flex::new(pin);
pin.set_as_input(pull);
Self { pin }
}
/// Type-erase (degrade) this pin into an `AnyPin`.
///
/// This converts pin singletons (`PA5`, `PB6`, ...), which
/// are all different types, into the same type. It is useful for
/// creating arrays of pins, or avoiding generics.
#[inline]
pub fn degrade(self) -> Input<'d, AnyPin> {
Input {
pin: self.pin.degrade(),
}
}
/// Get whether the pin input level is high.
#[inline]
pub fn is_high(&self) -> bool {
@ -386,14 +355,14 @@ impl From<Level> for bool {
/// Note that pins will **return to their floating state** when `Output` is dropped.
/// If pins should retain their state indefinitely, either keep ownership of the
/// `Output`, or pass it to [`core::mem::forget`].
pub struct Output<'d, T: Pin> {
pub(crate) pin: Flex<'d, T>,
pub struct Output<'d> {
pub(crate) pin: Flex<'d>,
}
impl<'d, T: Pin> Output<'d, T> {
impl<'d> Output<'d> {
/// Create GPIO output driver for a [Pin] with the provided [Level] and [Speed] configuration.
#[inline]
pub fn new(pin: impl Peripheral<P = T> + 'd, initial_output: Level, speed: Speed) -> Self {
pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, initial_output: Level, speed: Speed) -> Self {
let mut pin = Flex::new(pin);
match initial_output {
Level::High => pin.set_high(),
@ -403,18 +372,6 @@ impl<'d, T: Pin> Output<'d, T> {
Self { pin }
}
/// Type-erase (degrade) this pin into an `AnyPin`.
///
/// This converts pin singletons (`PA5`, `PB6`, ...), which
/// are all different types, into the same type. It is useful for
/// creating arrays of pins, or avoiding generics.
#[inline]
pub fn degrade(self) -> Output<'d, AnyPin> {
Output {
pin: self.pin.degrade(),
}
}
/// Set the output as high.
#[inline]
pub fn set_high(&mut self) {
@ -463,14 +420,14 @@ impl<'d, T: Pin> Output<'d, T> {
/// Note that pins will **return to their floating state** when `OutputOpenDrain` is dropped.
/// If pins should retain their state indefinitely, either keep ownership of the
/// `OutputOpenDrain`, or pass it to [`core::mem::forget`].
pub struct OutputOpenDrain<'d, T: Pin> {
pub(crate) pin: Flex<'d, T>,
pub struct OutputOpenDrain<'d> {
pub(crate) pin: Flex<'d>,
}
impl<'d, T: Pin> OutputOpenDrain<'d, T> {
impl<'d> OutputOpenDrain<'d> {
/// Create a new GPIO open drain output driver for a [Pin] with the provided [Level] and [Speed], [Pull] configuration.
#[inline]
pub fn new(pin: impl Peripheral<P = T> + 'd, initial_output: Level, speed: Speed, pull: Pull) -> Self {
pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, initial_output: Level, speed: Speed, pull: Pull) -> Self {
let mut pin = Flex::new(pin);
match initial_output {
@ -482,18 +439,6 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> {
Self { pin }
}
/// Type-erase (degrade) this pin into an `AnyPin`.
///
/// This converts pin singletons (`PA5`, `PB6`, ...), which
/// are all different types, into the same type. It is useful for
/// creating arrays of pins, or avoiding generics.
#[inline]
pub fn degrade(self) -> Output<'d, AnyPin> {
Output {
pin: self.pin.degrade(),
}
}
/// Get whether the pin input level is high.
#[inline]
pub fn is_high(&self) -> bool {
@ -836,7 +781,7 @@ pub(crate) unsafe fn init(_cs: CriticalSection) {
});
}
impl<'d, T: Pin> embedded_hal_02::digital::v2::InputPin for Input<'d, T> {
impl<'d> embedded_hal_02::digital::v2::InputPin for Input<'d> {
type Error = Infallible;
#[inline]
@ -850,7 +795,7 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::InputPin for Input<'d, T> {
}
}
impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for Output<'d, T> {
impl<'d> embedded_hal_02::digital::v2::OutputPin for Output<'d> {
type Error = Infallible;
#[inline]
@ -866,7 +811,7 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for Output<'d, T> {
}
}
impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Output<'d, T> {
impl<'d> embedded_hal_02::digital::v2::StatefulOutputPin for Output<'d> {
#[inline]
fn is_set_high(&self) -> Result<bool, Self::Error> {
Ok(self.is_set_high())
@ -879,7 +824,7 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Output<'d,
}
}
impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for Output<'d, T> {
impl<'d> embedded_hal_02::digital::v2::ToggleableOutputPin for Output<'d> {
type Error = Infallible;
#[inline]
fn toggle(&mut self) -> Result<(), Self::Error> {
@ -888,7 +833,7 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for Output<'d
}
}
impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for OutputOpenDrain<'d, T> {
impl<'d> embedded_hal_02::digital::v2::OutputPin for OutputOpenDrain<'d> {
type Error = Infallible;
#[inline]
@ -904,7 +849,7 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for OutputOpenDrain<'d,
}
}
impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for OutputOpenDrain<'d, T> {
impl<'d> embedded_hal_02::digital::v2::StatefulOutputPin for OutputOpenDrain<'d> {
#[inline]
fn is_set_high(&self) -> Result<bool, Self::Error> {
Ok(self.is_set_high())
@ -917,7 +862,7 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for OutputOpenD
}
}
impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for OutputOpenDrain<'d, T> {
impl<'d> embedded_hal_02::digital::v2::ToggleableOutputPin for OutputOpenDrain<'d> {
type Error = Infallible;
#[inline]
fn toggle(&mut self) -> Result<(), Self::Error> {
@ -926,7 +871,7 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for OutputOpe
}
}
impl<'d, T: Pin> embedded_hal_02::digital::v2::InputPin for Flex<'d, T> {
impl<'d> embedded_hal_02::digital::v2::InputPin for Flex<'d> {
type Error = Infallible;
#[inline]
@ -940,7 +885,7 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::InputPin for Flex<'d, T> {
}
}
impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for Flex<'d, T> {
impl<'d> embedded_hal_02::digital::v2::OutputPin for Flex<'d> {
type Error = Infallible;
#[inline]
@ -956,7 +901,7 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for Flex<'d, T> {
}
}
impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Flex<'d, T> {
impl<'d> embedded_hal_02::digital::v2::StatefulOutputPin for Flex<'d> {
#[inline]
fn is_set_high(&self) -> Result<bool, Self::Error> {
Ok(self.is_set_high())
@ -969,7 +914,7 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Flex<'d, T>
}
}
impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for Flex<'d, T> {
impl<'d> embedded_hal_02::digital::v2::ToggleableOutputPin for Flex<'d> {
type Error = Infallible;
#[inline]
fn toggle(&mut self) -> Result<(), Self::Error> {
@ -978,11 +923,11 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for Flex<'d,
}
}
impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Input<'d, T> {
impl<'d> embedded_hal_1::digital::ErrorType for Input<'d> {
type Error = Infallible;
}
impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Input<'d, T> {
impl<'d> embedded_hal_1::digital::InputPin for Input<'d> {
#[inline]
fn is_high(&mut self) -> Result<bool, Self::Error> {
Ok((*self).is_high())
@ -994,11 +939,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Input<'d, T> {
}
}
impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Output<'d, T> {
impl<'d> embedded_hal_1::digital::ErrorType for Output<'d> {
type Error = Infallible;
}
impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Output<'d, T> {
impl<'d> embedded_hal_1::digital::OutputPin for Output<'d> {
#[inline]
fn set_high(&mut self) -> Result<(), Self::Error> {
Ok(self.set_high())
@ -1010,7 +955,7 @@ impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Output<'d, T> {
}
}
impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Output<'d, T> {
impl<'d> embedded_hal_1::digital::StatefulOutputPin for Output<'d> {
#[inline]
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
Ok((*self).is_set_high())
@ -1023,11 +968,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Output<'d, T> {
}
}
impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for OutputOpenDrain<'d, T> {
impl<'d> embedded_hal_1::digital::ErrorType for OutputOpenDrain<'d> {
type Error = Infallible;
}
impl<'d, T: Pin> embedded_hal_1::digital::InputPin for OutputOpenDrain<'d, T> {
impl<'d> embedded_hal_1::digital::InputPin for OutputOpenDrain<'d> {
#[inline]
fn is_high(&mut self) -> Result<bool, Self::Error> {
Ok((*self).is_high())
@ -1039,7 +984,7 @@ impl<'d, T: Pin> embedded_hal_1::digital::InputPin for OutputOpenDrain<'d, T> {
}
}
impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for OutputOpenDrain<'d, T> {
impl<'d> embedded_hal_1::digital::OutputPin for OutputOpenDrain<'d> {
#[inline]
fn set_high(&mut self) -> Result<(), Self::Error> {
Ok(self.set_high())
@ -1051,7 +996,7 @@ impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for OutputOpenDrain<'d, T> {
}
}
impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for OutputOpenDrain<'d, T> {
impl<'d> embedded_hal_1::digital::StatefulOutputPin for OutputOpenDrain<'d> {
#[inline]
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
Ok((*self).is_set_high())
@ -1064,7 +1009,7 @@ impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for OutputOpenDrain<
}
}
impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Flex<'d, T> {
impl<'d> embedded_hal_1::digital::InputPin for Flex<'d> {
#[inline]
fn is_high(&mut self) -> Result<bool, Self::Error> {
Ok((*self).is_high())
@ -1076,7 +1021,7 @@ impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Flex<'d, T> {
}
}
impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Flex<'d, T> {
impl<'d> embedded_hal_1::digital::OutputPin for Flex<'d> {
#[inline]
fn set_high(&mut self) -> Result<(), Self::Error> {
Ok(self.set_high())
@ -1088,11 +1033,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Flex<'d, T> {
}
}
impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Flex<'d, T> {
impl<'d> embedded_hal_1::digital::ErrorType for Flex<'d> {
type Error = Infallible;
}
impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Flex<'d, T> {
impl<'d> embedded_hal_1::digital::StatefulOutputPin for Flex<'d> {
#[inline]
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
Ok((*self).is_set_high())

View File

@ -8,7 +8,7 @@ use embassy_embedded_hal::adapter::BlockingAsync;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::flash::{Flash, WRITE_SIZE};
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::gpio::{Level, Output, Pull, Speed};
use embassy_sync::mutex::Mutex;
use panic_reset as _;
@ -23,8 +23,7 @@ async fn main(_spawner: Spawner) {
let flash = Flash::new_blocking(p.FLASH);
let flash = Mutex::new(BlockingAsync::new(flash));
let button = Input::new(p.PC13, Pull::Up);
let mut button = ExtiInput::new(button, p.EXTI13);
let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Up);
let mut led = Output::new(p.PA5, Level::Low, Speed::Low);
led.set_high();

View File

@ -9,7 +9,7 @@ use embassy_boot_stm32::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdater
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::flash::{Flash, WRITE_SIZE};
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::gpio::{Level, Output, Pull, Speed};
use embassy_sync::blocking_mutex::Mutex;
use embedded_storage::nor_flash::NorFlash;
use panic_reset as _;
@ -25,8 +25,7 @@ async fn main(_spawner: Spawner) {
let flash = Flash::new_blocking(p.FLASH);
let flash = Mutex::new(RefCell::new(flash));
let button = Input::new(p.PC13, Pull::Down);
let mut button = ExtiInput::new(button, p.EXTI13);
let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down);
let mut led = Output::new(p.PB7, Level::Low, Speed::Low);
led.set_high();

View File

@ -9,7 +9,7 @@ use embassy_boot_stm32::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdater
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::flash::{Flash, WRITE_SIZE};
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::gpio::{Level, Output, Pull, Speed};
use embassy_sync::blocking_mutex::Mutex;
use embedded_storage::nor_flash::NorFlash;
use panic_reset as _;
@ -25,8 +25,7 @@ async fn main(_spawner: Spawner) {
let flash = Flash::new_blocking(p.FLASH);
let flash = Mutex::new(RefCell::new(flash));
let button = Input::new(p.PC13, Pull::Down);
let mut button = ExtiInput::new(button, p.EXTI13);
let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down);
let mut led = Output::new(p.PB14, Level::Low, Speed::Low);
led.set_high();

View File

@ -8,7 +8,7 @@ use embassy_embedded_hal::adapter::BlockingAsync;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::flash::{Flash, WRITE_SIZE};
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::gpio::{Level, Output, Pull, Speed};
use embassy_sync::mutex::Mutex;
use embassy_time::Timer;
use panic_reset as _;
@ -24,8 +24,7 @@ async fn main(_spawner: Spawner) {
let flash = Flash::new_blocking(p.FLASH);
let flash = Mutex::new(BlockingAsync::new(flash));
let button = Input::new(p.PB2, Pull::Up);
let mut button = ExtiInput::new(button, p.EXTI2);
let mut button = ExtiInput::new(p.PB2, p.EXTI2, Pull::Up);
let mut led = Output::new(p.PB5, Level::Low, Speed::Low);

View File

@ -8,7 +8,7 @@ use embassy_embedded_hal::adapter::BlockingAsync;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::flash::{Flash, WRITE_SIZE};
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::gpio::{Level, Output, Pull, Speed};
use embassy_sync::mutex::Mutex;
use embassy_time::Timer;
use panic_reset as _;
@ -24,8 +24,7 @@ async fn main(_spawner: Spawner) {
let flash = Flash::new_blocking(p.FLASH);
let flash = Mutex::new(BlockingAsync::new(flash));
let button = Input::new(p.PB2, Pull::Up);
let mut button = ExtiInput::new(button, p.EXTI2);
let mut button = ExtiInput::new(p.PB2, p.EXTI2, Pull::Up);
let mut led = Output::new(p.PB5, Level::Low, Speed::Low);

View File

@ -8,7 +8,7 @@ use embassy_embedded_hal::adapter::BlockingAsync;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::flash::{Flash, WRITE_SIZE};
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::gpio::{Level, Output, Pull, Speed};
use embassy_sync::mutex::Mutex;
use panic_reset as _;
@ -23,8 +23,7 @@ async fn main(_spawner: Spawner) {
let flash = Flash::new_blocking(p.FLASH);
let flash = Mutex::new(BlockingAsync::new(flash));
let button = Input::new(p.PC13, Pull::Up);
let mut button = ExtiInput::new(button, p.EXTI13);
let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Up);
let mut led = Output::new(p.PB14, Level::Low, Speed::Low);
led.set_high();

View File

@ -8,7 +8,7 @@ use embassy_embedded_hal::adapter::BlockingAsync;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::flash::{Flash, WRITE_SIZE};
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::gpio::{Level, Output, Pull, Speed};
use embassy_sync::mutex::Mutex;
use panic_reset as _;
@ -23,8 +23,7 @@ async fn main(_spawner: Spawner) {
let flash = Flash::new_blocking(p.FLASH);
let flash = Mutex::new(BlockingAsync::new(flash));
let button = Input::new(p.PA0, Pull::Up);
let mut button = ExtiInput::new(button, p.EXTI0);
let mut button = ExtiInput::new(p.PA0, p.EXTI0, Pull::Up);
let mut led = Output::new(p.PB9, Level::Low, Speed::Low);
led.set_high();

View File

@ -4,7 +4,7 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{Input, Pull};
use embassy_stm32::gpio::Pull;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
let button = Input::new(p.PC13, Pull::Up);
let mut button = ExtiInput::new(button, p.EXTI13);
let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Up);
info!("Press the USER button...");

View File

@ -8,7 +8,7 @@ use core::sync::atomic::{AtomicU32, Ordering};
use defmt::info;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{AnyPin, Input, Level, Output, Pin, Pull, Speed};
use embassy_stm32::gpio::{AnyPin, Level, Output, Pin, Pull, Speed};
use embassy_time::Timer;
use {defmt_rtt as _, panic_probe as _};
@ -36,8 +36,7 @@ async fn main(spawner: Spawner) {
// Configure the button pin and obtain handler.
// On the Nucleo F091RC there is a button connected to pin PC13.
let button = Input::new(p.PC13, Pull::None);
let mut button = ExtiInput::new(button, p.EXTI13);
let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::None);
// Create and initialize a delay variable to manage delay loop
let mut del_var = 2000;

View File

@ -4,7 +4,7 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{Input, Pull};
use embassy_stm32::gpio::Pull;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@ -13,8 +13,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
// Configure the button pin and obtain handler.
// On the Nucleo F091RC there is a button connected to pin PC13.
let button = Input::new(p.PC13, Pull::Down);
let mut button = ExtiInput::new(button, p.EXTI13);
let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down);
info!("Press the USER button...");
loop {

View File

@ -12,21 +12,20 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{AnyPin, Input, Level, Output, Pin, Pull, Speed};
use embassy_stm32::peripherals::PA0;
use embassy_stm32::gpio::{Level, Output, Pull, Speed};
use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
use embassy_sync::channel::Channel;
use embassy_time::{with_timeout, Duration, Timer};
use {defmt_rtt as _, panic_probe as _};
struct Leds<'a> {
leds: [Output<'a, AnyPin>; 8],
leds: [Output<'a>; 8],
direction: i8,
current_led: usize,
}
impl<'a> Leds<'a> {
fn new(pins: [Output<'a, AnyPin>; 8]) -> Self {
fn new(pins: [Output<'a>; 8]) -> Self {
Self {
leds: pins,
direction: 1,
@ -100,18 +99,17 @@ static CHANNEL: Channel<ThreadModeRawMutex, ButtonEvent, 4> = Channel::new();
#[embassy_executor::main]
async fn main(spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
let button = Input::new(p.PA0, Pull::Down);
let button = ExtiInput::new(button, p.EXTI0);
let button = ExtiInput::new(p.PA0, p.EXTI0, Pull::Down);
info!("Press the USER button...");
let leds = [
Output::new(p.PE9.degrade(), Level::Low, Speed::Low),
Output::new(p.PE10.degrade(), Level::Low, Speed::Low),
Output::new(p.PE11.degrade(), Level::Low, Speed::Low),
Output::new(p.PE12.degrade(), Level::Low, Speed::Low),
Output::new(p.PE13.degrade(), Level::Low, Speed::Low),
Output::new(p.PE14.degrade(), Level::Low, Speed::Low),
Output::new(p.PE15.degrade(), Level::Low, Speed::Low),
Output::new(p.PE8.degrade(), Level::Low, Speed::Low),
Output::new(p.PE9, Level::Low, Speed::Low),
Output::new(p.PE10, Level::Low, Speed::Low),
Output::new(p.PE11, Level::Low, Speed::Low),
Output::new(p.PE12, Level::Low, Speed::Low),
Output::new(p.PE13, Level::Low, Speed::Low),
Output::new(p.PE14, Level::Low, Speed::Low),
Output::new(p.PE15, Level::Low, Speed::Low),
Output::new(p.PE8, Level::Low, Speed::Low),
];
let leds = Leds::new(leds);
@ -127,7 +125,7 @@ async fn led_blinker(mut leds: Leds<'static>) {
}
#[embassy_executor::task]
async fn button_waiter(mut button: ExtiInput<'static, PA0>) {
async fn button_waiter(mut button: ExtiInput<'static>) {
const DOUBLE_CLICK_DELAY: u64 = 250;
const HOLD_DELAY: u64 = 1000;

View File

@ -4,7 +4,7 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{Input, Pull};
use embassy_stm32::gpio::Pull;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
let button = Input::new(p.PA0, Pull::Down);
let mut button = ExtiInput::new(button, p.EXTI0);
let mut button = ExtiInput::new(p.PA0, p.EXTI0, Pull::Down);
info!("Press the USER button...");

View File

@ -4,7 +4,7 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{Input, Pull};
use embassy_stm32::gpio::Pull;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
let button = Input::new(p.PC13, Pull::Down);
let mut button = ExtiInput::new(button, p.EXTI13);
let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down);
info!("Press the USER button...");

View File

@ -4,7 +4,7 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{Input, Pull};
use embassy_stm32::gpio::Pull;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
let button = Input::new(p.PC13, Pull::Down);
let mut button = ExtiInput::new(button, p.EXTI13);
let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down);
info!("Press the USER button...");

View File

@ -4,7 +4,7 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{Input, Pull};
use embassy_stm32::gpio::Pull;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
let button = Input::new(p.PC13, Pull::Up);
let mut button = ExtiInput::new(button, p.EXTI13);
let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Up);
info!("Press the USER button...");

View File

@ -4,7 +4,7 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{Input, Pull};
use embassy_stm32::gpio::Pull;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
let button = Input::new(p.PC13, Pull::Down);
let mut button = ExtiInput::new(button, p.EXTI13);
let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down);
info!("Press the USER button...");

View File

@ -4,7 +4,7 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{Input, Pull};
use embassy_stm32::gpio::Pull;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
let button = Input::new(p.PC13, Pull::Down);
let mut button = ExtiInput::new(button, p.EXTI13);
let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down);
info!("Press the USER button...");

View File

@ -4,7 +4,7 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{Input, Pull};
use embassy_stm32::gpio::Pull;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
let button = Input::new(p.PC13, Pull::Down);
let mut button = ExtiInput::new(button, p.EXTI13);
let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down);
info!("Press the USER button...");

View File

@ -4,7 +4,7 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{Input, Pull};
use embassy_stm32::gpio::Pull;
use embassy_stm32::Config;
use {defmt_rtt as _, panic_probe as _};
@ -13,8 +13,7 @@ async fn main(_spawner: Spawner) {
let config = Config::default();
let p = embassy_stm32::init(config);
let button = Input::new(p.PB2, Pull::Up);
let mut button = ExtiInput::new(button, p.EXTI2);
let mut button = ExtiInput::new(p.PB2, p.EXTI2, Pull::Up);
info!("Press the USER button...");

View File

@ -4,7 +4,7 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{Input, Pull};
use embassy_stm32::gpio::Pull;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
let button = Input::new(p.PC13, Pull::Up);
let mut button = ExtiInput::new(button, p.EXTI13);
let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Up);
info!("Press the USER button...");

View File

@ -58,9 +58,9 @@ const IP_ADDRESS: Ipv4Cidr = Ipv4Cidr::new(Ipv4Address([192, 168, 1, 5]), 24);
const HTTP_LISTEN_PORT: u16 = 80;
pub type SpeSpi = Spi<'static, peripherals::SPI2, peripherals::DMA1_CH1, peripherals::DMA1_CH2>;
pub type SpeSpiCs = ExclusiveDevice<SpeSpi, Output<'static, peripherals::PB12>, Delay>;
pub type SpeInt = exti::ExtiInput<'static, peripherals::PB11>;
pub type SpeRst = Output<'static, peripherals::PC7>;
pub type SpeSpiCs = ExclusiveDevice<SpeSpi, Output<'static>, Delay>;
pub type SpeInt = exti::ExtiInput<'static>;
pub type SpeRst = Output<'static>;
pub type Adin1110T = ADIN1110<SpeSpiCs>;
pub type TempSensI2c = I2c<'static, peripherals::I2C3, peripherals::DMA1_CH6, peripherals::DMA1_CH7>;
@ -134,8 +134,7 @@ async fn main(spawner: Spawner) {
let spe_cfg1 = Input::new(dp.PC9, Pull::None);
let _spe_ts_capt = Output::new(dp.PC6, Level::Low, Speed::Low);
let spe_int = Input::new(dp.PB11, Pull::None);
let spe_int = exti::ExtiInput::new(spe_int, dp.EXTI11);
let spe_int = exti::ExtiInput::new(dp.PB11, dp.EXTI11, Pull::None);
let spe_spi_cs_n = Output::new(dp.PB12, Level::High, Speed::High);
let spe_spi_sclk = dp.PB13;
@ -298,7 +297,7 @@ async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net:
}
#[embassy_executor::task]
async fn heartbeat_led(mut led: Output<'static, peripherals::PE6>) {
async fn heartbeat_led(mut led: Output<'static>) {
let mut tmr = Ticker::every(Duration::from_hz(3));
loop {
led.toggle();
@ -308,7 +307,7 @@ async fn heartbeat_led(mut led: Output<'static, peripherals::PE6>) {
// ADT7422
#[embassy_executor::task]
async fn temp_task(temp_dev_i2c: TempSensI2c, mut led: Output<'static, peripherals::PG15>) -> ! {
async fn temp_task(temp_dev_i2c: TempSensI2c, mut led: Output<'static>) -> ! {
let mut tmr = Ticker::every(Duration::from_hz(1));
let mut temp_sens = ADT7422::new(temp_dev_i2c, 0x48).unwrap();

View File

@ -4,7 +4,7 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{Input, Pull};
use embassy_stm32::gpio::Pull;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
let button = Input::new(p.PC13, Pull::Down);
let mut button = ExtiInput::new(button, p.EXTI13);
let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down);
info!("Press the USER button...");

View File

@ -4,7 +4,7 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{Input, Pull};
use embassy_stm32::gpio::Pull;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
let button = Input::new(p.PC4, Pull::Up);
let mut button = ExtiInput::new(button, p.EXTI4);
let mut button = ExtiInput::new(p.PC4, p.EXTI4, Pull::Up);
info!("Press the USER button...");

View File

@ -4,7 +4,7 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{Input, Pull};
use embassy_stm32::gpio::Pull;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
let button = Input::new(p.PC13, Pull::Up);
let mut button = ExtiInput::new(button, p.EXTI13);
let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Up);
info!("Press the USER button...");

View File

@ -4,7 +4,7 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{Input, Pull};
use embassy_stm32::gpio::Pull;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
let button = Input::new(p.PA0, Pull::Up);
let mut button = ExtiInput::new(button, p.EXTI0);
let mut button = ExtiInput::new(p.PA0, p.EXTI0, Pull::Up);
info!("Press the USER button...");