33#include "../../SensorBuildOpt.h"
34#if !SENSORLIB_EXCLUDE_PCF8563
36#include "../../platform/comm/I2CDeviceNoHal.hpp"
37#include "../SensorRTC.h"
43static const uint8_t PCF8563_SLAVE_ADDRESS = 0x51;
88 bool begin(TwoWire &wire,
int sda = -1,
int scl = -1)
92#elif defined(ESP_PLATFORM)
94#if defined(SENSORLIB_USE_I2C_LEGACY)
103 bool begin(i2c_port_t port_num,
int sda = -1,
int scl = -1)
114 bool begin(i2c_master_bus_handle_t handle)
151 if ((2000 % datetime.
getYear()) == 2000) {
170 uint8_t second =
BCD2DEC(buffer[0] & 0x7F);
171 uint8_t minute =
BCD2DEC(buffer[1] & 0x7F);
172 uint8_t hour =
BCD2DEC(buffer[2] & 0x3F);
173 uint8_t day =
BCD2DEC(buffer[3] & 0x3F);
174 uint8_t week =
BCD2DEC(buffer[4] & 0x07);
175 uint8_t month =
BCD2DEC(buffer[5] & 0x1F);
176 uint16_t year =
BCD2DEC(buffer[6]);
180 return RTC_DateTime(year, month, day, hour, minute, second, week);
208 buffer[0] =
BCD2DEC(buffer[0] & 0x80);
209 buffer[1] =
BCD2DEC(buffer[1] & 0x40);
210 buffer[2] =
BCD2DEC(buffer[2] & 0x40);
211 buffer[3] =
BCD2DEC(buffer[3] & 0x08);
213 return RTC_Alarm(buffer[1], buffer[0], 0, buffer[2], buffer[3]);
268 void setAlarm(uint8_t hour, uint8_t minute, uint8_t day, uint8_t week)
270 uint8_t buffer[4] = {0};
281 buffer[0] &= ~ALARM_ENABLE;
291 buffer[1] &= ~ALARM_ENABLE;
296 buffer[2] =
DEC2BCD(((day) < (1) ? (1) : ((day) > (daysInMonth) ? (daysInMonth) : (day))));
297 buffer[2] &= ~ALARM_ENABLE;
306 buffer[3] &= ~ALARM_ENABLE;
363 return buffer[1] &
TIMER_TE ? true :
false;
459 bool initImpl(uint8_t param)
override
466 if (
BCD2DEC(ret & 0x7F) > 59) {
bool begin(SensorCommCustom::CustomCallback callback, uint8_t addr)
Initialize the sensor using custom callback interface.
uint8_t getMinute() const
uint8_t getMinute() const
uint8_t getSecond() const
bool(*)(uint8_t addr, uint8_t reg, uint8_t *buf, size_t len, bool writeReg, bool isWrite) CustomCallback
bool clrRegBit(uint8_t reg, uint8_t bit)
bool getRegBit(uint8_t reg, uint8_t bit)
int readReg(uint8_t reg) const
int writeRegBuff(uint8_t reg, uint8_t *buf, size_t len)
int writeReg(uint8_t reg, uint8_t val)
int readRegBuff(uint8_t reg, uint8_t *buf, size_t len) const
bool setRegBit(uint8_t reg, uint8_t bit)
Driver for the PCF8563 real-time clock (RTC) over I2C.
SensorPCF8563()=default
Construct a PCF8563 driver instance.
ClockHz
Clock output frequencies for the CLKOUT pin.
@ CLK_DISABLE
Disable CLKOUT.
@ CLK_32768HZ
32.768 kHz output
@ CLK_1024HZ
1.024 kHz output
void resetAlarm()
Clear the alarm flag.
RTC_Alarm getAlarm()
Read the currently configured alarm settings.
void clearCountdownTimer()
Clear and disable the countdown timer.
void disableAlarm()
Disable the alarm interrupt.
static constexpr uint8_t ALRM_MIN_REG
static constexpr uint8_t TIMER_TIE
static constexpr uint8_t HR_REG
static constexpr uint8_t NO_ALARM
static constexpr uint8_t HOUR_MASK
static constexpr uint8_t CENTURY_MASK
void setDateTime(RTC_DateTime datetime) override
Set the RTC date/time.
void setAlarmByMinutes(uint8_t minute)
Convenience API to set an alarm that matches only minutes.
void setClockOutput(ClockHz freq)
Configure the clock output (CLKOUT) pin.
static constexpr uint8_t MONTH_REG
static constexpr uint8_t STAT1_REG
static constexpr uint8_t SQW_REG
static constexpr uint8_t MIN_REG
void setAlarmByDays(uint8_t day)
Convenience API to set an alarm that matches only day-of-month.
static constexpr uint8_t TIMER_CTL_MASK
void setAlarmByHours(uint8_t hour)
Convenience API to set an alarm that matches only hours.
void setCountdownTimer(uint8_t val, uint8_t freq)
Configure countdown timer.
bool isCountdownTimerActive()
Check whether the countdown timer flag is active.
static constexpr uint8_t ALARM_AIE
static constexpr uint8_t STAT2_REG
void enableAlarm()
Enable the alarm interrupt.
static constexpr uint8_t MINUTES_MASK
static constexpr uint8_t WEEKDAY_REG
bool isCountdownTimerEnable()
Check whether the countdown timer is enabled.
static constexpr uint8_t ALARM_ENABLE
void setAlarm(uint8_t hour, uint8_t minute, uint8_t day, uint8_t week)
Set the alarm configuration.
static constexpr uint8_t TIMER_TF
static constexpr uint8_t SEC_REG
static constexpr uint8_t DAY_MASK
static constexpr uint8_t WEEKDAY_MASK
void enableCountdownTimer()
Enable the countdown timer interrupt.
static constexpr uint8_t TIMER_TD10
static constexpr uint8_t TIMER_TE
static constexpr uint8_t DAY_REG
bool begin(SensorCommCustom::CustomCallback callback)
Initialize the device using a user-provided transport callback.
const char * getChipName() override
Get the chip name string.
static constexpr uint8_t TIMER2_REG
static constexpr uint8_t VOL_LOW_MASK
static constexpr uint8_t CLK_ENABLE
static constexpr uint8_t ALARM_AF
RTC_DateTime getDateTime() override
Get the current RTC date/time.
bool isClockIntegrityGuaranteed()
Check whether the clock integrity is guaranteed.
void setAlarmByWeekDay(uint8_t week)
Convenience API to set an alarm that matches only weekday.
static constexpr uint8_t TIMER1_REG
~SensorPCF8563()=default
Destructor.
void disableCountdownTimer()
Disable the countdown timer interrupt.
static constexpr uint8_t MONTH_MASK
bool isAlarmActive()
Check whether the alarm flag is active.
void setAlarm(RTC_Alarm alarm)
Set the alarm configuration.
static constexpr uint8_t YEAR_REG
void reset() override
Reset the RTC.
uint32_t getDayOfWeek(uint32_t day, uint32_t month, uint32_t year)
Calculate the day of the week for a given date using Zeller's congruence.
virtual void setDateTime(RTC_DateTime datetime)=0
Set the date and time of the RTC using an RTC_DateTime object.
static uint8_t BCD2DEC(uint8_t val)
Convert a Binary Coded Decimal (BCD) number to a decimal number.
uint8_t getDaysInMonth(uint8_t month, uint16_t year)
Get the number of days in a given month of a specific year, considering leap years.
virtual RTC_DateTime getDateTime()=0
Get the current date and time from the RTC.
static uint8_t DEC2BCD(uint8_t val)
Convert a decimal number to a Binary Coded Decimal (BCD) number.