80
80
81
81
use core:: marker:: PhantomData ;
82
82
83
- use crate :: pac:: { Interrupt , EXTI } ;
84
83
use crate :: rcc:: AHB ;
85
- use crate :: Switch ;
86
84
87
85
mod convert;
88
86
use convert:: PinMode ;
@@ -91,6 +89,7 @@ pub use partially_erased::PartiallyErasedPin;
91
89
mod erased;
92
90
pub use erased:: ErasedPin ;
93
91
mod dynamic;
92
+ mod exti;
94
93
pub use dynamic:: { Dynamic , DynamicPin } ;
95
94
mod hal_02;
96
95
@@ -172,6 +171,8 @@ mod marker {
172
171
pub trait IntoAf < const A : u8 > : super :: HL { }
173
172
}
174
173
174
+ impl < MODE > marker:: Interruptable for Output < MODE > { }
175
+ impl marker:: Interruptable for Input { }
175
176
impl marker:: Readable for Input { }
176
177
impl marker:: Readable for Output < OpenDrain > { }
177
178
impl marker:: Active for Input { }
@@ -207,10 +208,6 @@ pub enum Edge {
207
208
RisingFalling ,
208
209
}
209
210
210
- use marker:: Interruptable ;
211
- impl < MODE > Interruptable for Output < MODE > { }
212
- impl Interruptable for Input { }
213
-
214
211
/// Opaque MODER register
215
212
pub struct MODER < const P : char > ( ( ) ) ;
216
213
@@ -262,113 +259,6 @@ macro_rules! af {
262
259
263
260
af ! ( [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ] ) ;
264
261
265
- /// Return an EXTI register for the current CPU
266
- #[ cfg( feature = "svd-f373" ) ]
267
- macro_rules! reg_for_cpu {
268
- ( $exti: expr, $xr: ident) => {
269
- $exti. $xr
270
- } ;
271
- }
272
-
273
- /// Return an EXTI register for the current CPU
274
- #[ cfg( not( feature = "svd-f373" ) ) ]
275
- macro_rules! reg_for_cpu {
276
- ( $exti: expr, $xr: ident) => {
277
- paste:: paste! {
278
- $exti. [ <$xr 1 >]
279
- }
280
- } ;
281
- }
282
-
283
- impl < const P : char , const N : u8 , MODE > Pin < P , N , MODE >
284
- where
285
- MODE : Interruptable ,
286
- {
287
- /// NVIC interrupt number of interrupt from this pin
288
- ///
289
- /// Used to unmask / enable the interrupt with [`cortex_m::peripheral::NVIC::unmask()`].
290
- /// This is also useful for all other [`cortex_m::peripheral::NVIC`] functions.
291
- // TODO(Sh3rm4n): It would be cool to have this either const or have a const function.
292
- // But this is currenlty not possible, because index() is runtime defined.
293
- pub fn interrupt ( & self ) -> Interrupt {
294
- match N {
295
- 0 => Interrupt :: EXTI0 ,
296
- 1 => Interrupt :: EXTI1 ,
297
- #[ cfg( feature = "svd-f373" ) ]
298
- 2 => Interrupt :: EXTI2_TS ,
299
- #[ cfg( not( feature = "svd-f373" ) ) ]
300
- 2 => Interrupt :: EXTI2_TSC ,
301
- 3 => Interrupt :: EXTI3 ,
302
- 4 => Interrupt :: EXTI4 ,
303
- #[ cfg( feature = "svd-f373" ) ]
304
- 5 ..=9 => Interrupt :: EXTI5_9 ,
305
- #[ cfg( not( feature = "svd-f373" ) ) ]
306
- 5 ..=9 => Interrupt :: EXTI9_5 ,
307
- 10 ..=15 => Interrupt :: EXTI15_10 ,
308
- _ => crate :: unreachable!( ) ,
309
- }
310
- }
311
-
312
- /// Generate interrupt on rising edge, falling edge, or both
313
- pub fn trigger_on_edge ( & mut self , exti : & mut EXTI , edge : Edge ) {
314
- const BITWIDTH : u8 = 1 ;
315
- let ( rise, fall) = match edge {
316
- Edge :: Rising => ( true as u32 , false as u32 ) ,
317
- Edge :: Falling => ( false as u32 , true as u32 ) ,
318
- Edge :: RisingFalling => ( true as u32 , true as u32 ) ,
319
- } ;
320
- // SAFETY: Unguarded write to the register, but behind a &mut
321
- unsafe {
322
- crate :: modify_at!( reg_for_cpu!( exti, rtsr) , BITWIDTH , N , rise) ;
323
- crate :: modify_at!( reg_for_cpu!( exti, ftsr) , BITWIDTH , N , fall) ;
324
- }
325
- }
326
-
327
- /// Configure external interrupts from this pin
328
- ///
329
- /// # Note
330
- ///
331
- /// Remeber to also configure the interrupt pin on
332
- /// the SysCfg site, with [`crate::syscfg::SysCfg::select_exti_interrupt_source()`]
333
- pub fn configure_interrupt ( & mut self , exti : & mut EXTI , enable : impl Into < Switch > ) {
334
- const BITWIDTH : u8 = 1 ;
335
-
336
- let enable: Switch = enable. into ( ) ;
337
- let enable: bool = enable. into ( ) ;
338
-
339
- let value = u32:: from ( enable) ;
340
- // SAFETY: Unguarded write to the register, but behind a &mut
341
- unsafe { crate :: modify_at!( reg_for_cpu!( exti, imr) , BITWIDTH , N , value) } ;
342
- }
343
-
344
- /// Enable external interrupts from this pin
345
- ///
346
- /// # Note
347
- ///
348
- /// Remeber to also configure the interrupt pin on
349
- /// the SysCfg site, with [`crate::syscfg::SysCfg::select_exti_interrupt_source()`]
350
- pub fn enable_interrupt ( & mut self , exti : & mut EXTI ) {
351
- self . configure_interrupt ( exti, Switch :: On )
352
- }
353
-
354
- /// Disable external interrupts from this pin
355
- pub fn disable_interrupt ( & mut self , exti : & mut EXTI ) {
356
- self . configure_interrupt ( exti, Switch :: Off )
357
- }
358
-
359
- /// Clear the interrupt pending bit for this pin
360
- pub fn clear_interrupt ( & mut self ) {
361
- // SAFETY: Atomic write to register without side-effects.
362
- unsafe { reg_for_cpu ! ( ( * EXTI :: ptr( ) ) , pr) . write ( |w| w. bits ( 1 << N ) ) } ;
363
- }
364
-
365
- /// Reads the interrupt pending bit for this pin
366
- pub fn is_interrupt_pending ( & self ) -> bool {
367
- // SAFETY: Atomic write to register without side-effects.
368
- unsafe { reg_for_cpu ! ( ( * EXTI :: ptr( ) ) , pr) . read ( ) . bits ( ) & ( 1 << N ) != 0 }
369
- }
370
- }
371
-
372
262
/// Generic pin type
373
263
///
374
264
/// - `MODE` is one of the pin modes (see [Modes](crate::gpio#modes) section).
0 commit comments