Skip to content

Commit

Permalink
global set_can_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
robbederks committed Dec 3, 2024
1 parent 574c3ee commit c3b0612
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 224 deletions.
44 changes: 9 additions & 35 deletions board/boards/black.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,39 +57,6 @@ static void black_set_usb_load_switch(bool enabled) {
set_gpio_output(GPIOB, 1, !enabled);
}

static void black_set_can_mode(uint8_t mode) {
black_enable_can_transceiver(2U, false);
black_enable_can_transceiver(4U, false);
switch (mode) {
case CAN_MODE_NORMAL:
case CAN_MODE_OBD_CAN2:
if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(harness.status == HARNESS_STATUS_FLIPPED)) {
// B12,B13: disable OBD mode
set_gpio_mode(GPIOB, 12, MODE_INPUT);
set_gpio_mode(GPIOB, 13, MODE_INPUT);

// B5,B6: normal CAN2 mode
set_gpio_alternate(GPIOB, 5, GPIO_AF9_CAN2);
set_gpio_alternate(GPIOB, 6, GPIO_AF9_CAN2);
black_enable_can_transceiver(2U, true);

} else {
// B5,B6: disable normal CAN2 mode
set_gpio_mode(GPIOB, 5, MODE_INPUT);
set_gpio_mode(GPIOB, 6, MODE_INPUT);

// B12,B13: OBD mode
set_gpio_alternate(GPIOB, 12, GPIO_AF9_CAN2);
set_gpio_alternate(GPIOB, 13, GPIO_AF9_CAN2);
black_enable_can_transceiver(4U, true);
}
break;
default:
print("Tried to set unsupported CAN mode: "); puth(mode); print("\n");
break;
}
}

static bool black_check_ignition(void){
// ignition is checked through harness
return harness_check_ignition();
Expand Down Expand Up @@ -127,7 +94,15 @@ static harness_configuration black_harness_config = {
.pin_relay_SBU1 = 10,
.pin_relay_SBU2 = 11,
.adc_channel_SBU1 = 10,
.adc_channel_SBU2 = 13
.adc_channel_SBU2 = 13,
.GPIO_CAN2_RX_NORMAL = GPIOB,
.GPIO_CAN2_TX_NORMAL = GPIOB,
.GPIO_CAN2_RX_FLIPPED = GPIOB,
.GPIO_CAN2_TX_FLIPPED = GPIOB,
.pin_CAN2_RX_NORMAL = 12,
.pin_CAN2_TX_NORMAL = 13,
.pin_CAN2_RX_FLIPPED = 5,
.pin_CAN2_TX_FLIPPED = 6
};

board board_black = {
Expand All @@ -146,7 +121,6 @@ board board_black = {
.enable_can_transceiver = black_enable_can_transceiver,
.enable_can_transceivers = black_enable_can_transceivers,
.set_led = black_set_led,
.set_can_mode = black_set_can_mode,
.check_ignition = black_check_ignition,
.read_voltage_mV = white_read_voltage_mV,
.read_current_mA = unused_read_current,
Expand Down
2 changes: 0 additions & 2 deletions board/boards/board_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ typedef void (*board_init_bootloader)(void);
typedef void (*board_enable_can_transceiver)(uint8_t transceiver, bool enabled);
typedef void (*board_enable_can_transceivers)(bool enabled);
typedef void (*board_set_led)(uint8_t color, bool enabled);
typedef void (*board_set_can_mode)(uint8_t mode);
typedef bool (*board_check_ignition)(void);
typedef uint32_t (*board_read_voltage_mV)(void);
typedef uint32_t (*board_read_current_mA)(void);
Expand All @@ -41,7 +40,6 @@ struct board {
board_enable_can_transceiver enable_can_transceiver;
board_enable_can_transceivers enable_can_transceivers;
board_set_led set_led;
board_set_can_mode set_can_mode;
board_check_ignition check_ignition;
board_read_voltage_mV read_voltage_mV;
board_read_current_mA read_current_mA;
Expand Down
1 change: 0 additions & 1 deletion board/boards/cuatro.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ board board_cuatro = {
.enable_can_transceiver = cuatro_enable_can_transceiver,
.enable_can_transceivers = cuatro_enable_can_transceivers,
.set_led = cuatro_set_led,
.set_can_mode = tres_set_can_mode,
.check_ignition = red_check_ignition,
.read_voltage_mV = cuatro_read_voltage_mV,
.read_current_mA = cuatro_read_current_mA,
Expand Down
43 changes: 9 additions & 34 deletions board/boards/dos.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,38 +57,6 @@ static void dos_set_bootkick(BootState state) {
set_gpio_output(GPIOC, 4, state != BOOT_BOOTKICK);
}

static void dos_set_can_mode(uint8_t mode) {
dos_enable_can_transceiver(2U, false);
dos_enable_can_transceiver(4U, false);
switch (mode) {
case CAN_MODE_NORMAL:
case CAN_MODE_OBD_CAN2:
if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(harness.status == HARNESS_STATUS_FLIPPED)) {
// B12,B13: disable OBD mode
set_gpio_mode(GPIOB, 12, MODE_INPUT);
set_gpio_mode(GPIOB, 13, MODE_INPUT);

// B5,B6: normal CAN2 mode
set_gpio_alternate(GPIOB, 5, GPIO_AF9_CAN2);
set_gpio_alternate(GPIOB, 6, GPIO_AF9_CAN2);
dos_enable_can_transceiver(2U, true);
} else {
// B5,B6: disable normal CAN2 mode
set_gpio_mode(GPIOB, 5, MODE_INPUT);
set_gpio_mode(GPIOB, 6, MODE_INPUT);

// B12,B13: OBD mode
set_gpio_alternate(GPIOB, 12, GPIO_AF9_CAN2);
set_gpio_alternate(GPIOB, 13, GPIO_AF9_CAN2);
dos_enable_can_transceiver(4U, true);
}
break;
default:
print("Tried to set unsupported CAN mode: "); puth(mode); print("\n");
break;
}
}

static bool dos_check_ignition(void){
// ignition is checked through harness
return harness_check_ignition();
Expand Down Expand Up @@ -147,7 +115,15 @@ static harness_configuration dos_harness_config = {
.pin_relay_SBU1 = 10,
.pin_relay_SBU2 = 11,
.adc_channel_SBU1 = 10,
.adc_channel_SBU2 = 13
.adc_channel_SBU2 = 13,
.GPIO_CAN2_RX_NORMAL = GPIOB,
.GPIO_CAN2_TX_NORMAL = GPIOB,
.GPIO_CAN2_RX_FLIPPED = GPIOB,
.GPIO_CAN2_TX_FLIPPED = GPIOB,
.pin_CAN2_RX_NORMAL = 12,
.pin_CAN2_TX_NORMAL = 13,
.pin_CAN2_RX_FLIPPED = 5,
.pin_CAN2_TX_FLIPPED = 6
};

board board_dos = {
Expand All @@ -169,7 +145,6 @@ board board_dos = {
.enable_can_transceiver = dos_enable_can_transceiver,
.enable_can_transceivers = dos_enable_can_transceivers,
.set_led = dos_set_led,
.set_can_mode = dos_set_can_mode,
.check_ignition = dos_check_ignition,
.read_voltage_mV = white_read_voltage_mV,
.read_current_mA = unused_read_current,
Expand Down
1 change: 0 additions & 1 deletion board/boards/grey.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ board board_grey = {
.enable_can_transceiver = white_enable_can_transceiver,
.enable_can_transceivers = white_enable_can_transceivers,
.set_led = white_set_led,
.set_can_mode = white_set_can_mode,
.check_ignition = white_check_ignition,
.read_voltage_mV = white_read_voltage_mV,
.read_current_mA = white_read_current_mA,
Expand Down
53 changes: 9 additions & 44 deletions board/boards/red.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,48 +53,6 @@ static void red_set_led(uint8_t color, bool enabled) {
}
}

static void red_set_can_mode(uint8_t mode) {
red_enable_can_transceiver(2U, false);
red_enable_can_transceiver(4U, false);
switch (mode) {
case CAN_MODE_NORMAL:
case CAN_MODE_OBD_CAN2:
if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(harness.status == HARNESS_STATUS_FLIPPED)) {
// B12,B13: disable normal mode
set_gpio_pullup(GPIOB, 12, PULL_NONE);
set_gpio_mode(GPIOB, 12, MODE_ANALOG);

set_gpio_pullup(GPIOB, 13, PULL_NONE);
set_gpio_mode(GPIOB, 13, MODE_ANALOG);

// B5,B6: FDCAN2 mode
set_gpio_pullup(GPIOB, 5, PULL_NONE);
set_gpio_alternate(GPIOB, 5, GPIO_AF9_FDCAN2);

set_gpio_pullup(GPIOB, 6, PULL_NONE);
set_gpio_alternate(GPIOB, 6, GPIO_AF9_FDCAN2);
red_enable_can_transceiver(2U, true);
} else {
// B5,B6: disable normal mode
set_gpio_pullup(GPIOB, 5, PULL_NONE);
set_gpio_mode(GPIOB, 5, MODE_ANALOG);

set_gpio_pullup(GPIOB, 6, PULL_NONE);
set_gpio_mode(GPIOB, 6, MODE_ANALOG);
// B12,B13: FDCAN2 mode
set_gpio_pullup(GPIOB, 12, PULL_NONE);
set_gpio_alternate(GPIOB, 12, GPIO_AF9_FDCAN2);

set_gpio_pullup(GPIOB, 13, PULL_NONE);
set_gpio_alternate(GPIOB, 13, GPIO_AF9_FDCAN2);
red_enable_can_transceiver(4U, true);
}
break;
default:
break;
}
}

static bool red_check_ignition(void) {
// ignition is checked through harness
return harness_check_ignition();
Expand Down Expand Up @@ -142,7 +100,15 @@ static harness_configuration red_harness_config = {
.pin_relay_SBU1 = 10,
.pin_relay_SBU2 = 11,
.adc_channel_SBU1 = 4, //ADC12_INP4
.adc_channel_SBU2 = 17 //ADC1_INP17
.adc_channel_SBU2 = 17, //ADC1_INP17
.GPIO_CAN2_RX_NORMAL = GPIOB,
.GPIO_CAN2_TX_NORMAL = GPIOB,
.GPIO_CAN2_RX_FLIPPED = GPIOB,
.GPIO_CAN2_TX_FLIPPED = GPIOB,
.pin_CAN2_RX_NORMAL = 12,
.pin_CAN2_TX_NORMAL = 13,
.pin_CAN2_RX_FLIPPED = 5,
.pin_CAN2_TX_FLIPPED = 6
};

board board_red = {
Expand All @@ -161,7 +127,6 @@ board board_red = {
.enable_can_transceiver = red_enable_can_transceiver,
.enable_can_transceivers = red_enable_can_transceivers,
.set_led = red_set_led,
.set_can_mode = red_set_can_mode,
.check_ignition = red_check_ignition,
.read_voltage_mV = red_read_voltage_mV,
.read_current_mA = unused_read_current,
Expand Down
53 changes: 9 additions & 44 deletions board/boards/tres.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,48 +60,6 @@ static void tres_enable_can_transceivers(bool enabled) {
}
}

static void tres_set_can_mode(uint8_t mode) {
current_board->enable_can_transceiver(2U, false);
current_board->enable_can_transceiver(4U, false);
switch (mode) {
case CAN_MODE_NORMAL:
case CAN_MODE_OBD_CAN2:
if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(harness.status == HARNESS_STATUS_FLIPPED)) {
// B12,B13: disable normal mode
set_gpio_pullup(GPIOB, 12, PULL_NONE);
set_gpio_mode(GPIOB, 12, MODE_ANALOG);

set_gpio_pullup(GPIOB, 13, PULL_NONE);
set_gpio_mode(GPIOB, 13, MODE_ANALOG);

// B5,B6: FDCAN2 mode
set_gpio_pullup(GPIOB, 5, PULL_NONE);
set_gpio_alternate(GPIOB, 5, GPIO_AF9_FDCAN2);

set_gpio_pullup(GPIOB, 6, PULL_NONE);
set_gpio_alternate(GPIOB, 6, GPIO_AF9_FDCAN2);
current_board->enable_can_transceiver(2U, true);
} else {
// B5,B6: disable normal mode
set_gpio_pullup(GPIOB, 5, PULL_NONE);
set_gpio_mode(GPIOB, 5, MODE_ANALOG);

set_gpio_pullup(GPIOB, 6, PULL_NONE);
set_gpio_mode(GPIOB, 6, MODE_ANALOG);
// B12,B13: FDCAN2 mode
set_gpio_pullup(GPIOB, 12, PULL_NONE);
set_gpio_alternate(GPIOB, 12, GPIO_AF9_FDCAN2);

set_gpio_pullup(GPIOB, 13, PULL_NONE);
set_gpio_alternate(GPIOB, 13, GPIO_AF9_FDCAN2);
current_board->enable_can_transceiver(4U, true);
}
break;
default:
break;
}
}

static bool tres_read_som_gpio (void) {
return (get_gpio_input(GPIOC, 2) != 0);
}
Expand Down Expand Up @@ -155,7 +113,15 @@ static harness_configuration tres_harness_config = {
.pin_relay_SBU1 = 8,
.pin_relay_SBU2 = 3,
.adc_channel_SBU1 = 4, // ADC12_INP4
.adc_channel_SBU2 = 17 // ADC1_INP17
.adc_channel_SBU2 = 17, // ADC1_INP17
.GPIO_CAN2_RX_NORMAL = GPIOB,
.GPIO_CAN2_TX_NORMAL = GPIOB,
.GPIO_CAN2_RX_FLIPPED = GPIOB,
.GPIO_CAN2_TX_FLIPPED = GPIOB,
.pin_CAN2_RX_NORMAL = 12,
.pin_CAN2_TX_NORMAL = 13,
.pin_CAN2_RX_FLIPPED = 5,
.pin_CAN2_TX_FLIPPED = 6
};

board board_tres = {
Expand All @@ -173,7 +139,6 @@ board board_tres = {
.enable_can_transceiver = tres_enable_can_transceiver,
.enable_can_transceivers = tres_enable_can_transceivers,
.set_led = red_set_led,
.set_can_mode = tres_set_can_mode,
.check_ignition = red_check_ignition,
.read_voltage_mV = red_read_voltage_mV,
.read_current_mA = unused_read_current,
Expand Down
43 changes: 9 additions & 34 deletions board/boards/uno.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,38 +62,6 @@ static void uno_set_bootkick(BootState state) {
}
}

static void uno_set_can_mode(uint8_t mode) {
uno_enable_can_transceiver(2U, false);
uno_enable_can_transceiver(4U, false);
switch (mode) {
case CAN_MODE_NORMAL:
case CAN_MODE_OBD_CAN2:
if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(harness.status == HARNESS_STATUS_FLIPPED)) {
// B12,B13: disable OBD mode
set_gpio_mode(GPIOB, 12, MODE_INPUT);
set_gpio_mode(GPIOB, 13, MODE_INPUT);

// B5,B6: normal CAN2 mode
set_gpio_alternate(GPIOB, 5, GPIO_AF9_CAN2);
set_gpio_alternate(GPIOB, 6, GPIO_AF9_CAN2);
uno_enable_can_transceiver(2U, true);
} else {
// B5,B6: disable normal CAN2 mode
set_gpio_mode(GPIOB, 5, MODE_INPUT);
set_gpio_mode(GPIOB, 6, MODE_INPUT);

// B12,B13: OBD mode
set_gpio_alternate(GPIOB, 12, GPIO_AF9_CAN2);
set_gpio_alternate(GPIOB, 13, GPIO_AF9_CAN2);
uno_enable_can_transceiver(4U, true);
}
break;
default:
print("Tried to set unsupported CAN mode: "); puth(mode); print("\n");
break;
}
}

static bool uno_check_ignition(void){
// ignition is checked through harness
return harness_check_ignition();
Expand Down Expand Up @@ -163,7 +131,15 @@ static harness_configuration uno_harness_config = {
.pin_relay_SBU1 = 10,
.pin_relay_SBU2 = 11,
.adc_channel_SBU1 = 10,
.adc_channel_SBU2 = 13
.adc_channel_SBU2 = 13,
.GPIO_CAN2_RX_NORMAL = GPIOB,
.GPIO_CAN2_TX_NORMAL = GPIOB,
.GPIO_CAN2_RX_FLIPPED = GPIOB,
.GPIO_CAN2_TX_FLIPPED = GPIOB,
.pin_CAN2_RX_NORMAL = 12,
.pin_CAN2_TX_NORMAL = 13,
.pin_CAN2_RX_FLIPPED = 5,
.pin_CAN2_TX_FLIPPED = 6
};

board board_uno = {
Expand All @@ -181,7 +157,6 @@ board board_uno = {
.enable_can_transceiver = uno_enable_can_transceiver,
.enable_can_transceivers = uno_enable_can_transceivers,
.set_led = uno_set_led,
.set_can_mode = uno_set_can_mode,
.check_ignition = uno_check_ignition,
.read_voltage_mV = white_read_voltage_mV,
.read_current_mA = unused_read_current,
Expand Down
Loading

0 comments on commit c3b0612

Please sign in to comment.