Pinecil pd tweaking (#1272)

* Raise PD max to 21V

* gui -> settingsGUI

* VBus probe cache

* Rough pass PD capabilities display

* Cleanup build errors

* PD Debug menu working

* Update make_translation.py

* settingsGUI

* Update GUIThread.cpp

* Nicer debug prints

* Show VBus in PD debug

* Update GUIThread.cpp

* Update make_translation.py

* Add docs

* Build tweaks for TS80P 😢

* Show PPS ranges
This commit is contained in:
Ben V. Brown
2022-04-03 12:58:07 +10:00
committed by GitHub
parent 787bc46bdc
commit a73f634cff
11 changed files with 155 additions and 32 deletions

View File

@@ -124,7 +124,7 @@
#define POWER_LIMIT_STEPS 5 //
#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_PINECIL // Uses TS100 resistors
#define TEMP_uV_LOOKUP_HAKKO // Use Hakko lookup table
#define USB_PD_VMAX 20 // Maximum voltage for PD to negotiate
#define USB_PD_VMAX 21 // Maximum voltage for PD to negotiate
#define PID_TIM_HZ (8) // Tick rate of the PID loop
#define MAX_TEMP_C 450 // Max soldering temp selectable °C
#define MAX_TEMP_F 850 // Max soldering temp selectable °F
@@ -153,3 +153,5 @@
#endif
#define FLASH_LOGOADDR (0x08000000 + (126 * 1024))
#define HAS_POWER_DEBUG_MENU

View File

@@ -5,7 +5,7 @@
* Author: Ralim
*/
#include "FreeRTOS.h"
#include "gui.hpp"
#include "settingsGUI.hpp"
#include "task.h"
#include <Buttons.hpp>
uint32_t lastButtonTime = 0;

View File

@@ -67,10 +67,24 @@ bool USBPowerDelivery::fusbPresent() {
return detectionState == 1;
}
bool USBPowerDelivery::isVBUSConnected() { return fusb.isVBUSConnected(); }
bool USBPowerDelivery::isVBUSConnected() {
static uint8_t state = 0;
if (state) {
return state == 1;
}
if (fusb.isVBUSConnected()) {
state = 1;
return true;
} else {
state = 2;
return false;
}
}
pd_msg lastCapabilities;
pd_msg *USBPowerDelivery::getLastSeenCapabilities() { return &lastCapabilities; }
bool pdbs_dpm_evaluate_capability(const pd_msg *capabilities, pd_msg *request) {
memcpy(&lastCapabilities, capabilities, sizeof(pd_msg));
/* Get the number of PDOs */
uint8_t numobj = PD_NUMOBJ_GET(capabilities);

View File

@@ -2,6 +2,7 @@
#ifndef DRIVERS_USBPD_H_
#define DRIVERS_USBPD_H_
#include "configuration.h"
#include "pdb_msg.h"
#include <stdbool.h>
#include <stdint.h>
@@ -9,16 +10,17 @@
#if POW_PD
class USBPowerDelivery {
public:
static bool start(); // Start the PD stack
static bool negotiationComplete(); // Has negotiation completed to a voltage > 5v
static bool negotiationInProgress(); // Is negotiation ongoing
static bool fusbPresent(); // Is the FUSB302 present on the bus
static void PPSTimerCallback(); // PPS Timer
static void IRQOccured(); // Thread callback that an irq occured
static void step(); // Iterate the step machine
static bool negotiationHasWorked(); // Has PD negotiation worked (are we in a PD contract)
static uint8_t getStateNumber(); // Debugging - Get the internal state number
static bool isVBUSConnected(); // Is the VBus pin connected on the FUSB302
static bool start(); // Start the PD stack
static bool negotiationComplete(); // Has negotiation completed to a voltage > 5v
static bool negotiationInProgress(); // Is negotiation ongoing
static bool fusbPresent(); // Is the FUSB302 present on the bus
static void PPSTimerCallback(); // PPS Timer
static void IRQOccured(); // Thread callback that an irq occured
static void step(); // Iterate the step machine
static bool negotiationHasWorked(); // Has PD negotiation worked (are we in a PD contract)
static uint8_t getStateNumber(); // Debugging - Get the internal state number
static bool isVBUSConnected(); // Is the VBus pin connected on the FUSB302
static pd_msg *getLastSeenCapabilities(); // returns pointer to the last seen capabilities from the powersource
private:
//
static int detectionState;

View File

@@ -14,6 +14,7 @@ extern const bool HasFahrenheit;
extern const char *SymbolPlus;
extern const char *SymbolMinus;
extern const char *SymbolSpace;
extern const char *SymbolAmps;
extern const char *SymbolDot;
extern const char *SymbolDegC;
extern const char *SymbolDegF;
@@ -24,6 +25,10 @@ extern const char *SymbolVolts;
extern const char *SymbolDC;
extern const char *SymbolCellCount;
extern const char *SymbolVersionNumber;
extern const char *SymbolPDDebug;
extern const char *SymbolState;
extern const char *SymbolNoVBus;
extern const char *SymbolVBus;
extern const char *DebugMenu[];
extern const char *AccelTypeNames[];

View File

@@ -1,5 +1,5 @@
/*
* gui.h
* settingsGUI.h
*
* Created on: 3Sep.,2017
* Author: Ben V. Brown

View File

@@ -3,10 +3,10 @@
#include "Translation_multi.h"
#include "brieflz.h"
#include "configuration.h"
#include "gui.hpp"
#include "settingsGUI.hpp"
const TranslationIndexTable *Tr = nullptr;
const char * TranslationStrings = nullptr;
const char *TranslationStrings = nullptr;
static uint8_t selectedLangIndex = 255;
@@ -38,7 +38,7 @@ void prepareTranslations() {
const TranslationData *translationData;
uint16_t buffer_remaining_size = translation_data_out_buffer_size;
uint8_t * buffer_next_ptr = translation_data_out_buffer;
uint8_t *buffer_next_ptr = translation_data_out_buffer;
if (langMeta.translation_is_compressed) {
unsigned int outsize;
outsize = blz_depack_srcsize(langMeta.translation_data, buffer_next_ptr, langMeta.translation_size);
@@ -55,7 +55,7 @@ void prepareTranslations() {
memset(DynamicFontSections, 0, FontSectionsCount * sizeof(DynamicFontSections[0]));
for (int i = 0; i < FontSectionDataCount; i++) {
const auto &fontSectionDataInfo = FontSectionDataInfos[i];
auto & fontSection = DynamicFontSections[i];
auto &fontSection = DynamicFontSections[i];
fontSection.symbol_start = fontSectionDataInfo.symbol_start;
fontSection.symbol_end = fontSection.symbol_start + fontSectionDataInfo.symbol_count;
const uint16_t font12_size = fontSectionDataInfo.symbol_count * (12 * 16 / 8);

View File

@@ -1,11 +1,11 @@
/*
* gui.cpp
* settingsGUI.cpp
*
* Created on: 3Sep.,2017
* Author: Ben V. Brown
*/
#include "gui.hpp"
#include "settingsGUI.hpp"
#include "Buttons.hpp"
#include "ScrollMessage.hpp"
#include "TipThermoModel.h"

View File

@@ -11,20 +11,22 @@ extern "C" {
#include "Buttons.hpp"
#include "I2CBB.hpp"
#include "LIS2DH12.hpp"
#include "MMA8652FC.hpp"
#include "OLED.hpp"
#include "Settings.h"
#include "TipThermoModel.h"
#include "Translation.h"
#include "cmsis_os.h"
#include "configuration.h"
#include "history.hpp"
#include "main.hpp"
#include "power.hpp"
#include "settingsGUI.hpp"
#include "stdlib.h"
#include "string.h"
#include <MMA8652FC.hpp>
#include <gui.hpp>
#include <history.hpp>
#include <power.hpp>
#if POW_PD
#include "USBPD.h"
#include "pd.h"
#endif
// File local variables
extern uint32_t currentTempTargetDegC;
@@ -797,6 +799,82 @@ void showDebugMenu(void) {
}
}
#if POW_PD
#ifdef HAS_POWER_DEBUG_MENU
static void showPDDebug(void) {
// 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(SymbolPDDebug, FontStyle::SMALL); // Print Title
OLED::setCursor(0, 8); // second line
if (screen == 0) {
// Print the PD state machine
OLED::print(SymbolState, FontStyle::SMALL);
OLED::print(SymbolSpace, FontStyle::SMALL);
OLED::printNumber(USBPowerDelivery::getStateNumber(), 2, FontStyle::SMALL, true);
OLED::print(SymbolSpace, FontStyle::SMALL);
// Also print vbus mod status
if (USBPowerDelivery::fusbPresent()) {
if (USBPowerDelivery::negotiationComplete() || (xTaskGetTickCount() > (TICKS_SECOND * 10))) {
if (!USBPowerDelivery::isVBUSConnected()) {
OLED::print(SymbolNoVBus, FontStyle::SMALL);
} else {
OLED::print(SymbolVBus, FontStyle::SMALL);
}
}
}
} else {
// Print out the Proposed power options one by one
auto lastCaps = USBPowerDelivery::getLastSeenCapabilities();
uint8_t numobj = PD_NUMOBJ_GET(lastCaps);
if ((screen - 1) < numobj) {
int voltage_mv = 0;
int min_voltage = 0;
int current_a_x100 = 0;
if ((lastCaps->obj[screen - 1] & PD_PDO_TYPE) == PD_PDO_TYPE_FIXED) {
voltage_mv = PD_PDV2MV(PD_PDO_SRC_FIXED_VOLTAGE_GET(lastCaps->obj[screen - 1])); // voltage in mV units
current_a_x100 = PD_PDO_SRC_FIXED_CURRENT_GET(lastCaps->obj[screen - 1]); // current in 10mA units
} else {
voltage_mv = PD_PAV2MV(PD_APDO_PPS_MAX_VOLTAGE_GET(lastCaps->obj[screen - 1]));
min_voltage = PD_PAV2MV(PD_APDO_PPS_MIN_VOLTAGE_GET(lastCaps->obj[screen - 1]));
current_a_x100 = PD_PAI2CA(PD_APDO_PPS_CURRENT_GET(lastCaps->obj[screen - 1])); // max current in 10mA units
}
// print out this entry of the proposal
OLED::printNumber(screen, 1, FontStyle::SMALL, true); // print the entry number
OLED::print(SymbolSpace, FontStyle::SMALL);
if (min_voltage > 0) {
OLED::printNumber(min_voltage / 1000, 2, FontStyle::SMALL, true); // print the voltage
OLED::print(SymbolMinus, FontStyle::SMALL);
}
OLED::printNumber(voltage_mv / 1000, 2, FontStyle::SMALL, true); // print the voltage
OLED::print(SymbolVolts, FontStyle::SMALL);
OLED::print(SymbolSpace, FontStyle::SMALL);
OLED::printNumber(current_a_x100 / 100, 2, FontStyle::SMALL, true); // print the current in 0.1A res
OLED::print(SymbolDot, FontStyle::SMALL);
OLED::printNumber(current_a_x100 % 10, 1, FontStyle::SMALL, true); // print the current in 0.1A res
OLED::print(SymbolAmps, FontStyle::SMALL);
} else {
screen = 0;
}
}
OLED::refresh();
b = getButtonState();
if (b == BUTTON_B_SHORT)
return;
else if (b == BUTTON_F_SHORT) {
screen++;
}
GUIDelay();
}
}
#endif
#endif
void showWarnings() {
// Display alert if settings were reset
if (settingsWereReset) {
@@ -860,7 +938,14 @@ void startGUITask(void const *argument) {
}
getTipRawTemp(1); // reset filter
OLED::setRotation(getSettingValue(SettingsOptions::OrientationMode) & 1);
// If the front button is held down, on supported devices, show PD debugging metrics
#if POW_PD
#ifdef HAS_POWER_DEBUG_MENU
if (getButtonA()) {
showPDDebug();
}
#endif
#endif
BootLogo::handleShowingLogo((uint8_t *)FLASH_LOGOADDR);
showWarnings();