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

@@ -2,6 +2,7 @@
#include "BSP.h"
#include "BootLogo.h"
#include "FS2711.hpp"
#include "HUB238.hpp"
#include "I2C_Wrapper.hpp"
#include "Pins.h"
@@ -210,13 +211,23 @@ bool isTipDisconnected() {
void setStatusLED(const enum StatusLED state) {}
uint8_t preStartChecks() {
#if POW_PD_EXT == 1
if (!hub238_has_run_selection() && (xTaskGetTickCount() < TICKS_SECOND * 5)) {
return 0;
}
// We check if we are in a "Limited" mode; where we have to run the PWM really fast
// Where as if we are on 9V for example, the tip resistance is enough
uint16_t voltage = hub238_source_voltage();
uint16_t currentx100 = hub238_source_currentX100();
uint16_t voltage = hub238_source_voltage();
uint16_t currentx100 = hub238_source_currentX100();
#endif
#if POW_PD_EXT == 2
if (!FS2711::has_run_selection() && (xTaskGetTickCount() < TICKS_SECOND * 5)) {
return 0;
}
uint16_t voltage = FS2711::source_voltage();
uint16_t currentx100 = FS2711::source_currentx100();
#endif
uint16_t thresholdResistancex10 = ((voltage * 1000) / currentx100) + 5;
if (getTipResistanceX10() <= thresholdResistancex10) {

View File

@@ -40,7 +40,6 @@
#endif
#ifdef MODEL_S60P
#define KEY_B_Pin GPIO_PIN_1

View File

@@ -18,12 +18,14 @@
#define SOFT_SDA2_LOW() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_RESET)
#define SOFT_SDA2_READ() (HAL_GPIO_ReadPin(SDA2_GPIO_Port, SDA2_Pin) == GPIO_PIN_SET ? 1 : 0)
#define SOFT_SCL2_READ() (HAL_GPIO_ReadPin(SCL2_GPIO_Port, SCL2_Pin) == GPIO_PIN_SET ? 1 : 0)
// clang-format off
#define SOFT_I2C_DELAY() \
{ \
for (int xx = 0; xx < 12; xx++) { \
asm("nop"); \
} \
}
// clang-format on
#endif
// 40 ~= 100kHz; 15 gives around 250kHz or so which is fast _and_ stable

View File

@@ -24,8 +24,8 @@
* OLED Brightness
*
*/
#define MIN_BRIGHTNESS 0 // Min OLED brightness selectable
#define MAX_BRIGHTNESS 100 // Max OLED brightness selectable
#define MIN_BRIGHTNESS 1 // Min OLED brightness selectable
#define MAX_BRIGHTNESS 101 // Max OLED brightness selectable
#define BRIGHTNESS_STEP 25 // OLED brightness increment
#define DEFAULT_BRIGHTNESS 25 // default OLED brightness
@@ -166,7 +166,6 @@
#define MODEL_HAS_DCDC // We dont have DC/DC but have reallly fast PWM that gets us roughly the same place
#endif /* S60 */
#ifdef MODEL_S60P
#define VOLTAGE_DIV 460 // Default divider scaler
#define CALIBRATION_OFFSET 200 // Default adc offset in uV
@@ -176,7 +175,7 @@
#define POWER_LIMIT_STEPS 5
#define OP_AMP_GAIN_STAGE 536
#define TEMP_uV_LOOKUP_S60
#define USB_PD_VMAX 12 // Maximum voltage for PD to negotiate
#define USB_PD_VMAX 20 // Maximum voltage for PD to negotiate
#define HARDWARE_MAX_WATTAGE_X10 600
@@ -187,7 +186,7 @@
#define OLED_128x32
#define GPIO_VIBRATION
#define POW_PD_EXT 1
#define POW_PD_EXT 2
#define USB_PD_EPR_WATTAGE 0 /*No EPR*/
#define DEBUG_POWER_MENU_BUTTON_B 1
#define HAS_POWER_DEBUG_MENU
@@ -197,6 +196,7 @@
#define MODEL_HAS_DCDC // We dont have DC/DC but have reallly fast PWM that gets us roughly the same place
#endif /* S60P */
#define FLASH_LOGOADDR (0x08000000 + (62 * 1024))
#define SETTINGS_START_PAGE (0x08000000 + (63 * 1024))