Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement transceiver delay compensation configuration #57

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Update MSRV to 1.60
* Allow timestamp to be accessed in all modes
* Implement transceiver delay compensation configuration

## [v0.2.1] 2024-09-04

Expand Down
10 changes: 4 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,10 @@ pub struct DataBitTiming {
pub sync_jump_width: NonZeroU8,
}
impl DataBitTiming {
// #[inline]
// fn tdc(&self) -> u8 {
// let tsd = self.transceiver_delay_compensation as u8;
// //TODO: stm32g4 does not export the TDC field
// todo!()
// }
#[inline]
pub(crate) fn tdc(&self) -> bool {
self.transceiver_delay_compensation
}
#[inline]
pub(crate) fn dbrp(&self) -> u8 {
u8::from(self.prescaler) & 0x1F
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,11 @@ where
self.control.config.dbtr = btr;

let can = self.registers();
if btr.tdc() {
let tcdo = btr.dtseg1().saturating_mul(btr.dbrp());
let tcdo = core::cmp::min(tcdo, 127);
can.tdcr.write(|w| unsafe { w.tdco().bits(tcdo) });
liamkinne marked this conversation as resolved.
Show resolved Hide resolved
}
can.dbtp.write(|w| unsafe {
w.dbrp()
.bits(btr.dbrp() - 1)
Expand All @@ -764,6 +769,8 @@ where
.bits(btr.dtseg2() - 1)
.dsjw()
.bits(btr.dsjw() - 1)
.tdc()
.bit(btr.tdc())
});
}

Expand Down
Loading