@@ -67,6 +67,7 @@ use crate::{
67
67
pac:: { Interrupt , EXTI } ,
68
68
rcc:: AHB ,
69
69
syscfg:: SysCfg ,
70
+ Toggle ,
70
71
} ;
71
72
72
73
use crate :: hal:: digital:: v2:: { toggleable, InputPin , StatefulOutputPin } ;
@@ -582,7 +583,14 @@ where
582
583
}
583
584
}
584
585
585
- /// Make corresponding EXTI line sensitive to this pin
586
+ /// Make corresponding EXTI line sensitive to this pin.
587
+ ///
588
+ /// # Note
589
+ ///
590
+ /// Only **one** Pin index of all banks can be activated
591
+ /// for interrupts simultainously.
592
+ ///
593
+ /// For example, only on of `PA1`, `PB1`, `PC1`, ... can be activated.
586
594
pub fn make_interrupt_source ( & mut self , syscfg : & mut SysCfg ) {
587
595
let bitwidth = 4 ;
588
596
let index = self . index . index ( ) % 4 ;
@@ -611,29 +619,37 @@ where
611
619
}
612
620
}
613
621
614
- /// Enable external interrupts from this pin
615
- pub fn enable_interrupt ( & mut self , exti : & mut EXTI ) {
622
+ /// Configure external interrupts from this pin
623
+ ///
624
+ /// Remeber to also configure the interrupt pin on
625
+ /// the SysCfg site, with [`Pin::make_interrupt_source()`]
626
+ pub fn configure_interrupt ( & mut self , exti : & mut EXTI , enable : impl Into < Toggle > ) {
627
+ let enable: Toggle = enable. into ( ) ;
628
+ let enable: bool = enable. into ( ) ;
629
+
616
630
let bitwidth = 1 ;
617
631
let index = self . index . index ( ) ;
618
- let value = 1 ;
632
+ let value = u32 :: from ( enable ) ;
619
633
unsafe { modify_at ! ( reg_for_cpu!( exti, imr) , bitwidth, index, value) } ;
620
634
}
621
635
636
+ /// Enable external interrupts from this pin
637
+ pub fn enable_interrupt ( & mut self , exti : & mut EXTI ) {
638
+ self . configure_interrupt ( exti, Toggle :: On )
639
+ }
640
+
622
641
/// Disable external interrupts from this pin
623
642
pub fn disable_interrupt ( & mut self , exti : & mut EXTI ) {
624
- let bitwidth = 1 ;
625
- let index = self . index . index ( ) ;
626
- let value = 0 ;
627
- unsafe { modify_at ! ( reg_for_cpu!( exti, imr) , bitwidth, index, value) } ;
643
+ self . configure_interrupt ( exti, Toggle :: Off )
628
644
}
629
645
630
646
/// Clear the interrupt pending bit for this pin
631
- pub fn clear_interrupt_pending_bit ( & mut self ) {
647
+ pub fn clear_interrupt ( & mut self ) {
632
648
unsafe { reg_for_cpu ! ( ( * EXTI :: ptr( ) ) , pr) . write ( |w| w. bits ( 1 << self . index . index ( ) ) ) } ;
633
649
}
634
650
635
651
/// Reads the interrupt pending bit for this pin
636
- pub fn check_interrupt ( & self ) -> bool {
652
+ pub fn is_interrupt_pending ( & self ) -> bool {
637
653
unsafe { reg_for_cpu ! ( ( * EXTI :: ptr( ) ) , pr) . read ( ) . bits ( ) & ( 1 << self . index . index ( ) ) != 0 }
638
654
}
639
655
}
0 commit comments