@@ -39,6 +39,9 @@ pub struct PushPull;
3939/// Open drain output (type state)
4040pub struct OpenDrain ;
4141
42+ /// Analog mode (type state)
43+ pub struct Analog ;
44+
4245/// GPIO Pin speed selection
4346pub enum Speed {
4447 Low = 0 ,
@@ -184,7 +187,7 @@ macro_rules! gpio {
184187
185188 Alternate , AlternateOD ,
186189 AF1 , AF2 , AF3 , AF4 , AF5 , AF6 , AF7 , AF8 , AF9 , AF10 , AF11 , AF12 , AF13 , AF14 , AF15 ,
187- Floating , GpioExt , Input , OpenDrain , Output , Edge , ExtiPin ,
190+ Floating , GpioExt , Input , OpenDrain , Output , Analog , Edge , ExtiPin ,
188191 PullDown , PullUp , PushPull , State , Speed ,
189192 } ;
190193
@@ -523,6 +526,29 @@ macro_rules! gpio {
523526 res
524527 }
525528
529+ /// Configures the pin to operate as analog.
530+ /// This mode is suitable when the pin is connected to the DAC or ADC,
531+ /// COMP, OPAMP.
532+ pub fn into_analog(
533+ self ,
534+ moder: & mut MODER ,
535+ pupdr: & mut PUPDR ,
536+ ) -> $PXi<Analog > {
537+ let offset = 2 * $i;
538+
539+ // analog mode
540+ let mode = 0b11 ;
541+ moder. moder( ) . modify( |r, w| unsafe {
542+ w. bits( ( r. bits( ) & !( 0b11 << offset) ) | ( mode << offset) )
543+ } ) ;
544+
545+ // no pull-up or pull-down
546+ pupdr
547+ . pupdr( )
548+ . modify( |r, w| unsafe { w. bits( r. bits( ) & !( 0b11 << offset) ) } ) ;
549+ $PXi { _mode: PhantomData }
550+ }
551+
526552 /// Configures the pin to operate as an touch sample
527553 pub fn into_touch_sample(
528554 self ,
0 commit comments