diff --git a/source/Core/BSP/MHP30/Power.cpp b/source/Core/BSP/MHP30/Power.cpp index 95dd26e3..401b370e 100644 --- a/source/Core/BSP/MHP30/Power.cpp +++ b/source/Core/BSP/MHP30/Power.cpp @@ -16,7 +16,7 @@ void power_check() { if (FUSB302_present) { PolicyEngine::PPSTimerCallback(); // Cant start QC until either PD works or fails - if (PolicyEngine::setupCompleteOrTimedOut() == false) { + if (PolicyEngine::setupCompleteOrTimedOut(systemSettings.PDNegTimeout) == false) { return; } if (PolicyEngine::pdHasNegotiated()) { diff --git a/source/Core/BSP/Miniware/Power.cpp b/source/Core/BSP/Miniware/Power.cpp index 8cbee738..8b7c8eb3 100644 --- a/source/Core/BSP/Miniware/Power.cpp +++ b/source/Core/BSP/Miniware/Power.cpp @@ -16,7 +16,7 @@ void power_check() { if (FUSB302_present) { PolicyEngine::PPSTimerCallback(); // Cant start QC until either PD works or fails - if (PolicyEngine::setupCompleteOrTimedOut() == false) { + if (PolicyEngine::setupCompleteOrTimedOut(systemSettings.PDNegTimeout) == false) { return; } if (PolicyEngine::pdHasNegotiated()) { diff --git a/source/Core/BSP/Pine64/Power.cpp b/source/Core/BSP/Pine64/Power.cpp index 2dfa76a0..42bee942 100644 --- a/source/Core/BSP/Pine64/Power.cpp +++ b/source/Core/BSP/Pine64/Power.cpp @@ -16,7 +16,7 @@ void power_check() { if (FUSB302_present) { PolicyEngine::PPSTimerCallback(); // Cant start QC until either PD works or fails - if (PolicyEngine::setupCompleteOrTimedOut() == false) { + if (PolicyEngine::setupCompleteOrTimedOut(systemSettings.PDNegTimeout) == false) { return; } if (PolicyEngine::pdHasNegotiated()) { @@ -43,7 +43,7 @@ uint8_t usb_pd_detect() { bool getIsPoweredByDCIN() { // We return false until we are sure we are not using PD - if (PolicyEngine::setupCompleteOrTimedOut() == false) { + if (PolicyEngine::setupCompleteOrTimedOut(systemSettings.PDNegTimeout) == false) { return false; } if (PolicyEngine::pdHasNegotiated()) { diff --git a/source/Core/Drivers/FUSB302/policy_engine.cpp b/source/Core/Drivers/FUSB302/policy_engine.cpp index 8a2a29bd..3b135a1a 100644 --- a/source/Core/Drivers/FUSB302/policy_engine.cpp +++ b/source/Core/Drivers/FUSB302/policy_engine.cpp @@ -21,7 +21,6 @@ #include "int_n.h" #include #include -#include "Settings.h" bool PolicyEngine::pdNegotiationComplete; int PolicyEngine::current_voltage_mv; @@ -619,12 +618,13 @@ void PolicyEngine::PPSTimerCallback() { } } -bool PolicyEngine::NegotiationTimeoutReached() { - if (systemSettings.PDNegTimeout == 0){ +bool PolicyEngine::NegotiationTimeoutReached(uint8_t timeout) { + if (timeout == 0){ return false; } - if (xTaskGetTickCount() > (TICKS_SECOND/10 * systemSettings.PDNegTimeout)) { + if (xTaskGetTickCount() > (TICKS_100MS * timeout)) { + state = PESinkSourceUnresponsive; return true; } diff --git a/source/Core/Drivers/FUSB302/policy_engine.h b/source/Core/Drivers/FUSB302/policy_engine.h index 96bd12a5..8cd89611 100644 --- a/source/Core/Drivers/FUSB302/policy_engine.h +++ b/source/Core/Drivers/FUSB302/policy_engine.h @@ -33,10 +33,10 @@ public: static void handleMessage(union pd_msg *msg); // Returns true if headers indicate PD3.0 compliant static bool isPD3_0(); - static bool setupCompleteOrTimedOut() { + static bool setupCompleteOrTimedOut(uint8_t timeout) { if (pdNegotiationComplete) return true; - if (PolicyEngine::NegotiationTimeoutReached()) + if (PolicyEngine::NegotiationTimeoutReached(timeout)) return true; if (state == policy_engine_state::PESinkSourceUnresponsive) return true; @@ -48,16 +48,12 @@ public: static bool pdHasNegotiated() { if (state == policy_engine_state::PESinkSourceUnresponsive) return false; - if (pdNegotiationComplete) - return true; - if (PolicyEngine::NegotiationTimeoutReached()) - return false; return true; } // Call this periodically, at least once every second static void PPSTimerCallback(); - static bool NegotiationTimeoutReached(); + static bool NegotiationTimeoutReached(uint8_t timeout); enum class Notifications { PDB_EVT_PE_RESET = EVENT_MASK(0), diff --git a/source/Core/Inc/Settings.h b/source/Core/Inc/Settings.h index f04c026c..642f9f5a 100644 --- a/source/Core/Inc/Settings.h +++ b/source/Core/Inc/Settings.h @@ -27,7 +27,6 @@ typedef struct { uint8_t minDCVoltageCells; // The voltage we cut out at for under voltage when powered by DC jack uint8_t minVoltageCells; // Minimum allowed voltage per cell <3S - 3.0V (30)> <4S - 2.4V (24)> <...> (Minimum recommended 2.7V) uint8_t QCIdealVoltage; // Desired QC3.0 voltage (9,12,20V) - uint8_t PDNegTimeout; // PD timeout in 100ms steps uint8_t OrientationMode : 2; // Selects between Auto,Right and left handed layouts uint8_t sensitivity : 4; // Sensitivity of accelerometer (5 bits) uint8_t animationLoop : 1; // Animation loop switch @@ -62,6 +61,8 @@ typedef struct { uint8_t pdMissingWarningCounter; // Counter of how many times we have warned we cannot detect the pd interface char uiLanguage[8]; // Selected UI Language code, null-terminated *only if* the length is less than 8 chars + uint8_t PDNegTimeout; // PD timeout in 100ms steps + uint32_t padding; // This is here for in case we are not an even divisor so // that nothing gets cut off // MUST BE LAST diff --git a/source/Core/Src/gui.cpp b/source/Core/Src/gui.cpp index ac15b83b..662c2ee5 100644 --- a/source/Core/Src/gui.cpp +++ b/source/Core/Src/gui.cpp @@ -26,10 +26,10 @@ static bool settings_displayInputMinVRange(void); static bool settings_setQCInputV(void); static bool settings_displayQCInputV(void); #endif - +#ifdef POW_PD static bool settings_setPDNegTimeout(void); static bool settings_displayPDNegTimeout(void); - +#endif #ifndef NO_SLEEP_MODE static bool settings_setSleepTemp(void); static bool settings_displaySleepTemp(void); @@ -165,7 +165,7 @@ const menuitem rootSettingsMenu[] { } // end of menu marker. DO NOT REMOVE }; -#if defined(POW_DC) || defined(POW_QC) +#if defined(POW_DC) || defined(POW_QC) || defined(POW_PD) const menuitem powerMenu[] = { /* * Power Source @@ -177,7 +177,9 @@ const menuitem powerMenu[] = { #ifdef POW_QC {SETTINGS_DESC(SettingsItemIndex::QCMaxVoltage), settings_setQCInputV, settings_displayQCInputV}, /*Voltage input*/ #endif - {SETTINGS_DESC(SettingsItemIndex::PDNegTimeout), settings_setPDNegTimeout, settings_displayPDNegTimeout}, /*PD timeout setup*/ +#ifdef POW_PD + {SETTINGS_DESC(SettingsItemIndex::PDNegTimeout), settings_setPDNegTimeout, settings_displayPDNegTimeout}, /*PD timeout setup*/ +#endif {0, nullptr, nullptr} // end of menu marker. DO NOT REMOVE }; #endif @@ -387,6 +389,7 @@ static bool settings_displayQCInputV(void) { #endif +#ifdef POW_PD static bool settings_setPDNegTimeout(void) { systemSettings.PDNegTimeout = (systemSettings.PDNegTimeout + 1) % 50; @@ -399,6 +402,7 @@ static bool settings_displayPDNegTimeout(void){ return systemSettings.QCIdealVoltage == 49; } +#endif #ifndef NO_SLEEP_MODE static bool settings_setSleepTemp(void) {