Skip to content

Commit

Permalink
ensure auto mode is off
Browse files Browse the repository at this point in the history
  • Loading branch information
pd0wm committed Nov 26, 2024
1 parent 25120ee commit 0a8a18d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/panda/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub enum Endpoint {
CanRead = 0x81,
PacketsVersions = 0xdd,
PowerSave = 0xe7,
CanFDAuto = 0xe8,
HeartbeatDisabled = 0xf8,
}

Expand Down
12 changes: 12 additions & 0 deletions src/panda/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const VENDOR_ID: u16 = 0xbbaa;
const PRODUCT_ID: u16 = 0xddcc;
const EXPECTED_CAN_PACKET_VERSION: u8 = 4;
const MAX_BULK_SIZE: usize = 16384;
const PANDA_BUS_CNT: usize = 3;

/// Blocking implementation of the panda CAN adapter
pub struct Panda {
Expand Down Expand Up @@ -73,6 +74,10 @@ impl Panda {
panda.set_heartbeat_disabled()?;
panda.can_reset_communications()?;

for i in 0..PANDA_BUS_CNT {
panda.set_canfd_auto(i, false)?;
}

// can_reset_communications() doesn't work properly, flush manually
panda.flush_rx()?;

Expand Down Expand Up @@ -113,6 +118,13 @@ impl Panda {
self.usb_write_control(Endpoint::PowerSave, power_save_enabled as u16, 0)
}

fn set_canfd_auto(&self, bus: usize, auto: bool) -> Result<()> {
if bus >= PANDA_BUS_CNT {
return Err(crate::Error::NotSupported);
}
self.usb_write_control(Endpoint::CanFDAuto, bus as u16, auto as u16)
}

/// Get the hardware type of the panda. Usefull to detect if it supports CAN-FD.
pub fn get_hw_type(&self) -> Result<HwType> {
let hw_type = self.usb_read_control(Endpoint::HwType, 1)?;
Expand Down

0 comments on commit 0a8a18d

Please sign in to comment.