1
0
forked from me/IronOS

Compare commits

..

2 Commits

Author SHA1 Message Date
Ben V. Brown
64d5e8b1af Fix mixtake in I2C probe check 2020-05-30 18:35:15 +10:00
Ben V. Brown
441ac7f83a Move IRQ's for easier tracing 2020-05-30 18:34:49 +10:00
9 changed files with 155 additions and 133 deletions

View File

@@ -1,5 +1,6 @@
//BSP mapping functions //BSP mapping functions
#include <IRQ.h>
#include "BSP.h" #include "BSP.h"
#include "Setup.h" #include "Setup.h"
#include "history.hpp" #include "history.hpp"
@@ -212,41 +213,6 @@ uint8_t getButtonB() {
1 : 0; 1 : 0;
} }
/*
* Catch the IRQ that says that the conversion is done on the temperature
* readings coming in Once these have come in we can unblock the PID so that it
* runs again
*/
void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef *hadc) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
if (hadc == &hadc1) {
if (pidTaskNotification) {
vTaskNotifyGiveFromISR(pidTaskNotification,
&xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
}
}
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
FRToSI2C::CpltCallback();
}
void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
FRToSI2C::CpltCallback();
}
void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
FRToSI2C::CpltCallback();
}
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c __unused) {
FRToSI2C::CpltCallback();
}
void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
FRToSI2C::CpltCallback();
}
void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
FRToSI2C::CpltCallback();
}
void reboot() { void reboot() {
NVIC_SystemReset(); NVIC_SystemReset();
} }

View File

@@ -30,10 +30,10 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
// RToS is active, run threading // RToS is active, run threading
// Get the mutex so we can use the I2C port // Get the mutex so we can use the I2C port
// Wait up to 1 second for the mutex // Wait up to 1 second for the mutex
if (xSemaphoreTake(I2CSemaphore, (TickType_t)50) == pdTRUE) { if (xSemaphoreTake(I2CSemaphore, (TickType_t)500) == pdTRUE) {
#ifdef I2CUSESDMA #ifdef I2CUSESDMA
if (HAL_I2C_Mem_Read(&hi2c1, DevAddress, MemAddress, if (HAL_I2C_Mem_Read(&hi2c1, DevAddress, MemAddress,
I2C_MEMADD_SIZE_8BIT, pData, Size, 500) != HAL_OK) { I2C_MEMADD_SIZE_8BIT, pData, Size, 500) != HAL_OK) {
I2C_Unstick(); I2C_Unstick();
xSemaphoreGive(I2CSemaphore); xSemaphoreGive(I2CSemaphore);
@@ -78,22 +78,15 @@ void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
// RToS is active, run threading // RToS is active, run threading
// Get the mutex so we can use the I2C port // Get the mutex so we can use the I2C port
// Wait up to 1 second for the mutex // Wait up to 1 second for the mutex
if (xSemaphoreTake(I2CSemaphore, (TickType_t)50) == pdTRUE) { if (xSemaphoreTake(I2CSemaphore, (TickType_t)500) == pdTRUE) {
#ifdef I2CUSESDMA
if (HAL_I2C_Mem_Write(&hi2c1, DevAddress, MemAddress, if (HAL_I2C_Mem_Write(&hi2c1, DevAddress, MemAddress,
I2C_MEMADD_SIZE_8BIT, pData, Size, 500) != HAL_OK) { I2C_MEMADD_SIZE_8BIT, pData, Size, 500) != HAL_OK) {
I2C_Unstick(); I2C_Unstick();
xSemaphoreGive(I2CSemaphore); xSemaphoreGive(I2CSemaphore);
} }
xSemaphoreGive(I2CSemaphore); xSemaphoreGive(I2CSemaphore);
#else
if (HAL_I2C_Mem_Write(&hi2c1, DevAddress, MemAddress, I2C_MEMADD_SIZE_8BIT, pData,
Size, 5000) != HAL_OK) {
}
xSemaphoreGive(I2CSemaphore);
#endif
} else {
} }
} }
@@ -130,11 +123,9 @@ void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
bool FRToSI2C::probe(uint16_t DevAddress) { bool FRToSI2C::probe(uint16_t DevAddress) {
uint8_t buffer[1]; uint8_t buffer[1];
if (Mem_Read(DevAddress, 0, buffer, 1)) { return HAL_I2C_Mem_Read(&hi2c1, DevAddress, 0x0F, I2C_MEMADD_SIZE_8BIT,
//ACK'd buffer, 1, 1000) == HAL_OK;
return true;
}
return false;
} }
void FRToSI2C::I2C_Unstick() { void FRToSI2C::I2C_Unstick() {

View File

@@ -0,0 +1,43 @@
/*
* IRQ.c
*
* Created on: 30 May 2020
* Author: Ralim
*/
#include "IRQ.h"
/*
* Catch the IRQ that says that the conversion is done on the temperature
* readings coming in Once these have come in we can unblock the PID so that it
* runs again
*/
void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef *hadc) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
if (hadc == &hadc1) {
if (pidTaskNotification) {
vTaskNotifyGiveFromISR(pidTaskNotification,
&xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
}
}
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
FRToSI2C::CpltCallback();
}
void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
FRToSI2C::CpltCallback();
}
void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
FRToSI2C::CpltCallback();
}
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c __unused) {
FRToSI2C::CpltCallback();
}
void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
FRToSI2C::CpltCallback();
}
void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
FRToSI2C::CpltCallback();
}

View File

@@ -0,0 +1,31 @@
/*
* Irqs.h
*
* Created on: 30 May 2020
* Author: Ralim
*/
#ifndef BSP_MINIWARE_IRQ_H_
#define BSP_MINIWARE_IRQ_H_
#include "BSP.h"
#include "stm32f1xx_hal.h"
#include "I2C_Wrapper.hpp"
#include "Setup.h"
#include "main.hpp"
#ifdef __cplusplus
extern "C" {
#endif
void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef *hadc);
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c);
void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c);
void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c);
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c);
void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c);
void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c);
#ifdef __cplusplus
}
#endif
#endif /* BSP_MINIWARE_IRQ_H_ */

View File

@@ -7,7 +7,8 @@
#include "power.hpp" #include "power.hpp"
#include "stdlib.h" #include "stdlib.h"
#include "task.h" #include "task.h"
#include "I2C_Wrapper.hpp"
void postRToSInit() { void postRToSInit() {
// Any after RTos setup // Any after RTos setup
FRToSI2C::FRToSInit();
} }

View File

@@ -11,13 +11,6 @@ extern bool settingsWereReset;
extern "C" { extern "C" {
#endif #endif
void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef *hadc);
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c);
void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c);
void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c);
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c);
void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c);
void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c);
void vApplicationStackOverflowHook(xTaskHandle *pxTask, void vApplicationStackOverflowHook(xTaskHandle *pxTask,
signed portCHAR *pcTaskName); signed portCHAR *pcTaskName);

View File

@@ -38,11 +38,11 @@ int main(void) {
preRToSInit(); preRToSInit();
setTipX10Watts(0); // force tip off setTipX10Watts(0); // force tip off
resetWatchdog();
OLED::initialize(); // start up the LCD OLED::initialize(); // start up the LCD
OLED::setFont(0); // default to bigger font OLED::setFont(0); // default to bigger font
// Testing for which accelerometer is mounted // Testing for which accelerometer is mounted
resetWatchdog(); resetWatchdog();
resetWatchdog();
settingsWereReset = restoreSettings(); // load the settings from flash settingsWereReset = restoreSettings(); // load the settings from flash
if (MMA8652FC::detect()) { if (MMA8652FC::detect()) {
PCBVersion = 1; PCBVersion = 1;
@@ -72,11 +72,11 @@ int main(void) {
PIDTaskStackSize, PIDTaskBuffer, &PIDTaskControlBlock); PIDTaskStackSize, PIDTaskBuffer, &PIDTaskControlBlock);
PIDTaskHandle = osThreadCreate(osThread(PIDTask), NULL); PIDTaskHandle = osThreadCreate(osThread(PIDTask), NULL);
if (PCBVersion < 3) { osThreadStaticDef(MOVTask, startMOVTask, osPriorityNormal, 0,
osThreadStaticDef(MOVTask, startMOVTask, osPriorityNormal, 0, MOVTaskStackSize, MOVTaskBuffer, &MOVTaskControlBlock);
MOVTaskStackSize, MOVTaskBuffer, &MOVTaskControlBlock); MOVTaskHandle = osThreadCreate(osThread(MOVTask), NULL);
MOVTaskHandle = osThreadCreate(osThread(MOVTask), NULL);
} resetWatchdog();
/* Start scheduler */ /* Start scheduler */
osKernelStart(); osKernelStart();

View File

@@ -10,9 +10,8 @@ extern "C" {
#include <MMA8652FC.hpp> #include <MMA8652FC.hpp>
#include <gui.hpp> #include <gui.hpp>
#include <history.hpp> #include <history.hpp>
#include <main.hpp> #include "main.hpp"
#include <power.hpp> #include <power.hpp>
#include "../../configuration.h" #include "../../configuration.h"
#include "Buttons.hpp" #include "Buttons.hpp"
#include "LIS2DH12.hpp" #include "LIS2DH12.hpp"
@@ -23,7 +22,7 @@ extern "C" {
#include "stdlib.h" #include "stdlib.h"
#include "string.h" #include "string.h"
#include "unit.h" #include "unit.h"
extern uint8_t PCBVersion;
// File local variables // File local variables
extern uint32_t currentTempTargetDegC; extern uint32_t currentTempTargetDegC;
extern uint8_t accelInit; extern uint8_t accelInit;
@@ -597,7 +596,7 @@ void showDebugMenu(void) {
/* StartGUITask function */ /* StartGUITask function */
void startGUITask(void const *argument __unused) { void startGUITask(void const *argument __unused) {
FRToSI2C::FRToSInit();
uint8_t tempWarningState = 0; uint8_t tempWarningState = 0;
bool buttonLockout = false; bool buttonLockout = false;
bool tempOnDisplay = false; bool tempOnDisplay = false;

View File

@@ -23,71 +23,69 @@
uint8_t accelInit = 0; uint8_t accelInit = 0;
uint32_t lastMovementTime = 0; uint32_t lastMovementTime = 0;
void startMOVTask(void const *argument __unused) { void startMOVTask(void const *argument __unused) {
OLED::setRotation(true); OLED::setRotation(systemSettings.OrientationMode & 1);
postRToSInit(); postRToSInit();
power_probe(); power_probe();
while (pidTaskNotification == 0) osDelay(30); // Wait for PID to start lastMovementTime = 0;
int16_t datax[MOVFilter] = { 0 };
int16_t datay[MOVFilter] = { 0 };
int16_t dataz[MOVFilter] = { 0 };
uint8_t currentPointer = 0;
int16_t tx = 0, ty = 0, tz = 0;
int32_t avgx, avgy, avgz;
if (systemSettings.sensitivity > 9)
systemSettings.sensitivity = 9;
Orientation rotation = ORIENTATION_FLAT;
for (;;) {
int32_t threshold = 1500 + (9 * 200);
threshold -= systemSettings.sensitivity * 200; // 200 is the step size
OLED::setRotation(systemSettings.OrientationMode & 1); if (PCBVersion == 2) {
lastMovementTime = 0; LIS2DH12::getAxisReadings(tx, ty, tz);
int16_t datax[MOVFilter] = {0}; rotation = LIS2DH12::getOrientation();
int16_t datay[MOVFilter] = {0}; } else if (PCBVersion == 1) {
int16_t dataz[MOVFilter] = {0}; MMA8652FC::getAxisReadings(tx, ty, tz);
uint8_t currentPointer = 0; rotation = MMA8652FC::getOrientation();
int16_t tx = 0, ty = 0, tz = 0; }
int32_t avgx, avgy, avgz; if (systemSettings.OrientationMode == 2) {
if (systemSettings.sensitivity > 9) systemSettings.sensitivity = 9; if (rotation != ORIENTATION_FLAT) {
Orientation rotation = ORIENTATION_FLAT; OLED::setRotation(rotation == ORIENTATION_LEFT_HAND); // link the data through
for (;;) { }
int32_t threshold = 1500 + (9 * 200); }
threshold -= systemSettings.sensitivity * 200; // 200 is the step size datax[currentPointer] = (int32_t) tx;
datay[currentPointer] = (int32_t) ty;
dataz[currentPointer] = (int32_t) tz;
if (!accelInit) {
for (uint8_t i = currentPointer + 1; i < MOVFilter; i++) {
datax[i] = (int32_t) tx;
datay[i] = (int32_t) ty;
dataz[i] = (int32_t) tz;
}
accelInit = 1;
}
currentPointer = (currentPointer + 1) % MOVFilter;
avgx = avgy = avgz = 0;
// calculate averages
for (uint8_t i = 0; i < MOVFilter; i++) {
avgx += datax[i];
avgy += datay[i];
avgz += dataz[i];
}
avgx /= MOVFilter;
avgy /= MOVFilter;
avgz /= MOVFilter;
if (PCBVersion == 2) { // Sum the deltas
LIS2DH12::getAxisReadings(tx, ty, tz); int32_t error = (abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz));
rotation = LIS2DH12::getOrientation(); // So now we have averages, we want to look if these are different by more
} else if (PCBVersion == 1) { // than the threshold
MMA8652FC::getAxisReadings(tx, ty, tz);
rotation = MMA8652FC::getOrientation();
}
if (systemSettings.OrientationMode == 2) {
if (rotation != ORIENTATION_FLAT) {
OLED::setRotation(rotation == ORIENTATION_LEFT_HAND); // link the data through
}
}
datax[currentPointer] = (int32_t)tx;
datay[currentPointer] = (int32_t)ty;
dataz[currentPointer] = (int32_t)tz;
if (!accelInit) {
for (uint8_t i = currentPointer + 1; i < MOVFilter; i++) {
datax[i] = (int32_t)tx;
datay[i] = (int32_t)ty;
dataz[i] = (int32_t)tz;
}
accelInit = 1;
}
currentPointer = (currentPointer + 1) % MOVFilter;
avgx = avgy = avgz = 0;
// calculate averages
for (uint8_t i = 0; i < MOVFilter; i++) {
avgx += datax[i];
avgy += datay[i];
avgz += dataz[i];
}
avgx /= MOVFilter;
avgy /= MOVFilter;
avgz /= MOVFilter;
// Sum the deltas // If error has occurred then we update the tick timer
int32_t error = (abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz)); if (error > threshold) {
// So now we have averages, we want to look if these are different by more lastMovementTime = xTaskGetTickCount();
// than the threshold }
// If error has occurred then we update the tick timer osDelay(100); // Slow down update rate
if (error > threshold) { power_check();
lastMovementTime = xTaskGetTickCount(); }
}
osDelay(100); // Slow down update rate
power_check();
}
} }