Skip to content

Commit

Permalink
Merge commit '93aedd987bda7e267210689b877eb87f288fc6ab' into unusedFu…
Browse files Browse the repository at this point in the history
…nction
  • Loading branch information
dzid26 committed Sep 17, 2024
2 parents 624e2b1 + 93aedd9 commit fd6fe90
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 76 deletions.
22 changes: 13 additions & 9 deletions board/boards/black.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#pragma once

#include "board_declarations.h"

// /////////////////////////////// //
// Black Panda (STM32F4) + Harness //
// /////////////////////////////// //

void black_enable_can_transceiver(uint8_t transceiver, bool enabled) {
static void black_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver){
case 1U:
set_gpio_output(GPIOC, 1, !enabled);
Expand All @@ -22,7 +26,7 @@ void black_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}

void black_enable_can_transceivers(bool enabled) {
static void black_enable_can_transceivers(bool enabled) {
for(uint8_t i=1U; i<=4U; i++){
// Leave main CAN always on for CAN-based ignition detection
if((harness.status == HARNESS_STATUS_FLIPPED) ? (i == 3U) : (i == 1U)){
Expand All @@ -33,7 +37,7 @@ void black_enable_can_transceivers(bool enabled) {
}
}

void black_set_led(uint8_t color, bool enabled) {
static void black_set_led(uint8_t color, bool enabled) {
switch (color){
case LED_RED:
set_gpio_output(GPIOC, 9, !enabled);
Expand All @@ -49,11 +53,11 @@ void black_set_led(uint8_t color, bool enabled) {
}
}

void black_set_usb_load_switch(bool enabled) {
static void black_set_usb_load_switch(bool enabled) {
set_gpio_output(GPIOB, 1, !enabled);
}

void black_set_can_mode(uint8_t mode) {
static void black_set_can_mode(uint8_t mode) {
black_enable_can_transceiver(2U, false);
black_enable_can_transceiver(4U, false);
switch (mode) {
Expand Down Expand Up @@ -86,12 +90,12 @@ void black_set_can_mode(uint8_t mode) {
}
}

bool black_check_ignition(void){
static bool black_check_ignition(void){
// ignition is checked through harness
return harness_check_ignition();
}

void black_init(void) {
static void black_init(void) {
common_init_gpio();

// A8,A15: normal CAN3 mode
Expand Down Expand Up @@ -135,13 +139,13 @@ void black_init(void) {
black_set_can_mode(CAN_MODE_NORMAL);
}

void black_init_bootloader(void) {
static void black_init_bootloader(void) {
// GPS OFF
set_gpio_output(GPIOC, 5, 0);
set_gpio_output(GPIOC, 12, 0);
}

harness_configuration black_harness_config = {
static harness_configuration black_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOC,
Expand Down
14 changes: 14 additions & 0 deletions board/boards/board_declarations.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#pragma once

#include <stdint.h>
#include <stdbool.h>

// ******************** Prototypes ********************
typedef enum {
BOOT_STANDBY,
Expand Down Expand Up @@ -74,3 +79,12 @@ struct board {
// CAN modes
#define CAN_MODE_NORMAL 0U
#define CAN_MODE_OBD_CAN2 1U

extern struct board board_black;
extern struct board board_dos;
extern struct board board_uno;
extern struct board board_tres;
extern struct board board_grey;
extern struct board board_white;
extern struct board board_cuatro;
extern struct board board_red;
20 changes: 12 additions & 8 deletions board/boards/cuatro.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#pragma once

#include "board_declarations.h"

// ////////////////////////// //
// Cuatro (STM32H7) + Harness //
// ////////////////////////// //

void cuatro_set_led(uint8_t color, bool enabled) {
static void cuatro_set_led(uint8_t color, bool enabled) {
switch (color) {
case LED_RED:
set_gpio_output(GPIOD, 15, !enabled);
Expand All @@ -18,7 +22,7 @@ void cuatro_set_led(uint8_t color, bool enabled) {
}
}

void cuatro_enable_can_transceiver(uint8_t transceiver, bool enabled) {
static void cuatro_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver) {
case 1U:
set_gpio_output(GPIOB, 7, !enabled);
Expand All @@ -37,7 +41,7 @@ void cuatro_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}

void cuatro_enable_can_transceivers(bool enabled) {
static 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
Expand All @@ -49,25 +53,25 @@ void cuatro_enable_can_transceivers(bool enabled) {
}
}

uint32_t cuatro_read_voltage_mV(void) {
static uint32_t cuatro_read_voltage_mV(void) {
return adc_get_mV(8) * 11U;
}

uint32_t cuatro_read_current_mA(void) {
static uint32_t cuatro_read_current_mA(void) {
return adc_get_mV(3) * 2U;
}

void cuatro_set_fan_enabled(bool enabled) {
static void cuatro_set_fan_enabled(bool enabled) {
set_gpio_output(GPIOD, 3, !enabled);
}

void cuatro_set_bootkick(BootState state) {
static void cuatro_set_bootkick(BootState state) {
set_gpio_output(GPIOA, 0, state != BOOT_BOOTKICK);
// only use if we have to
//set_gpio_output(GPIOC, 12, state != BOOT_RESET);
}

void cuatro_init(void) {
static void cuatro_init(void) {
red_chiplet_init();

// init LEDs as open drain
Expand Down
28 changes: 16 additions & 12 deletions board/boards/dos.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#pragma once

#include "board_declarations.h"

// /////////////////////// //
// Dos (STM32F4) + Harness //
// /////////////////////// //

void dos_enable_can_transceiver(uint8_t transceiver, bool enabled) {
static void dos_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver){
case 1U:
set_gpio_output(GPIOC, 1, !enabled);
Expand All @@ -22,7 +26,7 @@ void dos_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}

void dos_enable_can_transceivers(bool enabled) {
static void dos_enable_can_transceivers(bool enabled) {
for(uint8_t i=1U; i<=4U; i++){
// Leave main CAN always on for CAN-based ignition detection
if((harness.status == HARNESS_STATUS_FLIPPED) ? (i == 3U) : (i == 1U)){
Expand All @@ -33,7 +37,7 @@ void dos_enable_can_transceivers(bool enabled) {
}
}

void dos_set_led(uint8_t color, bool enabled) {
static void dos_set_led(uint8_t color, bool enabled) {
switch (color){
case LED_RED:
set_gpio_output(GPIOC, 9, !enabled);
Expand All @@ -49,11 +53,11 @@ void dos_set_led(uint8_t color, bool enabled) {
}
}

void dos_set_bootkick(BootState state) {
static void dos_set_bootkick(BootState state) {
set_gpio_output(GPIOC, 4, state != BOOT_BOOTKICK);
}

void dos_set_can_mode(uint8_t mode) {
static void dos_set_can_mode(uint8_t mode) {
dos_enable_can_transceiver(2U, false);
dos_enable_can_transceiver(4U, false);
switch (mode) {
Expand Down Expand Up @@ -85,28 +89,28 @@ void dos_set_can_mode(uint8_t mode) {
}
}

bool dos_check_ignition(void){
static bool dos_check_ignition(void){
// ignition is checked through harness
return harness_check_ignition();
}

void dos_set_ir_power(uint8_t percentage){
static void dos_set_ir_power(uint8_t percentage){
pwm_set(TIM4, 2, percentage);
}

void dos_set_fan_enabled(bool enabled){
static void dos_set_fan_enabled(bool enabled){
set_gpio_output(GPIOA, 1, enabled);
}

void dos_set_siren(bool enabled){
static void dos_set_siren(bool enabled){
set_gpio_output(GPIOC, 12, enabled);
}

bool dos_read_som_gpio (void){
static bool dos_read_som_gpio (void){
return (get_gpio_input(GPIOC, 2) != 0);
}

void dos_init(void) {
static void dos_init(void) {
common_init_gpio();

// A8,A15: normal CAN3 mode
Expand Down Expand Up @@ -166,7 +170,7 @@ void dos_init(void) {
clock_source_init();
}

harness_configuration dos_harness_config = {
static harness_configuration dos_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOC,
Expand Down
4 changes: 4 additions & 0 deletions board/boards/grey.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#pragma once

#include "board_declarations.h"

// //////////////////// //
// Grey Panda (STM32F4) //
// //////////////////// //
Expand Down
20 changes: 12 additions & 8 deletions board/boards/red.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#pragma once

#include "board_declarations.h"

// ///////////////////////////// //
// Red Panda (STM32H7) + Harness //
// ///////////////////////////// //

void red_enable_can_transceiver(uint8_t transceiver, bool enabled) {
static void red_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver) {
case 1U:
set_gpio_output(GPIOG, 11, !enabled);
Expand All @@ -21,7 +25,7 @@ void red_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}

void red_enable_can_transceivers(bool enabled) {
static void red_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
Expand All @@ -33,7 +37,7 @@ void red_enable_can_transceivers(bool enabled) {
}
}

void red_set_led(uint8_t color, bool enabled) {
static void red_set_led(uint8_t color, bool enabled) {
switch (color) {
case LED_RED:
set_gpio_output(GPIOE, 4, !enabled);
Expand All @@ -49,7 +53,7 @@ void red_set_led(uint8_t color, bool enabled) {
}
}

void red_set_can_mode(uint8_t mode) {
static void red_set_can_mode(uint8_t mode) {
red_enable_can_transceiver(2U, false);
red_enable_can_transceiver(4U, false);
switch (mode) {
Expand Down Expand Up @@ -91,16 +95,16 @@ void red_set_can_mode(uint8_t mode) {
}
}

bool red_check_ignition(void) {
static bool red_check_ignition(void) {
// ignition is checked through harness
return harness_check_ignition();
}

uint32_t red_read_voltage_mV(void){
static uint32_t red_read_voltage_mV(void){
return adc_get_mV(2) * 11U; // TODO: is this correct?
}

void red_init(void) {
static void red_init(void) {
common_init_gpio();

//C10,C11 : OBD_SBU1_RELAY, OBD_SBU2_RELAY
Expand Down Expand Up @@ -153,7 +157,7 @@ void red_init(void) {
red_set_can_mode(CAN_MODE_NORMAL);
}

harness_configuration red_harness_config = {
static harness_configuration red_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOA,
Expand Down
16 changes: 10 additions & 6 deletions board/boards/red_chiplet.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#pragma once

#include "board_declarations.h"

// ///////////////////////////////////// //
// Red Panda chiplet (STM32H7) + Harness //
// ///////////////////////////////////// //

// Most hardware functionality is similar to red panda

void red_chiplet_enable_can_transceiver(uint8_t transceiver, bool enabled) {
static void red_chiplet_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver) {
case 1U:
set_gpio_output(GPIOG, 11, !enabled);
Expand All @@ -23,7 +27,7 @@ void red_chiplet_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}

void red_chiplet_enable_can_transceivers(bool enabled) {
static void red_chiplet_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
Expand All @@ -35,7 +39,7 @@ void red_chiplet_enable_can_transceivers(bool enabled) {
}
}

void red_chiplet_set_can_mode(uint8_t mode) {
static void red_chiplet_set_can_mode(uint8_t mode) {
red_chiplet_enable_can_transceiver(2U, false);
red_chiplet_enable_can_transceiver(4U, false);
switch (mode) {
Expand Down Expand Up @@ -77,11 +81,11 @@ void red_chiplet_set_can_mode(uint8_t mode) {
}
}

void red_chiplet_set_fan_or_usb_load_switch(bool enabled) {
static void red_chiplet_set_fan_or_usb_load_switch(bool enabled) {
set_gpio_output(GPIOD, 3, enabled);
}

void red_chiplet_init(void) {
static void red_chiplet_init(void) {
common_init_gpio();

// A8, A3: OBD_SBU1_RELAY, OBD_SBU2_RELAY
Expand Down Expand Up @@ -132,7 +136,7 @@ void red_chiplet_init(void) {
red_chiplet_set_can_mode(CAN_MODE_NORMAL);
}

harness_configuration red_chiplet_harness_config = {
static harness_configuration red_chiplet_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOA,
Expand Down
Loading

0 comments on commit fd6fe90

Please sign in to comment.