34#include "freertos/FreeRTOS.h"
40static const char *TAG =
"RTC";
44static bool init_done =
false;
46esp_err_t pcf8563_init()
48 ESP_LOGI(TAG,
"----DRIVER PCF8563 ----");
51#if CONFIG_I2C_COMMUNICATION_METHOD_CALLBACK_RW
53 uint8_t address = 0x51;
56 i2c_drv_device_init(address);
58 ESP_LOGI(TAG,
"Implemented using read and write callback methods");
60 ESP_LOGI(TAG,
"Initializing PCF8563 real-time clock successfully!");
62 ESP_LOGE(TAG,
"Failed to initialize PCF8563 real time clock!");
68#if CONFIG_I2C_COMMUNICATION_METHOD_BUILTIN_RW
69#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)
71 ESP_LOGI(TAG,
"Implemented using built-in read and write methods (Use higher version >= 5.0 API)");
75 extern i2c_master_bus_handle_t bus_handle;
78 ESP_LOGI(TAG,
"Initializing PCF8563 real-time clock successfully!");
80 ESP_LOGE(TAG,
"Failed to initialize PCF8563 real time clock!");
86 ESP_LOGI(TAG,
"Implemented using built-in read and write methods (Use lower version < 5.0 API)");
87 if (
rtc.
begin((i2c_port_t)CONFIG_I2C_MASTER_PORT_NUM, CONFIG_SENSOR_SDA, CONFIG_SENSOR_SCL)) {
88 ESP_LOGI(TAG,
"Initializing PCF8563 real-time clock successfully!");
90 ESP_LOGE(TAG,
"Failed to initialize PCF8563 real time clock!");
98 timeinfo.tm_yday = 2025 - 1900;
99 timeinfo.tm_mon = 1 - 1;
100 timeinfo.tm_mday = 17;
101 timeinfo.tm_hour = 4;
102 timeinfo.tm_min = 30;
103 timeinfo.tm_sec = 30;
123 size_t written = strftime(
buf, 64,
"%A, %B %d %Y %H:%M:%S", &timeinfo);
125 ESP_LOGI(
"RTC",
"%s",
buf);
127 written = strftime(
buf, 64,
"%b %d %Y %H:%M:%S", &timeinfo);
129 ESP_LOGI(
"RTC",
"%s",
buf);
131 written = strftime(
buf, 64,
"%A, %d. %B %Y %I:%M%p", &timeinfo);
133 ESP_LOGI(
"RTC",
"%s",
buf);
void setDateTime(RTC_DateTime datetime) override
Set the RTC date and time.
bool begin(SensorCommCustom::CustomCallback callback)
Initialize device using a custom transport callback.
RTC_DateTime getDateTime() override
Read the RTC date and time.
Driver for the PCF8563 real-time clock (RTC) over I2C.
bool i2c_wr_function(uint8_t addr, uint8_t reg, uint8_t *buf, size_t len, bool writeReg, bool isWrite)