Skip to content

Commit

Permalink
cuatro can fixes (commaai#1858)
Browse files Browse the repository at this point in the history
* more can

* other af

* cleanup

* misra fix

---------

Co-authored-by: Comma Device <[email protected]>
  • Loading branch information
adeebshihadeh and Comma Device authored Feb 7, 2024
1 parent 04c5a00 commit ad0f372
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions board/boards/cuatro.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ad0f372

Please sign in to comment.