UART commands work
This commit is contained in:
@@ -13,6 +13,13 @@
|
|||||||
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);
|
||||||
|
|
||||||
|
void clock_LedOffset(uint8_t offset);
|
||||||
|
|
||||||
|
void clock_setColourHours(uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
void clock_setColourMinutes(uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
void clock_setColourSeconds(uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
void clock_setColourBackground(uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* INC_CLOCK_H_ */
|
#endif /* INC_CLOCK_H_ */
|
||||||
|
|||||||
43
Core/Inc/myComms.h
Normal file
43
Core/Inc/myComms.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* muComms.h
|
||||||
|
*
|
||||||
|
* Created on: Mar 27, 2026
|
||||||
|
* Author: ewars
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef INC_MYCOMMS_H_
|
||||||
|
#define INC_MYCOMMS_H_
|
||||||
|
|
||||||
|
#include "stdint-gcc.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
com_WhoAmI,
|
||||||
|
com_setTime,
|
||||||
|
com_getTime,
|
||||||
|
com_setLedOffset,
|
||||||
|
com_setColour_hour,
|
||||||
|
com_setColour_minute,
|
||||||
|
com_setColour_second,
|
||||||
|
com_setColour_background,
|
||||||
|
com_MAX_command
|
||||||
|
|
||||||
|
} commands_e;
|
||||||
|
|
||||||
|
|
||||||
|
void cmd_UART_Request(void);
|
||||||
|
|
||||||
|
void cmd_RunCommand(commands_e cmd, uint32_t * input);
|
||||||
|
|
||||||
|
|
||||||
|
void cmd_WhoAmI(uint32_t);
|
||||||
|
void cmd_SetTime(uint32_t time);
|
||||||
|
void cmd_SetOffsetDiode(uint32_t diode);
|
||||||
|
void cmd_GetTime(uint32_t time);
|
||||||
|
void cmd_setColour_hour(uint32_t colour);
|
||||||
|
void cmd_setColour_minute(uint32_t colour);
|
||||||
|
void cmd_setColour_second(uint32_t colour);
|
||||||
|
void cmd_setColour_background(uint32_t colour);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* INC_MYCOMMS_H_ */
|
||||||
@@ -23,6 +23,7 @@ void ws2812_update(void);
|
|||||||
void ws2812_set_colour(uint8_t led, uint8_t red, uint8_t green, uint8_t blue);
|
void ws2812_set_colour(uint8_t led, uint8_t red, uint8_t green, uint8_t blue);
|
||||||
void ws2812_wait(void);
|
void ws2812_wait(void);
|
||||||
void ws2812_reset(void);
|
void ws2812_reset(void);
|
||||||
|
void ws2812_resetColour(uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
|
||||||
|
|
||||||
#endif /* INC_WS2812_DRV_H_ */
|
#endif /* INC_WS2812_DRV_H_ */
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ void ws_Effect_RandRound(void);
|
|||||||
void ws_Effect_RandRand(void);
|
void ws_Effect_RandRand(void);
|
||||||
|
|
||||||
void ws_effect_display_time(uint8_t hour, uint8_t minute, uint8_t second);
|
void ws_effect_display_time(uint8_t hour, uint8_t minute, uint8_t second);
|
||||||
|
|
||||||
void ws_effect_display_hour(uint8_t hour);
|
void ws_effect_display_hour(uint8_t hour);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,13 @@
|
|||||||
#include "clock.h"
|
#include "clock.h"
|
||||||
|
|
||||||
// define LED marking 12:00 or 00:00
|
// define LED marking 12:00 or 00:00
|
||||||
#define LED_ZERO_OFFSET 10
|
|
||||||
|
__attribute__((section(".noinit"))) volatile uint8_t ledOffset = 0;
|
||||||
|
|
||||||
|
|
||||||
|
void clock_LedOffset(uint8_t offset){
|
||||||
|
ledOffset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
uint8_t clock_convert_hours(uint8_t hours){
|
uint8_t clock_convert_hours(uint8_t hours){
|
||||||
@@ -26,7 +32,7 @@ uint8_t clock_convert_hours(uint8_t hours){
|
|||||||
h = hours;
|
h = hours;
|
||||||
}
|
}
|
||||||
|
|
||||||
led = 2 * h + LED_ZERO_OFFSET;
|
led = 2 * h + ledOffset;
|
||||||
if(led > 23){
|
if(led > 23){
|
||||||
led -= 24;
|
led -= 24;
|
||||||
}
|
}
|
||||||
@@ -44,7 +50,7 @@ uint8_t clock_convert_min_sec(uint8_t min_sec){
|
|||||||
if(min_sec < 60){
|
if(min_sec < 60){
|
||||||
led = (float) min_sec/(60/24);
|
led = (float) min_sec/(60/24);
|
||||||
|
|
||||||
led += LED_ZERO_OFFSET;
|
led += ledOffset;
|
||||||
if(led > 23){
|
if(led > 23){
|
||||||
led -= 24;
|
led -= 24;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -296,9 +296,10 @@ void ds1307_update(ds1307_dev_t *ds1307_dev){
|
|||||||
}
|
}
|
||||||
|
|
||||||
val = ds1307_get_minutes();
|
val = ds1307_get_minutes();
|
||||||
if(val != 255){
|
if(val != 255){
|
||||||
ds1307_dev->minutes = val;
|
ds1307_dev->minutes = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
ds1307_dev->hours = ds1307_get_hour();
|
ds1307_dev->hours = ds1307_get_hour();
|
||||||
ds1307_dev->day = ds1307_get_day();
|
ds1307_dev->day = ds1307_get_day();
|
||||||
ds1307_dev->date = ds1307_get_date();
|
ds1307_dev->date = ds1307_get_date();
|
||||||
|
|||||||
@@ -50,7 +50,7 @@
|
|||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
|
||||||
/* USER CODE BEGIN PV */
|
/* USER CODE BEGIN PV */
|
||||||
|
extern uint8_t UART_RxBuf[6];
|
||||||
/* USER CODE END PV */
|
/* USER CODE END PV */
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
@@ -122,6 +122,7 @@ int main(void)
|
|||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
/* USER CODE BEGIN 3 */
|
||||||
|
|
||||||
|
uint8_t UART_Buff[] = "Hello World\n";
|
||||||
|
|
||||||
|
|
||||||
#define EFFECT_TIME 10000
|
#define EFFECT_TIME 10000
|
||||||
@@ -141,10 +142,12 @@ int main(void)
|
|||||||
|
|
||||||
// ws_Effect_RoudTheClock();
|
// ws_Effect_RoudTheClock();
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
157
Core/Src/myComms.c
Normal file
157
Core/Src/myComms.c
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
/*
|
||||||
|
* myComms.c
|
||||||
|
*
|
||||||
|
* Created on: Mar 27, 2026
|
||||||
|
* Author: ewars
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "myComms.h"
|
||||||
|
#include "usart.h"
|
||||||
|
#include "clock.h"
|
||||||
|
|
||||||
|
#include "ds1307.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t cmdId;
|
||||||
|
|
||||||
|
struct{
|
||||||
|
uint8_t pByte_3;
|
||||||
|
uint8_t pByte_2;
|
||||||
|
uint8_t pByte_1;
|
||||||
|
uint8_t pByte_0;
|
||||||
|
} bytes;
|
||||||
|
|
||||||
|
uint8_t crc;
|
||||||
|
} uartMessage_s;
|
||||||
|
|
||||||
|
|
||||||
|
static uint8_t ok[] = "OK\n";
|
||||||
|
uint8_t myId[] = "Clock\n";
|
||||||
|
|
||||||
|
uint8_t UART_RxBuf[6] = {0};
|
||||||
|
|
||||||
|
void (*commands[])(uint32_t) = {
|
||||||
|
cmd_WhoAmI,
|
||||||
|
cmd_SetTime,
|
||||||
|
cmd_GetTime,
|
||||||
|
cmd_SetOffsetDiode,
|
||||||
|
cmd_setColour_hour,
|
||||||
|
cmd_setColour_minute,
|
||||||
|
cmd_setColour_second
|
||||||
|
};
|
||||||
|
|
||||||
|
void cmd_SetOffsetDiode(uint32_t diode){
|
||||||
|
|
||||||
|
uint8_t offset = (uint8_t) diode;
|
||||||
|
|
||||||
|
clock_LedOffset(offset);
|
||||||
|
|
||||||
|
HAL_UART_Transmit(&huart2, ok, sizeof(ok), 1000);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
|
||||||
|
|
||||||
|
cmd_UART_Request();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmd_UART_Request(void){
|
||||||
|
|
||||||
|
uartMessage_s* msg = (uartMessage_s*) &UART_RxBuf[0];
|
||||||
|
|
||||||
|
cmd_RunCommand((uint8_t) msg->cmdId, (uint32_t*) &msg->bytes);
|
||||||
|
|
||||||
|
HAL_UART_Transmit(&huart2, (uint8_t*) msg, sizeof(*msg), 1000);
|
||||||
|
|
||||||
|
HAL_UART_Transmit(&huart2, ok, sizeof(ok), 1000);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void cmd_RunCommand(commands_e cmd, uint32_t* input){
|
||||||
|
uint32_t i = *input;
|
||||||
|
if(cmd < com_MAX_command){
|
||||||
|
commands[cmd](i);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cmd_WhoAmI(uint32_t){
|
||||||
|
HAL_UART_Transmit(&huart2, myId, sizeof(myId), 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void cmd_SetTime(uint32_t time){
|
||||||
|
|
||||||
|
uint8_t h, m, s;
|
||||||
|
|
||||||
|
h = time & 0xFF;
|
||||||
|
m = time >> 8 & 0xFF;
|
||||||
|
s = time >> 16 & 0xFF;
|
||||||
|
|
||||||
|
ds1307_set_hour(h);
|
||||||
|
ds1307_set_minutes(m);
|
||||||
|
ds1307_set_second(s);
|
||||||
|
|
||||||
|
HAL_UART_Transmit(&huart2, ok, sizeof(ok), 1000);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmd_GetTime(uint32_t time){}
|
||||||
|
|
||||||
|
void cmd_setColour_hour(uint32_t colour){
|
||||||
|
|
||||||
|
uint8_t r, g, b;
|
||||||
|
|
||||||
|
r = colour & 0xFF;
|
||||||
|
g = colour >> 8 & 0xFF;
|
||||||
|
b = colour >> 16 & 0xFF;
|
||||||
|
|
||||||
|
clock_setColourHours(r, g, b);
|
||||||
|
|
||||||
|
HAL_UART_Transmit(&huart2, ok, sizeof(ok), 1000);
|
||||||
|
|
||||||
|
}
|
||||||
|
void cmd_setColour_minute(uint32_t colour){
|
||||||
|
|
||||||
|
uint8_t r, g, b;
|
||||||
|
|
||||||
|
r = colour & 0xFF;
|
||||||
|
g = colour >> 8 & 0xFF;
|
||||||
|
b = colour >> 16 & 0xFF;
|
||||||
|
|
||||||
|
clock_setColourMinutes(r, g, b);
|
||||||
|
|
||||||
|
HAL_UART_Transmit(&huart2, ok, sizeof(ok), 1000);
|
||||||
|
|
||||||
|
}
|
||||||
|
void cmd_setColour_second(uint32_t colour){
|
||||||
|
|
||||||
|
uint8_t r, g, b;
|
||||||
|
|
||||||
|
r = colour & 0xFF;
|
||||||
|
g = colour >> 8 & 0xFF;
|
||||||
|
b = colour >> 16 & 0xFF;
|
||||||
|
|
||||||
|
clock_setColourSeconds(r, g, b);
|
||||||
|
|
||||||
|
HAL_UART_Transmit(&huart2, ok, sizeof(ok), 1000);
|
||||||
|
|
||||||
|
}
|
||||||
|
void cmd_setColour_background(uint32_t colour){
|
||||||
|
|
||||||
|
uint8_t r, g, b;
|
||||||
|
|
||||||
|
r = colour & 0xFF;
|
||||||
|
g = colour >> 8 & 0xFF;
|
||||||
|
b = colour >> 16 & 0xFF;
|
||||||
|
|
||||||
|
clock_setColourBackground(r, g, b);
|
||||||
|
|
||||||
|
HAL_UART_Transmit(&huart2, ok, sizeof(ok), 1000);
|
||||||
|
}
|
||||||
@@ -43,6 +43,14 @@ void ws2812_set_colour(uint8_t led, uint8_t red, uint8_t green, uint8_t blue){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ws2812_resetColour(uint8_t r, uint8_t g, uint8_t b){
|
||||||
|
|
||||||
|
for(uint8_t i = 0; i < LED_N; i++){
|
||||||
|
ws2812_set_colour(i, r, g, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void ws2812_reset(void){
|
void ws2812_reset(void){
|
||||||
for(uint8_t i = 0; i < LED_N; i++){
|
for(uint8_t i = 0; i < LED_N; i++){
|
||||||
ws2812_set_colour(i, 0, 0, 0);
|
ws2812_set_colour(i, 0, 0, 0);
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
* Author: ewars
|
* Author: ewars
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "ws2812_effect.h"
|
|
||||||
#include "ws2812_drv.h"
|
#include "ws2812_drv.h"
|
||||||
|
#include "ws2812_effect.h"
|
||||||
|
#include "clock.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -19,6 +19,35 @@ typedef struct {
|
|||||||
static colour_s colour_hours = {250, 0, 0};
|
static colour_s colour_hours = {250, 0, 0};
|
||||||
static colour_s colour_minutes = {0, 250, 0};
|
static colour_s colour_minutes = {0, 250, 0};
|
||||||
static colour_s colour_seconds = {0, 0, 250};
|
static colour_s colour_seconds = {0, 0, 250};
|
||||||
|
static colour_s colour_background = {0, 0, 0};
|
||||||
|
|
||||||
|
void clock_setColourHours(uint8_t r, uint8_t g, uint8_t b){
|
||||||
|
colour_hours.r = r;
|
||||||
|
colour_hours.g = g;
|
||||||
|
colour_hours.b = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clock_setColourMinutes(uint8_t r, uint8_t g, uint8_t b){
|
||||||
|
colour_minutes.r = r;
|
||||||
|
colour_minutes.g = g;
|
||||||
|
colour_minutes.b = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clock_setColourSeconds(uint8_t r, uint8_t g, uint8_t b){
|
||||||
|
colour_seconds.r = r;
|
||||||
|
colour_seconds.g = g;
|
||||||
|
colour_seconds.b = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void clock_setColourBackground(uint8_t r, uint8_t g, uint8_t b){
|
||||||
|
|
||||||
|
colour_background.r = r;
|
||||||
|
colour_background.g = g;
|
||||||
|
colour_background.b = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ws_Effect_RoudTheClock(void){
|
void ws_Effect_RoudTheClock(void){
|
||||||
@@ -60,6 +89,8 @@ void ws_Effect_RandRound(void){
|
|||||||
void ws_effect_display_time(uint8_t hour, uint8_t minute, uint8_t second){
|
void ws_effect_display_time(uint8_t hour, uint8_t minute, uint8_t second){
|
||||||
|
|
||||||
ws2812_reset();
|
ws2812_reset();
|
||||||
|
//ws2812_resetColour(colour_background.r, colour_background.g, colour_background.b);
|
||||||
|
ws2812_update();
|
||||||
|
|
||||||
ws2812_set_colour(hour, colour_hours.r, colour_hours.g, colour_hours.b);
|
ws2812_set_colour(hour, colour_hours.r, colour_hours.g, colour_hours.b);
|
||||||
ws2812_update();
|
ws2812_update();
|
||||||
|
|||||||
Reference in New Issue
Block a user