Skip to content

Commit

Permalink
patch to be able to switch from EON to PC with a Panda that has EON b… (
Browse files Browse the repository at this point in the history
#290)

* fix switching from EON to PC with a Panda that has EON build and not 12V supply
  • Loading branch information
rbiasini authored Oct 4, 2019
1 parent a95c44a commit 4b3358c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
3 changes: 0 additions & 3 deletions board/boards/black.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,6 @@ void black_init(void) {

// init multiplexer
can_set_obd(car_harness_status, false);

// init usb power mode
black_set_usb_power_mode(USB_POWER_CDP);
}

const harness_configuration black_harness_config = {
Expand Down
7 changes: 0 additions & 7 deletions board/boards/white.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,6 @@ void white_init(void) {
set_gpio_alternate(GPIOA, 6, GPIO_AF5_SPI1);
set_gpio_alternate(GPIOA, 7, GPIO_AF5_SPI1);

// on PC, set USB power mode to CLIENT
#ifdef EON
white_set_usb_power_mode(USB_POWER_CDP);
#else
white_set_usb_power_mode(USB_POWER_CLIENT);
#endif

// B12: GMLAN, ignition sense, pull up
set_gpio_pullup(GPIOB, 12, PULL_UP);

Expand Down
10 changes: 10 additions & 0 deletions board/drivers/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ uint32_t adc_get(unsigned int channel) {
return ADC1->JDR1;
}

uint32_t adc_get_voltage(void) {
// REVC has a 10, 1 (1/11) voltage divider
// Here is the calculation for the scale (s)
// ADCV = VIN_S * (1/11) * (4095/3.3)
// RETVAL = ADCV * s = VIN_S*1000
// s = 1000/((4095/3.3)*(1/11)) = 8.8623046875

// Avoid needing floating point math, so output in mV
return (adc_get(ADCCHAN_VOLTAGE) * 8862U) / 1000U;
}
22 changes: 11 additions & 11 deletions board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,7 @@ int get_health_pkt(void *dat) {
uint8_t usb_power_mode_pkt;
} *health = dat;

//Voltage will be measured in mv. 5000 = 5V
uint32_t voltage = adc_get(ADCCHAN_VOLTAGE);

// REVC has a 10, 1 (1/11) voltage divider
// Here is the calculation for the scale (s)
// ADCV = VIN_S * (1/11) * (4095/3.3)
// RETVAL = ADCV * s = VIN_S*1000
// s = 1000/((4095/3.3)*(1/11)) = 8.8623046875

// Avoid needing floating point math
health->voltage_pkt = (voltage * 8862U) / 1000U;
health->voltage_pkt = adc_get_voltage();

// No current sense on panda black
if(hw_type != HW_TYPE_BLACK_PANDA){
Expand Down Expand Up @@ -662,6 +652,16 @@ int main(void) {
// init board
current_board->init();

// init usb power mode
uint32_t voltage = adc_get_voltage();
// init in CDP mode only if panda is powered by 12V.
// Otherwise a PC would not be able to flash a standalone panda with EON build
if (voltage > 8000U) { // 8V threshold
current_board->set_usb_power_mode(USB_POWER_CDP);
} else {
current_board->set_usb_power_mode(USB_POWER_CLIENT);
}

// panda has an FPU, let's use it!
enable_fpu();

Expand Down

0 comments on commit 4b3358c

Please sign in to comment.