Skip to content

Commit ad0f372

Browse files
adeebshihadehComma Device
and
Comma Device
authored
cuatro can fixes (commaai#1858)
* more can * other af * cleanup * misra fix --------- Co-authored-by: Comma Device <[email protected]>
1 parent 04c5a00 commit ad0f372

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

board/boards/cuatro.h

+32-11
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,50 @@ void cuatro_set_led(uint8_t color, bool enabled) {
1919
}
2020

2121
void cuatro_enable_can_transceiver(uint8_t transceiver, bool enabled) {
22-
if (transceiver == 1U) {
23-
set_gpio_output(GPIOB, 7, !enabled);
24-
} else if (transceiver == 3U) {
25-
set_gpio_output(GPIOD, 8, !enabled);
26-
} else {
27-
red_enable_can_transceiver(transceiver, enabled);
22+
switch (transceiver) {
23+
case 1U:
24+
set_gpio_output(GPIOB, 7, !enabled);
25+
break;
26+
case 2U:
27+
set_gpio_output(GPIOB, 10, !enabled);
28+
break;
29+
case 3U:
30+
set_gpio_output(GPIOD, 8, !enabled);
31+
break;
32+
case 4U:
33+
set_gpio_output(GPIOB, 11, !enabled);
34+
break;
35+
default:
36+
break;
37+
}
38+
}
39+
40+
void cuatro_enable_can_transceivers(bool enabled) {
41+
uint8_t main_bus = (harness.status == HARNESS_STATUS_FLIPPED) ? 3U : 1U;
42+
for (uint8_t i=1U; i<=4U; i++) {
43+
// Leave main CAN always on for CAN-based ignition detection
44+
if (i == main_bus) {
45+
cuatro_enable_can_transceiver(i, true);
46+
} else {
47+
cuatro_enable_can_transceiver(i, enabled);
48+
}
2849
}
2950
}
3051

3152
void cuatro_init(void) {
3253
red_chiplet_init();
3354

34-
// CAN FD 0 transceiver enable (rest are done in red init)
55+
// CAN transceiver enables
3556
set_gpio_pullup(GPIOB, 7, PULL_NONE);
3657
set_gpio_mode(GPIOB, 7, MODE_OUTPUT);
3758
set_gpio_pullup(GPIOD, 8, PULL_NONE);
3859
set_gpio_mode(GPIOD, 8, MODE_OUTPUT);
3960

40-
// FDCAN2
61+
// FDCAN3, different pins on this package than the rest of the reds
4162
set_gpio_pullup(GPIOD, 12, PULL_NONE);
42-
set_gpio_alternate(GPIOD, 12, GPIO_AF9_FDCAN2);
63+
set_gpio_alternate(GPIOD, 12, GPIO_AF5_FDCAN3);
4364
set_gpio_pullup(GPIOD, 13, PULL_NONE);
44-
set_gpio_alternate(GPIOD, 13, GPIO_AF9_FDCAN2);
65+
set_gpio_alternate(GPIOD, 13, GPIO_AF5_FDCAN3);
4566

4667
// C2: SOM GPIO used as input (fan control at boot)
4768
set_gpio_mode(GPIOC, 2, MODE_INPUT);
@@ -83,7 +104,7 @@ const board board_cuatro = {
83104
.init = cuatro_init,
84105
.init_bootloader = unused_init_bootloader,
85106
.enable_can_transceiver = cuatro_enable_can_transceiver,
86-
.enable_can_transceivers = red_chiplet_enable_can_transceivers,
107+
.enable_can_transceivers = cuatro_enable_can_transceivers,
87108
.set_led = cuatro_set_led,
88109
.set_can_mode = red_chiplet_set_can_mode,
89110
.check_ignition = red_check_ignition,

0 commit comments

Comments
 (0)