Skip to content

Commit 840a9a5

Browse files
bors[bot]burrbull
andauthored
Merge #563
563: restore erased pin r=therealprof a=burrbull Co-authored-by: Andrey Zgarbul <[email protected]>
2 parents 980c658 + 7ed0582 commit 840a9a5

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1616
### Added
1717

1818
[#426]: https://github.com/stm32-rs/stm32f4xx-hal/pull/426
19+
### Added
20+
21+
- `restore` for `ErasedPin` and `PartiallyErasedPin`
1922

2023
## [v0.14.0] - 2022-12-12
2124

src/gpio/erased.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::*;
22

3-
pub type EPin<MODE> = ErasedPin<MODE>;
3+
pub use ErasedPin as EPin;
44

55
/// Fully erased pin
66
///
@@ -56,6 +56,13 @@ impl<MODE> ErasedPin<MODE> {
5656
}
5757
}
5858

59+
/// Convert type erased pin to `Pin` with fixed type
60+
pub fn restore<const P: char, const N: u8>(self) -> Pin<P, N, MODE> {
61+
assert_eq!(self.port_id(), P as u8 - b'A');
62+
assert_eq!(self.pin_id(), N);
63+
Pin::new()
64+
}
65+
5966
#[inline]
6067
fn block(&self) -> &crate::pac::gpioa::RegisterBlock {
6168
// This function uses pointer arithmetic instead of branching to be more efficient

src/gpio/partially_erased.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::*;
22

3-
pub type PEPin<const P: char, MODE> = PartiallyErasedPin<P, MODE>;
3+
pub use PartiallyErasedPin as PEPin;
44

55
/// Partially erased pin
66
///
@@ -18,6 +18,12 @@ impl<const P: char, MODE> PartiallyErasedPin<P, MODE> {
1818
_mode: PhantomData,
1919
}
2020
}
21+
22+
/// Convert partially type erased pin to `Pin` with fixed type
23+
pub fn restore<const N: u8>(self) -> Pin<P, N, MODE> {
24+
assert_eq!(self.i, N);
25+
Pin::new()
26+
}
2127
}
2228

2329
impl<const P: char, MODE> fmt::Debug for PartiallyErasedPin<P, MODE> {

0 commit comments

Comments
 (0)