aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-04-11 00:06:28 +0000
committerGitHub <[email protected]>2025-04-11 00:06:28 +0000
commit29ef61cd572e24a1f76205569f97c88b3136d7f2 (patch)
treeb41998ede3ad4997b904428e93eb5e95f2ea5446
parent7e78e5829ce239b2e5a4afab0ca7f9ed895425fa (diff)
parentaae3f7fb70600851240501c9eced2cbc248ca700 (diff)
Merge pull request #4077 from RichardWGNR/issue-4075
[embassy-stm32] Capability to modify CAN frame data without copying.
-rw-r--r--embassy-stm32/src/can/frame.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/embassy-stm32/src/can/frame.rs b/embassy-stm32/src/can/frame.rs
index d2d1f7aa6..f621b8bd5 100644
--- a/embassy-stm32/src/can/frame.rs
+++ b/embassy-stm32/src/can/frame.rs
@@ -129,6 +129,11 @@ impl ClassicData {
129 &self.bytes 129 &self.bytes
130 } 130 }
131 131
132 /// Raw mutable read access to data.
133 pub fn raw_mut(&mut self) -> &mut [u8] {
134 &mut self.bytes
135 }
136
132 /// Checks if the length can be encoded in FDCAN DLC field. 137 /// Checks if the length can be encoded in FDCAN DLC field.
133 pub const fn is_valid_len(len: usize) -> bool { 138 pub const fn is_valid_len(len: usize) -> bool {
134 match len { 139 match len {
@@ -209,6 +214,11 @@ impl Frame {
209 &self.data.raw() 214 &self.data.raw()
210 } 215 }
211 216
217 /// Get mutable reference to data
218 pub fn data_mut(&mut self) -> &mut [u8] {
219 self.data.raw_mut()
220 }
221
212 /// Get priority of frame 222 /// Get priority of frame
213 pub fn priority(&self) -> u32 { 223 pub fn priority(&self) -> u32 {
214 self.header().priority() 224 self.header().priority()
@@ -314,6 +324,11 @@ impl FdData {
314 &self.bytes 324 &self.bytes
315 } 325 }
316 326
327 /// Raw mutable read access to data.
328 pub fn raw_mut(&mut self) -> &mut [u8] {
329 &mut self.bytes
330 }
331
317 /// Checks if the length can be encoded in FDCAN DLC field. 332 /// Checks if the length can be encoded in FDCAN DLC field.
318 pub const fn is_valid_len(len: usize) -> bool { 333 pub const fn is_valid_len(len: usize) -> bool {
319 match len { 334 match len {
@@ -392,6 +407,11 @@ impl FdFrame {
392 pub fn data(&self) -> &[u8] { 407 pub fn data(&self) -> &[u8] {
393 &self.data.raw() 408 &self.data.raw()
394 } 409 }
410
411 /// Get mutable reference to data
412 pub fn data_mut(&mut self) -> &mut [u8] {
413 self.data.raw_mut()
414 }
395} 415}
396 416
397impl embedded_can::Frame for FdFrame { 417impl embedded_can::Frame for FdFrame {