@@ -13,11 +13,17 @@ pub trait GpioExt {
13
13
fn split ( self , apb2 : & mut APB2 ) -> Self :: Parts ;
14
14
}
15
15
16
+ /// Marker trait for active states.
17
+ pub trait Active { }
18
+
16
19
/// Input mode (type state)
17
20
pub struct Input < MODE > {
18
21
_mode : PhantomData < MODE > ,
19
22
}
23
+ impl < MODE > Active for Input < MODE > { }
20
24
25
+ /// Used by the debugger (type state)
26
+ pub struct Debugger ;
21
27
/// Floating input (type state)
22
28
pub struct Floating ;
23
29
/// Pulled down input (type state)
@@ -29,6 +35,7 @@ pub struct PullUp;
29
35
pub struct Output < MODE > {
30
36
_mode : PhantomData < MODE > ,
31
37
}
38
+ impl < MODE > Active for Output < MODE > { }
32
39
33
40
/// Push pull output (type state)
34
41
pub struct PushPull ;
@@ -37,11 +44,13 @@ pub struct OpenDrain;
37
44
38
45
/// Analog mode (type state)
39
46
pub struct Analog ;
47
+ impl Active for Analog { }
40
48
41
49
/// Alternate function
42
50
pub struct Alternate < MODE > {
43
51
_mode : PhantomData < MODE > ,
44
52
}
53
+ impl < MODE > Active for Alternate < MODE > { }
45
54
46
55
pub enum State {
47
56
High ,
@@ -69,6 +78,8 @@ macro_rules! gpio {
69
78
PushPull ,
70
79
Analog ,
71
80
State ,
81
+ Active ,
82
+ Debugger ,
72
83
} ;
73
84
74
85
/// GPIO parts
@@ -184,7 +195,16 @@ macro_rules! gpio {
184
195
_mode: PhantomData <MODE >,
185
196
}
186
197
187
- impl <MODE > $PXi<MODE > {
198
+ impl $PXi<Debugger > {
199
+ /// Put the pin in an active state. The caller
200
+ /// must enforce that the pin is really in this
201
+ /// state in the hardware.
202
+ pub ( crate ) unsafe fn activate( self ) -> $PXi<Input <Floating >> {
203
+ $PXi { _mode: PhantomData }
204
+ }
205
+ }
206
+
207
+ impl <MODE > $PXi<MODE > where MODE : Active {
188
208
/// Configures the pin to operate as an alternate function push-pull output
189
209
/// pin.
190
210
pub fn into_alternate_push_pull(
@@ -402,7 +422,7 @@ macro_rules! gpio {
402
422
}
403
423
}
404
424
405
- impl <MODE > $PXi<MODE > {
425
+ impl <MODE > $PXi<MODE > where MODE : Active {
406
426
/// Erases the pin number from the type
407
427
///
408
428
/// This is useful when you want to collect the pins into an array where you
@@ -503,17 +523,17 @@ gpio!(GPIOA, gpioa, gpioa, iopaen, ioparst, PAx, [
503
523
PA10 : ( pa10, 10 , Input <Floating >, CRH ) ,
504
524
PA11 : ( pa11, 11 , Input <Floating >, CRH ) ,
505
525
PA12 : ( pa12, 12 , Input <Floating >, CRH ) ,
506
- PA13 : ( pa13, 13 , Input < Floating > , CRH ) ,
507
- PA14 : ( pa14, 14 , Input < Floating > , CRH ) ,
508
- PA15 : ( pa15, 15 , Input < Floating > , CRH ) ,
526
+ PA13 : ( pa13, 13 , Debugger , CRH ) ,
527
+ PA14 : ( pa14, 14 , Debugger , CRH ) ,
528
+ PA15 : ( pa15, 15 , Debugger , CRH ) ,
509
529
] ) ;
510
530
511
531
gpio ! ( GPIOB , gpiob, gpioa, iopben, iopbrst, PBx , [
512
532
PB0 : ( pb0, 0 , Input <Floating >, CRL ) ,
513
533
PB1 : ( pb1, 1 , Input <Floating >, CRL ) ,
514
534
PB2 : ( pb2, 2 , Input <Floating >, CRL ) ,
515
- PB3 : ( pb3, 3 , Input < Floating > , CRL ) ,
516
- PB4 : ( pb4, 4 , Input < Floating > , CRL ) ,
535
+ PB3 : ( pb3, 3 , Debugger , CRL ) ,
536
+ PB4 : ( pb4, 4 , Debugger , CRL ) ,
517
537
PB5 : ( pb5, 5 , Input <Floating >, CRL ) ,
518
538
PB6 : ( pb6, 6 , Input <Floating >, CRL ) ,
519
539
PB7 : ( pb7, 7 , Input <Floating >, CRL ) ,
0 commit comments