From 24dc7b91126e908e9e7b3f88d40e3cccce4875e5 Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Fri, 9 Oct 2026 05:12:53 -0500 Subject: [PATCH] Safety checks --- opendbc_repo/opendbc/safety/modes/hyundai_canfd.h | 6 ++++-- panda/board/drivers/gpio.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/opendbc_repo/opendbc/safety/modes/hyundai_canfd.h b/opendbc_repo/opendbc/safety/modes/hyundai_canfd.h index 0fd21ebf18..c89f73ac6e 100644 --- a/opendbc_repo/opendbc/safety/modes/hyundai_canfd.h +++ b/opendbc_repo/opendbc/safety/modes/hyundai_canfd.h @@ -185,8 +185,6 @@ static bool aol_optional_release_pending = false; static bool aol_optional_release_latch = false; static uint32_t aol_optional_release_ts = 0U; static bool aol_optional_release_counter_seen = false; -static uint8_t aol_optional_release_counter = 0U; -static uint32_t aol_optional_release_sample_ts = 0U; static bool hyundai_torque_long_aol_cancel_preserves_lateral = false; static bool hyundai_canfd_torque_ev_long = false; static bool aol_ioniq6_lateral_latch = false; @@ -523,6 +521,8 @@ static void hyundai_canfd_rx_hook(const CANPacket_t *msg) { } if (aol_ioniq6_long && (msg_matches(msg, hyundai_canfd_alt_buttons ? 0x1aaU : 0x1cfU, pt_bus))) { if (aol_optional_release_capable && aol_optional_release_policy) { + static uint8_t aol_optional_release_counter = 0U; + static uint32_t aol_optional_release_sample_ts = 0U; const uint8_t counter = hyundai_canfd_get_counter(msg); const uint8_t maximum = hyundai_canfd_alt_buttons ? 0xffU : 0xfU; const uint32_t sample_ts = microsecond_timer_get(); @@ -547,6 +547,8 @@ static void hyundai_canfd_rx_hook(const CANPacket_t *msg) { (aol_optional_release_previous == HYUNDAI_BTN_RESUME)) && (cruise_button == HYUNDAI_BTN_NONE)) { aol_optional_release_pending = true; aol_optional_release_ts = microsecond_timer_get(); + } else { + // No release edge; retain the current neutral/release state. } aol_optional_release_previous = (uint8_t)cruise_button; } diff --git a/panda/board/drivers/gpio.h b/panda/board/drivers/gpio.h index 395fe0a3ce..bbbcdbb928 100644 --- a/panda/board/drivers/gpio.h +++ b/panda/board/drivers/gpio.h @@ -49,7 +49,7 @@ void set_gpio_output_type(GPIO_TypeDef *GPIO, unsigned int pin, unsigned int out void set_gpio_alternate(GPIO_TypeDef *GPIO, unsigned int pin, unsigned int mode) { ENTER_CRITICAL(); uint32_t tmp = GPIO->AFR[pin >> 3U]; - tmp &= ~(0xFU << ((pin & 7U) * 4U)); + tmp &= ~((uint32_t)0xFU << ((pin & 7U) * 4U)); tmp |= mode << ((pin & 7U) * 4U); register_set(&(GPIO->AFR[pin >> 3]), tmp, 0xFFFFFFFFU); set_gpio_mode(GPIO, pin, MODE_ALTERNATE);