1
0
forked from me/IronOS

Re enable accel, fix accel flags & cleanup qc

This commit is contained in:
Ben V. Brown
2020-07-29 22:53:08 +10:00
parent a39185315d
commit 9391158399
5 changed files with 128 additions and 114 deletions

View File

@@ -51,8 +51,7 @@ uint8_t showBootLogoIfavailable();
void delay_ms(uint16_t count) ;
//Used to allow knowledge of if usb_pd is being used
uint8_t usb_pd_detect();
//Returns 0 when the irq line is pulled down
uint8_t pd_irq_read();
#ifdef __cplusplus
}
#endif

View File

@@ -12,9 +12,6 @@
extern "C" {
#endif
// Called once at startup, after RToS
// This can handle negotiations for QC/PD etc
void power_probe();
// Called periodically in the movement handling thread
// Can be used to check any details for the power system

View File

@@ -45,12 +45,15 @@ void QC_SeekContNeg() {
uint8_t QCMode = 0;
uint8_t QCTries = 0;
void seekQC(int16_t Vx10, uint16_t divisor) {
if (QCMode == 5) startQC(divisor);
if (QCMode == 0) return; // NOT connected to a QC Charger
if (QCMode == 0)
startQC(divisor);
if (Vx10 < 45) return;
if (xTaskGetTickCount() < 100) return;
if (Vx10 > 130) Vx10 = 130; // Cap max value at 13V
if (Vx10 < 45)
return;
if (xTaskGetTickCount() < 100)
return;
if (Vx10 > 130)
Vx10 = 130; // Cap max value at 13V
// Seek the QC to the Voltage given if this adapter supports continuous mode
// try and step towards the wanted value
@@ -62,7 +65,8 @@ void seekQC(int16_t Vx10, uint16_t divisor) {
int steps = difference / 2;
if (QCMode == 3) {
if (steps > -2 && steps < 2) return; // dont bother with small steps
if (steps > -2 && steps < 2)
return; // dont bother with small steps
while (steps < 0) {
QC_SeekContNeg();
osDelay(30);
@@ -106,6 +110,9 @@ void startQC(uint16_t divisor) {
QCMode = 1; // Already at 12V, user has probably over-ridden this
return;
}
if (QCTries > 10) {
return;
}
QC_Init_GPIO();
// Tries to negotiate QC for 9V
@@ -145,13 +152,12 @@ void startQC(uint16_t divisor) {
}
osDelay(100); // 100mS
}
QCMode = 5;
QCTries++;
if (QCTries > 10) // 10 goes to get it going
QCMode = 0;
QCTries++;
} else {
// no QC
QCMode = 0;
}
if (QCTries > 10) QCMode = 0;
}

View File

@@ -43,17 +43,23 @@ int main(void) {
OLED::setFont(0); // default to bigger font
// Testing for which accelerometer is mounted
resetWatchdog();
usb_pd_available = true;//usb_pd_detect();
usb_pd_available = usb_pd_detect();
resetWatchdog();
settingsWereReset = restoreSettings(); // load the settings from flash
/*if (MMA8652FC::detect()) {
#ifdef ACCEL_MMA
if (MMA8652FC::detect()) {
PCBVersion = 1;
MMA8652FC::initalize(); // this sets up the I2C registers
} else if (LIS2DH12::detect()) {
} else
#endif
#ifdef ACCEL_LIS
if (LIS2DH12::detect()) {
PCBVersion = 2;
// Setup the ST Accelerometer
LIS2DH12::initalize(); // startup the accelerometer
} else*/{
} else
#endif
{
PCBVersion = 3;
systemSettings.SleepTime = 0;
systemSettings.ShutdownTime = 0; // No accel -> disable sleep

View File

@@ -25,7 +25,6 @@ uint32_t lastMovementTime = 0;
void startMOVTask(void const *argument __unused) {
OLED::setRotation(systemSettings.OrientationMode & 1);
postRToSInit();
power_probe();
lastMovementTime = 0;
int16_t datax[MOVFilter] = { 0 };
int16_t datay[MOVFilter] = { 0 };
@@ -39,13 +38,20 @@ void startMOVTask(void const *argument __unused) {
for (;;) {
int32_t threshold = 1500 + (9 * 200);
threshold -= systemSettings.sensitivity * 200; // 200 is the step size
#ifdef ACCEL_LIS
if (PCBVersion == 2) {
LIS2DH12::getAxisReadings(tx, ty, tz);
rotation = LIS2DH12::getOrientation();
} else if (PCBVersion == 1) {
} else
#endif
#ifdef ACCEL_MMA
if (PCBVersion == 1) {
MMA8652FC::getAxisReadings(tx, ty, tz);
rotation = MMA8652FC::getOrientation();
}else
#endif
{
//do nothing :(
}
if (systemSettings.OrientationMode == 2) {
if (rotation != ORIENTATION_FLAT) {