@@ -603,30 +603,32 @@ where
603
603
///
604
604
/// For example, only on of `PA1`, `PB1`, `PC1`, ... can be activated.
605
605
pub fn make_interrupt_source ( & mut self , syscfg : & mut SysCfg ) {
606
- let bitwidth = 4 ;
606
+ const BITWIDTH : u8 = 4 ;
607
607
let index = self . index . index ( ) % 4 ;
608
608
let extigpionr = self . gpio . port_index ( ) as u32 ;
609
609
match self . index . index ( ) {
610
- 0 ..=3 => unsafe { modify_at ! ( syscfg. exticr1, bitwidth, index, extigpionr) } ,
611
- 4 ..=7 => unsafe { modify_at ! ( syscfg. exticr2, bitwidth, index, extigpionr) } ,
612
- 8 ..=11 => unsafe { modify_at ! ( syscfg. exticr3, bitwidth, index, extigpionr) } ,
613
- 12 ..=15 => unsafe { modify_at ! ( syscfg. exticr4, bitwidth, index, extigpionr) } ,
610
+ // SAFETY: These are all unguarded writes directly to the register,
611
+ // without leveraging the safety of stm32f3 generated values.
612
+ 0 ..=3 => unsafe { modify_at ! ( syscfg. exticr1, BITWIDTH , index, extigpionr) } ,
613
+ 4 ..=7 => unsafe { modify_at ! ( syscfg. exticr2, BITWIDTH , index, extigpionr) } ,
614
+ 8 ..=11 => unsafe { modify_at ! ( syscfg. exticr3, BITWIDTH , index, extigpionr) } ,
615
+ 12 ..=15 => unsafe { modify_at ! ( syscfg. exticr4, BITWIDTH , index, extigpionr) } ,
614
616
_ => unreachable ! ( ) ,
615
617
} ;
616
618
}
617
619
618
620
/// Generate interrupt on rising edge, falling edge, or both
619
621
pub fn trigger_on_edge ( & mut self , exti : & mut EXTI , edge : Edge ) {
620
- let bitwidth = 1 ;
622
+ const BITWIDTH : u8 = 1 ;
621
623
let index = self . index . index ( ) ;
622
624
let ( rise, fall) = match edge {
623
625
Edge :: Rising => ( true as u32 , false as u32 ) ,
624
626
Edge :: Falling => ( false as u32 , true as u32 ) ,
625
627
Edge :: RisingFalling => ( true as u32 , true as u32 ) ,
626
628
} ;
627
629
unsafe {
628
- modify_at ! ( reg_for_cpu!( exti, rtsr) , bitwidth , index, rise) ;
629
- modify_at ! ( reg_for_cpu!( exti, ftsr) , bitwidth , index, fall) ;
630
+ modify_at ! ( reg_for_cpu!( exti, rtsr) , BITWIDTH , index, rise) ;
631
+ modify_at ! ( reg_for_cpu!( exti, ftsr) , BITWIDTH , index, fall) ;
630
632
}
631
633
}
632
634
@@ -635,13 +637,14 @@ where
635
637
/// Remeber to also configure the interrupt pin on
636
638
/// the SysCfg site, with [`Pin::make_interrupt_source()`]
637
639
pub fn configure_interrupt ( & mut self , exti : & mut EXTI , enable : impl Into < Toggle > ) {
640
+ const BITWIDTH : u8 = 1 ;
641
+
638
642
let enable: Toggle = enable. into ( ) ;
639
643
let enable: bool = enable. into ( ) ;
640
644
641
- let bitwidth = 1 ;
642
645
let index = self . index . index ( ) ;
643
646
let value = u32:: from ( enable) ;
644
- unsafe { modify_at ! ( reg_for_cpu!( exti, imr) , bitwidth , index, value) } ;
647
+ unsafe { modify_at ! ( reg_for_cpu!( exti, imr) , BITWIDTH , index, value) } ;
645
648
}
646
649
647
650
/// Enable external interrupts from this pin
@@ -902,8 +905,8 @@ macro_rules! gpio {
902
905
impl Afr for AFRH {
903
906
#[ inline]
904
907
fn afx( & mut self , i: u8 , x: u8 ) {
905
- let bitwidth = 4 ;
906
- unsafe { modify_at!( ( * $GPIOX:: ptr( ) ) . afrh, bitwidth , i - 8 , x as u32 ) } ;
908
+ const BITWIDTH : u8 = 4 ;
909
+ unsafe { modify_at!( ( * $GPIOX:: ptr( ) ) . afrh, BITWIDTH , i - 8 , x as u32 ) } ;
907
910
}
908
911
}
909
912
@@ -913,8 +916,8 @@ macro_rules! gpio {
913
916
impl Afr for AFRL {
914
917
#[ inline]
915
918
fn afx( & mut self , i: u8 , x: u8 ) {
916
- let bitwidth = 4 ;
917
- unsafe { modify_at!( ( * $GPIOX:: ptr( ) ) . afrl, bitwidth , i, x as u32 ) } ;
919
+ const BITWIDTH : u8 = 4 ;
920
+ unsafe { modify_at!( ( * $GPIOX:: ptr( ) ) . afrl, BITWIDTH , i, x as u32 ) } ;
918
921
}
919
922
}
920
923
0 commit comments