Skip to content

Commit

Permalink
Fixed formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Guichard committed Nov 21, 2024
1 parent b700b0c commit 490829a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion embassy-stm32/src/can/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub enum FrameCreateError {
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum IdCreateError {
/// ID was out of range for 11/28 bit identifier
OutOfRange
OutOfRange,
}

/// Error returned by `try_read`
Expand Down
24 changes: 17 additions & 7 deletions embassy-stm32/src/can/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ pub struct Header {

/// Convenience wrapper for embedded_can::Id
#[derive(Debug, Copy, Clone)]
pub struct Id (
pub struct Id(
// Wrapped ID
embedded_can::Id
embedded_can::Id,
);

impl TryFrom<u16> for Id {
type Error = IdCreateError;

fn try_from(raw_id: u16) -> Result<Self, Self::Error> {
let standard_id = embedded_can::StandardId::new(raw_id).ok_or(IdCreateError::OutOfRange)?;
Ok (Id { 0: standard_id.into() })
Ok(Id { 0: standard_id.into() })
}
}

Expand All @@ -40,12 +40,14 @@ impl TryFrom<u32> for Id {

fn try_from(raw_id: u32) -> Result<Self, Self::Error> {
let extended_id = embedded_can::ExtendedId::new(raw_id).ok_or(IdCreateError::OutOfRange)?;
Ok (Id { 0: extended_id.into() })
Ok(Id { 0: extended_id.into() })
}
}

impl From<Id> for embedded_can::Id {
fn from(id: Id) -> Self { id.0 }
fn from(id: Id) -> Self {
id.0
}
}

#[cfg(feature = "defmt")]
Expand All @@ -71,7 +73,11 @@ impl Header {
pub fn new(id: impl Into<embedded_can::Id>, len: u8, rtr: bool) -> Header {
let mut flags = 0u8;
flags.set_bit(Self::FLAG_RTR, rtr);
Header { id: id.into(), len, flags }
Header {
id: id.into(),
len,
flags,
}
}

/// Create new CAN FD Header
Expand All @@ -80,7 +86,11 @@ impl Header {
flags.set_bit(Self::FLAG_RTR, rtr);
flags.set_bit(Self::FLAG_FDCAN, true);
flags.set_bit(Self::FLAG_BRS, brs);
Header { id: id.into(), len, flags }
Header {
id: id.into(),
len,
flags,
}
}

/// Return ID
Expand Down

0 comments on commit 490829a

Please sign in to comment.