Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 1 addition & 25 deletions board/boards/black.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,6 @@ void black_set_usb_load_switch(bool enabled) {
set_gpio_output(GPIOB, 1, !enabled);
}

void black_set_usb_power_mode(uint8_t mode) {
bool valid = false;
switch (mode) {
case USB_POWER_CLIENT:
black_set_usb_load_switch(false);
valid = true;
break;
case USB_POWER_CDP:
black_set_usb_load_switch(true);
valid = true;
break;
default:
puts("Invalid USB power mode\n");
break;
}
if (valid) {
usb_power_mode = mode;
}
}

void black_set_gps_mode(uint8_t mode) {
switch (mode) {
case GPS_DISABLED:
Expand Down Expand Up @@ -162,9 +142,6 @@ void black_init(void) {
// Turn on USB load switch.
black_set_usb_load_switch(true);

// Set right power mode
black_set_usb_power_mode(USB_POWER_CDP);

// Initialize harness
harness_init();

Expand Down Expand Up @@ -204,6 +181,7 @@ const harness_configuration black_harness_config = {

const board board_black = {
.board_type = "Black",
.board_tick = unused_board_tick,
.harness_config = &black_harness_config,
.has_gps = true,
.has_hw_gmlan = false,
Expand All @@ -215,10 +193,8 @@ const board board_black = {
.enable_can_transceiver = black_enable_can_transceiver,
.enable_can_transceivers = black_enable_can_transceivers,
.set_led = black_set_led,
.set_usb_power_mode = black_set_usb_power_mode,
.set_gps_mode = black_set_gps_mode,
.set_can_mode = black_set_can_mode,
.usb_power_mode_tick = unused_usb_power_mode_tick,
.check_ignition = black_check_ignition,
.read_current = unused_read_current,
.set_fan_enabled = unused_set_fan_enabled,
Expand Down
9 changes: 2 additions & 7 deletions board/boards/board_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ typedef void (*board_init)(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_usb_power_mode)(uint8_t mode);
typedef void (*board_set_gps_mode)(uint8_t mode);
typedef void (*board_set_can_mode)(uint8_t mode);
typedef void (*board_usb_power_mode_tick)(uint32_t uptime);
typedef bool (*board_check_ignition)(void);
typedef uint32_t (*board_read_current)(void);
typedef void (*board_set_ir_power)(uint8_t percentage);
typedef void (*board_set_fan_enabled)(bool enabled);
typedef void (*board_set_phone_power)(bool enabled);
typedef void (*board_set_clock_source_mode)(uint8_t mode);
typedef void (*board_set_siren)(bool enabled);
typedef void (*board_board_tick)(bool ignition, bool usb_enum, bool heartbeat_seen);

struct board {
const char *board_type;
Expand All @@ -28,17 +27,16 @@ struct board {
board_enable_can_transceiver enable_can_transceiver;
board_enable_can_transceivers enable_can_transceivers;
board_set_led set_led;
board_set_usb_power_mode set_usb_power_mode;
board_set_gps_mode set_gps_mode;
board_set_can_mode set_can_mode;
board_usb_power_mode_tick usb_power_mode_tick;
board_check_ignition check_ignition;
board_read_current read_current;
board_set_ir_power set_ir_power;
board_set_fan_enabled set_fan_enabled;
board_set_phone_power set_phone_power;
board_set_clock_source_mode set_clock_source_mode;
board_set_siren set_siren;
board_board_tick board_tick;
};

// ******************* Definitions ********************
Expand Down Expand Up @@ -73,6 +71,3 @@ struct board {
#define CAN_MODE_GMLAN_CAN2 1U
#define CAN_MODE_GMLAN_CAN3 2U
#define CAN_MODE_OBD_CAN2 3U

// ********************* Globals **********************
uint8_t usb_power_mode = USB_POWER_NONE;
34 changes: 14 additions & 20 deletions board/boards/dos.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,15 @@ void dos_set_bootkick(bool enabled){
set_gpio_output(GPIOC, 4, !enabled);
}

void dos_set_usb_power_mode(uint8_t mode) {
bool valid = false;
switch (mode) {
case USB_POWER_CLIENT:
dos_set_bootkick(false);
valid = true;
break;
case USB_POWER_CDP:
dos_set_bootkick(true);
valid = true;
break;
default:
puts("Invalid USB power mode\n");
break;
}
if (valid) {
usb_power_mode = mode;
void dos_board_tick(bool ignition, bool usb_enum, bool heartbeat_seen) {
if (ignition && !usb_enum) {
// enable bootkick if ignition seen
dos_set_bootkick(true);
} else if (heartbeat_seen) {
// disable once openpilot is up
dos_set_bootkick(false);
} else {

}
}

Expand Down Expand Up @@ -173,6 +165,9 @@ void dos_init(void) {
dos_set_led(LED_GREEN, false);
dos_set_led(LED_BLUE, false);

// Bootkick
dos_set_bootkick(true);

// Set normal CAN mode
dos_set_can_mode(CAN_MODE_NORMAL);

Expand Down Expand Up @@ -201,6 +196,7 @@ const harness_configuration dos_harness_config = {

const board board_dos = {
.board_type = "Dos",
.board_tick = dos_board_tick,
.harness_config = &dos_harness_config,
.has_gps = false,
.has_hw_gmlan = false,
Expand All @@ -212,15 +208,13 @@ const board board_dos = {
.enable_can_transceiver = dos_enable_can_transceiver,
.enable_can_transceivers = dos_enable_can_transceivers,
.set_led = dos_set_led,
.set_usb_power_mode = dos_set_usb_power_mode,
.set_gps_mode = unused_set_gps_mode,
.set_can_mode = dos_set_can_mode,
.usb_power_mode_tick = unused_usb_power_mode_tick,
.check_ignition = dos_check_ignition,
.read_current = unused_read_current,
.set_fan_enabled = dos_set_fan_enabled,
.set_ir_power = dos_set_ir_power,
.set_phone_power = unused_set_phone_power,
.set_clock_source_mode = dos_set_clock_source_mode,
.set_siren = dos_set_siren
.set_siren = unused_set_siren
};
3 changes: 1 addition & 2 deletions board/boards/grey.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void grey_set_gps_mode(uint8_t mode) {

const board board_grey = {
.board_type = "Grey",
.board_tick = unused_board_tick,
.harness_config = &white_harness_config,
.has_gps = true,
.has_hw_gmlan = true,
Expand All @@ -46,10 +47,8 @@ const board board_grey = {
.enable_can_transceiver = white_enable_can_transceiver,
.enable_can_transceivers = white_enable_can_transceivers,
.set_led = white_set_led,
.set_usb_power_mode = white_set_usb_power_mode,
.set_gps_mode = grey_set_gps_mode,
.set_can_mode = white_set_can_mode,
.usb_power_mode_tick = unused_usb_power_mode_tick,
.check_ignition = white_check_ignition,
.read_current = white_read_current,
.set_fan_enabled = unused_set_fan_enabled,
Expand Down
8 changes: 1 addition & 7 deletions board/boards/pedal.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ void pedal_set_led(uint8_t color, bool enabled) {
}
}

void pedal_set_usb_power_mode(uint8_t mode){
usb_power_mode = mode;
puts("Trying to set USB power mode on pedal. This is not supported.\n");
}

void pedal_set_gps_mode(uint8_t mode) {
UNUSED(mode);
puts("Trying to set ESP/GPS mode on pedal. This is not supported.\n");
Expand Down Expand Up @@ -78,6 +73,7 @@ const harness_configuration pedal_harness_config = {

const board board_pedal = {
.board_type = "Pedal",
.board_tick = unused_board_tick,
.harness_config = &pedal_harness_config,
.has_gps = false,
.has_hw_gmlan = false,
Expand All @@ -89,10 +85,8 @@ const board board_pedal = {
.enable_can_transceiver = pedal_enable_can_transceiver,
.enable_can_transceivers = pedal_enable_can_transceivers,
.set_led = pedal_set_led,
.set_usb_power_mode = pedal_set_usb_power_mode,
.set_gps_mode = pedal_set_gps_mode,
.set_can_mode = pedal_set_can_mode,
.usb_power_mode_tick = unused_usb_power_mode_tick,
.check_ignition = pedal_check_ignition,
.read_current = unused_read_current,
.set_fan_enabled = unused_set_fan_enabled,
Expand Down
25 changes: 1 addition & 24 deletions board/boards/red.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,6 @@ void red_set_usb_load_switch(bool enabled) {
set_gpio_output(GPIOB, 14, !enabled);
}

void red_set_usb_power_mode(uint8_t mode) {
bool valid = false;
switch (mode) {
case USB_POWER_CLIENT:
red_set_usb_load_switch(false);
valid = true;
break;
case USB_POWER_CDP:
red_set_usb_load_switch(true);
valid = true;
break;
default:
break;
}
if (valid) {
usb_power_mode = mode;
}
}

void red_set_can_mode(uint8_t mode) {
switch (mode) {
case CAN_MODE_NORMAL:
Expand Down Expand Up @@ -139,9 +120,6 @@ void red_init(void) {
// Turn on USB load switch.
red_set_usb_load_switch(true);

// Set right power mode
red_set_usb_power_mode(USB_POWER_CDP);

// Initialize harness
harness_init();

Expand Down Expand Up @@ -181,6 +159,7 @@ const harness_configuration red_harness_config = {

const board board_red = {
.board_type = "Red",
.board_tick = unused_board_tick,
.harness_config = &red_harness_config,
.has_gps = false,
.has_hw_gmlan = false,
Expand All @@ -192,10 +171,8 @@ const board board_red = {
.enable_can_transceiver = red_enable_can_transceiver,
.enable_can_transceivers = red_enable_can_transceivers,
.set_led = red_set_led,
.set_usb_power_mode = red_set_usb_power_mode,
.set_gps_mode = unused_set_gps_mode,
.set_can_mode = red_set_can_mode,
.usb_power_mode_tick = unused_usb_power_mode_tick,
.check_ignition = red_check_ignition,
.read_current = unused_read_current,
.set_fan_enabled = unused_set_fan_enabled,
Expand Down
32 changes: 7 additions & 25 deletions board/boards/uno.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void uno_set_gps_load_switch(bool enabled) {
}

void uno_set_bootkick(bool enabled){
if(enabled){
if (enabled) {
set_gpio_output(GPIOB, 14, false);
} else {
// We want the pin to be floating, not forced high!
Expand All @@ -73,25 +73,6 @@ void uno_set_phone_power(bool enabled){
set_gpio_output(GPIOB, 4, enabled);
}

void uno_set_usb_power_mode(uint8_t mode) {
bool valid = false;
switch (mode) {
case USB_POWER_CLIENT:
valid = true;
break;
case USB_POWER_CDP:
uno_bootkick();
valid = true;
break;
default:
puts("Invalid USB power mode\n");
break;
}
if (valid) {
usb_power_mode = mode;
}
}

void uno_set_gps_mode(uint8_t mode) {
switch (mode) {
case GPS_DISABLED:
Expand Down Expand Up @@ -145,9 +126,11 @@ void uno_set_can_mode(uint8_t mode){
}
}

void uno_usb_power_mode_tick(uint32_t uptime){
UNUSED(uptime);
if(bootkick_timer != 0U){
void uno_board_tick(bool ignition, bool usb_enum, bool heartbeat_seen) {
UNUSED(ignition);
UNUSED(usb_enum);
UNUSED(heartbeat_seen);
if (bootkick_timer != 0U) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to increase BOOTKICK_TIME since the tick is now called at 8Hz instead of 1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to the 1Hz loop

bootkick_timer--;
} else {
uno_set_bootkick(false);
Expand Down Expand Up @@ -262,6 +245,7 @@ const harness_configuration uno_harness_config = {

const board board_uno = {
.board_type = "Uno",
.board_tick = uno_board_tick,
.harness_config = &uno_harness_config,
.has_gps = true,
.has_hw_gmlan = false,
Expand All @@ -273,10 +257,8 @@ const board board_uno = {
.enable_can_transceiver = uno_enable_can_transceiver,
.enable_can_transceivers = uno_enable_can_transceivers,
.set_led = uno_set_led,
.set_usb_power_mode = uno_set_usb_power_mode,
.set_gps_mode = uno_set_gps_mode,
.set_can_mode = uno_set_can_mode,
.usb_power_mode_tick = uno_usb_power_mode_tick,
.check_ignition = uno_check_ignition,
.read_current = unused_read_current,
.set_fan_enabled = uno_set_fan_enabled,
Expand Down
10 changes: 6 additions & 4 deletions board/boards/unused_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ void unused_set_gps_mode(uint8_t mode) {
UNUSED(mode);
}

void unused_usb_power_mode_tick(uint32_t uptime) {
UNUSED(uptime);
}

void unused_set_ir_power(uint8_t percentage) {
UNUSED(percentage);
}
Expand All @@ -29,3 +25,9 @@ void unused_set_siren(bool enabled) {
uint32_t unused_read_current(void) {
return 0U;
}

void unused_board_tick(bool ignition, bool usb_enum, bool heartbeat_seen) {
UNUSED(ignition);
UNUSED(usb_enum);
UNUSED(heartbeat_seen);
}
Loading