Merge branch 'ds1307_NVRAM'
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
8DF89ED150041C4CBC7CB9A9CAA90856=3B9AC612F80B3672D4AEDF95B2FAE837
|
8DF89ED150041C4CBC7CB9A9CAA90856=3B9AC612F80B3672D4AEDF95B2FAE837
|
||||||
DC22A860405A8BF2F2C095E5B6529F12=B906B5FA0271D057D2544B3C1B4A8DE5
|
DC22A860405A8BF2F2C095E5B6529F12=3B9AC612F80B3672D4AEDF95B2FAE837
|
||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
|
|||||||
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_minute,
|
||||||
com_setColour_second,
|
com_setColour_second,
|
||||||
com_setColour_background,
|
com_setColour_background,
|
||||||
|
com_readNV,
|
||||||
|
com_writeNV,
|
||||||
com_MAX_command
|
com_MAX_command
|
||||||
|
|
||||||
} commands_e;
|
} commands_e;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ void ws_Effect_RoudTheClock(void);
|
|||||||
void ws_Effect_RandRound(void);
|
void ws_Effect_RandRound(void);
|
||||||
void ws_Effect_RandRand(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_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);
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
// define LED marking 12:00 or 00:00
|
// define LED marking 12:00 or 00:00
|
||||||
|
|
||||||
#define LED_OFFSET 11
|
#define LED_OFFSET 12
|
||||||
|
|
||||||
void clock_update(ds1307_dev_t *ds1307_dev){
|
void clock_update(ds1307_dev_t *ds1307_dev){
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ void MX_DMA_Init(void)
|
|||||||
|
|
||||||
/* DMA interrupt init */
|
/* DMA interrupt init */
|
||||||
/* DMA1_Channel5_IRQn interrupt configuration */
|
/* 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);
|
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_decode(uint8_t data);
|
||||||
static uint8_t ds1307_bcd_encode(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
|
* @brief Write byte data from an specific address ds1307 RTC
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -12,6 +12,12 @@
|
|||||||
#include "clock.h"
|
#include "clock.h"
|
||||||
#include "ds1307.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 {
|
typedef struct {
|
||||||
uint8_t cmdId;
|
uint8_t cmdId;
|
||||||
|
|
||||||
@@ -25,7 +31,10 @@ typedef struct {
|
|||||||
uint8_t crc;
|
uint8_t crc;
|
||||||
} uartMessage_s;
|
} 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";
|
static uint8_t ok[] = "OK\n";
|
||||||
uint8_t myId[] = "Clock\n";
|
uint8_t myId[] = "Clock\n";
|
||||||
|
|
||||||
@@ -38,9 +47,44 @@ void (*commands[])(uint32_t) = {
|
|||||||
cmd_GetTime,
|
cmd_GetTime,
|
||||||
cmd_setColour_hour,
|
cmd_setColour_hour,
|
||||||
cmd_setColour_minute,
|
cmd_setColour_minute,
|
||||||
|
cmd_setColour_second,
|
||||||
|
cmd_setColour_background,
|
||||||
|
cmd_readNV,
|
||||||
|
cmd_writeNV,
|
||||||
cmd_setColour_second
|
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){
|
void setRxFlag(void){
|
||||||
RxComplete_fl = 1;
|
RxComplete_fl = 1;
|
||||||
@@ -128,6 +172,15 @@ void cmd_setColour_hour(uint32_t colour){
|
|||||||
|
|
||||||
clock_setColourHours(r, g, b);
|
clock_setColourHours(r, g, b);
|
||||||
|
|
||||||
|
uint8_t nv[] = {
|
||||||
|
NV_COLOUR_HOURS_ADDR,
|
||||||
|
r,
|
||||||
|
g,
|
||||||
|
b
|
||||||
|
};
|
||||||
|
|
||||||
|
cmd_writeNV(nv);
|
||||||
|
|
||||||
CDC_Transmit_FS(ok, sizeof(ok));
|
CDC_Transmit_FS(ok, sizeof(ok));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -141,6 +194,16 @@ void cmd_setColour_minute(uint32_t colour){
|
|||||||
|
|
||||||
clock_setColourMinutes(r, g, b);
|
clock_setColourMinutes(r, g, b);
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t nv[] = {
|
||||||
|
NV_COLOUR_MINUTES_ADDR,
|
||||||
|
r,
|
||||||
|
g,
|
||||||
|
b
|
||||||
|
};
|
||||||
|
|
||||||
|
cmd_writeNV(nv);
|
||||||
|
|
||||||
CDC_Transmit_FS(ok, sizeof(ok));
|
CDC_Transmit_FS(ok, sizeof(ok));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -154,6 +217,16 @@ void cmd_setColour_second(uint32_t colour){
|
|||||||
|
|
||||||
clock_setColourSeconds(r, g, b);
|
clock_setColourSeconds(r, g, b);
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t nv[] = {
|
||||||
|
NV_COLOUR_SECONDS_ADDR,
|
||||||
|
r,
|
||||||
|
g,
|
||||||
|
b
|
||||||
|
};
|
||||||
|
|
||||||
|
cmd_writeNV(nv);
|
||||||
|
|
||||||
CDC_Transmit_FS(ok, sizeof(ok));
|
CDC_Transmit_FS(ok, sizeof(ok));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -167,5 +240,15 @@ void cmd_setColour_background(uint32_t colour){
|
|||||||
|
|
||||||
clock_setColourBackground(r, g, b);
|
clock_setColourBackground(r, g, b);
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t nv[] = {
|
||||||
|
NV_COLOUR_BACKGND_ADDR,
|
||||||
|
r,
|
||||||
|
g,
|
||||||
|
b
|
||||||
|
};
|
||||||
|
|
||||||
|
cmd_writeNV(nv);
|
||||||
|
|
||||||
CDC_Transmit_FS(ok, sizeof(ok));
|
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);
|
__HAL_LINKDMA(tim_baseHandle,hdma[TIM_DMA_ID_CC1],hdma_tim2_ch1);
|
||||||
|
|
||||||
/* TIM2 interrupt Init */
|
/* TIM2 interrupt Init */
|
||||||
HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0);
|
HAL_NVIC_SetPriority(TIM2_IRQn, 6, 0);
|
||||||
HAL_NVIC_EnableIRQ(TIM2_IRQn);
|
HAL_NVIC_EnableIRQ(TIM2_IRQn);
|
||||||
/* USER CODE BEGIN TIM2_MspInit 1 */
|
/* USER CODE BEGIN TIM2_MspInit 1 */
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,13 @@
|
|||||||
#include "ws2812_effect.h"
|
#include "ws2812_effect.h"
|
||||||
//#include "clock.h"
|
//#include "clock.h"
|
||||||
#include <stdlib.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 {
|
typedef struct {
|
||||||
uint8_t r;
|
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_seconds = {0, 0, 250};
|
||||||
static colour_s colour_background = {0, 0, 0};
|
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){
|
void clock_setColourHours(uint8_t r, uint8_t g, uint8_t b){
|
||||||
colour_hours.r = r;
|
colour_hours.r = r;
|
||||||
colour_hours.g = g;
|
colour_hours.g = g;
|
||||||
|
|||||||
11
LedRing.ioc
11
LedRing.ioc
@@ -46,10 +46,10 @@ Mcu.PinsNb=13
|
|||||||
Mcu.ThirdPartyNb=0
|
Mcu.ThirdPartyNb=0
|
||||||
Mcu.UserConstants=
|
Mcu.UserConstants=
|
||||||
Mcu.UserName=STM32F103C6Tx
|
Mcu.UserName=STM32F103C6Tx
|
||||||
MxCube.Version=6.14.0
|
MxCube.Version=6.14.1
|
||||||
MxDb.Version=DB.6.0.140
|
MxDb.Version=DB.6.0.141
|
||||||
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
NVIC.DMA1_Channel5_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
|
NVIC.DMA1_Channel5_IRQn=true\:6\:0\:true\:false\:true\:false\:true\:true
|
||||||
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
NVIC.ForceEnableDMAVector=true
|
NVIC.ForceEnableDMAVector=true
|
||||||
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
@@ -59,7 +59,7 @@ NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
|||||||
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
|
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
|
||||||
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
|
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
|
||||||
NVIC.TIM2_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
NVIC.TIM2_IRQn=true\:6\:0\:true\:false\:true\:true\:true\:true
|
||||||
NVIC.USB_LP_CAN1_RX0_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
|
NVIC.USB_LP_CAN1_RX0_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
|
||||||
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
PA0-WKUP.Signal=S_TIM2_CH1_ETR
|
PA0-WKUP.Signal=S_TIM2_CH1_ETR
|
||||||
@@ -115,7 +115,7 @@ ProjectManager.ToolChainLocation=
|
|||||||
ProjectManager.UAScriptAfterPath=
|
ProjectManager.UAScriptAfterPath=
|
||||||
ProjectManager.UAScriptBeforePath=
|
ProjectManager.UAScriptBeforePath=
|
||||||
ProjectManager.UnderRoot=true
|
ProjectManager.UnderRoot=true
|
||||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_TIM2_Init-TIM2-false-HAL-true,5-MX_I2C1_Init-I2C1-false-HAL-true,6-MX_USART2_UART_Init-USART2-false-HAL-true
|
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_TIM2_Init-TIM2-false-HAL-true,5-MX_I2C1_Init-I2C1-false-HAL-true,6-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false
|
||||||
RCC.ADCFreqValue=36000000
|
RCC.ADCFreqValue=36000000
|
||||||
RCC.AHBFreq_Value=72000000
|
RCC.AHBFreq_Value=72000000
|
||||||
RCC.APB1CLKDivider=RCC_HCLK_DIV2
|
RCC.APB1CLKDivider=RCC_HCLK_DIV2
|
||||||
@@ -158,3 +158,4 @@ VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT
|
|||||||
VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Mode=CDC_FS
|
VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Mode=CDC_FS
|
||||||
VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Signal=USB_DEVICE_VS_USB_DEVICE_CDC_FS
|
VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Signal=USB_DEVICE_VS_USB_DEVICE_CDC_FS
|
||||||
board=custom
|
board=custom
|
||||||
|
isbadioc=false
|
||||||
|
|||||||
@@ -256,7 +256,6 @@ static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
|
|||||||
* @param Len: Number of data received (in bytes)
|
* @param Len: Number of data received (in bytes)
|
||||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
|
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
|
||||||
{
|
{
|
||||||
/* USER CODE BEGIN 6 */
|
/* USER CODE BEGIN 6 */
|
||||||
|
|||||||
Reference in New Issue
Block a user