From e7de86f1c597535fb5e5232dcc2efc9569a1878a Mon Sep 17 00:00:00 2001 From: Michael Schloh von Bennewitz Date: Fri, 4 Sep 2020 11:08:16 +0200 Subject: [PATCH] Abstract static definitions out of source containing variable code. --- firmware/src/main.c | 48 +++++++++++++++------------------------------ firmware/src/main.h | 30 ++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 32 deletions(-) create mode 100644 firmware/src/main.h diff --git a/firmware/src/main.c b/firmware/src/main.c index 120318b..1c631f0 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -1,47 +1,31 @@ -#if F0 -#include "stm32f0xx_hal.h" -#elif F1 -#include "stm32f1xx_hal.h" -#elif F2 -#include "stm32f2xx_hal.h" -#elif F3 -#include "stm32f3xx_hal.h" -#elif F4 -#include "stm32f4xx_hal.h" -#elif F7 -#include "stm32f7xx_hal.h" -#elif L0 -#include "stm32l0xx_hal.h" -#elif L1 -#include "stm32l1xx_hal.h" -#elif L4 -#include "stm32l4xx_hal.h" -#else -#error "Unsupported STM32 Family" -#endif +#include "main.h" -#define LED_PIN GPIO_PIN_5 -#define LED_GPIO_PORT GPIOA -#define LED_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() -int main(void) +void LED_Init() { - HAL_Init(); - LED_GPIO_CLK_ENABLE(); - + GPIO_InitTypeDef GPIO_InitStruct; - + GPIO_InitStruct.Pin = LED_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; - HAL_GPIO_Init(LED_GPIO_PORT, &GPIO_InitStruct); + GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; + HAL_GPIO_Init(LED_GPIO_PORT, &GPIO_InitStruct); +} + +#ifndef UNIT_TEST +int main(void) +#else +int app_main(void) +#endif +{ + HAL_Init(); + LED_Init(); while (1) { HAL_GPIO_TogglePin(LED_GPIO_PORT, LED_PIN); - HAL_Delay(1000); } } diff --git a/firmware/src/main.h b/firmware/src/main.h new file mode 100644 index 0000000..71fc85d --- /dev/null +++ b/firmware/src/main.h @@ -0,0 +1,30 @@ +#ifndef MAIN_H +#define MAIN_H + +#if F0 +#include "stm32f0xx_hal.h" +#elif F1 +#include "stm32f1xx_hal.h" +#elif F2 +#include "stm32f2xx_hal.h" +#elif F3 +#include "stm32f3xx_hal.h" +#elif F4 +#include "stm32f4xx_hal.h" +#elif F7 +#include "stm32f7xx_hal.h" +#elif L0 +#include "stm32l0xx_hal.h" +#elif L1 +#include "stm32l1xx_hal.h" +#elif L4 +#include "stm32l4xx_hal.h" +#else +#error "Unsupported STM32 Family" +#endif + +#define LED_PIN GPIO_PIN_5 +#define LED_GPIO_PORT GPIOA +#define LED_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() + +#endif // MAIN_H \ No newline at end of file