Skip to content

Commit 4e902d2

Browse files
bors[bot]surban
andauthored
Merge #460
460: Allow GPIO splitting without reset and pin output configuration keeping initial state r=burrbull a=surban Fixes #459. Co-authored-by: Sebastian Urban <surban@surban.net>
2 parents c993283 + 55f3eae commit 4e902d2

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/gpio.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,13 @@ pub trait GpioExt {
119119
/// The to split the GPIO into
120120
type Parts;
121121

122-
/// Splits the GPIO block into independent pins and registers
122+
/// Splits the GPIO block into independent pins and registers.
123+
///
124+
/// This resets the state of the GPIO block.
123125
fn split(self) -> Self::Parts;
126+
127+
/// Splits the GPIO block into independent pins and registers without resetting its state.
128+
unsafe fn split_without_reset(self) -> Self::Parts;
124129
}
125130

126131
/// Marker trait for active states.
@@ -391,6 +396,19 @@ macro_rules! gpio {
391396
)+
392397
}
393398
}
399+
400+
unsafe fn split_without_reset(self) -> Parts {
401+
let rcc = unsafe { &(*RCC::ptr()) };
402+
$GPIOX::enable(rcc);
403+
404+
Parts {
405+
crl: Cr::<$port_id, false>(()),
406+
crh: Cr::<$port_id, true>(()),
407+
$(
408+
$pxi: $PXi::new(),
409+
)+
410+
}
411+
}
394412
}
395413

396414
impl<MODE> PartiallyErasedPin<$port_id, MODE> {
@@ -802,6 +820,17 @@ where
802820
Pin::new()
803821
}
804822

823+
/// Configures the pin to operate as an push-pull output pin.
824+
/// The state will not be changed.
825+
#[inline]
826+
pub fn into_push_pull_output_with_current_state(
827+
mut self,
828+
cr: &mut <Self as HL>::Cr,
829+
) -> Pin<P, N, Output<PushPull>> {
830+
self.mode::<Output<PushPull>>(cr);
831+
Pin::new()
832+
}
833+
805834
/// Configures the pin to operate as an analog input pin
806835
#[inline]
807836
pub fn into_analog(mut self, cr: &mut <Self as HL>::Cr) -> Pin<P, N, Analog> {

0 commit comments

Comments
 (0)