Architecture cleanup

This commit is contained in:
StefansE
2026-03-29 16:26:57 +02:00
parent 21874c4455
commit 3bab7eda33
10 changed files with 41 additions and 57 deletions

View File

@@ -9,7 +9,15 @@
#define INC_CLOCK_H_ #define INC_CLOCK_H_
#include <stdint-gcc.h> #include <stdint-gcc.h>
#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_hours(uint8_t hours);
uint8_t clock_convert_min_sec(uint8_t min_sec); uint8_t clock_convert_min_sec(uint8_t min_sec);

View File

@@ -11,7 +11,6 @@
#define DS1307_H_ #define DS1307_H_
#include "i2c.h" #include "i2c.h"
//#include "DBG.h"
typedef enum { 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, 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); 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_ */ #endif /* DS1307_H_ */

View File

@@ -8,8 +8,6 @@
#ifndef INC_MYCOMMS_H_ #ifndef INC_MYCOMMS_H_
#define INC_MYCOMMS_H_ #define INC_MYCOMMS_H_
#include "stdint-gcc.h"
typedef enum { typedef enum {
com_WhoAmI, com_WhoAmI,
com_setTime, com_setTime,

View File

@@ -10,6 +10,7 @@
#include "stdint-gcc.h" #include "stdint-gcc.h"
void ws_Effect_InitModule(void);
void ws_Effect_RoudTheClock(void); void ws_Effect_RoudTheClock(void);
void ws_Effect_RandRound(void); void ws_Effect_RandRound(void);

View File

@@ -12,6 +12,16 @@
#define LED_OFFSET 11 #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){ uint8_t clock_convert_hours(uint8_t hours){

View File

@@ -123,6 +123,9 @@ uint8_t ds1307_get_clock_halt(void){
if(read != 255){ if(read != 255){
return (read & 0x80) >> 7; 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); 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 * @brief This function helps to scan all connected devices on our I2C peripheral
* *

View File

@@ -26,12 +26,11 @@
/* Private includes ----------------------------------------------------------*/ /* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN 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 "usbd_cdc_if.h"
#include "ws2812_effect.h"
#include "clock.h"
#include "myComms.h"
/* USER CODE END Includes */ /* USER CODE END Includes */
@@ -126,13 +125,10 @@ int main(void)
HAL_TIM_Base_Start(&htim2); HAL_TIM_Base_Start(&htim2);
ws_Effect_InitModule();
ws2812_Init();
uint32_t mytimer = 0;
// RTC config // RTC config
ds1307_init(); clock_InitModule();
// ds1307_config(0, 10, 19, THURSDAY, 26, MARCH, 2026, +1, 33); // ds1307_config(0, 10, 19, THURSDAY, 26, MARCH, 2026, +1, 33);
@@ -145,14 +141,7 @@ int main(void)
/* USER CODE END WHILE */ /* USER CODE END WHILE */
/* USER CODE BEGIN 3 */ /* USER CODE BEGIN 3 */
clock_update(&my_rtc);
uint8_t UART_Buff[] = "Hello World\n";
#define EFFECT_TIME 10000
ds1307_update(&my_rtc);
uint8_t hour = my_rtc.hours; uint8_t hour = my_rtc.hours;
uint8_t minutes = my_rtc.minutes; uint8_t minutes = my_rtc.minutes;
@@ -166,19 +155,10 @@ uint8_t UART_Buff[] = "Hello World\n";
// ws_Effect_RoudTheClock(); // ws_Effect_RoudTheClock();
//CDC_Transmit_FS(UART_Buff, sizeof(UART_Buff));
RxCpltCallback(); RxCpltCallback();
//HAL_UART_Receive_IT(&huart2, UART_RxBuf, sizeof(UART_RxBuf));
HAL_GPIO_TogglePin(LED_Green_GPIO_Port, LED_Green_Pin); HAL_GPIO_TogglePin(LED_Green_GPIO_Port, LED_Green_Pin);
//HAL_UART_Transmit(&huart2, UART_Buff, sizeof(UART_Buff), 1000);
HAL_Delay(1000); HAL_Delay(1000);
} }

View File

@@ -5,14 +5,11 @@
* Author: ewars * Author: ewars
*/ */
#include "myComms.h"
#include "usbd_cdc_if.h" #include "usbd_cdc_if.h"
// #include "usart.h"
#include "clock.h"
#include "stdio.h" #include "stdio.h"
#include "myComms.h"
#include "clock.h"
#include "ds1307.h" #include "ds1307.h"
typedef struct { typedef struct {

View File

@@ -7,8 +7,8 @@
#include <ws2812_drv.h> #include <ws2812_drv.h>
#include "stm32f1xx_hal.h" #include "stm32f1xx_hal.h"
#include "tim.h"
extern htim2;
static void set_byte(uint32_t pos, uint8_t value); 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){ void ws2812_wait(void){
while(HAL_TIM_GetChannelState(&htim2, TIM_CHANNEL_1)){} while(HAL_TIM_GetChannelState(&htim2, (uint32_t) TIM_CHANNEL_1)){}
} }

View File

@@ -7,7 +7,7 @@
#include "ws2812_drv.h" #include "ws2812_drv.h"
#include "ws2812_effect.h" #include "ws2812_effect.h"
#include "clock.h" //#include "clock.h"
#include <stdlib.h> #include <stdlib.h>
typedef struct { 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){ void clock_setColourBackground(uint8_t r, uint8_t g, uint8_t b){
colour_background.r = r; 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){ void ws_Effect_RoudTheClock(void){
#define RAND_MAX 25
uint8_t r = rand(); uint8_t r = rand();
uint8_t g = rand(); uint8_t g = rand();
uint8_t b = rand(); uint8_t b = rand();
@@ -63,7 +68,6 @@ void ws_Effect_RoudTheClock(void){
ws2812_set_colour(led, r, g, b); ws2812_set_colour(led, r, g, b);
ws2812_update(); ws2812_update();
HAL_Delay(20);
} }
} }
@@ -71,7 +75,6 @@ void ws_Effect_RoudTheClock(void){
void ws_Effect_RandRound(void){ void ws_Effect_RandRound(void){
#define RAND_MAX 25
uint8_t r = rand(); uint8_t r = rand();
uint8_t g = rand(); uint8_t g = rand();
uint8_t b = rand(); uint8_t b = rand();
@@ -82,7 +85,6 @@ void ws_Effect_RandRound(void){
ws2812_set_colour(led, r, g, b); ws2812_set_colour(led, r, g, b);
ws2812_update(); 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_update();
ws2812_set_colour(second, colour_seconds.r, colour_seconds.g, colour_seconds.b); ws2812_set_colour(second, colour_seconds.r, colour_seconds.g, colour_seconds.b);
ws2812_update(); ws2812_update();
} }
void ws_effect_display_hour(uint8_t hour){ 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){ void ws_Effect_RandRand(void){
#define RAND_MAX 25
uint8_t r = rand(); uint8_t r = rand();
uint8_t g = rand(); uint8_t g = rand();
uint8_t b = rand(); uint8_t b = rand();
#define RAND_MAX 24
uint8_t led = rand(); uint8_t led = rand();
ws2812_set_colour(led, r, g, b); ws2812_set_colour(led, r, g, b);
ws2812_update(); ws2812_update();
HAL_Delay(1);
} }