From 769ade0511483c4ba6e4e9a3b5380ffe50d01f13 Mon Sep 17 00:00:00 2001 From: hivoltag3 <60766260+hivoltag3@users.noreply.github.com> Date: Mon, 17 Feb 2020 15:26:52 -0700 Subject: [PATCH] Harness orientation designation fixes (#435) * Fix orientation designations in harness.h * Fix orientation designations in black.h * Fix orientation designations in uno.h * Fix typo --- board/boards/black.h | 12 ++++++------ board/boards/uno.h | 12 ++++++------ board/drivers/harness.h | 31 ++++++++++++------------------- 3 files changed, 24 insertions(+), 31 deletions(-) diff --git a/board/boards/black.h b/board/boards/black.h index 7165aa6cbb85b2..97f322f69b04b0 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -99,7 +99,7 @@ void black_set_can_mode(uint8_t mode){ switch (mode) { case CAN_MODE_NORMAL: case CAN_MODE_OBD_CAN2: - if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(car_harness_status == HARNESS_STATUS_NORMAL)) { + if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(car_harness_status == HARNESS_STATUS_FLIPPED)) { // B12,B13: disable OBD mode set_gpio_mode(GPIOB, 12, MODE_INPUT); set_gpio_mode(GPIOB, 13, MODE_INPUT); @@ -198,7 +198,7 @@ void black_init(void) { black_set_can_mode(CAN_MODE_NORMAL); // flip CAN0 and CAN2 if we are flipped - if (car_harness_status == HARNESS_STATUS_NORMAL) { + if (car_harness_status == HARNESS_STATUS_FLIPPED) { can_flip_buses(0, 2); } @@ -210,12 +210,12 @@ const harness_configuration black_harness_config = { .has_harness = true, .GPIO_SBU1 = GPIOC, .GPIO_SBU2 = GPIOC, - .GPIO_relay_normal = GPIOC, - .GPIO_relay_flipped = GPIOC, + .GPIO_relay_SBU1 = GPIOC, + .GPIO_relay_SBU2 = GPIOC, .pin_SBU1 = 0, .pin_SBU2 = 3, - .pin_relay_normal = 10, - .pin_relay_flipped = 11, + .pin_relay_SBU1 = 10, + .pin_relay_SBU2 = 11, .adc_channel_SBU1 = 10, .adc_channel_SBU2 = 13 }; diff --git a/board/boards/uno.h b/board/boards/uno.h index 1545a3f2dbcddf..a6a06eff3e9974 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -113,7 +113,7 @@ void uno_set_can_mode(uint8_t mode){ switch (mode) { case CAN_MODE_NORMAL: case CAN_MODE_OBD_CAN2: - if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(car_harness_status == HARNESS_STATUS_NORMAL)) { + if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(car_harness_status == HARNESS_STATUS_FLIPPED)) { // B12,B13: disable OBD mode set_gpio_mode(GPIOB, 12, MODE_INPUT); set_gpio_mode(GPIOB, 13, MODE_INPUT); @@ -230,7 +230,7 @@ void uno_init(void) { uno_set_can_mode(CAN_MODE_NORMAL); // flip CAN0 and CAN2 if we are flipped - if (car_harness_status == HARNESS_STATUS_NORMAL) { + if (car_harness_status == HARNESS_STATUS_FLIPPED) { can_flip_buses(0, 2); } @@ -252,12 +252,12 @@ const harness_configuration uno_harness_config = { .has_harness = true, .GPIO_SBU1 = GPIOC, .GPIO_SBU2 = GPIOC, - .GPIO_relay_normal = GPIOC, - .GPIO_relay_flipped = GPIOC, + .GPIO_relay_SBU1 = GPIOC, + .GPIO_relay_SBU2 = GPIOC, .pin_SBU1 = 0, .pin_SBU2 = 3, - .pin_relay_normal = 10, - .pin_relay_flipped = 11, + .pin_relay_SBU1 = 10, + .pin_relay_SBU2 = 11, .adc_channel_SBU1 = 10, .adc_channel_SBU2 = 13 }; diff --git a/board/drivers/harness.h b/board/drivers/harness.h index c996bff0b2efe7..4aeb41fe6300b0 100644 --- a/board/drivers/harness.h +++ b/board/drivers/harness.h @@ -10,12 +10,12 @@ struct harness_configuration { const bool has_harness; GPIO_TypeDef *GPIO_SBU1; GPIO_TypeDef *GPIO_SBU2; - GPIO_TypeDef *GPIO_relay_normal; - GPIO_TypeDef *GPIO_relay_flipped; + GPIO_TypeDef *GPIO_relay_SBU1; + GPIO_TypeDef *GPIO_relay_SBU2; uint8_t pin_SBU1; uint8_t pin_SBU2; - uint8_t pin_relay_normal; - uint8_t pin_relay_flipped; + uint8_t pin_relay_SBU1; + uint8_t pin_relay_SBU2; uint8_t adc_channel_SBU1; uint8_t adc_channel_SBU2; }; @@ -30,9 +30,9 @@ void set_intercept_relay(bool intercept) { } if(car_harness_status == HARNESS_STATUS_NORMAL){ - set_gpio_output(current_board->harness_config->GPIO_relay_normal, current_board->harness_config->pin_relay_normal, !intercept); + set_gpio_output(current_board->harness_config->GPIO_relay_SBU2, current_board->harness_config->pin_relay_SBU2, !intercept); } else { - set_gpio_output(current_board->harness_config->GPIO_relay_flipped, current_board->harness_config->pin_relay_flipped, !intercept); + set_gpio_output(current_board->harness_config->GPIO_relay_SBU1, current_board->harness_config->pin_relay_SBU1, !intercept); } } } @@ -41,10 +41,10 @@ bool harness_check_ignition(void) { bool ret = false; switch(car_harness_status){ case HARNESS_STATUS_NORMAL: - ret = !get_gpio_input(current_board->harness_config->GPIO_SBU2, current_board->harness_config->pin_SBU2); + ret = !get_gpio_input(current_board->harness_config->GPIO_SBU1, current_board->harness_config->pin_SBU1); break; case HARNESS_STATUS_FLIPPED: - ret = !get_gpio_input(current_board->harness_config->GPIO_SBU1, current_board->harness_config->pin_SBU1); + ret = !get_gpio_input(current_board->harness_config->GPIO_SBU2, current_board->harness_config->pin_SBU2); break; default: break; @@ -62,11 +62,11 @@ uint8_t harness_detect_orientation(void) { // Detect connection and orientation if((sbu1_voltage < HARNESS_CONNECTED_THRESHOLD) || (sbu2_voltage < HARNESS_CONNECTED_THRESHOLD)){ if (sbu1_voltage < sbu2_voltage) { - // orientation normal - ret = HARNESS_STATUS_NORMAL; - } else { - // orientation flipped + // orientation flipped (PANDA_SBU1->HARNESS_SBU1(relay), PANDA_SBU2->HARNESS_SBU2(ign)) ret = HARNESS_STATUS_FLIPPED; + } else { + // orientation normal (PANDA_SBU2->HARNESS_SBU1(relay), PANDA_SBU1->HARNESS_SBU2(ign)) + ret = HARNESS_STATUS_NORMAL; } } #endif @@ -90,13 +90,6 @@ void harness_init(void) { set_gpio_mode(current_board->harness_config->GPIO_SBU1, current_board->harness_config->pin_SBU1, MODE_INPUT); set_gpio_mode(current_board->harness_config->GPIO_SBU2, current_board->harness_config->pin_SBU2, MODE_INPUT); - // now we have orientation, set pin ignition detection - if(car_harness_status == HARNESS_STATUS_NORMAL){ - set_gpio_mode(current_board->harness_config->GPIO_SBU2, current_board->harness_config->pin_SBU2, MODE_INPUT); - } else { - set_gpio_mode(current_board->harness_config->GPIO_SBU1, current_board->harness_config->pin_SBU1, MODE_INPUT); - } - // keep busses connected by default set_intercept_relay(false); } else {