aboutsummaryrefslogtreecommitdiffhomepage
path: root/source/Core/Drivers
diff options
context:
space:
mode:
authorBen V. Brown <[email protected]>2024-06-01 16:36:34 +1000
committerGitHub <[email protected]>2024-06-01 16:36:34 +1000
commit442dbd982e83fc1872d638acac952047e03b72e8 (patch)
tree198539247b4a1ffc6a5fff9fb63f6a2231b9778a /source/Core/Drivers
parentc135732ebbce2a630c7715696268566fce9a84a1 (diff)
downloadIronOS-442dbd982e83fc1872d638acac952047e03b72e8.tar.gz
IronOS-442dbd982e83fc1872d638acac952047e03b72e8.zip
Expand USB-PD mode option (#1917)
* Use PDMode to decide if we do resistance pad * Rename PDVpdo to USBPDMode * Add options for PD Mode * OLED: Allow soft line-wrap x position * Add new translation option for menu settings values * Use new setting value for PD Mode * Update translations for new menu setting * Fixup! S60 * black python
Diffstat (limited to 'source/Core/Drivers')
-rw-r--r--source/Core/Drivers/FS2711.cpp5
-rw-r--r--source/Core/Drivers/OLED.cpp12
-rw-r--r--source/Core/Drivers/OLED.hpp9
-rw-r--r--source/Core/Drivers/USBPD.cpp7
-rw-r--r--source/Core/Drivers/Utils.cpp5
5 files changed, 22 insertions, 16 deletions
diff --git a/source/Core/Drivers/FS2711.cpp b/source/Core/Drivers/FS2711.cpp
index 9b192d03..1aec92e8 100644
--- a/source/Core/Drivers/FS2711.cpp
+++ b/source/Core/Drivers/FS2711.cpp
@@ -157,7 +157,10 @@ void FS2711::negotiate() {
// FS2711 uses mV instead of V
const uint16_t vmax = USB_PD_VMAX * 1000;
- const uint8_t tip_resistance = getTipResistanceX10() + 5;
+ uint8_t tip_resistance = getTipResistanceX10();
+ if (getSettingValue(SettingsOptions::USBPDMode) == 1) {
+ tip_resistance += 5;
+ }
uint16_t pdo_min_mv = 0, pdo_max_mv = 0, pdo_max_curr = 0, pdo_type = 0;
diff --git a/source/Core/Drivers/OLED.cpp b/source/Core/Drivers/OLED.cpp
index d8f046d1..76742890 100644
--- a/source/Core/Drivers/OLED.cpp
+++ b/source/Core/Drivers/OLED.cpp
@@ -160,7 +160,7 @@ void OLED::setFramebuffer(uint8_t *buffer) {
* UTF font handling is done using the two input chars.
* Precursor is the command char that is used to select the table.
*/
-void OLED::drawChar(const uint16_t charCode, const FontStyle fontStyle) {
+void OLED::drawChar(const uint16_t charCode, const FontStyle fontStyle, const uint8_t soft_x_limit) {
const uint8_t *currentFont;
static uint8_t fontWidth, fontHeight;
uint16_t index;
@@ -175,7 +175,7 @@ void OLED::drawChar(const uint16_t charCode, const FontStyle fontStyle) {
case FontStyle::LARGE:
default:
if (charCode == '\x01' && cursor_y == 0) { // 0x01 is used as new line char
- setCursor(0, 8);
+ setCursor(soft_x_limit, 8);
return;
} else if (charCode <= 0x01) {
return;
@@ -505,7 +505,7 @@ void OLED::setInverseDisplay(bool inverse) {
}
// print a string to the current cursor location, len chars MAX
-void OLED::print(const char *const str, FontStyle fontStyle, uint8_t len) {
+void OLED::print(const char *const str, FontStyle fontStyle, uint8_t len, const uint8_t soft_x_limit) {
const uint8_t *next = reinterpret_cast<const uint8_t *>(str);
if (next[0] == 0x01) {
fontStyle = FontStyle::LARGE;
@@ -523,7 +523,7 @@ void OLED::print(const char *const str, FontStyle fontStyle, uint8_t len) {
index = (next[0] - 0xF0) * 0xFF - 15 + next[1];
next += 2;
}
- drawChar(index, fontStyle);
+ drawChar(index, fontStyle, soft_x_limit);
}
}
@@ -580,7 +580,7 @@ void OLED::drawHex(uint32_t x, FontStyle fontStyle, uint8_t digits) {
// print number to hex
for (uint_fast8_t i = 0; i < digits; i++) {
uint16_t value = (x >> (4 * (7 - i))) & 0b1111;
- drawChar(value + 2, fontStyle);
+ drawChar(value + 2, fontStyle, 0);
}
}
@@ -635,7 +635,7 @@ void OLED::debugNumber(int32_t val, FontStyle fontStyle) {
void OLED::drawSymbol(uint8_t symbolID) {
// draw a symbol to the current cursor location
- drawChar(symbolID, FontStyle::EXTRAS);
+ drawChar(symbolID, FontStyle::EXTRAS, 0);
}
// Draw an area, but y must be aligned on 0/8 offset
diff --git a/source/Core/Drivers/OLED.hpp b/source/Core/Drivers/OLED.hpp
index 40811948..65bf8e58 100644
--- a/source/Core/Drivers/OLED.hpp
+++ b/source/Core/Drivers/OLED.hpp
@@ -78,10 +78,7 @@ enum class FontStyle {
class OLED {
public:
- enum DisplayState : bool {
- OFF = false,
- ON = true
- };
+ enum DisplayState : bool { OFF = false, ON = true };
static void initialize(); // Startup the I2C coms (brings screen out of reset etc)
static bool isInitDone();
@@ -120,7 +117,7 @@ public:
static void setInverseDisplay(bool inverted);
static int16_t getCursorX() { return cursor_x; }
// Draw a string to the current location, with selected font; optionally - with MAX length only
- static void print(const char *string, FontStyle fontStyle, uint8_t length = 255);
+ static void print(const char *string, FontStyle fontStyle, uint8_t length = 255, const uint8_t soft_x_limit = 0);
static void printWholeScreen(const char *string);
// Print *F or *C - in font style of Small, Large (by default) or Extra based on input arg
static void printSymbolDeg(FontStyle fontStyle = FontStyle::LARGE);
@@ -166,7 +163,7 @@ private:
displayChecksum = hash;
return result;
}
- static void drawChar(uint16_t charCode, FontStyle fontStyle); // Draw a character to the current cursor location
+ static void drawChar(uint16_t charCode, FontStyle fontStyle, const uint8_t soft_x_limit); // Draw a character to the current cursor location
static void setFramebuffer(uint8_t *buffer);
static uint8_t *stripPointers[4]; // Pointers to the strips to allow for buffer having extra content
static bool inLeftHandedMode; // Whether the screen is in left or not (used for offsets in GRAM)
diff --git a/source/Core/Drivers/USBPD.cpp b/source/Core/Drivers/USBPD.cpp
index 5e114d16..1f154080 100644
--- a/source/Core/Drivers/USBPD.cpp
+++ b/source/Core/Drivers/USBPD.cpp
@@ -135,7 +135,10 @@ bool parseCapabilitiesArray(const uint8_t numCaps, uint8_t *bestIndex, uint16_t
*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;
+ uint8_t tipResistance = getTipResistanceX10();
+ if (getSettingValue(SettingsOptions::USBPDMode) == 1) {
+ tipResistance += 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
@@ -167,7 +170,7 @@ bool parseCapabilitiesArray(const uint8_t numCaps, uint8_t *bestIndex, uint16_t
}
}
}
- } else if ((lastCapabilities[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED && getSettingValue(SettingsOptions::PDVpdo)) {
+ } else if ((lastCapabilities[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED && getSettingValue(SettingsOptions::USBPDMode)) {
bool sourceIsEPRCapable = lastCapabilities[0] & PD_PDO_SRC_FIXED_EPR_CAPABLE;
bool isPPS = false;
bool isAVS = false;
diff --git a/source/Core/Drivers/Utils.cpp b/source/Core/Drivers/Utils.cpp
index b65922f3..b560fd3a 100644
--- a/source/Core/Drivers/Utils.cpp
+++ b/source/Core/Drivers/Utils.cpp
@@ -22,7 +22,10 @@ int32_t Utils::InterpolateLookupTable(const int32_t *lookupTable, const int noIt
int32_t Utils::LinearInterpolate(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x) { return y1 + (((((x - x1) * 1000) / (x2 - x1)) * (y2 - y1))) / 1000; }
uint16_t Utils::RequiredCurrentForTipAtVoltage(uint16_t voltageX10) {
- uint8_t tipResistancex10 = getTipResistanceX10() + 5;
+ uint8_t tipResistancex10 = getTipResistanceX10();
+ if (getSettingValue(SettingsOptions::USBPDMode) == 1) {
+ tipResistancex10 += 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