Skip to content

Commit

Permalink
Uno (commaai#274)
Browse files Browse the repository at this point in the history
* Added uno

* Added usb switch support

* Added PWM and IR power functions

* Implemented bootkick

* Added uno as a new hw type

* Bumped version

* Added fan control and tach readout

* WIP: RTC support

* Working RTC

* Fixed python

* Misra compliance

* Added USB control messages for fan/IR power

* Added USB commands + tests for fan & IR control. Fixed bootstub and pedal compilation

* Added IR and fan to power saving mode

* Changed defaults

* Fix safety considering uno

* passing safety now

* Minor UNO tweaks

* Fixed version

* More minor temporary tweaks

* Removed usb load switch from uno

* Added power control for shutting down the fan completely

* Disable IR LEDs by default

* Fixed linter issue

* Linter fix #2
  • Loading branch information
rbiasini authored and robbederks committed Oct 25, 2019
1 parent 7d29dc5 commit a12a148
Show file tree
Hide file tree
Showing 25 changed files with 734 additions and 59 deletions.
33 changes: 30 additions & 3 deletions board/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
// ///// Board definition and detection ///// //
#include "drivers/harness.h"
#ifdef PANDA
#include "drivers/fan.h"
#include "drivers/rtc.h"
#include "boards/white.h"
#include "boards/grey.h"
#include "boards/black.h"
#include "boards/uno.h"
#else
#include "boards/pedal.h"
#endif
Expand All @@ -23,6 +26,9 @@ void detect_board_type(void) {
} else if(detect_with_pull(GPIOA, 13, PULL_DOWN)) { // Rev AB deprecated, so no pullup means black. In REV C, A13 is pulled up to 5V with a 10K
hw_type = HW_TYPE_GREY_PANDA;
current_board = &board_grey;
} else if(!detect_with_pull(GPIOB, 15, PULL_UP)) {
hw_type = HW_TYPE_UNO;
current_board = &board_uno;
} else {
hw_type = HW_TYPE_BLACK_PANDA;
current_board = &board_black;
Expand All @@ -31,7 +37,7 @@ void detect_board_type(void) {
#ifdef PEDAL
hw_type = HW_TYPE_PEDAL;
current_board = &board_pedal;
#else
#else
hw_type = HW_TYPE_UNKNOWN;
puts("Hardware type is UNKNOWN!\n");
#endif
Expand Down Expand Up @@ -60,6 +66,27 @@ void detect_configuration(void) {
}

// ///// Board functions ///// //
// TODO: Make these config options in the board struct
bool board_has_gps(void) {
return ((hw_type == HW_TYPE_GREY_PANDA) || (hw_type == HW_TYPE_BLACK_PANDA));
}
return ((hw_type == HW_TYPE_GREY_PANDA) || (hw_type == HW_TYPE_BLACK_PANDA) || (hw_type == HW_TYPE_UNO));
}

bool board_has_gmlan(void) {
return ((hw_type == HW_TYPE_WHITE_PANDA) || (hw_type == HW_TYPE_GREY_PANDA));
}

bool board_has_obd(void) {
return ((hw_type == HW_TYPE_BLACK_PANDA) || (hw_type == HW_TYPE_UNO));
}

bool board_has_lin(void) {
return ((hw_type == HW_TYPE_WHITE_PANDA) || (hw_type == HW_TYPE_GREY_PANDA));
}

bool board_has_rtc(void) {
return (hw_type == HW_TYPE_UNO);
}

bool board_has_relay(void) {
return ((hw_type == HW_TYPE_BLACK_PANDA) || (hw_type == HW_TYPE_UNO));
}
7 changes: 7 additions & 0 deletions board/board_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ typedef void (*board_set_esp_gps_mode)(uint8_t mode);
typedef void (*board_set_can_mode)(uint8_t mode);
typedef void (*board_usb_power_mode_tick)(uint64_t tcnt);
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_power)(uint8_t percentage);

struct board {
const char *board_type;
Expand All @@ -21,6 +24,9 @@ struct board {
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_power set_fan_power;
};

// ******************* Definitions ********************
Expand All @@ -30,6 +36,7 @@ struct board {
#define HW_TYPE_GREY_PANDA 2U
#define HW_TYPE_BLACK_PANDA 3U
#define HW_TYPE_PEDAL 4U
#define HW_TYPE_UNO 5U

// LED colors
#define LED_RED 0U
Expand Down
21 changes: 17 additions & 4 deletions board/boards/black.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ bool black_check_ignition(void){
return harness_check_ignition();
}

uint32_t black_read_current(void){
// No current sense on black panda
return 0U;
}

void black_set_ir_power(uint8_t percentage){
UNUSED(percentage);
}

void black_set_fan_power(uint8_t percentage){
UNUSED(percentage);
}

void black_init(void) {
common_init_gpio();

Expand All @@ -154,9 +167,6 @@ void black_init(void) {
set_gpio_output(GPIOC, 10, 1);
set_gpio_output(GPIOC, 11, 1);

// C8: FAN aka TIM3_CH3
set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3);

// Turn on GPS load switch.
black_set_gps_load_switch(true);

Expand Down Expand Up @@ -214,5 +224,8 @@ const board board_black = {
.set_esp_gps_mode = black_set_esp_gps_mode,
.set_can_mode = black_set_can_mode,
.usb_power_mode_tick = black_usb_power_mode_tick,
.check_ignition = black_check_ignition
.check_ignition = black_check_ignition,
.read_current = black_read_current,
.set_fan_power = black_set_fan_power,
.set_ir_power = black_set_ir_power
};
6 changes: 4 additions & 2 deletions board/boards/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,18 @@ void peripherals_init(void){
#endif
RCC->APB1ENR |= RCC_APB1ENR_DACEN;
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; // main counter
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; // slow loop and pedal
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN; // gmlan_alt
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; // pedal and fan PWM
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN; // gmlan_alt and IR PWM
//RCC->APB1ENR |= RCC_APB1ENR_TIM5EN;
//RCC->APB1ENR |= RCC_APB1ENR_TIM6EN;
RCC->APB1ENR |= RCC_APB1ENR_PWREN; // for RTC config
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;
//RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
RCC->APB2ENR |= RCC_APB2ENR_TIM9EN; // slow loop
}

// Detection with internal pullup
Expand Down
5 changes: 4 additions & 1 deletion board/boards/grey.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ const board board_grey = {
.set_esp_gps_mode = white_set_esp_gps_mode,
.set_can_mode = white_set_can_mode,
.usb_power_mode_tick = white_usb_power_mode_tick,
.check_ignition = white_check_ignition
.check_ignition = white_check_ignition,
.read_current = white_read_current,
.set_fan_power = white_set_fan_power,
.set_ir_power = white_set_ir_power
};
16 changes: 16 additions & 0 deletions board/boards/pedal.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ bool pedal_check_ignition(void){
return false;
}

uint32_t pedal_read_current(void){
// No current sense on pedal
return 0U;
}

void pedal_set_ir_power(uint8_t percentage){
UNUSED(percentage);
}

void pedal_set_fan_power(uint8_t percentage){
UNUSED(percentage);
}

void pedal_init(void) {
common_init_gpio();

Expand Down Expand Up @@ -93,4 +106,7 @@ const board board_pedal = {
.set_can_mode = pedal_set_can_mode,
.usb_power_mode_tick = pedal_usb_power_mode_tick,
.check_ignition = pedal_check_ignition,
.read_current = pedal_read_current,
.set_fan_power = pedal_set_fan_power,
.set_ir_power = pedal_set_ir_power
};
Loading

0 comments on commit a12a148

Please sign in to comment.