78
78
//! To make a pin dynamic, use the `into_dynamic` function, and then use the `make_<mode>` functions to
79
79
//! change the mode
80
80
81
- #![ allow( missing_docs) ]
82
-
83
81
use core:: marker:: PhantomData ;
84
82
85
83
use crate :: pac:: { Interrupt , EXTI } ;
@@ -89,9 +87,9 @@ use crate::Toggle;
89
87
mod convert;
90
88
use convert:: PinMode ;
91
89
mod partially_erased;
92
- pub use partially_erased:: { PEPin , PartiallyErasedPin } ;
90
+ pub use partially_erased:: PartiallyErasedPin ;
93
91
mod erased;
94
- pub use erased:: { EPin , ErasedPin } ;
92
+ pub use erased:: ErasedPin ;
95
93
mod dynamic;
96
94
pub use dynamic:: { Dynamic , DynamicPin } ;
97
95
mod hal_02;
@@ -114,11 +112,13 @@ pub trait GpioExt {
114
112
fn split ( self , ahb : & mut AHB ) -> Self :: Parts ;
115
113
}
116
114
115
+ /// Id, port and mode for any pin
117
116
pub trait PinExt {
117
+ /// Current pin mode
118
118
type Mode ;
119
- /// Return pin number
119
+ /// Pin number
120
120
fn pin_id ( & self ) -> u8 ;
121
- /// Return port number
121
+ /// Port number starting from 0
122
122
fn port_id ( & self ) -> u8 ;
123
123
}
124
124
@@ -154,6 +154,7 @@ pub struct PushPull;
154
154
/// Analog mode (type state)
155
155
pub struct Analog ;
156
156
157
+ /// JTAG/SWD mote (type state)
157
158
pub type Debugger = Alternate < 0 , PushPull > ;
158
159
159
160
mod sealed {
@@ -184,16 +185,23 @@ impl sealed::NotAlt for Analog {}
184
185
#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
185
186
#[ derive( Debug , PartialEq , Eq , Clone , Copy ) ]
186
187
pub enum Speed {
188
+ /// Low speed
187
189
Low = 0 ,
190
+ /// Medium speed
188
191
Medium = 1 ,
192
+ /// High speed
189
193
High = 3 ,
190
194
}
191
195
196
+ /// GPIO interrupt trigger edge selection
192
197
#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
193
198
#[ derive( Debug , PartialEq , Eq , Clone , Copy ) ]
194
199
pub enum Edge {
200
+ /// Rising edge of voltage
195
201
Rising ,
202
+ /// Falling edge of voltage
196
203
Falling ,
204
+ /// Rising and falling edge of voltage
197
205
RisingFalling ,
198
206
}
199
207
@@ -474,16 +482,16 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, MODE> {
474
482
///
475
483
/// This is useful when you want to collect the pins into an array where you
476
484
/// need all the elements to have the same type
477
- pub fn erase_number ( self ) -> PEPin < P , MODE > {
478
- PEPin :: new ( N )
485
+ pub fn erase_number ( self ) -> PartiallyErasedPin < P , MODE > {
486
+ PartiallyErasedPin :: new ( N )
479
487
}
480
488
481
489
/// Erases the pin number and the port from the type
482
490
///
483
491
/// This is useful when you want to collect the pins into an array where you
484
492
/// need all the elements to have the same type
485
- pub fn erase ( self ) -> EPin < MODE > {
486
- EPin :: new ( P as u8 - b'A' , N )
493
+ pub fn erase ( self ) -> ErasedPin < MODE > {
494
+ ErasedPin :: new ( P as u8 - b'A' , N )
487
495
}
488
496
}
489
497
@@ -522,16 +530,19 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, MODE> {
522
530
}
523
531
524
532
impl < const P : char , const N : u8 , MODE > Pin < P , N , Output < MODE > > {
533
+ /// Drives the pin high
525
534
#[ inline( always) ]
526
535
pub fn set_high ( & mut self ) {
527
536
self . _set_high ( )
528
537
}
529
538
539
+ /// Drives the pin low
530
540
#[ inline( always) ]
531
541
pub fn set_low ( & mut self ) {
532
542
self . _set_low ( )
533
543
}
534
544
545
+ /// Is the pin in drive high or low mode?
535
546
#[ inline( always) ]
536
547
pub fn get_state ( & self ) -> PinState {
537
548
if self . is_set_low ( ) {
@@ -541,6 +552,7 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, Output<MODE>> {
541
552
}
542
553
}
543
554
555
+ /// Drives the pin high or low depending on the provided value
544
556
#[ inline( always) ]
545
557
pub fn set_state ( & mut self , state : PinState ) {
546
558
match state {
@@ -549,16 +561,19 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, Output<MODE>> {
549
561
}
550
562
}
551
563
564
+ /// Is the pin in drive high mode?
552
565
#[ inline( always) ]
553
566
pub fn is_set_high ( & self ) -> bool {
554
567
!self . is_set_low ( )
555
568
}
556
569
570
+ /// Is the pin in drive low mode?
557
571
#[ inline( always) ]
558
572
pub fn is_set_low ( & self ) -> bool {
559
573
self . _is_set_low ( )
560
574
}
561
575
576
+ /// Toggle pin output
562
577
#[ inline( always) ]
563
578
pub fn toggle ( & mut self ) {
564
579
if self . is_set_low ( ) {
@@ -573,11 +588,13 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, MODE>
573
588
where
574
589
MODE : sealed:: Readable ,
575
590
{
591
+ /// Is the input pin high?
576
592
#[ inline( always) ]
577
593
pub fn is_high ( & self ) -> bool {
578
594
!self . is_low ( )
579
595
}
580
596
597
+ /// Is the input pin low?
581
598
#[ inline( always) ]
582
599
pub fn is_low ( & self ) -> bool {
583
600
self . _is_low ( )
@@ -635,9 +652,14 @@ macro_rules! gpio {
635
652
}
636
653
}
637
654
638
- pub type $PXn<MODE > = super :: PEPin <$port_id, MODE >;
655
+ #[ doc="Common type for " ]
656
+ #[ doc=stringify!( $GPIOX) ]
657
+ #[ doc=" related pins" ]
658
+ pub type $PXn<MODE > = super :: PartiallyErasedPin <$port_id, MODE >;
639
659
640
660
$(
661
+ #[ doc=stringify!( $PXi) ]
662
+ #[ doc=" pin" ]
641
663
pub type $PXi<MODE = Input > = super :: Pin <$port_id, $i, MODE >;
642
664
643
665
$(
@@ -722,7 +744,6 @@ gpio!(GPIOF, gpiof, PF, 'F', PFn, [
722
744
PF1 : ( pf1, 1 , [ 4 , 5 ] ) ,
723
745
] ) ;
724
746
725
-
726
747
#[ cfg( feature = "gpio-f303e" ) ]
727
748
gpio ! ( GPIOA , gpioa, PA , 'A' , PAn , [
728
749
PA0 : ( pa0, 0 , [ 1 , 3 , 7 , 8 , 9 , 10 , 15 ] ) ,
@@ -870,7 +891,6 @@ gpio!(GPIOH, gpioh, PH, 'H', PHn, [
870
891
PH2 : ( ph2, 2 , [ 1 ] ) ,
871
892
] ) ;
872
893
873
-
874
894
#[ cfg( feature = "gpio-f303" ) ]
875
895
gpio ! ( GPIOA , gpioa, PA , 'A' , PAn , [
876
896
PA0 : ( pa0, 0 , [ 1 , 3 , 7 , 8 , 9 , 10 , 15 ] ) ,
@@ -982,7 +1002,6 @@ gpio!(GPIOF, gpiof, PF, 'F', PFn, [
982
1002
PF10 : ( pf10, 10 , [ 1 , 3 , 5 ] ) ,
983
1003
] ) ;
984
1004
985
-
986
1005
#[ cfg( feature = "gpio-f333" ) ]
987
1006
gpio ! ( GPIOA , gpioa, PA , 'A' , PAn , [
988
1007
PA0 : ( pa0, 0 , [ 1 , 3 , 7 , 15 ] ) ,
@@ -1054,7 +1073,6 @@ gpio!(GPIOF, gpiof, PF, 'F', PFn, [
1054
1073
PF1 : ( pf1, 1 , [ ] ) ,
1055
1074
] ) ;
1056
1075
1057
-
1058
1076
#[ cfg( feature = "gpio-f373" ) ]
1059
1077
gpio ! ( GPIOA , gpioa, PA , 'A' , PAn , [
1060
1078
PA0 : ( pa0, 0 , [ 1 , 2 , 3 , 7 , 8 , 11 , 15 ] ) ,
0 commit comments