From 5f2a604215723b10827647ce8e73a7d1c0daff07 Mon Sep 17 00:00:00 2001 From: Ivan Zorin Date: Mon, 8 Jul 2024 23:51:41 +0300 Subject: [PATCH 1/2] Add enum for USB PD modes --- source/Core/Drivers/FS2711.cpp | 2 +- source/Core/Drivers/USBPD.cpp | 2 +- source/Core/Drivers/Utils.cpp | 4 ++-- source/Core/Inc/Settings.h | 6 ++++++ source/Core/Src/settingsGUI.cpp | 13 +++++++------ 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/source/Core/Drivers/FS2711.cpp b/source/Core/Drivers/FS2711.cpp index 1aec92e80d..35e90898a6 100644 --- a/source/Core/Drivers/FS2711.cpp +++ b/source/Core/Drivers/FS2711.cpp @@ -158,7 +158,7 @@ void FS2711::negotiate() { // FS2711 uses mV instead of V const uint16_t vmax = USB_PD_VMAX * 1000; uint8_t tip_resistance = getTipResistanceX10(); - if (getSettingValue(SettingsOptions::USBPDMode) == 1) { + if (getSettingValue(SettingsOptions::USBPDMode) == usbpdMode_t::DEFAULT) { tip_resistance += 5; } diff --git a/source/Core/Drivers/USBPD.cpp b/source/Core/Drivers/USBPD.cpp index 1f154080a4..6c21f5ed5d 100644 --- a/source/Core/Drivers/USBPD.cpp +++ b/source/Core/Drivers/USBPD.cpp @@ -136,7 +136,7 @@ bool parseCapabilitiesArray(const uint8_t numCaps, uint8_t *bestIndex, uint16_t // Fudge of 0.5 ohms to round up a little to account for us always having off periods in PWM uint8_t tipResistance = getTipResistanceX10(); - if (getSettingValue(SettingsOptions::USBPDMode) == 1) { + if (getSettingValue(SettingsOptions::USBPDMode) == usbpdMode_t::DEFAULT) { tipResistance += 5; } #ifdef MODEL_HAS_DCDC diff --git a/source/Core/Drivers/Utils.cpp b/source/Core/Drivers/Utils.cpp index b560fd3a40..20f8c46faa 100644 --- a/source/Core/Drivers/Utils.cpp +++ b/source/Core/Drivers/Utils.cpp @@ -23,7 +23,7 @@ int32_t Utils::LinearInterpolate(int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint16_t Utils::RequiredCurrentForTipAtVoltage(uint16_t voltageX10) { uint8_t tipResistancex10 = getTipResistanceX10(); - if (getSettingValue(SettingsOptions::USBPDMode) == 1) { + if (getSettingValue(SettingsOptions::USBPDMode) == usbpdMode_t::DEFAULT) { tipResistancex10 += 5; } #ifdef MODEL_HAS_DCDC @@ -34,4 +34,4 @@ uint16_t Utils::RequiredCurrentForTipAtVoltage(uint16_t voltageX10) { // V/R = I uint16_t currentX10 = (voltageX10 * 10) / tipResistancex10; return currentX10; -} \ No newline at end of file +} diff --git a/source/Core/Inc/Settings.h b/source/Core/Inc/Settings.h index e9bddfaf07..7cef208f4e 100644 --- a/source/Core/Inc/Settings.h +++ b/source/Core/Inc/Settings.h @@ -104,6 +104,12 @@ typedef enum { INFINITY = 6, // Show boot logo on repeat (if animated) until a button toggled } logoMode_t; +typedef enum { + DEFAULT = 1, // PPS + EPR + more power request through increasing resistance by 0.5 Ohm + SAFE = 2, // PPS + EPR, without requesting more power + NO_DYNAMIC = 0, // Disabled, fixed PDO only +} usbpdMode_t; + // Settings wide operations void saveSettings(); bool loadSettings(); diff --git a/source/Core/Src/settingsGUI.cpp b/source/Core/Src/settingsGUI.cpp index b9ded2853b..5dbabe2ed0 100644 --- a/source/Core/Src/settingsGUI.cpp +++ b/source/Core/Src/settingsGUI.cpp @@ -531,19 +531,20 @@ static void displayPDNegTimeout(void) { static void displayUSBPDMode(void) { /* - * PD Mode - * 0 = Safe mode, no PPS, no EPR - * 1 = Default mode, tolerant + PPS + EPR - * 2 = Strict mode + PPS + EPR + * Supported PD modes: + * DEFAULT, 1 = PPS + EPR + more power request through increasing resistance by 0.5 Ohm + * SAFE, 2 = PPS + EPR, without requesting more power + * NO_DYNAMIC, 0 = Disabled, fixed PDO only */ switch (getSettingValue(SettingsOptions::USBPDMode)) { - case 1: + case usbpdMode_t::DEFAULT: OLED::print(translatedString(Tr->USBPDModeDefault), FontStyle::SMALL, 255, OLED::getCursorX()); break; - case 2: + case usbpdMode_t::SAFE: OLED::print(translatedString(Tr->USBPDModeSafe), FontStyle::SMALL, 255, OLED::getCursorX()); break; + case usbpdMode_t::NO_DYNAMIC: default: OLED::print(translatedString(Tr->USBPDModeNoDynamic), FontStyle::SMALL, 255, OLED::getCursorX()); break; From 4831299ed8aee8f1c6613e8f99082a46bbe74b95 Mon Sep 17 00:00:00 2001 From: Ivan Zorin Date: Tue, 9 Jul 2024 10:19:09 +0300 Subject: [PATCH 2/2] Update comments for clarification according to code review --- source/Core/Inc/Settings.h | 4 ++-- source/Core/Src/settingsGUI.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/Core/Inc/Settings.h b/source/Core/Inc/Settings.h index 7cef208f4e..e84fbd872c 100644 --- a/source/Core/Inc/Settings.h +++ b/source/Core/Inc/Settings.h @@ -105,9 +105,9 @@ typedef enum { } logoMode_t; typedef enum { - DEFAULT = 1, // PPS + EPR + more power request through increasing resistance by 0.5 Ohm + DEFAULT = 1, // PPS + EPR + more power request through increasing resistance by 0.5 Ohm to compensate power loss over cable/PCB/etc. SAFE = 2, // PPS + EPR, without requesting more power - NO_DYNAMIC = 0, // Disabled, fixed PDO only + NO_DYNAMIC = 0, // PPS + EPR disabled, fixed PDO only } usbpdMode_t; // Settings wide operations diff --git a/source/Core/Src/settingsGUI.cpp b/source/Core/Src/settingsGUI.cpp index 5dbabe2ed0..180b8547c1 100644 --- a/source/Core/Src/settingsGUI.cpp +++ b/source/Core/Src/settingsGUI.cpp @@ -532,9 +532,9 @@ static void displayPDNegTimeout(void) { static void displayUSBPDMode(void) { /* * Supported PD modes: - * DEFAULT, 1 = PPS + EPR + more power request through increasing resistance by 0.5 Ohm + * DEFAULT, 1 = PPS + EPR + more power request through increasing resistance by 0.5 Ohm to compensate power loss over cable/PCB/etc. * SAFE, 2 = PPS + EPR, without requesting more power - * NO_DYNAMIC, 0 = Disabled, fixed PDO only + * NO_DYNAMIC, 0 = PPS + EPR disabled, fixed PDO only */ switch (getSettingValue(SettingsOptions::USBPDMode)) {