diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-01-22 20:12:36 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2024-01-22 21:31:06 +0100 |
| commit | 3387ee7238f1c9c4eeccb732ba543cbe38ab7ccd (patch) | |
| tree | 0b2353dcc0c44c6415a1d765427b59318c6e3a63 | |
| parent | 9f76dbb93b4ab5efc8a0d51b4507ab7eb144fcd9 (diff) | |
stm32/gpio: remove generics.
29 files changed, 144 insertions, 215 deletions
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs index e6753be28..004602816 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs | |||
| @@ -3,14 +3,14 @@ | |||
| 3 | 3 | ||
| 4 | use embassy_executor::Spawner; | 4 | use embassy_executor::Spawner; |
| 5 | use embassy_stm32::exti::ExtiInput; | 5 | use embassy_stm32::exti::ExtiInput; |
| 6 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 6 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| 7 | use {defmt_rtt as _, panic_probe as _}; | 7 | use {defmt_rtt as _, panic_probe as _}; |
| 8 | 8 | ||
| 9 | #[embassy_executor::main] | 9 | #[embassy_executor::main] |
| 10 | async fn main(_spawner: Spawner) { | 10 | async fn main(_spawner: Spawner) { |
| 11 | let p = embassy_stm32::init(Default::default()); | 11 | let p = embassy_stm32::init(Default::default()); |
| 12 | let mut led = Output::new(p.PB14, Level::Low, Speed::VeryHigh); | 12 | let mut led = Output::new(p.PB14, Level::Low, Speed::VeryHigh); |
| 13 | let mut button = ExtiInput::new(Input::new(p.PC13, Pull::Up), p.EXTI13); | 13 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Up); |
| 14 | 14 | ||
| 15 | loop { | 15 | loop { |
| 16 | button.wait_for_any_edge().await; | 16 | button.wait_for_any_edge().await; |
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs index aecba0755..743c9d99b 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs | |||
| @@ -6,13 +6,12 @@ use core::cell::RefCell; | |||
| 6 | use cortex_m::interrupt::Mutex; | 6 | use cortex_m::interrupt::Mutex; |
| 7 | use cortex_m::peripheral::NVIC; | 7 | use cortex_m::peripheral::NVIC; |
| 8 | use cortex_m_rt::entry; | 8 | use cortex_m_rt::entry; |
| 9 | use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed}; | 9 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 10 | use embassy_stm32::peripherals::{PB14, PC13}; | ||
| 11 | use embassy_stm32::{interrupt, pac}; | 10 | use embassy_stm32::{interrupt, pac}; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 12 | ||
| 14 | static BUTTON: Mutex<RefCell<Option<Input<'static, PC13>>>> = Mutex::new(RefCell::new(None)); | 13 | static BUTTON: Mutex<RefCell<Option<Input<'static>>>> = Mutex::new(RefCell::new(None)); |
| 15 | static LED: Mutex<RefCell<Option<Output<'static, PB14>>>> = Mutex::new(RefCell::new(None)); | 14 | static LED: Mutex<RefCell<Option<Output<'static>>>> = Mutex::new(RefCell::new(None)); |
| 16 | 15 | ||
| 17 | #[entry] | 16 | #[entry] |
| 18 | fn main() -> ! { | 17 | fn main() -> ! { |
| @@ -62,14 +61,14 @@ fn EXTI15_10() { | |||
| 62 | 61 | ||
| 63 | const PORT: u8 = 2; | 62 | const PORT: u8 = 2; |
| 64 | const PIN: usize = 13; | 63 | const PIN: usize = 13; |
| 65 | fn check_interrupt<P: Pin>(_pin: &mut Input<'static, P>) -> bool { | 64 | fn check_interrupt(_pin: &mut Input<'static>) -> bool { |
| 66 | let exti = pac::EXTI; | 65 | let exti = pac::EXTI; |
| 67 | let pin = PIN; | 66 | let pin = PIN; |
| 68 | let lines = exti.pr(0).read(); | 67 | let lines = exti.pr(0).read(); |
| 69 | lines.line(pin) | 68 | lines.line(pin) |
| 70 | } | 69 | } |
| 71 | 70 | ||
| 72 | fn clear_interrupt<P: Pin>(_pin: &mut Input<'static, P>) { | 71 | fn clear_interrupt(_pin: &mut Input<'static>) { |
| 73 | let exti = pac::EXTI; | 72 | let exti = pac::EXTI; |
| 74 | let pin = PIN; | 73 | let pin = PIN; |
| 75 | let mut lines = exti.pr(0).read(); | 74 | let mut lines = exti.pr(0).read(); |
| @@ -77,7 +76,7 @@ fn clear_interrupt<P: Pin>(_pin: &mut Input<'static, P>) { | |||
| 77 | exti.pr(0).write_value(lines); | 76 | exti.pr(0).write_value(lines); |
| 78 | } | 77 | } |
| 79 | 78 | ||
| 80 | fn enable_interrupt<P: Pin>(_pin: &mut Input<'static, P>) { | 79 | fn enable_interrupt(_pin: &mut Input<'static>) { |
| 81 | cortex_m::interrupt::free(|_| { | 80 | cortex_m::interrupt::free(|_| { |
| 82 | let rcc = pac::RCC; | 81 | let rcc = pac::RCC; |
| 83 | rcc.apb2enr().modify(|w| w.set_syscfgen(true)); | 82 | rcc.apb2enr().modify(|w| w.set_syscfgen(true)); |
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index 2821435ef..bd10ba158 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs | |||
| @@ -5,10 +5,10 @@ use core::marker::PhantomData; | |||
| 5 | use core::pin::Pin; | 5 | use core::pin::Pin; |
| 6 | use core::task::{Context, Poll}; | 6 | use core::task::{Context, Poll}; |
| 7 | 7 | ||
| 8 | use embassy_hal_internal::impl_peripheral; | 8 | use embassy_hal_internal::{impl_peripheral, into_ref}; |
| 9 | use embassy_sync::waitqueue::AtomicWaker; | 9 | use embassy_sync::waitqueue::AtomicWaker; |
| 10 | 10 | ||
| 11 | use crate::gpio::{AnyPin, Input, Level, Pin as GpioPin}; | 11 | use crate::gpio::{AnyPin, Input, Level, Pin as GpioPin, Pull}; |
| 12 | use crate::pac::exti::regs::Lines; | 12 | use crate::pac::exti::regs::Lines; |
| 13 | use crate::pac::EXTI; | 13 | use crate::pac::EXTI; |
| 14 | use crate::{interrupt, pac, peripherals, Peripheral}; | 14 | use crate::{interrupt, pac, peripherals, Peripheral}; |
| @@ -93,16 +93,27 @@ impl Iterator for BitIter { | |||
| 93 | /// EXTI channel, which is a limited resource. | 93 | /// EXTI channel, which is a limited resource. |
| 94 | /// | 94 | /// |
| 95 | /// Pins PA5, PB5, PC5... all use EXTI channel 5, so you can't use EXTI on, say, PA5 and PC5 at the same time. | 95 | /// Pins PA5, PB5, PC5... all use EXTI channel 5, so you can't use EXTI on, say, PA5 and PC5 at the same time. |
| 96 | pub struct ExtiInput<'d, T: GpioPin> { | 96 | pub struct ExtiInput<'d> { |
| 97 | pin: Input<'d, T>, | 97 | pin: Input<'d>, |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | impl<'d, T: GpioPin> Unpin for ExtiInput<'d, T> {} | 100 | impl<'d> Unpin for ExtiInput<'d> {} |
| 101 | 101 | ||
| 102 | impl<'d, T: GpioPin> ExtiInput<'d, T> { | 102 | impl<'d> ExtiInput<'d> { |
| 103 | /// Create an EXTI input. | 103 | /// Create an EXTI input. |
| 104 | pub fn new(pin: Input<'d, T>, _ch: impl Peripheral<P = T::ExtiChannel> + 'd) -> Self { | 104 | pub fn new<T: GpioPin>( |
| 105 | Self { pin } | 105 | pin: impl Peripheral<P = T> + 'd, |
| 106 | ch: impl Peripheral<P = T::ExtiChannel> + 'd, | ||
| 107 | pull: Pull, | ||
| 108 | ) -> Self { | ||
| 109 | into_ref!(pin, ch); | ||
| 110 | |||
| 111 | // Needed if using AnyPin+AnyChannel. | ||
| 112 | assert_eq!(pin.pin(), ch.number()); | ||
| 113 | |||
| 114 | Self { | ||
| 115 | pin: Input::new(pin, pull), | ||
| 116 | } | ||
| 106 | } | 117 | } |
| 107 | 118 | ||
| 108 | /// Get whether the pin is high. | 119 | /// Get whether the pin is high. |
| @@ -162,7 +173,7 @@ impl<'d, T: GpioPin> ExtiInput<'d, T> { | |||
| 162 | } | 173 | } |
| 163 | } | 174 | } |
| 164 | 175 | ||
| 165 | impl<'d, T: GpioPin> embedded_hal_02::digital::v2::InputPin for ExtiInput<'d, T> { | 176 | impl<'d> embedded_hal_02::digital::v2::InputPin for ExtiInput<'d> { |
| 166 | type Error = Infallible; | 177 | type Error = Infallible; |
| 167 | 178 | ||
| 168 | fn is_high(&self) -> Result<bool, Self::Error> { | 179 | 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> | |||
| 174 | } | 185 | } |
| 175 | } | 186 | } |
| 176 | 187 | ||
| 177 | impl<'d, T: GpioPin> embedded_hal_1::digital::ErrorType for ExtiInput<'d, T> { | 188 | impl<'d> embedded_hal_1::digital::ErrorType for ExtiInput<'d> { |
| 178 | type Error = Infallible; | 189 | type Error = Infallible; |
| 179 | } | 190 | } |
| 180 | 191 | ||
| 181 | impl<'d, T: GpioPin> embedded_hal_1::digital::InputPin for ExtiInput<'d, T> { | 192 | impl<'d> embedded_hal_1::digital::InputPin for ExtiInput<'d> { |
| 182 | fn is_high(&mut self) -> Result<bool, Self::Error> { | 193 | fn is_high(&mut self) -> Result<bool, Self::Error> { |
| 183 | Ok((*self).is_high()) | 194 | Ok((*self).is_high()) |
| 184 | } | 195 | } |
| @@ -188,7 +199,7 @@ impl<'d, T: GpioPin> embedded_hal_1::digital::InputPin for ExtiInput<'d, T> { | |||
| 188 | } | 199 | } |
| 189 | } | 200 | } |
| 190 | 201 | ||
| 191 | impl<'d, T: GpioPin> embedded_hal_async::digital::Wait for ExtiInput<'d, T> { | 202 | impl<'d> embedded_hal_async::digital::Wait for ExtiInput<'d> { |
| 192 | async fn wait_for_high(&mut self) -> Result<(), Self::Error> { | 203 | async fn wait_for_high(&mut self) -> Result<(), Self::Error> { |
| 193 | self.wait_for_high().await; | 204 | self.wait_for_high().await; |
| 194 | Ok(()) | 205 | Ok(()) |
| @@ -326,7 +337,7 @@ pub(crate) mod sealed { | |||
| 326 | /// EXTI channel trait. | 337 | /// EXTI channel trait. |
| 327 | pub trait Channel: sealed::Channel + Sized { | 338 | pub trait Channel: sealed::Channel + Sized { |
| 328 | /// Get the EXTI channel number. | 339 | /// Get the EXTI channel number. |
| 329 | fn number(&self) -> usize; | 340 | fn number(&self) -> u8; |
| 330 | 341 | ||
| 331 | /// Type-erase (degrade) this channel into an `AnyChannel`. | 342 | /// Type-erase (degrade) this channel into an `AnyChannel`. |
| 332 | /// | 343 | /// |
| @@ -350,8 +361,8 @@ pub struct AnyChannel { | |||
| 350 | impl_peripheral!(AnyChannel); | 361 | impl_peripheral!(AnyChannel); |
| 351 | impl sealed::Channel for AnyChannel {} | 362 | impl sealed::Channel for AnyChannel {} |
| 352 | impl Channel for AnyChannel { | 363 | impl Channel for AnyChannel { |
| 353 | fn number(&self) -> usize { | 364 | fn number(&self) -> u8 { |
| 354 | self.number as usize | 365 | self.number |
| 355 | } | 366 | } |
| 356 | } | 367 | } |
| 357 | 368 | ||
| @@ -359,8 +370,8 @@ macro_rules! impl_exti { | |||
| 359 | ($type:ident, $number:expr) => { | 370 | ($type:ident, $number:expr) => { |
| 360 | impl sealed::Channel for peripherals::$type {} | 371 | impl sealed::Channel for peripherals::$type {} |
| 361 | impl Channel for peripherals::$type { | 372 | impl Channel for peripherals::$type { |
| 362 | fn number(&self) -> usize { | 373 | fn number(&self) -> u8 { |
| 363 | $number as usize | 374 | $number |
| 364 | } | 375 | } |
| 365 | } | 376 | } |
| 366 | }; | 377 | }; |
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index 7eb70496f..1051a13c8 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs | |||
| @@ -6,6 +6,7 @@ use core::convert::Infallible; | |||
| 6 | use critical_section::CriticalSection; | 6 | use critical_section::CriticalSection; |
| 7 | use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef}; | 7 | use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef}; |
| 8 | 8 | ||
| 9 | use self::sealed::Pin as _; | ||
| 9 | use crate::pac::gpio::{self, vals}; | 10 | use crate::pac::gpio::{self, vals}; |
| 10 | use crate::{pac, peripherals, Peripheral}; | 11 | use crate::{pac, peripherals, Peripheral}; |
| 11 | 12 | ||
| @@ -14,41 +15,21 @@ use crate::{pac, peripherals, Peripheral}; | |||
| 14 | /// This pin can either be a disconnected, input, or output pin, or both. The level register bit will remain | 15 | /// This pin can either be a disconnected, input, or output pin, or both. The level register bit will remain |
| 15 | /// set while not in output mode, so the pin's level will be 'remembered' when it is not in output | 16 | /// set while not in output mode, so the pin's level will be 'remembered' when it is not in output |
| 16 | /// mode. | 17 | /// mode. |
| 17 | pub struct Flex<'d, T: Pin> { | 18 | pub struct Flex<'d> { |
| 18 | pub(crate) pin: PeripheralRef<'d, T>, | 19 | pub(crate) pin: PeripheralRef<'d, AnyPin>, |
| 19 | } | 20 | } |
| 20 | 21 | ||
| 21 | impl<'d, T: Pin> Flex<'d, T> { | 22 | impl<'d> Flex<'d> { |
| 22 | /// Wrap the pin in a `Flex`. | 23 | /// Wrap the pin in a `Flex`. |
| 23 | /// | 24 | /// |
| 24 | /// The pin remains disconnected. The initial output level is unspecified, but can be changed | 25 | /// The pin remains disconnected. The initial output level is unspecified, but can be changed |
| 25 | /// before the pin is put into output mode. | 26 | /// before the pin is put into output mode. |
| 26 | /// | 27 | /// |
| 27 | #[inline] | 28 | #[inline] |
| 28 | pub fn new(pin: impl Peripheral<P = T> + 'd) -> Self { | 29 | pub fn new(pin: impl Peripheral<P = impl Pin> + 'd) -> Self { |
| 29 | into_ref!(pin); | 30 | into_ref!(pin); |
| 30 | // Pin will be in disconnected state. | 31 | // Pin will be in disconnected state. |
| 31 | Self { pin } | 32 | Self { pin: pin.map_into() } |
| 32 | } | ||
| 33 | |||
| 34 | /// Type-erase (degrade) this pin into an `AnyPin`. | ||
| 35 | /// | ||
| 36 | /// This converts pin singletons (`PA5`, `PB6`, ...), which | ||
| 37 | /// are all different types, into the same type. It is useful for | ||
| 38 | /// creating arrays of pins, or avoiding generics. | ||
| 39 | #[inline] | ||
| 40 | pub fn degrade(self) -> Flex<'d, AnyPin> { | ||
| 41 | // Safety: We are about to drop the other copy of this pin, so | ||
| 42 | // this clone is safe. | ||
| 43 | let pin = unsafe { self.pin.clone_unchecked() }; | ||
| 44 | |||
| 45 | // We don't want to run the destructor here, because that would | ||
| 46 | // deconfigure the pin. | ||
| 47 | core::mem::forget(self); | ||
| 48 | |||
| 49 | Flex { | ||
| 50 | pin: pin.map_into::<AnyPin>(), | ||
| 51 | } | ||
| 52 | } | 33 | } |
| 53 | 34 | ||
| 54 | /// Put the pin into input mode. | 35 | /// Put the pin into input mode. |
| @@ -218,7 +199,7 @@ impl<'d, T: Pin> Flex<'d, T> { | |||
| 218 | } | 199 | } |
| 219 | } | 200 | } |
| 220 | 201 | ||
| 221 | impl<'d, T: Pin> Drop for Flex<'d, T> { | 202 | impl<'d> Drop for Flex<'d> { |
| 222 | #[inline] | 203 | #[inline] |
| 223 | fn drop(&mut self) { | 204 | fn drop(&mut self) { |
| 224 | critical_section::with(|_| { | 205 | critical_section::with(|_| { |
| @@ -309,31 +290,19 @@ impl From<Speed> for vals::Ospeedr { | |||
| 309 | } | 290 | } |
| 310 | 291 | ||
| 311 | /// GPIO input driver. | 292 | /// GPIO input driver. |
| 312 | pub struct Input<'d, T: Pin> { | 293 | pub struct Input<'d> { |
| 313 | pub(crate) pin: Flex<'d, T>, | 294 | pub(crate) pin: Flex<'d>, |
| 314 | } | 295 | } |
| 315 | 296 | ||
| 316 | impl<'d, T: Pin> Input<'d, T> { | 297 | impl<'d> Input<'d> { |
| 317 | /// Create GPIO input driver for a [Pin] with the provided [Pull] configuration. | 298 | /// Create GPIO input driver for a [Pin] with the provided [Pull] configuration. |
| 318 | #[inline] | 299 | #[inline] |
| 319 | pub fn new(pin: impl Peripheral<P = T> + 'd, pull: Pull) -> Self { | 300 | pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, pull: Pull) -> Self { |
| 320 | let mut pin = Flex::new(pin); | 301 | let mut pin = Flex::new(pin); |
| 321 | pin.set_as_input(pull); | 302 | pin.set_as_input(pull); |
| 322 | Self { pin } | 303 | Self { pin } |
| 323 | } | 304 | } |
| 324 | 305 | ||
| 325 | /// Type-erase (degrade) this pin into an `AnyPin`. | ||
| 326 | /// | ||
| 327 | /// This converts pin singletons (`PA5`, `PB6`, ...), which | ||
| 328 | /// are all different types, into the same type. It is useful for | ||
| 329 | /// creating arrays of pins, or avoiding generics. | ||
| 330 | #[inline] | ||
| 331 | pub fn degrade(self) -> Input<'d, AnyPin> { | ||
| 332 | Input { | ||
| 333 | pin: self.pin.degrade(), | ||
| 334 | } | ||
| 335 | } | ||
| 336 | |||
| 337 | /// Get whether the pin input level is high. | 306 | /// Get whether the pin input level is high. |
| 338 | #[inline] | 307 | #[inline] |
| 339 | pub fn is_high(&self) -> bool { | 308 | pub fn is_high(&self) -> bool { |
| @@ -386,14 +355,14 @@ impl From<Level> for bool { | |||
| 386 | /// Note that pins will **return to their floating state** when `Output` is dropped. | 355 | /// Note that pins will **return to their floating state** when `Output` is dropped. |
| 387 | /// If pins should retain their state indefinitely, either keep ownership of the | 356 | /// If pins should retain their state indefinitely, either keep ownership of the |
| 388 | /// `Output`, or pass it to [`core::mem::forget`]. | 357 | /// `Output`, or pass it to [`core::mem::forget`]. |
| 389 | pub struct Output<'d, T: Pin> { | 358 | pub struct Output<'d> { |
| 390 | pub(crate) pin: Flex<'d, T>, | 359 | pub(crate) pin: Flex<'d>, |
| 391 | } | 360 | } |
| 392 | 361 | ||
| 393 | impl<'d, T: Pin> Output<'d, T> { | 362 | impl<'d> Output<'d> { |
| 394 | /// Create GPIO output driver for a [Pin] with the provided [Level] and [Speed] configuration. | 363 | /// Create GPIO output driver for a [Pin] with the provided [Level] and [Speed] configuration. |
| 395 | #[inline] | 364 | #[inline] |
| 396 | pub fn new(pin: impl Peripheral<P = T> + 'd, initial_output: Level, speed: Speed) -> Self { | 365 | pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, initial_output: Level, speed: Speed) -> Self { |
| 397 | let mut pin = Flex::new(pin); | 366 | let mut pin = Flex::new(pin); |
| 398 | match initial_output { | 367 | match initial_output { |
| 399 | Level::High => pin.set_high(), | 368 | Level::High => pin.set_high(), |
| @@ -403,18 +372,6 @@ impl<'d, T: Pin> Output<'d, T> { | |||
| 403 | Self { pin } | 372 | Self { pin } |
| 404 | } | 373 | } |
| 405 | 374 | ||
| 406 | /// Type-erase (degrade) this pin into an `AnyPin`. | ||
| 407 | /// | ||
| 408 | /// This converts pin singletons (`PA5`, `PB6`, ...), which | ||
| 409 | /// are all different types, into the same type. It is useful for | ||
| 410 | /// creating arrays of pins, or avoiding generics. | ||
| 411 | #[inline] | ||
| 412 | pub fn degrade(self) -> Output<'d, AnyPin> { | ||
| 413 | Output { | ||
| 414 | pin: self.pin.degrade(), | ||
| 415 | } | ||
| 416 | } | ||
| 417 | |||
| 418 | /// Set the output as high. | 375 | /// Set the output as high. |
| 419 | #[inline] | 376 | #[inline] |
| 420 | pub fn set_high(&mut self) { | 377 | pub fn set_high(&mut self) { |
| @@ -463,14 +420,14 @@ impl<'d, T: Pin> Output<'d, T> { | |||
| 463 | /// Note that pins will **return to their floating state** when `OutputOpenDrain` is dropped. | 420 | /// Note that pins will **return to their floating state** when `OutputOpenDrain` is dropped. |
| 464 | /// If pins should retain their state indefinitely, either keep ownership of the | 421 | /// If pins should retain their state indefinitely, either keep ownership of the |
| 465 | /// `OutputOpenDrain`, or pass it to [`core::mem::forget`]. | 422 | /// `OutputOpenDrain`, or pass it to [`core::mem::forget`]. |
| 466 | pub struct OutputOpenDrain<'d, T: Pin> { | 423 | pub struct OutputOpenDrain<'d> { |
| 467 | pub(crate) pin: Flex<'d, T>, | 424 | pub(crate) pin: Flex<'d>, |
| 468 | } | 425 | } |
| 469 | 426 | ||
| 470 | impl<'d, T: Pin> OutputOpenDrain<'d, T> { | 427 | impl<'d> OutputOpenDrain<'d> { |
| 471 | /// Create a new GPIO open drain output driver for a [Pin] with the provided [Level] and [Speed], [Pull] configuration. | 428 | /// Create a new GPIO open drain output driver for a [Pin] with the provided [Level] and [Speed], [Pull] configuration. |
| 472 | #[inline] | 429 | #[inline] |
| 473 | pub fn new(pin: impl Peripheral<P = T> + 'd, initial_output: Level, speed: Speed, pull: Pull) -> Self { | 430 | pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, initial_output: Level, speed: Speed, pull: Pull) -> Self { |
| 474 | let mut pin = Flex::new(pin); | 431 | let mut pin = Flex::new(pin); |
| 475 | 432 | ||
| 476 | match initial_output { | 433 | match initial_output { |
| @@ -482,18 +439,6 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { | |||
| 482 | Self { pin } | 439 | Self { pin } |
| 483 | } | 440 | } |
| 484 | 441 | ||
| 485 | /// Type-erase (degrade) this pin into an `AnyPin`. | ||
| 486 | /// | ||
| 487 | /// This converts pin singletons (`PA5`, `PB6`, ...), which | ||
| 488 | /// are all different types, into the same type. It is useful for | ||
| 489 | /// creating arrays of pins, or avoiding generics. | ||
| 490 | #[inline] | ||
| 491 | pub fn degrade(self) -> Output<'d, AnyPin> { | ||
| 492 | Output { | ||
| 493 | pin: self.pin.degrade(), | ||
| 494 | } | ||
| 495 | } | ||
| 496 | |||
| 497 | /// Get whether the pin input level is high. | 442 | /// Get whether the pin input level is high. |
| 498 | #[inline] | 443 | #[inline] |
| 499 | pub fn is_high(&self) -> bool { | 444 | pub fn is_high(&self) -> bool { |
| @@ -836,7 +781,7 @@ pub(crate) unsafe fn init(_cs: CriticalSection) { | |||
| 836 | }); | 781 | }); |
| 837 | } | 782 | } |
| 838 | 783 | ||
| 839 | impl<'d, T: Pin> embedded_hal_02::digital::v2::InputPin for Input<'d, T> { | 784 | impl<'d> embedded_hal_02::digital::v2::InputPin for Input<'d> { |
| 840 | type Error = Infallible; | 785 | type Error = Infallible; |
| 841 | 786 | ||
| 842 | #[inline] | 787 | #[inline] |
| @@ -850,7 +795,7 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::InputPin for Input<'d, T> { | |||
| 850 | } | 795 | } |
| 851 | } | 796 | } |
| 852 | 797 | ||
| 853 | impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for Output<'d, T> { | 798 | impl<'d> embedded_hal_02::digital::v2::OutputPin for Output<'d> { |
| 854 | type Error = Infallible; | 799 | type Error = Infallible; |
| 855 | 800 | ||
| 856 | #[inline] | 801 | #[inline] |
| @@ -866,7 +811,7 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for Output<'d, T> { | |||
| 866 | } | 811 | } |
| 867 | } | 812 | } |
| 868 | 813 | ||
| 869 | impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Output<'d, T> { | 814 | impl<'d> embedded_hal_02::digital::v2::StatefulOutputPin for Output<'d> { |
| 870 | #[inline] | 815 | #[inline] |
| 871 | fn is_set_high(&self) -> Result<bool, Self::Error> { | 816 | fn is_set_high(&self) -> Result<bool, Self::Error> { |
| 872 | Ok(self.is_set_high()) | 817 | Ok(self.is_set_high()) |
| @@ -879,7 +824,7 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Output<'d, | |||
| 879 | } | 824 | } |
| 880 | } | 825 | } |
| 881 | 826 | ||
| 882 | impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for Output<'d, T> { | 827 | impl<'d> embedded_hal_02::digital::v2::ToggleableOutputPin for Output<'d> { |
| 883 | type Error = Infallible; | 828 | type Error = Infallible; |
| 884 | #[inline] | 829 | #[inline] |
| 885 | fn toggle(&mut self) -> Result<(), Self::Error> { | 830 | fn toggle(&mut self) -> Result<(), Self::Error> { |
| @@ -888,7 +833,7 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for Output<'d | |||
| 888 | } | 833 | } |
| 889 | } | 834 | } |
| 890 | 835 | ||
| 891 | impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for OutputOpenDrain<'d, T> { | 836 | impl<'d> embedded_hal_02::digital::v2::OutputPin for OutputOpenDrain<'d> { |
| 892 | type Error = Infallible; | 837 | type Error = Infallible; |
| 893 | 838 | ||
| 894 | #[inline] | 839 | #[inline] |
| @@ -904,7 +849,7 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for OutputOpenDrain<'d, | |||
| 904 | } | 849 | } |
| 905 | } | 850 | } |
| 906 | 851 | ||
| 907 | impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for OutputOpenDrain<'d, T> { | 852 | impl<'d> embedded_hal_02::digital::v2::StatefulOutputPin for OutputOpenDrain<'d> { |
| 908 | #[inline] | 853 | #[inline] |
| 909 | fn is_set_high(&self) -> Result<bool, Self::Error> { | 854 | fn is_set_high(&self) -> Result<bool, Self::Error> { |
| 910 | Ok(self.is_set_high()) | 855 | Ok(self.is_set_high()) |
| @@ -917,7 +862,7 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for OutputOpenD | |||
| 917 | } | 862 | } |
| 918 | } | 863 | } |
| 919 | 864 | ||
| 920 | impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for OutputOpenDrain<'d, T> { | 865 | impl<'d> embedded_hal_02::digital::v2::ToggleableOutputPin for OutputOpenDrain<'d> { |
| 921 | type Error = Infallible; | 866 | type Error = Infallible; |
| 922 | #[inline] | 867 | #[inline] |
| 923 | fn toggle(&mut self) -> Result<(), Self::Error> { | 868 | fn toggle(&mut self) -> Result<(), Self::Error> { |
| @@ -926,7 +871,7 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for OutputOpe | |||
| 926 | } | 871 | } |
| 927 | } | 872 | } |
| 928 | 873 | ||
| 929 | impl<'d, T: Pin> embedded_hal_02::digital::v2::InputPin for Flex<'d, T> { | 874 | impl<'d> embedded_hal_02::digital::v2::InputPin for Flex<'d> { |
| 930 | type Error = Infallible; | 875 | type Error = Infallible; |
| 931 | 876 | ||
| 932 | #[inline] | 877 | #[inline] |
| @@ -940,7 +885,7 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::InputPin for Flex<'d, T> { | |||
| 940 | } | 885 | } |
| 941 | } | 886 | } |
| 942 | 887 | ||
| 943 | impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for Flex<'d, T> { | 888 | impl<'d> embedded_hal_02::digital::v2::OutputPin for Flex<'d> { |
| 944 | type Error = Infallible; | 889 | type Error = Infallible; |
| 945 | 890 | ||
| 946 | #[inline] | 891 | #[inline] |
| @@ -956,7 +901,7 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for Flex<'d, T> { | |||
| 956 | } | 901 | } |
| 957 | } | 902 | } |
| 958 | 903 | ||
| 959 | impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Flex<'d, T> { | 904 | impl<'d> embedded_hal_02::digital::v2::StatefulOutputPin for Flex<'d> { |
| 960 | #[inline] | 905 | #[inline] |
| 961 | fn is_set_high(&self) -> Result<bool, Self::Error> { | 906 | fn is_set_high(&self) -> Result<bool, Self::Error> { |
| 962 | Ok(self.is_set_high()) | 907 | Ok(self.is_set_high()) |
| @@ -969,7 +914,7 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Flex<'d, T> | |||
| 969 | } | 914 | } |
| 970 | } | 915 | } |
| 971 | 916 | ||
| 972 | impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for Flex<'d, T> { | 917 | impl<'d> embedded_hal_02::digital::v2::ToggleableOutputPin for Flex<'d> { |
| 973 | type Error = Infallible; | 918 | type Error = Infallible; |
| 974 | #[inline] | 919 | #[inline] |
| 975 | fn toggle(&mut self) -> Result<(), Self::Error> { | 920 | fn toggle(&mut self) -> Result<(), Self::Error> { |
| @@ -978,11 +923,11 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for Flex<'d, | |||
| 978 | } | 923 | } |
| 979 | } | 924 | } |
| 980 | 925 | ||
| 981 | impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Input<'d, T> { | 926 | impl<'d> embedded_hal_1::digital::ErrorType for Input<'d> { |
| 982 | type Error = Infallible; | 927 | type Error = Infallible; |
| 983 | } | 928 | } |
| 984 | 929 | ||
| 985 | impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Input<'d, T> { | 930 | impl<'d> embedded_hal_1::digital::InputPin for Input<'d> { |
| 986 | #[inline] | 931 | #[inline] |
| 987 | fn is_high(&mut self) -> Result<bool, Self::Error> { | 932 | fn is_high(&mut self) -> Result<bool, Self::Error> { |
| 988 | Ok((*self).is_high()) | 933 | Ok((*self).is_high()) |
| @@ -994,11 +939,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Input<'d, T> { | |||
| 994 | } | 939 | } |
| 995 | } | 940 | } |
| 996 | 941 | ||
| 997 | impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Output<'d, T> { | 942 | impl<'d> embedded_hal_1::digital::ErrorType for Output<'d> { |
| 998 | type Error = Infallible; | 943 | type Error = Infallible; |
| 999 | } | 944 | } |
| 1000 | 945 | ||
| 1001 | impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Output<'d, T> { | 946 | impl<'d> embedded_hal_1::digital::OutputPin for Output<'d> { |
| 1002 | #[inline] | 947 | #[inline] |
| 1003 | fn set_high(&mut self) -> Result<(), Self::Error> { | 948 | fn set_high(&mut self) -> Result<(), Self::Error> { |
| 1004 | Ok(self.set_high()) | 949 | Ok(self.set_high()) |
| @@ -1010,7 +955,7 @@ impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Output<'d, T> { | |||
| 1010 | } | 955 | } |
| 1011 | } | 956 | } |
| 1012 | 957 | ||
| 1013 | impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Output<'d, T> { | 958 | impl<'d> embedded_hal_1::digital::StatefulOutputPin for Output<'d> { |
| 1014 | #[inline] | 959 | #[inline] |
| 1015 | fn is_set_high(&mut self) -> Result<bool, Self::Error> { | 960 | fn is_set_high(&mut self) -> Result<bool, Self::Error> { |
| 1016 | Ok((*self).is_set_high()) | 961 | Ok((*self).is_set_high()) |
| @@ -1023,11 +968,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Output<'d, T> { | |||
| 1023 | } | 968 | } |
| 1024 | } | 969 | } |
| 1025 | 970 | ||
| 1026 | impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for OutputOpenDrain<'d, T> { | 971 | impl<'d> embedded_hal_1::digital::ErrorType for OutputOpenDrain<'d> { |
| 1027 | type Error = Infallible; | 972 | type Error = Infallible; |
| 1028 | } | 973 | } |
| 1029 | 974 | ||
| 1030 | impl<'d, T: Pin> embedded_hal_1::digital::InputPin for OutputOpenDrain<'d, T> { | 975 | impl<'d> embedded_hal_1::digital::InputPin for OutputOpenDrain<'d> { |
| 1031 | #[inline] | 976 | #[inline] |
| 1032 | fn is_high(&mut self) -> Result<bool, Self::Error> { | 977 | fn is_high(&mut self) -> Result<bool, Self::Error> { |
| 1033 | Ok((*self).is_high()) | 978 | Ok((*self).is_high()) |
| @@ -1039,7 +984,7 @@ impl<'d, T: Pin> embedded_hal_1::digital::InputPin for OutputOpenDrain<'d, T> { | |||
| 1039 | } | 984 | } |
| 1040 | } | 985 | } |
| 1041 | 986 | ||
| 1042 | impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for OutputOpenDrain<'d, T> { | 987 | impl<'d> embedded_hal_1::digital::OutputPin for OutputOpenDrain<'d> { |
| 1043 | #[inline] | 988 | #[inline] |
| 1044 | fn set_high(&mut self) -> Result<(), Self::Error> { | 989 | fn set_high(&mut self) -> Result<(), Self::Error> { |
| 1045 | Ok(self.set_high()) | 990 | Ok(self.set_high()) |
| @@ -1051,7 +996,7 @@ impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for OutputOpenDrain<'d, T> { | |||
| 1051 | } | 996 | } |
| 1052 | } | 997 | } |
| 1053 | 998 | ||
| 1054 | impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for OutputOpenDrain<'d, T> { | 999 | impl<'d> embedded_hal_1::digital::StatefulOutputPin for OutputOpenDrain<'d> { |
| 1055 | #[inline] | 1000 | #[inline] |
| 1056 | fn is_set_high(&mut self) -> Result<bool, Self::Error> { | 1001 | fn is_set_high(&mut self) -> Result<bool, Self::Error> { |
| 1057 | Ok((*self).is_set_high()) | 1002 | Ok((*self).is_set_high()) |
| @@ -1064,7 +1009,7 @@ impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for OutputOpenDrain< | |||
| 1064 | } | 1009 | } |
| 1065 | } | 1010 | } |
| 1066 | 1011 | ||
| 1067 | impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Flex<'d, T> { | 1012 | impl<'d> embedded_hal_1::digital::InputPin for Flex<'d> { |
| 1068 | #[inline] | 1013 | #[inline] |
| 1069 | fn is_high(&mut self) -> Result<bool, Self::Error> { | 1014 | fn is_high(&mut self) -> Result<bool, Self::Error> { |
| 1070 | Ok((*self).is_high()) | 1015 | Ok((*self).is_high()) |
| @@ -1076,7 +1021,7 @@ impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Flex<'d, T> { | |||
| 1076 | } | 1021 | } |
| 1077 | } | 1022 | } |
| 1078 | 1023 | ||
| 1079 | impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Flex<'d, T> { | 1024 | impl<'d> embedded_hal_1::digital::OutputPin for Flex<'d> { |
| 1080 | #[inline] | 1025 | #[inline] |
| 1081 | fn set_high(&mut self) -> Result<(), Self::Error> { | 1026 | fn set_high(&mut self) -> Result<(), Self::Error> { |
| 1082 | Ok(self.set_high()) | 1027 | Ok(self.set_high()) |
| @@ -1088,11 +1033,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Flex<'d, T> { | |||
| 1088 | } | 1033 | } |
| 1089 | } | 1034 | } |
| 1090 | 1035 | ||
| 1091 | impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Flex<'d, T> { | 1036 | impl<'d> embedded_hal_1::digital::ErrorType for Flex<'d> { |
| 1092 | type Error = Infallible; | 1037 | type Error = Infallible; |
| 1093 | } | 1038 | } |
| 1094 | 1039 | ||
| 1095 | impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Flex<'d, T> { | 1040 | impl<'d> embedded_hal_1::digital::StatefulOutputPin for Flex<'d> { |
| 1096 | #[inline] | 1041 | #[inline] |
| 1097 | fn is_set_high(&mut self) -> Result<bool, Self::Error> { | 1042 | fn is_set_high(&mut self) -> Result<bool, Self::Error> { |
| 1098 | Ok((*self).is_set_high()) | 1043 | Ok((*self).is_set_high()) |
diff --git a/examples/boot/application/stm32f3/src/bin/a.rs b/examples/boot/application/stm32f3/src/bin/a.rs index 96ae5c47b..3f9ebe5c8 100644 --- a/examples/boot/application/stm32f3/src/bin/a.rs +++ b/examples/boot/application/stm32f3/src/bin/a.rs | |||
| @@ -8,7 +8,7 @@ use embassy_embedded_hal::adapter::BlockingAsync; | |||
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_stm32::exti::ExtiInput; | 9 | use embassy_stm32::exti::ExtiInput; |
| 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 11 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 11 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| 12 | use embassy_sync::mutex::Mutex; | 12 | use embassy_sync::mutex::Mutex; |
| 13 | use panic_reset as _; | 13 | use panic_reset as _; |
| 14 | 14 | ||
| @@ -23,8 +23,7 @@ async fn main(_spawner: Spawner) { | |||
| 23 | let flash = Flash::new_blocking(p.FLASH); | 23 | let flash = Flash::new_blocking(p.FLASH); |
| 24 | let flash = Mutex::new(BlockingAsync::new(flash)); | 24 | let flash = Mutex::new(BlockingAsync::new(flash)); |
| 25 | 25 | ||
| 26 | let button = Input::new(p.PC13, Pull::Up); | 26 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Up); |
| 27 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 28 | 27 | ||
| 29 | let mut led = Output::new(p.PA5, Level::Low, Speed::Low); | 28 | let mut led = Output::new(p.PA5, Level::Low, Speed::Low); |
| 30 | led.set_high(); | 29 | led.set_high(); |
diff --git a/examples/boot/application/stm32f7/src/bin/a.rs b/examples/boot/application/stm32f7/src/bin/a.rs index a6107386a..c57c29263 100644 --- a/examples/boot/application/stm32f7/src/bin/a.rs +++ b/examples/boot/application/stm32f7/src/bin/a.rs | |||
| @@ -9,7 +9,7 @@ use embassy_boot_stm32::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdater | |||
| 9 | use embassy_executor::Spawner; | 9 | use embassy_executor::Spawner; |
| 10 | use embassy_stm32::exti::ExtiInput; | 10 | use embassy_stm32::exti::ExtiInput; |
| 11 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 11 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 12 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 12 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| 13 | use embassy_sync::blocking_mutex::Mutex; | 13 | use embassy_sync::blocking_mutex::Mutex; |
| 14 | use embedded_storage::nor_flash::NorFlash; | 14 | use embedded_storage::nor_flash::NorFlash; |
| 15 | use panic_reset as _; | 15 | use panic_reset as _; |
| @@ -25,8 +25,7 @@ async fn main(_spawner: Spawner) { | |||
| 25 | let flash = Flash::new_blocking(p.FLASH); | 25 | let flash = Flash::new_blocking(p.FLASH); |
| 26 | let flash = Mutex::new(RefCell::new(flash)); | 26 | let flash = Mutex::new(RefCell::new(flash)); |
| 27 | 27 | ||
| 28 | let button = Input::new(p.PC13, Pull::Down); | 28 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down); |
| 29 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 30 | 29 | ||
| 31 | let mut led = Output::new(p.PB7, Level::Low, Speed::Low); | 30 | let mut led = Output::new(p.PB7, Level::Low, Speed::Low); |
| 32 | led.set_high(); | 31 | led.set_high(); |
diff --git a/examples/boot/application/stm32h7/src/bin/a.rs b/examples/boot/application/stm32h7/src/bin/a.rs index b73506cf3..a00d17408 100644 --- a/examples/boot/application/stm32h7/src/bin/a.rs +++ b/examples/boot/application/stm32h7/src/bin/a.rs | |||
| @@ -9,7 +9,7 @@ use embassy_boot_stm32::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdater | |||
| 9 | use embassy_executor::Spawner; | 9 | use embassy_executor::Spawner; |
| 10 | use embassy_stm32::exti::ExtiInput; | 10 | use embassy_stm32::exti::ExtiInput; |
| 11 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 11 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 12 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 12 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| 13 | use embassy_sync::blocking_mutex::Mutex; | 13 | use embassy_sync::blocking_mutex::Mutex; |
| 14 | use embedded_storage::nor_flash::NorFlash; | 14 | use embedded_storage::nor_flash::NorFlash; |
| 15 | use panic_reset as _; | 15 | use panic_reset as _; |
| @@ -25,8 +25,7 @@ async fn main(_spawner: Spawner) { | |||
| 25 | let flash = Flash::new_blocking(p.FLASH); | 25 | let flash = Flash::new_blocking(p.FLASH); |
| 26 | let flash = Mutex::new(RefCell::new(flash)); | 26 | let flash = Mutex::new(RefCell::new(flash)); |
| 27 | 27 | ||
| 28 | let button = Input::new(p.PC13, Pull::Down); | 28 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down); |
| 29 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 30 | 29 | ||
| 31 | let mut led = Output::new(p.PB14, Level::Low, Speed::Low); | 30 | let mut led = Output::new(p.PB14, Level::Low, Speed::Low); |
| 32 | led.set_high(); | 31 | led.set_high(); |
diff --git a/examples/boot/application/stm32l0/src/bin/a.rs b/examples/boot/application/stm32l0/src/bin/a.rs index 02f74bdef..dbec49d44 100644 --- a/examples/boot/application/stm32l0/src/bin/a.rs +++ b/examples/boot/application/stm32l0/src/bin/a.rs | |||
| @@ -8,7 +8,7 @@ use embassy_embedded_hal::adapter::BlockingAsync; | |||
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_stm32::exti::ExtiInput; | 9 | use embassy_stm32::exti::ExtiInput; |
| 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 11 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 11 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| 12 | use embassy_sync::mutex::Mutex; | 12 | use embassy_sync::mutex::Mutex; |
| 13 | use embassy_time::Timer; | 13 | use embassy_time::Timer; |
| 14 | use panic_reset as _; | 14 | use panic_reset as _; |
| @@ -24,8 +24,7 @@ async fn main(_spawner: Spawner) { | |||
| 24 | let flash = Flash::new_blocking(p.FLASH); | 24 | let flash = Flash::new_blocking(p.FLASH); |
| 25 | let flash = Mutex::new(BlockingAsync::new(flash)); | 25 | let flash = Mutex::new(BlockingAsync::new(flash)); |
| 26 | 26 | ||
| 27 | let button = Input::new(p.PB2, Pull::Up); | 27 | let mut button = ExtiInput::new(p.PB2, p.EXTI2, Pull::Up); |
| 28 | let mut button = ExtiInput::new(button, p.EXTI2); | ||
| 29 | 28 | ||
| 30 | let mut led = Output::new(p.PB5, Level::Low, Speed::Low); | 29 | let mut led = Output::new(p.PB5, Level::Low, Speed::Low); |
| 31 | 30 | ||
diff --git a/examples/boot/application/stm32l1/src/bin/a.rs b/examples/boot/application/stm32l1/src/bin/a.rs index 02f74bdef..dbec49d44 100644 --- a/examples/boot/application/stm32l1/src/bin/a.rs +++ b/examples/boot/application/stm32l1/src/bin/a.rs | |||
| @@ -8,7 +8,7 @@ use embassy_embedded_hal::adapter::BlockingAsync; | |||
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_stm32::exti::ExtiInput; | 9 | use embassy_stm32::exti::ExtiInput; |
| 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 11 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 11 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| 12 | use embassy_sync::mutex::Mutex; | 12 | use embassy_sync::mutex::Mutex; |
| 13 | use embassy_time::Timer; | 13 | use embassy_time::Timer; |
| 14 | use panic_reset as _; | 14 | use panic_reset as _; |
| @@ -24,8 +24,7 @@ async fn main(_spawner: Spawner) { | |||
| 24 | let flash = Flash::new_blocking(p.FLASH); | 24 | let flash = Flash::new_blocking(p.FLASH); |
| 25 | let flash = Mutex::new(BlockingAsync::new(flash)); | 25 | let flash = Mutex::new(BlockingAsync::new(flash)); |
| 26 | 26 | ||
| 27 | let button = Input::new(p.PB2, Pull::Up); | 27 | let mut button = ExtiInput::new(p.PB2, p.EXTI2, Pull::Up); |
| 28 | let mut button = ExtiInput::new(button, p.EXTI2); | ||
| 29 | 28 | ||
| 30 | let mut led = Output::new(p.PB5, Level::Low, Speed::Low); | 29 | let mut led = Output::new(p.PB5, Level::Low, Speed::Low); |
| 31 | 30 | ||
diff --git a/examples/boot/application/stm32l4/src/bin/a.rs b/examples/boot/application/stm32l4/src/bin/a.rs index 892446968..e946c3cdf 100644 --- a/examples/boot/application/stm32l4/src/bin/a.rs +++ b/examples/boot/application/stm32l4/src/bin/a.rs | |||
| @@ -8,7 +8,7 @@ use embassy_embedded_hal::adapter::BlockingAsync; | |||
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_stm32::exti::ExtiInput; | 9 | use embassy_stm32::exti::ExtiInput; |
| 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 11 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 11 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| 12 | use embassy_sync::mutex::Mutex; | 12 | use embassy_sync::mutex::Mutex; |
| 13 | use panic_reset as _; | 13 | use panic_reset as _; |
| 14 | 14 | ||
| @@ -23,8 +23,7 @@ async fn main(_spawner: Spawner) { | |||
| 23 | let flash = Flash::new_blocking(p.FLASH); | 23 | let flash = Flash::new_blocking(p.FLASH); |
| 24 | let flash = Mutex::new(BlockingAsync::new(flash)); | 24 | let flash = Mutex::new(BlockingAsync::new(flash)); |
| 25 | 25 | ||
| 26 | let button = Input::new(p.PC13, Pull::Up); | 26 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Up); |
| 27 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 28 | 27 | ||
| 29 | let mut led = Output::new(p.PB14, Level::Low, Speed::Low); | 28 | let mut led = Output::new(p.PB14, Level::Low, Speed::Low); |
| 30 | led.set_high(); | 29 | led.set_high(); |
diff --git a/examples/boot/application/stm32wl/src/bin/a.rs b/examples/boot/application/stm32wl/src/bin/a.rs index d9665e6ee..b582d8b25 100644 --- a/examples/boot/application/stm32wl/src/bin/a.rs +++ b/examples/boot/application/stm32wl/src/bin/a.rs | |||
| @@ -8,7 +8,7 @@ use embassy_embedded_hal::adapter::BlockingAsync; | |||
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_stm32::exti::ExtiInput; | 9 | use embassy_stm32::exti::ExtiInput; |
| 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 11 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 11 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| 12 | use embassy_sync::mutex::Mutex; | 12 | use embassy_sync::mutex::Mutex; |
| 13 | use panic_reset as _; | 13 | use panic_reset as _; |
| 14 | 14 | ||
| @@ -23,8 +23,7 @@ async fn main(_spawner: Spawner) { | |||
| 23 | let flash = Flash::new_blocking(p.FLASH); | 23 | let flash = Flash::new_blocking(p.FLASH); |
| 24 | let flash = Mutex::new(BlockingAsync::new(flash)); | 24 | let flash = Mutex::new(BlockingAsync::new(flash)); |
| 25 | 25 | ||
| 26 | let button = Input::new(p.PA0, Pull::Up); | 26 | let mut button = ExtiInput::new(p.PA0, p.EXTI0, Pull::Up); |
| 27 | let mut button = ExtiInput::new(button, p.EXTI0); | ||
| 28 | 27 | ||
| 29 | let mut led = Output::new(p.PB9, Level::Low, Speed::Low); | 28 | let mut led = Output::new(p.PB9, Level::Low, Speed::Low); |
| 30 | led.set_high(); | 29 | led.set_high(); |
diff --git a/examples/stm32c0/src/bin/button_exti.rs b/examples/stm32c0/src/bin/button_exti.rs index 1e970fdd6..34a08bbc6 100644 --- a/examples/stm32c0/src/bin/button_exti.rs +++ b/examples/stm32c0/src/bin/button_exti.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::exti::ExtiInput; | 6 | use embassy_stm32::exti::ExtiInput; |
| 7 | use embassy_stm32::gpio::{Input, Pull}; | 7 | use embassy_stm32::gpio::Pull; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 9 | ||
| 10 | #[embassy_executor::main] | 10 | #[embassy_executor::main] |
| @@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) { | |||
| 12 | let p = embassy_stm32::init(Default::default()); | 12 | let p = embassy_stm32::init(Default::default()); |
| 13 | info!("Hello World!"); | 13 | info!("Hello World!"); |
| 14 | 14 | ||
| 15 | let button = Input::new(p.PC13, Pull::Up); | 15 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Up); |
| 16 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 17 | 16 | ||
| 18 | info!("Press the USER button..."); | 17 | info!("Press the USER button..."); |
| 19 | 18 | ||
diff --git a/examples/stm32f0/src/bin/button_controlled_blink.rs b/examples/stm32f0/src/bin/button_controlled_blink.rs index 360d153c3..4465483d9 100644 --- a/examples/stm32f0/src/bin/button_controlled_blink.rs +++ b/examples/stm32f0/src/bin/button_controlled_blink.rs | |||
| @@ -8,7 +8,7 @@ use core::sync::atomic::{AtomicU32, Ordering}; | |||
| 8 | use defmt::info; | 8 | use defmt::info; |
| 9 | use embassy_executor::Spawner; | 9 | use embassy_executor::Spawner; |
| 10 | use embassy_stm32::exti::ExtiInput; | 10 | use embassy_stm32::exti::ExtiInput; |
| 11 | use embassy_stm32::gpio::{AnyPin, Input, Level, Output, Pin, Pull, Speed}; | 11 | use embassy_stm32::gpio::{AnyPin, Level, Output, Pin, Pull, Speed}; |
| 12 | use embassy_time::Timer; | 12 | use embassy_time::Timer; |
| 13 | use {defmt_rtt as _, panic_probe as _}; | 13 | use {defmt_rtt as _, panic_probe as _}; |
| 14 | 14 | ||
| @@ -36,8 +36,7 @@ async fn main(spawner: Spawner) { | |||
| 36 | 36 | ||
| 37 | // Configure the button pin and obtain handler. | 37 | // Configure the button pin and obtain handler. |
| 38 | // On the Nucleo F091RC there is a button connected to pin PC13. | 38 | // On the Nucleo F091RC there is a button connected to pin PC13. |
| 39 | let button = Input::new(p.PC13, Pull::None); | 39 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::None); |
| 40 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 41 | 40 | ||
| 42 | // Create and initialize a delay variable to manage delay loop | 41 | // Create and initialize a delay variable to manage delay loop |
| 43 | let mut del_var = 2000; | 42 | let mut del_var = 2000; |
diff --git a/examples/stm32f0/src/bin/button_exti.rs b/examples/stm32f0/src/bin/button_exti.rs index ce17c1a48..fd615a215 100644 --- a/examples/stm32f0/src/bin/button_exti.rs +++ b/examples/stm32f0/src/bin/button_exti.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::exti::ExtiInput; | 6 | use embassy_stm32::exti::ExtiInput; |
| 7 | use embassy_stm32::gpio::{Input, Pull}; | 7 | use embassy_stm32::gpio::Pull; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 9 | ||
| 10 | #[embassy_executor::main] | 10 | #[embassy_executor::main] |
| @@ -13,8 +13,7 @@ async fn main(_spawner: Spawner) { | |||
| 13 | let p = embassy_stm32::init(Default::default()); | 13 | let p = embassy_stm32::init(Default::default()); |
| 14 | // Configure the button pin and obtain handler. | 14 | // Configure the button pin and obtain handler. |
| 15 | // On the Nucleo F091RC there is a button connected to pin PC13. | 15 | // On the Nucleo F091RC there is a button connected to pin PC13. |
| 16 | let button = Input::new(p.PC13, Pull::Down); | 16 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down); |
| 17 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 18 | 17 | ||
| 19 | info!("Press the USER button..."); | 18 | info!("Press the USER button..."); |
| 20 | loop { | 19 | loop { |
diff --git a/examples/stm32f3/src/bin/button_events.rs b/examples/stm32f3/src/bin/button_events.rs index 2f7da4ef5..f5ed5d2c9 100644 --- a/examples/stm32f3/src/bin/button_events.rs +++ b/examples/stm32f3/src/bin/button_events.rs | |||
| @@ -12,21 +12,20 @@ | |||
| 12 | use defmt::*; | 12 | use defmt::*; |
| 13 | use embassy_executor::Spawner; | 13 | use embassy_executor::Spawner; |
| 14 | use embassy_stm32::exti::ExtiInput; | 14 | use embassy_stm32::exti::ExtiInput; |
| 15 | use embassy_stm32::gpio::{AnyPin, Input, Level, Output, Pin, Pull, Speed}; | 15 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| 16 | use embassy_stm32::peripherals::PA0; | ||
| 17 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; | 16 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; |
| 18 | use embassy_sync::channel::Channel; | 17 | use embassy_sync::channel::Channel; |
| 19 | use embassy_time::{with_timeout, Duration, Timer}; | 18 | use embassy_time::{with_timeout, Duration, Timer}; |
| 20 | use {defmt_rtt as _, panic_probe as _}; | 19 | use {defmt_rtt as _, panic_probe as _}; |
| 21 | 20 | ||
| 22 | struct Leds<'a> { | 21 | struct Leds<'a> { |
| 23 | leds: [Output<'a, AnyPin>; 8], | 22 | leds: [Output<'a>; 8], |
| 24 | direction: i8, | 23 | direction: i8, |
| 25 | current_led: usize, | 24 | current_led: usize, |
| 26 | } | 25 | } |
| 27 | 26 | ||
| 28 | impl<'a> Leds<'a> { | 27 | impl<'a> Leds<'a> { |
| 29 | fn new(pins: [Output<'a, AnyPin>; 8]) -> Self { | 28 | fn new(pins: [Output<'a>; 8]) -> Self { |
| 30 | Self { | 29 | Self { |
| 31 | leds: pins, | 30 | leds: pins, |
| 32 | direction: 1, | 31 | direction: 1, |
| @@ -100,18 +99,17 @@ static CHANNEL: Channel<ThreadModeRawMutex, ButtonEvent, 4> = Channel::new(); | |||
| 100 | #[embassy_executor::main] | 99 | #[embassy_executor::main] |
| 101 | async fn main(spawner: Spawner) { | 100 | async fn main(spawner: Spawner) { |
| 102 | let p = embassy_stm32::init(Default::default()); | 101 | let p = embassy_stm32::init(Default::default()); |
| 103 | let button = Input::new(p.PA0, Pull::Down); | 102 | let button = ExtiInput::new(p.PA0, p.EXTI0, Pull::Down); |
| 104 | let button = ExtiInput::new(button, p.EXTI0); | ||
| 105 | info!("Press the USER button..."); | 103 | info!("Press the USER button..."); |
| 106 | let leds = [ | 104 | let leds = [ |
| 107 | Output::new(p.PE9.degrade(), Level::Low, Speed::Low), | 105 | Output::new(p.PE9, Level::Low, Speed::Low), |
| 108 | Output::new(p.PE10.degrade(), Level::Low, Speed::Low), | 106 | Output::new(p.PE10, Level::Low, Speed::Low), |
| 109 | Output::new(p.PE11.degrade(), Level::Low, Speed::Low), | 107 | Output::new(p.PE11, Level::Low, Speed::Low), |
| 110 | Output::new(p.PE12.degrade(), Level::Low, Speed::Low), | 108 | Output::new(p.PE12, Level::Low, Speed::Low), |
| 111 | Output::new(p.PE13.degrade(), Level::Low, Speed::Low), | 109 | Output::new(p.PE13, Level::Low, Speed::Low), |
| 112 | Output::new(p.PE14.degrade(), Level::Low, Speed::Low), | 110 | Output::new(p.PE14, Level::Low, Speed::Low), |
| 113 | Output::new(p.PE15.degrade(), Level::Low, Speed::Low), | 111 | Output::new(p.PE15, Level::Low, Speed::Low), |
| 114 | Output::new(p.PE8.degrade(), Level::Low, Speed::Low), | 112 | Output::new(p.PE8, Level::Low, Speed::Low), |
| 115 | ]; | 113 | ]; |
| 116 | let leds = Leds::new(leds); | 114 | let leds = Leds::new(leds); |
| 117 | 115 | ||
| @@ -127,7 +125,7 @@ async fn led_blinker(mut leds: Leds<'static>) { | |||
| 127 | } | 125 | } |
| 128 | 126 | ||
| 129 | #[embassy_executor::task] | 127 | #[embassy_executor::task] |
| 130 | async fn button_waiter(mut button: ExtiInput<'static, PA0>) { | 128 | async fn button_waiter(mut button: ExtiInput<'static>) { |
| 131 | const DOUBLE_CLICK_DELAY: u64 = 250; | 129 | const DOUBLE_CLICK_DELAY: u64 = 250; |
| 132 | const HOLD_DELAY: u64 = 1000; | 130 | const HOLD_DELAY: u64 = 1000; |
| 133 | 131 | ||
diff --git a/examples/stm32f3/src/bin/button_exti.rs b/examples/stm32f3/src/bin/button_exti.rs index 86ff68492..a55530e0e 100644 --- a/examples/stm32f3/src/bin/button_exti.rs +++ b/examples/stm32f3/src/bin/button_exti.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::exti::ExtiInput; | 6 | use embassy_stm32::exti::ExtiInput; |
| 7 | use embassy_stm32::gpio::{Input, Pull}; | 7 | use embassy_stm32::gpio::Pull; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 9 | ||
| 10 | #[embassy_executor::main] | 10 | #[embassy_executor::main] |
| @@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) { | |||
| 12 | let p = embassy_stm32::init(Default::default()); | 12 | let p = embassy_stm32::init(Default::default()); |
| 13 | info!("Hello World!"); | 13 | info!("Hello World!"); |
| 14 | 14 | ||
| 15 | let button = Input::new(p.PA0, Pull::Down); | 15 | let mut button = ExtiInput::new(p.PA0, p.EXTI0, Pull::Down); |
| 16 | let mut button = ExtiInput::new(button, p.EXTI0); | ||
| 17 | 16 | ||
| 18 | info!("Press the USER button..."); | 17 | info!("Press the USER button..."); |
| 19 | 18 | ||
diff --git a/examples/stm32f4/src/bin/button_exti.rs b/examples/stm32f4/src/bin/button_exti.rs index 67751187d..2a546dac5 100644 --- a/examples/stm32f4/src/bin/button_exti.rs +++ b/examples/stm32f4/src/bin/button_exti.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::exti::ExtiInput; | 6 | use embassy_stm32::exti::ExtiInput; |
| 7 | use embassy_stm32::gpio::{Input, Pull}; | 7 | use embassy_stm32::gpio::Pull; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 9 | ||
| 10 | #[embassy_executor::main] | 10 | #[embassy_executor::main] |
| @@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) { | |||
| 12 | let p = embassy_stm32::init(Default::default()); | 12 | let p = embassy_stm32::init(Default::default()); |
| 13 | info!("Hello World!"); | 13 | info!("Hello World!"); |
| 14 | 14 | ||
| 15 | let button = Input::new(p.PC13, Pull::Down); | 15 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down); |
| 16 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 17 | 16 | ||
| 18 | info!("Press the USER button..."); | 17 | info!("Press the USER button..."); |
| 19 | 18 | ||
diff --git a/examples/stm32f7/src/bin/button_exti.rs b/examples/stm32f7/src/bin/button_exti.rs index 67751187d..2a546dac5 100644 --- a/examples/stm32f7/src/bin/button_exti.rs +++ b/examples/stm32f7/src/bin/button_exti.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::exti::ExtiInput; | 6 | use embassy_stm32::exti::ExtiInput; |
| 7 | use embassy_stm32::gpio::{Input, Pull}; | 7 | use embassy_stm32::gpio::Pull; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 9 | ||
| 10 | #[embassy_executor::main] | 10 | #[embassy_executor::main] |
| @@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) { | |||
| 12 | let p = embassy_stm32::init(Default::default()); | 12 | let p = embassy_stm32::init(Default::default()); |
| 13 | info!("Hello World!"); | 13 | info!("Hello World!"); |
| 14 | 14 | ||
| 15 | let button = Input::new(p.PC13, Pull::Down); | 15 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down); |
| 16 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 17 | 16 | ||
| 18 | info!("Press the USER button..."); | 17 | info!("Press the USER button..."); |
| 19 | 18 | ||
diff --git a/examples/stm32g0/src/bin/button_exti.rs b/examples/stm32g0/src/bin/button_exti.rs index 1e970fdd6..34a08bbc6 100644 --- a/examples/stm32g0/src/bin/button_exti.rs +++ b/examples/stm32g0/src/bin/button_exti.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::exti::ExtiInput; | 6 | use embassy_stm32::exti::ExtiInput; |
| 7 | use embassy_stm32::gpio::{Input, Pull}; | 7 | use embassy_stm32::gpio::Pull; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 9 | ||
| 10 | #[embassy_executor::main] | 10 | #[embassy_executor::main] |
| @@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) { | |||
| 12 | let p = embassy_stm32::init(Default::default()); | 12 | let p = embassy_stm32::init(Default::default()); |
| 13 | info!("Hello World!"); | 13 | info!("Hello World!"); |
| 14 | 14 | ||
| 15 | let button = Input::new(p.PC13, Pull::Up); | 15 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Up); |
| 16 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 17 | 16 | ||
| 18 | info!("Press the USER button..."); | 17 | info!("Press the USER button..."); |
| 19 | 18 | ||
diff --git a/examples/stm32g4/src/bin/button_exti.rs b/examples/stm32g4/src/bin/button_exti.rs index 67751187d..2a546dac5 100644 --- a/examples/stm32g4/src/bin/button_exti.rs +++ b/examples/stm32g4/src/bin/button_exti.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::exti::ExtiInput; | 6 | use embassy_stm32::exti::ExtiInput; |
| 7 | use embassy_stm32::gpio::{Input, Pull}; | 7 | use embassy_stm32::gpio::Pull; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 9 | ||
| 10 | #[embassy_executor::main] | 10 | #[embassy_executor::main] |
| @@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) { | |||
| 12 | let p = embassy_stm32::init(Default::default()); | 12 | let p = embassy_stm32::init(Default::default()); |
| 13 | info!("Hello World!"); | 13 | info!("Hello World!"); |
| 14 | 14 | ||
| 15 | let button = Input::new(p.PC13, Pull::Down); | 15 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down); |
| 16 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 17 | 16 | ||
| 18 | info!("Press the USER button..."); | 17 | info!("Press the USER button..."); |
| 19 | 18 | ||
diff --git a/examples/stm32h5/src/bin/button_exti.rs b/examples/stm32h5/src/bin/button_exti.rs index 67751187d..2a546dac5 100644 --- a/examples/stm32h5/src/bin/button_exti.rs +++ b/examples/stm32h5/src/bin/button_exti.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::exti::ExtiInput; | 6 | use embassy_stm32::exti::ExtiInput; |
| 7 | use embassy_stm32::gpio::{Input, Pull}; | 7 | use embassy_stm32::gpio::Pull; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 9 | ||
| 10 | #[embassy_executor::main] | 10 | #[embassy_executor::main] |
| @@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) { | |||
| 12 | let p = embassy_stm32::init(Default::default()); | 12 | let p = embassy_stm32::init(Default::default()); |
| 13 | info!("Hello World!"); | 13 | info!("Hello World!"); |
| 14 | 14 | ||
| 15 | let button = Input::new(p.PC13, Pull::Down); | 15 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down); |
| 16 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 17 | 16 | ||
| 18 | info!("Press the USER button..."); | 17 | info!("Press the USER button..."); |
| 19 | 18 | ||
diff --git a/examples/stm32h7/src/bin/button_exti.rs b/examples/stm32h7/src/bin/button_exti.rs index 67751187d..2a546dac5 100644 --- a/examples/stm32h7/src/bin/button_exti.rs +++ b/examples/stm32h7/src/bin/button_exti.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::exti::ExtiInput; | 6 | use embassy_stm32::exti::ExtiInput; |
| 7 | use embassy_stm32::gpio::{Input, Pull}; | 7 | use embassy_stm32::gpio::Pull; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 9 | ||
| 10 | #[embassy_executor::main] | 10 | #[embassy_executor::main] |
| @@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) { | |||
| 12 | let p = embassy_stm32::init(Default::default()); | 12 | let p = embassy_stm32::init(Default::default()); |
| 13 | info!("Hello World!"); | 13 | info!("Hello World!"); |
| 14 | 14 | ||
| 15 | let button = Input::new(p.PC13, Pull::Down); | 15 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down); |
| 16 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 17 | 16 | ||
| 18 | info!("Press the USER button..."); | 17 | info!("Press the USER button..."); |
| 19 | 18 | ||
diff --git a/examples/stm32l0/src/bin/button_exti.rs b/examples/stm32l0/src/bin/button_exti.rs index f517fce04..4945da7ce 100644 --- a/examples/stm32l0/src/bin/button_exti.rs +++ b/examples/stm32l0/src/bin/button_exti.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::exti::ExtiInput; | 6 | use embassy_stm32::exti::ExtiInput; |
| 7 | use embassy_stm32::gpio::{Input, Pull}; | 7 | use embassy_stm32::gpio::Pull; |
| 8 | use embassy_stm32::Config; | 8 | use embassy_stm32::Config; |
| 9 | use {defmt_rtt as _, panic_probe as _}; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 10 | ||
| @@ -13,8 +13,7 @@ async fn main(_spawner: Spawner) { | |||
| 13 | let config = Config::default(); | 13 | let config = Config::default(); |
| 14 | let p = embassy_stm32::init(config); | 14 | let p = embassy_stm32::init(config); |
| 15 | 15 | ||
| 16 | let button = Input::new(p.PB2, Pull::Up); | 16 | let mut button = ExtiInput::new(p.PB2, p.EXTI2, Pull::Up); |
| 17 | let mut button = ExtiInput::new(button, p.EXTI2); | ||
| 18 | 17 | ||
| 19 | info!("Press the USER button..."); | 18 | info!("Press the USER button..."); |
| 20 | 19 | ||
diff --git a/examples/stm32l4/src/bin/button_exti.rs b/examples/stm32l4/src/bin/button_exti.rs index 1e970fdd6..34a08bbc6 100644 --- a/examples/stm32l4/src/bin/button_exti.rs +++ b/examples/stm32l4/src/bin/button_exti.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::exti::ExtiInput; | 6 | use embassy_stm32::exti::ExtiInput; |
| 7 | use embassy_stm32::gpio::{Input, Pull}; | 7 | use embassy_stm32::gpio::Pull; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 9 | ||
| 10 | #[embassy_executor::main] | 10 | #[embassy_executor::main] |
| @@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) { | |||
| 12 | let p = embassy_stm32::init(Default::default()); | 12 | let p = embassy_stm32::init(Default::default()); |
| 13 | info!("Hello World!"); | 13 | info!("Hello World!"); |
| 14 | 14 | ||
| 15 | let button = Input::new(p.PC13, Pull::Up); | 15 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Up); |
| 16 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 17 | 16 | ||
| 18 | info!("Press the USER button..."); | 17 | info!("Press the USER button..."); |
| 19 | 18 | ||
diff --git a/examples/stm32l4/src/bin/spe_adin1110_http_server.rs b/examples/stm32l4/src/bin/spe_adin1110_http_server.rs index 5b4cdfe5e..026a3a477 100644 --- a/examples/stm32l4/src/bin/spe_adin1110_http_server.rs +++ b/examples/stm32l4/src/bin/spe_adin1110_http_server.rs | |||
| @@ -58,9 +58,9 @@ const IP_ADDRESS: Ipv4Cidr = Ipv4Cidr::new(Ipv4Address([192, 168, 1, 5]), 24); | |||
| 58 | const HTTP_LISTEN_PORT: u16 = 80; | 58 | const HTTP_LISTEN_PORT: u16 = 80; |
| 59 | 59 | ||
| 60 | pub type SpeSpi = Spi<'static, peripherals::SPI2, peripherals::DMA1_CH1, peripherals::DMA1_CH2>; | 60 | pub type SpeSpi = Spi<'static, peripherals::SPI2, peripherals::DMA1_CH1, peripherals::DMA1_CH2>; |
| 61 | pub type SpeSpiCs = ExclusiveDevice<SpeSpi, Output<'static, peripherals::PB12>, Delay>; | 61 | pub type SpeSpiCs = ExclusiveDevice<SpeSpi, Output<'static>, Delay>; |
| 62 | pub type SpeInt = exti::ExtiInput<'static, peripherals::PB11>; | 62 | pub type SpeInt = exti::ExtiInput<'static>; |
| 63 | pub type SpeRst = Output<'static, peripherals::PC7>; | 63 | pub type SpeRst = Output<'static>; |
| 64 | pub type Adin1110T = ADIN1110<SpeSpiCs>; | 64 | pub type Adin1110T = ADIN1110<SpeSpiCs>; |
| 65 | pub type TempSensI2c = I2c<'static, peripherals::I2C3, peripherals::DMA1_CH6, peripherals::DMA1_CH7>; | 65 | pub type TempSensI2c = I2c<'static, peripherals::I2C3, peripherals::DMA1_CH6, peripherals::DMA1_CH7>; |
| 66 | 66 | ||
| @@ -134,8 +134,7 @@ async fn main(spawner: Spawner) { | |||
| 134 | let spe_cfg1 = Input::new(dp.PC9, Pull::None); | 134 | let spe_cfg1 = Input::new(dp.PC9, Pull::None); |
| 135 | let _spe_ts_capt = Output::new(dp.PC6, Level::Low, Speed::Low); | 135 | let _spe_ts_capt = Output::new(dp.PC6, Level::Low, Speed::Low); |
| 136 | 136 | ||
| 137 | let spe_int = Input::new(dp.PB11, Pull::None); | 137 | let spe_int = exti::ExtiInput::new(dp.PB11, dp.EXTI11, Pull::None); |
| 138 | let spe_int = exti::ExtiInput::new(spe_int, dp.EXTI11); | ||
| 139 | 138 | ||
| 140 | let spe_spi_cs_n = Output::new(dp.PB12, Level::High, Speed::High); | 139 | let spe_spi_cs_n = Output::new(dp.PB12, Level::High, Speed::High); |
| 141 | let spe_spi_sclk = dp.PB13; | 140 | let spe_spi_sclk = dp.PB13; |
| @@ -298,7 +297,7 @@ async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net: | |||
| 298 | } | 297 | } |
| 299 | 298 | ||
| 300 | #[embassy_executor::task] | 299 | #[embassy_executor::task] |
| 301 | async fn heartbeat_led(mut led: Output<'static, peripherals::PE6>) { | 300 | async fn heartbeat_led(mut led: Output<'static>) { |
| 302 | let mut tmr = Ticker::every(Duration::from_hz(3)); | 301 | let mut tmr = Ticker::every(Duration::from_hz(3)); |
| 303 | loop { | 302 | loop { |
| 304 | led.toggle(); | 303 | led.toggle(); |
| @@ -308,7 +307,7 @@ async fn heartbeat_led(mut led: Output<'static, peripherals::PE6>) { | |||
| 308 | 307 | ||
| 309 | // ADT7422 | 308 | // ADT7422 |
| 310 | #[embassy_executor::task] | 309 | #[embassy_executor::task] |
| 311 | async fn temp_task(temp_dev_i2c: TempSensI2c, mut led: Output<'static, peripherals::PG15>) -> ! { | 310 | async fn temp_task(temp_dev_i2c: TempSensI2c, mut led: Output<'static>) -> ! { |
| 312 | let mut tmr = Ticker::every(Duration::from_hz(1)); | 311 | let mut tmr = Ticker::every(Duration::from_hz(1)); |
| 313 | let mut temp_sens = ADT7422::new(temp_dev_i2c, 0x48).unwrap(); | 312 | let mut temp_sens = ADT7422::new(temp_dev_i2c, 0x48).unwrap(); |
| 314 | 313 | ||
diff --git a/examples/stm32l5/src/bin/button_exti.rs b/examples/stm32l5/src/bin/button_exti.rs index 91d0ccc2e..e6639d22b 100644 --- a/examples/stm32l5/src/bin/button_exti.rs +++ b/examples/stm32l5/src/bin/button_exti.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::exti::ExtiInput; | 6 | use embassy_stm32::exti::ExtiInput; |
| 7 | use embassy_stm32::gpio::{Input, Pull}; | 7 | use embassy_stm32::gpio::Pull; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 9 | ||
| 10 | #[embassy_executor::main] | 10 | #[embassy_executor::main] |
| @@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) { | |||
| 12 | let p = embassy_stm32::init(Default::default()); | 12 | let p = embassy_stm32::init(Default::default()); |
| 13 | info!("Hello World!"); | 13 | info!("Hello World!"); |
| 14 | 14 | ||
| 15 | let button = Input::new(p.PC13, Pull::Down); | 15 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down); |
| 16 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 17 | 16 | ||
| 18 | info!("Press the USER button..."); | 17 | info!("Press the USER button..."); |
| 19 | 18 | ||
diff --git a/examples/stm32wb/src/bin/button_exti.rs b/examples/stm32wb/src/bin/button_exti.rs index d34dde3e9..2871fd55f 100644 --- a/examples/stm32wb/src/bin/button_exti.rs +++ b/examples/stm32wb/src/bin/button_exti.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::exti::ExtiInput; | 6 | use embassy_stm32::exti::ExtiInput; |
| 7 | use embassy_stm32::gpio::{Input, Pull}; | 7 | use embassy_stm32::gpio::Pull; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 9 | ||
| 10 | #[embassy_executor::main] | 10 | #[embassy_executor::main] |
| @@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) { | |||
| 12 | let p = embassy_stm32::init(Default::default()); | 12 | let p = embassy_stm32::init(Default::default()); |
| 13 | info!("Hello World!"); | 13 | info!("Hello World!"); |
| 14 | 14 | ||
| 15 | let button = Input::new(p.PC4, Pull::Up); | 15 | let mut button = ExtiInput::new(p.PC4, p.EXTI4, Pull::Up); |
| 16 | let mut button = ExtiInput::new(button, p.EXTI4); | ||
| 17 | 16 | ||
| 18 | info!("Press the USER button..."); | 17 | info!("Press the USER button..."); |
| 19 | 18 | ||
diff --git a/examples/stm32wba/src/bin/button_exti.rs b/examples/stm32wba/src/bin/button_exti.rs index 1e970fdd6..34a08bbc6 100644 --- a/examples/stm32wba/src/bin/button_exti.rs +++ b/examples/stm32wba/src/bin/button_exti.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::exti::ExtiInput; | 6 | use embassy_stm32::exti::ExtiInput; |
| 7 | use embassy_stm32::gpio::{Input, Pull}; | 7 | use embassy_stm32::gpio::Pull; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 9 | ||
| 10 | #[embassy_executor::main] | 10 | #[embassy_executor::main] |
| @@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) { | |||
| 12 | let p = embassy_stm32::init(Default::default()); | 12 | let p = embassy_stm32::init(Default::default()); |
| 13 | info!("Hello World!"); | 13 | info!("Hello World!"); |
| 14 | 14 | ||
| 15 | let button = Input::new(p.PC13, Pull::Up); | 15 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Up); |
| 16 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 17 | 16 | ||
| 18 | info!("Press the USER button..."); | 17 | info!("Press the USER button..."); |
| 19 | 18 | ||
diff --git a/examples/stm32wl/src/bin/button_exti.rs b/examples/stm32wl/src/bin/button_exti.rs index e6ad4b80b..27d5330bd 100644 --- a/examples/stm32wl/src/bin/button_exti.rs +++ b/examples/stm32wl/src/bin/button_exti.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::exti::ExtiInput; | 6 | use embassy_stm32::exti::ExtiInput; |
| 7 | use embassy_stm32::gpio::{Input, Pull}; | 7 | use embassy_stm32::gpio::Pull; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 9 | ||
| 10 | #[embassy_executor::main] | 10 | #[embassy_executor::main] |
| @@ -12,8 +12,7 @@ async fn main(_spawner: Spawner) { | |||
| 12 | let p = embassy_stm32::init(Default::default()); | 12 | let p = embassy_stm32::init(Default::default()); |
| 13 | info!("Hello World!"); | 13 | info!("Hello World!"); |
| 14 | 14 | ||
| 15 | let button = Input::new(p.PA0, Pull::Up); | 15 | let mut button = ExtiInput::new(p.PA0, p.EXTI0, Pull::Up); |
| 16 | let mut button = ExtiInput::new(button, p.EXTI0); | ||
| 17 | 16 | ||
| 18 | info!("Press the USER button..."); | 17 | info!("Press the USER button..."); |
| 19 | 18 | ||
