From 0a8a18dfe59deb1eb4ffb77505274702abe3dbab Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Tue, 26 Nov 2024 09:56:44 +0100 Subject: [PATCH] ensure auto mode is off --- src/panda/constants.rs | 1 + src/panda/mod.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/panda/constants.rs b/src/panda/constants.rs index 9f722b3..6cb56e7 100644 --- a/src/panda/constants.rs +++ b/src/panda/constants.rs @@ -25,6 +25,7 @@ pub enum Endpoint { CanRead = 0x81, PacketsVersions = 0xdd, PowerSave = 0xe7, + CanFDAuto = 0xe8, HeartbeatDisabled = 0xf8, } diff --git a/src/panda/mod.rs b/src/panda/mod.rs index cf06ae2..c5e5ce5 100644 --- a/src/panda/mod.rs +++ b/src/panda/mod.rs @@ -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 { @@ -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()?; @@ -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 { let hw_type = self.usb_read_control(Endpoint::HwType, 1)?;