diff options
| author | RichardWGNR <[email protected]> | 2025-04-11 04:27:03 +0500 |
|---|---|---|
| committer | RichardWGNR <[email protected]> | 2025-04-11 04:27:03 +0500 |
| commit | 4d903a713eb1db05a8465c74e6c6cd71fefc5d4e (patch) | |
| tree | 8fd5ccf4d14b93d6acf5a1d64a5beed11988a345 | |
| parent | 8fb0186f878f28727203d021a5a5ce21a9c06e82 (diff) | |
Capability to modify CAN frame data without copying. #4075
| -rw-r--r-- | embassy-stm32/src/can/frame.rs | 20 |
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..f1bc81ec3 100644 --- a/embassy-stm32/src/can/frame.rs +++ b/embassy-stm32/src/can/frame.rs | |||
| @@ -128,6 +128,11 @@ impl ClassicData { | |||
| 128 | pub fn raw(&self) -> &[u8] { | 128 | pub fn raw(&self) -> &[u8] { |
| 129 | &self.bytes | 129 | &self.bytes |
| 130 | } | 130 | } |
| 131 | |||
| 132 | /// Raw mutable read access to data. | ||
| 133 | pub fn raw_mut(&mut self) -> &mut [u8] { | ||
| 134 | &mut self.bytes | ||
| 135 | } | ||
| 131 | 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 { |
| @@ -208,6 +213,11 @@ impl Frame { | |||
| 208 | pub fn data(&self) -> &[u8] { | 213 | pub fn data(&self) -> &[u8] { |
| 209 | &self.data.raw() | 214 | &self.data.raw() |
| 210 | } | 215 | } |
| 216 | |||
| 217 | /// Get mutable reference to data | ||
| 218 | pub fn data_mut(&mut self) -> &mut [u8] { | ||
| 219 | self.data.raw_mut() | ||
| 220 | } | ||
| 211 | 221 | ||
| 212 | /// Get priority of frame | 222 | /// Get priority of frame |
| 213 | pub fn priority(&self) -> u32 { | 223 | pub fn priority(&self) -> u32 { |
| @@ -313,6 +323,11 @@ impl FdData { | |||
| 313 | pub fn raw(&self) -> &[u8] { | 323 | pub fn raw(&self) -> &[u8] { |
| 314 | &self.bytes | 324 | &self.bytes |
| 315 | } | 325 | } |
| 326 | |||
| 327 | /// Raw mutable read access to data. | ||
| 328 | pub fn raw_mut(&mut self) -> &mut [u8] { | ||
| 329 | &mut self.bytes | ||
| 330 | } | ||
| 316 | 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 { |
| @@ -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 | ||
| 397 | impl embedded_can::Frame for FdFrame { | 417 | impl embedded_can::Frame for FdFrame { |
