Skip to content

Commit f3b4914

Browse files
authored
gpio: add dynamic pin support and conversion functions (#20)
- Add DynamicPin to allow for dynamic pin mode changes - Add type conversion functions for pin configuration This is taken directly from the implementation in [stm32h7xx-hal](https://github.com/stm32-rs/stm32h7xx-hal).
1 parent 97ad29e commit f3b4914

File tree

4 files changed

+615
-4
lines changed

4 files changed

+615
-4
lines changed

src/gpio.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,32 @@
4343
//! If you need a more temporary mode change, and can not use the `into_<mode>` functions for
4444
//! ownership reasons, you can use the closure based `with_<mode>` functions to temporarily change the pin type, do
4545
//! some output or input, and then have it change back once done.
46+
//!
47+
//! ### Dynamic Mode Change
48+
//! The above mode change methods guarantee that you can only call input functions when the pin is
49+
//! in input mode, and output when in output modes, but can lead to some issues. Therefore, there
50+
//! is also a mode where the state is kept track of at runtime, allowing you to change the mode
51+
//! often, and without problems with ownership, or references, at the cost of some performance and
52+
//! the risk of runtime errors.
53+
//!
54+
//! To make a pin dynamic, use the `into_dynamic` function, and then use the `make_<mode>` functions to
55+
//! change the mode
4656
57+
mod convert;
58+
mod dynamic;
4759
mod erased;
4860
mod exti;
4961
mod gpio_def;
5062
mod partially_erased;
5163

5264
use core::{fmt, marker::PhantomData};
5365

54-
pub use embedded_hal::digital::PinState;
55-
5666
use crate::rcc::ResetEnable;
5767

68+
pub use convert::PinMode;
69+
pub use dynamic::{Dynamic, DynamicPin};
70+
pub use embedded_hal::digital::PinState;
71+
5872
pub use erased::{EPin, ErasedPin};
5973
pub use exti::ExtiPin;
6074
pub use gpio_def::*;
@@ -166,10 +180,8 @@ mod marker {
166180
/// Marker trait for active pin modes
167181
pub trait Active {}
168182
/// Marker trait for all pin modes except alternate
169-
#[allow(dead_code)] // TODO: Remove when alternate function conversion is implemented
170183
pub trait NotAlt {}
171184
/// Marker trait for pins with alternate function `A` mapping
172-
#[allow(dead_code)] // TODO: Remove when alternate function conversion is implemented
173185
pub trait IntoAf<const A: u8> {}
174186
}
175187

0 commit comments

Comments
 (0)