Skip to content

Commit

Permalink
Add enum for USB PD modes (Ralim#1943)
Browse files Browse the repository at this point in the history
* Add enum for USB PD modes

* Update comments for clarification according to code review
  • Loading branch information
ia authored Jul 9, 2024
1 parent ac6994a commit c19e882
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion source/Core/Drivers/FS2711.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion source/Core/Drivers/USBPD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions source/Core/Drivers/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,4 +34,4 @@ uint16_t Utils::RequiredCurrentForTipAtVoltage(uint16_t voltageX10) {
// V/R = I
uint16_t currentX10 = (voltageX10 * 10) / tipResistancex10;
return currentX10;
}
}
6 changes: 6 additions & 0 deletions source/Core/Inc/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 to compensate power loss over cable/PCB/etc.
SAFE = 2, // PPS + EPR, without requesting more power
NO_DYNAMIC = 0, // PPS + EPR disabled, fixed PDO only
} usbpdMode_t;

// Settings wide operations
void saveSettings();
bool loadSettings();
Expand Down
13 changes: 7 additions & 6 deletions source/Core/Src/settingsGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 to compensate power loss over cable/PCB/etc.
* SAFE, 2 = PPS + EPR, without requesting more power
* NO_DYNAMIC, 0 = PPS + EPR 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;
Expand Down

0 comments on commit c19e882

Please sign in to comment.