Fixed formatting
This commit is contained in:
@@ -6,9 +6,11 @@
|
|||||||
#define I2C_SCL_PIN 41
|
#define I2C_SCL_PIN 41
|
||||||
#define I2C_SDA_PIN 42
|
#define I2C_SDA_PIN 42
|
||||||
|
|
||||||
namespace drivers {
|
namespace drivers
|
||||||
|
{
|
||||||
|
|
||||||
class I2C {
|
class I2C
|
||||||
|
{
|
||||||
private:
|
private:
|
||||||
bool isInitialized = false;
|
bool isInitialized = false;
|
||||||
std::mutex busy;
|
std::mutex busy;
|
||||||
@@ -19,7 +21,6 @@ namespace drivers {
|
|||||||
|
|
||||||
const bool Read(const uint8_t deviceAddr, const uint8_t deviceReg, const uint8_t len, std::vector<uint8_t> &data);
|
const bool Read(const uint8_t deviceAddr, const uint8_t deviceReg, const uint8_t len, std::vector<uint8_t> &data);
|
||||||
const bool Write(const uint8_t deviceAddr, const uint8_t deviceReg, const std::vector<uint8_t> &data);
|
const bool Write(const uint8_t deviceAddr, const uint8_t deviceReg, const std::vector<uint8_t> &data);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +1,31 @@
|
|||||||
#include "WS_PCF85063.h"
|
#include "WS_PCF85063.h"
|
||||||
|
|
||||||
datetime_t datetime= {0};
|
datetime_t datetime = {0};
|
||||||
datetime_t Update_datetime= {0};
|
datetime_t Update_datetime = {0};
|
||||||
static uint8_t decToBcd(int val);
|
static uint8_t decToBcd(int val);
|
||||||
static int bcdToDec(uint8_t val);
|
static int bcdToDec(uint8_t val);
|
||||||
|
|
||||||
|
void Time_printf(void *parameter)
|
||||||
void Time_printf(void *parameter) {
|
{
|
||||||
while(1){
|
while (1)
|
||||||
|
{
|
||||||
char datetime_str[50];
|
char datetime_str[50];
|
||||||
datetime_to_str(datetime_str,datetime);
|
datetime_to_str(datetime_str, datetime);
|
||||||
printf("Time:%s\r\n",datetime_str);
|
printf("Time:%s\r\n", datetime_str);
|
||||||
vTaskDelay(pdMS_TO_TICKS(500));
|
vTaskDelay(pdMS_TO_TICKS(500));
|
||||||
}
|
}
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
void PCF85063_Init(void) // PCF85063 initialized
|
void PCF85063_Init(void) // PCF85063 initialized
|
||||||
{
|
{
|
||||||
uint8_t Value = RTC_CTRL_1_DEFAULT|RTC_CTRL_1_CAP_SEL;
|
uint8_t Value = RTC_CTRL_1_DEFAULT | RTC_CTRL_1_CAP_SEL;
|
||||||
|
|
||||||
I2C_Write(PCF85063_ADDRESS, RTC_CTRL_1_ADDR, &Value, 1);
|
I2C_Write(PCF85063_ADDRESS, RTC_CTRL_1_ADDR, &Value, 1);
|
||||||
I2C_Read(PCF85063_ADDRESS, RTC_CTRL_1_ADDR, &Value, 1);
|
I2C_Read(PCF85063_ADDRESS, RTC_CTRL_1_ADDR, &Value, 1);
|
||||||
if(Value & RTC_CTRL_1_STOP)
|
if (Value & RTC_CTRL_1_STOP)
|
||||||
printf("PCF85063 failed to be initialized.state :%d\r\n",Value);
|
printf("PCF85063 failed to be initialized.state :%d\r\n", Value);
|
||||||
else
|
else
|
||||||
printf("PCF85063 is running,state :%d\r\n",Value);
|
printf("PCF85063 is running,state :%d\r\n", Value);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Update_datetime.year = 2024;
|
// Update_datetime.year = 2024;
|
||||||
@@ -42,8 +43,7 @@ void PCF85063_Init(void) // PCF85063 initialized
|
|||||||
NULL,
|
NULL,
|
||||||
3,
|
3,
|
||||||
NULL,
|
NULL,
|
||||||
0
|
0);
|
||||||
);
|
|
||||||
// xTaskCreatePinnedToCore(
|
// xTaskCreatePinnedToCore(
|
||||||
// Time_printf,
|
// Time_printf,
|
||||||
// "Time_printf",
|
// "Time_printf",
|
||||||
@@ -55,8 +55,10 @@ void PCF85063_Init(void) // PCF85063 initialized
|
|||||||
// );
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
void PCF85063Task(void *parameter) {
|
void PCF85063Task(void *parameter)
|
||||||
while(1){
|
{
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
PCF85063_Read_Time(&datetime);
|
PCF85063_Read_Time(&datetime);
|
||||||
vTaskDelay(pdMS_TO_TICKS(100));
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
}
|
}
|
||||||
@@ -65,9 +67,9 @@ void PCF85063Task(void *parameter) {
|
|||||||
|
|
||||||
void PCF85063_Reset() // Reset PCF85063
|
void PCF85063_Reset() // Reset PCF85063
|
||||||
{
|
{
|
||||||
uint8_t Value = RTC_CTRL_1_DEFAULT|RTC_CTRL_1_CAP_SEL|RTC_CTRL_1_SR;
|
uint8_t Value = RTC_CTRL_1_DEFAULT | RTC_CTRL_1_CAP_SEL | RTC_CTRL_1_SR;
|
||||||
esp_err_t ret = I2C_Write(PCF85063_ADDRESS, RTC_CTRL_1_ADDR, &Value, 1);
|
esp_err_t ret = I2C_Write(PCF85063_ADDRESS, RTC_CTRL_1_ADDR, &Value, 1);
|
||||||
if(ret != ESP_OK)
|
if (ret != ESP_OK)
|
||||||
printf("PCF85063 : Reset failure\r\n");
|
printf("PCF85063 : Reset failure\r\n");
|
||||||
}
|
}
|
||||||
void PCF85063_Set_Time(datetime_t time) // Set Time
|
void PCF85063_Set_Time(datetime_t time) // Set Time
|
||||||
@@ -76,7 +78,7 @@ void PCF85063_Set_Time(datetime_t time) // Set Time
|
|||||||
decToBcd(time.minute),
|
decToBcd(time.minute),
|
||||||
decToBcd(time.hour)};
|
decToBcd(time.hour)};
|
||||||
esp_err_t ret = I2C_Write(PCF85063_ADDRESS, RTC_SECOND_ADDR, buf, sizeof(buf));
|
esp_err_t ret = I2C_Write(PCF85063_ADDRESS, RTC_SECOND_ADDR, buf, sizeof(buf));
|
||||||
if(ret != ESP_OK)
|
if (ret != ESP_OK)
|
||||||
printf("PCF85063 : Time setting failure\r\n");
|
printf("PCF85063 : Time setting failure\r\n");
|
||||||
}
|
}
|
||||||
void PCF85063_Set_Date(datetime_t date) // Set Date
|
void PCF85063_Set_Date(datetime_t date) // Set Date
|
||||||
@@ -86,7 +88,7 @@ void PCF85063_Set_Date(datetime_t date) // Set Date
|
|||||||
decToBcd(date.month),
|
decToBcd(date.month),
|
||||||
decToBcd(date.year - YEAR_OFFSET)};
|
decToBcd(date.year - YEAR_OFFSET)};
|
||||||
esp_err_t ret = I2C_Write(PCF85063_ADDRESS, RTC_DAY_ADDR, buf, sizeof(buf));
|
esp_err_t ret = I2C_Write(PCF85063_ADDRESS, RTC_DAY_ADDR, buf, sizeof(buf));
|
||||||
if(ret != ESP_OK)
|
if (ret != ESP_OK)
|
||||||
printf("PCF85063 : Date setting failed\r\n");
|
printf("PCF85063 : Date setting failed\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +102,7 @@ void PCF85063_Set_All(datetime_t time) // Set Time And Date
|
|||||||
decToBcd(time.month),
|
decToBcd(time.month),
|
||||||
decToBcd(time.year - YEAR_OFFSET)};
|
decToBcd(time.year - YEAR_OFFSET)};
|
||||||
esp_err_t ret = I2C_Write(PCF85063_ADDRESS, RTC_SECOND_ADDR, buf, sizeof(buf));
|
esp_err_t ret = I2C_Write(PCF85063_ADDRESS, RTC_SECOND_ADDR, buf, sizeof(buf));
|
||||||
if(ret != ESP_OK)
|
if (ret != ESP_OK)
|
||||||
printf("PCF85063 : Failed to set the date and time\r\n");
|
printf("PCF85063 : Failed to set the date and time\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,9 +110,10 @@ void PCF85063_Read_Time(datetime_t *time) // Read Time And Date
|
|||||||
{
|
{
|
||||||
uint8_t buf[7] = {0};
|
uint8_t buf[7] = {0};
|
||||||
esp_err_t ret = I2C_Read(PCF85063_ADDRESS, RTC_SECOND_ADDR, buf, sizeof(buf));
|
esp_err_t ret = I2C_Read(PCF85063_ADDRESS, RTC_SECOND_ADDR, buf, sizeof(buf));
|
||||||
if(ret != ESP_OK)
|
if (ret != ESP_OK)
|
||||||
printf("PCF85063 : Time read failure\r\n");
|
printf("PCF85063 : Time read failure\r\n");
|
||||||
else{
|
else
|
||||||
|
{
|
||||||
time->second = bcdToDec(buf[0] & 0x7F);
|
time->second = bcdToDec(buf[0] & 0x7F);
|
||||||
time->minute = bcdToDec(buf[1] & 0x7F);
|
time->minute = bcdToDec(buf[1] & 0x7F);
|
||||||
time->hour = bcdToDec(buf[2] & 0x3F);
|
time->hour = bcdToDec(buf[2] & 0x3F);
|
||||||
@@ -126,7 +129,7 @@ void PCF85063_Enable_Alarm() // Enable Alarm and Clear Alarm flag
|
|||||||
uint8_t Value = RTC_CTRL_2_DEFAULT | RTC_CTRL_2_AIE;
|
uint8_t Value = RTC_CTRL_2_DEFAULT | RTC_CTRL_2_AIE;
|
||||||
Value &= ~RTC_CTRL_2_AF;
|
Value &= ~RTC_CTRL_2_AF;
|
||||||
esp_err_t ret = I2C_Write(PCF85063_ADDRESS, RTC_CTRL_2_ADDR, &Value, 1);
|
esp_err_t ret = I2C_Write(PCF85063_ADDRESS, RTC_CTRL_2_ADDR, &Value, 1);
|
||||||
if(ret != ESP_OK)
|
if (ret != ESP_OK)
|
||||||
printf("PCF85063 : Failed to enable Alarm Flag and Clear Alarm Flag \r\n");
|
printf("PCF85063 : Failed to enable Alarm Flag and Clear Alarm Flag \r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,28 +137,28 @@ uint8_t PCF85063_Get_Alarm_Flag() // Get Alarm flag
|
|||||||
{
|
{
|
||||||
uint8_t Value = 0;
|
uint8_t Value = 0;
|
||||||
esp_err_t ret = I2C_Read(PCF85063_ADDRESS, RTC_CTRL_2_ADDR, &Value, 1);
|
esp_err_t ret = I2C_Read(PCF85063_ADDRESS, RTC_CTRL_2_ADDR, &Value, 1);
|
||||||
if(ret != ESP_OK)
|
if (ret != ESP_OK)
|
||||||
printf("PCF85063 : Failed to obtain a warning flag.\r\n");
|
printf("PCF85063 : Failed to obtain a warning flag.\r\n");
|
||||||
else
|
else
|
||||||
Value &= RTC_CTRL_2_AF | RTC_CTRL_2_AIE;
|
Value &= RTC_CTRL_2_AF | RTC_CTRL_2_AIE;
|
||||||
//printf("Value = 0x%x",Value);
|
// printf("Value = 0x%x",Value);
|
||||||
return Value;
|
return Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PCF85063_Set_Alarm(datetime_t time) // Set Alarm
|
void PCF85063_Set_Alarm(datetime_t time) // Set Alarm
|
||||||
{
|
{
|
||||||
|
|
||||||
uint8_t buf[5] ={
|
uint8_t buf[5] = {
|
||||||
decToBcd(time.second)&(~RTC_ALARM),
|
decToBcd(time.second) & (~RTC_ALARM),
|
||||||
decToBcd(time.minute)&(~RTC_ALARM),
|
decToBcd(time.minute) & (~RTC_ALARM),
|
||||||
decToBcd(time.hour)&(~RTC_ALARM),
|
decToBcd(time.hour) & (~RTC_ALARM),
|
||||||
//decToBcd(time.day)&(~RTC_ALARM),
|
// decToBcd(time.day)&(~RTC_ALARM),
|
||||||
//decToBcd(time.dotw)&(~RTC_ALARM)
|
// decToBcd(time.dotw)&(~RTC_ALARM)
|
||||||
RTC_ALARM, //disalbe day
|
RTC_ALARM, // disalbe day
|
||||||
RTC_ALARM //disalbe weekday
|
RTC_ALARM // disalbe weekday
|
||||||
};
|
};
|
||||||
esp_err_t ret = I2C_Write(PCF85063_ADDRESS, RTC_SECOND_ALARM, buf, sizeof(buf));
|
esp_err_t ret = I2C_Write(PCF85063_ADDRESS, RTC_SECOND_ALARM, buf, sizeof(buf));
|
||||||
if(ret != ESP_OK)
|
if (ret != ESP_OK)
|
||||||
printf("PCF85063 : Failed to set alarm flag\r\n");
|
printf("PCF85063 : Failed to set alarm flag\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,9 +166,10 @@ void PCF85063_Read_Alarm(datetime_t *time) // Read Alarm
|
|||||||
{
|
{
|
||||||
uint8_t buf[5] = {0};
|
uint8_t buf[5] = {0};
|
||||||
esp_err_t ret = I2C_Read(PCF85063_ADDRESS, RTC_SECOND_ALARM, buf, sizeof(buf));
|
esp_err_t ret = I2C_Read(PCF85063_ADDRESS, RTC_SECOND_ALARM, buf, sizeof(buf));
|
||||||
if(ret != ESP_OK)
|
if (ret != ESP_OK)
|
||||||
printf("PCF85063 : Failed to read the alarm sign\r\n");
|
printf("PCF85063 : Failed to read the alarm sign\r\n");
|
||||||
else{
|
else
|
||||||
|
{
|
||||||
time->second = bcdToDec(buf[0] & 0x7F);
|
time->second = bcdToDec(buf[0] & 0x7F);
|
||||||
time->minute = bcdToDec(buf[1] & 0x7F);
|
time->minute = bcdToDec(buf[1] & 0x7F);
|
||||||
time->hour = bcdToDec(buf[2] & 0x3F);
|
time->hour = bcdToDec(buf[2] & 0x3F);
|
||||||
@@ -182,7 +186,7 @@ static int bcdToDec(uint8_t val) // Convert binary coded decimal to normal decim
|
|||||||
{
|
{
|
||||||
return (int)((val / 16 * 10) + (val % 16));
|
return (int)((val / 16 * 10) + (val % 16));
|
||||||
}
|
}
|
||||||
void datetime_to_str(char *datetime_str,datetime_t time)
|
void datetime_to_str(char *datetime_str, datetime_t time)
|
||||||
{
|
{
|
||||||
sprintf(datetime_str, " %d.%d.%d %d:%d:%d %s", time.year, time.month,
|
sprintf(datetime_str, " %d.%d.%d %d:%d:%d %s", time.year, time.month,
|
||||||
time.day, time.hour, time.minute, time.second, Week[time.dotw]);
|
time.day, time.hour, time.minute, time.second, Week[time.dotw]);
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
#include "I2C_Driver.h"
|
#include "I2C_Driver.h"
|
||||||
|
|
||||||
//PCF85063_ADDRESS
|
// PCF85063_ADDRESS
|
||||||
#define PCF85063_ADDRESS (0x51)
|
#define PCF85063_ADDRESS (0x51)
|
||||||
//
|
|
||||||
#define YEAR_OFFSET (1970)
|
#define YEAR_OFFSET (1970)
|
||||||
// registar overview - crtl & status reg
|
// registar overview - crtl & status reg
|
||||||
#define RTC_CTRL_1_ADDR (0x00)
|
#define RTC_CTRL_1_ADDR (0x00)
|
||||||
@@ -29,28 +29,28 @@
|
|||||||
#define RTC_TIMER_VAL (0x10)
|
#define RTC_TIMER_VAL (0x10)
|
||||||
#define RTC_TIMER_MODE (0x11)
|
#define RTC_TIMER_MODE (0x11)
|
||||||
|
|
||||||
//RTC_CTRL_1 registar
|
// RTC_CTRL_1 registar
|
||||||
#define RTC_CTRL_1_EXT_TEST (0x80)
|
#define RTC_CTRL_1_EXT_TEST (0x80)
|
||||||
#define RTC_CTRL_1_STOP (0x20) //0-RTC clock runs 1- RTC clock is stopped
|
#define RTC_CTRL_1_STOP (0x20) // 0-RTC clock runs 1- RTC clock is stopped
|
||||||
#define RTC_CTRL_1_SR (0X10) //0-no software reset 1-initiate software rese
|
#define RTC_CTRL_1_SR (0X10) // 0-no software reset 1-initiate software rese
|
||||||
#define RTC_CTRL_1_CIE (0X04) //0-no correction interrupt generated 1-interrupt pulses are generated at every correction cycle
|
#define RTC_CTRL_1_CIE (0X04) // 0-no correction interrupt generated 1-interrupt pulses are generated at every correction cycle
|
||||||
#define RTC_CTRL_1_12_24 (0X02) //0-24H 1-12H
|
#define RTC_CTRL_1_12_24 (0X02) // 0-24H 1-12H
|
||||||
#define RTC_CTRL_1_CAP_SEL (0X01) //0-7PF 1-12.5PF
|
#define RTC_CTRL_1_CAP_SEL (0X01) // 0-7PF 1-12.5PF
|
||||||
|
|
||||||
//RTC_CTRL_2 registar
|
// RTC_CTRL_2 registar
|
||||||
#define RTC_CTRL_2_AIE (0X80) //alarm interrupt 0-disalbe 1-enable
|
#define RTC_CTRL_2_AIE (0X80) // alarm interrupt 0-disalbe 1-enable
|
||||||
#define RTC_CTRL_2_AF (0X40) //alarm flag 0-inactive/cleared 1-active/unchanged
|
#define RTC_CTRL_2_AF (0X40) // alarm flag 0-inactive/cleared 1-active/unchanged
|
||||||
#define RTC_CTRL_2_MI (0X20) //minute interrupt 0-disalbe 1-enable
|
#define RTC_CTRL_2_MI (0X20) // minute interrupt 0-disalbe 1-enable
|
||||||
#define RTC_CTRL_2_HMI (0X10) //half minute interrupt
|
#define RTC_CTRL_2_HMI (0X10) // half minute interrupt
|
||||||
#define RTC_CTRL_2_TF (0X08)
|
#define RTC_CTRL_2_TF (0X08)
|
||||||
|
|
||||||
//
|
//
|
||||||
#define RTC_OFFSET_MODE (0X80)
|
#define RTC_OFFSET_MODE (0X80)
|
||||||
|
|
||||||
//
|
//
|
||||||
#define RTC_TIMER_MODE_TE (0X04) //timer enable 0-disalbe 1-enable
|
#define RTC_TIMER_MODE_TE (0X04) // timer enable 0-disalbe 1-enable
|
||||||
#define RTC_TIMER_MODE_TIE (0X02) //timer interrupt enable 0-disalbe 1-enable
|
#define RTC_TIMER_MODE_TIE (0X02) // timer interrupt enable 0-disalbe 1-enable
|
||||||
#define RTC_TIMER_MODE_TI_TP (0X01) //timer interrupt mode 0-interrupt follows timer flag 1-interrupt generates a pulse
|
#define RTC_TIMER_MODE_TI_TP (0X01) // timer interrupt mode 0-interrupt follows timer flag 1-interrupt generates a pulse
|
||||||
|
|
||||||
// format
|
// format
|
||||||
#define RTC_ALARM (0x80) // set AEN_x registers
|
#define RTC_ALARM (0x80) // set AEN_x registers
|
||||||
@@ -59,7 +59,8 @@
|
|||||||
|
|
||||||
#define RTC_TIMER_FLAG (0x08)
|
#define RTC_TIMER_FLAG (0x08)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
uint16_t year;
|
uint16_t year;
|
||||||
uint8_t month;
|
uint8_t month;
|
||||||
uint8_t day;
|
uint8_t day;
|
||||||
@@ -67,11 +68,10 @@ typedef struct {
|
|||||||
uint8_t hour;
|
uint8_t hour;
|
||||||
uint8_t minute;
|
uint8_t minute;
|
||||||
uint8_t second;
|
uint8_t second;
|
||||||
}datetime_t;
|
} datetime_t;
|
||||||
|
|
||||||
|
const unsigned char MonthStr[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||||
const unsigned char MonthStr[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov","Dec"};
|
const unsigned char Week[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
||||||
const unsigned char Week[7][5] = {"SUN","Mon","Tues","Wed","Thur","Fri","Sat"};
|
|
||||||
|
|
||||||
extern datetime_t datetime;
|
extern datetime_t datetime;
|
||||||
void PCF85063_Init(void);
|
void PCF85063_Init(void);
|
||||||
@@ -84,20 +84,9 @@ void PCF85063_Set_All(datetime_t time);
|
|||||||
|
|
||||||
void PCF85063_Read_Time(datetime_t *time);
|
void PCF85063_Read_Time(datetime_t *time);
|
||||||
|
|
||||||
|
|
||||||
void PCF85063_Enable_Alarm(void);
|
void PCF85063_Enable_Alarm(void);
|
||||||
uint8_t PCF85063_Get_Alarm_Flag();
|
uint8_t PCF85063_Get_Alarm_Flag(void);
|
||||||
void PCF85063_Set_Alarm(datetime_t time);
|
void PCF85063_Set_Alarm(datetime_t time);
|
||||||
void PCF85063_Read_Alarm(datetime_t *time);
|
void PCF85063_Read_Alarm(datetime_t *time);
|
||||||
|
|
||||||
void datetime_to_str(char *datetime_str,datetime_t time);
|
void datetime_to_str(char *datetime_str, datetime_t time);
|
||||||
|
|
||||||
|
|
||||||
// weekday format
|
|
||||||
// 0 - sunday
|
|
||||||
// 1 - monday
|
|
||||||
// 2 - tuesday
|
|
||||||
// 3 - wednesday
|
|
||||||
// 4 - thursday
|
|
||||||
// 5 - friday
|
|
||||||
// 6 - saturday
|
|
||||||
|
|||||||
Reference in New Issue
Block a user