Merge pull request #4077 from RichardWGNR/issue-4075

[embassy-stm32] Capability to modify CAN frame data without copying.
This commit is contained in:
Dario Nieuwenhuis 2025-04-11 00:06:28 +00:00 committed by GitHub
commit 29ef61cd57
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -129,6 +129,11 @@ impl ClassicData {
&self.bytes &self.bytes
} }
/// Raw mutable read access to data.
pub fn raw_mut(&mut self) -> &mut [u8] {
&mut self.bytes
}
/// Checks if the length can be encoded in FDCAN DLC field. /// Checks if the length can be encoded in FDCAN DLC field.
pub const fn is_valid_len(len: usize) -> bool { pub const fn is_valid_len(len: usize) -> bool {
match len { match len {
@ -209,6 +214,11 @@ impl Frame {
&self.data.raw() &self.data.raw()
} }
/// Get mutable reference to data
pub fn data_mut(&mut self) -> &mut [u8] {
self.data.raw_mut()
}
/// Get priority of frame /// Get priority of frame
pub fn priority(&self) -> u32 { pub fn priority(&self) -> u32 {
self.header().priority() self.header().priority()
@ -314,6 +324,11 @@ impl FdData {
&self.bytes &self.bytes
} }
/// Raw mutable read access to data.
pub fn raw_mut(&mut self) -> &mut [u8] {
&mut self.bytes
}
/// Checks if the length can be encoded in FDCAN DLC field. /// Checks if the length can be encoded in FDCAN DLC field.
pub const fn is_valid_len(len: usize) -> bool { pub const fn is_valid_len(len: usize) -> bool {
match len { match len {
@ -392,6 +407,11 @@ impl FdFrame {
pub fn data(&self) -> &[u8] { pub fn data(&self) -> &[u8] {
&self.data.raw() &self.data.raw()
} }
/// Get mutable reference to data
pub fn data_mut(&mut self) -> &mut [u8] {
self.data.raw_mut()
}
} }
impl embedded_can::Frame for FdFrame { impl embedded_can::Frame for FdFrame {