Update QC to allow 20V theoretically + allow query for power source

This commit is contained in:
Ben V. Brown
2020-11-01 14:43:49 +11:00
parent 3146343bbb
commit f5644a090f
5 changed files with 51 additions and 25 deletions

View File

@@ -68,6 +68,8 @@ bool getHallSensorFitted();
// If the sensor is single polarity (or polarity insensitive) just return 0..32768 // If the sensor is single polarity (or polarity insensitive) just return 0..32768
int16_t getRawHallEffect(); int16_t getRawHallEffect();
//Returns true if power is from dumb "DC" input rather than "smart" QC or PD
bool getIsPoweredByDCIN();
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -119,7 +119,7 @@ uint8_t getButtonB() {
} }
void reboot() { void reboot() {
// TODO //Spin for watchdog
for (;;) { for (;;) {
} }
} }
@@ -127,3 +127,4 @@ void reboot() {
void delay_ms(uint16_t count) { void delay_ms(uint16_t count) {
delay_1ms(count); delay_1ms(count);
} }

View File

@@ -34,3 +34,16 @@ uint8_t usb_pd_detect() {
return false; return false;
} }
bool getIsPoweredByDCIN() {
//We return false until we are sure we are not using PD
if (PolicyEngine::setupCompleteOrTimedOut() == false) {
return false;
}
if (PolicyEngine::pdHasNegotiated()) {
return false; // We are using PD
}
if (hasQCNegotiated()) {
return false; // We are using QC
}
return true;
}

View File

@@ -13,7 +13,7 @@ extern "C" {
#endif #endif
void seekQC(int16_t Vx10, uint16_t divisor); void seekQC(int16_t Vx10, uint16_t divisor);
void startQC(uint16_t divisor); // Tries to negotiate QC for highest voltage, must be run after void startQC(uint16_t divisor); // Tries to negotiate QC for highest voltage, must be run after
bool hasQCNegotiated();// Returns true if a QC negotiation worked (we are using QC)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -52,8 +52,14 @@ void seekQC(int16_t Vx10, uint16_t divisor) {
return; return;
if (xTaskGetTickCount() < 1000) if (xTaskGetTickCount() < 1000)
return; return;
if (Vx10 > 130) #ifdef POW_QC_20V
Vx10 = 130; // Cap max value at 13V if (Vx10 > 200)
Vx10 = 200; // Cap max value at 20V
#else
if (Vx10 > 130)
Vx10 =130; // Cap max value at 13V
#endif
// Seek the QC to the Voltage given if this adapter supports continuous mode // Seek the QC to the Voltage given if this adapter supports continuous mode
// try and step towards the wanted value // try and step towards the wanted value
@@ -80,25 +86,25 @@ void seekQC(int16_t Vx10, uint16_t divisor) {
osDelay(100); osDelay(100);
} }
#ifdef ENABLE_QC2 #ifdef ENABLE_QC2
// Re-measure // Re-measure
/* Disabled due to nothing to test and code space of around 1k*/ /* Disabled due to nothing to test and code space of around 1k*/
steps = vStart - getInputVoltageX10(divisor, 1); steps = vStart - getInputVoltageX10(divisor, 1);
if (steps < 0) steps = -steps; if (steps < 0) steps = -steps;
if (steps > 4) { if (steps > 4) {
// No continuous mode, so QC2 // No continuous mode, so QC2
QCMode = 2; QCMode = 2;
// Goto nearest // Goto nearest
if (Vx10 > 110) { if (Vx10 > 190) {
// request 12V // request 20V
// D- = 0.6V, D+ = 0.6V QC_Seek20V();
// Clamp PB3 } else if (Vx10 > 110) {
QC_Seek12V(); // request 12V
QC_Seek12V();
} else { } else {
// request 9V // request 9V
QC_Seek9V(); QC_Seek9V();
} }
} }
#endif #endif
} }
// Must be called after FreeRToS Starts // Must be called after FreeRToS Starts
@@ -106,8 +112,8 @@ void startQC(uint16_t divisor) {
// Pre check that the input could be >5V already, and if so, dont both // Pre check that the input could be >5V already, and if so, dont both
// negotiating as someone is feeding in hv // negotiating as someone is feeding in hv
uint16_t vin = getInputVoltageX10(divisor, 1); uint16_t vin = getInputVoltageX10(divisor, 1);
if (vin > 100) { if (vin > 80) {
QCMode = 1; // Already at 12V, user has probably over-ridden this QCMode = 0; //If over 8V something else has already negotiated
return; return;
} }
if (QCTries > 10) { if (QCTries > 10) {
@@ -161,3 +167,7 @@ void startQC(uint16_t divisor) {
} }
} }
bool hasQCNegotiated() {
return QCMode > 0;
}