Skip to content

Commit bd0dd68

Browse files
committed
add some brief docs
1 parent 4618c51 commit bd0dd68

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/can.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Controller Area Network
12
pub use embedded_hal_can::{self, Filter, Frame, Id, Receiver, Transmitter};
23

34
use crate::gpio::gpioa;
@@ -12,23 +13,29 @@ use core::sync::atomic::{AtomicU8, Ordering};
1213
const EXID_MASK: u32 = 0b11111_11111100_00000000_00000000;
1314
const MAX_EXTENDED_ID: u32 = 0x1FFF_FFFF;
1415

16+
/// A CAN identifier, which can be either 11 or 27 (extended) bits. u16 and u32 respectively are used here despite the fact that the upper bits are unused.
1517
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1618
pub enum CanId {
1719
BaseId(u16),
1820
ExtendedId(u32),
1921
}
2022

23+
/// A CAN frame consisting of a destination ID and up to 8 bytes of data.
24+
///
25+
/// Currently, we always allocate a fixed size array for each frame regardless of actual size, but this could be improved in the future using const-generics.
2126
#[derive(Debug, Clone, Eq, PartialEq)]
2227
pub struct CanFrame {
2328
pub id: CanId,
2429
pub data: Vec<u8, U8>,
2530
}
2631

32+
/// Represents the operating mode of a CAN filter, which can either contain a list of identifiers, or a mask to match on.
2733
pub enum FilterMode {
2834
Mask,
2935
List,
3036
}
3137

38+
/// A fully specified CAN filter with its associated list of of IDs or mask.
3239
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
3340
pub enum CanFilterData {
3441
IdFilter(CanId),
@@ -51,16 +58,19 @@ pub struct Can {
5158
_tx: gpioa::PA12<AF9>,
5259
}
5360

61+
/// A CAN FIFO which is used to receive and buffer messages from the CAN network that match on of the assigned filters.
5462
pub struct CanFifo {
5563
idx: usize,
5664
}
5765

66+
/// A CAN transmitter which is used to send messages to the CAN network.
5867
pub struct CanTransmitter {
5968
_can: stm32::CAN,
6069
_rx: gpioa::PA11<AF9>,
6170
_tx: gpioa::PA12<AF9>,
6271
}
6372

73+
/// CAN Interrupt events
6474
pub enum Event {
6575
Fifo0Fmp,
6676
Fifo1Fmp,
@@ -145,10 +155,12 @@ impl embedded_hal_can::Filter for CanFilter {
145155
}
146156

147157
impl CanFilter {
158+
/// Create a new filter with no assigned index. To actually active the filter call `Receiver::set_filter`, which will assign an index.
148159
pub fn new(data: CanFilterData) -> CanFilter {
149160
CanFilter { data, index: None }
150161
}
151162

163+
/// Create a new filter with a specified filter index.
152164
pub fn new_with_index(index: u8, data: CanFilterData) -> CanFilter {
153165
CanFilter {
154166
data,
@@ -246,6 +258,7 @@ impl Can {
246258
}
247259
}
248260

261+
/// Enable CAN event interrupts for `Event`
249262
pub fn listen(&mut self, event: Event) {
250263
self.can.ier.modify(|_, w| match event {
251264
Event::Fifo0Fmp => w.fmpie0().set_bit(),
@@ -256,6 +269,7 @@ impl Can {
256269
});
257270
}
258271

272+
/// Split the CAN peripheral into a transmitter and associated FIFOs.
259273
pub fn split(self) -> (CanTransmitter, CanFifo, CanFifo) {
260274
let fifo0 = CanFifo { idx: 0 };
261275
let fifo1 = CanFifo { idx: 1 };

0 commit comments

Comments
 (0)