@@ -39,6 +39,9 @@ pub struct PushPull;
39
39
/// Open drain output (type state)
40
40
pub struct OpenDrain ;
41
41
42
+ /// Analog mode (type state)
43
+ pub struct Analog ;
44
+
42
45
/// GPIO Pin speed selection
43
46
pub enum Speed {
44
47
Low = 0 ,
@@ -184,7 +187,7 @@ macro_rules! gpio {
184
187
185
188
Alternate , AlternateOD ,
186
189
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 ,
188
191
PullDown , PullUp , PushPull , State , Speed ,
189
192
} ;
190
193
@@ -523,6 +526,29 @@ macro_rules! gpio {
523
526
res
524
527
}
525
528
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
+
526
552
/// Configures the pin to operate as an touch sample
527
553
pub fn into_touch_sample(
528
554
self ,
0 commit comments