Merge pull request #4137 from cschuhen/stm32-can-data-len
Stm32 can data len
This commit is contained in:
commit
1d2f0add77
@ -299,9 +299,9 @@ impl Registers {
|
|||||||
mb.tdtr().write(|w| w.set_dlc(frame.header().len() as u8));
|
mb.tdtr().write(|w| w.set_dlc(frame.header().len() as u8));
|
||||||
|
|
||||||
mb.tdlr()
|
mb.tdlr()
|
||||||
.write(|w| w.0 = u32::from_ne_bytes(unwrap!(frame.data()[0..4].try_into())));
|
.write(|w| w.0 = u32::from_ne_bytes(unwrap!(frame.raw_data()[0..4].try_into())));
|
||||||
mb.tdhr()
|
mb.tdhr()
|
||||||
.write(|w| w.0 = u32::from_ne_bytes(unwrap!(frame.data()[4..8].try_into())));
|
.write(|w| w.0 = u32::from_ne_bytes(unwrap!(frame.raw_data()[4..8].try_into())));
|
||||||
let id: IdReg = frame.id().into();
|
let id: IdReg = frame.id().into();
|
||||||
mb.tir().write(|w| {
|
mb.tir().write(|w| {
|
||||||
w.0 = id.0;
|
w.0 = id.0;
|
||||||
|
|||||||
@ -75,7 +75,7 @@ impl Registers {
|
|||||||
let mailbox = self.tx_buffer_element(bufidx);
|
let mailbox = self.tx_buffer_element(bufidx);
|
||||||
mailbox.reset();
|
mailbox.reset();
|
||||||
put_tx_header(mailbox, header);
|
put_tx_header(mailbox, header);
|
||||||
put_tx_data(mailbox, &buffer[..header.len() as usize]);
|
put_tx_data(mailbox, buffer);
|
||||||
|
|
||||||
// Set <idx as Mailbox> as ready to transmit
|
// Set <idx as Mailbox> as ready to transmit
|
||||||
self.regs.txbar().modify(|w| w.set_ar(bufidx, true));
|
self.regs.txbar().modify(|w| w.set_ar(bufidx, true));
|
||||||
@ -190,7 +190,7 @@ impl Registers {
|
|||||||
DataLength::Fdcan(len) => len,
|
DataLength::Fdcan(len) => len,
|
||||||
DataLength::Classic(len) => len,
|
DataLength::Classic(len) => len,
|
||||||
};
|
};
|
||||||
if len as usize > ClassicData::MAX_DATA_LEN {
|
if len as usize > 8 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -104,15 +104,13 @@ pub trait CanHeader: Sized {
|
|||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct ClassicData {
|
pub struct ClassicData {
|
||||||
pub(crate) bytes: [u8; Self::MAX_DATA_LEN],
|
pub(crate) bytes: [u8; 8],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClassicData {
|
impl ClassicData {
|
||||||
pub(crate) const MAX_DATA_LEN: usize = 8;
|
|
||||||
/// Creates a data payload from a raw byte slice.
|
/// Creates a data payload from a raw byte slice.
|
||||||
///
|
///
|
||||||
/// Returns `None` if `data` is more than 64 bytes (which is the maximum) or
|
/// Returns `FrameCreateError` if `data` is more than 8 bytes (which is the maximum).
|
||||||
/// cannot be represented with an FDCAN DLC.
|
|
||||||
pub fn new(data: &[u8]) -> Result<Self, FrameCreateError> {
|
pub fn new(data: &[u8]) -> Result<Self, FrameCreateError> {
|
||||||
if data.len() > 8 {
|
if data.len() > 8 {
|
||||||
return Err(FrameCreateError::InvalidDataLength);
|
return Err(FrameCreateError::InvalidDataLength);
|
||||||
@ -211,12 +209,17 @@ impl Frame {
|
|||||||
|
|
||||||
/// Get reference to data
|
/// Get reference to data
|
||||||
pub fn data(&self) -> &[u8] {
|
pub fn data(&self) -> &[u8] {
|
||||||
&self.data.raw()
|
&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()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get mutable reference to data
|
/// Get mutable reference to data
|
||||||
pub fn data_mut(&mut self) -> &mut [u8] {
|
pub fn data_mut(&mut self) -> &mut [u8] {
|
||||||
self.data.raw_mut()
|
&mut self.data.raw_mut()[..self.can_header.len as usize]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get priority of frame
|
/// Get priority of frame
|
||||||
@ -260,7 +263,7 @@ impl embedded_can::Frame for Frame {
|
|||||||
self.can_header.len as usize
|
self.can_header.len as usize
|
||||||
}
|
}
|
||||||
fn data(&self) -> &[u8] {
|
fn data(&self) -> &[u8] {
|
||||||
&self.data.raw()
|
&self.data()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,12 +408,12 @@ impl FdFrame {
|
|||||||
|
|
||||||
/// Get reference to data
|
/// Get reference to data
|
||||||
pub fn data(&self) -> &[u8] {
|
pub fn data(&self) -> &[u8] {
|
||||||
&self.data.raw()
|
&self.data.raw()[..self.can_header.len as usize]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get mutable reference to data
|
/// Get mutable reference to data
|
||||||
pub fn data_mut(&mut self) -> &mut [u8] {
|
pub fn data_mut(&mut self) -> &mut [u8] {
|
||||||
self.data.raw_mut()
|
&mut self.data.raw_mut()[..self.can_header.len as usize]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,7 +451,7 @@ impl embedded_can::Frame for FdFrame {
|
|||||||
self.can_header.len as usize
|
self.can_header.len as usize
|
||||||
}
|
}
|
||||||
fn data(&self) -> &[u8] {
|
fn data(&self) -> &[u8] {
|
||||||
&self.data.raw()
|
&self.data()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -422,11 +422,13 @@ impl<'d, T: Instance> OpAmp<'d, T> {
|
|||||||
|
|
||||||
T::regs().csr().modify(|w| match pair {
|
T::regs().csr().modify(|w| match pair {
|
||||||
OpAmpDifferentialPair::P => {
|
OpAmpDifferentialPair::P => {
|
||||||
defmt::info!("p calibration. offset: {}", mid);
|
#[cfg(feature = "defmt")]
|
||||||
|
defmt::debug!("opamp p calibration. offset: {}", mid);
|
||||||
w.set_trimoffsetp(mid);
|
w.set_trimoffsetp(mid);
|
||||||
}
|
}
|
||||||
OpAmpDifferentialPair::N => {
|
OpAmpDifferentialPair::N => {
|
||||||
defmt::info!("n calibration. offset: {}", mid);
|
#[cfg(feature = "defmt")]
|
||||||
|
defmt::debug!("opamp n calibration. offset: {}", mid);
|
||||||
w.set_trimoffsetn(mid);
|
w.set_trimoffsetn(mid);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user