From ad0f372adabef438d67340c6b9c76ba7146d0671 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 6 Feb 2024 22:29:42 -0800 Subject: [PATCH] cuatro can fixes (#1858) * more can * other af * cleanup * misra fix --------- Co-authored-by: Comma Device --- board/boards/cuatro.h | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/board/boards/cuatro.h b/board/boards/cuatro.h index 049e6e20a6..ed120bb052 100644 --- a/board/boards/cuatro.h +++ b/board/boards/cuatro.h @@ -19,29 +19,50 @@ void cuatro_set_led(uint8_t color, bool enabled) { } void cuatro_enable_can_transceiver(uint8_t transceiver, bool enabled) { - if (transceiver == 1U) { - set_gpio_output(GPIOB, 7, !enabled); - } else if (transceiver == 3U) { - set_gpio_output(GPIOD, 8, !enabled); - } else { - red_enable_can_transceiver(transceiver, enabled); + switch (transceiver) { + case 1U: + set_gpio_output(GPIOB, 7, !enabled); + break; + case 2U: + set_gpio_output(GPIOB, 10, !enabled); + break; + case 3U: + set_gpio_output(GPIOD, 8, !enabled); + break; + case 4U: + set_gpio_output(GPIOB, 11, !enabled); + break; + default: + break; + } +} + +void cuatro_enable_can_transceivers(bool enabled) { + uint8_t main_bus = (harness.status == HARNESS_STATUS_FLIPPED) ? 3U : 1U; + for (uint8_t i=1U; i<=4U; i++) { + // Leave main CAN always on for CAN-based ignition detection + if (i == main_bus) { + cuatro_enable_can_transceiver(i, true); + } else { + cuatro_enable_can_transceiver(i, enabled); + } } } void cuatro_init(void) { red_chiplet_init(); - // CAN FD 0 transceiver enable (rest are done in red init) + // CAN transceiver enables set_gpio_pullup(GPIOB, 7, PULL_NONE); set_gpio_mode(GPIOB, 7, MODE_OUTPUT); set_gpio_pullup(GPIOD, 8, PULL_NONE); set_gpio_mode(GPIOD, 8, MODE_OUTPUT); - // FDCAN2 + // FDCAN3, different pins on this package than the rest of the reds set_gpio_pullup(GPIOD, 12, PULL_NONE); - set_gpio_alternate(GPIOD, 12, GPIO_AF9_FDCAN2); + set_gpio_alternate(GPIOD, 12, GPIO_AF5_FDCAN3); set_gpio_pullup(GPIOD, 13, PULL_NONE); - set_gpio_alternate(GPIOD, 13, GPIO_AF9_FDCAN2); + set_gpio_alternate(GPIOD, 13, GPIO_AF5_FDCAN3); // C2: SOM GPIO used as input (fan control at boot) set_gpio_mode(GPIOC, 2, MODE_INPUT); @@ -83,7 +104,7 @@ const board board_cuatro = { .init = cuatro_init, .init_bootloader = unused_init_bootloader, .enable_can_transceiver = cuatro_enable_can_transceiver, - .enable_can_transceivers = red_chiplet_enable_can_transceivers, + .enable_can_transceivers = cuatro_enable_can_transceivers, .set_led = cuatro_set_led, .set_can_mode = red_chiplet_set_can_mode, .check_ignition = red_check_ignition,