@@ -80,6 +80,25 @@ use crate::afio;
8080use crate :: pac:: EXTI ;
8181use crate :: rcc:: APB2 ;
8282
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+
83102/// Extension trait to split a GPIO peripheral in independent pins and registers
84103pub trait GpioExt {
85104 /// The to split the GPIO into
@@ -250,6 +269,8 @@ macro_rules! gpio {
250269 PinMode ,
251270 Dynamic ,
252271 PinModeError ,
272+ OutputSpeed ,
273+ IOPinSpeed ,
253274 } ;
254275
255276 /// GPIO parts
@@ -752,6 +773,26 @@ macro_rules! gpio {
752773 }
753774 }
754775
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+
755796 impl <MODE > toggleable:: Default for $PXi<Output <MODE >> { }
756797
757798 impl <MODE > InputPin for $PXi<Input <MODE >> {
0 commit comments