@@ -66,7 +66,6 @@ use crate::{
66
66
hal:: digital:: v2:: OutputPin ,
67
67
pac:: { Interrupt , EXTI } ,
68
68
rcc:: AHB ,
69
- syscfg:: SysCfg ,
70
69
Toggle ,
71
70
} ;
72
71
@@ -291,8 +290,8 @@ pub enum Edge {
291
290
292
291
/// Generic pin
293
292
pub struct Pin < Gpio , Index , Mode > {
294
- gpio : Gpio ,
295
- index : Index ,
293
+ pub ( crate ) gpio : Gpio ,
294
+ pub ( crate ) index : Index ,
296
295
_mode : PhantomData < Mode > ,
297
296
}
298
297
@@ -310,17 +309,6 @@ impl<Gpio, Index, Mode> crate::private::Sealed for Pin<Gpio, Index, Mode> {}
310
309
/// [examples/gpio_erased.rs]: https://github.com/stm32-rs/stm32f3xx-hal/blob/v0.7.0/examples/gpio_erased.rs
311
310
pub type PXx < Mode > = Pin < Gpiox , Ux , Mode > ;
312
311
313
- /// Modify specific index of array-like register
314
- macro_rules! modify_at {
315
- ( $reg: expr, $bitwidth: expr, $index: expr, $value: expr) => {
316
- $reg. modify( |r, w| {
317
- let mask = !( u32 :: MAX >> ( 32 - $bitwidth) << ( $bitwidth * $index) ) ;
318
- let value = $value << ( $bitwidth * $index) ;
319
- w. bits( r. bits( ) & mask | value)
320
- } ) ;
321
- } ;
322
- }
323
-
324
312
impl < Gpio , Mode , const X : u8 > Pin < Gpio , U < X > , Mode > {
325
313
/// Erases the pin number from the type
326
314
///
@@ -593,33 +581,10 @@ where
593
581
#[ cfg( not( feature = "svd-f373" ) ) ]
594
582
5 ..=9 => Interrupt :: EXTI9_5 ,
595
583
10 ..=15 => Interrupt :: EXTI15_10 ,
596
- _ => unreachable ! ( ) ,
584
+ _ => crate :: unreachable!( ) ,
597
585
}
598
586
}
599
587
600
- /// Make corresponding EXTI line sensitive to this pin.
601
- ///
602
- /// # Note
603
- ///
604
- /// Only **one** Pin index of all banks can be activated
605
- /// for interrupts simultainously.
606
- ///
607
- /// For example, only on of `PA1`, `PB1`, `PC1`, ... can be activated.
608
- pub fn make_interrupt_source ( & mut self , syscfg : & mut SysCfg ) {
609
- const BITWIDTH : u8 = 4 ;
610
- let index = self . index . index ( ) % 4 ;
611
- let extigpionr = self . gpio . port_index ( ) as u32 ;
612
- match self . index . index ( ) {
613
- // SAFETY: These are all unguarded writes directly to the register,
614
- // without leveraging the safety of stm32f3 generated values.
615
- 0 ..=3 => unsafe { modify_at ! ( syscfg. exticr1, BITWIDTH , index, extigpionr) } ,
616
- 4 ..=7 => unsafe { modify_at ! ( syscfg. exticr2, BITWIDTH , index, extigpionr) } ,
617
- 8 ..=11 => unsafe { modify_at ! ( syscfg. exticr3, BITWIDTH , index, extigpionr) } ,
618
- 12 ..=15 => unsafe { modify_at ! ( syscfg. exticr4, BITWIDTH , index, extigpionr) } ,
619
- _ => unreachable ! ( ) ,
620
- } ;
621
- }
622
-
623
588
/// Generate interrupt on rising edge, falling edge, or both
624
589
pub fn trigger_on_edge ( & mut self , exti : & mut EXTI , edge : Edge ) {
625
590
const BITWIDTH : u8 = 1 ;
@@ -631,15 +596,17 @@ where
631
596
} ;
632
597
// SAFETY: Unguarded write to the register, but behind a &mut
633
598
unsafe {
634
- modify_at ! ( reg_for_cpu!( exti, rtsr) , BITWIDTH , index, rise) ;
635
- modify_at ! ( reg_for_cpu!( exti, ftsr) , BITWIDTH , index, fall) ;
599
+ crate :: modify_at!( reg_for_cpu!( exti, rtsr) , BITWIDTH , index, rise) ;
600
+ crate :: modify_at!( reg_for_cpu!( exti, ftsr) , BITWIDTH , index, fall) ;
636
601
}
637
602
}
638
603
639
604
/// Configure external interrupts from this pin
640
605
///
606
+ /// # Note
607
+ ///
641
608
/// Remeber to also configure the interrupt pin on
642
- /// the SysCfg site, with [`Pin::make_interrupt_source ()`]
609
+ /// the SysCfg site, with [`crate::syscfg::SysCfg::select_exti_interrupt_source ()`]
643
610
pub fn configure_interrupt ( & mut self , exti : & mut EXTI , enable : impl Into < Toggle > ) {
644
611
const BITWIDTH : u8 = 1 ;
645
612
@@ -649,10 +616,15 @@ where
649
616
let index = self . index . index ( ) ;
650
617
let value = u32:: from ( enable) ;
651
618
// SAFETY: Unguarded write to the register, but behind a &mut
652
- unsafe { modify_at ! ( reg_for_cpu!( exti, imr) , BITWIDTH , index, value) } ;
619
+ unsafe { crate :: modify_at!( reg_for_cpu!( exti, imr) , BITWIDTH , index, value) } ;
653
620
}
654
621
655
622
/// Enable external interrupts from this pin
623
+ ///
624
+ /// # Note
625
+ ///
626
+ /// Remeber to also configure the interrupt pin on
627
+ /// the SysCfg site, with [`crate::syscfg::SysCfg::select_exti_interrupt_source()`]
656
628
pub fn enable_interrupt ( & mut self , exti : & mut EXTI ) {
657
629
self . configure_interrupt ( exti, Toggle :: On )
658
630
}
@@ -772,7 +744,7 @@ macro_rules! r_trait {
772
744
#[ inline]
773
745
fn $fn( & mut self , i: u8 ) {
774
746
let value = $gpioy:: $xr:: $enum:: $VARIANT as u32 ;
775
- unsafe { modify_at!( ( * $GPIOX:: ptr( ) ) . $xr, $bitwidth, i, value) } ;
747
+ unsafe { crate :: modify_at!( ( * $GPIOX:: ptr( ) ) . $xr, $bitwidth, i, value) } ;
776
748
}
777
749
) +
778
750
}
@@ -913,7 +885,7 @@ macro_rules! gpio {
913
885
#[ inline]
914
886
fn afx( & mut self , i: u8 , x: u8 ) {
915
887
const BITWIDTH : u8 = 4 ;
916
- unsafe { modify_at!( ( * $GPIOX:: ptr( ) ) . afrh, BITWIDTH , i - 8 , x as u32 ) } ;
888
+ unsafe { crate :: modify_at!( ( * $GPIOX:: ptr( ) ) . afrh, BITWIDTH , i - 8 , x as u32 ) } ;
917
889
}
918
890
}
919
891
@@ -924,7 +896,7 @@ macro_rules! gpio {
924
896
#[ inline]
925
897
fn afx( & mut self , i: u8 , x: u8 ) {
926
898
const BITWIDTH : u8 = 4 ;
927
- unsafe { modify_at!( ( * $GPIOX:: ptr( ) ) . afrl, BITWIDTH , i, x as u32 ) } ;
899
+ unsafe { crate :: modify_at!( ( * $GPIOX:: ptr( ) ) . afrl, BITWIDTH , i, x as u32 ) } ;
928
900
}
929
901
}
930
902
0 commit comments