From c0e370c802d9360738aa2f6391ee68b618c121d3 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Wed, 7 Jun 2017 22:15:54 +0200 Subject: [PATCH] code beautifying --- my_src/{display.c => hmi.c} | 9 +++++++-- my_src/{display.h => hmi.h} | 9 +++++---- my_src/main2.c | 9 ++++----- my_src/oled.c | 2 +- my_src/oled.h | 2 +- my_src/switches.c | 11 +++++------ my_src/timer.c | 6 +++++- my_src/timer.h | 2 ++ 8 files changed, 30 insertions(+), 20 deletions(-) rename my_src/{display.c => hmi.c} (96%) rename my_src/{display.h => hmi.h} (86%) diff --git a/my_src/display.c b/my_src/hmi.c similarity index 96% rename from my_src/display.c rename to my_src/hmi.c index 24782b8..652ac47 100644 --- a/my_src/display.c +++ b/my_src/hmi.c @@ -6,11 +6,11 @@ */ +#include #include "stm32f1xx_hal.h" -#include "display.h" #include "alarm.h" #include - +#include "oled.h" @@ -50,6 +50,11 @@ void updateDisplay(void *handle) { LED_P8x16Str(0, 6, buf); } + +void hmiInit() { + schAdd(updateDisplay, &display, 0, 250); +} + void clearSetMode(void *handle) { tDisplay *lDisplay = (tDisplay*) handle; lDisplay->setModeTemperature = 0; diff --git a/my_src/display.h b/my_src/hmi.h similarity index 86% rename from my_src/display.h rename to my_src/hmi.h index 450976a..97a7248 100644 --- a/my_src/display.h +++ b/my_src/hmi.h @@ -1,12 +1,12 @@ /* - * display.h + * hmi.h * * Created on: May 31, 2017 * Author: wn */ -#ifndef DISPLAY_H_ -#define DISPLAY_H_ +#ifndef HMI_H_ +#define HMI_H_ #include "timer.h" @@ -26,10 +26,11 @@ typedef struct { uint32_t overrunTime; } tDisplay; +void hmiInit(void); void updateDisplay(void *handle); void displayToggleSetMode(); void displayDecValue(); void displayIncValue(); -#endif /* DISPLAY_H_ */ +#endif /* HMI_H_ */ diff --git a/my_src/main2.c b/my_src/main2.c index be86b71..067b90f 100644 --- a/my_src/main2.c +++ b/my_src/main2.c @@ -16,21 +16,18 @@ +#include #include #include #include "stm32f1xx_hal.h" #include "oled.h" #include "timer.h" -#include "display.h" -extern tDisplay display; void my_setup_1() { schInit(); - schAdd(updateDisplay, &display, 0, 250); - schAdd(secondTick, &display, 0, 1000); } void my_loop() { @@ -47,7 +44,9 @@ void my_errorHandler() { } void my_setup_2() { - LED_Init(); + hmiInit(); + timerInit(); + oledInit(); } diff --git a/my_src/oled.c b/my_src/oled.c index f8bf5e7..27c3df4 100644 --- a/my_src/oled.c +++ b/my_src/oled.c @@ -242,7 +242,7 @@ void Set_NOP(void) LED_WrCmd(0xE3); // Command for No Operation } -void LED_Init(void) +void oledInit(void) { // LEDPIN_Init(); // LED_PORT=0X0F; diff --git a/my_src/oled.h b/my_src/oled.h index 23d2ad3..c519e30 100644 --- a/my_src/oled.h +++ b/my_src/oled.h @@ -15,7 +15,7 @@ * Adapted from Arduino to STM32 HAL by wollud1969 */ -void LED_Init(void); +void oledInit(void); void LED_CLS(void); void LED_Set_Pos(unsigned char x,unsigned char y);//Set the coordinate diff --git a/my_src/switches.c b/my_src/switches.c index 0e9d881..7bfda1d 100644 --- a/my_src/switches.c +++ b/my_src/switches.c @@ -6,13 +6,12 @@ */ +#include #include "stm32f1xx_hal.h" #include "switches.h" -#include "display.h" -extern tDisplay display; volatile uint32_t lastEvent = 0; @@ -20,17 +19,17 @@ void switch_interrupt() { static uint8_t state = 0; uint32_t currentEvent = HAL_GetTick(); - uint16_t line = HAL_GPIO_ReadPin(SWITCH_GPIO_Port, SWITCH_Pin); + GPIO_PinState line = HAL_GPIO_ReadPin(SWITCH_GPIO_Port, SWITCH_Pin); switch (state) { case 0: - if (line == RESET) { + if (line == GPIO_PIN_RESET) { lastEvent = currentEvent; state = 1; } break; case 1: - if (line != RESET) { + if (line != GPIO_PIN_RESET) { if (lastEvent + LONG_BUTTON_TIME + DEBOUNCING_DEAD_TIME < currentEvent) { lastEvent = currentEvent; buttonLong(); @@ -50,7 +49,7 @@ void switch_interrupt() { int myDigitalRead(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) { int16_t r = 0; for (uint32_t i = 0; i < DEBOUNCING_REPEAT; i++) { - if (HAL_GPIO_ReadPin(GPIOx, GPIO_Pin) != RESET) { + if (HAL_GPIO_ReadPin(GPIOx, GPIO_Pin) != GPIO_PIN_RESET) { r++; } else { r--; diff --git a/my_src/timer.c b/my_src/timer.c index a9513a1..a6bff03 100644 --- a/my_src/timer.c +++ b/my_src/timer.c @@ -5,8 +5,8 @@ * Author: wn */ +#include #include "timer.h" -#include "display.h" #include "alarm.h" @@ -46,3 +46,7 @@ void secondTick(void *handle) { ; } } + +void timerInit() { + schAdd(secondTick, &display, 0, 1000); +} diff --git a/my_src/timer.h b/my_src/timer.h index 4da8ca2..edf5db7 100644 --- a/my_src/timer.h +++ b/my_src/timer.h @@ -15,6 +15,8 @@ typedef enum { OVERRUN = 3 } tTimerState; + +void timerInit(); void secondTick(void *handle); void startTimer(); void stopTimer();