From f5644a090f0d573c3f186f7197e54debc7e29f7d Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sun, 1 Nov 2020 14:43:49 +1100 Subject: [PATCH] Update QC to allow 20V theoretically + allow query for power source --- workspace/TS100/Core/BSP/BSP.h | 2 + workspace/TS100/Core/BSP/Pine64/BSP.cpp | 3 +- workspace/TS100/Core/BSP/Pine64/Power.cpp | 13 +++++ workspace/TS100/Core/Inc/QC3.h | 2 +- workspace/TS100/Core/Src/{QC3.c => QC3.cpp} | 56 ++++++++++++--------- 5 files changed, 51 insertions(+), 25 deletions(-) rename workspace/TS100/Core/Src/{QC3.c => QC3.cpp} (76%) diff --git a/workspace/TS100/Core/BSP/BSP.h b/workspace/TS100/Core/BSP/BSP.h index 5fde786d..6bce9d44 100644 --- a/workspace/TS100/Core/BSP/BSP.h +++ b/workspace/TS100/Core/BSP/BSP.h @@ -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 } diff --git a/workspace/TS100/Core/BSP/Pine64/BSP.cpp b/workspace/TS100/Core/BSP/Pine64/BSP.cpp index 936f4d82..95537c7b 100644 --- a/workspace/TS100/Core/BSP/Pine64/BSP.cpp +++ b/workspace/TS100/Core/BSP/Pine64/BSP.cpp @@ -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); } + diff --git a/workspace/TS100/Core/BSP/Pine64/Power.cpp b/workspace/TS100/Core/BSP/Pine64/Power.cpp index 23b02783..47be7645 100644 --- a/workspace/TS100/Core/BSP/Pine64/Power.cpp +++ b/workspace/TS100/Core/BSP/Pine64/Power.cpp @@ -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; +} diff --git a/workspace/TS100/Core/Inc/QC3.h b/workspace/TS100/Core/Inc/QC3.h index 0ddf1b0f..9ba9d5b4 100644 --- a/workspace/TS100/Core/Inc/QC3.h +++ b/workspace/TS100/Core/Inc/QC3.h @@ -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 diff --git a/workspace/TS100/Core/Src/QC3.c b/workspace/TS100/Core/Src/QC3.cpp similarity index 76% rename from workspace/TS100/Core/Src/QC3.c rename to workspace/TS100/Core/Src/QC3.cpp index 473c14b2..4eb7e1e1 100644 --- a/workspace/TS100/Core/Src/QC3.c +++ b/workspace/TS100/Core/Src/QC3.cpp @@ -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; +}