Merge branch 'ds1307_NVRAM'
This commit is contained in:
17
Core/Inc/ComsRead.h
Normal file
17
Core/Inc/ComsRead.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* ComsRead.h
|
||||
*
|
||||
* Created on: Mar 29, 2026
|
||||
* Author: ewars
|
||||
*/
|
||||
|
||||
#ifndef INC_COMSREAD_H_
|
||||
#define INC_COMSREAD_H_
|
||||
|
||||
void readColour_Hours(uint8_t * data);
|
||||
void readColour_Minutes(uint8_t * data);
|
||||
void readColour_Seconds(uint8_t * data);
|
||||
void readColour_Background(uint8_t * data);
|
||||
|
||||
|
||||
#endif /* INC_COMSREAD_H_ */
|
||||
@@ -16,6 +16,8 @@ typedef enum {
|
||||
com_setColour_minute,
|
||||
com_setColour_second,
|
||||
com_setColour_background,
|
||||
com_readNV,
|
||||
com_writeNV,
|
||||
com_MAX_command
|
||||
|
||||
} commands_e;
|
||||
|
||||
@@ -16,6 +16,7 @@ void ws_Effect_RoudTheClock(void);
|
||||
void ws_Effect_RandRound(void);
|
||||
void ws_Effect_RandRand(void);
|
||||
|
||||
void ws_effect_setDisplayColoursNV(void);
|
||||
void ws_effect_display_time(uint8_t hour, uint8_t minute, uint8_t second);
|
||||
void ws_effect_display_hour(uint8_t hour);
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
// define LED marking 12:00 or 00:00
|
||||
|
||||
#define LED_OFFSET 11
|
||||
#define LED_OFFSET 12
|
||||
|
||||
void clock_update(ds1307_dev_t *ds1307_dev){
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ void MX_DMA_Init(void)
|
||||
|
||||
/* DMA interrupt init */
|
||||
/* DMA1_Channel5_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 0, 0);
|
||||
HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 6, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn);
|
||||
|
||||
}
|
||||
|
||||
@@ -42,6 +42,58 @@ static uint8_t ds1307_read_byte(uint8_t ds1307_reg_addres);
|
||||
static uint8_t ds1307_bcd_decode(uint8_t data);
|
||||
static uint8_t ds1307_bcd_encode(uint8_t data);
|
||||
|
||||
/*
|
||||
*
|
||||
Function designed to read embedded RAM data.
|
||||
Address range 0x08 to 0x3F
|
||||
56 bytes of data
|
||||
|
||||
addr: address of data to read 0x08 to 0x3F
|
||||
data: pointer to data
|
||||
len: number of bytes of data to read
|
||||
|
||||
*/
|
||||
|
||||
uint8_t ds1307_read_user_RAM(uint8_t addr, uint8_t * data, uint8_t len){
|
||||
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
for(uint8_t i = 0; i < len; i++){
|
||||
uint8_t resp = ds1307_read_byte(addr + i);
|
||||
*(data + i) = resp;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
Function designed to write embedded RAM data.
|
||||
Address range 0x08 to 0x3F
|
||||
56 bytes of data
|
||||
|
||||
addr: address of data to read 0x08 to 0x3F
|
||||
data: pointer to data
|
||||
len: number of bytes of data to read
|
||||
|
||||
*/
|
||||
|
||||
uint8_t ds1307_write_user_RAM(uint8_t addr, uint8_t * data, uint8_t len){
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
uint8_t buff[4] = {0};
|
||||
buff[0] = addr;
|
||||
|
||||
for(uint8_t i = 0; i < len; i++){
|
||||
|
||||
ds1307_write_byte(addr + i, *(data + i));
|
||||
HAL_Delay(5);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write byte data from an specific address ds1307 RTC
|
||||
*
|
||||
|
||||
@@ -12,6 +12,12 @@
|
||||
#include "clock.h"
|
||||
#include "ds1307.h"
|
||||
|
||||
|
||||
#define NV_COLOUR_HOURS_ADDR 0x08
|
||||
#define NV_COLOUR_MINUTES_ADDR 0x0B
|
||||
#define NV_COLOUR_SECONDS_ADDR 0x0E
|
||||
#define NV_COLOUR_BACKGND_ADDR 0x11
|
||||
|
||||
typedef struct {
|
||||
uint8_t cmdId;
|
||||
|
||||
@@ -25,7 +31,10 @@ typedef struct {
|
||||
uint8_t crc;
|
||||
} uartMessage_s;
|
||||
|
||||
static void cmd_readNV(uint32_t data);
|
||||
static void cmd_writeNV(uint8_t data);
|
||||
|
||||
static uint8_t nok[] = "NOK\n";
|
||||
static uint8_t ok[] = "OK\n";
|
||||
uint8_t myId[] = "Clock\n";
|
||||
|
||||
@@ -38,9 +47,44 @@ void (*commands[])(uint32_t) = {
|
||||
cmd_GetTime,
|
||||
cmd_setColour_hour,
|
||||
cmd_setColour_minute,
|
||||
cmd_setColour_second,
|
||||
cmd_setColour_background,
|
||||
cmd_readNV,
|
||||
cmd_writeNV,
|
||||
cmd_setColour_second
|
||||
};
|
||||
|
||||
static void cmd_readNV(uint32_t data){
|
||||
HAL_StatusTypeDef status = HAL_ERROR;
|
||||
|
||||
uint8_t addr = (uint8_t) data;
|
||||
uint8_t respBuf[3] = {0};
|
||||
|
||||
status = ds1307_read_user_RAM(addr, respBuf, sizeof(respBuf));
|
||||
|
||||
if(HAL_OK == status){
|
||||
CDC_Transmit_FS(respBuf, sizeof(respBuf));
|
||||
}
|
||||
else{
|
||||
CDC_Transmit_FS(nok, sizeof(nok));
|
||||
}
|
||||
}
|
||||
|
||||
static void cmd_writeNV(uint8_t data){
|
||||
HAL_StatusTypeDef status = HAL_ERROR;
|
||||
|
||||
|
||||
status = ds1307_write_user_RAM(UART_RxBuf[1], &UART_RxBuf[2], 3);
|
||||
|
||||
if(HAL_OK == status){
|
||||
CDC_Transmit_FS(ok, sizeof(ok));
|
||||
}
|
||||
else{
|
||||
CDC_Transmit_FS(nok, sizeof(nok));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void setRxFlag(void){
|
||||
RxComplete_fl = 1;
|
||||
@@ -128,6 +172,15 @@ void cmd_setColour_hour(uint32_t colour){
|
||||
|
||||
clock_setColourHours(r, g, b);
|
||||
|
||||
uint8_t nv[] = {
|
||||
NV_COLOUR_HOURS_ADDR,
|
||||
r,
|
||||
g,
|
||||
b
|
||||
};
|
||||
|
||||
cmd_writeNV(nv);
|
||||
|
||||
CDC_Transmit_FS(ok, sizeof(ok));
|
||||
|
||||
}
|
||||
@@ -141,6 +194,16 @@ void cmd_setColour_minute(uint32_t colour){
|
||||
|
||||
clock_setColourMinutes(r, g, b);
|
||||
|
||||
|
||||
uint8_t nv[] = {
|
||||
NV_COLOUR_MINUTES_ADDR,
|
||||
r,
|
||||
g,
|
||||
b
|
||||
};
|
||||
|
||||
cmd_writeNV(nv);
|
||||
|
||||
CDC_Transmit_FS(ok, sizeof(ok));
|
||||
|
||||
}
|
||||
@@ -154,6 +217,16 @@ void cmd_setColour_second(uint32_t colour){
|
||||
|
||||
clock_setColourSeconds(r, g, b);
|
||||
|
||||
|
||||
uint8_t nv[] = {
|
||||
NV_COLOUR_SECONDS_ADDR,
|
||||
r,
|
||||
g,
|
||||
b
|
||||
};
|
||||
|
||||
cmd_writeNV(nv);
|
||||
|
||||
CDC_Transmit_FS(ok, sizeof(ok));
|
||||
|
||||
}
|
||||
@@ -167,5 +240,15 @@ void cmd_setColour_background(uint32_t colour){
|
||||
|
||||
clock_setColourBackground(r, g, b);
|
||||
|
||||
|
||||
uint8_t nv[] = {
|
||||
NV_COLOUR_BACKGND_ADDR,
|
||||
r,
|
||||
g,
|
||||
b
|
||||
};
|
||||
|
||||
cmd_writeNV(nv);
|
||||
|
||||
CDC_Transmit_FS(ok, sizeof(ok));
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
|
||||
__HAL_LINKDMA(tim_baseHandle,hdma[TIM_DMA_ID_CC1],hdma_tim2_ch1);
|
||||
|
||||
/* TIM2 interrupt Init */
|
||||
HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0);
|
||||
HAL_NVIC_SetPriority(TIM2_IRQn, 6, 0);
|
||||
HAL_NVIC_EnableIRQ(TIM2_IRQn);
|
||||
/* USER CODE BEGIN TIM2_MspInit 1 */
|
||||
|
||||
|
||||
@@ -9,6 +9,13 @@
|
||||
#include "ws2812_effect.h"
|
||||
//#include "clock.h"
|
||||
#include <stdlib.h>
|
||||
#include "ds1307.h"
|
||||
|
||||
#define NV_COLOUR_HOURS_ADDR 0x08
|
||||
#define NV_COLOUR_MINUTES_ADDR 0x0B
|
||||
#define NV_COLOUR_SECONDS_ADDR 0x0E
|
||||
#define NV_COLOUR_BACKGND_ADDR 0x11
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint8_t r;
|
||||
@@ -21,6 +28,32 @@ static colour_s colour_minutes = {0, 250, 0};
|
||||
static colour_s colour_seconds = {0, 0, 250};
|
||||
static colour_s colour_background = {0, 0, 0};
|
||||
|
||||
void ws_effect_setDisplayColoursNV(void){
|
||||
|
||||
uint8_t rxBuf[3] = {0};
|
||||
|
||||
ds1307_read_user_RAM(NV_COLOUR_HOURS_ADDR, rxBuf, 3);
|
||||
colour_hours.r = rxBuf[0];
|
||||
colour_hours.g = rxBuf[1];
|
||||
colour_hours.b = rxBuf[2];
|
||||
|
||||
ds1307_read_user_RAM(NV_COLOUR_MINUTES_ADDR, rxBuf, 3);
|
||||
colour_minutes.r = rxBuf[0];
|
||||
colour_minutes.g = rxBuf[1];
|
||||
colour_minutes.b = rxBuf[2];
|
||||
|
||||
ds1307_read_user_RAM(NV_COLOUR_SECONDS_ADDR, rxBuf, 3);
|
||||
colour_seconds.r = rxBuf[0];
|
||||
colour_seconds.g = rxBuf[1];
|
||||
colour_seconds.b = rxBuf[2];
|
||||
|
||||
ds1307_read_user_RAM(NV_COLOUR_BACKGND_ADDR, rxBuf, 3);
|
||||
colour_background.r = rxBuf[0];
|
||||
colour_background.g = rxBuf[1];
|
||||
colour_background.b = rxBuf[2];
|
||||
|
||||
}
|
||||
|
||||
void clock_setColourHours(uint8_t r, uint8_t g, uint8_t b){
|
||||
colour_hours.r = r;
|
||||
colour_hours.g = g;
|
||||
|
||||
Reference in New Issue
Block a user