diff --git a/common/extpower_usb.c b/common/extpower_usb.c index 85f11f3101..7f1dbcd93c 100644 --- a/common/extpower_usb.c +++ b/common/extpower_usb.c @@ -82,6 +82,10 @@ enum ilim_config { #define PWM_MAPPING_A 3012 #define PWM_MAPPING_B (-29) +/* Current sense resistor values */ +#define R_INPUT_MOHM 20 /* mOhm */ +#define R_BATTERY_MOHM 33 /* mOhm */ + static int current_dev_type = TSU6721_TYPE_NONE; static int nominal_pwm_duty; static int current_pwm_duty; @@ -779,11 +783,11 @@ static int command_batdebug(int argc, char **argv) ccprintf("VAC = %d mV\n", pmu_adc_read(ADC_VAC, ADC_FLAG_KEEP_ON) * 17000 / 1024); ccprintf("IAC = %d mA\n", pmu_adc_read(ADC_IAC, ADC_FLAG_KEEP_ON) - * 20 * 33 / 1024); + * (1000 / R_INPUT_MOHM) * 33 / 1024); ccprintf("VBAT = %d mV\n", pmu_adc_read(ADC_VBAT, ADC_FLAG_KEEP_ON) * 17000 / 1024); ccprintf("IBAT = %d mA\n", pmu_adc_read(ADC_IBAT, 0) - * 50 * 40 / 1024); + * (1000 / R_BATTERY_MOHM) * 40 / 1024); ccprintf("PWM = %d%%\n", STM32_TIM_CCR1(3)); battery_current(&val); ccprintf("Battery Current = %d mA\n", val); @@ -844,7 +848,7 @@ static int power_command_info(struct host_cmd_handler_args *args) r->voltage_system = pmu_adc_read(ADC_VAC, ADC_FLAG_KEEP_ON) * 17000 / 1024; r->current_system = pmu_adc_read(ADC_IAC, 0) - * 20 * 33 / 1024; + * (1000 / R_INPUT_MOHM) * 33 / 1024; r->usb_dev_type = current_dev_type; /* Approximate value by PWM duty cycle */