From 1fef2fb53aae3eaf24b13ed6d837aefd50c903e4 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sun, 6 May 2018 18:56:38 +1000 Subject: [PATCH] Move OLED LCD update to be DMA'ed Start Cleaning up I2C HAL --- .../TS100/HAL_Driver/Src/stm32f1xx_hal_i2c.c | 43 +------------------ .../TS100/HAL_Driver/Src/stm32f1xx_hal_tim.c | 2 +- workspace/TS100/inc/main.hpp | 2 + workspace/TS100/src/FRToSI2C.cpp | 6 +-- workspace/TS100/src/main.cpp | 41 +++++------------- 5 files changed, 18 insertions(+), 76 deletions(-) diff --git a/workspace/TS100/HAL_Driver/Src/stm32f1xx_hal_i2c.c b/workspace/TS100/HAL_Driver/Src/stm32f1xx_hal_i2c.c index 3c957e2b..5c2554c9 100644 --- a/workspace/TS100/HAL_Driver/Src/stm32f1xx_hal_i2c.c +++ b/workspace/TS100/HAL_Driver/Src/stm32f1xx_hal_i2c.c @@ -3467,48 +3467,7 @@ void HAL_I2C_EV_IRQHandler(I2C_HandleTypeDef *hi2c) } } } - /* Slave mode selected */ - else - { - /* ADDR set --------------------------------------------------------------*/ - if(((sr1itflags & I2C_FLAG_ADDR) != RESET) && ((itsources & I2C_IT_EVT) != RESET)) - { - I2C_Slave_ADDR(hi2c); - } - /* STOPF set --------------------------------------------------------------*/ - else if(((sr1itflags & I2C_FLAG_STOPF) != RESET) && ((itsources & I2C_IT_EVT) != RESET)) - { - I2C_Slave_STOPF(hi2c); - } - /* I2C in mode Transmitter -----------------------------------------------*/ - else if((sr2itflags & I2C_FLAG_TRA) != RESET) - { - /* TXE set and BTF reset -----------------------------------------------*/ - if(((sr1itflags & I2C_FLAG_TXE) != RESET) && ((itsources & I2C_IT_BUF) != RESET) && ((sr1itflags & I2C_FLAG_BTF) == RESET)) - { - I2C_SlaveTransmit_TXE(hi2c); - } - /* BTF set -------------------------------------------------------------*/ - else if(((sr1itflags & I2C_FLAG_BTF) != RESET) && ((itsources & I2C_IT_EVT) != RESET)) - { - I2C_SlaveTransmit_BTF(hi2c); - } - } - /* I2C in mode Receiver --------------------------------------------------*/ - else - { - /* RXNE set and BTF reset ----------------------------------------------*/ - if(((sr1itflags & I2C_FLAG_RXNE) != RESET) && ((itsources & I2C_IT_BUF) != RESET) && ((sr1itflags & I2C_FLAG_BTF) == RESET)) - { - I2C_SlaveReceive_RXNE(hi2c); - } - /* BTF set -------------------------------------------------------------*/ - else if(((sr1itflags & I2C_FLAG_BTF) != RESET) && ((itsources & I2C_IT_EVT) != RESET)) - { - I2C_SlaveReceive_BTF(hi2c); - } - } - } + } /** diff --git a/workspace/TS100/HAL_Driver/Src/stm32f1xx_hal_tim.c b/workspace/TS100/HAL_Driver/Src/stm32f1xx_hal_tim.c index 7b60cccc..89bee1bd 100644 --- a/workspace/TS100/HAL_Driver/Src/stm32f1xx_hal_tim.c +++ b/workspace/TS100/HAL_Driver/Src/stm32f1xx_hal_tim.c @@ -4280,7 +4280,7 @@ uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel) */ /** - * @brief Period elapsed callback in non blocking mode + * @brief Period elapsed callback in non blocking mode * @param htim : TIM handle * @retval None */ diff --git a/workspace/TS100/inc/main.hpp b/workspace/TS100/inc/main.hpp index 10c61353..632f3ca3 100644 --- a/workspace/TS100/inc/main.hpp +++ b/workspace/TS100/inc/main.hpp @@ -28,6 +28,7 @@ void waitForButtonPressOrTimeout(uint32_t timeout); #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); @@ -36,6 +37,7 @@ 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, signed portCHAR *pcTaskName ); + #ifdef __cplusplus } #endif diff --git a/workspace/TS100/src/FRToSI2C.cpp b/workspace/TS100/src/FRToSI2C.cpp index a1c28530..af49e10e 100644 --- a/workspace/TS100/src/FRToSI2C.cpp +++ b/workspace/TS100/src/FRToSI2C.cpp @@ -73,7 +73,7 @@ void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, } void FRToSI2C::FRToSInit() { - I2CSemaphore = xSemaphoreCreateMutex(); + I2CSemaphore = xSemaphoreCreateBinary(); xSemaphoreGive(I2CSemaphore); } @@ -87,11 +87,11 @@ void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t* pData, uint16_t Size) { //Get the mutex so we can use the I2C port //Wait up to 1 second for the mutex if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) 1000 ) == pdTRUE) { - if (HAL_I2C_Master_Transmit(i2c, DevAddress, pData, Size, 5000) + if (HAL_I2C_Master_Transmit_DMA(i2c, DevAddress, pData, Size) != HAL_OK) { NVIC_SystemReset(); } - xSemaphoreGive(I2CSemaphore); + //xSemaphoreGive(I2CSemaphore); } else { NVIC_SystemReset(); } diff --git a/workspace/TS100/src/main.cpp b/workspace/TS100/src/main.cpp index 503e0ab8..a2476069 100644 --- a/workspace/TS100/src/main.cpp +++ b/workspace/TS100/src/main.cpp @@ -99,7 +99,7 @@ void printVoltage() { void GUIDelay() { osDelay(66); // 15Hz } -void gui_drawTipTemp() { +void gui_drawTipTemp(bool symbol) { // Draw tip temp handling unit conversion & tolerance near setpoint uint16_t Temp = getTipRawTemp(0); @@ -112,6 +112,12 @@ void gui_drawTipTemp() { // Temp = systemSettings.SolderingTemp; lcd.printNumber(Temp, 3); // Draw the tip temp out finally + if (symbol) { + if (systemSettings.temperatureInF) + lcd.print("F"); + else + lcd.print("C"); + } } ButtonState getButtonState() { /* @@ -473,18 +479,7 @@ static void gui_solderingMode() { lcd.setCursor(0, 8); lcd.print(SleepingTipAdvancedString); - uint16_t Temp = getTipRawTemp(0); - - if (systemSettings.temperatureInF) - Temp = tipMeasurementToF(Temp); - else - Temp = tipMeasurementToC(Temp); - lcd.printNumber(Temp, 3); - if (systemSettings.temperatureInF) - lcd.print("F"); - else - lcd.print("C"); - + gui_drawTipTemp(true); lcd.print(" "); printVoltage(); lcd.drawChar('V'); @@ -495,13 +490,7 @@ static void gui_solderingMode() { gui_drawBatteryIcon(); lcd.drawChar(' '); // Space out gap between battery <-> temp - if (systemSettings.temperatureInF) { - gui_drawTipTemp(); // Draw current tip temp - lcd.drawSymbol(0); // deg F - } else { - gui_drawTipTemp(); // Draw current tip temp - lcd.drawSymbol(1); // deg C - } + gui_drawTipTemp(true); // Draw current tip temp // We draw boost arrow if boosting, or else gap temp <-> heat indicator if (boostModeOn) @@ -519,14 +508,7 @@ static void gui_solderingMode() { lcd.drawSymbol(2); else lcd.drawChar(' '); - - if (systemSettings.temperatureInF) { - gui_drawTipTemp(); // Draw current tip temp - lcd.drawSymbol(0); // deg F - } else { - gui_drawTipTemp(); // Draw current tip temp - lcd.drawSymbol(1); // deg C - } + gui_drawTipTemp(true); // Draw current tip temp lcd.drawChar(' '); // Space out gap between battery <-> temp @@ -800,7 +782,7 @@ void startGUITask(void const *argument) { } //draw in the temp lcd.setFont(0); //big font - gui_drawTipTemp(); // draw in the temp + gui_drawTipTemp(false); // draw in the temp } } @@ -1054,7 +1036,6 @@ void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c) { i2cDev.CpltCallback(); } void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c) { - i2cDev.CpltCallback(); } void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c) {