Skip to content

Commit

Permalink
add tripple sampling feature using edge filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
liamkinne committed Jan 27, 2025
1 parent 01a6ead commit 8516601
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased]

- Implement triple sampling using edge filtering

## v0.1.3

- Add more test scripts
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Based on the gs_usb protocol, this firmware is plug and play on most recent linu
| -------------------------------------------- | -------------- |
| Loopback | No |
| Listen-only | No |
| Tripple-sampling | No<sup>1</sup> |
| Tripple-sampling | Yes |
| One-shot | Yes |
| Hardware timestamp | No |
| Bus error reporting | No |
Expand Down
13 changes: 11 additions & 2 deletions src/can.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,21 @@ impl Device for UsbCanDevice {

fn bit_timing(&self) -> DeviceBitTimingConst {
DeviceBitTimingConst {
features: Feature::FD | Feature::BT_CONST_EXT | Feature::ONE_SHOT,
features: Feature::FD
| Feature::BT_CONST_EXT
| Feature::ONE_SHOT
| Feature::TRIPLE_SAMPLE,
fclk_can: self.clock.to_Hz(),
timing: TIMING_NOMINAL,
}
}

fn bit_timing_ext(&self) -> DeviceBitTimingConstExtended {
DeviceBitTimingConstExtended {
features: Feature::FD | Feature::BT_CONST_EXT | Feature::ONE_SHOT,
features: Feature::FD
| Feature::BT_CONST_EXT
| Feature::ONE_SHOT
| Feature::TRIPLE_SAMPLE,
fclk_can: self.clock.to_Hz(),
timing_nominal: TIMING_NOMINAL,
timing_data: CanBitTimingConst {
Expand Down Expand Up @@ -174,12 +180,14 @@ impl Device for UsbCanDevice {

fn start(&mut self, interface: u8, features: Feature) {
let retransmit = !features.intersects(Feature::ONE_SHOT);
let triple_sampling = features.intersects(Feature::TRIPLE_SAMPLE);

match interface {
0 => {
if let Some(can) = self.can1.take() {
let mut can = can.into_config_mode();
can.set_automatic_retransmit(retransmit);
can.set_edge_filtering(triple_sampling);
can.enable_interrupt_line(InterruptLine::_0, true);
can.enable_interrupt_line(InterruptLine::_1, true);
self.can1.replace(can.into_normal());
Expand All @@ -189,6 +197,7 @@ impl Device for UsbCanDevice {
if let Some(can) = self.can2.take() {
let mut can = can.into_config_mode();
can.set_automatic_retransmit(retransmit);
can.set_edge_filtering(triple_sampling);
can.enable_interrupt_line(InterruptLine::_0, true);
can.enable_interrupt_line(InterruptLine::_1, true);
self.can2.replace(can.into_normal());
Expand Down

0 comments on commit 8516601

Please sign in to comment.