Fix QC 20V support

This commit is contained in:
Ben V. Brown
2020-11-01 15:42:36 +11:00
parent 3538acb07d
commit f465d17bb3
4 changed files with 52 additions and 37 deletions

View File

@@ -34,3 +34,17 @@ uint8_t usb_pd_detect() {
return false;
}
bool getIsPoweredByDCIN() {
#ifdef MODEL_TS80
return false;
#endif
#ifdef MODEL_TS80P
return false;
#endif
#ifdef MODEL_TS100
return true;
#endif
}

View File

@@ -20,11 +20,11 @@
#define POW_QC
#define POW_DC
#define POW_QC_20V
#define ENABLE_QC2
#define TEMP_TMP36
#define ACCEL_BMA
#define HALL_SENSOR
#define HALL_SI7210
#define BATTFILTERDEPTH 32
#endif

View File

@@ -50,7 +50,7 @@ void seekQC(int16_t Vx10, uint16_t divisor) {
if (Vx10 < 45)
return;
if (xTaskGetTickCount() < 1000)
if (xTaskGetTickCount() < TICKS_SECOND)
return;
#ifdef POW_QC_20V
if (Vx10 > 200)
@@ -89,7 +89,8 @@ void seekQC(int16_t Vx10, uint16_t divisor) {
// Re-measure
/* Disabled due to nothing to test and code space of around 1k*/
steps = vStart - getInputVoltageX10(divisor, 1);
if (steps < 0) steps = -steps;
if (steps < 0)
steps = -steps;
if (steps > 4) {
// No continuous mode, so QC2
QCMode = 2;
@@ -111,11 +112,7 @@ void seekQC(int16_t Vx10, uint16_t divisor) {
void startQC(uint16_t divisor) {
// Pre check that the input could be >5V already, and if so, dont both
// negotiating as someone is feeding in hv
uint16_t vin = getInputVoltageX10(divisor, 1);
if (vin > 80) {
QCMode = 0; //If over 8V something else has already negotiated
return;
}
QCMode=0;
if (QCTries > 10) {
return;
}

View File

@@ -126,9 +126,9 @@ static bool checkVoltageForExit() {
#endif
static void gui_drawBatteryIcon() {
#if defined(POW_PD) || defined(POW_QC)
if (!getIsPoweredByDCIN()) {
// On TS80 we replace this symbol with the voltage we are operating on
// If <9V then show single digit, if not show duals
// If <9V then show single digit, if not show dual small ones vertically stacked
uint8_t V = getInputVoltageX10(systemSettings.voltageDiv, 0);
if (V % 10 >= 5)
V = V / 10 + 1; // round up
@@ -145,23 +145,26 @@ static void gui_drawBatteryIcon() {
} else {
OLED::printNumber(V, 1);
}
#else
if (systemSettings.cutoutSetting) {
return;
}
#endif
#ifdef POW_DC
if (systemSettings.minDCVoltageCells) {
// User is on a lithium battery
// we need to calculate which of the 10 levels they are on
uint8_t cellCount = systemSettings.cutoutSetting + 2;
uint32_t cellV =
getInputVoltageX10(systemSettings.voltageDiv, 0) / cellCount;
uint8_t cellCount = systemSettings.minDCVoltageCells + 2;
uint32_t cellV = getInputVoltageX10(systemSettings.voltageDiv, 0) / cellCount;
// Should give us approx cell voltage X10
// Range is 42 -> 33 = 9 steps therefore we will use battery 1-10
// Range is 42 -> 33 = 9 steps therefore we will use battery 0-9
if (cellV < 33)
cellV = 33;
cellV -= 33; // Should leave us a number of 0-9
if (cellV > 9)
cellV = 9;
OLED::drawBattery(cellV + 1);
} else
} else {
OLED::drawSymbol(15); // Draw the DC Logo
}
#endif
}
static void gui_solderingTempAdjust() {
@@ -410,6 +413,7 @@ static bool shouldBeSleeping() {
return true;
}
}
#ifdef HALL_SENSOR
// If the hall effect sensor is enabled in the build, check if its over
// threshold, and if so then we force sleep