Skip to content

Commit f634c33

Browse files
committed
add docs
1 parent 597f50b commit f634c33

File tree

10 files changed

+88
-33
lines changed

10 files changed

+88
-33
lines changed

examples/gpio_erased.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn main() -> ! {
2323
let mut gpioc = dp.GPIOC.split(&mut rcc.ahb);
2424
let mut gpiod = dp.GPIOD.split(&mut rcc.ahb);
2525

26-
let mut pin_array: [gpio::EPin<Input>; 4] = [
26+
let mut pin_array: [gpio::ErasedPin<Input>; 4] = [
2727
gpiob
2828
.pb11
2929
.into_floating_input(&mut gpiob.moder, &mut gpiob.pupdr)

src/gpio.rs

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@
7878
//! To make a pin dynamic, use the `into_dynamic` function, and then use the `make_<mode>` functions to
7979
//! change the mode
8080
81-
#![allow(missing_docs)]
82-
8381
use core::marker::PhantomData;
8482

8583
use crate::pac::{Interrupt, EXTI};
@@ -89,9 +87,9 @@ use crate::Switch;
8987
mod convert;
9088
use convert::PinMode;
9189
mod partially_erased;
92-
pub use partially_erased::{PEPin, PartiallyErasedPin};
90+
pub use partially_erased::PartiallyErasedPin;
9391
mod erased;
94-
pub use erased::{EPin, ErasedPin};
92+
pub use erased::ErasedPin;
9593
mod dynamic;
9694
pub use dynamic::{Dynamic, DynamicPin};
9795
mod hal_02;
@@ -114,11 +112,13 @@ pub trait GpioExt {
114112
fn split(self, ahb: &mut AHB) -> Self::Parts;
115113
}
116114

115+
/// Id, port and mode for any pin
117116
pub trait PinExt {
117+
/// Current pin mode
118118
type Mode;
119-
/// Return pin number
119+
/// Pin number
120120
fn pin_id(&self) -> u8;
121-
/// Return port number
121+
/// Port number starting from 0
122122
fn port_id(&self) -> u8;
123123
}
124124

@@ -154,6 +154,7 @@ pub struct PushPull;
154154
/// Analog mode (type state)
155155
pub struct Analog;
156156

157+
/// JTAG/SWD mote (type state)
157158
pub type Debugger = Alternate<0, PushPull>;
158159

159160
mod sealed {
@@ -184,16 +185,23 @@ impl sealed::NotAlt for Analog {}
184185
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
185186
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
186187
pub enum Speed {
188+
/// Low speed
187189
Low = 0,
190+
/// Medium speed
188191
Medium = 1,
192+
/// High speed
189193
High = 3,
190194
}
191195

196+
/// GPIO interrupt trigger edge selection
192197
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
193198
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
194199
pub enum Edge {
200+
/// Rising edge of voltage
195201
Rising,
202+
/// Falling edge of voltage
196203
Falling,
204+
/// Rising and falling edge of voltage
197205
RisingFalling,
198206
}
199207

@@ -474,16 +482,16 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, MODE> {
474482
///
475483
/// This is useful when you want to collect the pins into an array where you
476484
/// 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)
479487
}
480488

481489
/// Erases the pin number and the port from the type
482490
///
483491
/// This is useful when you want to collect the pins into an array where you
484492
/// 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)
487495
}
488496
}
489497

@@ -522,16 +530,19 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, MODE> {
522530
}
523531

524532
impl<const P: char, const N: u8, MODE> Pin<P, N, Output<MODE>> {
533+
/// Drives the pin high
525534
#[inline(always)]
526535
pub fn set_high(&mut self) {
527536
self._set_high()
528537
}
529538

539+
/// Drives the pin low
530540
#[inline(always)]
531541
pub fn set_low(&mut self) {
532542
self._set_low()
533543
}
534544

545+
/// Is the pin in drive high or low mode?
535546
#[inline(always)]
536547
pub fn get_state(&self) -> PinState {
537548
if self.is_set_low() {
@@ -541,6 +552,7 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, Output<MODE>> {
541552
}
542553
}
543554

555+
/// Drives the pin high or low depending on the provided value
544556
#[inline(always)]
545557
pub fn set_state(&mut self, state: PinState) {
546558
match state {
@@ -549,16 +561,19 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, Output<MODE>> {
549561
}
550562
}
551563

564+
/// Is the pin in drive high mode?
552565
#[inline(always)]
553566
pub fn is_set_high(&self) -> bool {
554567
!self.is_set_low()
555568
}
556569

570+
/// Is the pin in drive low mode?
557571
#[inline(always)]
558572
pub fn is_set_low(&self) -> bool {
559573
self._is_set_low()
560574
}
561575

576+
/// Toggle pin output
562577
#[inline(always)]
563578
pub fn toggle(&mut self) {
564579
if self.is_set_low() {
@@ -573,11 +588,13 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, MODE>
573588
where
574589
MODE: sealed::Readable,
575590
{
591+
/// Is the input pin high?
576592
#[inline(always)]
577593
pub fn is_high(&self) -> bool {
578594
!self.is_low()
579595
}
580596

597+
/// Is the input pin low?
581598
#[inline(always)]
582599
pub fn is_low(&self) -> bool {
583600
self._is_low()
@@ -635,9 +652,14 @@ macro_rules! gpio {
635652
}
636653
}
637654

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>;
639659

640660
$(
661+
#[doc=stringify!($PXi)]
662+
#[doc=" pin"]
641663
pub type $PXi<MODE = Input> = super::Pin<$port_id, $i, MODE>;
642664

643665
$(
@@ -722,7 +744,6 @@ gpio!(GPIOF, gpiof, PF, 'F', PFn, [
722744
PF1: (pf1, 1, [4, 5]),
723745
]);
724746

725-
726747
#[cfg(feature = "gpio-f303e")]
727748
gpio!(GPIOA, gpioa, PA, 'A', PAn, [
728749
PA0: (pa0, 0, [1, 3, 7, 8, 9, 10, 15]),
@@ -870,7 +891,6 @@ gpio!(GPIOH, gpioh, PH, 'H', PHn, [
870891
PH2: (ph2, 2, [1]),
871892
]);
872893

873-
874894
#[cfg(feature = "gpio-f303")]
875895
gpio!(GPIOA, gpioa, PA, 'A', PAn, [
876896
PA0: (pa0, 0, [1, 3, 7, 8, 9, 10, 15]),
@@ -982,7 +1002,6 @@ gpio!(GPIOF, gpiof, PF, 'F', PFn, [
9821002
PF10: (pf10, 10, [1, 3, 5]),
9831003
]);
9841004

985-
9861005
#[cfg(feature = "gpio-f333")]
9871006
gpio!(GPIOA, gpioa, PA, 'A', PAn, [
9881007
PA0: (pa0, 0, [1, 3, 7, 15]),
@@ -1054,7 +1073,6 @@ gpio!(GPIOF, gpiof, PF, 'F', PFn, [
10541073
PF1: (pf1, 1, []),
10551074
]);
10561075

1057-
10581076
#[cfg(feature = "gpio-f373")]
10591077
gpio!(GPIOA, gpioa, PA, 'A', PAn, [
10601078
PA0: (pa0, 0, [1, 2, 3, 7, 8, 11, 15]),

src/gpio/dynamic.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,36 @@ pub struct DynamicPin<const P: char, const N: u8> {
1111

1212
/// Tracks the current pin state for dynamic pins
1313
pub enum Dynamic {
14+
/// Floating input mode
1415
InputFloating,
16+
/// Pull-up input mode
1517
InputPullUp,
18+
/// Pull-down input mode
1619
InputPullDown,
20+
/// Push-pull output mode
1721
OutputPushPull,
22+
/// Open-drain output mode
1823
OutputOpenDrain,
1924
}
2025

26+
/// Error for [DynamicPin]
2127
#[derive(Debug, PartialEq)]
2228
pub enum PinModeError {
29+
/// For operations unsupported in current mode
2330
IncorrectMode,
2431
}
2532

2633
impl Dynamic {
34+
/// Is pin in readable mode
2735
pub fn is_input(&self) -> bool {
2836
use Dynamic::*;
2937
match self {
3038
InputFloating | InputPullUp | InputPullDown | OutputOpenDrain => true,
3139
OutputPushPull => false,
3240
}
3341
}
42+
43+
/// Is pin in writable mode
3444
pub fn is_output(&self) -> bool {
3545
use Dynamic::*;
3646
match self {
@@ -47,34 +57,39 @@ impl crate::Sealed for Unknown {}
4757
impl PinMode for Unknown {}
4858

4959
impl<const P: char, const N: u8> DynamicPin<P, N> {
50-
pub const fn new(mode: Dynamic) -> Self {
60+
pub(super) const fn new(mode: Dynamic) -> Self {
5161
Self { mode }
5262
}
5363

64+
/// Switch pin into pull-up input
5465
#[inline]
5566
pub fn make_pull_up_input(&mut self, moder: &mut MODER<P>, pupdr: &mut PUPDR<P>) {
5667
// NOTE(unsafe), we have a mutable reference to the current pin
5768
Pin::<P, N, Unknown>::new().into_pull_up_input(moder, pupdr);
5869
self.mode = Dynamic::InputPullUp;
5970
}
71+
/// Switch pin into pull-down input
6072
#[inline]
6173
pub fn make_pull_down_input(&mut self, moder: &mut MODER<P>, pupdr: &mut PUPDR<P>) {
6274
// NOTE(unsafe), we have a mutable reference to the current pin
6375
Pin::<P, N, Unknown>::new().into_pull_down_input(moder, pupdr);
6476
self.mode = Dynamic::InputPullDown;
6577
}
78+
/// Switch pin into floating input
6679
#[inline]
6780
pub fn make_floating_input(&mut self, moder: &mut MODER<P>, pupdr: &mut PUPDR<P>) {
6881
// NOTE(unsafe), we have a mutable reference to the current pin
6982
Pin::<P, N, Unknown>::new().into_floating_input(moder, pupdr);
7083
self.mode = Dynamic::InputFloating;
7184
}
85+
/// Switch pin into push-pull output
7286
#[inline]
7387
pub fn make_push_pull_output(&mut self, moder: &mut MODER<P>, otyper: &mut OTYPER<P>) {
7488
// NOTE(unsafe), we have a mutable reference to the current pin
7589
Pin::<P, N, Unknown>::new().into_push_pull_output(moder, otyper);
7690
self.mode = Dynamic::OutputPushPull;
7791
}
92+
/// Switch pin into push-pull output with required voltage state
7893
#[inline]
7994
pub fn make_push_pull_output_in_state(
8095
&mut self,
@@ -86,12 +101,14 @@ impl<const P: char, const N: u8> DynamicPin<P, N> {
86101
Pin::<P, N, Unknown>::new().into_push_pull_output_in_state(moder, otyper, state);
87102
self.mode = Dynamic::OutputPushPull;
88103
}
104+
/// Switch pin into open-drain output
89105
#[inline]
90106
pub fn make_open_drain_output(&mut self, moder: &mut MODER<P>, otyper: &mut OTYPER<P>) {
91107
// NOTE(unsafe), we have a mutable reference to the current pin
92108
Pin::<P, N, Unknown>::new().into_open_drain_output(moder, otyper);
93109
self.mode = Dynamic::OutputOpenDrain;
94110
}
111+
/// Switch pin into open-drain output with required voltage state
95112
#[inline]
96113
pub fn make_open_drain_output_in_state(
97114
&mut self,
@@ -104,6 +121,7 @@ impl<const P: char, const N: u8> DynamicPin<P, N> {
104121
self.mode = Dynamic::OutputOpenDrain;
105122
}
106123

124+
/// Drives the pin high
107125
pub fn set_high(&mut self) -> Result<(), PinModeError> {
108126
if self.mode.is_output() {
109127
Pin::<P, N, Unknown>::new()._set_state(PinState::High);
@@ -112,6 +130,8 @@ impl<const P: char, const N: u8> DynamicPin<P, N> {
112130
Err(PinModeError::IncorrectMode)
113131
}
114132
}
133+
134+
/// Drives the pin low
115135
pub fn set_low(&mut self) -> Result<(), PinModeError> {
116136
if self.mode.is_output() {
117137
Pin::<P, N, Unknown>::new()._set_state(PinState::Low);
@@ -121,9 +141,12 @@ impl<const P: char, const N: u8> DynamicPin<P, N> {
121141
}
122142
}
123143

144+
/// Is the input pin high?
124145
pub fn is_high(&self) -> Result<bool, PinModeError> {
125146
self.is_low().map(|b| !b)
126147
}
148+
149+
/// Is the input pin low?
127150
pub fn is_low(&self) -> Result<bool, PinModeError> {
128151
if self.mode.is_input() {
129152
Ok(Pin::<P, N, Unknown>::new()._is_low())

0 commit comments

Comments
 (0)