Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can refactor #178

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/can.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

pub use embedded_hal_can::{self, Filter, Frame, Id, Receiver, Transmitter};

// TODO Switch to embedded-can
// https://github.com/timokroeger/embedded-can/blob/master/src/lib.rs
// https://github.com/rust-embedded/embedded-hal/pull/212
// TODO Use bxcan
// https://github.com/stm32-rs/bxcan

use crate::gpio::gpioa;
use crate::gpio::AF9;
use crate::rcc::APB1;
Expand All @@ -33,13 +39,14 @@ pub enum CanId {
/// Extended 29bit Identifier (0..=0x1FFF_FFFF)
ExtendedId(u32),
}

/// A CAN frame consisting of a destination ID and up to 8 bytes of data.
///
/// 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.
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct CanFrame {
// TODO must they be pub?
// How are they set and get interally?
/// CAN Frame ID
id: CanId,
/// Data Length Code (range 0..=8)
Expand Down Expand Up @@ -187,6 +194,7 @@ impl embedded_hal_can::Filter for CanFilter {

/// Constuct a mask filter. This method accepts two parameters, the mask which designates which
/// bits are actually matched againts and the filter, with the actual bits to match.
// TODO Result?
fn from_mask(mask: u32, filter: u32) -> Self {
assert!(
mask < MAX_EXTENDED_ID,
Expand Down