From 771f0a1b9e946e31793e39cb9e4ad9384b897ae3 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sun, 6 May 2018 20:06:16 +1000 Subject: [PATCH] Cleanup LCD on/off commands into buffer --- workspace/TS100/Makefile | 14 +++++----- workspace/TS100/inc/OLED.hpp | 2 +- workspace/TS100/src/FRToSI2C.cpp | 6 ++--- workspace/TS100/src/OLED.cpp | 46 ++++++++++++++------------------ workspace/TS100/src/main.cpp | 31 ++++----------------- 5 files changed, 36 insertions(+), 63 deletions(-) diff --git a/workspace/TS100/Makefile b/workspace/TS100/Makefile index 866e1bd0..29fd1aa6 100644 --- a/workspace/TS100/Makefile +++ b/workspace/TS100/Makefile @@ -9,8 +9,6 @@ SOURCE := $(shell find . -type f -name '*.c') SOURCE_CPP := $(shell find . -type f -name '*.cpp') SOURCES := $(shell find . -type f -name '*.c*') S_SRCS := $(shell find . -type f -name '*.s') -CPPCHECK := cppcheck -CHECKFLAGS := -q --error-exitcode=1 APP_INC_DIR = ./inc CMSIS_DEVICE_INC_DIR = ./CMSIS/device @@ -34,7 +32,7 @@ HEXFILE_DIR=Hexfile OUTPUT_DIR=Objects # code optimisation ------------------------------------------------------------ -OPTIM=-O2 -finline-small-functions -findirect-inlining -fdiagnostics-color +OPTIM=-Os -finline-small-functions -findirect-inlining -fdiagnostics-color -ffunction-sections -fdata-sections # global defines --------------------------------------------------------------- @@ -133,7 +131,11 @@ CXXFLAGS=$(CPUFLAGS) \ -fno-rtti \ -fno-exceptions \ -fno-non-call-exceptions \ - -fno-use-cxa-atexit \ + -fno-use-cxa-atexit \ + -fno-strict-aliasing \ + -fno-rtti \ + -fno-exceptions \ + -fno-threadsafe-statics \ -T$(LDSCRIPT) @@ -175,7 +177,7 @@ OUT_OBJS_CPP=$(addprefix $(OUTPUT_DIR)/,$(OBJS_CPP)) OUT_OBJS_S=$(addprefix $(OUTPUT_DIR)/,$(OBJS_S)) OUT_HEXFILE=$(addprefix $(HEXFILE_DIR)/,$(OUTPUT_EXE)) -all: cppcheck.out.xml $(OUT_HEXFILE).hex +all: $(OUT_HEXFILE).hex # # The rule to create the target directory @@ -212,8 +214,6 @@ $(OUT_OBJS_S): $(OUTPUT_DIR)/%.o: %.s Makefile @echo 'Finished building: $<' @echo ' ' -cppcheck.out.xml: $(SOURCES) - $(CPPCHECK) $(CHECKFLAGS) $^ -xml >$@ clean : rm -Rf $(OUTPUT_DIR) diff --git a/workspace/TS100/inc/OLED.hpp b/workspace/TS100/inc/OLED.hpp index 09030bf6..c8098cd1 100644 --- a/workspace/TS100/inc/OLED.hpp +++ b/workspace/TS100/inc/OLED.hpp @@ -57,7 +57,7 @@ private: FRToSI2C* i2c; //i2c Pointer const uint8_t* currentFont; // Pointer to the current font used for rendering to the buffer - uint8_t screenBuffer[14 + 96 + 96 + 10]; // The data buffer + uint8_t screenBuffer[16 + 96 + 96 + 10]; // The data buffer uint8_t* firstStripPtr; // Pointers to the strips to allow for buffer having extra content uint8_t* secondStripPtr; //Pointers to the strips bool inLeftHandedMode; // Whether the screen is in left or not (used for offsets in GRAM) diff --git a/workspace/TS100/src/FRToSI2C.cpp b/workspace/TS100/src/FRToSI2C.cpp index af49e10e..49058ce1 100644 --- a/workspace/TS100/src/FRToSI2C.cpp +++ b/workspace/TS100/src/FRToSI2C.cpp @@ -32,7 +32,7 @@ void FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, //RToS is active, run threading //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 ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) portMAX_DELAY ) == pdTRUE) { if (HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData, Size, 5000) != HAL_OK) { NVIC_SystemReset(); @@ -57,7 +57,7 @@ void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, //RToS is active, run threading //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 ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) portMAX_DELAY ) == pdTRUE) { if (HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize, pData, Size, 5000) != HAL_OK) { NVIC_SystemReset(); @@ -86,7 +86,7 @@ void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t* pData, uint16_t Size) { //RToS is active, run threading //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 ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) portMAX_DELAY ) == pdTRUE) { if (HAL_I2C_Master_Transmit_DMA(i2c, DevAddress, pData, Size) != HAL_OK) { NVIC_SystemReset(); diff --git a/workspace/TS100/src/OLED.cpp b/workspace/TS100/src/OLED.cpp index 5533c8d0..723fc744 100644 --- a/workspace/TS100/src/OLED.cpp +++ b/workspace/TS100/src/OLED.cpp @@ -49,8 +49,8 @@ OLED::OLED(FRToSI2C* i2cHandle) { currentFont = FONT_12; fontWidth = 12; inLeftHandedMode = false; - firstStripPtr = &screenBuffer[15]; - secondStripPtr = &screenBuffer[15 + 96]; + firstStripPtr = &screenBuffer[16 + 1]; + secondStripPtr = &screenBuffer[16 + 1 + 96]; fontHeight = 16; fontWidth = 12; displayOffset = 0; @@ -70,22 +70,24 @@ void OLED::initialize() { //Write out the buffer to the OLEd & call any rendering objects void OLED::refresh() { screenBuffer[0] = 0x80; - screenBuffer[1] = 0x21; + screenBuffer[1] = displayOnOffState ? 0xAF : 0xAE; screenBuffer[2] = 0x80; - screenBuffer[3] = inLeftHandedMode ? 0 : 32; //display is shifted by 32 in left handed mode as driver ram is 128 wide + screenBuffer[3] = 0x21; screenBuffer[4] = 0x80; - screenBuffer[5] = inLeftHandedMode ? 95 : 0x7F; //End address of the ram segment we are writing to (96 wide) - screenBuffer[6] = 0x80; /*Set COM Scan direction*/ - screenBuffer[7] = inLeftHandedMode ? 0xC8 : 0xC0; - screenBuffer[8] = 0x80; //Set pages to rollover after 2 - screenBuffer[9] = 0x22; - screenBuffer[10] = 0x80; - screenBuffer[11] = 0x00; //start page 0 + screenBuffer[5] = inLeftHandedMode ? 0 : 32; //display is shifted by 32 in left handed mode as driver ram is 128 wide + screenBuffer[6] = 0x80; + screenBuffer[7] = inLeftHandedMode ? 95 : 0x7F; //End address of the ram segment we are writing to (96 wide) + screenBuffer[8] = 0x80; /*Set COM Scan direction*/ + screenBuffer[9] = inLeftHandedMode ? 0xC8 : 0xC0; + screenBuffer[10] = 0x80; //Set pages to rollover after 2 + screenBuffer[11] = 0x22; screenBuffer[12] = 0x80; - screenBuffer[13] = 0x01; - screenBuffer[14] = 0x40; //start of data marker + screenBuffer[13] = 0x00; //start page 0 + screenBuffer[14] = 0x80; + screenBuffer[15] = 0x01; + screenBuffer[16] = 0x40; //start of data marker - i2c->Transmit( DEVICEADDR_OLED, screenBuffer, 14 + 96 * 2 + 1); + i2c->Transmit( DEVICEADDR_OLED, screenBuffer, 16 + (96 * 2) + 1); } @@ -150,16 +152,7 @@ void OLED::drawChar(char c, char PrecursorCommand) { } void OLED::displayOnOff(bool on) { - - if (on != displayOnOffState) { - uint8_t data[6] = { 0x80, 0X8D, 0x80, 0X14, 0x80, 0XAF }; //on - if (!on) { - data[3] = 0x10; - data[5] = 0xAE; - } - i2c->Transmit( DEVICEADDR_OLED, data, 6); - displayOnOffState = on; - } + displayOnOffState = on; } void OLED::setRotation(bool leftHanded) { @@ -172,7 +165,8 @@ void OLED::setRotation(bool leftHanded) { OLED_Setup_Array[11] = 0xC0; OLED_Setup_Array[19] = 0xA0; } - i2c->Transmit( DEVICEADDR_OLED, (uint8_t*) OLED_Setup_Array, configLength); + i2c->Transmit( DEVICEADDR_OLED, (uint8_t*) OLED_Setup_Array, + configLength); inLeftHandedMode = leftHanded; } } @@ -340,7 +334,7 @@ void OLED::fillArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, } void OLED::drawFilledRect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, - bool clear) { +bool clear) { //Draw this in 3 sections //This is basically a N wide version of vertical line diff --git a/workspace/TS100/src/main.cpp b/workspace/TS100/src/main.cpp index a2476069..dd986967 100644 --- a/workspace/TS100/src/main.cpp +++ b/workspace/TS100/src/main.cpp @@ -587,6 +587,10 @@ void showVersion(void) { case 5: lcd.print("Time: "); lcd.printNumber(xTaskGetTickCount() / 100, 5); + break; + case 6: + lcd.print("Move: "); + lcd.printNumber(lastMovementTime / 100, 5); break; } @@ -597,7 +601,7 @@ void showVersion(void) { return; else if (b == BUTTON_F_SHORT) { screen++; - screen = screen % 6; + screen = screen % 7; } } } @@ -605,29 +609,6 @@ void showVersion(void) { /* StartGUITask function */ void startGUITask(void const *argument) { i2cDev.FRToSInit(); - /* - * Main program states: - * - * * Soldering (gui_solderingMode) - * -> Main loop where we draw temp, and animations - * --> User presses buttons and they goto the temperature adjust screen - * ---> Display the current setpoint temperature - * ---> Use buttons to change forward and back on temperature - * ---> Both buttons or timeout for exiting - * --> Long hold front button to enter boost mode - * ---> Just temporarily sets the system into the alternate temperature for - * PID control - * --> Long hold back button to exit - * --> Double button to exit - * * Settings Menu (gui_settingsMenu) - * -> Show setting name - * --> If no button press for > 3 Seconds, scroll description - * -> If user presses back button, adjust the setting - * -> Currently the same as 1.x (future to make more depth based) - */ - - uint8_t animationStep = 0; - uint8_t tempWarningState = 0; bool buttonLockout = false; @@ -727,7 +708,6 @@ void startGUITask(void const *argument) { lcd.displayOnOff(false); // turn lcd off when no movement } else lcd.displayOnOff(true); // turn lcd on - } else lcd.displayOnOff(true); // turn lcd on - disabled motion sleep } else @@ -787,7 +767,6 @@ void startGUITask(void const *argument) { } lcd.refresh(); - animationStep++; GUIDelay(); } }