Hold PD negotiation until detection is done for tip res

This commit is contained in:
Ben V. Brown
2022-07-01 20:01:59 +10:00
parent 1b43f71a2e
commit 0d248a601b
3 changed files with 11 additions and 7 deletions

View File

@@ -98,6 +98,7 @@ void setStatusLED(const enum StatusLED state);
// By the PID, after each ADC sample comes in
// For example, on the MHP30 this is used to figure out the resistance of the hotplate
uint8_t preStartChecks();
uint8_t preStartChecksDone();
#ifdef __cplusplus
}
#endif

View File

@@ -226,7 +226,7 @@ void setStatusLED(const enum StatusLED state) {
// Dont have one
}
uint8_t lastTipResistance = 85; // default safe
uint8_t lastTipResistance = 0; // default to unknown
uint32_t lastTipReadinguV = 0;
uint8_t getTipResitanceX10() {
// Return tip resistance in x10 ohms
@@ -270,7 +270,6 @@ void FinishMeasureTipResistance() {
lastTipResistance = newRes;
}
volatile bool tipMeasurementOccuring = false;
volatile uint8_t tipSenseResistancex10Ohms = 0;
void performTipMeasurementStep(bool start) {
static TickType_t lastMeas = 0;
@@ -280,13 +279,13 @@ void performTipMeasurementStep(bool start) {
// We want to perform our startup measurements of the tip resistance until we detect one fitted
// Step 1; if not setup, we turn on pullup and then wait
if (tipMeasurementOccuring == false && (start || tipSenseResistancex10Ohms == 0 || lastMeas == 0)) {
if (tipMeasurementOccuring == false && (start || lastTipResistance == 0 || lastMeas == 0)) {
// Block starting if tip removed
if (isTipDisconnected()) {
return;
}
tipMeasurementOccuring = true;
tipSenseResistancex10Ohms = 0;
lastTipResistance = 0;
lastMeas = xTaskGetTickCount();
startMeasureTipResistance();
return;
@@ -308,6 +307,7 @@ uint8_t preStartChecks() {
performTipMeasurementStep(false);
return tipMeasurementOccuring ? 1 : 0;
}
uint8_t preStartChecksDone() { return (lastTipResistance == 0 || tipMeasurementOccuring) ? 0 : 1; }
// Return hardware unique ID if possible
uint64_t getDeviceID() {

View File

@@ -21,6 +21,9 @@
void startPOWTask(void const *argument __unused) {
// Init any other misc sensors
postRToSInit();
while (preStartChecksDone() == 0) {
osDelay(3);
}
// You have to run this once we are willing to answer PD messages
// Setting up too early can mean that we miss the ~20ms window to respond on some chargers
#if POW_PD