Halfway RTC driver refactoring

This commit is contained in:
Emanuele Trabattoni
2025-06-22 15:27:10 +02:00
parent dcbe637ccc
commit 79e5760d19
3 changed files with 112 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
#pragma once
#include "I2C_Driver.h"
#include <string>
// 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);
};
}