From 79e5760d19c828b15f11ef541a78b2dc157dab06 Mon Sep 17 00:00:00 2001 From: Emanuele Trabattoni Date: Sun, 22 Jun 2025 15:27:10 +0200 Subject: [PATCH] Halfway RTC driver refactoring --- lib/RTC/WS_PCF85063.cpp | 66 ++++++++++++++++++++++++++++++++++++++++- lib/RTC/WS_PCF85063.h | 46 ++++++++++++++++++++++++++++ src/MAIN_WIFI_MQTT.cpp | 2 +- 3 files changed, 112 insertions(+), 2 deletions(-) diff --git a/lib/RTC/WS_PCF85063.cpp b/lib/RTC/WS_PCF85063.cpp index 7000ab2..ed1a269 100644 --- a/lib/RTC/WS_PCF85063.cpp +++ b/lib/RTC/WS_PCF85063.cpp @@ -190,4 +190,68 @@ void datetime_to_str(char *datetime_str, datetime_t time) { 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]); -} \ No newline at end of file +} + +namespace drivers +{ + + PCF85063::PCF85063(I2C &i2c, const uint8_t address) : m_i2c(i2c), m_address(address) + { + } + + const bool PCF85063::reset(void) + { + } + + const bool PCF85063::setTime(datetime_t time) + { + } + + const bool PCF85063::setDate(datetime_t date) + { + } + + const bool PCF85063::setDatetime(datetime_t datetime) + { + } + + const bool PCF85063::readDate(datetime_t &datetime) + { + } + + const bool PCF85063::readTime(datetime_t &datetime) + { + } + + const bool PCF85063::readDatetime(datetime_t &datetime) + { + } + + const bool PCF85063::enableAlarm(const bool enable) + { + } + + const bool PCF85063::setAlarm(datetime_t time) + { + } + + const bool PCF85063::readAlarm(datetime_t &time) + { + } + + const bool PCF85063::getAlarmFlafs(uint8_t &flags) + { + } + + const std::string PCF85063::datetime2str(datetime_t &time) + { + } + + const uint8_t PCF85063::decToBcd(int val) + { + } + + const int PCF85063::bcdToDec(uint8_t val) + { + } +} diff --git a/lib/RTC/WS_PCF85063.h b/lib/RTC/WS_PCF85063.h index 51c013d..56b9be9 100644 --- a/lib/RTC/WS_PCF85063.h +++ b/lib/RTC/WS_PCF85063.h @@ -1,6 +1,7 @@ #pragma once #include "I2C_Driver.h" +#include // PCF85063_ADDRESS #define PCF85063_ADDRESS (0x51) @@ -90,3 +91,48 @@ void PCF85063_Set_Alarm(datetime_t time); void PCF85063_Read_Alarm(datetime_t *time); void datetime_to_str(char *datetime_str, datetime_t time); + +namespace drivers +{ + + class PCF85063 + { + I2C &m_i2c; + uint8_t m_address; + + typedef struct + { + uint16_t year; + uint8_t month; + uint8_t day; + uint8_t dotw; + uint8_t hour; + uint8_t minute; + uint8_t second; + } datetime_t; + + public: + PCF85063(I2C &i2c, const uint8_t address, const uint8_t ctrl1, const uint8_t ctrl2); + + const bool reset(void); + + const bool setTime(datetime_t time); + const bool setDate(datetime_t date); + const bool setDatetime(datetime_t datetime); + + const bool readDate(datetime_t &datetime); + const bool readTime(datetime_t &datetime); + const bool readDatetime(datetime_t &datetime); + + const bool enableAlarm(const bool enable); + const bool setAlarm(datetime_t time); + const bool readAlarm(datetime_t &time); + const bool getAlarmFlafs(uint8_t& flags); + + private: + const std::string datetime2str(datetime_t &time); + const uint8_t decToBcd(int val); + const int bcdToDec(uint8_t val); + }; + +} diff --git a/src/MAIN_WIFI_MQTT.cpp b/src/MAIN_WIFI_MQTT.cpp index b3df6c6..69b102c 100644 --- a/src/MAIN_WIFI_MQTT.cpp +++ b/src/MAIN_WIFI_MQTT.cpp @@ -18,7 +18,7 @@ void setup() { Flash_test(); GPIO_Init(); // RGB . Buzzer GPIO //I2C_Init(); - RTC_Init();// RTC + //RTC_Init(); // RTC SD_Init(); Serial_Init(); // UART(RS485/CAN) MQTT_Init();// MQTT