From b700b0c13cff2df61f9278120d2cde73a15bf537 Mon Sep 17 00:00:00 2001 From: Max Guichard Date: Thu, 21 Nov 2024 13:08:38 +0100 Subject: [PATCH] Cleanup CAN Header interface --- embassy-stm32/src/can/frame.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/embassy-stm32/src/can/frame.rs b/embassy-stm32/src/can/frame.rs index 3497bae5f..98a2b19f5 100644 --- a/embassy-stm32/src/can/frame.rs +++ b/embassy-stm32/src/can/frame.rs @@ -68,19 +68,19 @@ impl Header { const FLAG_BRS: usize = 2; // Bit-rate switching, ignored for Classic CAN /// Create new CAN Header - pub fn new(id: embedded_can::Id, len: u8, rtr: bool) -> Header { + pub fn new(id: impl Into, len: u8, rtr: bool) -> Header { let mut flags = 0u8; flags.set_bit(Self::FLAG_RTR, rtr); - Header { id, len, flags } + Header { id: id.into(), len, flags } } /// Create new CAN FD Header - pub fn new_fd(id: embedded_can::Id, len: u8, rtr: bool, brs: bool) -> Header { + pub fn new_fd(id: impl Into, len: u8, rtr: bool, brs: bool) -> Header { let mut flags = 0u8; flags.set_bit(Self::FLAG_RTR, rtr); flags.set_bit(Self::FLAG_FDCAN, true); flags.set_bit(Self::FLAG_BRS, brs); - Header { id, len, flags } + Header { id: id.into(), len, flags } } /// Return ID @@ -199,7 +199,7 @@ impl Frame { /// Create new extended frame pub fn new_extended(raw_id: u32, raw_data: &[u8]) -> Result { if let Some(id) = embedded_can::ExtendedId::new(raw_id) { - Self::new(Header::new(id.into(), raw_data.len() as u8, false), raw_data) + Self::new(Header::new(id, raw_data.len() as u8, false), raw_data) } else { Err(FrameCreateError::InvalidCanId) } @@ -208,7 +208,7 @@ impl Frame { /// Create new standard frame pub fn new_standard(raw_id: u16, raw_data: &[u8]) -> Result { if let Some(id) = embedded_can::StandardId::new(raw_id) { - Self::new(Header::new(id.into(), raw_data.len() as u8, false), raw_data) + Self::new(Header::new(id, raw_data.len() as u8, false), raw_data) } else { Err(FrameCreateError::InvalidCanId) } @@ -384,7 +384,7 @@ impl FdFrame { /// BRS is set to false by default pub fn new_extended(raw_id: u32, raw_data: &[u8]) -> Result { if let Some(id) = embedded_can::ExtendedId::new(raw_id) { - Self::new(Header::new(id.into(), raw_data.len() as u8, false), raw_data) + Self::new(Header::new(id, raw_data.len() as u8, false), raw_data) } else { Err(FrameCreateError::InvalidCanId) } @@ -393,7 +393,7 @@ impl FdFrame { /// Create new standard frame pub fn new_standard(raw_id: u16, raw_data: &[u8]) -> Result { if let Some(id) = embedded_can::StandardId::new(raw_id) { - Self::new(Header::new(id.into(), raw_data.len() as u8, false), raw_data) + Self::new(Header::new(id, raw_data.len() as u8, false), raw_data) } else { Err(FrameCreateError::InvalidCanId) }