|
SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
|
Driver for the PCF85063 real-time clock (RTC) over I2C. More...
#include <SensorPCF85063.hpp>
Public Types | |
| enum | ClockHz { CLK_32768HZ = 0 , CLK_16384HZ , CLK_8192HZ , CLK_4096HZ , CLK_2048HZ , CLK_1024HZ , CLK_1HZ , CLK_LOW } |
| Clock output frequency selection. More... | |
Public Member Functions | |
| SensorPCF85063 ()=default | |
| Construct a SensorPCF85063 instance. | |
| ~SensorPCF85063 ()=default | |
| Destructor. | |
| bool | begin (SensorCommCustom::CustomCallback callback) |
| Initialize device using a custom transport callback. | |
| void | setDateTime (RTC_DateTime datetime) override |
| Set the RTC date and time. | |
| RTC_DateTime | getDateTime () override |
| Read the RTC date and time. | |
| bool | isClockIntegrityGuaranteed () |
| Check whether the clock integrity is guaranteed. | |
| void | stop () |
| Stop the RTC oscillator (timekeeping stops). | |
| void | start () |
| Start the RTC oscillator (timekeeping runs). | |
| bool | isRunning () |
| Check whether the RTC oscillator is currently running. | |
| void | enableAlarm () |
| Enable alarm interrupt/event generation. | |
| void | disableAlarm () |
| Disable alarm interrupt/event generation. | |
| void | resetAlarm () |
| Clear/reset the alarm flag. | |
| bool | isAlarmActive () |
| Check whether the alarm flag is active. | |
| RTC_Alarm | getAlarm () |
| Read current alarm configuration from the device. | |
| void | setAlarm (RTC_Alarm alarm) |
| Set alarm using RTC_Alarm object. | |
| void | setAlarm (uint8_t hour, uint8_t minute, uint8_t second, uint8_t day, uint8_t week) |
| Set the alarm fields (hour/minute/second/day/weekday). | |
| void | setAlarmByHours (uint8_t hour) |
| Convenience: enable only hour alarm. | |
| void | setAlarmBySecond (uint8_t second) |
| Convenience: enable only second alarm. | |
| void | setAlarmByMinutes (uint8_t minute) |
| Convenience: enable only minute alarm. | |
| void | setAlarmByDays (uint8_t day) |
| Convenience: enable only day-of-month alarm. | |
| void | setAlarmByWeekDay (uint8_t week) |
| Convenience: enable only weekday alarm. | |
| void | setClockOutput (ClockHz hz) |
| Configure the clock output frequency. | |
| const char * | getChipName () override |
| Get RTC chip name. | |
| 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. | |
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 |
Protected Attributes | |
| bool | is24Hour |
| Hour mode flag (true = 24-hour mode). | |
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 |
Static Protected Attributes | |
| static constexpr uint8_t | PCF85063_CTRL1_REG = 0x00 |
| static constexpr uint8_t | PCF85063_CTRL2_REG = 0x01 |
| static constexpr uint8_t | PCF85063_OFFSET_REG = 0x02 |
| static constexpr uint8_t | PCF85063_RAM_REG = 0x03 |
| static constexpr uint8_t | PCF85063_SEC_REG = 0x04 |
| static constexpr uint8_t | PCF85063_MIN_REG = 0x05 |
| static constexpr uint8_t | PCF85063_HR_REG = 0x06 |
| static constexpr uint8_t | PCF85063_DAY_REG = 0x07 |
| static constexpr uint8_t | PCF85063_WEEKDAY_REG = 0x08 |
| static constexpr uint8_t | PCF85063_MONTH_REG = 0x09 |
| static constexpr uint8_t | PCF85063_YEAR_REG = 0x0A |
| static constexpr uint8_t | PCF85063_ALRM_SEC_REG = 0x0B |
| static constexpr uint8_t | PCF85063_ALRM_MIN_REG = 0x0C |
| static constexpr uint8_t | PCF8563_ALRM_HR_REG = 0x0D |
| static constexpr uint8_t | PCF85063_ALRM_DAY_REG = 0x0E |
| static constexpr uint8_t | PCF85063_ALRM_WEEK_REG = 0x0F |
| static constexpr uint8_t | PCF85063_TIMER_VAL_REG = 0x10 |
| static constexpr uint8_t | PCF85063_TIMER_MD_REG = 0x11 |
| static constexpr uint8_t | PCF85063_CTRL1_TEST_EN_MASK = (1 << 7u) |
| static constexpr uint8_t | PCF85063_CTRL1_CLOCK_EN_MASK = (1 << 5u) |
| static constexpr uint8_t | PCF85063_CTRL1_SOFTRST_EN_MASK = (1 << 4u) |
| static constexpr uint8_t | PCF85063_CTRL1_CIE_EN_MASK = (1 << 2u) |
| static constexpr uint8_t | PCF85063_CTRL1_HOUR_FORMAT_12H_MASK = (1 << 1u) |
| static constexpr uint8_t | PCF85063_NO_ALARM = 0xFF |
| static constexpr uint8_t | PCF85063_ALARM_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) |
Driver for the PCF85063 real-time clock (RTC) over I2C.
Definition at line 48 of file time/pcf85063/SensorPCF85063.hpp.
Clock output frequency selection.
Values map to the PCF85063 clock output control bits (see datasheet).
Definition at line 59 of file time/pcf85063/SensorPCF85063.hpp.
|
default |
Construct a SensorPCF85063 instance.
The instance is not usable until begin() succeeds.
|
default |
Destructor.
Deinitializes the communication backend if created.
References I2CDeviceNoHal::begin(), and PCF85063_SLAVE_ADDRESS.
|
inlinevirtual |
Initialize device using a custom transport callback.
| callback | User-provided callback used by SensorCommCustom. |
Implements SensorRTC.
Definition at line 130 of file time/pcf85063/SensorPCF85063.hpp.
References I2CDeviceNoHal::begin(), and PCF85063_SLAVE_ADDRESS.
Referenced by setup().
|
inline |
Disable alarm interrupt/event generation.
Definition at line 252 of file time/pcf85063/SensorPCF85063.hpp.
References SensorCommWrapper::clrRegBit(), and PCF85063_CTRL2_REG.
|
inline |
Enable alarm interrupt/event generation.
Definition at line 244 of file time/pcf85063/SensorPCF85063.hpp.
References PCF85063_CTRL2_REG, and SensorCommWrapper::setRegBit().
Referenced by setup().
|
inline |
Read current alarm configuration from the device.
Definition at line 283 of file time/pcf85063/SensorPCF85063.hpp.
References SensorRTC::BCD2DEC(), PCF85063_ALRM_MIN_REG, and SensorCommWrapper::readRegBuff().
|
inlineoverridevirtual |
Get RTC chip name.
Implements SensorRTC.
Definition at line 474 of file time/pcf85063/SensorPCF85063.hpp.
|
inlineoverridevirtual |
Read the RTC date and time.
Reads 7 bytes starting from the seconds register and converts BCD values to a RTC_DateTime instance.
Implements SensorRTC.
Definition at line 165 of file time/pcf85063/SensorPCF85063.hpp.
References SensorRTC::BCD2DEC(), is24Hour, PCF85063_SEC_REG, and SensorCommWrapper::readRegBuff().
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 270 of file time/pcf85063/SensorPCF85063.hpp.
References SensorCommWrapper::getRegBit(), and PCF85063_CTRL2_REG.
Referenced by testAlarmDay(), testAlarmHour(), testAlarmMinute(), and testAlarmSeconds().
|
inline |
Check whether the clock integrity is guaranteed.
Typically this is determined by the "OS" (oscillator stop) flag in the seconds register. If the oscillator has stopped, the time registers may not be reliable.
Definition at line 201 of file time/pcf85063/SensorPCF85063.hpp.
References SensorCommWrapper::getRegBit(), and PCF85063_SEC_REG.
Referenced by setup().
|
inline |
Check whether the RTC oscillator is currently running.
Definition at line 236 of file time/pcf85063/SensorPCF85063.hpp.
References SensorCommWrapper::getRegBit(), and PCF85063_CTRL1_REG.
|
inlineoverridevirtual |
Reset the RTC.
Reimplemented from SensorRTC.
Definition at line 482 of file time/pcf85063/SensorPCF85063.hpp.
References PCF85063_CTRL1_REG, and SensorCommWrapper::writeReg().
|
inline |
Clear/reset the alarm flag.
Definition at line 260 of file time/pcf85063/SensorPCF85063.hpp.
References SensorCommWrapper::clrRegBit(), and PCF85063_CTRL2_REG.
Referenced by testAlarmDay(), testAlarmHour(), testAlarmMinute(), and testAlarmSeconds().
|
inline |
Set alarm using RTC_Alarm object.
| alarm | Alarm configuration object. |
Definition at line 301 of file time/pcf85063/SensorPCF85063.hpp.
References RTC_Alarm::getDay(), RTC_Alarm::getHour(), RTC_Alarm::getMinute(), RTC_Alarm::getSecond(), RTC_Alarm::getWeek(), and setAlarm().
Referenced by setAlarm(), setAlarmByDays(), setAlarmByHours(), setAlarmByMinutes(), setAlarmBySecond(), and setAlarmByWeekDay().
|
inline |
Set the alarm fields (hour/minute/second/day/weekday).
Any field can be disabled by passing PCF85063_NO_ALARM. Values out of range will be clamped where appropriate.
| hour | Hour [0..23] (24H mode) or chip-specific in 12H mode; or PCF85063_NO_ALARM. |
| minute | Minute [0..59]; or PCF85063_NO_ALARM. |
| second | Second [0..59]; or PCF85063_NO_ALARM. |
| day | Day of month [1..daysInMonth]; or PCF85063_NO_ALARM. |
| week | Weekday [0..6]; or PCF85063_NO_ALARM. |
Definition at line 319 of file time/pcf85063/SensorPCF85063.hpp.
References SensorRTC::DEC2BCD(), getDateTime(), SensorRTC::getDaysInMonth(), RTC_DateTime::getMonth(), RTC_DateTime::getYear(), is24Hour, PCF85063_ALARM_ENABLE, PCF85063_ALRM_SEC_REG, PCF85063_NO_ALARM, and SensorCommWrapper::writeRegBuff().
|
inline |
Convenience: enable only day-of-month alarm.
| day | Day of month [1..31] (will be clamped to valid range for current month). |
Definition at line 431 of file time/pcf85063/SensorPCF85063.hpp.
References PCF85063_NO_ALARM, and setAlarm().
Referenced by testAlarmHour().
|
inline |
Convenience: enable only hour alarm.
| hour | Hour [0..23]. |
Definition at line 389 of file time/pcf85063/SensorPCF85063.hpp.
References PCF85063_NO_ALARM, and setAlarm().
Referenced by testAlarmMinute().
|
inline |
Convenience: enable only minute alarm.
| minute | Minute [0..59]. |
Definition at line 417 of file time/pcf85063/SensorPCF85063.hpp.
References PCF85063_NO_ALARM, and setAlarm().
Referenced by testAlarmSeconds().
|
inline |
Convenience: enable only second alarm.
| second | Second [0..59]. |
Definition at line 403 of file time/pcf85063/SensorPCF85063.hpp.
References PCF85063_NO_ALARM, and setAlarm().
Referenced by setup().
|
inline |
Convenience: enable only weekday alarm.
| week | Weekday [0..6]. |
Definition at line 445 of file time/pcf85063/SensorPCF85063.hpp.
References PCF85063_NO_ALARM, and setAlarm().
|
inline |
Configure the clock output frequency.
| hz | Output frequency selection. |
Definition at line 459 of file time/pcf85063/SensorPCF85063.hpp.
References PCF85063_CTRL2_REG, SensorCommWrapper::readReg(), and SensorCommWrapper::writeReg().
Referenced by loop().
|
inlineoverridevirtual |
Set the RTC date and time.
This method converts RTC_DateTime into the PCF85063 register format (BCD) and writes to the seconds register onward.
| datetime | Date-time object to set. |
Implements SensorRTC.
Definition at line 143 of file time/pcf85063/SensorPCF85063.hpp.
References SensorRTC::DEC2BCD(), RTC_DateTime::getDay(), SensorRTC::getDayOfWeek(), RTC_DateTime::getHour(), RTC_DateTime::getMinute(), RTC_DateTime::getMonth(), RTC_DateTime::getSecond(), RTC_DateTime::getYear(), PCF85063_SEC_REG, and SensorCommWrapper::writeRegBuff().
Referenced by loop(), setup(), testAlarmDay(), testAlarmHour(), testAlarmMinute(), and testAlarmSeconds().
|
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.
|
inline |
Start the RTC oscillator (timekeeping runs).
Clears the STOP bit in CTRL1.
Definition at line 226 of file time/pcf85063/SensorPCF85063.hpp.
References SensorCommWrapper::clrRegBit(), and PCF85063_CTRL1_REG.
|
inline |
Stop the RTC oscillator (timekeeping stops).
Sets the STOP bit in CTRL1.
Definition at line 216 of file time/pcf85063/SensorPCF85063.hpp.
References PCF85063_CTRL1_REG, and SensorCommWrapper::setRegBit().
|
protected |
Hour mode flag (true = 24-hour mode).
This is detected (and forced to 24H) during initialization.
Definition at line 552 of file time/pcf85063/SensorPCF85063.hpp.
Referenced by getDateTime(), and setAlarm().
|
staticconstexprprotected |
Definition at line 583 of file time/pcf85063/SensorPCF85063.hpp.
Referenced by setAlarm().
|
staticconstexprprotected |
Definition at line 569 of file time/pcf85063/SensorPCF85063.hpp.
|
staticconstexprprotected |
Definition at line 567 of file time/pcf85063/SensorPCF85063.hpp.
Referenced by getAlarm().
|
staticconstexprprotected |
Definition at line 566 of file time/pcf85063/SensorPCF85063.hpp.
Referenced by setAlarm().
|
staticconstexprprotected |
Definition at line 570 of file time/pcf85063/SensorPCF85063.hpp.
|
staticconstexprprotected |
Definition at line 578 of file time/pcf85063/SensorPCF85063.hpp.
|
staticconstexprprotected |
Definition at line 576 of file time/pcf85063/SensorPCF85063.hpp.
|
staticconstexprprotected |
Definition at line 579 of file time/pcf85063/SensorPCF85063.hpp.
|
staticconstexprprotected |
Definition at line 555 of file time/pcf85063/SensorPCF85063.hpp.
Referenced by isRunning(), reset(), start(), and stop().
|
staticconstexprprotected |
Definition at line 577 of file time/pcf85063/SensorPCF85063.hpp.
|
staticconstexprprotected |
Definition at line 575 of file time/pcf85063/SensorPCF85063.hpp.
|
staticconstexprprotected |
Definition at line 556 of file time/pcf85063/SensorPCF85063.hpp.
Referenced by disableAlarm(), enableAlarm(), isAlarmActive(), resetAlarm(), and setClockOutput().
|
staticconstexprprotected |
Definition at line 562 of file time/pcf85063/SensorPCF85063.hpp.
|
staticconstexprprotected |
Definition at line 561 of file time/pcf85063/SensorPCF85063.hpp.
|
staticconstexprprotected |
Definition at line 560 of file time/pcf85063/SensorPCF85063.hpp.
|
staticconstexprprotected |
Definition at line 564 of file time/pcf85063/SensorPCF85063.hpp.
|
staticconstexprprotected |
Definition at line 582 of file time/pcf85063/SensorPCF85063.hpp.
Referenced by setAlarm(), setAlarmByDays(), setAlarmByHours(), setAlarmByMinutes(), setAlarmBySecond(), and setAlarmByWeekDay().
|
staticconstexprprotected |
Definition at line 557 of file time/pcf85063/SensorPCF85063.hpp.
|
staticconstexprprotected |
Definition at line 558 of file time/pcf85063/SensorPCF85063.hpp.
|
staticconstexprprotected |
Definition at line 559 of file time/pcf85063/SensorPCF85063.hpp.
Referenced by getDateTime(), isClockIntegrityGuaranteed(), and setDateTime().
|
staticconstexprprotected |
Definition at line 572 of file time/pcf85063/SensorPCF85063.hpp.
|
staticconstexprprotected |
Definition at line 571 of file time/pcf85063/SensorPCF85063.hpp.
|
staticconstexprprotected |
Definition at line 563 of file time/pcf85063/SensorPCF85063.hpp.
|
staticconstexprprotected |
Definition at line 565 of file time/pcf85063/SensorPCF85063.hpp.
|
staticconstexprprotected |
Definition at line 568 of file time/pcf85063/SensorPCF85063.hpp.