Skip to content

Commit aa2e809

Browse files
committed
Add missing docs
Leverage doc_comment macr
1 parent 360d02a commit aa2e809

File tree

10 files changed

+442
-369
lines changed

10 files changed

+442
-369
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ nb = "0.1"
3232
paste = "1"
3333
rtcc = "0.2"
3434
stm32f3 = "0.12"
35+
doc-comment = "0.3.3"
3536

3637
[dependencies.embedded-hal-can]
3738
version = "0.1.0"
@@ -73,7 +74,7 @@ gpio-f303e = []
7374
gpio-f333 = []
7475
gpio-f373 = []
7576

76-
# Any Changes here should be mirrored in README.md, src/lib.rs, and
77+
# Any changes here should be mirrored in README.md, src/lib.rs, and
7778
# .github/workflows/ci.yml.
7879
stm32f301 = ["gpio-f302", "stm32f3/stm32f301", "device-selected"]
7980
stm32f318 = ["gpio-f302", "stm32f3/stm32f301", "device-selected"]

src/adc.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ use crate::{
3434
pac::{ADC3, ADC3_4, ADC4},
3535
};
3636

37-
/// ADC configuration
37+
/// Analog Digital Converter Peripheral
3838
// TODO: Remove `pub` from the register block once all functionalities are implemented.
3939
// Leave it here until then as it allows easy access to the registers.
4040
pub struct Adc<ADC> {
41+
/// ADC Register
4142
pub rb: ADC,
4243
clocks: Clocks,
4344
ckmode: CkMode,
@@ -51,13 +52,21 @@ pub struct Adc<ADC> {
5152
/// E.g. For Sampletime T_19 the total conversion time (in ADC clock cycles) is
5253
/// 13 + 19 = 32 ADC Clock Cycles
5354
pub enum SampleTime {
55+
/// 1.5 ADC clock cycles
5456
T_1,
57+
/// 2.5 ADC clock cycles
5558
T_2,
59+
/// 4.5 ADC clock cycles
5660
T_4,
61+
/// 7.5 ADC clock cycles
5762
T_7,
63+
/// 19.5 ADC clock cycles
5864
T_19,
65+
/// 61.5 ADC clock cycles
5966
T_61,
67+
/// 181.5 ADC clock cycles
6068
T_181,
69+
/// 601.5 ADC clock cycles
6170
T_601,
6271
}
6372

@@ -88,16 +97,21 @@ impl SampleTime {
8897
/// ADC operation mode
8998
// TODO: Implement other modes (DMA, Differential,…)
9099
pub enum OperationMode {
100+
/// OneShot Mode
91101
OneShot,
92102
}
93103

94104
#[derive(Clone, Copy, PartialEq)]
95105
/// ADC CkMode
96106
// TODO: Add ASYNCHRONOUS mode
97107
pub enum CkMode {
108+
// /// Use Kernel Clock adc_ker_ck_input divided by PRESC. Asynchronous to AHB clock
98109
// ASYNCHRONOUS = 0,
110+
/// Use AHB clock rcc_hclk3. In this case rcc_hclk must equal sys_d1cpre_ck
99111
SYNCDIV1 = 1,
112+
/// Use AHB clock rcc_hclk3 divided by 2
100113
SYNCDIV2 = 2,
114+
/// Use AHB clock rcc_hclk3 divided by 4
101115
SYNCDIV4 = 4,
102116
}
103117

src/can.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,33 @@ pub struct CanFrame {
4343
pub data: Vec<u8, U8>,
4444
}
4545

46+
/// Can Frame Filter Mode
47+
///
4648
/// Represents the operating mode of a CAN filter, which can either contain a
4749
/// list of identifiers, or a mask to match on.
4850
pub enum FilterMode {
51+
/// Filter on a given Mask
4952
Mask,
53+
/// Filter on a list of identifiers
5054
List,
5155
}
5256

5357
/// A fully specified CAN filter with its associated list of of IDs or mask.
5458
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
5559
pub enum CanFilterData {
60+
/// Can Frame Identifier Filter
5661
IdFilter(CanId),
62+
/// Filter for an identifier with a applied mask
5763
MaskFilter(u16, u16),
64+
/// Filter for an extended identifier with a applied mask
5865
ExtendedMaskFilter(u32, u32),
66+
/// Do not filter
5967
AcceptAll,
6068
}
6169

70+
/// CAN Filter type
71+
///
72+
/// Used to specify the filter behavior
6273
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
6374
pub struct CanFilter {
6475
data: CanFilterData,
@@ -178,7 +189,9 @@ impl embedded_hal_can::Filter for CanFilter {
178189
}
179190

180191
impl CanFilter {
181-
/// Create a new filter with no assigned index. To actually active the filter call
192+
/// Create a new filter with no assigned index.
193+
///
194+
/// To actually active the filter call
182195
/// [`Receiver::set_filter`], which will assign an index.
183196
pub fn new(data: CanFilterData) -> CanFilter {
184197
CanFilter { data, index: None }
@@ -310,6 +323,7 @@ impl Can {
310323
(transmitter, fifo0, fifo1)
311324
}
312325

326+
/// Release owned peripherals
313327
pub fn free(self) -> (stm32::CAN, gpioa::PA11<AF9>, gpioa::PA12<AF9>) {
314328
(self.can, self._rx, self._tx)
315329
}

src/dma.rs

Lines changed: 63 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -420,80 +420,86 @@ macro_rules! dma {
420420
), )+
421421
},
422422
) => {
423-
pub mod $dmax {
424-
use super::*;
425-
use crate::pac::$DMAx;
423+
doc_comment::doc_comment! {
424+
concat!("All associated types, traits and methods of the ", stringify!($DMAx), " peripheral."),
425+
pub mod $dmax {
426+
use super::*;
427+
use crate::pac::$DMAx;
426428

427-
impl DmaExt for $DMAx {
428-
type Channels = Channels;
429+
impl DmaExt for $DMAx {
430+
type Channels = Channels;
429431

430-
fn split(self, ahb: &mut AHB) -> Channels {
431-
ahb.enr().modify(|_, w| w.$dmaxen().set_bit());
432+
fn split(self, ahb: &mut AHB) -> Channels {
433+
ahb.enr().modify(|_, w| w.$dmaxen().set_bit());
432434

433-
let mut channels = Channels {
434-
$( $chi: $Ci { _0: () }, )+
435-
};
435+
let mut channels = Channels {
436+
$( $chi: $Ci { _0: () }, )+
437+
};
436438

437-
channels.reset();
438-
channels
439+
channels.reset();
440+
channels
441+
}
439442
}
440-
}
441-
442-
/// DMA channels
443-
pub struct Channels {
444-
$( pub $chi: $Ci, )+
445-
}
446443

447-
impl Channels {
448-
/// Reset the control registers of all channels.
449-
/// This stops any ongoing transfers.
450-
fn reset(&mut self) {
451-
$( self.$chi.reset(); )+
444+
/// DMA channels
445+
pub struct Channels {
446+
$(
447+
/// Channel
448+
pub $chi: $Ci,
449+
)+
452450
}
453-
}
454451

455-
$(
456-
/// Singleton that represents a DMA channel
457-
pub struct $Ci {
458-
_0: (),
452+
impl Channels {
453+
/// Reset the control registers of all channels.
454+
/// This stops any ongoing transfers.
455+
fn reset(&mut self) {
456+
$( self.$chi.reset(); )+
457+
}
459458
}
460459

461-
impl private::Channel for $Ci {
462-
fn ch(&self) -> &pac::dma1::CH {
463-
// NOTE(unsafe) $Ci grants exclusive access to this register
464-
unsafe { &(*$DMAx::ptr()).$chi }
460+
$(
461+
/// Singleton that represents a DMA channel
462+
pub struct $Ci {
463+
_0: (),
465464
}
466-
}
467465

468-
impl Channel for $Ci {
469-
fn event_occurred(&self, event: Event) -> bool {
470-
use Event::*;
471-
472-
// NOTE(unsafe) atomic read
473-
let flags = unsafe { (*$DMAx::ptr()).isr.read() };
474-
match event {
475-
HalfTransfer => flags.$htifi().bit_is_set(),
476-
TransferComplete => flags.$tcifi().bit_is_set(),
477-
TransferError => flags.$teifi().bit_is_set(),
478-
Any => flags.$gifi().bit_is_set(),
466+
impl private::Channel for $Ci {
467+
fn ch(&self) -> &pac::dma1::CH {
468+
// NOTE(unsafe) $Ci grants exclusive access to this register
469+
unsafe { &(*$DMAx::ptr()).$chi }
479470
}
480471
}
481472

482-
fn clear_event(&mut self, event: Event) {
483-
use Event::*;
484-
485-
// NOTE(unsafe) atomic write to a stateless register
486-
unsafe {
487-
&(*$DMAx::ptr()).ifcr.write(|w| match event {
488-
HalfTransfer => w.$chtifi().set_bit(),
489-
TransferComplete => w.$ctcifi().set_bit(),
490-
TransferError => w.$cteifi().set_bit(),
491-
Any => w.$cgifi().set_bit(),
492-
});
473+
impl Channel for $Ci {
474+
fn event_occurred(&self, event: Event) -> bool {
475+
use Event::*;
476+
477+
// NOTE(unsafe) atomic read
478+
let flags = unsafe { (*$DMAx::ptr()).isr.read() };
479+
match event {
480+
HalfTransfer => flags.$htifi().bit_is_set(),
481+
TransferComplete => flags.$tcifi().bit_is_set(),
482+
TransferError => flags.$teifi().bit_is_set(),
483+
Any => flags.$gifi().bit_is_set(),
484+
}
485+
}
486+
487+
fn clear_event(&mut self, event: Event) {
488+
use Event::*;
489+
490+
// NOTE(unsafe) atomic write to a stateless register
491+
unsafe {
492+
&(*$DMAx::ptr()).ifcr.write(|w| match event {
493+
HalfTransfer => w.$chtifi().set_bit(),
494+
TransferComplete => w.$ctcifi().set_bit(),
495+
TransferError => w.$cteifi().set_bit(),
496+
Any => w.$cgifi().set_bit(),
497+
});
498+
}
493499
}
494500
}
495-
}
496-
)+
501+
)+
502+
}
497503
}
498504
};
499505

0 commit comments

Comments
 (0)