|
STM32duino RTC
Arduino library for managing the RTC peripheral on STM32 boards.
|
Controls the RTC peripheral on an STM32 board. More...
#include <STM32RTC.h>
Public Types | |
| enum | Hour_Format : uint8_t { HOUR_12 = HOUR_FORMAT_12 , HOUR_24 = HOUR_FORMAT_24 } |
| Selects the RTC hour display format. More... | |
| enum | AM_PM : uint8_t { AM = HOUR_AM , PM = HOUR_PM } |
| Selects the AM or PM period in 12-hour format. More... | |
| enum | Binary_Mode : uint8_t { MODE_BCD = MODE_BINARY_NONE , MODE_BIN = MODE_BINARY_ONLY , MODE_MIX = MODE_BINARY_MIX } |
| Selects BCD, binary, or combined RTC mode. More... | |
| enum | Alarm_Match : uint8_t { MATCH_OFF = OFF_MSK , MATCH_SUBSEC = SUBSEC_MSK , MATCH_SS = SS_MSK , MATCH_MMSS = SS_MSK | MM_MSK , MATCH_HHMMSS = SS_MSK | MM_MSK | HH_MSK , MATCH_DHHMMSS = SS_MSK | MM_MSK | HH_MSK | D_MSK , MATCH_MMDDHHMMSS = SS_MSK | MM_MSK | HH_MSK | D_MSK | M_MSK , MATCH_YYMMDDHHMMSS = SS_MSK | MM_MSK | HH_MSK | D_MSK | M_MSK | Y_MSK } |
| Selects which RTC fields must match for an alarm. More... | |
| enum | Source_Clock : uint8_t { LSI_CLOCK = ::LSI_CLOCK , LSE_CLOCK = ::LSE_CLOCK , HSE_CLOCK = ::HSE_CLOCK } |
| Selects the input clock source for the RTC. More... | |
| enum | Alarm : uint32_t { ALARM_A = ::ALARM_A } |
| Identifies an RTC alarm. More... | |
Public Member Functions | |
| STM32RTC (STM32RTC const &)=delete | |
| void | operator= (STM32RTC const &)=delete |
| void | begin (bool resetTime, Hour_Format format=HOUR_24) |
| Initializes the RTC and optionally resets its time. | |
| void | begin (Hour_Format format=HOUR_24) |
| Initializes the RTC without resetting its current time. | |
| void | end (void) |
| Deinitializes the RTC and clears registered callbacks. | |
| RTC_HandleTypeDef * | getHandle (void) |
| Returns the STM32 HAL RTC handle. | |
| Source_Clock | getClockSource (void) |
| Returns the selected RTC input clock source. | |
| void | setClockSource (Source_Clock source, uint32_t predivA=(PREDIVA_MAX+1), uint32_t predivS=(PREDIVS_MAX+1)) |
| Selects the RTC clock source and its prescalers. | |
| void | getPrediv (uint32_t *predivA, uint32_t *predivS) |
| Reads the configured or calculated RTC prescalers. | |
| void | setPrediv (uint32_t predivA, uint32_t predivS) |
| Sets the RTC prescalers. | |
| Binary_Mode | getBinaryMode (void) |
| Returns the current RTC operating mode. | |
| void | setBinaryMode (Binary_Mode mode) |
| Selects BCD, binary, or mixed RTC operation. | |
| void | enableAlarm (Alarm_Match match, Alarm name=ALARM_A) |
| Enables an RTC alarm with the requested match fields. | |
| void | disableAlarm (Alarm name=ALARM_A) |
| Disables an RTC alarm. | |
| void | attachInterrupt (voidFuncPtrParam callback, Alarm name) |
| Attaches a callback to an RTC alarm. | |
| void | attachInterrupt (voidFuncPtrParam callback, void *data=nullptr, Alarm name=ALARM_A) |
| Attaches a callback and user data to an RTC alarm. | |
| void | detachInterrupt (Alarm name=ALARM_A) |
| Detaches the callback from an RTC alarm. | |
| void | standbyMode () |
| Compatibility method; use the STM32LowPower library for standby mode. | |
| uint32_t | getSubSeconds (void) |
| Returns the current subsecond value in milliseconds. | |
| uint8_t | getSeconds (void) |
| Returns the current seconds value. | |
| uint8_t | getMinutes (void) |
| Returns the current minutes value. | |
| uint8_t | getHours (AM_PM *period=nullptr) |
| Returns the current hours value. | |
| void | getTime (uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, AM_PM *period=nullptr) |
| Reads the current time. | |
| uint8_t | getWeekDay (void) |
| Returns the current weekday. | |
| uint8_t | getDay (void) |
| Returns the current day of the month. | |
| uint8_t | getMonth (void) |
| Returns the current month. | |
| uint8_t | getYear (void) |
| Returns the current year value. | |
| void | getDate (uint8_t *weekDay, uint8_t *day, uint8_t *month, uint8_t *year) |
| Reads the current date. | |
| uint32_t | getAlarmSubSeconds (Alarm name=ALARM_A) |
| Returns the alarm subsecond value in milliseconds. | |
| uint8_t | getAlarmSeconds (Alarm name=ALARM_A) |
| Returns the alarm seconds value. | |
| uint8_t | getAlarmMinutes (Alarm name=ALARM_A) |
| Returns the alarm minutes value. | |
| uint8_t | getAlarmHours (Alarm name) |
| Returns the alarm hours value. | |
| uint8_t | getAlarmHours (AM_PM *period=nullptr, Alarm name=ALARM_A) |
| Returns the alarm hours value and optionally its AM/PM period. | |
| uint8_t | getAlarmDay (Alarm name=ALARM_A) |
| Returns the alarm day of the month. | |
| uint8_t | getAlarmMonth (void) |
| Returns zero; STM32 RTC alarms do not match a month. | |
| uint8_t | getAlarmYear (void) |
| Returns zero; STM32 RTC alarms do not match a year. | |
| void | setSubSeconds (uint32_t subSeconds) |
| Sets the current subsecond value in milliseconds. | |
| void | setSeconds (uint8_t seconds) |
| Sets the current seconds value. | |
| void | setMinutes (uint8_t minutes) |
| Sets the current minutes value. | |
| void | setHours (uint8_t hours, AM_PM period=AM) |
| Sets the current hour value and optional AM/PM period. | |
| void | setTime (uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds=1000, AM_PM period=AM) |
| Sets the current time. | |
| void | setWeekDay (uint8_t weekDay) |
| Sets the current weekday. | |
| void | setDay (uint8_t day) |
| Sets the current day of the month. | |
| void | setMonth (uint8_t month) |
| Sets the current month. | |
| void | setYear (uint8_t year) |
| Sets the current year value. | |
| void | setDate (uint8_t day, uint8_t month, uint8_t year) |
| Sets the current date without changing the weekday. | |
| void | setDate (uint8_t weekDay, uint8_t day, uint8_t month, uint8_t year) |
| Sets the current weekday and date. | |
| void | setAlarmSubSeconds (uint32_t subSeconds, Alarm name=ALARM_A) |
| Sets the alarm subsecond value in milliseconds. | |
| void | setAlarmSeconds (uint8_t seconds, Alarm name=ALARM_A) |
| Sets the alarm seconds value. | |
| void | setAlarmMinutes (uint8_t minutes, Alarm name=ALARM_A) |
| Sets the alarm minutes value. | |
| void | setAlarmHours (uint8_t hours, Alarm name) |
| Sets the alarm hours value. | |
| void | setAlarmHours (uint8_t hours, AM_PM period=AM, Alarm name=ALARM_A) |
| Sets the alarm hours value and optional AM/PM period. | |
| void | setAlarmTime (uint32_t subSeconds, Alarm name=ALARM_A) |
| Sets an alarm using a subsecond value. | |
| void | setAlarmTime (uint8_t hours, uint8_t minutes, uint8_t seconds, Alarm name) |
| Sets an alarm time without a subsecond value. | |
| void | setAlarmTime (uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, Alarm name) |
| Sets an alarm time and subsecond value. | |
| void | setAlarmTime (uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds=0, AM_PM period=AM, Alarm name=ALARM_A) |
| Sets an alarm time. | |
| void | setAlarmDay (uint8_t day, Alarm name=ALARM_A) |
| Sets the alarm day of the month. | |
| void | setAlarmMonth (uint8_t month) |
| Compatibility method; the month is ignored by STM32 RTC alarms. | |
| void | setAlarmYear (uint8_t year) |
| Compatibility method; the year is ignored by STM32 RTC alarms. | |
| void | setAlarmDate (uint8_t day, uint8_t month, uint8_t year, Alarm name=ALARM_A) |
| Sets the alarm day; the month and year are ignored. | |
| time_t | getEpoch (uint32_t *subSeconds=nullptr) |
| Returns the current Unix epoch time. | |
| time_t | getY2kEpoch (void) |
| Returns the current time as seconds since the Y2K epoch. | |
| void | setEpoch (time_t ts, uint32_t subSeconds=0) |
| Sets the RTC from a Unix epoch timestamp. | |
| void | setY2kEpoch (time_t ts) |
| Sets the RTC from seconds since the Y2K epoch. | |
| time_t | getAlarmEpoch (Alarm name) |
| Returns the configured alarm's epoch timestamp. | |
| time_t | getAlarmEpoch (uint32_t *subSeconds=nullptr, Alarm name=ALARM_A) |
| Returns the configured alarm's epoch timestamp. | |
| void | setAlarmEpoch (time_t ts, Alarm_Match match, Alarm name) |
| Configures an alarm from an epoch timestamp. | |
| void | setAlarmEpoch (time_t ts, Alarm_Match match=MATCH_DHHMMSS, uint32_t subSeconds=0, Alarm name=ALARM_A) |
| Configures an alarm from an epoch timestamp. | |
| bool | isConfigured (void) |
| Reports whether the RTC peripheral is configured. | |
| bool | isFormat_24hour (void) |
| Reports whether the current hour format is 24-hour. | |
| bool | isAlarmEnabled (Alarm name=ALARM_A) |
| Reports whether the selected alarm is enabled. | |
| bool | isTimeSet (void) |
| Reports whether the library has set the current time. | |
Static Public Member Functions | |
| static STM32RTC & | getInstance () |
| Returns the singleton RTC controller. | |
Friends | |
| class | STM32LowPower |
Controls the RTC peripheral on an STM32 board.
Use getInstance() to access the single library instance.
| enum STM32RTC::Alarm : uint32_t |
| enum STM32RTC::Alarm_Match : uint8_t |
| enum STM32RTC::AM_PM : uint8_t |
| enum STM32RTC::Binary_Mode : uint8_t |
| enum STM32RTC::Hour_Format : uint8_t |
| enum STM32RTC::Source_Clock : uint8_t |
|
delete |
| void STM32RTC::attachInterrupt | ( | voidFuncPtrParam | callback, |
| Alarm | name ) |
Attaches a callback to an RTC alarm.
| callback | Function called when the alarm fires. |
| name | Alarm that invokes the callback. |
| void STM32RTC::attachInterrupt | ( | voidFuncPtrParam | callback, |
| void * | data = nullptr, | ||
| Alarm | name = ALARM_A ) |
Attaches a callback and user data to an RTC alarm.
| callback | Function called when the alarm fires. |
| data | User data passed to the callback. |
| name | Alarm that invokes the callback. |
| void STM32RTC::begin | ( | bool | resetTime, |
| Hour_Format | format = HOUR_24 ) |
Initializes the RTC and optionally resets its time.
| resetTime | Set true to reset the RTC registers. |
| format | Hour format to use. |
| void STM32RTC::begin | ( | Hour_Format | format = HOUR_24 | ) |
Initializes the RTC without resetting its current time.
| format | Hour format to use. |
Detaches the callback from an RTC alarm.
| name | Alarm whose callback will be detached. |
Disables an RTC alarm.
| name | Alarm to disable; defaults to ALARM_A. |
| void STM32RTC::enableAlarm | ( | Alarm_Match | match, |
| Alarm | name = ALARM_A ) |
Enables an RTC alarm with the requested match fields.
| match | Fields that must match when the alarm fires. |
| name | Alarm to enable. |
| void STM32RTC::end | ( | void | ) |
Deinitializes the RTC and clears registered callbacks.
| time_t STM32RTC::getAlarmEpoch | ( | Alarm | name | ) |
| uint8_t STM32RTC::getAlarmHours | ( | Alarm | name | ) |
| uint8_t STM32RTC::getAlarmMonth | ( | void | ) |
Returns zero; STM32 RTC alarms do not match a month.
| uint8_t STM32RTC::getAlarmYear | ( | void | ) |
Returns zero; STM32 RTC alarms do not match a year.
| Binary_Mode STM32RTC::getBinaryMode | ( | void | ) |
Returns the current RTC operating mode.
| Source_Clock STM32RTC::getClockSource | ( | void | ) |
Returns the selected RTC input clock source.
| void STM32RTC::getDate | ( | uint8_t * | weekDay, |
| uint8_t * | day, | ||
| uint8_t * | month, | ||
| uint8_t * | year ) |
Reads the current date.
| weekDay | Optional pointer receiving the weekday. |
| day | Optional pointer receiving the day of the month. |
| month | Optional pointer receiving the month. |
| year | Optional pointer receiving the year value. |
| uint8_t STM32RTC::getDay | ( | void | ) |
Returns the current day of the month.
| time_t STM32RTC::getEpoch | ( | uint32_t * | subSeconds = nullptr | ) |
Returns the current Unix epoch time.
| subSeconds | Optional pointer receiving the subsecond value in milliseconds. |
|
inline |
Returns the STM32 HAL RTC handle.
| uint8_t STM32RTC::getHours | ( | AM_PM * | period = nullptr | ) |
Returns the current hours value.
| period | Optional pointer receiving AM or PM in 12-hour mode. |
|
inlinestatic |
Returns the singleton RTC controller.
| uint8_t STM32RTC::getMinutes | ( | void | ) |
Returns the current minutes value.
| uint8_t STM32RTC::getMonth | ( | void | ) |
Returns the current month.
| void STM32RTC::getPrediv | ( | uint32_t * | predivA, |
| uint32_t * | predivS ) |
Reads the configured or calculated RTC prescalers.
| predivA | Receives the asynchronous prescaler. |
| predivS | Receives the synchronous prescaler; unused on STM32F1. |
| uint8_t STM32RTC::getSeconds | ( | void | ) |
Returns the current seconds value.
| uint32_t STM32RTC::getSubSeconds | ( | void | ) |
Returns the current subsecond value in milliseconds.
| void STM32RTC::getTime | ( | uint8_t * | hours, |
| uint8_t * | minutes, | ||
| uint8_t * | seconds, | ||
| uint32_t * | subSeconds, | ||
| AM_PM * | period = nullptr ) |
Reads the current time.
| hours | Optional pointer receiving the hour value. |
| minutes | Optional pointer receiving the minute value. |
| seconds | Optional pointer receiving the second value. |
| subSeconds | Optional pointer receiving the subsecond value in milliseconds. |
| period | Optional pointer receiving AM or PM in 12-hour mode. |
| uint8_t STM32RTC::getWeekDay | ( | void | ) |
Returns the current weekday.
| time_t STM32RTC::getY2kEpoch | ( | void | ) |
Returns the current time as seconds since the Y2K epoch.
| uint8_t STM32RTC::getYear | ( | void | ) |
Returns the current year value.
Reports whether the selected alarm is enabled.
| name | Alarm to check. |
|
inline |
Reports whether the RTC peripheral is configured.
|
inline |
Reports whether the current hour format is 24-hour.
|
inline |
Reports whether the library has set the current time.
|
delete |
Sets the alarm day; the month and year are ignored.
| day | Day value in the range 1-31. |
| month | Ignored. |
| year | Ignored. |
| name | Alarm to configure. |
Sets the alarm day of the month.
| day | Day value in the range 1-31. |
| name | Alarm to configure. |
| void STM32RTC::setAlarmEpoch | ( | time_t | ts, |
| Alarm_Match | match, | ||
| Alarm | name ) |
Configures an alarm from an epoch timestamp.
| ts | Epoch timestamp. |
| match | Fields that must match when the alarm fires. |
| name | Alarm to configure. |
| void STM32RTC::setAlarmEpoch | ( | time_t | ts, |
| Alarm_Match | match = MATCH_DHHMMSS, | ||
| uint32_t | subSeconds = 0, | ||
| Alarm | name = ALARM_A ) |
Configures an alarm from an epoch timestamp.
| ts | Epoch timestamp. |
| match | Fields that must match when the alarm fires. |
| subSeconds | Subsecond value in milliseconds. |
| name | Alarm to configure. |
| void STM32RTC::setAlarmHours | ( | uint8_t | hours, |
| Alarm | name ) |
Sets the alarm hours value.
| hours | Hour value. |
| name | Alarm to configure. |
Sets the alarm hours value and optional AM/PM period.
| hours | Hour value. |
| period | AM or PM when using 12-hour format. |
| name | Alarm to configure. |
Sets the alarm minutes value.
| minutes | Minutes value in the range 0-59. |
| name | Alarm to configure. |
| void STM32RTC::setAlarmMonth | ( | uint8_t | month | ) |
Compatibility method; the month is ignored by STM32 RTC alarms.
| month | Ignored. |
Sets the alarm seconds value.
| seconds | Seconds value in the range 0-59. |
| name | Alarm to configure. |
Sets the alarm subsecond value in milliseconds.
| subSeconds | Subsecond value; 0-999 in BCD/MIX mode. |
| name | Alarm to configure. |
Sets an alarm using a subsecond value.
| subSeconds | Subsecond value in milliseconds. |
| name | Alarm to configure. |
| void STM32RTC::setAlarmTime | ( | uint8_t | hours, |
| uint8_t | minutes, | ||
| uint8_t | seconds, | ||
| Alarm | name ) |
Sets an alarm time without a subsecond value.
| hours | Hour value. |
| minutes | Minute value. |
| seconds | Second value. |
| name | Alarm to configure. |
| void STM32RTC::setAlarmTime | ( | uint8_t | hours, |
| uint8_t | minutes, | ||
| uint8_t | seconds, | ||
| uint32_t | subSeconds, | ||
| Alarm | name ) |
Sets an alarm time and subsecond value.
| hours | Hour value. |
| minutes | Minute value. |
| seconds | Second value. |
| subSeconds | Subsecond value in milliseconds. |
| name | Alarm to configure. |
| void STM32RTC::setAlarmTime | ( | uint8_t | hours, |
| uint8_t | minutes, | ||
| uint8_t | seconds, | ||
| uint32_t | subSeconds = 0, | ||
| AM_PM | period = AM, | ||
| Alarm | name = ALARM_A ) |
Sets an alarm time.
| hours | Hour value. |
| minutes | Minute value. |
| seconds | Second value. |
| subSeconds | Subsecond value in milliseconds. |
| period | AM or PM when using 12-hour format. |
| name | Alarm to configure. |
| void STM32RTC::setAlarmYear | ( | uint8_t | year | ) |
Compatibility method; the year is ignored by STM32 RTC alarms.
| year | Ignored. |
| void STM32RTC::setBinaryMode | ( | Binary_Mode | mode | ) |
Selects BCD, binary, or mixed RTC operation.
| mode | Requested RTC mode; unsupported modes fall back to BCD. |
| void STM32RTC::setClockSource | ( | Source_Clock | source, |
| uint32_t | predivA = (PREDIVA_MAX+1), | ||
| uint32_t | predivS = (PREDIVS_MAX+1) ) |
Selects the RTC clock source and its prescalers.
| source | RTC input clock source. |
| predivA | Asynchronous prescaler; use PREDIVA_MAX + 1 for automatic calculation. |
| predivS | Synchronous prescaler; use PREDIVS_MAX + 1 for automatic calculation. |
Call before begin(). For a 1 Hz calendar clock, the source frequency divided by ((predivA + 1) * (predivS + 1)) must equal 1 Hz.
| void STM32RTC::setDate | ( | uint8_t | day, |
| uint8_t | month, | ||
| uint8_t | year ) |
Sets the current date without changing the weekday.
| day | Day value in the range 1-31. |
| month | Month value in the range 1-12. |
| year | Year value in the range 0-99. |
| void STM32RTC::setDate | ( | uint8_t | weekDay, |
| uint8_t | day, | ||
| uint8_t | month, | ||
| uint8_t | year ) |
Sets the current weekday and date.
| weekDay | Weekday value in the range 1-7 (Monday is 1). |
| day | Day value in the range 1-31. |
| month | Month value in the range 1-12. |
| year | Year value in the range 0-99. |
| void STM32RTC::setDay | ( | uint8_t | day | ) |
Sets the current day of the month.
| day | Day value in the range 1-31. |
| void STM32RTC::setEpoch | ( | time_t | ts, |
| uint32_t | subSeconds = 0 ) |
Sets the RTC from a Unix epoch timestamp.
| ts | Epoch timestamp. |
| subSeconds | Subsecond value in milliseconds. |
Sets the current hour value and optional AM/PM period.
| hours | Hour value. |
| period | AM or PM when using 12-hour format. |
| void STM32RTC::setMinutes | ( | uint8_t | minutes | ) |
Sets the current minutes value.
| minutes | Minutes value in the range 0-59. |
| void STM32RTC::setMonth | ( | uint8_t | month | ) |
Sets the current month.
| month | Month value in the range 1-12. |
| void STM32RTC::setPrediv | ( | uint32_t | predivA, |
| uint32_t | predivS ) |
Sets the RTC prescalers.
| predivA | Asynchronous prescaler. |
| predivS | Synchronous prescaler. |
Call before begin().
| void STM32RTC::setSeconds | ( | uint8_t | seconds | ) |
Sets the current seconds value.
| seconds | Seconds value in the range 0-59. |
| void STM32RTC::setSubSeconds | ( | uint32_t | subSeconds | ) |
Sets the current subsecond value in milliseconds.
| subSeconds | Subsecond value in the range 0-999. |
| void STM32RTC::setTime | ( | uint8_t | hours, |
| uint8_t | minutes, | ||
| uint8_t | seconds, | ||
| uint32_t | subSeconds = 1000, | ||
| AM_PM | period = AM ) |
Sets the current time.
| hours | Hour value. |
| minutes | Minute value. |
| seconds | Second value. |
| subSeconds | Subsecond value in milliseconds. |
| period | AM or PM when using 12-hour format. |
| void STM32RTC::setWeekDay | ( | uint8_t | weekDay | ) |
Sets the current weekday.
| weekDay | Weekday value in the range 1-7 (Monday is 1). |
| void STM32RTC::setY2kEpoch | ( | time_t | ts | ) |
Sets the RTC from seconds since the Y2K epoch.
| ts | Seconds since 2000-01-01 00:00:00. |
| void STM32RTC::setYear | ( | uint8_t | year | ) |
Sets the current year value.
| year | Year value in the range 0-99. |
| void STM32RTC::standbyMode | ( | ) |
Compatibility method; use the STM32LowPower library for standby mode.
|
friend |