@@ -45,6 +45,11 @@ pub struct Alternate<AF, MODE>
4545 _mode : PhantomData < MODE > ,
4646}
4747
48+ pub enum State {
49+ High ,
50+ Low ,
51+ }
52+
4853/// Alternate function 0 (type state)
4954pub struct AF0 ;
5055
@@ -107,7 +112,7 @@ macro_rules! gpio {
107112 use crate :: rcc:: AHB2 ;
108113 use super :: {
109114 Alternate , AF4 , AF5 , AF6 , AF7 , AF8 , AF9 , Floating , GpioExt , Input , OpenDrain , Output ,
110- PullDown , PullUp , PushPull ,
115+ PullDown , PullUp , PushPull , State ,
111116 } ;
112117
113118 /// GPIO parts
@@ -458,11 +463,32 @@ macro_rules! gpio {
458463 }
459464
460465 /// Configures the pin to operate as an push pull output pin
466+ /// Initial state will be low
461467 pub fn into_push_pull_output(
462468 self ,
463469 moder: & mut MODER ,
464470 otyper: & mut OTYPER ,
465471 ) -> $PXi<Output <PushPull >> {
472+ self . into_push_pull_output_with_state( moder, otyper, State :: Low )
473+ }
474+
475+ /// Configures the pin to operate as an push pull output pin
476+ /// Initial state can be chosen to be high or low
477+ pub fn into_push_pull_output_with_state(
478+ self ,
479+ moder: & mut MODER ,
480+ otyper: & mut OTYPER ,
481+ initial_state: State ,
482+ ) -> $PXi<Output <PushPull >> {
483+ let mut res = $PXi { _mode: PhantomData } ;
484+
485+ // set pin high/low before activating, to prevent
486+ // spurious signals (e.g. LED flash)
487+ match initial_state {
488+ State :: High => res. set_high( ) ,
489+ State :: Low => res. set_low( ) ,
490+ }
491+
466492 let offset = 2 * $i;
467493
468494 // general purpose output mode
@@ -476,7 +502,7 @@ macro_rules! gpio {
476502 . otyper( )
477503 . modify( |r, w| unsafe { w. bits( r. bits( ) & !( 0b1 << $i) ) } ) ;
478504
479- $PXi { _mode : PhantomData }
505+ res
480506 }
481507
482508 /// Configures the pin to operate as an touch sample
0 commit comments