From 3bab7eda33b3c67548b6c2954ab26811e21bb936 Mon Sep 17 00:00:00 2001 From: StefansE Date: Sun, 29 Mar 2026 16:26:57 +0200 Subject: [PATCH] Architecture cleanup --- Core/Inc/clock.h | 8 ++++++++ Core/Inc/ds1307.h | 3 --- Core/Inc/myComms.h | 2 -- Core/Inc/ws2812_effect.h | 1 + Core/Src/clock.c | 10 ++++++++++ Core/Src/ds1307.c | 13 ++++--------- Core/Src/main.c | 34 +++++++--------------------------- Core/Src/myComms.c | 7 ++----- Core/Src/ws2812_drv.c | 4 ++-- Core/Src/ws2812_effect.c | 16 +++++++--------- 10 files changed, 41 insertions(+), 57 deletions(-) diff --git a/Core/Inc/clock.h b/Core/Inc/clock.h index f679ebb..5a8c935 100644 --- a/Core/Inc/clock.h +++ b/Core/Inc/clock.h @@ -9,7 +9,15 @@ #define INC_CLOCK_H_ #include +#include "ds1307.h" +// functions from lower layer +void clock_InitModule(void); +void clock_update(ds1307_dev_t *ds1307_dev); + + + +// functions from service layer uint8_t clock_convert_hours(uint8_t hours); uint8_t clock_convert_min_sec(uint8_t min_sec); diff --git a/Core/Inc/ds1307.h b/Core/Inc/ds1307.h index 6bbabfa..d47caa1 100644 --- a/Core/Inc/ds1307.h +++ b/Core/Inc/ds1307.h @@ -11,7 +11,6 @@ #define DS1307_H_ #include "i2c.h" -//#include "DBG.h" typedef enum { @@ -94,7 +93,5 @@ void ds1307_update(ds1307_dev_t *ds1307_dev); void ds1307_config(uint8_t seconds, uint8_t minutes, uint8_t hours,ds1307_days_t day, uint8_t date, ds1307_months_t month, uint16_t year, int8_t t_zone_hour, int8_t t_zone_min); -void ds1307_log_uart(ds1307_dev_t *ds1307_dev); - #endif /* DS1307_H_ */ diff --git a/Core/Inc/myComms.h b/Core/Inc/myComms.h index 9ad3c43..1ddcba9 100644 --- a/Core/Inc/myComms.h +++ b/Core/Inc/myComms.h @@ -8,8 +8,6 @@ #ifndef INC_MYCOMMS_H_ #define INC_MYCOMMS_H_ -#include "stdint-gcc.h" - typedef enum { com_WhoAmI, com_setTime, diff --git a/Core/Inc/ws2812_effect.h b/Core/Inc/ws2812_effect.h index 7825208..c97665b 100644 --- a/Core/Inc/ws2812_effect.h +++ b/Core/Inc/ws2812_effect.h @@ -10,6 +10,7 @@ #include "stdint-gcc.h" +void ws_Effect_InitModule(void); void ws_Effect_RoudTheClock(void); void ws_Effect_RandRound(void); diff --git a/Core/Src/clock.c b/Core/Src/clock.c index b4d96d4..ead2dcc 100644 --- a/Core/Src/clock.c +++ b/Core/Src/clock.c @@ -12,6 +12,16 @@ #define LED_OFFSET 11 +void clock_update(ds1307_dev_t *ds1307_dev){ + + ds1307_update(ds1307_dev); +} + +void clock_InitModule(void){ + + ds1307_init(); + +} uint8_t clock_convert_hours(uint8_t hours){ diff --git a/Core/Src/ds1307.c b/Core/Src/ds1307.c index b5232c6..e9ed2fa 100644 --- a/Core/Src/ds1307.c +++ b/Core/Src/ds1307.c @@ -123,6 +123,9 @@ uint8_t ds1307_get_clock_halt(void){ if(read != 255){ return (read & 0x80) >> 7; } + else{ + return 255; + } } /** @@ -334,15 +337,7 @@ void ds1307_config(uint8_t seconds, uint8_t minutes, uint8_t hours,ds1307_days_t ds1307_set_time_zone(t_zone_hour, t_zone_min); } -/** - * @brief: Display ds1307 info by UART, @todo you need to implement your printf function! - * - * @param: ds1307_dev ds1307 struct pointer - */ -void ds1307_log_uart(ds1307_dev_t *ds1307_dev){ - DBG_print("%d:%d:%d %d/%d/%d\n",ds1307_dev->hours,ds1307_dev->minutes,ds1307_dev->seconds, - ds1307_dev->date,ds1307_dev->month,ds1307_dev->year); -} + /** * @brief This function helps to scan all connected devices on our I2C peripheral * diff --git a/Core/Src/main.c b/Core/Src/main.c index f97f14a..6d225ae 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -26,12 +26,11 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ -#include "ws2812_drv.h" -#include "ws2812_effect.h" -#include "ds1307.h" -#include "clock.h" - #include "usbd_cdc_if.h" +#include "ws2812_effect.h" +#include "clock.h" +#include "myComms.h" + /* USER CODE END Includes */ @@ -126,13 +125,10 @@ int main(void) HAL_TIM_Base_Start(&htim2); - - ws2812_Init(); - - uint32_t mytimer = 0; + ws_Effect_InitModule(); // RTC config - ds1307_init(); + clock_InitModule(); // ds1307_config(0, 10, 19, THURSDAY, 26, MARCH, 2026, +1, 33); @@ -145,14 +141,7 @@ int main(void) /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ - -uint8_t UART_Buff[] = "Hello World\n"; - - -#define EFFECT_TIME 10000 - - - ds1307_update(&my_rtc); + clock_update(&my_rtc); uint8_t hour = my_rtc.hours; uint8_t minutes = my_rtc.minutes; @@ -166,19 +155,10 @@ uint8_t UART_Buff[] = "Hello World\n"; // ws_Effect_RoudTheClock(); - - - //CDC_Transmit_FS(UART_Buff, sizeof(UART_Buff)); - RxCpltCallback(); - - //HAL_UART_Receive_IT(&huart2, UART_RxBuf, sizeof(UART_RxBuf)); - HAL_GPIO_TogglePin(LED_Green_GPIO_Port, LED_Green_Pin); - //HAL_UART_Transmit(&huart2, UART_Buff, sizeof(UART_Buff), 1000); - HAL_Delay(1000); } diff --git a/Core/Src/myComms.c b/Core/Src/myComms.c index fbdecb8..e8816bf 100644 --- a/Core/Src/myComms.c +++ b/Core/Src/myComms.c @@ -5,14 +5,11 @@ * Author: ewars */ - -#include "myComms.h" #include "usbd_cdc_if.h" -// #include "usart.h" -#include "clock.h" - #include "stdio.h" +#include "myComms.h" +#include "clock.h" #include "ds1307.h" typedef struct { diff --git a/Core/Src/ws2812_drv.c b/Core/Src/ws2812_drv.c index bd13d22..d9b9127 100644 --- a/Core/Src/ws2812_drv.c +++ b/Core/Src/ws2812_drv.c @@ -7,8 +7,8 @@ #include #include "stm32f1xx_hal.h" +#include "tim.h" -extern htim2; static void set_byte(uint32_t pos, uint8_t value); @@ -74,7 +74,7 @@ static void set_byte(uint32_t pos, uint8_t value) void ws2812_wait(void){ - while(HAL_TIM_GetChannelState(&htim2, TIM_CHANNEL_1)){} + while(HAL_TIM_GetChannelState(&htim2, (uint32_t) TIM_CHANNEL_1)){} } diff --git a/Core/Src/ws2812_effect.c b/Core/Src/ws2812_effect.c index a092e42..8839d9a 100644 --- a/Core/Src/ws2812_effect.c +++ b/Core/Src/ws2812_effect.c @@ -7,7 +7,7 @@ #include "ws2812_drv.h" #include "ws2812_effect.h" -#include "clock.h" +//#include "clock.h" #include typedef struct { @@ -40,6 +40,12 @@ void clock_setColourSeconds(uint8_t r, uint8_t g, uint8_t b){ } +void ws_Effect_InitModule(void){ + + ws2812_Init(); + +} + void clock_setColourBackground(uint8_t r, uint8_t g, uint8_t b){ colour_background.r = r; @@ -52,7 +58,6 @@ void clock_setColourBackground(uint8_t r, uint8_t g, uint8_t b){ void ws_Effect_RoudTheClock(void){ - #define RAND_MAX 25 uint8_t r = rand(); uint8_t g = rand(); uint8_t b = rand(); @@ -63,7 +68,6 @@ void ws_Effect_RoudTheClock(void){ ws2812_set_colour(led, r, g, b); ws2812_update(); - HAL_Delay(20); } } @@ -71,7 +75,6 @@ void ws_Effect_RoudTheClock(void){ void ws_Effect_RandRound(void){ - #define RAND_MAX 25 uint8_t r = rand(); uint8_t g = rand(); uint8_t b = rand(); @@ -82,7 +85,6 @@ void ws_Effect_RandRound(void){ ws2812_set_colour(led, r, g, b); ws2812_update(); - HAL_Delay(20); } } @@ -98,7 +100,6 @@ void ws_effect_display_time(uint8_t hour, uint8_t minute, uint8_t second){ ws2812_update(); ws2812_set_colour(second, colour_seconds.r, colour_seconds.g, colour_seconds.b); ws2812_update(); - } void ws_effect_display_hour(uint8_t hour){ @@ -111,15 +112,12 @@ void ws_effect_display_hour(uint8_t hour){ void ws_Effect_RandRand(void){ - #define RAND_MAX 25 uint8_t r = rand(); uint8_t g = rand(); uint8_t b = rand(); - #define RAND_MAX 24 uint8_t led = rand(); ws2812_set_colour(led, r, g, b); ws2812_update(); - HAL_Delay(1); }