Skip to content

Commit

Permalink
Merge commit 'ad0f372ad' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
csouers committed Feb 12, 2024
2 parents b574b60 + ad0f372 commit b7dead7
Show file tree
Hide file tree
Showing 29 changed files with 126 additions and 133 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ repos:
additional_dependencies: ['git+https://github.com/numpy/numpy-stubs', 'types-requests', 'types-atomicwrites',
'types-pycurl']
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.14
rev: v0.2.1
hooks:
- id: ruff
9 changes: 4 additions & 5 deletions board/boards/black.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ///////////////////// //
// Black Panda + Harness //
// ///////////////////// //
// /////////////////////////////// //
// Black Panda (STM32F4) + Harness //
// /////////////////////////////// //

void black_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver){
Expand Down Expand Up @@ -136,7 +136,7 @@ void black_init(void) {
// Set normal CAN mode
black_set_can_mode(CAN_MODE_NORMAL);

// flip CAN0 and CAN2 if we are flipped
// change CAN mapping when flipped
if (harness.status == HARNESS_STATUS_FLIPPED) {
can_flip_buses(0, 2);
}
Expand Down Expand Up @@ -165,7 +165,6 @@ const harness_configuration black_harness_config = {
const board board_black = {
.set_bootkick = unused_set_bootkick,
.harness_config = &black_harness_config,
.has_hw_gmlan = false,
.has_obd = true,
.has_spi = false,
.has_canfd = false,
Expand Down
1 change: 0 additions & 1 deletion board/boards/board_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ typedef bool (*board_read_som_gpio)(void);

struct board {
const harness_configuration *harness_config;
const bool has_hw_gmlan;
const bool has_obd;
const bool has_spi;
const bool has_canfd;
Expand Down
52 changes: 49 additions & 3 deletions board/boards/cuatro.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// ////////////////////////// //
// Cuatro (STM32H7) + Harness //
// ////////////////////////// //

void cuatro_set_led(uint8_t color, bool enabled) {
switch (color) {
case LED_RED:
Expand All @@ -14,9 +18,52 @@ void cuatro_set_led(uint8_t color, bool enabled) {
}
}

void cuatro_enable_can_transceiver(uint8_t transceiver, bool 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 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);

// 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_AF5_FDCAN3);
set_gpio_pullup(GPIOD, 13, PULL_NONE);
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);
set_gpio_pullup(GPIOC, 2, PULL_DOWN);
Expand Down Expand Up @@ -46,7 +93,6 @@ void cuatro_init(void) {

const board board_cuatro = {
.harness_config = &red_chiplet_harness_config,
.has_hw_gmlan = false,
.has_obd = true,
.has_spi = true,
.has_canfd = true,
Expand All @@ -57,8 +103,8 @@ const board board_cuatro = {
.fan_enable_cooldown_time = 3U,
.init = cuatro_init,
.init_bootloader = unused_init_bootloader,
.enable_can_transceiver = red_chiplet_enable_can_transceiver,
.enable_can_transceivers = red_chiplet_enable_can_transceivers,
.enable_can_transceiver = cuatro_enable_can_transceiver,
.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
9 changes: 4 additions & 5 deletions board/boards/dos.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ///////////// //
// Dos + Harness //
// ///////////// //
// /////////////////////// //
// Dos (STM32F4) + Harness //
// /////////////////////// //

void dos_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver){
Expand Down Expand Up @@ -168,7 +168,7 @@ void dos_init(void) {
// Set normal CAN mode
dos_set_can_mode(CAN_MODE_NORMAL);

// flip CAN0 and CAN2 if we are flipped
// change CAN mapping when flipped
if (harness.status == HARNESS_STATUS_FLIPPED) {
can_flip_buses(0, 2);
}
Expand All @@ -193,7 +193,6 @@ const harness_configuration dos_harness_config = {

const board board_dos = {
.harness_config = &dos_harness_config,
.has_hw_gmlan = false,
.has_obd = true,
#ifdef ENABLE_SPI
.has_spi = true,
Expand Down
7 changes: 3 additions & 4 deletions board/boards/grey.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// ////////// //
// Grey Panda //
// ////////// //
// //////////////////// //
// Grey Panda (STM32F4) //
// //////////////////// //

// Most hardware functionality is similar to white panda

const board board_grey = {
.set_bootkick = unused_set_bootkick,
.harness_config = &white_harness_config,
.has_hw_gmlan = true,
.has_obd = false,
.has_spi = false,
.has_canfd = false,
Expand Down
7 changes: 3 additions & 4 deletions board/boards/pedal.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ///// //
// Pedal //
// ///// //
// ///////////// //
// Pedal STM32F2 //
// ///////////// //

void pedal_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver){
Expand Down Expand Up @@ -69,7 +69,6 @@ const harness_configuration pedal_harness_config = {
const board board_pedal = {
.set_bootkick = unused_set_bootkick,
.harness_config = &pedal_harness_config,
.has_hw_gmlan = false,
.has_obd = false,
.has_spi = false,
.has_canfd = false,
Expand Down
9 changes: 4 additions & 5 deletions board/boards/red.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ///////////////////// //
// Red Panda + Harness //
// ///////////////////// //
// ///////////////////////////// //
// Red Panda (STM32H7) + Harness //
// ///////////////////////////// //

void red_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver) {
Expand Down Expand Up @@ -150,7 +150,7 @@ void red_init(void) {
// Set normal CAN mode
red_set_can_mode(CAN_MODE_NORMAL);

// flip CAN0 and CAN2 if we are flipped
// change CAN mapping when flipped
if (harness.status == HARNESS_STATUS_FLIPPED) {
can_flip_buses(0, 2);
}
Expand All @@ -173,7 +173,6 @@ const harness_configuration red_harness_config = {
const board board_red = {
.set_bootkick = unused_set_bootkick,
.harness_config = &red_harness_config,
.has_hw_gmlan = false,
.has_obd = true,
.has_spi = false,
.has_canfd = true,
Expand Down
8 changes: 4 additions & 4 deletions board/boards/red_chiplet.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ///////////////////// //
// Red Panda chiplet + Harness //
// ///////////////////// //
// ///////////////////////////////////// //
// Red Panda chiplet (STM32H7) + Harness //
// ///////////////////////////////////// //

// Most hardware functionality is similar to red panda

Expand Down Expand Up @@ -133,7 +133,7 @@ void red_chiplet_init(void) {
// Set normal CAN mode
red_chiplet_set_can_mode(CAN_MODE_NORMAL);

// flip CAN0 and CAN2 if we are flipped
// change CAN mapping when flipped
if (harness.status == HARNESS_STATUS_FLIPPED) {
can_flip_buses(0, 2);
}
Expand Down
7 changes: 3 additions & 4 deletions board/boards/tres.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// /////////////////
// Tres + Harness //
// /////////////////
// ///////////////////////////
// Tres (STM32H7) + Harness //
// ///////////////////////////

bool tres_ir_enabled;
bool tres_fan_enabled;
Expand Down Expand Up @@ -72,7 +72,6 @@ void tres_init(void) {

const board board_tres = {
.harness_config = &red_chiplet_harness_config,
.has_hw_gmlan = false,
.has_obd = true,
.has_spi = true,
.has_canfd = true,
Expand Down
9 changes: 4 additions & 5 deletions board/boards/uno.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ///////////// //
// Uno + Harness //
// ///////////// //
// /////////////////////// //
// Uno (STM32F4) + Harness //
// /////////////////////// //

void uno_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver){
Expand Down Expand Up @@ -161,7 +161,7 @@ void uno_init(void) {
// Set normal CAN mode
uno_set_can_mode(CAN_MODE_NORMAL);

// flip CAN0 and CAN2 if we are flipped
// change CAN mapping when flipped
if (harness.status == HARNESS_STATUS_FLIPPED) {
can_flip_buses(0, 2);
}
Expand Down Expand Up @@ -200,7 +200,6 @@ const harness_configuration uno_harness_config = {

const board board_uno = {
.harness_config = &uno_harness_config,
.has_hw_gmlan = false,
.has_obd = true,
.has_spi = false,
.has_canfd = false,
Expand Down
7 changes: 3 additions & 4 deletions board/boards/white.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// /////////// //
// White Panda //
// /////////// //
// ///////////////////// //
// White Panda (STM32F4) //
// ///////////////////// //

void white_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver){
Expand Down Expand Up @@ -224,7 +224,6 @@ const harness_configuration white_harness_config = {
const board board_white = {
.set_bootkick = unused_set_bootkick,
.harness_config = &white_harness_config,
.has_hw_gmlan = true,
.has_obd = false,
.has_spi = false,
.has_canfd = false,
Expand Down
50 changes: 0 additions & 50 deletions board/drivers/bxcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,56 +23,6 @@ bool can_set_speed(uint8_t can_number) {
return ret;
}

// TODO: Cleanup with new abstraction
void can_set_gmlan(uint8_t bus) {
if(current_board->has_hw_gmlan){
// first, disable GMLAN on prev bus
uint8_t prev_bus = bus_config[3].can_num_lookup;
if (bus != prev_bus) {
switch (prev_bus) {
case 1:
case 2:
print("Disable GMLAN on CAN");
puth(prev_bus + 1U);
print("\n");
current_board->set_can_mode(CAN_MODE_NORMAL);
bus_config[prev_bus].bus_lookup = prev_bus;
bus_config[prev_bus].can_num_lookup = prev_bus;
bus_config[3].can_num_lookup = -1;
bool ret = can_init(prev_bus);
UNUSED(ret);
break;
default:
// GMLAN was not set on either BUS 1 or 2
break;
}
}

// now enable GMLAN on the new bus
switch (bus) {
case 1:
case 2:
print("Enable GMLAN on CAN");
puth(bus + 1U);
print("\n");
current_board->set_can_mode((bus == 1U) ? CAN_MODE_GMLAN_CAN2 : CAN_MODE_GMLAN_CAN3);
bus_config[bus].bus_lookup = 3;
bus_config[bus].can_num_lookup = -1;
bus_config[3].can_num_lookup = bus;
bool ret = can_init(bus);
UNUSED(ret);
break;
case 0xFF: //-1 unsigned
break;
default:
print("GMLAN can only be set on CAN2 or CAN3\n");
break;
}
} else {
print("GMLAN not available on black panda\n");
}
}

void update_can_health_pkt(uint8_t can_number, uint32_t ir_reg) {
CAN_TypeDef *CANx = CANIF_FROM_CAN_NUM(can_number);
uint32_t esr_reg = CANx->ESR;
Expand Down
5 changes: 0 additions & 5 deletions board/drivers/fdcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ bool can_set_speed(uint8_t can_number) {
return ret;
}

void can_set_gmlan(uint8_t bus) {
UNUSED(bus);
print("GMLAN not available on red panda\n");
}

void update_can_health_pkt(uint8_t can_number, uint32_t ir_reg) {
FDCAN_GlobalTypeDef *FDCANx = CANIF_FROM_CAN_NUM(can_number);
uint32_t psr_reg = FDCANx->PSR;
Expand Down
1 change: 0 additions & 1 deletion board/jungle/boards/board_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ struct board {

// TODO: shouldn't need these
bool has_spi;
bool has_hw_gmlan;
};

// ******************* Definitions ********************
Expand Down
3 changes: 3 additions & 0 deletions board/jungle/boards/board_v1.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// ///////////////////////// //
// Jungle board v1 (STM32F4) //
// ///////////////////////// //

void board_v1_set_led(uint8_t color, bool enabled) {
switch (color) {
Expand Down
3 changes: 3 additions & 0 deletions board/jungle/boards/board_v2.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// ///////////////////////// //
// Jungle board v2 (STM32H7) //
// ///////////////////////// //

const gpio_t power_pins[] = {
{.bank = GPIOA, .pin = 0},
Expand Down
Loading

0 comments on commit b7dead7

Please sign in to comment.