diff --git a/CHANGELOG.md b/CHANGELOG.md index d8245ddc..9eed8d85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added + - `AnyPin` alias for `ErasedPin` + - `new` constructors for `Input`, `Output`, `Analog` - Add `f469disc-lcd-test` with color/BER test pattern LCD output [#789] - Port `dsihost` implementation from stm32h7xx-hal [#786] - I2C 10-bit address support for I2c [#772] [#783] diff --git a/examples/rtic-button.rs b/examples/rtic-button.rs index f8f6cbb0..eab3e89e 100644 --- a/examples/rtic-button.rs +++ b/examples/rtic-button.rs @@ -8,7 +8,7 @@ use panic_halt as _; #[rtic::app(device = stm32f4xx_hal::pac, peripherals = true)] mod app { use stm32f4xx_hal::{ - gpio::{gpioa::PA0, gpioc::PC13, Edge, Input, Output, PushPull}, + gpio::{gpioa::PA0, gpioc::PC13, Edge, Input, Output, PinState, Pull}, prelude::*, }; const SYSFREQ: u32 = 100_000_000; @@ -20,7 +20,7 @@ mod app { #[local] struct Local { button: PA0, - led: PC13>, + led: PC13, } #[init] @@ -34,12 +34,14 @@ mod app { let gpioa = ctx.device.GPIOA.split(); let gpioc = ctx.device.GPIOC.split(); // button - let mut button = gpioa.pa0.into_pull_up_input(); + let mut button = Input::new(gpioa.pa0, Pull::Up); + // or + //let mut button = gpioa.pa0.into_pull_up_input(); button.make_interrupt_source(&mut syscfg); button.enable_interrupt(&mut ctx.device.EXTI); button.trigger_on_edge(&mut ctx.device.EXTI, Edge::Falling); // led - let led = gpioc.pc13.into_push_pull_output(); + let led = Output::new(gpioc.pc13, PinState::Low); ( Shared { diff --git a/src/gpio.rs b/src/gpio.rs index 5b8a8143..5a8a1e72 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -63,7 +63,7 @@ pub use convert::PinMode; mod partially_erased; pub use partially_erased::{PEPin, PartiallyErasedPin}; mod erased; -pub use erased::{EPin, ErasedPin}; +pub use erased::{AnyPin, ErasedPin}; mod exti; pub use exti::ExtiPin; mod dynamic; @@ -145,8 +145,8 @@ pub struct OpenDrain; /// Output mode (type state) #[derive(Debug, Default)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct Output { - _mode: PhantomData, +pub struct Output { + _mode: PhantomData, } /// Push pull output (type state) diff --git a/src/gpio/convert.rs b/src/gpio/convert.rs index eaf303f9..5ef222bf 100644 --- a/src/gpio/convert.rs +++ b/src/gpio/convert.rs @@ -1,6 +1,34 @@ use super::*; use crate::pac::gpioa::{moder::MODER0 as Mode, otyper::OT0 as OutputType}; +impl Input { + pub fn new( + pin: Pin, + pull: Pull, + ) -> Pin { + pin.into_mode().internal_resistor(pull) + } +} + +impl Output { + pub fn new( + mut pin: Pin, + state: PinState, + ) -> Pin + where + Self: PinMode, + { + pin._set_state(state); + pin.into_mode() + } +} + +impl Analog { + pub fn new(pin: Pin) -> Pin { + pin.into_mode() + } +} + impl Pin> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self) -> Pin> { diff --git a/src/gpio/erased.rs b/src/gpio/erased.rs index 67df8397..163e227f 100644 --- a/src/gpio/erased.rs +++ b/src/gpio/erased.rs @@ -1,6 +1,6 @@ use super::*; -pub use ErasedPin as EPin; +pub use ErasedPin as AnyPin; /// Fully erased pin ///