Merge panda subtree

This commit is contained in:
Vehicle Researcher
2019-12-13 13:02:46 -08:00
105 changed files with 2436 additions and 1664 deletions
+11 -3
View File
@@ -123,8 +123,8 @@ void black_set_can_mode(uint8_t mode){
}
}
void black_usb_power_mode_tick(uint64_t tcnt){
UNUSED(tcnt);
void black_usb_power_mode_tick(uint32_t uptime){
UNUSED(uptime);
// Not applicable
}
@@ -146,6 +146,10 @@ void black_set_fan_power(uint8_t percentage){
UNUSED(percentage);
}
void black_set_phone_power(bool enabled){
UNUSED(enabled);
}
void black_init(void) {
common_init_gpio();
@@ -158,6 +162,9 @@ void black_init(void) {
set_gpio_mode(GPIOC, 0, MODE_ANALOG);
set_gpio_mode(GPIOC, 3, MODE_ANALOG);
// Set default state of GPS
current_board->set_esp_gps_mode(ESP_GPS_ENABLED);
// C10: OBD_SBU1_RELAY (harness relay driving output)
// C11: OBD_SBU2_RELAY (harness relay driving output)
set_gpio_mode(GPIOC, 10, MODE_OUTPUT);
@@ -227,5 +234,6 @@ const board board_black = {
.check_ignition = black_check_ignition,
.read_current = black_read_current,
.set_fan_power = black_set_fan_power,
.set_ir_power = black_set_ir_power
.set_ir_power = black_set_ir_power,
.set_phone_power = black_set_phone_power
};
+1 -1
View File
@@ -61,7 +61,7 @@ void peripherals_init(void){
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_TIM6EN; // interrupt timer
RCC->APB1ENR |= RCC_APB1ENR_PWREN; // for RTC config
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;
+11 -2
View File
@@ -3,10 +3,18 @@
// ////////// //
// Most hardware functionality is similar to white panda
void grey_init(void) {
white_grey_common_init();
// Set default state of GPS
current_board->set_esp_gps_mode(ESP_GPS_ENABLED);
}
const board board_grey = {
.board_type = "Grey",
.harness_config = &white_harness_config,
.init = white_init,
.init = grey_init,
.enable_can_transciever = white_enable_can_transciever,
.enable_can_transcievers = white_enable_can_transcievers,
.set_led = white_set_led,
@@ -17,5 +25,6 @@ const board board_grey = {
.check_ignition = white_check_ignition,
.read_current = white_read_current,
.set_fan_power = white_set_fan_power,
.set_ir_power = white_set_ir_power
.set_ir_power = white_set_ir_power,
.set_phone_power = white_set_phone_power
};
+8 -3
View File
@@ -50,8 +50,8 @@ void pedal_set_can_mode(uint8_t mode){
}
}
void pedal_usb_power_mode_tick(uint64_t tcnt){
UNUSED(tcnt);
void pedal_usb_power_mode_tick(uint32_t uptime){
UNUSED(uptime);
// Not applicable
}
@@ -73,6 +73,10 @@ void pedal_set_fan_power(uint8_t percentage){
UNUSED(percentage);
}
void pedal_set_phone_power(bool enabled){
UNUSED(enabled);
}
void pedal_init(void) {
common_init_gpio();
@@ -108,5 +112,6 @@ const board board_pedal = {
.check_ignition = pedal_check_ignition,
.read_current = pedal_read_current,
.set_fan_power = pedal_set_fan_power,
.set_ir_power = pedal_set_ir_power
.set_ir_power = pedal_set_ir_power,
.set_phone_power = pedal_set_phone_power
};
+45 -11
View File
@@ -1,6 +1,8 @@
// ///////////// //
// Uno + Harness //
// ///////////// //
#define BOOTKICK_TIME 3U
uint8_t bootkick_timer = 0U;
void uno_enable_can_transciever(uint8_t transciever, bool enabled) {
switch (transciever){
@@ -48,9 +50,38 @@ void uno_set_gps_load_switch(bool enabled) {
set_gpio_output(GPIOC, 12, enabled);
}
void uno_set_bootkick(bool enabled){
set_gpio_output(GPIOB, 14, !enabled);
}
void uno_bootkick(void) {
bootkick_timer = BOOTKICK_TIME;
uno_set_bootkick(true);
}
void uno_set_phone_power(bool enabled){
set_gpio_output(GPIOB, 4, enabled);
}
void uno_set_usb_power_mode(uint8_t mode) {
UNUSED(mode);
puts("Setting USB mode makes no sense on UNO\n");
bool valid = false;
switch (mode) {
case USB_POWER_CLIENT:
uno_set_phone_power(false);
valid = true;
break;
case USB_POWER_CDP:
uno_set_phone_power(true);
uno_bootkick();
valid = true;
break;
default:
puts("Invalid USB power mode\n");
break;
}
if (valid) {
usb_power_mode = mode;
}
}
void uno_set_esp_gps_mode(uint8_t mode) {
@@ -106,12 +137,11 @@ void uno_set_can_mode(uint8_t mode){
}
}
void uno_set_bootkick(bool enabled){
set_gpio_output(GPIOB, 14, !enabled);
}
void uno_usb_power_mode_tick(uint64_t tcnt){
if(tcnt == 3U){
void uno_usb_power_mode_tick(uint32_t uptime){
UNUSED(uptime);
if(bootkick_timer != 0U){
bootkick_timer--;
} else {
uno_set_bootkick(false);
}
}
@@ -152,6 +182,9 @@ void uno_init(void) {
set_gpio_mode(GPIOC, 0, MODE_ANALOG);
set_gpio_mode(GPIOC, 3, MODE_ANALOG);
// Set default state of GPS
current_board->set_esp_gps_mode(ESP_GPS_ENABLED);
// C10: OBD_SBU1_RELAY (harness relay driving output)
// C11: OBD_SBU2_RELAY (harness relay driving output)
set_gpio_mode(GPIOC, 10, MODE_OUTPUT);
@@ -168,7 +201,7 @@ void uno_init(void) {
uno_set_gps_load_switch(true);
// Turn on phone regulator
set_gpio_output(GPIOB, 4, 1);
uno_set_phone_power(true);
// Initialize IR PWM and set to 0%
set_gpio_alternate(GPIOB, 7, GPIO_AF2_TIM4);
@@ -212,7 +245,7 @@ void uno_init(void) {
}
// Bootkick phone
uno_set_bootkick(true);
uno_bootkick();
}
const harness_configuration uno_harness_config = {
@@ -243,5 +276,6 @@ const board board_uno = {
.check_ignition = uno_check_ignition,
.read_current = uno_read_current,
.set_fan_power = uno_set_fan_power,
.set_ir_power = uno_set_ir_power
.set_ir_power = uno_set_ir_power,
.set_phone_power = uno_set_phone_power
};
+32 -21
View File
@@ -78,11 +78,13 @@ void white_set_esp_gps_mode(uint8_t mode) {
set_gpio_output(GPIOC, 14, 0);
set_gpio_output(GPIOC, 5, 0);
break;
#ifndef EON
case ESP_GPS_ENABLED:
// ESP ON
set_gpio_output(GPIOC, 14, 1);
set_gpio_output(GPIOC, 5, 1);
break;
#endif
case ESP_GPS_BOOTMODE:
set_gpio_output(GPIOC, 14, 1);
set_gpio_output(GPIOC, 5, 0);
@@ -156,8 +158,8 @@ uint32_t white_read_current(void){
return adc_get(ADCCHAN_CURRENT);
}
uint64_t marker = 0;
void white_usb_power_mode_tick(uint64_t tcnt){
uint32_t marker = 0;
void white_usb_power_mode_tick(uint32_t uptime){
// on EON or BOOTSTUB, no state machine
#if !defined(BOOTSTUB) && !defined(EON)
@@ -171,47 +173,47 @@ void white_usb_power_mode_tick(uint64_t tcnt){
switch (usb_power_mode) {
case USB_POWER_CLIENT:
if ((tcnt - marker) >= CLICKS) {
if ((uptime - marker) >= CLICKS) {
if (!is_enumerated) {
puts("USBP: didn't enumerate, switching to CDP mode\n");
// switch to CDP
white_set_usb_power_mode(USB_POWER_CDP);
marker = tcnt;
marker = uptime;
}
}
// keep resetting the timer if it's enumerated
if (is_enumerated) {
marker = tcnt;
marker = uptime;
}
break;
case USB_POWER_CDP:
// been CLICKS clicks since we switched to CDP
if ((tcnt-marker) >= CLICKS) {
if ((uptime - marker) >= CLICKS) {
// measure current draw, if positive and no enumeration, switch to DCP
if (!is_enumerated && (current < CURRENT_THRESHOLD)) {
puts("USBP: no enumeration with current draw, switching to DCP mode\n");
white_set_usb_power_mode(USB_POWER_DCP);
marker = tcnt;
marker = uptime;
}
}
// keep resetting the timer if there's no current draw in CDP
if (current >= CURRENT_THRESHOLD) {
marker = tcnt;
marker = uptime;
}
break;
case USB_POWER_DCP:
// been at least CLICKS clicks since we switched to DCP
if ((tcnt-marker) >= CLICKS) {
if ((uptime - marker) >= CLICKS) {
// if no current draw, switch back to CDP
if (current >= CURRENT_THRESHOLD) {
puts("USBP: no current draw, switching back to CDP mode\n");
white_set_usb_power_mode(USB_POWER_CDP);
marker = tcnt;
marker = uptime;
}
}
// keep resetting the timer if there's current draw in DCP
if (current < CURRENT_THRESHOLD) {
marker = tcnt;
marker = uptime;
}
break;
default:
@@ -219,7 +221,7 @@ void white_usb_power_mode_tick(uint64_t tcnt){
break;
}
#else
UNUSED(tcnt);
UNUSED(uptime);
#endif
}
@@ -236,7 +238,11 @@ bool white_check_ignition(void){
return !get_gpio_input(GPIOA, 1);
}
void white_init(void) {
void white_set_phone_power(bool enabled){
UNUSED(enabled);
}
void white_grey_common_init(void) {
common_init_gpio();
// C3: current sense
@@ -296,13 +302,6 @@ void white_init(void) {
// Set normal CAN mode
white_set_can_mode(CAN_MODE_NORMAL);
// Setup ignition interrupts
SYSCFG->EXTICR[1] = SYSCFG_EXTICR1_EXTI1_PA;
EXTI->IMR |= (1U << 1);
EXTI->RTSR |= (1U << 1);
EXTI->FTSR |= (1U << 1);
NVIC_EnableIRQ(EXTI1_IRQn);
// Init usb power mode
uint32_t voltage = adc_get_voltage();
// Init in CDP mode only if panda is powered by 12V.
@@ -314,6 +313,17 @@ void white_init(void) {
}
}
void white_init(void) {
white_grey_common_init();
// Set default state of ESP
#ifdef EON
current_board->set_esp_gps_mode(ESP_GPS_DISABLED);
#else
current_board->set_esp_gps_mode(ESP_GPS_ENABLED);
#endif
}
const harness_configuration white_harness_config = {
.has_harness = false
};
@@ -332,5 +342,6 @@ const board board_white = {
.check_ignition = white_check_ignition,
.read_current = white_read_current,
.set_fan_power = white_set_fan_power,
.set_ir_power = white_set_ir_power
.set_ir_power = white_set_ir_power,
.set_phone_power = white_set_phone_power
};