1
0
forked from me/IronOS

USB-PD Support for Sequre S60P (#1883)

* Basic Init

* Rought implementation of fs2711 usb pd interface

* Rought implementation of fs2711 usb pd interface

* Still needs work overcurrent protection keeps getting tripped

* New pdo selection logic

* Update push.yml

* Update push.yml

* Update push.yml

* Update Makefile

* Adds PPS

* Removed unused define

* Adds PPS

* Apply suggestions from code review

Co-authored-by: Ben V. Brown <5425387+Ralim@users.noreply.github.com>

* Code review changes

* Added osDelay include

* New line alignment for S60 softwarei2c

* Code review

* Fixes code review stuff

* code review changes

* Change voltage limit to 20 as that's what the device is rated for

* Shortened wait time for usb pd

* Fixed issues that cuase S60P to restart constantly

* fixing minimal OLED brightness

With the current settings, the OLED turns off if the first level is selected.

* Adds protocol to s60p debug menu

* loosened fs2711 protocol selection timing

* Adds PDO register reading to negotiation logic

* Fixes FS2711 timeout issue and cleans up driver

* Adds FS2711 protocol negotiation to power loop

* Removed uneeded define

* Reverts changes to Font.h and adds clang-format comments

---------

Co-authored-by: Ben V. Brown <Ralim@Ralimtek.com>
Co-authored-by: discip <53649486+discip@users.noreply.github.com>
Co-authored-by: Ben V. Brown <5425387+Ralim@users.noreply.github.com>
This commit is contained in:
Arturo
2024-02-25 05:04:48 -06:00
committed by GitHub
parent 9f6f2f86ff
commit 9ea71bc4d2
12 changed files with 507 additions and 14 deletions

View File

@@ -1,3 +1,4 @@
#include "FS2711.hpp"
#include "HUB238.hpp"
#include "OperatingModes.h"
OperatingMode showWarnings(const ButtonState buttons, guiContext *cxt) {
@@ -80,9 +81,25 @@ OperatingMode showWarnings(const ButtonState buttons, guiContext *cxt) {
} else {
cxt->scratch_state.state1 = 4;
}
#else
#if POW_PD_EXT == 2
if (!FS2711::probe()) {
if (getSettingValue(SettingsOptions::PDMissingWarningCounter) < 2) {
if (warnUser(translatedString(Tr->NoPowerDeliveryMessage), buttons)) {
cxt->scratch_state.state1 = 4;
nextSettingValue(SettingsOptions::PDMissingWarningCounter);
saveSettings();
}
} else {
cxt->scratch_state.state1 = 4;
}
} else {
cxt->scratch_state.state1 = 4;
}
#else
cxt->scratch_state.state1 = 4;
#endif /*POW_PD_EXT==1*/
#endif /*POW_PD_EXT==2*/
#endif /*POW_PD*/
break;

View File

@@ -0,0 +1,81 @@
#include "FS2711.hpp"
#include "OperatingModes.h"
#include "stdbool.h"
#if POW_PD_EXT == 2
#ifdef HAS_POWER_DEBUG_MENU
OperatingMode showPDDebug(const ButtonState buttons, guiContext *cxt) {
// Print out the USB-PD state
// Basically this is like the Debug menu, but instead we want to print out the PD status
uint8_t screen = 0;
ButtonState b;
for (;;) {
OLED::clearScreen(); // Ensure the buffer starts clean
OLED::setCursor(0, 0); // Position the cursor at the 0,0 (top left)
OLED::print(SmallSymbolPDDebug, FontStyle::SMALL); // Print Title
OLED::setCursor(0, 8); // second line
if (screen > 7) {
screen = 0;
}
if (screen == 0) {
// Print the PD Debug state
OLED::print(SmallSymbolState, FontStyle::SMALL);
OLED::print(SmallSymbolSpace, FontStyle::SMALL);
fs2711_state_t state = FS2711::debug_get_state();
OLED::printNumber(state.pdo_num, 1, FontStyle::SMALL);
OLED::print(SmallSymbolSpace, FontStyle::SMALL);
// OLED::drawHex(state.req_pdo_num, FontStyle::SMALL, 4);
OLED::printNumber(state.req_pdo_num > 7 ? 0 : state.req_pdo_num + 1, 1, FontStyle::SMALL, true);
OLED::print(SmallSymbolSpace, FontStyle::SMALL);
uint8_t protocol = FS2711::selected_protocol();
OLED::printNumber(protocol, 2, FontStyle::SMALL);
OLED::print(SmallSymbolSpace, FontStyle::SMALL);
} else {
// Print out the Proposed power options one by one
uint16_t max_voltage = FS2711::debug_pdo_max_voltage(screen - 1);
if (max_voltage == 0) {
screen += 1;
} else {
uint16_t min_voltage = FS2711::debug_pdo_min_voltage(screen - 1);
uint16_t current = FS2711::debug_pdo_source_current(screen - 1);
uint16_t pdo_type = FS2711::debug_pdo_type(screen - 1);
OLED::printNumber(screen, 1, FontStyle::SMALL, true);
OLED::print(SmallSymbolSpace, FontStyle::SMALL);
if (pdo_type == 1) {
OLED::printNumber(min_voltage / 1000, 2, FontStyle::SMALL, true);
OLED::print(SmallSymbolMinus, FontStyle::SMALL);
OLED::printNumber(max_voltage / 1000, 2, FontStyle::SMALL, false);
} else {
OLED::printNumber(max_voltage / 1000, 2, FontStyle::SMALL, true);
}
OLED::print(SmallSymbolVolts, FontStyle::SMALL);
OLED::print(SmallSymbolSpace, FontStyle::SMALL);
OLED::printNumber(current / 1000, 2, FontStyle::SMALL, true);
OLED::print(SmallSymbolDot, FontStyle::SMALL);
OLED::printNumber(current % 1000, 1, FontStyle::SMALL, false);
OLED::print(SmallSymbolAmps, FontStyle::SMALL);
// OLED::printNumber(currentx100 % 100, 2, FontStyle::SMALL, true);
}
}
OLED::refresh();
b = getButtonState();
if (b == BUTTON_B_SHORT) {
return OperatingMode::InitialisationDone;
} else if (b == BUTTON_F_SHORT) {
screen++;
}
GUIDelay();
}
return OperatingMode::UsbPDDebug;
}
#endif
#endif

View File

@@ -6,6 +6,7 @@
*/
#include "BSP.h"
#include "FS2711.hpp"
#include "FreeRTOS.h"
#include "HUB238.hpp"
#include "QC3.h"
@@ -14,6 +15,7 @@
#include "cmsis_os.h"
#include "configuration.h"
#include "main.hpp"
#include "stdbool.h"
#include "stdlib.h"
#include "task.h"
@@ -32,8 +34,12 @@ void startPOWTask(void const *argument __unused) {
USBPowerDelivery::start();
// Crank the handle at boot until we are stable and waiting for IRQ
USBPowerDelivery::step();
#endif
#if POW_PD_EXT == 2
FS2711::start();
FS2711::negotiate();
#endif
BaseType_t res;
for (;;) {
res = pdFALSE;
@@ -60,6 +66,9 @@ void startPOWTask(void const *argument __unused) {
#endif
#if POW_PD_EXT == 1
hub238_check_negotiation();
#endif
#if POW_PD_EXT == 2
FS2711::negotiate();
#endif
power_check();
}