patch to be able to switch from EON to PC with a Panda that has EON b… (#290)
* fix switching from EON to PC with a Panda that has EON build and not 12V supplymaster
parent
a95c44a717
commit
4b3358c921
|
@ -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 = {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
board/main.c
22
board/main.c
|
@ -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){
|
||||
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue