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
int16_t getRawHallEffect();
//Returns true if power is from dumb "DC" input rather than "smart" QC or PD
bool getIsPoweredByDCIN();
#ifdef __cplusplus
}

View File

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

View File

@@ -34,3 +34,16 @@ uint8_t usb_pd_detect() {
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
void seekQC(int16_t Vx10, uint16_t divisor);
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
}
#endif

View File

@@ -52,8 +52,14 @@ void seekQC(int16_t Vx10, uint16_t divisor) {
return;
if (xTaskGetTickCount() < 1000)
return;
if (Vx10 > 130)
Vx10 = 130; // Cap max value at 13V
#ifdef POW_QC_20V
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
// try and step towards the wanted value
@@ -80,25 +86,25 @@ void seekQC(int16_t Vx10, uint16_t divisor) {
osDelay(100);
}
#ifdef ENABLE_QC2
// 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 > 4) {
// No continuous mode, so QC2
QCMode = 2;
// Goto nearest
if (Vx10 > 110) {
// request 12V
// D- = 0.6V, D+ = 0.6V
// Clamp PB3
QC_Seek12V();
} else {
// request 9V
QC_Seek9V();
}
}
// 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 > 4) {
// No continuous mode, so QC2
QCMode = 2;
// Goto nearest
if (Vx10 > 190) {
// request 20V
QC_Seek20V();
} else if (Vx10 > 110) {
// request 12V
QC_Seek12V();
} else {
// request 9V
QC_Seek9V();
}
}
#endif
}
// 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
// negotiating as someone is feeding in hv
uint16_t vin = getInputVoltageX10(divisor, 1);
if (vin > 100) {
QCMode = 1; // Already at 12V, user has probably over-ridden this
if (vin > 80) {
QCMode = 0; //If over 8V something else has already negotiated
return;
}
if (QCTries > 10) {
@@ -161,3 +167,7 @@ void startQC(uint16_t divisor) {
}
}
bool hasQCNegotiated() {
return QCMode > 0;
}