1
0
forked from me/IronOS

Fixes for I2C on Pinecil + USB-PD stack (#1099)

* Remove unused includes

* Adding in submodule

* Move fusb functions to the BSP

* Remove old code

* Creating IronOS PD integration wrapper

* Redirect to wrapper

* pd lib updates

* fix Docker build

* Finish linking across

* Cleanup

* Update Makefile

* Update push.yml

* Update push.yml

* PD -> Compensate for different tick rates

* Update codeql-analysis.yml

* Fix PD #define for @Firebie

* Check irq low at start

* Update BSP.h

* Update main.cpp

* Closer delay

* Update OLED.cpp

* Bugfix trying to start QC too early

* Missing fusb shouldnt hang qc

* Update FreeRTOSConfig.h

* Update the GD drivers

* Update Pinecil IRQ setup

* Redirect printf() to uart

* Update Power.cpp

* Adding extras to PD state

* Update USBPD.cpp

* Delay in printf

* Iterate once before delay on start

* Update usb-pd

* master usb-pd now

* Format gd libs

* Update gd32vf103_bkp.c

* Guard with PD timeout

* Remove CodeQL

* Slow for testing, fix runt pulses at start

* Fix runt pulse in read size 1

* Cleaner probing setup

* Testing delay during stop gen in read 1

* Update I2C driver

* Update gd32vf103_i2c.c

* Cleaning up i2c wrapper a little, given up on dma for rx

* Update preRTOS.cpp

* Update Setup.cpp

* Update MOVThread.cpp

* Slow down UART to work with new clock config

* Better ack setup for 2 byte read

* Cleanup POW_PD so cant be lost in #includes

* tipResistance -> TIP_RESISTANCE

* handle NOP race on len==2

* Update configuration.h

* Dont use neg timeout to mask anymore

* Not required for MHP

* Fix up source display Miniware

* Fix race on PD init

* Update POWThread.cpp

* Update formatting

* MHP format

* Update push.yml

* Faster TS80P I2C

* Bugfix for IRQ handlers

* Correctly handle I2C race on PD access

* Fix CI error (unused var) and MHP IRQ

* Test Pinecil alt ADC mode
This commit is contained in:
Ben V. Brown
2021-10-02 14:48:58 +10:00
committed by GitHub
parent 04ad5a3bfc
commit 3594604efc
114 changed files with 3099 additions and 6434 deletions

View File

@@ -22,8 +22,8 @@ extern "C" {
#include <gui.hpp>
#include <history.hpp>
#include <power.hpp>
#ifdef POW_PD
#include "policy_engine.h"
#if POW_PD
#include "USBPD.h"
#endif
// File local variables
extern uint32_t currentTempTargetDegC;
@@ -724,10 +724,10 @@ void showDebugMenu(void) {
} else {
// We are not powered via DC, so want to display the appropriate state for PD or QC
bool poweredbyPD = false;
#ifdef POW_PD
if (usb_pd_detect()) {
#if POW_PD
if (USBPowerDelivery::fusbPresent()) {
// We are PD capable
if (PolicyEngine::pdHasNegotiated()) {
if (USBPowerDelivery::negotiationComplete()) {
// We are powered via PD
poweredbyPD = true;
}
@@ -782,9 +782,9 @@ void showWarnings() {
warnUser(translatedString(Tr->NoAccelerometerMessage), 10 * TICKS_SECOND);
}
}
#ifdef POW_PD
#if POW_PD
// We expect pd to be present
if (!usb_pd_detect()) {
if (!USBPowerDelivery::fusbPresent()) {
if (getSettingValue(SettingsOptions::PDMissingWarningCounter) < 2) {
nextSettingValue(SettingsOptions::PDMissingWarningCounter);
saveSettings();

View File

@@ -30,44 +30,49 @@ TickType_t lastMovementTime = 0;
void detectAccelerometerVersion() {
DetectedAccelerometerVersion = AccelType::Scanning;
#ifdef ACCEL_SC7
if (SC7A20::detect()) {
// Setup the SC7A20 Accelerometer
if (SC7A20::initalize()) {
DetectedAccelerometerVersion = AccelType::SC7;
return;
}
}
#endif
#ifdef ACCEL_MMA
if (MMA8652FC::detect()) {
if (MMA8652FC::initalize()) {
DetectedAccelerometerVersion = AccelType::MMA;
return;
}
} else
}
#endif
#ifdef ACCEL_LIS
if (LIS2DH12::detect()) {
if (LIS2DH12::detect()) {
// Setup the ST Accelerometer
if (LIS2DH12::initalize()) {
DetectedAccelerometerVersion = AccelType::LIS;
return;
}
} else
}
#endif
#ifdef ACCEL_BMA
if (BMA223::detect()) {
if (BMA223::detect()) {
// Setup the BMA223 Accelerometer
if (BMA223::initalize()) {
DetectedAccelerometerVersion = AccelType::BMA;
return;
}
} else
}
#endif
#ifdef ACCEL_MSA
if (MSA301::detect()) {
if (MSA301::detect()) {
// Setup the MSA301 Accelerometer
if (MSA301::initalize()) {
DetectedAccelerometerVersion = AccelType::MSA;
return;
}
} else
#endif
#ifdef ACCEL_SC7
if (SC7A20::detect()) {
// Setup the SC7A20 Accelerometer
if (SC7A20::initalize()) {
DetectedAccelerometerVersion = AccelType::SC7;
}
} else
}
#endif
{
// disable imu sensitivity

View File

@@ -9,29 +9,51 @@
#include "FreeRTOS.h"
#include "QC3.h"
#include "Settings.h"
#include "USBPD.h"
#include "cmsis_os.h"
#include "fusbpd.h"
#include "configuration.h"
#include "main.hpp"
#include "stdlib.h"
#include "task.h"
// Small worker thread to handle power (mostly QC) related steps
// Small worker thread to handle power (PD + QC) related steps
void startPOWTask(void const *argument __unused) {
// 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
#ifdef POW_PD
if (usb_pd_detect() == true) {
// Spawn all of the USB-C processors
fusb302_start_processing();
}
#endif
vTaskDelay(TICKS_100MS);
// Init any other misc sensors
postRToSInit();
// 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
USBPowerDelivery::start();
// Crank the handle at boot until we are stable and waiting for IRQ
USBPowerDelivery::step();
#endif
BaseType_t res;
for (;;) {
res = pdFALSE;
// While the interrupt is low, dont delay
/*This is due to a possible race condition, where:
* IRQ fires
* We read interrupt register but dont see the Good CRC
* Then Good CRC is set while reading it out (racing on I2C read)
* Then we would sleep as nothing to do, but 100ms> 20ms power supply typical timeout
*/
if (!getFUS302IRQLow()) {
res = xTaskNotifyWait(0x0, 0xFFFFFF, NULL, TICKS_100MS);
}
#if POW_PD
if (res != pdFALSE || getFUS302IRQLow()) {
USBPowerDelivery::IRQOccured();
}
USBPowerDelivery::step();
USBPowerDelivery::PPSTimerCallback();
#else
(void)res;
#endif
power_check();
osDelay(TICKS_100MS); // Slow down update rate
}
}