This commit is contained in:
jonasius
2025-02-23 19:46:19 +01:00
committed by GitHub
28 changed files with 237 additions and 115 deletions

View File

@@ -4,8 +4,10 @@
#include "BSP.h"
#include "FS2711.hpp"
#include "FS2711_defines.h"
#include "I2CBB1.hpp"
#include "I2CBB2.hpp"
#include "Settings.h"
#include "Utils.h"
#include "cmsis_os.h"
#include <stdbool.h>
#include <stdint.h>
@@ -15,31 +17,61 @@
#error Max PD Voltage must be defined
#endif
#define PROTOCOL_TIMEOUT 100 // ms
extern int32_t powerSupplyWattageLimit;
uint8_t I2C_PORT = 2;
fs2711_state_t FS2711::state;
inline void i2c_write(uint8_t addr, uint8_t data) { I2CBB2::Mem_Write(FS2711_ADDR, addr, &data, 1); }
void i2c_write(uint8_t addr, uint8_t data) {
if (I2C_PORT == 2) {
I2CBB2::Mem_Write(FS2711_ADDR, addr, &data, 1);
} else if (I2C_PORT == 1) {
I2CBB1::Mem_Write(FS2711_ADDR, addr, &data, 1);
}
}
inline uint8_t i2c_read(uint8_t addr) {
uint8_t i2c_read(uint8_t addr) {
uint8_t data = 0;
I2CBB2::Mem_Read(FS2711_ADDR, addr, &data, 1);
if (I2C_PORT == 2) {
I2CBB2::Mem_Read(FS2711_ADDR, addr, &data, 1);
} else if (I2C_PORT == 1) {
I2CBB1::Mem_Read(FS2711_ADDR, addr, &data, 1);
}
return data;
}
inline bool i2c_probe(uint8_t addr) { return I2CBB2::probe(addr); }
bool i2c_probe(uint8_t addr) {
bool probing_state = false;
if (I2C_PORT == 2) {
probing_state = I2CBB2::probe(addr);
} else if (I2C_PORT == 1) {
probing_state = I2CBB1::probe(addr);
}
return probing_state;
}
uint8_t FS2711::detect_i2c_bus_num() {
I2CBB2::probe(88);
I2CBB2::probe(89);
if (I2CBB2::probe(FS2711_ADDR)) {
I2C_PORT = 2;
} else {
I2C_PORT = 1;
}
return I2C_PORT;
}
void FS2711::start() {
memset(&state, 0, sizeof(fs2711_state_t));
state.req_pdo_num = 0xFF;
enable_protocol(false);
osDelay(PROTOCOL_TIMEOUT);
// PDNegTimeout is in 100ms, so x100 for ms
osDelay(getSettingValue(SettingsOptions::PDNegTimeout) * 100);
select_protocol(FS2711_PROTOCOL_PD);
enable_protocol(true);
osDelay(PROTOCOL_TIMEOUT);
osDelay(getSettingValue(SettingsOptions::PDNegTimeout) * 100);
}
uint8_t FS2711::selected_protocol() { return i2c_read(FS2711_REG_SELECT_PROTOCOL); }
@@ -163,6 +195,11 @@ void FS2711::negotiate() {
if (getSettingValue(SettingsOptions::USBPDMode) == usbpdMode_t::DEFAULT) {
tip_resistance += 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
tip_resistance = 255; // (Push to 25.5 ohms to effectively disable this check)
#endif
uint16_t pdo_min_mv = 0, pdo_max_mv = 0, pdo_max_curr = 0, pdo_type = 0;
@@ -228,7 +265,7 @@ bool FS2711::has_run_selection() { return state.req_pdo_num != 0xFF; }
uint16_t FS2711::source_voltage() { return state.source_voltage / 1000; }
// FS2711 does current in mV so it needs to be converted to x100 intead of x1000
// FS2711 does current in mA so it needs to be converted to x100 intead of x1000
uint16_t FS2711::source_currentx100() { return state.source_current / 10; }
uint16_t FS2711::debug_pdo_max_voltage(uint8_t pdoid) { return state.pdo_max_volt[pdoid]; }

View File

@@ -19,6 +19,8 @@ typedef struct {
class FS2711 {
public:
static uint8_t detect_i2c_bus_num();
static bool probe();
static void start();

View File

@@ -93,8 +93,8 @@
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x30, 0x0C, 0x02, 0xF1, 0xF1, 0xF1, 0x02, 0x0C, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xC0, 0xB0, 0x8C, 0x83, 0x80, 0x80, 0x80, 0x80, 0xB3, 0xB3, 0xB3, 0x80, 0x80, 0x80, 0x80, 0x83, 0x8C, 0xB0, 0xC0, 0x00, 0x00};
#if defined(MODEL_S60) || defined(MODEL_S60P) || defined(MODEL_TS101) || defined(MODEL_T55)
#if defined(MODEL_S60) || defined(MODEL_S60P)
#if defined(MODEL_S60) || defined(MODEL_S60P) || defined(MODEL_TS101) || defined(MODEL_T55) || defined(MODEL_S99)
#if defined(MODEL_S60) || defined(MODEL_S60P) || defined(MODEL_S99)
const uint8_t buttonA[] = {
// width = 56
// height = 32

View File

@@ -14,6 +14,7 @@ void I2CBB2::init() {
// Set GPIO's to output open drain
GPIO_InitTypeDef GPIO_InitStruct;
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
GPIO_InitStruct.Pin = SDA2_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;