Revert "Stm32 can data len"

This commit is contained in:
Dario Nieuwenhuis 2025-04-28 01:18:41 +02:00 committed by GitHub
parent 1d2f0add77
commit 1b42953f03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 21 deletions

View File

@ -299,9 +299,9 @@ impl Registers {
mb.tdtr().write(|w| w.set_dlc(frame.header().len() as u8));
mb.tdlr()
.write(|w| w.0 = u32::from_ne_bytes(unwrap!(frame.raw_data()[0..4].try_into())));
.write(|w| w.0 = u32::from_ne_bytes(unwrap!(frame.data()[0..4].try_into())));
mb.tdhr()
.write(|w| w.0 = u32::from_ne_bytes(unwrap!(frame.raw_data()[4..8].try_into())));
.write(|w| w.0 = u32::from_ne_bytes(unwrap!(frame.data()[4..8].try_into())));
let id: IdReg = frame.id().into();
mb.tir().write(|w| {
w.0 = id.0;

View File

@ -75,7 +75,7 @@ impl Registers {
let mailbox = self.tx_buffer_element(bufidx);
mailbox.reset();
put_tx_header(mailbox, header);
put_tx_data(mailbox, buffer);
put_tx_data(mailbox, &buffer[..header.len() as usize]);
// Set <idx as Mailbox> as ready to transmit
self.regs.txbar().modify(|w| w.set_ar(bufidx, true));
@ -190,7 +190,7 @@ impl Registers {
DataLength::Fdcan(len) => len,
DataLength::Classic(len) => len,
};
if len as usize > 8 {
if len as usize > ClassicData::MAX_DATA_LEN {
return None;
}

View File

@ -104,13 +104,15 @@ pub trait CanHeader: Sized {
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct ClassicData {
pub(crate) bytes: [u8; 8],
pub(crate) bytes: [u8; Self::MAX_DATA_LEN],
}
impl ClassicData {
pub(crate) const MAX_DATA_LEN: usize = 8;
/// Creates a data payload from a raw byte slice.
///
/// Returns `FrameCreateError` if `data` is more than 8 bytes (which is the maximum).
/// Returns `None` if `data` is more than 64 bytes (which is the maximum) or
/// cannot be represented with an FDCAN DLC.
pub fn new(data: &[u8]) -> Result<Self, FrameCreateError> {
if data.len() > 8 {
return Err(FrameCreateError::InvalidDataLength);
@ -209,17 +211,12 @@ impl Frame {
/// Get reference to data
pub fn data(&self) -> &[u8] {
&self.data.raw()[..self.can_header.len as usize]
}
/// Get reference to underlying 8-byte raw data buffer, some bytes on the tail might be undefined.
pub fn raw_data(&self) -> &[u8] {
self.data.raw()
&self.data.raw()
}
/// Get mutable reference to data
pub fn data_mut(&mut self) -> &mut [u8] {
&mut self.data.raw_mut()[..self.can_header.len as usize]
self.data.raw_mut()
}
/// Get priority of frame
@ -263,7 +260,7 @@ impl embedded_can::Frame for Frame {
self.can_header.len as usize
}
fn data(&self) -> &[u8] {
&self.data()
&self.data.raw()
}
}
@ -408,12 +405,12 @@ impl FdFrame {
/// Get reference to data
pub fn data(&self) -> &[u8] {
&self.data.raw()[..self.can_header.len as usize]
&self.data.raw()
}
/// Get mutable reference to data
pub fn data_mut(&mut self) -> &mut [u8] {
&mut self.data.raw_mut()[..self.can_header.len as usize]
self.data.raw_mut()
}
}
@ -451,7 +448,7 @@ impl embedded_can::Frame for FdFrame {
self.can_header.len as usize
}
fn data(&self) -> &[u8] {
&self.data()
&self.data.raw()
}
}

View File

@ -422,13 +422,11 @@ impl<'d, T: Instance> OpAmp<'d, T> {
T::regs().csr().modify(|w| match pair {
OpAmpDifferentialPair::P => {
#[cfg(feature = "defmt")]
defmt::debug!("opamp p calibration. offset: {}", mid);
defmt::info!("p calibration. offset: {}", mid);
w.set_trimoffsetp(mid);
}
OpAmpDifferentialPair::N => {
#[cfg(feature = "defmt")]
defmt::debug!("opamp n calibration. offset: {}", mid);
defmt::info!("n calibration. offset: {}", mid);
w.set_trimoffsetn(mid);
}
});