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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 6 additions & 4 deletions examples/rtic-button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,7 +20,7 @@ mod app {
#[local]
struct Local {
button: PA0<Input>,
led: PC13<Output<PushPull>>,
led: PC13<Output>,
}

#[init]
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = PushPull> {
_mode: PhantomData<MODE>,
pub struct Output<Otype = PushPull> {
_mode: PhantomData<Otype>,
}

/// Push pull output (type state)
Expand Down
28 changes: 28 additions & 0 deletions src/gpio/convert.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
use super::*;
use crate::pac::gpioa::{moder::MODER0 as Mode, otyper::OT0 as OutputType};

impl Input {
pub fn new<const P: char, const N: u8, MODE: PinMode>(
pin: Pin<P, N, MODE>,
pull: Pull,
) -> Pin<P, N, Self> {
pin.into_mode().internal_resistor(pull)
}
}

impl<Otype> Output<Otype> {
pub fn new<const P: char, const N: u8, MODE: PinMode>(
mut pin: Pin<P, N, MODE>,
state: PinState,
) -> Pin<P, N, Self>
where
Self: PinMode,
{
pin._set_state(state);
pin.into_mode()
}
}

impl Analog {
pub fn new<const P: char, const N: u8, MODE: PinMode>(pin: Pin<P, N, MODE>) -> Pin<P, N, Self> {
pin.into_mode()
}
}

impl<const P: char, const N: u8, const A: u8> Pin<P, N, Alternate<A, PushPull>> {
/// Turns pin alternate configuration pin into open drain
pub fn set_open_drain(self) -> Pin<P, N, Alternate<A, OpenDrain>> {
Expand Down
2 changes: 1 addition & 1 deletion src/gpio/erased.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;

pub use ErasedPin as EPin;
pub use ErasedPin as AnyPin;

/// Fully erased pin
///
Expand Down