|
SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
|
Driver for the PCF8563 real-time clock (RTC) over I2C. More...
#include <SensorPCF8563.hpp>
Public Types | |
| enum | ClockHz { CLK_32768HZ , CLK_1024HZ , CLK_32HZ , CLK_1HZ , CLK_DISABLE } |
| Clock output frequencies for the CLKOUT pin. More... | |
Public Member Functions | |
| SensorPCF8563 ()=default | |
| Construct a PCF8563 driver instance. | |
| ~SensorPCF8563 ()=default | |
| Destructor. | |
| bool | begin (SensorCommCustom::CustomCallback callback) |
| Initialize the device using a user-provided transport callback. | |
| void | setDateTime (RTC_DateTime datetime) override |
| Set the RTC date/time. | |
| RTC_DateTime | getDateTime () override |
| Get the current RTC date/time. | |
| bool | isClockIntegrityGuaranteed () |
| Check whether the clock integrity is guaranteed. | |
| RTC_Alarm | getAlarm () |
| Read the currently configured alarm settings. | |
| void | enableAlarm () |
| Enable the alarm interrupt. | |
| void | disableAlarm () |
| Disable the alarm interrupt. | |
| void | resetAlarm () |
| Clear the alarm flag. | |
| bool | isAlarmActive () |
| Check whether the alarm flag is active. | |
| void | setAlarm (RTC_Alarm alarm) |
| Set the alarm configuration. | |
| void | setAlarm (uint8_t hour, uint8_t minute, uint8_t day, uint8_t week) |
| Set the alarm configuration. | |
| void | setAlarmByMinutes (uint8_t minute) |
| Convenience API to set an alarm that matches only minutes. | |
| void | setAlarmByDays (uint8_t day) |
| Convenience API to set an alarm that matches only day-of-month. | |
| void | setAlarmByHours (uint8_t hour) |
| Convenience API to set an alarm that matches only hours. | |
| void | setAlarmByWeekDay (uint8_t week) |
| Convenience API to set an alarm that matches only weekday. | |
| bool | isCountdownTimerEnable () |
| Check whether the countdown timer is enabled. | |
| bool | isCountdownTimerActive () |
| Check whether the countdown timer flag is active. | |
| void | enableCountdownTimer () |
| Enable the countdown timer interrupt. | |
| void | disableCountdownTimer () |
| Disable the countdown timer interrupt. | |
| void | setCountdownTimer (uint8_t val, uint8_t freq) |
| Configure countdown timer. | |
| void | clearCountdownTimer () |
| Clear and disable the countdown timer. | |
| void | setClockOutput (ClockHz freq) |
| Configure the clock output (CLKOUT) pin. | |
| const char * | getChipName () override |
| Get the chip name string. | |
| void | reset () override |
| Reset the RTC. | |
| virtual void | setDateTime (RTC_DateTime datetime)=0 |
| Set the date and time of the RTC using an RTC_DateTime object. | |
| void | setDateTime (uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) |
| Set the date and time of the RTC using individual values. | |
| virtual RTC_DateTime | getDateTime ()=0 |
| Get the current date and time from the RTC. | |
| void | getDateTime (struct tm *info) |
| Retrieve the current date and time from the RTC (Real-Time Clock) and populate a struct tm object. | |
| bool | begin (SensorCommCustom::CustomCallback callback, uint8_t addr) |
| Initialize the sensor using custom callback interface. | |
Public Member Functions inherited from SensorRTC | |
| void | getDateTime (struct tm *info) |
| Retrieve the current date and time from the RTC (Real-Time Clock) and populate a struct tm object. | |
| void | setDateTime (uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) |
| Set the date and time of the RTC using individual values. | |
| const char * | strftime (DateTimeFormat style=DT_FMT_YMD_HMS_WEEK) |
| Format the current date and time according to the specified style. | |
| time_t | hwClockRead (const timezone *tz=NULL) |
| Read the time from the RTC (Real-Time Clock) and write it to the system clock. | |
| int | hwClockWrite () |
| Write the current system time to the RTC clock chip. | |
| 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. | |
| uint8_t | getNextMonth (uint8_t curMonth) |
| Get the next month based on the current month. | |
| uint16_t | getNextYear (uint16_t curYear) |
| Get the next year based on the current year. | |
| uint32_t | getLeapYear (uint32_t year) |
| Determine whether a given year is a leap year. | |
| 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. | |
| void | convertUtcToTimezone (int &year, int &month, int &day, int &hour, int &minute, int &second, int timezoneOffsetSeconds) |
| Convert UTC time represented by individual values to the time in the specified timezone. | |
| void | convertUtcToTimezone (struct tm &utcTime, int timezoneOffsetSeconds) |
| Overloaded function to convert UTC time represented by a struct tm object to the time in the specified timezone. | |
Public Member Functions inherited from I2CDeviceNoHal | |
| bool | begin (SensorCommCustom::CustomCallback callback, uint8_t addr) |
| Initialize the sensor using custom callback interface. | |
Public Member Functions inherited from DeviceBeginCommon | |
| virtual | ~DeviceBeginCommon () |
| uint8_t | getAddress () const |
| uint8_t | getInterface () const |
Public Member Functions inherited from SensorCommWrapper | |
| SensorCommWrapper ()=default | |
| int | readReg (uint8_t reg) const |
| int | readRegBuff (uint8_t reg, uint8_t *buf, size_t len) const |
| int | readBuff (uint8_t *buf, size_t len) const |
| int | writeReg (uint8_t reg, uint8_t val) |
| int | writeRegBuff (uint8_t reg, uint8_t *buf, size_t len) |
| int | writeBuff (uint8_t *buf, size_t len) |
| int | writeThenRead (const uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len) |
| bool | setRegBit (uint8_t reg, uint8_t bit) |
| bool | clrRegBit (uint8_t reg, uint8_t bit) |
| bool | getRegBit (uint8_t reg, uint8_t bit) |
| int | updateBits (uint8_t reg, uint8_t mask, uint8_t value_shifted) |
| void | setAddress (uint8_t address) |
| void | setAck (bool enable) |
Public Member Functions inherited from SensorCommInterface | |
| virtual | ~SensorCommInterface ()=default |
Static Protected Attributes | |
| static constexpr uint8_t | STAT1_REG = 0x00 |
| static constexpr uint8_t | STAT2_REG = 0x01 |
| static constexpr uint8_t | SEC_REG = 0x02 |
| static constexpr uint8_t | MIN_REG = 0x03 |
| static constexpr uint8_t | HR_REG = 0x04 |
| static constexpr uint8_t | DAY_REG = 0x05 |
| static constexpr uint8_t | WEEKDAY_REG = 0x06 |
| static constexpr uint8_t | MONTH_REG = 0x07 |
| static constexpr uint8_t | YEAR_REG = 0x08 |
| static constexpr uint8_t | ALRM_MIN_REG = 0x09 |
| static constexpr uint8_t | SQW_REG = 0x0D |
| static constexpr uint8_t | TIMER1_REG = 0x0E |
| static constexpr uint8_t | TIMER2_REG = 0x0F |
| static constexpr uint8_t | VOL_LOW_MASK = 0x80 |
| static constexpr uint8_t | MINUTES_MASK = 0x7F |
| static constexpr uint8_t | HOUR_MASK = 0x3F |
| static constexpr uint8_t | WEEKDAY_MASK = 0x07 |
| static constexpr uint8_t | CENTURY_MASK = 0x80 |
| static constexpr uint8_t | DAY_MASK = 0x3F |
| static constexpr uint8_t | MONTH_MASK = 0x1F |
| static constexpr uint8_t | TIMER_CTL_MASK = 0x03 |
| static constexpr uint8_t | ALARM_AF = 0x08 |
| static constexpr uint8_t | TIMER_TF = 0x04 |
| static constexpr uint8_t | ALARM_AIE = 0x02 |
| static constexpr uint8_t | TIMER_TIE = 0x01 |
| static constexpr uint8_t | TIMER_TE = 0x80 |
| static constexpr uint8_t | TIMER_TD10 = 0x03 |
| static constexpr uint8_t | NO_ALARM = 0xFF |
| static constexpr uint8_t | ALARM_ENABLE = 0x80 |
| static constexpr uint8_t | CLK_ENABLE = 0x80 |
Additional Inherited Members | |
Static Public Member Functions inherited from SensorRTC | |
| static uint8_t | BCD2DEC (uint8_t val) |
| Convert a Binary Coded Decimal (BCD) number to a decimal number. | |
| static uint8_t | DEC2BCD (uint8_t val) |
| Convert a decimal number to a Binary Coded Decimal (BCD) number. | |
Protected Member Functions inherited from DeviceBeginCommon | |
| DeviceBeginCommon ()=default | |
| virtual bool | ensureValid () const override |
| virtual SensorCommBase * | getComm () const override |
| virtual void | beforeBegin () |
| virtual void | afterCommReady () |
| virtual void | afterInitSuccess (uint8_t param) |
| virtual void | onBeginFail () |
| bool | fail () |
| void | clearCommState () |
| template<typename CreateComm > | |
| bool | beginLifecycle (uint8_t addr, uint8_t iface, uint8_t initParam, CreateComm createComm) |
Protected Attributes inherited from DeviceBeginCommon | |
| std::unique_ptr< SensorCommBase > | comm |
| std::unique_ptr< SensorHal > | hal |
| std::unique_ptr< SensorCommStatic > | staticComm |
| uint8_t | _addr = 0 |
| uint8_t | _iface = COMM_CUSTOM |
Driver for the PCF8563 real-time clock (RTC) over I2C.
Definition at line 49 of file time/pcf8563/SensorPCF8563.hpp.
Clock output frequencies for the CLKOUT pin.
| Enumerator | |
|---|---|
| CLK_32768HZ | 32.768 kHz output |
| CLK_1024HZ | 1.024 kHz output |
| CLK_32HZ | 32 Hz output |
| CLK_1HZ | 1 Hz output |
| CLK_DISABLE | Disable CLKOUT. |
Definition at line 59 of file time/pcf8563/SensorPCF8563.hpp.
|
default |
Construct a PCF8563 driver instance.
|
default |
Destructor.
Deinitializes the underlying communication bus if it has been created.
References I2CDeviceNoHal::begin().
|
inlinevirtual |
Initialize the device using a user-provided transport callback.
| callback | Custom communication callback. |
Implements SensorRTC.
Definition at line 127 of file time/pcf8563/SensorPCF8563.hpp.
References I2CDeviceNoHal::begin().
Referenced by setup().
|
inline |
Initialize the sensor using custom callback interface.
| interface | Communication interface type (COMM_SPI or COMM_I2C). |
| callback | Register read/write callback function. |
| addr | Device address |
Definition at line 94 of file I2CDeviceNoHal.hpp.
|
inline |
Clear and disable the countdown timer.
Definition at line 412 of file time/pcf8563/SensorPCF8563.hpp.
References ALARM_AF, SensorCommWrapper::readReg(), STAT2_REG, TIMER1_REG, TIMER_TF, TIMER_TIE, and SensorCommWrapper::writeReg().
|
inline |
Disable the alarm interrupt.
Definition at line 227 of file time/pcf8563/SensorPCF8563.hpp.
References SensorCommWrapper::clrRegBit(), and STAT2_REG.
|
inline |
Disable the countdown timer interrupt.
Definition at line 388 of file time/pcf8563/SensorPCF8563.hpp.
References SensorCommWrapper::clrRegBit(), and STAT2_REG.
|
inline |
Enable the alarm interrupt.
Definition at line 219 of file time/pcf8563/SensorPCF8563.hpp.
References SensorCommWrapper::setRegBit(), and STAT2_REG.
Referenced by setup().
|
inline |
Enable the countdown timer interrupt.
Definition at line 380 of file time/pcf8563/SensorPCF8563.hpp.
References SensorCommWrapper::setRegBit(), and STAT2_REG.
|
inline |
Read the currently configured alarm settings.
Definition at line 204 of file time/pcf8563/SensorPCF8563.hpp.
References ALRM_MIN_REG, SensorRTC::BCD2DEC(), and SensorCommWrapper::readRegBuff().
|
inlineoverridevirtual |
Get the chip name string.
Implements SensorRTC.
Definition at line 439 of file time/pcf8563/SensorPCF8563.hpp.
|
inlineoverridevirtual |
Get the current RTC date/time.
Reads the registers and converts the BCD values into a RTC_DateTime.
Implements SensorRTC.
Definition at line 166 of file time/pcf8563/SensorPCF8563.hpp.
References SensorRTC::BCD2DEC(), CENTURY_MASK, SensorCommWrapper::readRegBuff(), and SEC_REG.
Referenced by loop(), and setAlarm().
|
virtual |
Get the current date and time from the RTC.
This is a pure virtual function that derived classes must implement. It retrieves the current date and time from the RTC and returns them as an RTC_DateTime object.
Implements SensorRTC.
|
inline |
Retrieve the current date and time from the RTC (Real-Time Clock) and populate a struct tm object.
This function fetches the current date and time information from the RTC device. It then fills the provided struct tm object with the corresponding values. The struct tm object is a standard C structure used to represent date and time components, such as year, month, day, hour, minute, and second.
| info | A pointer to a struct tm object where the retrieved date and time information will be stored. This pointer must not be a null pointer |
struct tm object is the number of years since 1900. The month value ranges from 0 (January) to 11 (December). The day value represents the day of the month, starting from 1. The hour value ranges from 0 to 23, the minute and second values range from 0 to 59. Definition at line 335 of file SensorRTC.h.
|
inline |
Check whether the alarm flag is active.
Definition at line 244 of file time/pcf8563/SensorPCF8563.hpp.
References SensorCommWrapper::getRegBit(), and STAT2_REG.
Referenced by testAlarmDay(), testAlarmHour(), and testAlarmMinute().
|
inline |
Check whether the clock integrity is guaranteed.
The PCF8563 sets the VL (Voltage Low) flag when the supply voltage has dropped below the minimum for reliable timekeeping.
Definition at line 191 of file time/pcf8563/SensorPCF8563.hpp.
References SensorCommWrapper::getRegBit(), and SEC_REG.
Referenced by setup().
|
inline |
Check whether the countdown timer flag is active.
Definition at line 372 of file time/pcf8563/SensorPCF8563.hpp.
References SensorCommWrapper::getRegBit(), and STAT2_REG.
|
inline |
Check whether the countdown timer is enabled.
This checks both the timer interrupt enable (TIE) and timer enable (TE) bits.
Definition at line 357 of file time/pcf8563/SensorPCF8563.hpp.
References SensorCommWrapper::readReg(), STAT2_REG, TIMER1_REG, TIMER_TE, and TIMER_TIE.
|
inlineoverridevirtual |
Reset the RTC.
Reimplemented from SensorRTC.
Definition at line 447 of file time/pcf8563/SensorPCF8563.hpp.
|
inline |
Clear the alarm flag.
Definition at line 235 of file time/pcf8563/SensorPCF8563.hpp.
References SensorCommWrapper::clrRegBit(), and STAT2_REG.
Referenced by testAlarmDay(), testAlarmHour(), and testAlarmMinute().
|
inline |
Set the alarm configuration.
| alarm | Alarm configuration object. |
Definition at line 253 of file time/pcf8563/SensorPCF8563.hpp.
References RTC_Alarm::getDay(), RTC_Alarm::getHour(), RTC_Alarm::getMinute(), RTC_Alarm::getWeek(), and setAlarm().
Referenced by setAlarm(), setAlarmByDays(), setAlarmByHours(), setAlarmByMinutes(), and setAlarmByWeekDay().
|
inline |
Set the alarm configuration.
Any field can be disabled by passing NO_ALARM.
| hour | Hour value [0..23] or NO_ALARM. |
| minute | Minute value [0..59] or NO_ALARM. |
| day | Day-of-month [1..31] or NO_ALARM (clamped to the current month). |
| week | Weekday [0..6] or NO_ALARM. |
Definition at line 268 of file time/pcf8563/SensorPCF8563.hpp.
References ALARM_ENABLE, ALRM_MIN_REG, SensorRTC::DEC2BCD(), getDateTime(), SensorRTC::getDaysInMonth(), RTC_DateTime::getMonth(), RTC_DateTime::getYear(), NO_ALARM, and SensorCommWrapper::writeRegBuff().
|
inline |
Convenience API to set an alarm that matches only day-of-month.
| day | Day-of-month value. |
Definition at line 326 of file time/pcf8563/SensorPCF8563.hpp.
References NO_ALARM, and setAlarm().
Referenced by testAlarmHour().
|
inline |
Convenience API to set an alarm that matches only hours.
| hour | Hour value. |
Definition at line 335 of file time/pcf8563/SensorPCF8563.hpp.
References NO_ALARM, and setAlarm().
Referenced by testAlarmMinute().
|
inline |
Convenience API to set an alarm that matches only minutes.
| minute | Minute value [0..59]. |
Definition at line 317 of file time/pcf8563/SensorPCF8563.hpp.
References NO_ALARM, and setAlarm().
Referenced by setup().
|
inline |
Convenience API to set an alarm that matches only weekday.
| week | Weekday [0..6]. |
Definition at line 344 of file time/pcf8563/SensorPCF8563.hpp.
References NO_ALARM, and setAlarm().
|
inline |
Configure the clock output (CLKOUT) pin.
| freq | Output frequency selection. |
Definition at line 426 of file time/pcf8563/SensorPCF8563.hpp.
References CLK_DISABLE, CLK_ENABLE, SensorCommWrapper::clrRegBit(), SQW_REG, and SensorCommWrapper::writeReg().
Referenced by loop().
|
inline |
Configure countdown timer.
| val | Countdown value. |
| freq | Timer frequency selection (see PCF8563Constants). |
Definition at line 399 of file time/pcf8563/SensorPCF8563.hpp.
References SensorCommWrapper::readReg(), TIMER1_REG, TIMER2_REG, TIMER_TD10, and SensorCommWrapper::writeReg().
|
inlineoverridevirtual |
Set the RTC date/time.
Converts the provided datetime to BCD and writes it to the device.
| datetime | Date/time to write. |
Implements SensorRTC.
Definition at line 139 of file time/pcf8563/SensorPCF8563.hpp.
References SensorRTC::DEC2BCD(), RTC_DateTime::getDay(), SensorRTC::getDayOfWeek(), RTC_DateTime::getHour(), RTC_DateTime::getMinute(), RTC_DateTime::getMonth(), RTC_DateTime::getSecond(), RTC_DateTime::getYear(), SEC_REG, and SensorCommWrapper::writeRegBuff().
Referenced by loop(), setup(), testAlarmDay(), testAlarmHour(), and testAlarmMinute().
|
virtual |
Set the date and time of the RTC using an RTC_DateTime object.
This is a pure virtual function that derived classes must implement. It allows setting the RTC's date and time using a single RTC_DateTime object.
| datetime | An RTC_DateTime object containing the date and time information to set on the RTC. |
Implements SensorRTC.
|
inline |
Set the date and time of the RTC using individual values.
| year | The year to set on the RTC. It's usually a 16 - bit unsigned integer. |
| month | The month to set on the RTC, ranging from 1 (January) to 12 (December). |
| day | The day of the month to set on the RTC, ranging from 1 to 31, depending on the month and leap year. |
| hour | The hour to set on the RTC, ranging from 0 to 23. |
| minute | The minute to set on the RTC, ranging from 0 to 59. |
| second | The second to set on the RTC, ranging from 0 to 59. |
Definition at line 351 of file SensorRTC.h.
|
staticconstexprprotected |
Definition at line 499 of file time/pcf8563/SensorPCF8563.hpp.
Referenced by clearCountdownTimer().
|
staticconstexprprotected |
Definition at line 501 of file time/pcf8563/SensorPCF8563.hpp.
|
staticconstexprprotected |
Definition at line 508 of file time/pcf8563/SensorPCF8563.hpp.
Referenced by setAlarm().
|
staticconstexprprotected |
Definition at line 483 of file time/pcf8563/SensorPCF8563.hpp.
Referenced by getAlarm(), and setAlarm().
|
staticconstexprprotected |
Definition at line 493 of file time/pcf8563/SensorPCF8563.hpp.
Referenced by getDateTime().
|
staticconstexprprotected |
Definition at line 509 of file time/pcf8563/SensorPCF8563.hpp.
Referenced by setClockOutput().
|
staticconstexprprotected |
Definition at line 494 of file time/pcf8563/SensorPCF8563.hpp.
|
staticconstexprprotected |
Definition at line 479 of file time/pcf8563/SensorPCF8563.hpp.
|
staticconstexprprotected |
Definition at line 491 of file time/pcf8563/SensorPCF8563.hpp.
|
staticconstexprprotected |
Definition at line 478 of file time/pcf8563/SensorPCF8563.hpp.
|
staticconstexprprotected |
Definition at line 477 of file time/pcf8563/SensorPCF8563.hpp.
|
staticconstexprprotected |
Definition at line 490 of file time/pcf8563/SensorPCF8563.hpp.
|
staticconstexprprotected |
Definition at line 495 of file time/pcf8563/SensorPCF8563.hpp.
|
staticconstexprprotected |
Definition at line 481 of file time/pcf8563/SensorPCF8563.hpp.
|
staticconstexprprotected |
Definition at line 507 of file time/pcf8563/SensorPCF8563.hpp.
Referenced by setAlarm(), setAlarmByDays(), setAlarmByHours(), setAlarmByMinutes(), and setAlarmByWeekDay().
|
staticconstexprprotected |
Definition at line 476 of file time/pcf8563/SensorPCF8563.hpp.
Referenced by getDateTime(), isClockIntegrityGuaranteed(), and setDateTime().
|
staticconstexprprotected |
Definition at line 484 of file time/pcf8563/SensorPCF8563.hpp.
Referenced by setClockOutput().
|
staticconstexprprotected |
Definition at line 474 of file time/pcf8563/SensorPCF8563.hpp.
|
staticconstexprprotected |
Definition at line 475 of file time/pcf8563/SensorPCF8563.hpp.
Referenced by clearCountdownTimer(), disableAlarm(), disableCountdownTimer(), enableAlarm(), enableCountdownTimer(), isAlarmActive(), isCountdownTimerActive(), isCountdownTimerEnable(), and resetAlarm().
|
staticconstexprprotected |
Definition at line 485 of file time/pcf8563/SensorPCF8563.hpp.
Referenced by clearCountdownTimer(), isCountdownTimerEnable(), and setCountdownTimer().
|
staticconstexprprotected |
Definition at line 486 of file time/pcf8563/SensorPCF8563.hpp.
Referenced by setCountdownTimer().
|
staticconstexprprotected |
Definition at line 496 of file time/pcf8563/SensorPCF8563.hpp.
|
staticconstexprprotected |
Definition at line 504 of file time/pcf8563/SensorPCF8563.hpp.
Referenced by setCountdownTimer().
|
staticconstexprprotected |
Definition at line 503 of file time/pcf8563/SensorPCF8563.hpp.
Referenced by isCountdownTimerEnable().
|
staticconstexprprotected |
Definition at line 500 of file time/pcf8563/SensorPCF8563.hpp.
Referenced by clearCountdownTimer().
|
staticconstexprprotected |
Definition at line 502 of file time/pcf8563/SensorPCF8563.hpp.
Referenced by clearCountdownTimer(), and isCountdownTimerEnable().
|
staticconstexprprotected |
Definition at line 489 of file time/pcf8563/SensorPCF8563.hpp.
|
staticconstexprprotected |
Definition at line 492 of file time/pcf8563/SensorPCF8563.hpp.
|
staticconstexprprotected |
Definition at line 480 of file time/pcf8563/SensorPCF8563.hpp.
|
staticconstexprprotected |
Definition at line 482 of file time/pcf8563/SensorPCF8563.hpp.