@@ -80,6 +80,25 @@ use crate::afio;
80
80
use crate :: pac:: EXTI ;
81
81
use crate :: rcc:: APB2 ;
82
82
83
+ /// Slew rates available for Output and relevant AlternateMode Pins
84
+ ///
85
+ /// See Table 21 "Output MODE bits" in the reference
86
+ pub enum IOPinSpeed {
87
+ /// Slew at 10Mhz
88
+ Mhz10 = 0b01 , // (yes, this one is "less" then 2Mhz)
89
+ /// Slew at 2Mhz
90
+ Mhz2 = 0b10 ,
91
+ /// Slew at 50Mhz
92
+ Mhz50 = 0b11 ,
93
+ }
94
+
95
+ /// Allow setting of the slew rate of an IO pin
96
+ ///
97
+ /// Initially all pins are set to the maximum slew rate
98
+ pub trait OutputSpeed < CR > {
99
+ fn set_speed ( & mut self , cr : & mut CR , speed : IOPinSpeed ) ;
100
+ }
101
+
83
102
/// Extension trait to split a GPIO peripheral in independent pins and registers
84
103
pub trait GpioExt {
85
104
/// The to split the GPIO into
@@ -250,6 +269,8 @@ macro_rules! gpio {
250
269
PinMode ,
251
270
Dynamic ,
252
271
PinModeError ,
272
+ OutputSpeed ,
273
+ IOPinSpeed ,
253
274
} ;
254
275
255
276
/// GPIO parts
@@ -752,6 +773,26 @@ macro_rules! gpio {
752
773
}
753
774
}
754
775
776
+ impl <MODE > OutputSpeed <$CR> for $PXi<Output <MODE >> {
777
+ fn set_speed( & mut self , cr: & mut $CR, speed: IOPinSpeed ) {
778
+ const OFFSET : u32 = ( 4 * $i) % 32 ;
779
+
780
+ cr. cr( ) . modify( |r, w| unsafe {
781
+ w. bits( ( r. bits( ) & !( 0b11 << OFFSET ) ) | ( ( speed as u32 ) << OFFSET ) )
782
+ } ) ;
783
+ }
784
+ }
785
+
786
+ impl OutputSpeed <$CR> for $PXi<Alternate <PushPull >> {
787
+ fn set_speed( & mut self , cr: & mut $CR, speed: IOPinSpeed ) {
788
+ const OFFSET : u32 = ( 4 * $i) % 32 ;
789
+
790
+ cr. cr( ) . modify( |r, w| unsafe {
791
+ w. bits( ( r. bits( ) & !( 0b11 << OFFSET ) ) | ( ( speed as u32 ) << OFFSET ) )
792
+ } ) ;
793
+ }
794
+ }
795
+
755
796
impl <MODE > toggleable:: Default for $PXi<Output <MODE >> { }
756
797
757
798
impl <MODE > InputPin for $PXi<Input <MODE >> {
0 commit comments