Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harness orientation designation fixes #435

Merged
merged 4 commits into from
Feb 17, 2020
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
12 changes: 6 additions & 6 deletions board/boards/black.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand All @@ -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
};
Expand Down
12 changes: 6 additions & 6 deletions board/boards/uno.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand All @@ -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
};
Expand Down
31 changes: 12 additions & 19 deletions board/drivers/harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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);
}
}
}
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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 {
Expand Down