From 1fe3210263351d204b82f1713d98c5e095477fb3 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" <5425387+Ralim@users.noreply.github.com> Date: Fri, 24 Jun 2022 10:33:23 +1000 Subject: [PATCH 01/19] Fix startup current pulse on some devices Always force power to 0 if <= to handle vin not yet stable at boot --- source/Core/Src/power.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Core/Src/power.cpp b/source/Core/Src/power.cpp index e7037882..2fcc120b 100644 --- a/source/Core/Src/power.cpp +++ b/source/Core/Src/power.cpp @@ -62,7 +62,7 @@ uint32_t availableW10(uint8_t sample) { } uint8_t X10WattsToPWM(int32_t x10Watts, uint8_t sample) { // Scale input x10Watts to the pwm range available - if (x10Watts < 0) { + if (x10Watts <= 0) { // keep the battery voltage updating the filter getInputVoltageX10(getSettingValue(SettingsOptions::VoltageDiv), sample); return 0; From 6c3666e29721a02ce2e5c903a977f8558640b6e5 Mon Sep 17 00:00:00 2001 From: d-rez Date: Fri, 24 Jun 2022 19:49:24 +1000 Subject: [PATCH 02/19] Update translation_PL.json (#1320) Corrected the definition of QCMaxVoltage which was previously mentioning power and wattage rather than QC voltage as it should --- Translations/translation_PL.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Translations/translation_PL.json b/Translations/translation_PL.json index 1ab7c532..de373430 100644 --- a/Translations/translation_PL.json +++ b/Translations/translation_PL.json @@ -132,8 +132,8 @@ "desc": "Szybkość przewijania tekstu" }, "QCMaxVoltage": { - "text2": ["Moc", "w W"], - "desc": "Moc używanego zasilacza w (W)" + "text2": ["QC", "napięcie"], + "desc": "Maksymalne napięcie, które lutownica będzie próbowała wynegocjować z ładowarką Quick Charge (V)" }, "PDNegTimeout": { "text2": ["Limit czasu", "PD"], From 0a69f5c9633032b0ca6e07450656c8351c00610e Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" <5425387+Ralim@users.noreply.github.com> Date: Wed, 29 Jun 2022 09:20:09 +1000 Subject: [PATCH 03/19] Adding features table (#1318) Update README.md --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index e8b1bbdf..c41f7b98 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,15 @@ This project is considered feature complete for use as a soldering iron, _so ple _This firmware does **NOT** support the USB port while running for changing settings. This is done through the onscreen menu only. Logos are edited using the tool or python script and uploaded in DFU mode._ + +| Device | DC Supported | QC Supported | PD Supported | Reccomended | +|--------: |:------------: |:------------: |:------------: |:-----------: | +| MHP30 | N | N | Y | Y | +| Pinecil | Y | Y | Y | Y | +| TS100 | Y | N | N | N | +| TS80 | N | Y | N | N | +| TS80P | N | Y | Y | Y | + ## Getting Started To get started with IronOS firmware, please jump to [Getting Started Guide](Documentation/GettingStarted.md). From 81d679e468b0f68ad9da7c0df0818a7e221cfdb0 Mon Sep 17 00:00:00 2001 From: HanaO00 <17810985+HanaO00@users.noreply.github.com> Date: Fri, 1 Jul 2022 01:21:14 +0200 Subject: [PATCH 04/19] Update translation_FR.json (#1322) --- Translations/translation_FR.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Translations/translation_FR.json b/Translations/translation_FR.json index 37c7d0e3..310bd703 100644 --- a/Translations/translation_FR.json +++ b/Translations/translation_FR.json @@ -80,8 +80,8 @@ "desc": "Délai avant mise en veille (s=secondes | m=minutes)" }, "ShutdownTimeout": { - "text2": ["Délai", "extinction"], - "desc": "Délai avant extinction (m=minutes)" + "text2": ["Délai", "arrêt"], + "desc": "Délai avant l'arrêt du fer à souder (m=minutes)" }, "MotionSensitivity": { "text2": ["Sensibilité", "au mouvement"], @@ -136,7 +136,7 @@ "desc": "Tension maximale désirée avec une alimentation QC" }, "PDNegTimeout": { - "text2": ["Délai", "expiration PD"], + "text2": ["Délai", "expir. PD"], "desc": "Délai de la negociation PD par étapes de 100ms pour la compatiblité avec certains chargeurs QC" }, "PowerLimit": { @@ -156,17 +156,17 @@ "desc": "Incrément de changement de température sur appui long" }, "PowerPulsePower": { - "text2": ["Puissance des", "impulsions"], + "text2": ["Puissance", "impulsions"], "desc": "Puissance des impulsions pour éviter la mise en veille des batteries (watts)" }, - "LockingMode": { - "text2": ["Verrouiller", "les boutons"], - "desc": "Pendant la soudure, appuyer sur les deux boutons pour les verrouiller (D=désactivé | B=boost seulement | V=verr. total)" - }, "HallEffSensitivity": { "text2": ["Sensibilité", "capteur effet hall"], "desc": "Sensibilité du capteur à effet Hall pour la mise en veille (0=désactivé | 1=peu sensible | ... | 9=très sensible)" }, + "LockingMode": { + "text2": ["Verrouiller", "les boutons"], + "desc": "Pendant la soudure, appuyer sur les deux boutons pour les verrouiller (D=désactivé | B=boost seulement | V=verr. total)" + }, "MinVolCell": { "text2": ["Tension", "minimale"], "desc": "Tension minimale autorisée par cellule (3S: 3 - 3.7V | 4-6S: 2.4 - 3.7V)" @@ -193,15 +193,15 @@ }, "Brightness": { "text2": ["Luminosité", "de l'écran"], - "desc": "Ajuster le contraste/luminosité de l'écran OLED" + "desc": "Ajuster la luminosité de l'écran OLED" }, "ColourInversion": { "text2": ["Inverser", "les couleurs"], "desc": "Inverser les couleurs de l'écran OLED" }, "LOGOTime": { - "text2": ["Boot logo", "duration"], - "desc": "Sets the duration for the boot logo (s=seconds)" + "text2": ["Durée logo", "au démarrage"], + "desc": "Définit la durée d'affichage du logo au démarrage (s=secondes)" } } } From b5cb42740e4dfbf93ce5d6b6412a191667bc7ceb Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" <5425387+Ralim@users.noreply.github.com> Date: Sun, 3 Jul 2022 11:59:12 +1000 Subject: [PATCH 05/19] Update version.h --- source/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/version.h b/source/version.h index 2d4e10b1..54f6b508 100644 --- a/source/version.h +++ b/source/version.h @@ -4,4 +4,4 @@ * i.e.: BUILD_VERSION = 'Rel. v2.08' --> Will generated to: 'v2.08.1a2b3c4' */ -#define BUILD_VERSION "v2.18" +#define BUILD_VERSION "v2.19" From 8db0bbf4a5d6b48c995861d9bbbf4765968da525 Mon Sep 17 00:00:00 2001 From: discip <53649486+discip@users.noreply.github.com> Date: Wed, 6 Jul 2022 05:23:06 +0200 Subject: [PATCH 06/19] more obvious feature list (#1325) --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c41f7b98..b319730d 100644 --- a/README.md +++ b/README.md @@ -23,11 +23,11 @@ _This firmware does **NOT** support the USB port while running for changing sett | Device | DC Supported | QC Supported | PD Supported | Reccomended | |--------: |:------------: |:------------: |:------------: |:-----------: | -| MHP30 | N | N | Y | Y | -| Pinecil | Y | Y | Y | Y | -| TS100 | Y | N | N | N | -| TS80 | N | Y | N | N | -| TS80P | N | Y | Y | Y | +| MHP30 | ❌ | ❌ | ✔️ | ✔️ | +| Pinecil | ✔️ | ✔️ | ✔️ | ✔️ | +| TS100 | ✔️ | ❌ | ❌ | ❌ | +| TS80 | ❌ | ✔️ | ❌ | ❌ | +| TS80P | ❌ | ✔️ | ✔️ | ✔️ | ## Getting Started From aac42199f6857f04a61314850aa7ccef0429f058 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Mon, 18 Jul 2022 22:54:56 +1000 Subject: [PATCH 07/19] getTipResistanceX10() --- source/Core/BSP/BSP_Power.h | 3 +++ source/Core/BSP/MHP30/Power.cpp | 2 ++ source/Core/BSP/Miniware/BSP.cpp | 2 ++ source/Core/BSP/Pine64/BSP.cpp | 2 ++ source/Core/Src/power.cpp | 2 +- 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/source/Core/BSP/BSP_Power.h b/source/Core/BSP/BSP_Power.h index a924a1ec..386ffc74 100644 --- a/source/Core/BSP/BSP_Power.h +++ b/source/Core/BSP/BSP_Power.h @@ -16,6 +16,9 @@ extern "C" { // Can be used to check any details for the power system void power_check(); +// Return the tip resistance in x10 ohms (8.5 -> 85) +uint8_t getTipResistanceX10(); + #ifdef __cplusplus } #endif diff --git a/source/Core/BSP/MHP30/Power.cpp b/source/Core/BSP/MHP30/Power.cpp index 661a4bb4..5b508ada 100644 --- a/source/Core/BSP/MHP30/Power.cpp +++ b/source/Core/BSP/MHP30/Power.cpp @@ -17,3 +17,5 @@ void power_check() { } bool getIsPoweredByDCIN() { return false; } + +uint8_t getTipResistanceX10() { return TIP_RESISTANCE; } \ No newline at end of file diff --git a/source/Core/BSP/Miniware/BSP.cpp b/source/Core/BSP/Miniware/BSP.cpp index 2e86af22..cb7d5248 100644 --- a/source/Core/BSP/Miniware/BSP.cpp +++ b/source/Core/BSP/Miniware/BSP.cpp @@ -288,3 +288,5 @@ uint64_t getDeviceID() { // return HAL_GetUIDw0() | ((uint64_t)HAL_GetUIDw1() << 32); } + +uint8_t getTipResistanceX10() { return TIP_RESISTANCE; } \ No newline at end of file diff --git a/source/Core/BSP/Pine64/BSP.cpp b/source/Core/BSP/Pine64/BSP.cpp index 3b8df2eb..0b84339e 100644 --- a/source/Core/BSP/Pine64/BSP.cpp +++ b/source/Core/BSP/Pine64/BSP.cpp @@ -93,3 +93,5 @@ void setStatusLED(const enum StatusLED state) {} uint8_t preStartChecks() { return 0; } uint64_t getDeviceID() { return dbg_id_get(); } + +uint8_t getTipResistanceX10() { return TIP_RESISTANCE; } \ No newline at end of file diff --git a/source/Core/Src/power.cpp b/source/Core/Src/power.cpp index 2fcc120b..593c4945 100644 --- a/source/Core/Src/power.cpp +++ b/source/Core/Src/power.cpp @@ -49,7 +49,7 @@ uint32_t availableW10(uint8_t sample) { // R = R*10 // P therefore is in V^2*100/R*10 = W*10. uint32_t v = getInputVoltageX10(getSettingValue(SettingsOptions::VoltageDiv), sample); // 100 = 10v - uint32_t availableWattsX10 = (v * v) / TIP_RESISTANCE; + uint32_t availableWattsX10 = (v * v) / getTipResistanceX10(); // However, 100% duty cycle is not possible as there is a dead time while the ADC takes a reading // Therefore need to scale available milliwats by this From 0590f9b3f8e2019e2ff2bc40c35c351946901437 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Mon, 18 Jul 2022 22:55:01 +1000 Subject: [PATCH 08/19] Update usb-pd --- source/Core/Drivers/usb-pd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Core/Drivers/usb-pd b/source/Core/Drivers/usb-pd index b3859826..d05b069f 160000 --- a/source/Core/Drivers/usb-pd +++ b/source/Core/Drivers/usb-pd @@ -1 +1 @@ -Subproject commit b38598261df4f705bcbd37cdd5dcccfaa5ab7b4a +Subproject commit d05b069ff6a4d0d21c0bd8905274ab1ffd5ac3dd From 77af6223a448f82d1bf5bf66a72189fb1724a425 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Mon, 18 Jul 2022 22:58:01 +1000 Subject: [PATCH 09/19] Merge in draft EPR --- source/Core/Drivers/USBPD.cpp | 269 ++++++++++++++++++++++++---------- source/Core/Drivers/USBPD.h | 23 ++- 2 files changed, 202 insertions(+), 90 deletions(-) diff --git a/source/Core/Drivers/USBPD.cpp b/source/Core/Drivers/USBPD.cpp index 4d01e055..2111bf32 100644 --- a/source/Core/Drivers/USBPD.cpp +++ b/source/Core/Drivers/USBPD.cpp @@ -12,9 +12,6 @@ #ifndef USB_PD_VMAX #error Max PD Voltage must be defined #endif -#ifndef TIP_RESISTANCE -#error Tip resistance must be defined -#endif void ms_delay(uint32_t delayms) { // Convert ms -> ticks @@ -28,8 +25,9 @@ uint32_t get_ms_timestamp() { } bool pdbs_dpm_evaluate_capability(const pd_msg *capabilities, pd_msg *request); void pdbs_dpm_get_sink_capability(pd_msg *cap, const bool isPD3); +bool EPREvaluateCapabilityFunc(const epr_pd_msg *capabilities, pd_msg *request); FUSB302 fusb((0x22 << 1), fusb_read_buf, fusb_write_buf, ms_delay); // Create FUSB driver -PolicyEngine pe(fusb, get_ms_timestamp, ms_delay, pdbs_dpm_get_sink_capability, pdbs_dpm_evaluate_capability); +PolicyEngine pe(fusb, get_ms_timestamp, ms_delay, pdbs_dpm_get_sink_capability, pdbs_dpm_evaluate_capability, EPREvaluateCapabilityFunc, 140); int USBPowerDelivery::detectionState = 0; uint16_t requested_voltage_mv = 0; @@ -48,10 +46,10 @@ void USBPowerDelivery::IRQOccured() { pe.IRQOccured(); } bool USBPowerDelivery::negotiationHasWorked() { return pe.pdHasNegotiated(); } uint8_t USBPowerDelivery::getStateNumber() { return pe.currentStateCode(true); } void USBPowerDelivery::step() { - while (pe.thread()) {} + while (pe.thread()) {} } -void USBPowerDelivery::PPSTimerCallback() { pe.PPSTimerCallback(); } +void USBPowerDelivery::PPSTimerCallback() { pe.TimersCallback(); } bool USBPowerDelivery::negotiationComplete() { if (!fusbPresent()) { return true; @@ -72,6 +70,10 @@ bool USBPowerDelivery::isVBUSConnected() { if (state) { return state == 1; } + // Dont run if we havent negotiated + if (!negotiationComplete()) { + return true; + } if (fusb.isVBUSConnected()) { state = 1; return true; @@ -80,84 +82,191 @@ bool USBPowerDelivery::isVBUSConnected() { return false; } } -pd_msg lastCapabilities; -pd_msg *USBPowerDelivery::getLastSeenCapabilities() { return &lastCapabilities; } +uint32_t lastCapabilities[11]; +uint32_t *USBPowerDelivery::getLastSeenCapabilities() { return lastCapabilities; } + +#ifdef POW_EPR +static unsigned int sqrtI(unsigned long sqrtArg) { + unsigned int answer, x; + unsigned long temp; + if (sqrtArg == 0) + return 0; // undefined result + if (sqrtArg == 1) + return 1; // identity + answer = 0; // integer square root + for (x = 0x8000; x > 0; x = x >> 1) { // 16 bit shift + answer |= x; // possible bit in root + temp = answer * answer; // + if (temp == sqrtArg) + break; // exact, found it + if (temp > sqrtArg) + answer ^= x; // too large, reverse bit + } + return answer; // approximate root +} +#endif + +// parseCapabilitiesArray returns true if a valid capability was found +// caps is the array of capabilities objects +// best* are output references +bool parseCapabilitiesArray(const uint8_t numCaps, uint8_t *bestIndex, uint16_t *bestVoltage, uint16_t *bestCurrent, bool *bestIsPPS, bool *bestIsAVO) { + // Walk the given capabilities array; and select the best option + // Given assumption of fixed tip resistance; this can be simplified to highest voltage selection + *bestIndex = 0xFF; // Mark unselected + *bestVoltage = 5000; // Default 5V + + // Fudge of 0.5 ohms to round up a little to account for us always having off periods in PWM + uint8_t tipResistance = getTipResistanceX10() + 5; +#ifdef MODEL_HAS_DCDC + // If this device has step down DC/DC inductor to smooth out current spikes + // We can instead ignore resistance and go for max voltage we can accept; and rely on the DC/DC regulation to keep under current limit + tipResistance = 255; // (Push to 25.5 ohms to effectively disable this check) +#endif + + for (uint8_t i = 0; i < numCaps; i++) { + if ((lastCapabilities[i] & PD_PDO_TYPE) == PD_PDO_TYPE_FIXED) { + // This is a fixed PDO entry + // Evaluate if it can produve sufficient current based on the TIP_RESISTANCE (ohms*10) + // V=I*R -> V/I => minimum resistance, if our tip resistance is >= this then we can use this supply + + int voltage_mv = PD_PDV2MV(PD_PDO_SRC_FIXED_VOLTAGE_GET(lastCapabilities[i])); // voltage in mV units + int current_a_x100 = PD_PDO_SRC_FIXED_CURRENT_GET(lastCapabilities[i]); // current in 10mA units + int min_resistance_ohmsx10 = voltage_mv / current_a_x100; + if (voltage_mv <= (USB_PD_VMAX * 1000)) { + if (min_resistance_ohmsx10 <= tipResistance) { + // This is a valid power source we can select as + if (voltage_mv > *bestVoltage) { + // Higher voltage and valid, select this instead + *bestIndex = i; + *bestVoltage = voltage_mv; + *bestCurrent = current_a_x100; + *bestIsPPS = false; + *bestIsAVO = false; + } + } + } + } else if ((lastCapabilities[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED && (((lastCapabilities[i] & PD_APDO_TYPE) == PD_APDO_TYPE_PPS))) { + // If this is a PPS slot, calculate the max voltage in the PPS range that can we be used and maintain + uint16_t max_voltage = PD_PAV2MV(PD_APDO_PPS_MAX_VOLTAGE_GET(lastCapabilities[i])); + // uint16_t min_voltage = PD_PAV2MV(PD_APDO_PPS_MIN_VOLTAGE_GET(lastCapabilities[i])); + uint16_t max_current = PD_PAI2CA(PD_APDO_PPS_CURRENT_GET(lastCapabilities[i])); // max current in 10mA units + // Using the current and tip resistance, calculate the ideal max voltage + // if this is range, then we will work with this voltage + // if this is not in range; then max_voltage can be safely selected + int ideal_voltage_mv = (tipResistance * max_current); + if (ideal_voltage_mv > max_voltage) { + ideal_voltage_mv = max_voltage; // constrain to what this PDO offers + } + if (ideal_voltage_mv > 20000) { + ideal_voltage_mv = 20000; // Limit to 20V as some advertise 21 but are not stable at 21 + } + if (ideal_voltage_mv > (USB_PD_VMAX * 1000)) { + ideal_voltage_mv = (USB_PD_VMAX * 1000); // constrain to model max voltage safe to select + } + if (ideal_voltage_mv > *bestVoltage) { + *bestIndex = i; + *bestVoltage = ideal_voltage_mv; + *bestCurrent = max_current; + *bestIsPPS = true; + *bestIsAVO = false; + } + } +#ifdef POW_EPR + else if ((lastCapabilities[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED && (((lastCapabilities[i] & PD_APDO_TYPE) == PD_APDO_TYPE_AVS))) { + *bestIsAVO = true; + uint16_t max_voltage = PD_PAV2MV(PD_APDO_AVS_MAX_VOLTAGE_GET(lastCapabilities[i])); + uint8_t max_wattage = PD_APDO_AVS_MAX_POWER_GET(lastCapabilities[i]); + + // W = v^2/tip_resistance => Wattage*tip_resistance == Max_voltage^2 + auto ideal_max_voltage = sqrtI((max_wattage * tipResistance) / 10) * 1000; + if (ideal_max_voltage > (USB_PD_VMAX * 1000)) { + ideal_max_voltage = (USB_PD_VMAX * 1000); // constrain to model max voltage safe to select + } + if (ideal_max_voltage > (max_voltage)) { + ideal_max_voltage = (max_voltage); // constrain to model max voltage safe to select + } + auto operating_current = (ideal_max_voltage / tipResistance); // Current in centiamps + + if (ideal_max_voltage > *bestVoltage) { + *bestIndex = i; + *bestVoltage = ideal_max_voltage; + *bestCurrent = operating_current; + *bestIsAVO = true; + } + } +#endif + } + // Now that the best index is known, set the current values + return *bestIndex != 0xFF; // have we selected one +} + +bool EPREvaluateCapabilityFunc(const epr_pd_msg *capabilities, pd_msg *request) { +#ifdef POW_EPR + // Select any EPR slots up to USB_PD_VMAX + memset(lastCapabilities, 0, sizeof(lastCapabilities)); + memcpy(lastCapabilities, capabilities->obj, sizeof(lastCapabilities)); + // PDO slots 1-7 shall be the standard PDO's + // PDO slots 8-11 shall be the >20V slots + uint8_t numobj = 11; + uint8_t bestIndex = 0xFF; + uint16_t bestIndexVoltage = 0; + uint16_t bestIndexCurrent = 0; + bool bestIsPPS = false; + bool bestIsAVO = false; + + if (parseCapabilitiesArray(numobj, &bestIndex, &bestIndexVoltage, &bestIndexCurrent, &bestIsPPS, &bestIsAVO)) { + /* We got what we wanted, so build a request for that */ + request->hdr = PD_MSGTYPE_EPR_REQUEST | PD_NUMOBJ(2); + request->obj[1] = lastCapabilities[bestIndex]; // Copy PDO into slot 2 + + if (bestIsAVO) { + request->obj[0] = PD_RDO_PROG_CURRENT_SET(PD_CA2PAI(bestIndexCurrent)) | PD_RDO_PROG_VOLTAGE_SET(PD_MV2APS(bestIndexVoltage)) | PD_RDO_NO_USB_SUSPEND | PD_RDO_OBJPOS_SET(bestIndex + 1); + } else if (bestIsPPS) { + request->obj[0] = PD_RDO_PROG_CURRENT_SET(PD_CA2PAI(bestIndexCurrent)) | PD_RDO_PROG_VOLTAGE_SET(PD_MV2PRV(bestIndexVoltage)) | PD_RDO_NO_USB_SUSPEND | PD_RDO_OBJPOS_SET(bestIndex + 1); + } else { + request->obj[0] = PD_RDO_FV_MAX_CURRENT_SET(bestIndexCurrent) | PD_RDO_FV_CURRENT_SET(bestIndexCurrent) | PD_RDO_NO_USB_SUSPEND | PD_RDO_OBJPOS_SET(bestIndex + 1); + } + request->obj[0] |= PD_RDO_EPR_CAPABLE; + + // We dont do usb + // request->obj[0] |= PD_RDO_USB_COMMS; + + /* Update requested voltage */ + requested_voltage_mv = bestIndexVoltage; + powerSupplyWattageLimit = bestIndexVoltage * bestIndexCurrent / 100 / 1000; // Set watts for limit from PSU limit + + } else { + /* Nothing matched (or no configuration), so get 5 V at low current */ + request->hdr = PD_MSGTYPE_EPR_REQUEST | PD_NUMOBJ(2); + request->obj[1] = lastCapabilities[0]; + request->obj[0] = PD_RDO_FV_MAX_CURRENT_SET(100) | PD_RDO_FV_CURRENT_SET(100) | PD_RDO_NO_USB_SUSPEND | PD_RDO_OBJPOS_SET(1); + // We dont do usb + // request->obj[0] |= PD_RDO_USB_COMMS; + + /* Update requested voltage */ + requested_voltage_mv = 5000; + } + return true; +#endif + return false; +} bool pdbs_dpm_evaluate_capability(const pd_msg *capabilities, pd_msg *request) { - memcpy(&lastCapabilities, capabilities, sizeof(pd_msg)); + memset(lastCapabilities, 0, sizeof(lastCapabilities)); + memcpy(lastCapabilities, capabilities->obj, sizeof(uint32_t) * 7); /* Get the number of PDOs */ uint8_t numobj = PD_NUMOBJ_GET(capabilities); /* Make sure we have configuration */ /* Look at the PDOs to see if one matches our desires */ // Look against USB_PD_Desired_Levels to select in order of preference - uint8_t bestIndex = 0xFF; - int bestIndexVoltage = 0; - int bestIndexCurrent = 0; - bool bestIsPPS = false; - powerSupplyWattageLimit = 0; - for (uint8_t i = 0; i < numobj; i++) { - /* If we have a fixed PDO, its V equals our desired V, and its I is - * at least our desired I */ - if ((capabilities->obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_FIXED) { - // This is a fixed PDO entry - // Evaluate if it can produve sufficient current based on the TIP_RESISTANCE (ohms*10) - // V=I*R -> V/I => minimum resistance, if our tip resistance is >= this then we can use this supply + uint8_t bestIndex = 0xFF; + uint16_t bestIndexVoltage = 0; + uint16_t bestIndexCurrent = 0; + bool bestIsPPS = false; + bool bestIsAVO = false; - int voltage_mv = PD_PDV2MV(PD_PDO_SRC_FIXED_VOLTAGE_GET(capabilities->obj[i])); // voltage in mV units - int current_a_x100 = PD_PDO_SRC_FIXED_CURRENT_GET(capabilities->obj[i]); // current in 10mA units - int min_resistance_ohmsx10 = voltage_mv / current_a_x100; - if (voltage_mv <= (USB_PD_VMAX * 1000)) { -#ifdef MODEL_HAS_DCDC - // If this device has step down DC/DC inductor to smooth out current spikes - // We can instead ignore resistance and go for max voltage we can accept - min_resistance_ohmsx10 = TIP_RESISTANCE; -#endif - // Fudge of 0.5 ohms to round up a little to account for other losses - if (min_resistance_ohmsx10 <= (TIP_RESISTANCE + 5)) { - // This is a valid power source we can select as - if ((voltage_mv > bestIndexVoltage) || bestIndex == 0xFF) { - // Higher voltage and valid, select this instead - bestIndex = i; - bestIndexVoltage = voltage_mv; - bestIndexCurrent = current_a_x100; - bestIsPPS = false; -#ifdef MODEL_HAS_DCDC - // set limiter for wattage - powerSupplyWattageLimit = ((voltage_mv * current_a_x100) / 100 / 1000); -#endif - } - } - } - } else if ((capabilities->obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED && (capabilities->obj[i] & PD_APDO_TYPE) == PD_APDO_TYPE_PPS) { - // If this is a PPS slot, calculate the max voltage in the PPS range that can we be used and maintain - uint16_t max_voltage = PD_PAV2MV(PD_APDO_PPS_MAX_VOLTAGE_GET(capabilities->obj[i])); - // uint16_t min_voltage = PD_PAV2MV(PD_APDO_PPS_MIN_VOLTAGE_GET(capabilities->obj[i])); - uint16_t max_current = PD_PAI2CA(PD_APDO_PPS_CURRENT_GET(capabilities->obj[i])); // max current in 10mA units - // Using the current and tip resistance, calculate the ideal max voltage - // if this is range, then we will work with this voltage - // if this is not in range; then max_voltage can be safely selected - int ideal_voltage_mv = (TIP_RESISTANCE * max_current); - if (ideal_voltage_mv > max_voltage) { - ideal_voltage_mv = max_voltage; // constrain - } - if (ideal_voltage_mv > (USB_PD_VMAX * 1000)) { - ideal_voltage_mv = (USB_PD_VMAX * 1000); // constrain to model max - } - if (ideal_voltage_mv > bestIndexVoltage || bestIndex == 0xFF) { - bestIndex = i; - bestIndexVoltage = ideal_voltage_mv; - bestIndexCurrent = max_current; - bestIsPPS = true; -#ifdef MODEL_HAS_DCDC - // set limiter for wattage - powerSupplyWattageLimit = ((ideal_voltage_mv * max_current) / 100 / 1000); -#endif - } - } - } - - if (bestIndex != 0xFF) { + if (parseCapabilitiesArray(numobj, &bestIndex, &bestIndexVoltage, &bestIndexCurrent, &bestIsPPS, &bestIsAVO)) { /* We got what we wanted, so build a request for that */ request->hdr = PD_MSGTYPE_REQUEST | PD_NUMOBJ(1); if (bestIsPPS) { @@ -167,14 +276,18 @@ bool pdbs_dpm_evaluate_capability(const pd_msg *capabilities, pd_msg *request) { } // We dont do usb // request->obj[0] |= PD_RDO_USB_COMMS; +#ifdef POW_EPR + request->obj[0] |= PD_RDO_EPR_CAPABLE; +#endif /* Update requested voltage */ - requested_voltage_mv = bestIndexVoltage; + requested_voltage_mv = bestIndexVoltage; + powerSupplyWattageLimit = bestIndexVoltage * bestIndexCurrent / 100 / 1000; // Set watts for limit from PSU limit } else { /* Nothing matched (or no configuration), so get 5 V at low current */ request->hdr = PD_MSGTYPE_REQUEST | PD_NUMOBJ(1); - request->obj[0] = PD_RDO_FV_MAX_CURRENT_SET(DPM_MIN_CURRENT) | PD_RDO_FV_CURRENT_SET(DPM_MIN_CURRENT) | PD_RDO_NO_USB_SUSPEND | PD_RDO_OBJPOS_SET(1); + request->obj[0] = PD_RDO_FV_MAX_CURRENT_SET(100) | PD_RDO_FV_CURRENT_SET(100) | PD_RDO_NO_USB_SUSPEND | PD_RDO_OBJPOS_SET(1); // We dont do usb // request->obj[0] |= PD_RDO_USB_COMMS; @@ -199,7 +312,7 @@ void pdbs_dpm_get_sink_capability(pd_msg *cap, const bool isPD3) { // if (requested_voltage_mv != 5000) { // voltage = requested_voltage_mv; // } - // uint16_t current = (voltage) / TIP_RESISTANCE; // In centi-amps + // uint16_t current = (voltage) / getTipResistanceX10(); // In centi-amps // /* Add a PDO for the desired power. */ // cap->obj[numobj++] = PD_PDO_TYPE_FIXED | PD_PDO_SNK_FIXED_VOLTAGE_SET(PD_MV2PDV(voltage)) | PD_PDO_SNK_FIXED_CURRENT_SET(current); diff --git a/source/Core/Drivers/USBPD.h b/source/Core/Drivers/USBPD.h index 50013e24..2afa9b31 100644 --- a/source/Core/Drivers/USBPD.h +++ b/source/Core/Drivers/USBPD.h @@ -2,7 +2,6 @@ #ifndef DRIVERS_USBPD_H_ #define DRIVERS_USBPD_H_ #include "configuration.h" -#include "pdb_msg.h" #include #include @@ -10,17 +9,17 @@ #if POW_PD class USBPowerDelivery { public: - static bool start(); // Start the PD stack - static bool negotiationComplete(); // Has negotiation completed to a voltage > 5v - static bool negotiationInProgress(); // Is negotiation ongoing - static bool fusbPresent(); // Is the FUSB302 present on the bus - static void PPSTimerCallback(); // PPS Timer - static void IRQOccured(); // Thread callback that an irq occured - static void step(); // Iterate the step machine - static bool negotiationHasWorked(); // Has PD negotiation worked (are we in a PD contract) - static uint8_t getStateNumber(); // Debugging - Get the internal state number - static bool isVBUSConnected(); // Is the VBus pin connected on the FUSB302 - static pd_msg *getLastSeenCapabilities(); // returns pointer to the last seen capabilities from the powersource + static bool start(); // Start the PD stack + static bool negotiationComplete(); // Has negotiation completed to a voltage > 5v + static bool negotiationInProgress(); // Is negotiation ongoing + static bool fusbPresent(); // Is the FUSB302 present on the bus + static void PPSTimerCallback(); // PPS Timer + static void IRQOccured(); // Thread callback that an irq occured + static void step(); // Iterate the step machine + static bool negotiationHasWorked(); // Has PD negotiation worked (are we in a PD contract) + static uint8_t getStateNumber(); // Debugging - Get the internal state number + static bool isVBUSConnected(); // Is the VBus pin connected on the FUSB302 + static uint32_t *getLastSeenCapabilities(); // returns pointer to the last seen capabilities from the powersource private: // static int detectionState; From 7166dd1f33424ebc0b76496b19988114467c8d7f Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Mon, 18 Jul 2022 22:59:51 +1000 Subject: [PATCH 10/19] Update PD debug to be EPR aware --- source/Core/Threads/GUIThread.cpp | 67 +++++++++++++++++++------------ 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/source/Core/Threads/GUIThread.cpp b/source/Core/Threads/GUIThread.cpp index d0a863fc..327e947a 100644 --- a/source/Core/Threads/GUIThread.cpp +++ b/source/Core/Threads/GUIThread.cpp @@ -42,7 +42,7 @@ void showWarnings(); #define BUTTON_INACTIVITY_TIME (60 * configTICK_RATE_HZ) static TickType_t lastHallEffectSleepStart = 0; static uint16_t min(uint16_t a, uint16_t b) { - if (a > b) + if (a > b) return b; else return a; @@ -840,35 +840,50 @@ static void showPDDebug(void) { } } else { // Print out the Proposed power options one by one - auto lastCaps = USBPowerDelivery::getLastSeenCapabilities(); - uint8_t numobj = PD_NUMOBJ_GET(lastCaps); - if ((screen - 1) < numobj) { + auto lastCaps = USBPowerDelivery::getLastSeenCapabilities(); + if ((screen - 1) < 11) { int voltage_mv = 0; int min_voltage = 0; int current_a_x100 = 0; - if ((lastCaps->obj[screen - 1] & PD_PDO_TYPE) == PD_PDO_TYPE_FIXED) { - voltage_mv = PD_PDV2MV(PD_PDO_SRC_FIXED_VOLTAGE_GET(lastCaps->obj[screen - 1])); // voltage in mV units - current_a_x100 = PD_PDO_SRC_FIXED_CURRENT_GET(lastCaps->obj[screen - 1]); // current in 10mA units - } else { - voltage_mv = PD_PAV2MV(PD_APDO_PPS_MAX_VOLTAGE_GET(lastCaps->obj[screen - 1])); - min_voltage = PD_PAV2MV(PD_APDO_PPS_MIN_VOLTAGE_GET(lastCaps->obj[screen - 1])); - current_a_x100 = PD_PAI2CA(PD_APDO_PPS_CURRENT_GET(lastCaps->obj[screen - 1])); // max current in 10mA units - } - // print out this entry of the proposal - OLED::printNumber(screen, 1, FontStyle::SMALL, true); // print the entry number - OLED::print(SymbolSpace, FontStyle::SMALL); - if (min_voltage > 0) { - OLED::printNumber(min_voltage / 1000, 2, FontStyle::SMALL, true); // print the voltage - OLED::print(SymbolMinus, FontStyle::SMALL); - } - OLED::printNumber(voltage_mv / 1000, 2, FontStyle::SMALL, true); // print the voltage - OLED::print(SymbolVolts, FontStyle::SMALL); - OLED::print(SymbolSpace, FontStyle::SMALL); - OLED::printNumber(current_a_x100 / 100, 2, FontStyle::SMALL, true); // print the current in 0.1A res - OLED::print(SymbolDot, FontStyle::SMALL); - OLED::printNumber(current_a_x100 % 100, 2, FontStyle::SMALL, true); // print the current in 0.1A res - OLED::print(SymbolAmps, FontStyle::SMALL); + int wattage = 0; + if ((lastCaps[screen - 1] & PD_PDO_TYPE) == PD_PDO_TYPE_FIXED) { + voltage_mv = PD_PDV2MV(PD_PDO_SRC_FIXED_VOLTAGE_GET(lastCaps[screen - 1])); // voltage in mV units + current_a_x100 = PD_PDO_SRC_FIXED_CURRENT_GET(lastCaps[screen - 1]); // current in 10mA units + } else if ((lastCaps[screen - 1] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED) { + voltage_mv = PD_PAV2MV(PD_APDO_AVS_MAX_VOLTAGE_GET(lastCaps[screen - 1])); + min_voltage = PD_PAV2MV(PD_APDO_PPS_MIN_VOLTAGE_GET(lastCaps[screen - 1])); + // Last value is wattage + wattage = PD_APDO_AVS_MAX_POWER_GET(lastCaps[screen - 1]); + } else { + voltage_mv = PD_PAV2MV(PD_APDO_PPS_MAX_VOLTAGE_GET(lastCaps[screen - 1])); + min_voltage = PD_PAV2MV(PD_APDO_PPS_MIN_VOLTAGE_GET(lastCaps[screen - 1])); + current_a_x100 = PD_PAI2CA(PD_APDO_PPS_CURRENT_GET(lastCaps[screen - 1])); // max current in 10mA units + } + // Skip not used entries + if (voltage_mv == 0) { + screen++; + } else { + // print out this entry of the proposal + OLED::printNumber(screen, 2, FontStyle::SMALL, true); // print the entry number + OLED::print(SymbolSpace, FontStyle::SMALL); + if (min_voltage > 0) { + OLED::printNumber(min_voltage / 1000, 2, FontStyle::SMALL, true); // print the voltage + OLED::print(SymbolMinus, FontStyle::SMALL); + } + OLED::printNumber(voltage_mv / 1000, 2, FontStyle::SMALL, true); // print the voltage + OLED::print(SymbolVolts, FontStyle::SMALL); + OLED::print(SymbolSpace, FontStyle::SMALL); + if (wattage) { + OLED::printNumber(wattage, 3, FontStyle::SMALL, true); // print the current in 0.1A res + OLED::print(SymbolWatts, FontStyle::SMALL); + } else { + OLED::printNumber(current_a_x100 / 100, 2, FontStyle::SMALL, true); // print the current in 0.1A res + OLED::print(SymbolDot, FontStyle::SMALL); + OLED::printNumber(current_a_x100 % 100, 2, FontStyle::SMALL, true); // print the current in 0.1A res + OLED::print(SymbolAmps, FontStyle::SMALL); + } + } } else { screen = 0; } From 086e4664a66cb9b338830f8a023d6d6f60f3cee6 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" <5425387+Ralim@users.noreply.github.com> Date: Tue, 19 Jul 2022 11:22:01 +1000 Subject: [PATCH 11/19] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index b319730d..a5afe657 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,9 @@ _This firmware does **NOT** support the USB port while running for changing sett | TS80 | ❌ | ✔️ | ❌ | ❌ | | TS80P | ❌ | ✔️ | ✔️ | ✔️ | +Please note that Miniware have started to ship TS100's using cloned STM32 Chips. While these do work with IronOS, their DFU bootloader works terribly and it is hard to get it to successfully flash larger firmware images like IronOS without timing out. + + ## Getting Started To get started with IronOS firmware, please jump to [Getting Started Guide](Documentation/GettingStarted.md). From 6a05439da50f5c2940da6d2581acf7d629e36bfd Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" <5425387+Ralim@users.noreply.github.com> Date: Tue, 19 Jul 2022 11:22:34 +1000 Subject: [PATCH 12/19] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a5afe657..c431650a 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ _This firmware does **NOT** support the USB port while running for changing sett | TS80 | ❌ | ✔️ | ❌ | ❌ | | TS80P | ❌ | ✔️ | ✔️ | ✔️ | -Please note that Miniware have started to ship TS100's using cloned STM32 Chips. While these do work with IronOS, their DFU bootloader works terribly and it is hard to get it to successfully flash larger firmware images like IronOS without timing out. +Please note that Miniware have started to ship TS100's using cloned STM32 Chips. While these do work with IronOS, their DFU bootloader works terribly and it is hard to get it to successfully flash larger firmware images like IronOS without timing out. THis is the main reason why the TS100 is _no longer reccomended_. ## Getting Started From c89a6d855c8de22fcfb5df33395f8321dbd6c5c6 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Tue, 19 Jul 2022 20:58:47 +1000 Subject: [PATCH 13/19] Update usb-pd --- source/Core/Drivers/usb-pd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Core/Drivers/usb-pd b/source/Core/Drivers/usb-pd index d05b069f..c5876074 160000 --- a/source/Core/Drivers/usb-pd +++ b/source/Core/Drivers/usb-pd @@ -1 +1 @@ -Subproject commit d05b069ff6a4d0d21c0bd8905274ab1ffd5ac3dd +Subproject commit c587607419803cc573614684419fb5374f9bbad4 From 6d6f42d242ff39cdce17850bb0bface0fac1e548 Mon Sep 17 00:00:00 2001 From: nyanpasu64 Date: Sun, 24 Jul 2022 15:12:27 -0700 Subject: [PATCH 14/19] Cleanup getButtonState() --- source/Core/Drivers/Buttons.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/source/Core/Drivers/Buttons.cpp b/source/Core/Drivers/Buttons.cpp index 3875ed96..b7111373 100644 --- a/source/Core/Drivers/Buttons.cpp +++ b/source/Core/Drivers/Buttons.cpp @@ -50,14 +50,10 @@ ButtonState getButtonState() { ButtonState retVal = BUTTON_NONE; if (currentState) { // User has pressed a button down (nothing done on down) - if (currentState != previousState) { - // There has been a change in the button states - // If there is a rising edge on one of the buttons from double press we - // want to mask that out As users are having issues with not release - // both at once - if (previousState == 0x03) - currentState = 0x03; - } + // If there is a rising edge on one of the buttons from double press we + // want to mask that out As users are having issues with not release + // both at once + previousState |= currentState; } else { // User has released buttons // If they previously had the buttons down we want to check if they were < @@ -73,8 +69,8 @@ ButtonState getButtonState() { else retVal = BUTTON_BOTH; // Both being held case } + previousState = 0; } - previousState = currentState; previousStateChange = xTaskGetTickCount(); return retVal; } From c855f4cffea349d887bd08afb1a9e2290038f0fe Mon Sep 17 00:00:00 2001 From: nyanpasu64 Date: Sun, 24 Jul 2022 15:16:11 -0700 Subject: [PATCH 15/19] Don't send short-presses after releasing long-presses --- source/Core/Drivers/Buttons.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/Core/Drivers/Buttons.cpp b/source/Core/Drivers/Buttons.cpp index b7111373..885a0b50 100644 --- a/source/Core/Drivers/Buttons.cpp +++ b/source/Core/Drivers/Buttons.cpp @@ -23,6 +23,7 @@ ButtonState getButtonState() { * (downtime>filter) */ static uint8_t previousState = 0; + static bool longPressed = false; static uint32_t previousStateChange = 0; const uint16_t timeout = TICKS_100MS * 4; uint8_t currentState; @@ -34,9 +35,10 @@ ButtonState getButtonState() { if (currentState == previousState) { if (currentState == 0) return BUTTON_NONE; - if ((xTaskGetTickCount() - previousStateChange) > timeout) { + if ((xTaskGetTickCount() - previousStateChange) >= timeout) { // User has been holding the button down // We want to send a button is held message + longPressed = true; if (currentState == 0x01) return BUTTON_F_LONG; else if (currentState == 0x02) @@ -58,7 +60,7 @@ ButtonState getButtonState() { // User has released buttons // If they previously had the buttons down we want to check if they were < // long hold and trigger a press - if ((xTaskGetTickCount() - previousStateChange) < timeout) { + if ((xTaskGetTickCount() - previousStateChange) < timeout && !longPressed) { // The user didn't hold the button for long // So we send button press @@ -70,6 +72,7 @@ ButtonState getButtonState() { retVal = BUTTON_BOTH; // Both being held case } previousState = 0; + longPressed = false; } previousStateChange = xTaskGetTickCount(); return retVal; From 06e3ca59ea82826176904fde88bd48d4a33905e5 Mon Sep 17 00:00:00 2001 From: nyanpasu64 Date: Sun, 24 Jul 2022 15:34:39 -0700 Subject: [PATCH 16/19] Fix button presses between short and long being ignored entirely --- source/Core/Drivers/Buttons.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Core/Drivers/Buttons.cpp b/source/Core/Drivers/Buttons.cpp index 885a0b50..247e47f1 100644 --- a/source/Core/Drivers/Buttons.cpp +++ b/source/Core/Drivers/Buttons.cpp @@ -60,7 +60,7 @@ ButtonState getButtonState() { // User has released buttons // If they previously had the buttons down we want to check if they were < // long hold and trigger a press - if ((xTaskGetTickCount() - previousStateChange) < timeout && !longPressed) { + if (!longPressed) { // The user didn't hold the button for long // So we send button press From 138e3260da9b21ba7bab4aa0cca0b569fc292f6a Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Mon, 25 Jul 2022 16:41:57 +1000 Subject: [PATCH 17/19] Update portmacro.h --- .../Vendor/OS/FreeRTOS/Source/portable/GCC/portmacro.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/source/Core/BSP/Pine64/Vendor/OS/FreeRTOS/Source/portable/GCC/portmacro.h b/source/Core/BSP/Pine64/Vendor/OS/FreeRTOS/Source/portable/GCC/portmacro.h index b2911fcd..f73dacf6 100644 --- a/source/Core/BSP/Pine64/Vendor/OS/FreeRTOS/Source/portable/GCC/portmacro.h +++ b/source/Core/BSP/Pine64/Vendor/OS/FreeRTOS/Source/portable/GCC/portmacro.h @@ -58,14 +58,9 @@ typedef portSTACK_TYPE StackType_t; typedef long BaseType_t; typedef unsigned long UBaseType_t; -#if (configUSE_16_BIT_TICKS == 1) -typedef uint16_t TickType_t; -#define portMAX_DELAY (TickType_t)0xffff -#else /* RISC-V TIMER is 64-bit long */ typedef uint64_t TickType_t; #define portMAX_DELAY (TickType_t)0xFFFFFFFFFFFFFFFFULL -#endif /*-----------------------------------------------------------*/ /* Architecture specifics. */ From dd239375b1e1daa157d3c1aa186654801eac818e Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Mon, 25 Jul 2022 16:42:16 +1000 Subject: [PATCH 18/19] All Ticks as the right TickType Update usb-pd --- source/Core/Drivers/Buttons.cpp | 12 ++++++------ source/Core/Drivers/Buttons.hpp | 6 +++--- source/Core/Drivers/OLED.cpp | 10 +++++----- source/Core/Inc/ScrollMessage.hpp | 8 ++++---- source/Core/Src/ScrollMessage.cpp | 2 +- source/Core/Threads/GUIThread.cpp | 8 ++++---- source/Core/Threads/PIDThread.cpp | 6 +++--- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/source/Core/Drivers/Buttons.cpp b/source/Core/Drivers/Buttons.cpp index 3875ed96..eec5a5f8 100644 --- a/source/Core/Drivers/Buttons.cpp +++ b/source/Core/Drivers/Buttons.cpp @@ -8,7 +8,7 @@ #include "settingsGUI.hpp" #include "task.h" #include -uint32_t lastButtonTime = 0; +TickType_t lastButtonTime = 0; ButtonState getButtonState() { /* @@ -22,10 +22,10 @@ ButtonState getButtonState() { * press (buttons still down), or if release we trigger press * (downtime>filter) */ - static uint8_t previousState = 0; - static uint32_t previousStateChange = 0; - const uint16_t timeout = TICKS_100MS * 4; - uint8_t currentState; + static uint8_t previousState = 0; + static TickType_t previousStateChange = 0; + const TickType_t timeout = TICKS_100MS * 4; + uint8_t currentState; currentState = (getButtonA()) << 0; currentState |= (getButtonB()) << 1; @@ -95,7 +95,7 @@ void waitForButtonPress() { } } -void waitForButtonPressOrTimeout(uint32_t timeout) { +void waitForButtonPressOrTimeout(TickType_t timeout) { timeout += xTaskGetTickCount(); // calculate the exit point diff --git a/source/Core/Drivers/Buttons.hpp b/source/Core/Drivers/Buttons.hpp index 1aab1f3c..2e421118 100644 --- a/source/Core/Drivers/Buttons.hpp +++ b/source/Core/Drivers/Buttons.hpp @@ -7,8 +7,8 @@ #include "BSP.h" #ifndef INC_BUTTONS_H_ #define INC_BUTTONS_H_ - -extern uint32_t lastButtonTime; +#include "portmacro.h" +extern TickType_t lastButtonTime; enum ButtonState { BUTTON_NONE = 0, /* No buttons pressed / < filter time*/ @@ -29,7 +29,7 @@ enum ButtonState { // Returns what buttons are pressed (if any) ButtonState getButtonState(); // Helpers -void waitForButtonPressOrTimeout(uint32_t timeout); +void waitForButtonPressOrTimeout(TickType_t timeout); void waitForButtonPress(); #endif /* INC_BUTTONS_H_ */ diff --git a/source/Core/Drivers/OLED.cpp b/source/Core/Drivers/OLED.cpp index ab436e0e..0832c48f 100644 --- a/source/Core/Drivers/OLED.cpp +++ b/source/Core/Drivers/OLED.cpp @@ -221,7 +221,7 @@ void OLED::maskScrollIndicatorOnOLED() { // it from the screen buffer which is updated by `OLED::setRotation`. uint8_t rightmostColumn = screenBuffer[7]; uint8_t maskCommands[] = { - // Set column address: + // Set column address: // A[6:0] - Column start address = rightmost column // B[6:0] - Column end address = rightmost column 0x80, @@ -252,10 +252,10 @@ void OLED::transitionSecondaryFramebuffer(bool forwardNavigation) { uint8_t *firstBackStripPtr = &secondFrameBuffer[0]; uint8_t *secondBackStripPtr = &secondFrameBuffer[OLED_WIDTH]; - uint32_t totalDuration = TICKS_100MS * 5; // 500ms - uint32_t duration = 0; - uint32_t start = xTaskGetTickCount(); - uint8_t offset = 0; + TickType_t totalDuration = TICKS_100MS * 5; // 500ms + TickType_t duration = 0; + TickType_t start = xTaskGetTickCount(); + uint8_t offset = 0; while (duration <= totalDuration) { duration = xTaskGetTickCount() - start; diff --git a/source/Core/Inc/ScrollMessage.hpp b/source/Core/Inc/ScrollMessage.hpp index 3bce9aaf..3f97fdb9 100644 --- a/source/Core/Inc/ScrollMessage.hpp +++ b/source/Core/Inc/ScrollMessage.hpp @@ -1,14 +1,14 @@ #ifndef SCROLL_MESSAGE_HPP_ #define SCROLL_MESSAGE_HPP_ +#include "portmacro.h" #include - /** * A helper class for showing a full-screen scrolling message. */ class ScrollMessage { - uint32_t messageStart = 0; - int16_t lastOffset = -1; + TickType_t messageStart = 0; + int16_t lastOffset = -1; /** * Calcualte the width in pixels of the message string, in the large @@ -47,7 +47,7 @@ public: * @param currentTick The current tick as returned by `xTaskGetTickCount()`. * @return Whether the OLED framebuffer has been modified. */ - bool drawUpdate(const char *message, uint32_t currentTick); + bool drawUpdate(const char *message, TickType_t currentTick); }; #endif /* SCROLL_MESSAGE_HPP_ */ diff --git a/source/Core/Src/ScrollMessage.cpp b/source/Core/Src/ScrollMessage.cpp index 88bebfb7..d63cede3 100644 --- a/source/Core/Src/ScrollMessage.cpp +++ b/source/Core/Src/ScrollMessage.cpp @@ -30,7 +30,7 @@ static uint16_t str_display_len(const char *const str) { uint16_t ScrollMessage::messageWidth(const char *message) { return FONT_12_WIDTH * str_display_len(message); } -bool ScrollMessage::drawUpdate(const char *message, uint32_t currentTick) { +bool ScrollMessage::drawUpdate(const char *message, TickType_t currentTick) { bool lcdRefresh = false; if (messageStart == 0) { diff --git a/source/Core/Threads/GUIThread.cpp b/source/Core/Threads/GUIThread.cpp index d0a863fc..719f77ea 100644 --- a/source/Core/Threads/GUIThread.cpp +++ b/source/Core/Threads/GUIThread.cpp @@ -42,7 +42,7 @@ void showWarnings(); #define BUTTON_INACTIVITY_TIME (60 * configTICK_RATE_HZ) static TickType_t lastHallEffectSleepStart = 0; static uint16_t min(uint16_t a, uint16_t b) { - if (a > b) + if (a > b) return b; else return a; @@ -171,9 +171,9 @@ static void gui_drawBatteryIcon() { #endif } static void gui_solderingTempAdjust() { - uint32_t lastChange = xTaskGetTickCount(); + TickType_t lastChange = xTaskGetTickCount(); currentTempTargetDegC = 0; // Turn off header while adjusting temp - uint32_t autoRepeatTimer = 0; + TickType_t autoRepeatTimer = 0; uint8_t autoRepeatAcceleration = 0; bool waitForRelease = false; ButtonState buttons = getButtonState(); @@ -370,7 +370,7 @@ static void display_countdown(int sleepThres) { * Print seconds or minutes (if > 99 seconds) until sleep * mode is triggered. */ - int lastEventTime = lastButtonTime < lastMovementTime ? lastMovementTime : lastButtonTime; + TickType_t lastEventTime = lastButtonTime < lastMovementTime ? lastMovementTime : lastButtonTime; TickType_t downCount = sleepThres - xTaskGetTickCount() + lastEventTime; if (downCount > (99 * TICKS_SECOND)) { OLED::printNumber(downCount / 60000 + 1, 2, FontStyle::SMALL); diff --git a/source/Core/Threads/PIDThread.cpp b/source/Core/Threads/PIDThread.cpp index 7df72fc5..4b3c9704 100644 --- a/source/Core/Threads/PIDThread.cpp +++ b/source/Core/Threads/PIDThread.cpp @@ -17,7 +17,7 @@ static TickType_t powerPulseWaitUnit = 25 * TICKS_100MS; // 2.5 s static TickType_t powerPulseDurationUnit = (5 * TICKS_100MS) / 2; // 250 ms TaskHandle_t pidTaskNotification = NULL; -volatile uint32_t currentTempTargetDegC = 0; // Current temperature target in C +volatile uint32_t currentTempTargetDegC = 0; // Current temperature target in C int32_t powerSupplyWattageLimit = 0; bool heaterThermalRunaway = false; @@ -114,8 +114,8 @@ int32_t getPIDResultX10Watts(int32_t setpointDelta) { static TickType_t lastCall = 0; static Integrator powerStore = {0}; - const int rate = 1000 / (xTaskGetTickCount() - lastCall); - lastCall = xTaskGetTickCount(); + const TickType_t rate = 1000 / (xTaskGetTickCount() - lastCall); + lastCall = xTaskGetTickCount(); // Sandman note: // PID Challenge - we have a small thermal mass that we to want heat up as fast as possible but we don't // want to overshot excessively (if at all) the setpoint temperature. In the same time we have 'imprecise' From d47a627b1aaa19e08ab4968d42cf3936259e8677 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Mon, 25 Jul 2022 16:56:37 +1000 Subject: [PATCH 19/19] Update portmacro --- source/Core/BSP/MHP30/portmacro.h | 3 ++- source/Core/BSP/Miniware/FreeRTOSConfig.h | 2 +- source/Core/BSP/Miniware/portmacro.h | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/source/Core/BSP/MHP30/portmacro.h b/source/Core/BSP/MHP30/portmacro.h index 16d5242c..f6bf700c 100644 --- a/source/Core/BSP/MHP30/portmacro.h +++ b/source/Core/BSP/MHP30/portmacro.h @@ -27,7 +27,8 @@ #ifndef PORTMACRO_H #define PORTMACRO_H - +#include "FreeRTOSConfig.h" +#include "projdefs.h" #ifdef __cplusplus extern "C" { #endif diff --git a/source/Core/BSP/Miniware/FreeRTOSConfig.h b/source/Core/BSP/Miniware/FreeRTOSConfig.h index dd95674e..ed690c09 100644 --- a/source/Core/BSP/Miniware/FreeRTOSConfig.h +++ b/source/Core/BSP/Miniware/FreeRTOSConfig.h @@ -100,7 +100,7 @@ extern uint32_t SystemCoreClock; #define configUSE_IDLE_HOOK 1 #define configUSE_TICK_HOOK 0 #define configCPU_CLOCK_HZ (SystemCoreClock) -#define configTICK_RATE_HZ ((TickType_t)1000) +#define configTICK_RATE_HZ (1000) #define configMAX_PRIORITIES (6) #define configMINIMAL_STACK_SIZE ((uint16_t)256) #define configTOTAL_HEAP_SIZE ((size_t)1024 * 14) /*Currently use about 9000*/ diff --git a/source/Core/BSP/Miniware/portmacro.h b/source/Core/BSP/Miniware/portmacro.h index 16d5242c..85fe3b13 100644 --- a/source/Core/BSP/Miniware/portmacro.h +++ b/source/Core/BSP/Miniware/portmacro.h @@ -27,6 +27,8 @@ #ifndef PORTMACRO_H #define PORTMACRO_H +#include "FreeRTOSConfig.h" +#include "projdefs.h" #ifdef __cplusplus extern "C" {