From 3ab74acef0758e722893e385b4afccabccc4eddc Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Thu, 3 Dec 2026 17:06:29 +0100 Subject: [PATCH 1/3] ci(docs): add API documentation workflows Run the reusable documentation check on pull requests and publish versioned docs from main and release tags. Assisted-by: GitHub Copilot: gpt-6-luna Signed-off-by: Frederic Pillon --- .github/workflows/docs-check.yml | 21 +++++++++++++++++++++ .github/workflows/publish-docs.yml | 16 ++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 .github/workflows/docs-check.yml create mode 100644 .github/workflows/publish-docs.yml diff --git a/.github/workflows/docs-check.yml b/.github/workflows/docs-check.yml new file mode 100644 index 0000000..b71f7c7 --- /dev/null +++ b/.github/workflows/docs-check.yml @@ -0,0 +1,21 @@ +name: Documentation build + +on: + pull_request: + push: + branches: + - main + paths: + - Doxyfile + - docs/** + - README.md + - src/** + - mkdocs.yml + - .github/workflows/docs-check.yml + +permissions: + contents: read + +jobs: + build: + uses: stm32duino/actions/.github/workflows/check-library-docs.yml@main diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml new file mode 100644 index 0000000..58fdeea --- /dev/null +++ b/.github/workflows/publish-docs.yml @@ -0,0 +1,16 @@ +name: Publish versioned documentation + +on: + push: + branches: + - main + tags: + - "[0-9]*" + workflow_dispatch: + +permissions: + contents: write + +jobs: + publish: + uses: stm32duino/actions/.github/workflows/publish-library-docs.yml@main From 559a16d24baced911adbd60289d7ca5f1efa4375 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Thu, 3 Dec 2026 17:07:02 +0100 Subject: [PATCH 2/3] docs: configure STM32RTC API documentation Generate the API reference from the README and public header, then build a versioned Material site. Link the site from the README and ignore generated output. Assisted-by: GitHub Copilot: gpt-6-luna Signed-off-by: Frederic Pillon --- .gitignore | 2 ++ Doxyfile | 15 +++++++++++++++ README.md | 11 ++++++++--- mkdocs.yml | 13 +++++++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 Doxyfile create mode 100644 mkdocs.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fbf05b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +api-docs +site diff --git a/Doxyfile b/Doxyfile new file mode 100644 index 0000000..d169562 --- /dev/null +++ b/Doxyfile @@ -0,0 +1,15 @@ +PROJECT_NAME = STM32duino RTC +PROJECT_BRIEF = Arduino library for managing the RTC peripheral on STM32 boards. +OUTPUT_DIRECTORY = api-docs +INPUT = README.md src/STM32RTC.h +FILE_PATTERNS = *.h *.md +RECURSIVE = YES +USE_MDFILE_AS_MAINPAGE = README.md +EXTRACT_ALL = YES +GENERATE_HTML = YES +HTML_OUTPUT = html +GENERATE_LATEX = NO +GENERATE_XML = NO +QUIET = YES +WARN_IF_UNDOCUMENTED = NO +WARN_AS_ERROR = NO diff --git a/README.md b/README.md index 32507d1..652bc8e 100644 --- a/README.md +++ b/README.md @@ -168,9 +168,10 @@ Some STM32 RTC have a binary mode with 32-bit free-running counter in addition to their BCD mode for calendar (for example stm32wl55). Combined with BCD this is the MIX mode. Only using the binary counter is the BIN mode. Three RTC functional modes are available: - - `STM32RTC::MODE_BCD` - - `STM32RTC::MODE_MIX` - - `STM32RTC::MODE_BIN` + +- `STM32RTC::MODE_BCD` +- `STM32RTC::MODE_MIX` +- `STM32RTC::MODE_BIN` * **`Binary_Mode getBinaryMode(void);`** * **`void setBinaryMode(Binary_Mode mode);`** @@ -204,3 +205,7 @@ Returns True if the current Hour Format is HOUR_24 else false if Hour format is Source files available at: https://github.com/stm32duino/STM32RTC + +## Documentation + +See the [STM32RTC API documentation](https://stm32duino.github.io/STM32RTC/). diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..ca62486 --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,13 @@ +site_name: STM32duino RTC +site_description: STM32duino RTC Arduino library API reference +site_url: https://stm32duino.github.io/STM32RTC/ +repo_name: stm32duino/STM32RTC +repo_url: https://github.com/stm32duino/STM32RTC +docs_dir: api-docs/html + +theme: + name: material + +extra: + version: + provider: mike From 8c4fde80021e72fb2597fba140b052656e3a6d98 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Thu, 3 Dec 2026 17:10:10 +0100 Subject: [PATCH 3/3] docs: move RTC API contracts into headers Document public contracts in STM32RTC.h and rtc.h with matching parameter names and return tags. Keep implementation details and source-only helper and callback docs beside their definitions. Assisted-by: GitHub Copilot: gpt-6-luna Signed-off-by: Frederic Pillon --- src/STM32RTC.cpp | 451 +---------------------------------------------- src/STM32RTC.h | 375 ++++++++++++++++++++++++++++++++++++++- src/rtc.c | 283 +++++++---------------------- src/rtc.h | 132 +++++++++++++- 4 files changed, 569 insertions(+), 672 deletions(-) diff --git a/src/STM32RTC.cpp b/src/STM32RTC.cpp index 3d7e71f..0699386 100644 --- a/src/STM32RTC.cpp +++ b/src/STM32RTC.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * @file STM32RTC.cpp * @author Frederic Pillon - * @brief Provides a RTC interface for Arduino + * @brief Implements the STM32 RTC Arduino interface. * ****************************************************************************** * @attention @@ -41,22 +41,11 @@ // Initialize static variable bool STM32RTC::_timeSet = false; -/** - * @brief initializes the RTC - * @param format: hour format: HOUR_12 or HOUR_24(default) - * @retval None - */ void STM32RTC::begin(Hour_Format format) { begin(false, format); } -/** - * @brief initializes the RTC - * @param resetTime: if true reconfigures the RTC - * @param format: hour format: HOUR_12 or HOUR_24(default) - * @retval None - */ void STM32RTC::begin(bool resetTime, Hour_Format format) { bool reinit; @@ -111,36 +100,17 @@ void STM32RTC::begin(bool resetTime, Hour_Format format) #endif } -/** - * @brief Deinitialize and stop the RTC - * @param None - * @retval None - */ void STM32RTC::end(void) { RTC_DeInit(true); _timeSet = false; } -/** - * @brief get the RTC clock source. - * @retval clock source: LSI_CLOCK, LSE_CLOCK or HSE_CLOCK - */ STM32RTC::Source_Clock STM32RTC::getClockSource(void) { return _clockSource; } -/** - * @brief set the RTC clock source and user (a)synchronous prescalers values. - * @note By default LSI clock is selected. This method must be called before begin(). - * @param source: clock source: LSI_CLOCK, LSE_CLOCK or HSE_CLOCK - * @param predivA: Asynchronous prescaler value. - * @note Reset value: RTC_AUTO_1_SECOND for STM32F1xx series, else (PREDIVA_MAX + 1) - * @param predivS: Synchronous prescaler value. - * @note Reset value: (PREDIVS_MAX + 1), not used for STM32F1xx series. - * @retval None - */ void STM32RTC::setClockSource(Source_Clock source, uint32_t predivA, uint32_t predivS) { if (IS_CLOCK_SOURCE(source)) { @@ -156,21 +126,11 @@ void STM32RTC::setClockSource(Source_Clock source, uint32_t predivA, uint32_t pr RTC_setPrediv(predivA, predivS); } -/** - * @brief get the Binary Mode. - * @retval mode: MODE_BCD, MODE_BIN or MODE_MIX - */ STM32RTC::Binary_Mode STM32RTC::getBinaryMode(void) { return _mode; } -/** - * @brief set the Binary Mode. By default MODE_BCD is selected. This - * method must be called before begin(). - * @param mode: the RTC mode: MODE_BCD, MODE_BIN or MODE_MIX - * @retval None - */ void STM32RTC::setBinaryMode(Binary_Mode mode) { #if defined(LL_RTC_BINARY_NONE) @@ -181,14 +141,6 @@ void STM32RTC::setBinaryMode(Binary_Mode mode) #endif /* LL_RTC_BINARY_NONE */ } -/** - * @brief get user (a)synchronous prescaler values if set else computed - * ones for the current clock source. - * @param predivA: pointer to the current Asynchronous prescaler value - * @param predivS: pointer to the current Synchronous prescaler value, - * not used for STM32F1xx series. - * @retval None - */ void STM32RTC::getPrediv(uint32_t *predivA, uint32_t *predivS) { if ((predivA != nullptr) @@ -200,27 +152,11 @@ void STM32RTC::getPrediv(uint32_t *predivA, uint32_t *predivS) } } -/** - * @brief set user (a)synchronous prescalers values. - * @note This method must be called before begin(). - * @param predivA: Asynchronous prescaler value. - * @note Reset value: RTC_AUTO_1_SECOND for STM32F1xx series, else (PREDIVA_MAX + 1) - * @param predivS: Synchronous prescaler value. - * @note Reset value: (PREDIVS_MAX + 1), not used for STM32F1xx series. - * @retval None - */ void STM32RTC::setPrediv(uint32_t predivA, uint32_t predivS) { setClockSource(_clockSource, predivA, predivS); } -/** - * @brief enable the RTC alarm. - * @param match: Alarm_Match configuration - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - * @retval None - */ void STM32RTC::enableAlarm(Alarm_Match match, Alarm name) { #if defined(ALARM_B_AVAILABLE) @@ -283,69 +219,33 @@ void STM32RTC::enableAlarm(Alarm_Match match, Alarm name) } } -/** - * @brief disable the RTC alarm. - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - * @retval None - */ void STM32RTC::disableAlarm(Alarm name) { RTC_StopAlarm(static_cast(name)); } - -/** - * @brief attach a callback to the RTC alarm interrupt. - * @param callback: pointer to the callback - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - * @retval None - */ void STM32RTC::attachInterrupt(voidFuncPtrParam callback, Alarm name) { attachInterrupt(callback, nullptr, name); } -/** - * @brief attach a callback to the RTC alarm interrupt. - * @param callback: pointer to the callback - * @param data: pointer to callback argument if any (default: nullptr) - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - * @retval None - */ void STM32RTC::attachInterrupt(voidFuncPtrParam callback, void *data, Alarm name) { attachAlarmCallback(callback, data, static_cast(name)); } -/** - * @brief detach the RTC alarm callback. - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - * @retval None - */ void STM32RTC::detachInterrupt(Alarm name) { detachAlarmCallback(static_cast(name)); } #ifdef ONESECOND_IRQn -/** - * @brief attach a callback to the RTC Seconds interrupt. - * @param callback: pointer to the callback - * @retval None - */ + void STM32RTC::attachSecondsInterrupt(voidFuncPtrParam callback) { attachSecondsIrqCallback(callback); } -/** - * @brief detach the RTC Seconds callback. - * @retval None - */ void STM32RTC::detachSecondsInterrupt(void) { detachSecondsIrqCallback(); @@ -354,21 +254,12 @@ void STM32RTC::detachSecondsInterrupt(void) #endif /* ONESECOND_IRQn */ #ifdef STM32WLxx -/** - * @brief attach a callback to the RTC SubSeconds underflow interrupt. - * @note only for STM32WLxx - * @param callback: pointer to the callback - * @retval None - */ + void STM32RTC::attachSubSecondsUnderflowInterrupt(voidFuncPtrParam callback) { attachSubSecondsUnderflowIrqCallback(callback); } -/** - * @brief detach the RTC SubSeconds underflow callback. - * @retval None - */ void STM32RTC::detachSubSecondsUnderflowInterrupt(void) { detachSubSecondsUnderflowIrqCallback(); @@ -376,7 +267,6 @@ void STM32RTC::detachSubSecondsUnderflowInterrupt(void) #endif /* STM32WLxx */ - // Kept for compatibility. Use STM32LowPower library. void STM32RTC::standbyMode(void) { @@ -387,42 +277,24 @@ void STM32RTC::standbyMode(void) * Get Functions */ -/** - * @brief get RTC subseconds. - * @retval return the current milliseconds from the RTC. - */ uint32_t STM32RTC::getSubSeconds(void) { syncTime(); return _subSeconds; } -/** - * @brief get RTC seconds. - * @retval return the current seconds from the RTC. - */ uint8_t STM32RTC::getSeconds(void) { syncTime(); return _seconds; } -/** - * @brief get RTC minutes. - * @retval return the current minutes from the RTC. - */ uint8_t STM32RTC::getMinutes(void) { syncTime(); return _minutes; } -/** - * @brief get RTC hours. - * @param format: optional (default: nullptr) - * pointer to the current hour period set in the RTC: AM or PM - * @retval return the current hours from the RTC. - */ uint8_t STM32RTC::getHours(AM_PM *period) { syncTime(); @@ -432,16 +304,6 @@ uint8_t STM32RTC::getHours(AM_PM *period) return _hours; } -/** - * @brief get RTC time. - * @param hours: pointer to the current hours - * @param minutes: pointer to the current minutes - * @param seconds: pointer to the current seconds - * @param subSeconds: pointer to the current subSeconds (in milliseconds) - * @param period: optional (default: nullptr) - * pointer to the current hour period set in the RTC: AM or PM - * @retval none - */ void STM32RTC::getTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, AM_PM *period) { syncTime(); @@ -462,54 +324,30 @@ void STM32RTC::getTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint3 } } -/** - * @brief get RTC week day. - * @retval return the current week day from the RTC. - */ uint8_t STM32RTC::getWeekDay(void) { syncDate(); return _wday; } -/** - * @brief get RTC day. - * @retval return the current day from the RTC. - */ uint8_t STM32RTC::getDay(void) { syncDate(); return _day; } -/** - * @brief get RTC month. - * @retval return the current month from the RTC. - */ uint8_t STM32RTC::getMonth(void) { syncDate(); return _month; } -/** - * @brief get RTC year. - * @retval return the current year from the RTC. - */ uint8_t STM32RTC::getYear(void) { syncDate(); return _year; } -/** - * @brief get RTC time. - * @param weekDay: pointer to the current weekDay - * @param day: pointer to the current day - * @param month: pointer to the current month - * @param year: pointer to the current year - * @retval none - */ void STM32RTC::getDate(uint8_t *weekDay, uint8_t *day, uint8_t *month, uint8_t *year) { syncDate(); @@ -527,12 +365,6 @@ void STM32RTC::getDate(uint8_t *weekDay, uint8_t *day, uint8_t *month, uint8_t * } } -/** - * @brief get RTC alarm subsecond. - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - * @retval return the current alarm subsecond. - */ uint32_t STM32RTC::getAlarmSubSeconds(Alarm name) { uint32_t alarmSubSeconds = 0; @@ -548,12 +380,6 @@ uint32_t STM32RTC::getAlarmSubSeconds(Alarm name) return alarmSubSeconds; } -/** - * @brief get RTC alarm second. - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - * @retval return the current alarm second. - */ uint8_t STM32RTC::getAlarmSeconds(Alarm name) { uint8_t alarmSeconds = 0; @@ -569,12 +395,6 @@ uint8_t STM32RTC::getAlarmSeconds(Alarm name) return alarmSeconds; } -/** - * @brief get RTC alarm minute. - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - * @retval return the current alarm minute. - */ uint8_t STM32RTC::getAlarmMinutes(Alarm name) { uint8_t alarmMinutes = 0; @@ -590,25 +410,11 @@ uint8_t STM32RTC::getAlarmMinutes(Alarm name) return alarmMinutes; } -/** - * @brief get RTC alarm hour. - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - * @retval return the current alarm hour. - */ uint8_t STM32RTC::getAlarmHours(Alarm name) { return getAlarmHours(nullptr, name); } -/** - * @brief get RTC alarm hour. - * @param format: optional (default: nullptr) - * pointer to the current hour format set in the RTC: AM or PM - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - * @retval return the current alarm hour. - */ uint8_t STM32RTC::getAlarmHours(AM_PM *period, Alarm name) { uint8_t alarmHours = 0; @@ -630,12 +436,6 @@ uint8_t STM32RTC::getAlarmHours(AM_PM *period, Alarm name) return alarmHours; } -/** - * @brief get RTC alarm day. - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - * @retval return the current alarm day. - */ uint8_t STM32RTC::getAlarmDay(Alarm name) { uint8_t alarmDay = 0; @@ -651,23 +451,11 @@ uint8_t STM32RTC::getAlarmDay(Alarm name) return alarmDay; } -/** - * @brief get RTC alarm month. - * @NOTE This function is kept for compatibility but the STM32 RTC - * can't assign a month to an alarm. See board datasheet. - * @retval always returns 0 - */ uint8_t STM32RTC::getAlarmMonth(void) { return 0; } -/** - * @brief get RTC alarm year. - * @NOTE This function is kept for compatibility but the STM32 RTC - * can't assign a year to an alarm. See board datasheet. - * @retval always returns 0 - */ uint8_t STM32RTC::getAlarmYear(void) { return 0; @@ -677,11 +465,6 @@ uint8_t STM32RTC::getAlarmYear(void) * Set Functions */ -/** - * @brief set RTC subseconds. - * @param subseconds: 0-999 milliseconds - * @retval none - */ void STM32RTC::setSubSeconds(uint32_t subSeconds) { syncTime(); @@ -692,11 +475,6 @@ void STM32RTC::setSubSeconds(uint32_t subSeconds) _timeSet = true; } -/** - * @brief set RTC seconds. - * @param seconds: 0-59 - * @retval none - */ void STM32RTC::setSeconds(uint8_t seconds) { syncTime(); @@ -707,11 +485,6 @@ void STM32RTC::setSeconds(uint8_t seconds) _timeSet = true; } -/** - * @brief set RTC minutes. - * @param minutes: 0-59 - * @retval none - */ void STM32RTC::setMinutes(uint8_t minutes) { syncTime(); @@ -722,12 +495,6 @@ void STM32RTC::setMinutes(uint8_t minutes) _timeSet = true; } -/** - * @brief set RTC hours. - * @param hours: 0-23 - * @param period: hour format AM or PM (optional) - * @retval none - */ void STM32RTC::setHours(uint8_t hours, AM_PM period) { syncTime(); @@ -741,15 +508,6 @@ void STM32RTC::setHours(uint8_t hours, AM_PM period) _timeSet = true; } -/** - * @brief set RTC time. - * @param hours: 0-23 - * @param minutes: 0-59 - * @param seconds: 0-59 - * @param subSeconds: 0-999 (optional) - * @param period: hour format AM or PM (optional) - * @retval none - */ void STM32RTC::setTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, AM_PM period) { syncTime(); @@ -772,11 +530,6 @@ void STM32RTC::setTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t _timeSet = true; } -/** - * @brief set RTC week day. - * @param week day: 1-7 (Monday first) - * @retval none - */ void STM32RTC::setWeekDay(uint8_t weekDay) { syncDate(); @@ -787,11 +540,6 @@ void STM32RTC::setWeekDay(uint8_t weekDay) _timeSet = true; } -/** - * @brief set RTC day. - * @param day: 1-31 - * @retval none - */ void STM32RTC::setDay(uint8_t day) { syncDate(); @@ -802,11 +550,6 @@ void STM32RTC::setDay(uint8_t day) _timeSet = true; } -/** - * @brief set RTC month. - * @param month: 1-12 - * @retval none - */ void STM32RTC::setMonth(uint8_t month) { syncDate(); @@ -817,11 +560,6 @@ void STM32RTC::setMonth(uint8_t month) _timeSet = true; } -/** - * @brief set RTC year. - * @param year: 0-99 - * @retval none - */ void STM32RTC::setYear(uint8_t year) { syncDate(); @@ -832,13 +570,6 @@ void STM32RTC::setYear(uint8_t year) _timeSet = true; } -/** - * @brief set RTC calendar. - * @param day: 1-31 - * @param month: 1-12 - * @param year: 0-99 - * @retval none - */ void STM32RTC::setDate(uint8_t day, uint8_t month, uint8_t year) { syncDate(); @@ -855,14 +586,6 @@ void STM32RTC::setDate(uint8_t day, uint8_t month, uint8_t year) _timeSet = true; } -/** - * @brief set RTC calendar. - * @param weekDay: 1-7 (Monday first) - * @param day: 1-31 - * @param month: 1-12 - * @param year: 0-99 - * @retval none - */ void STM32RTC::setDate(uint8_t weekDay, uint8_t day, uint8_t month, uint8_t year) { syncDate(); @@ -882,13 +605,6 @@ void STM32RTC::setDate(uint8_t weekDay, uint8_t day, uint8_t month, uint8_t year _timeSet = true; } -/** - * @brief set RTC alarm subseconds. - * @param subseconds: 0-999 (in ms) or 32bit nb of milliseconds in BIN mode - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - * @retval none - */ void STM32RTC::setAlarmSubSeconds(uint32_t subSeconds, Alarm name) { #if !defined(RTC_ALARM_B) && !defined(USE_HALV2_DRIVER) @@ -906,13 +622,6 @@ void STM32RTC::setAlarmSubSeconds(uint32_t subSeconds, Alarm name) } } -/** - * @brief set RTC alarm second. - * @param seconds: 0-59 - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - * @retval none - */ void STM32RTC::setAlarmSeconds(uint8_t seconds, Alarm name) { if (seconds < 60) { @@ -929,13 +638,6 @@ void STM32RTC::setAlarmSeconds(uint8_t seconds, Alarm name) } } -/** - * @brief set RTC alarm minute. - * @param minutes: 0-59 - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - * @retval none - */ void STM32RTC::setAlarmMinutes(uint8_t minutes, Alarm name) { if (minutes < 60) { @@ -952,26 +654,11 @@ void STM32RTC::setAlarmMinutes(uint8_t minutes, Alarm name) } } -/** - * @brief set RTC alarm hour. - * @param hour: 0-23 or 0-12 - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - * @retval none - */ void STM32RTC::setAlarmHours(uint8_t hours, Alarm name) { setAlarmHours(hours, AM, name); } -/** - * @brief set RTC alarm hour. - * @param hour: 0-23 or 0-12 - * @param period: hour format AM or PM (optional) - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - * @retval none - */ void STM32RTC::setAlarmHours(uint8_t hours, AM_PM period, Alarm name) { if (hours < 24) { @@ -994,56 +681,21 @@ void STM32RTC::setAlarmHours(uint8_t hours, AM_PM period, Alarm name) } } - -/** - * @brief set RTC alarm time. - * @param subSeconds: 0-999 ms or 32bit nb of milliseconds in BIN mode - * @param name: ALARM_A or ALARM_B if exists - * @retval none - */ void STM32RTC::setAlarmTime(uint32_t subSeconds, Alarm name) { setAlarmTime(0, 0, 0, subSeconds, AM, name); } -/** - * @brief set RTC alarm time. - * @param hours: 0-23 - * @param minutes: 0-59 - * @param seconds: 0-59 - * @param name: ALARM_A or ALARM_B if exists - * @retval none - */ void STM32RTC::setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, Alarm name) { setAlarmTime(hours, minutes, seconds, 0, AM, name); } -/** - * @brief set RTC alarm time. - * @param hours: 0-23 - * @param minutes: 0-59 - * @param seconds: 0-59 - * @param subSeconds: 0-999 ms or 32bit nb of milliseconds in BIN mode - * @param name: ALARM_A or ALARM_B if exists - * @retval none - */ void STM32RTC::setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, Alarm name) { setAlarmTime(hours, minutes, seconds, subSeconds, AM, name); } -/** - * @brief set RTC alarm time. - * @param hours: 0-23 (not used in BIN mode) - * @param minutes: 0-59 (not used in BIN mode) - * @param seconds: 0-59 (not used in BIN mode) - * @param subSeconds: 0-999 ms (optional) or 32bit nb of milliseconds in BIN mode - * @param period: hour format AM or PM (optional) - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - * @retval none - */ void STM32RTC::setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, AM_PM period, Alarm name) { setAlarmHours(hours, period, name); @@ -1052,13 +704,6 @@ void STM32RTC::setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uin setAlarmSubSeconds(subSeconds, name); } -/** - * @brief set RTC alarm day. - * @param day: 1-31 - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - * @retval none - */ void STM32RTC::setAlarmDay(uint8_t day, Alarm name) { if ((day >= 1) && (day <= 31)) { @@ -1075,38 +720,16 @@ void STM32RTC::setAlarmDay(uint8_t day, Alarm name) } } -/** - * @brief set RTC alarm month. - * @NOTE This function is kept for compatibility but the STM32 RTC - * can't assign a month to an alarm. See board datasheet. - * @param month is ignored. - */ void STM32RTC::setAlarmMonth(uint8_t month) { UNUSED(month); } -/** - * @brief set RTC alarm year. - * @NOTE This function is kept for compatibility but the STM32 RTC - * can't assign a year to an alarm. See board datasheet. - * @param year is ignored. - */ void STM32RTC::setAlarmYear(uint8_t year) { UNUSED(year); } -/** - * @brief set RTC alarm date. - * @NOTE Parameters month and year are ignored because the STM32 RTC can't - * assign a month or year to an alarm. See board datasheet. - * @param day: 1-31 - * @param month is ignored - * @param year is ignored - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - */ void STM32RTC::setAlarmDate(uint8_t day, uint8_t month, uint8_t year, Alarm name) { UNUSED(month); @@ -1115,11 +738,6 @@ void STM32RTC::setAlarmDate(uint8_t day, uint8_t month, uint8_t year, Alarm name setAlarmDay(day, name); } -/** - * @brief get epoch time - * @param subSeconds: optional pointer to where to store subseconds of the epoch in ms - * @retval epoch time in seconds - */ time_t STM32RTC::getEpoch(uint32_t *subSeconds) { struct tm tm; @@ -1152,32 +770,16 @@ time_t STM32RTC::getEpoch(uint32_t *subSeconds) return mktime(&tm); } -/** - * @brief get epoch time since 1st January 2000, 00:00:00 - * @retval epoch time in seconds - */ time_t STM32RTC::getY2kEpoch(void) { return (getEpoch() - EPOCH_TIME_OFF); } -/** - * @brief get alarm epoch time - * @param name: ALARM_A or ALARM_B if exists - * @retval epoch time in seconds - */ time_t STM32RTC::getAlarmEpoch(Alarm name) { return getAlarmEpoch(nullptr, name); } -/** - * @brief get alarm epoch time - * @param subSeconds: optional pointer to where to store subseconds of the epoch in ms - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - * @retval epoch time in seconds - */ time_t STM32RTC::getAlarmEpoch(uint32_t *subSeconds, Alarm name) { struct tm tm; @@ -1215,26 +817,11 @@ time_t STM32RTC::getAlarmEpoch(uint32_t *subSeconds, Alarm name) return mktime(&tm); } -/** - * @brief set RTC alarm from epoch time - * @param epoch time in seconds - * @param Alarm_Match match enum - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - */ void STM32RTC::setAlarmEpoch(time_t ts, Alarm_Match match, Alarm name) { setAlarmEpoch(ts, match, 0, name); } -/** - * @brief set RTC alarm from epoch time - * @param epoch time in seconds - * @param Alarm_Match match enum - * @param subSeconds optional subSeconds in ms (default: 0) - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - */ void STM32RTC::setAlarmEpoch(time_t ts, Alarm_Match match, uint32_t subSeconds, Alarm name) { if (ts < EPOCH_TIME_OFF) { @@ -1255,11 +842,6 @@ void STM32RTC::setAlarmEpoch(time_t ts, Alarm_Match match, uint32_t subSeconds, enableAlarm(match, name); } -/** - * @brief set RTC time from epoch time - * @param epoch time in seconds - * @param subSeconds subSeconds in ms - */ void STM32RTC::setEpoch(time_t ts, uint32_t subSeconds) { if (ts < EPOCH_TIME_OFF) { @@ -1291,19 +873,11 @@ void STM32RTC::setEpoch(time_t ts, uint32_t subSeconds) _timeSet = true; } -/** - * @brief set RTC time from epoch time since 1st January 2000, 00:00:00 - * @param epoch time in seconds - */ void STM32RTC::setY2kEpoch(time_t ts) { setEpoch(ts + EPOCH_TIME_OFF); } -/** - * @brief configure RTC source clock for low power - * @param none - */ void STM32RTC::configForLowPower(Source_Clock source) { #if defined(HAL_PWR_MODULE_ENABLED) || (defined(USE_HAL_PWR_MODULE) && (USE_HAL_PWR_MODULE == 1)) @@ -1336,21 +910,11 @@ void STM32RTC::configForLowPower(Source_Clock source) #endif } -/** - * @brief Check whether RTC alarm is set - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - * @retval True if Alarm is set - */ bool STM32RTC::isAlarmEnabled(Alarm name) { return RTC_IsAlarmSet(static_cast(name)); } -/** - * @brief synchronise the time from the current RTC one - * @param none - */ void STM32RTC::syncTime(void) { hourAM_PM_t p = HOUR_AM; @@ -1359,10 +923,6 @@ void STM32RTC::syncTime(void) _hoursPeriod = (p == HOUR_AM) ? AM : PM; } -/** - * @brief synchronise the time from the current RTC one - * @param none - */ void STM32RTC::syncDate(void) { RTC_GetDate(&_year, &_month, &_day, &_wday); @@ -1371,11 +931,6 @@ void STM32RTC::syncDate(void) #endif /* STM32F1xx */ } -/** - * @brief synchronise the specified alarm time from the current RTC one - * @param name: optional (default: ALARM_A) - * ALARM_A or ALARM_B if exists - */ void STM32RTC::syncAlarmTime(Alarm name) { hourAM_PM_t p = HOUR_AM; diff --git a/src/STM32RTC.h b/src/STM32RTC.h index 397e2f6..37c9d97 100644 --- a/src/STM32RTC.h +++ b/src/STM32RTC.h @@ -2,7 +2,7 @@ ****************************************************************************** * @file STM32RTC.h * @author Frederic Pillon - * @brief Provides a RTC interface for Arduino + * @brief Provides an RTC interface for Arduino. * ****************************************************************************** * @attention @@ -77,25 +77,34 @@ #endif /* RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 || RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512 */ #define IS_HOUR_FORMAT(FMT) (((FMT) == STM32RTC::HOUR_12) || ((FMT) == STM32RTC::HOUR_24)) +/** + * @brief Controls the RTC peripheral on an STM32 board. + * + * Use getInstance() to access the single library instance. + */ class STM32RTC { public: + /** @brief Selects the RTC hour display format. */ enum Hour_Format : uint8_t { HOUR_12 = HOUR_FORMAT_12, HOUR_24 = HOUR_FORMAT_24 }; + /** @brief Selects the AM or PM period in 12-hour format. */ enum AM_PM : uint8_t { AM = HOUR_AM, PM = HOUR_PM }; + /** @brief Selects BCD, binary, or combined RTC mode. */ enum Binary_Mode : uint8_t { MODE_BCD = MODE_BINARY_NONE, MODE_BIN = MODE_BINARY_ONLY, MODE_MIX = MODE_BINARY_MIX }; + /** @brief Selects which RTC fields must match for an alarm. */ enum Alarm_Match : uint8_t { MATCH_OFF = OFF_MSK, // Never MATCH_SUBSEC = SUBSEC_MSK, // Every Subsecond @@ -109,6 +118,7 @@ class STM32RTC { MATCH_YYMMDDHHMMSS = SS_MSK | MM_MSK | HH_MSK | D_MSK | M_MSK | Y_MSK }; + /** @brief Selects the input clock source for the RTC. */ enum Source_Clock : uint8_t { LSI_CLOCK = ::LSI_CLOCK, LSE_CLOCK = ::LSE_CLOCK, @@ -119,6 +129,7 @@ class STM32RTC { #endif /* RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 || RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512 */ }; + /** @brief Identifies an RTC alarm. */ enum Alarm : uint32_t { ALARM_A = ::ALARM_A, #if defined(ALARM_B_AVAILABLE) @@ -126,6 +137,10 @@ class STM32RTC { #endif }; + /** + * @brief Returns the singleton RTC controller. + * @return Reference to the library's sole STM32RTC instance. + */ static STM32RTC &getInstance() { static STM32RTC instance; // Guaranteed to be destroyed. @@ -136,125 +151,483 @@ class STM32RTC { STM32RTC(STM32RTC const &) = delete; void operator=(STM32RTC const &) = delete; + /** + * @brief Initializes the RTC and optionally resets its time. + * @param resetTime Set true to reset the RTC registers. + * @param format Hour format to use. + */ void begin(bool resetTime, Hour_Format format = HOUR_24); + /** + * @brief Initializes the RTC without resetting its current time. + * @param format Hour format to use. + */ void begin(Hour_Format format = HOUR_24); + /** @brief Deinitializes the RTC and clears registered callbacks. */ void end(void); #if !defined(USE_HALV2_DRIVER) // Could be used to mix Arduino API and STM32Cube HAL API (ex: DMA). Use at your own risk. + /** + * @brief Returns the STM32 HAL RTC handle. + * @return Pointer to the RTC handle. + */ RTC_HandleTypeDef *getHandle(void) { return RTC_GetHandle(); } #endif + /** + * @brief Returns the selected RTC input clock source. + * @return The current RTC clock source. + */ Source_Clock getClockSource(void); + /** + * @brief Selects the RTC clock source and its prescalers. + * @param source RTC input clock source. + * @param predivA Asynchronous prescaler; use PREDIVA_MAX + 1 for automatic calculation. + * @param 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 setClockSource(Source_Clock source, uint32_t predivA = (PREDIVA_MAX + 1), uint32_t predivS = (PREDIVS_MAX + 1)); + /** + * @brief Reads the configured or calculated RTC prescalers. + * @param predivA Receives the asynchronous prescaler. + * @param predivS Receives the synchronous prescaler; unused on STM32F1. + */ void getPrediv(uint32_t *predivA, uint32_t *predivS); + /** + * @brief Sets the RTC prescalers. + * @param predivA Asynchronous prescaler. + * @param predivS Synchronous prescaler. + * + * Call before begin(). + */ void setPrediv(uint32_t predivA, uint32_t predivS); + /** + * @brief Returns the current RTC operating mode. + * @return The current binary mode. + */ Binary_Mode getBinaryMode(void); + /** + * @brief Selects BCD, binary, or mixed RTC operation. + * @param mode Requested RTC mode; unsupported modes fall back to BCD. + */ void setBinaryMode(Binary_Mode mode); + /** + * @brief Enables an RTC alarm with the requested match fields. + * @param match Fields that must match when the alarm fires. + * @param name Alarm to enable. + */ void enableAlarm(Alarm_Match match, Alarm name = ALARM_A); + /** + * @brief Disables an RTC alarm. + * @param name Alarm to disable; defaults to ALARM_A. + */ void disableAlarm(Alarm name = ALARM_A); + /** + * @brief Attaches a callback to an RTC alarm. + * @param callback Function called when the alarm fires. + * @param name Alarm that invokes the callback. + */ void attachInterrupt(voidFuncPtrParam callback, Alarm name); + /** + * @brief Attaches a callback and user data to an RTC alarm. + * @param callback Function called when the alarm fires. + * @param data User data passed to the callback. + * @param name Alarm that invokes the callback. + */ void attachInterrupt(voidFuncPtrParam callback, void *data = nullptr, Alarm name = ALARM_A); + /** + * @brief Detaches the callback from an RTC alarm. + * @param name Alarm whose callback will be detached. + */ void detachInterrupt(Alarm name = ALARM_A); #ifdef ONESECOND_IRQn // Other mcu than stm32F1 will use the WakeUp feature to interrupt each second. + /** + * @brief Attaches a callback to the RTC one-second interrupt. + * @param callback Function called once per second. + */ void attachSecondsInterrupt(voidFuncPtrParam callback); + /** @brief Detaches the RTC one-second interrupt callback. */ void detachSecondsInterrupt(void); #endif /* ONESECOND_IRQn */ #ifdef STM32WLxx // STM32WLxx has a dedicated IRQ + /** + * @brief Attaches a callback to the RTC subsecond-underflow interrupt. + * @param callback Function called when the subsecond counter underflows. + * @note Available on STM32WLxx only. + */ void attachSubSecondsUnderflowInterrupt(voidFuncPtrParam callback); + /** @brief Detaches the RTC subsecond-underflow interrupt callback. */ void detachSubSecondsUnderflowInterrupt(void); #endif /* STM32WLxx */ // Kept for compatibility: use STM32LowPower library. + /** @brief Compatibility method; use the STM32LowPower library for standby mode. */ void standbyMode(); /* Get Functions */ + /** + * @brief Returns the current subsecond value in milliseconds. + * @return Current subsecond value. + */ uint32_t getSubSeconds(void); + /** + * @brief Returns the current seconds value. + * @return Seconds in the current minute. + */ uint8_t getSeconds(void); + /** + * @brief Returns the current minutes value. + * @return Minutes in the current hour. + */ uint8_t getMinutes(void); + /** + * @brief Returns the current hours value. + * @param period Optional pointer receiving AM or PM in 12-hour mode. + * @return Current hour value. + */ uint8_t getHours(AM_PM *period = nullptr); + /** + * @brief Reads the current time. + * @param hours Optional pointer receiving the hour value. + * @param minutes Optional pointer receiving the minute value. + * @param seconds Optional pointer receiving the second value. + * @param subSeconds Optional pointer receiving the subsecond value in milliseconds. + * @param period Optional pointer receiving AM or PM in 12-hour mode. + */ void getTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, AM_PM *period = nullptr); + /** + * @brief Returns the current weekday. + * @return Weekday value. + */ uint8_t getWeekDay(void); + /** + * @brief Returns the current day of the month. + * @return Day value. + */ uint8_t getDay(void); + /** + * @brief Returns the current month. + * @return Month value. + */ uint8_t getMonth(void); + /** + * @brief Returns the current year value. + * @return Year value in the range 0-99. + */ uint8_t getYear(void); + /** + * @brief Reads the current date. + * @param weekDay Optional pointer receiving the weekday. + * @param day Optional pointer receiving the day of the month. + * @param month Optional pointer receiving the month. + * @param year Optional pointer receiving the year value. + */ void getDate(uint8_t *weekDay, uint8_t *day, uint8_t *month, uint8_t *year); + /** + * @brief Returns the alarm subsecond value in milliseconds. + * @param name Alarm to read. + * @return Alarm subsecond value. + */ uint32_t getAlarmSubSeconds(Alarm name = ALARM_A); + /** + * @brief Returns the alarm seconds value. + * @param name Alarm to read. + * @return Alarm seconds value. + */ uint8_t getAlarmSeconds(Alarm name = ALARM_A); + /** + * @brief Returns the alarm minutes value. + * @param name Alarm to read. + * @return Alarm minutes value. + */ uint8_t getAlarmMinutes(Alarm name = ALARM_A); + /** + * @brief Returns the alarm hours value. + * @param name Alarm to read. + * @return Alarm hours value. + */ uint8_t getAlarmHours(Alarm name); + /** + * @brief Returns the alarm hours value and optionally its AM/PM period. + * @param period Optional pointer receiving AM or PM in 12-hour mode. + * @param name Alarm to read. + * @return Alarm hour value. + */ uint8_t getAlarmHours(AM_PM *period = nullptr, Alarm name = ALARM_A); + /** + * @brief Returns the alarm day of the month. + * @param name Alarm to read. + * @return Alarm day value. + */ uint8_t getAlarmDay(Alarm name = ALARM_A); // Kept for compatibility with Arduino RTCZero library. + /** + * @brief Returns zero; STM32 RTC alarms do not match a month. + * @return Always zero. + */ uint8_t getAlarmMonth(void); + /** + * @brief Returns zero; STM32 RTC alarms do not match a year. + * @return Always zero. + */ uint8_t getAlarmYear(void); /* Set Functions */ + /** + * @brief Sets the current subsecond value in milliseconds. + * @param subSeconds Subsecond value in the range 0-999. + */ void setSubSeconds(uint32_t subSeconds); + /** + * @brief Sets the current seconds value. + * @param seconds Seconds value in the range 0-59. + */ void setSeconds(uint8_t seconds); + /** + * @brief Sets the current minutes value. + * @param minutes Minutes value in the range 0-59. + */ void setMinutes(uint8_t minutes); + /** + * @brief Sets the current hour value and optional AM/PM period. + * @param hours Hour value. + * @param period AM or PM when using 12-hour format. + */ void setHours(uint8_t hours, AM_PM period = AM); + /** + * @brief Sets the current time. + * @param hours Hour value. + * @param minutes Minute value. + * @param seconds Second value. + * @param subSeconds Subsecond value in milliseconds. + * @param period AM or PM when using 12-hour format. + */ void setTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds = 1000, AM_PM period = AM); + /** + * @brief Sets the current weekday. + * @param weekDay Weekday value in the range 1-7 (Monday is 1). + */ void setWeekDay(uint8_t weekDay); + /** + * @brief Sets the current day of the month. + * @param day Day value in the range 1-31. + */ void setDay(uint8_t day); + /** + * @brief Sets the current month. + * @param month Month value in the range 1-12. + */ void setMonth(uint8_t month); + /** + * @brief Sets the current year value. + * @param year Year value in the range 0-99. + */ void setYear(uint8_t year); + /** + * @brief Sets the current date without changing the weekday. + * @param day Day value in the range 1-31. + * @param month Month value in the range 1-12. + * @param year Year value in the range 0-99. + */ void setDate(uint8_t day, uint8_t month, uint8_t year); + /** + * @brief Sets the current weekday and date. + * @param weekDay Weekday value in the range 1-7 (Monday is 1). + * @param day Day value in the range 1-31. + * @param month Month value in the range 1-12. + * @param year Year value in the range 0-99. + */ void setDate(uint8_t weekDay, uint8_t day, uint8_t month, uint8_t year); + /** + * @brief Sets the alarm subsecond value in milliseconds. + * @param subSeconds Subsecond value; 0-999 in BCD/MIX mode. + * @param name Alarm to configure. + */ void setAlarmSubSeconds(uint32_t subSeconds, Alarm name = ALARM_A); + /** + * @brief Sets the alarm seconds value. + * @param seconds Seconds value in the range 0-59. + * @param name Alarm to configure. + */ void setAlarmSeconds(uint8_t seconds, Alarm name = ALARM_A); + /** + * @brief Sets the alarm minutes value. + * @param minutes Minutes value in the range 0-59. + * @param name Alarm to configure. + */ void setAlarmMinutes(uint8_t minutes, Alarm name = ALARM_A); + /** + * @brief Sets the alarm hours value. + * @param hours Hour value. + * @param name Alarm to configure. + */ void setAlarmHours(uint8_t hours, Alarm name); + /** + * @brief Sets the alarm hours value and optional AM/PM period. + * @param hours Hour value. + * @param period AM or PM when using 12-hour format. + * @param name Alarm to configure. + */ void setAlarmHours(uint8_t hours, AM_PM period = AM, Alarm name = ALARM_A); + /** + * @brief Sets an alarm using a subsecond value. + * @param subSeconds Subsecond value in milliseconds. + * @param name Alarm to configure. + */ void setAlarmTime(uint32_t subSeconds, Alarm name = ALARM_A); + /** + * @brief Sets an alarm time without a subsecond value. + * @param hours Hour value. + * @param minutes Minute value. + * @param seconds Second value. + * @param name Alarm to configure. + */ void setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, Alarm name); + /** + * @brief Sets an alarm time and subsecond value. + * @param hours Hour value. + * @param minutes Minute value. + * @param seconds Second value. + * @param subSeconds Subsecond value in milliseconds. + * @param name Alarm to configure. + */ void setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, Alarm name); + /** + * @brief Sets an alarm time. + * @param hours Hour value. + * @param minutes Minute value. + * @param seconds Second value. + * @param subSeconds Subsecond value in milliseconds. + * @param period AM or PM when using 12-hour format. + * @param name Alarm to configure. + */ void setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds = 0, AM_PM period = AM, Alarm name = ALARM_A); + /** + * @brief Sets the alarm day of the month. + * @param day Day value in the range 1-31. + * @param name Alarm to configure. + */ void setAlarmDay(uint8_t day, Alarm name = ALARM_A); // Kept for compatibility with Arduino RTCZero library. + /** + * @brief Compatibility method; the month is ignored by STM32 RTC alarms. + * @param month Ignored. + */ void setAlarmMonth(uint8_t month); + /** + * @brief Compatibility method; the year is ignored by STM32 RTC alarms. + * @param year Ignored. + */ void setAlarmYear(uint8_t year); + /** + * @brief Sets the alarm day; the month and year are ignored. + * @param day Day value in the range 1-31. + * @param month Ignored. + * @param year Ignored. + * @param name Alarm to configure. + */ void setAlarmDate(uint8_t day, uint8_t month, uint8_t year, Alarm name = ALARM_A); /* Epoch Functions */ + /** + * @brief Returns the current Unix epoch time. + * @param subSeconds Optional pointer receiving the subsecond value in milliseconds. + * @return Current epoch time. + */ time_t getEpoch(uint32_t *subSeconds = nullptr); + /** + * @brief Returns the current time as seconds since the Y2K epoch. + * @return Seconds since 2000-01-01 00:00:00. + */ time_t getY2kEpoch(void); + /** + * @brief Sets the RTC from a Unix epoch timestamp. + * @param ts Epoch timestamp. + * @param subSeconds Subsecond value in milliseconds. + */ void setEpoch(time_t ts, uint32_t subSeconds = 0); + /** + * @brief Sets the RTC from seconds since the Y2K epoch. + * @param ts Seconds since 2000-01-01 00:00:00. + */ void setY2kEpoch(time_t ts); + /** + * @brief Returns the configured alarm's epoch timestamp. + * @param name Alarm to read. + * @return Alarm time as an epoch timestamp. + */ time_t getAlarmEpoch(Alarm name); + /** + * @brief Returns the configured alarm's epoch timestamp. + * @param subSeconds Optional pointer receiving the subsecond value in milliseconds. + * @param name Alarm to read. + * @return Alarm epoch timestamp. + */ time_t getAlarmEpoch(uint32_t *subSeconds = nullptr, Alarm name = ALARM_A); + /** + * @brief Configures an alarm from an epoch timestamp. + * @param ts Epoch timestamp. + * @param match Fields that must match when the alarm fires. + * @param name Alarm to configure. + */ void setAlarmEpoch(time_t ts, Alarm_Match match, Alarm name); + /** + * @brief Configures an alarm from an epoch timestamp. + * @param ts Epoch timestamp. + * @param match Fields that must match when the alarm fires. + * @param subSeconds Subsecond value in milliseconds. + * @param name Alarm to configure. + */ void setAlarmEpoch(time_t ts, Alarm_Match match = MATCH_DHHMMSS, uint32_t subSeconds = 0, Alarm name = ALARM_A); + /** + * @brief Reports whether the RTC peripheral is configured. + * @return True if the RTC is configured; otherwise false. + */ bool isConfigured(void) { return RTC_IsConfigured(); } + /** + * @brief Reports whether the current hour format is 24-hour. + * @return True for 24-hour format; otherwise false. + */ bool isFormat_24hour(void) { return (_format == HOUR_24); } + /** + * @brief Reports whether the selected alarm is enabled. + * @param name Alarm to check. + * @return True if the alarm is enabled; otherwise false. + */ bool isAlarmEnabled(Alarm name = ALARM_A); + /** + * @brief Reports whether the library has set the current time. + * @return True if the library has set the time; otherwise false. + */ bool isTimeSet(void) { return _timeSet; diff --git a/src/rtc.c b/src/rtc.c index 3b3af12..ead8015 100644 --- a/src/rtc.c +++ b/src/rtc.c @@ -2,7 +2,7 @@ ****************************************************************************** * @file rtc.c * @author Frederic Pillon - * @brief Provides a RTC driver + * @brief Implements the STM32 RTC HAL driver. * ****************************************************************************** * @attention @@ -42,11 +42,10 @@ #if !defined(HAL_RTC_MODULE_ONLY) && \ (defined(HAL_RTC_MODULE_ENABLED) || (defined(USE_HAL_RTC_MODULE) && (USE_HAL_RTC_MODULE == 1))) #if defined(STM32MP1xx) - /** - * Currently there is no RTC driver for STM32MP1xx. If RTC is used in the future - * the function call HAL_RCCEx_PeriphCLKConfig() shall be done under - * if(IS_ENGINEERING_BOOT_MODE()), since clock source selection is done by - * First Stage Boot Loader on Cortex-A. + /* + * There is no RTC driver for STM32MP1xx. If RTC support is added in the future, + * HAL_RCCEx_PeriphCLKConfig() must run under if(IS_ENGINEERING_BOOT_MODE()), + * because the Cortex-A First Stage Boot Loader selects the clock source. */ #error "RTC shall not be handled by Arduino in STM32MP1xx." #endif /* STM32MP1xx */ @@ -59,9 +58,7 @@ extern "C" { #if defined(USE_HALV2_DRIVER) #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FU) /* ToDo: check if mode is needed */ -/** - * Test synchronous prescaler value if mode is HAL_RTC_MODE_BCD. - */ +/* Test the synchronous prescaler value when mode is HAL_RTC_MODE_BCD. */ /* #define IS_RTC_SYNCH_PREDIV(prediv, mode) (((mode) != HAL_RTC_MODE_BCD) || ((prediv) <= 0x7FFFU))*/ #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FFFU) #endif @@ -122,6 +119,11 @@ static void RTC_BinaryConf(binaryMode_t mode); static void RTC_SetBinaryConf(void); #endif +/** + * @brief Computes the floor of the base-2 logarithm. + * @param x Positive integer input. + * @return floor(log2(x)) when x is positive; otherwise zero. + */ static inline int _log2(int x) { return (x > 0) ? (sizeof(int) * 8 - __builtin_clz(x) - 1) : 0; @@ -129,22 +131,13 @@ static inline int _log2(int x) /* Exported functions --------------------------------------------------------*/ #if !defined(USE_HALV2_DRIVER) -/** - * @brief Get pointer to RTC_HandleTypeDef - * @param None - * @retval pointer to RTC_HandleTypeDef - */ + RTC_HandleTypeDef *RTC_GetHandle(void) { return &RtcHandle; } #endif /* !USE_HALV2_DRIVER */ -/** - * @brief Set RTC clock source - * @param source: RTC clock source: LSE, LSI or HSE - * @retval None - */ void RTC_SetClockSource(sourceClock_t source) { clkSrc = source; @@ -207,15 +200,11 @@ void RTC_SetClockSource(sourceClock_t source) } /** - * @brief RTC clock initialization - * This function configures the hardware resources used. - * @param source: RTC clock source: LSE, LSI or HSE - * @note Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to select - * the RTC clock source; in this case the Backup domain will be reset in - * order to modify the RTC Clock source, as consequence RTC registers (including - * the backup registers) and RCC_CSR register are set to their reset values. - * @retval None - */ + * @brief Configures the RTC peripheral clock and selected clock source. + * @param source RTC clock source. + * @note Selecting the source through HAL_RCCEx_PeriphCLKConfig() resets the + * backup domain, including RTC and backup registers. + */ static void RTC_initClock(sourceClock_t source) { #if defined(USE_HALV2_DRIVER) @@ -325,14 +314,6 @@ static void RTC_initClock(sourceClock_t source) #endif /* USE_HALV2_DRIVER */ } -/** - * @brief set user (a)synchronous prescaler values. - * @param asynch: asynchronous prescaler value in range 0 - PREDIVA_MAX - * @note Reset value: RTC_AUTO_1_SECOND for STM32F1xx series, else (PREDIVA_MAX + 1) - * @param synch: synchronous prescaler value in range 0 - PREDIVS_MAX - * @note Reset value: (PREDIVS_MAX + 1), not used for STM32F1xx series. - * @retval None - */ void RTC_setPrediv(uint32_t asynch, uint32_t synch) { #if defined(STM32F1xx) @@ -354,15 +335,6 @@ void RTC_setPrediv(uint32_t asynch, uint32_t synch) #endif /* STM32F1xx */ } - -/** - * @brief get user (a)synchronous prescaler values if set else computed ones - * for the current clock source. - * @param asynch: pointer where return asynchronous prescaler value. - * @param synch: pointer where return synchronous prescaler value, - * not used for STM32F1xx series. - * @retval None - */ void RTC_getPrediv(uint32_t *asynch, uint32_t *synch) { #if defined(STM32F1xx) @@ -398,12 +370,10 @@ void RTC_getPrediv(uint32_t *asynch, uint32_t *synch) #if !defined(STM32F1xx) /** - * @brief Compute (a)synchronous prescaler - * RTC prescalers are compute to obtain the RTC clock to 1Hz. See AN4759. - * @param asynch: pointer where return asynchronous prescaler value. - * @param synch: pointer where return synchronous prescaler value. - * @retval None - */ + * @brief Computes prescalers for a 1 Hz RTC calendar clock. + * @param asynch Receives the asynchronous prescaler. + * @param synch Receives the synchronous prescaler. + */ static void RTC_computePrediv(uint32_t *asynch, uint32_t *synch) { uint32_t predivS = PREDIVS_MAX + 1; @@ -443,6 +413,10 @@ static void RTC_computePrediv(uint32_t *asynch, uint32_t *synch) #endif /* !STM32F1xx */ #if defined(LL_RTC_BINARY_NONE) +/** + * @brief Configures the selected RTC binary mode. + * @param mode BCD, binary, or mixed RTC mode. + */ static void RTC_BinaryConf(binaryMode_t mode) { #if defined(USE_HALV2_DRIVER) @@ -514,6 +488,9 @@ static void RTC_BinaryConf(binaryMode_t mode) #error "RTC_BINARY_MIX_BCDU_n and LL_RTC_BINARY_MIX_BCDU_n do not match" #endif #endif /* !USE_HALV2_DRIVER */ +/** + * @brief Applies the configured binary mode and mixed-mode BCD update setting. + */ static void RTC_SetBinaryConf(void) { #if defined(USE_HALV2_DRIVER) @@ -544,17 +521,6 @@ static void RTC_SetBinaryConf(void) } #endif /* LL_RTC_BINARY_NONE */ -/** - * @brief RTC Initialization - * This function configures the RTC time and calendar. By default, the - * RTC is set to the 1st January 2001 - * Note: year 2000 is invalid as it is the hardware reset value and doesn't raise INITS flag - * @param format: enable the RTC in 12 or 24 hours mode - * @param mode: enable the RTC in BCD or Mix or Binary mode - * @param source: RTC clock source: LSE, LSI or HSE - * @param reset: force RTC reset, even if previously configured - * @retval True if RTC is reinitialized, else false - */ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool reset) { bool reinit = false; @@ -821,11 +787,6 @@ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool return reinit; } -/** - * @brief RTC deinitialization. Stop the RTC. - * @param reset_cb: reset user callback - * @retval None - */ void RTC_DeInit(bool reset_cb) { #if defined(USE_HALV2_DRIVER) @@ -869,10 +830,6 @@ void RTC_DeInit(bool reset_cb) } } -/** - * @brief Check if time is already set - * @retval True if set else false - */ bool RTC_IsConfigured(void) { #if defined(STM32F1xx) @@ -889,15 +846,6 @@ bool RTC_IsConfigured(void) #endif } -/** - * @brief Set RTC time - * @param hours: 0-12 or 0-23. Depends on the format used. - * @param minutes: 0-59 - * @param seconds: 0-59 - * @param subSeconds: 0-999 (not used) - * @param period: select HOUR_AM or HOUR_PM period in case RTC is set in 12 hours mode. Else ignored. - * @retval None - */ void RTC_SetTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, hourAM_PM_t period) { #if defined(USE_HALV2_DRIVER) @@ -952,15 +900,6 @@ void RTC_SetTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSe #endif /* USE_HALV2_DRIVER */ } -/** - * @brief Get RTC time - * @param hours: 0-12 or 0-23. Depends on the format used. - * @param minutes: 0-59 - * @param seconds: 0-59 - * @param subSeconds: 0-999 (optional could be NULL) - * @param period: HOUR_AM or HOUR_PM period in case RTC is set in 12 hours mode (optional could be NULL). - * @retval None - */ void RTC_GetTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, hourAM_PM_t *period) { #if defined(USE_HALV2_DRIVER) @@ -1047,14 +986,6 @@ void RTC_GetTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *s #endif /* USE_HALV2_DRIVER */ } -/** - * @brief Set RTC calendar - * @param year: 0-99 - * @param month: 1-12 - * @param day: 1-31 - * @param wday: 1-7 - * @retval None - */ void RTC_SetDate(uint8_t year, uint8_t month, uint8_t day, uint8_t wday) { #if defined(USE_HALV2_DRIVER) @@ -1087,14 +1018,6 @@ void RTC_SetDate(uint8_t year, uint8_t month, uint8_t day, uint8_t wday) #endif } -/** - * @brief Get RTC calendar - * @param year: 0-99 - * @param month: 1-12 - * @param day: 1-31 - * @param wday: 1-7 - * @retval None - */ void RTC_GetDate(uint8_t *year, uint8_t *month, uint8_t *day, uint8_t *wday) { #if defined(USE_HALV2_DRIVER) @@ -1120,20 +1043,6 @@ void RTC_GetDate(uint8_t *year, uint8_t *month, uint8_t *day, uint8_t *wday) #endif } -/** - * @brief Set RTC alarm and activate it with IT mode with 64bit accuracy on subsecond param - * Mainly used by Lorawan in RTC BIN or MIX mode - * @param name: ALARM_A or ALARM_B if exists - * @param day: 1-31 (day of the month) - * @param hours: 0-12 or 0-23 depends on the hours mode. - * @param minutes: 0-59 - * @param seconds: 0-59 - * @param subSeconds: 0-999 milliseconds or 64bit nb of milliseconds in no BCD mode - * @param period: HOUR_AM or HOUR_PM if in 12 hours mode else ignored. - * @param mask: configure alarm behavior using alarmMask_t combination. - * See AN4579 Table 5 for possible values. - * @retval None - */ void RTC_StartAlarm64(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds, uint64_t subSeconds, hourAM_PM_t period, uint8_t mask) { #if defined(USE_HALV2_DRIVER) @@ -1374,30 +1283,12 @@ void RTC_StartAlarm64(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, #endif /* USE_HALV2_DRIVER */ } -/** - * @brief Set RTC alarm and activate it with IT mode - * @param name: ALARM_A or ALARM_B if exists - * @param day: 1-31 (day of the month) - * @param hours: 0-12 or 0-23 depends on the hours mode. - * @param minutes: 0-59 - * @param seconds: 0-59 - * @param subSeconds: 0-999 milliseconds - * @param period: HOUR_AM or HOUR_PM if in 12 hours mode else ignored. - * @param mask: configure alarm behavior using alarmMask_t combination. - * See AN4579 Table 5 for possible values. - * @retval None - */ void RTC_StartAlarm(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, hourAM_PM_t period, uint8_t mask) { /* Same RTC_StartAlarm where the nb of SubSeconds is lower than UINT32_MAX */ RTC_StartAlarm64(name, day, hours, minutes, seconds, (uint64_t)subSeconds, period, mask); } -/** - * @brief Disable RTC alarm - * @param name: ALARM_A or ALARM_B if exists - * @retval None - */ void RTC_StopAlarm(alarm_t name) { /* Clear RTC Alarm Flag */ @@ -1423,11 +1314,6 @@ void RTC_StopAlarm(alarm_t name) #endif } -/** - * @brief Check whether RTC alarm is set - * @param ALARM_A or ALARM_B if exists - * @retval True if Alarm is set - */ bool RTC_IsAlarmSet(alarm_t name) { bool status = false; @@ -1455,19 +1341,6 @@ bool RTC_IsAlarmSet(alarm_t name) return status; } -/** - * @brief Get RTC alarm - * @param name: ALARM_A or ALARM_B if exists - * @param day: 1-31 day of the month (optional could be NULL) - * @param hours: 0-12 or 0-23 depends on the hours mode - * @param minutes: 0-59 - * @param seconds: 0-59 - * @param subSeconds: 0-999 (optional could be NULL) - * @param period: HOUR_AM or HOUR_PM (optional could be NULL) - * @param mask: alarm behavior using alarmMask_t combination (optional could be NULL) - * See AN4579 Table 5 for possible values - * @retval None - */ void RTC_GetAlarm(alarm_t name, uint8_t *day, uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, hourAM_PM_t *period, uint8_t *mask) { #if defined(USE_HALV2_DRIVER) @@ -1588,13 +1461,6 @@ void RTC_GetAlarm(alarm_t name, uint8_t *day, uint8_t *hours, uint8_t *minutes, } } -/** - * @brief Attach alarm callback. - * @param func: pointer to the callback - * @param func: pointer to callback argument - * @param name: ALARM_A or ALARM_B if exists - * @retval None - */ void attachAlarmCallback(voidCallbackPtr func, void *data, alarm_t name) { #if defined(ALARM_B_AVAILABLE) @@ -1611,11 +1477,6 @@ void attachAlarmCallback(voidCallbackPtr func, void *data, alarm_t name) } } -/** - * @brief Detach alarm callback. - * @param name: ALARM_A or ALARM_B if exists - * @retval None - */ void detachAlarmCallback(alarm_t name) { #if defined(ALARM_B_AVAILABLE) @@ -1634,10 +1495,8 @@ void detachAlarmCallback(alarm_t name) #if defined(USE_HALV2_DRIVER) /** - * @brief Alarm A callback. - * @param None - * @retval None - */ + * @brief Forwards the HAL Alarm A event to the registered callback. + */ void HAL_RTC_AlarmAEventCallback(void) { if (RTCUserCallback != NULL) { @@ -1646,10 +1505,8 @@ void HAL_RTC_AlarmAEventCallback(void) } /** - * @brief Alarm B callback. - * @param None - * @retval None - */ + * @brief Forwards the HAL Alarm B event to the registered callback. + */ void HAL_RTC_AlarmBEventCallback(void) { if (RTCUserCallbackB != NULL) { @@ -1657,6 +1514,10 @@ void HAL_RTC_AlarmBEventCallback(void) } } #else +/** + * @brief Forwards the HAL Alarm A event to the registered callback. + * @param hrtc HAL RTC handle. + */ void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) { (void)hrtc; @@ -1668,10 +1529,9 @@ void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) #if defined(ALARM_B_AVAILABLE) /** - * @brief Alarm B callback. - * @param hrtc RTC handle - * @retval None - */ + * @brief Forwards the HAL Alarm B event to the registered callback. + * @param hrtc HAL RTC handle. + */ void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc) { (void)hrtc; @@ -1683,10 +1543,8 @@ void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc) #endif #endif /* USE_HALV2_DRIVER */ /** - * @brief RTC Alarm IRQHandler - * @param None - * @retval None - */ + * @brief Dispatches the RTC alarm interrupt to the HAL handlers. + */ void RTC_Alarm_IRQHandler(void) { #if defined(USE_HALV2_DRIVER) @@ -1708,13 +1566,7 @@ void RTC_Alarm_IRQHandler(void) } #ifdef ONESECOND_IRQn -/** - * @brief Attach Seconds interrupt callback. - * @note stm32F1 has a second interrupt capability - * other MCUs map this on their WakeUp feature - * @param func: pointer to the callback - * @retval None - */ + void attachSecondsIrqCallback(voidCallbackPtr func) { RTCSecondsIrqCallback = func; @@ -1749,11 +1601,6 @@ void attachSecondsIrqCallback(voidCallbackPtr func) #endif /* USE_HALV2_DRIVER */ } -/** - * @brief Detach Seconds interrupt callback. - * @param None - * @retval None - */ void detachSecondsIrqCallback(void) { #if defined(STM32F1xx) @@ -1768,10 +1615,9 @@ void detachSecondsIrqCallback(void) #if defined(STM32F1xx) /** - * @brief Seconds interrupt callback. - * @param hrtc RTC handle - * @retval None - */ + * @brief Forwards the HAL RTC event to the registered one-second callback. + * @param hrtc HAL RTC handle. + */ void HAL_RTCEx_RTCEventCallback(RTC_HandleTypeDef *hrtc) { (void)hrtc; @@ -1782,22 +1628,18 @@ void HAL_RTCEx_RTCEventCallback(RTC_HandleTypeDef *hrtc) } /** - * @brief This function handles RTC Seconds interrupt request. - * @param None - * @retval None - */ + * @brief Handles the RTC one-second interrupt on STM32F1. + */ void RTC_IRQHandler(void) { HAL_RTCEx_RTCIRQHandler(&RtcHandle); } #else -/** - * @brief WakeUp event mapping the Seconds interrupt callback. - * @param hrtc RTC handle - * @retval None - */ #if defined(USE_HALV2_DRIVER) +/** + * @brief Forwards the HAL wakeup event to the registered one-second callback. + */ void HAL_RTC_WakeUpTimerEventCallback() { if (RTCSecondsIrqCallback != NULL) { @@ -1805,6 +1647,10 @@ void HAL_RTC_WakeUpTimerEventCallback() } } #else +/** + * @brief Forwards the HAL wakeup event to the registered one-second callback. + * @param hrtc HAL RTC handle. + */ void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc) { (void)hrtc; @@ -1816,10 +1662,8 @@ void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc) #endif /** - * @brief This function handles RTC Seconds through wakeup interrupt request. - * @param None - * @retval None - */ + * @brief Handles the RTC wakeup interrupt used for one-second events. + */ void RTC_WKUP_IRQHandler(void) { #if defined(USE_HALV2_DRIVER) @@ -1832,11 +1676,7 @@ void RTC_WKUP_IRQHandler(void) #endif /* ONESECOND_IRQn */ #ifdef STM32WLxx -/** - * @brief Attach SubSeconds underflow interrupt callback. - * @param func: pointer to the callback - * @retval None - */ + void attachSubSecondsUnderflowIrqCallback(voidCallbackPtr func) { /* Callback called on SSRU interrupt */ @@ -1850,11 +1690,6 @@ void attachSubSecondsUnderflowIrqCallback(voidCallbackPtr func) HAL_NVIC_EnableIRQ(TAMP_STAMP_LSECSS_SSRU_IRQn); } -/** - * @brief Detach SubSeconds underflow interrupt callback. - * @param None - * @retval None - */ void detachSubSecondsUnderflowIrqCallback(void) { RTCSubSecondsUnderflowIrqCallback = NULL; @@ -1864,6 +1699,10 @@ void detachSubSecondsUnderflowIrqCallback(void) HAL_NVIC_DisableIRQ(TAMP_STAMP_LSECSS_SSRU_IRQn); } +/** + * @brief Forwards the HAL subsecond-underflow event to the registered callback. + * @param hrtc HAL RTC handle. + */ void HAL_RTCEx_SSRUEventCallback(RTC_HandleTypeDef *hrtc) { (void)hrtc; diff --git a/src/rtc.h b/src/rtc.h index 1fe1e31..1489776 100644 --- a/src/rtc.h +++ b/src/rtc.h @@ -2,7 +2,7 @@ ****************************************************************************** * @file rtc.h * @author Frederic Pillon - * @brief Header for RTC driver + * @brief Internal interface for the STM32 RTC driver. ****************************************************************************** * @attention * @@ -101,6 +101,7 @@ typedef enum { #endif } alarm_t; +/** @brief Callback type used by RTC interrupt registration functions. */ typedef void(*voidCallbackPtr)(void *); /* Exported constants --------------------------------------------------------*/ @@ -215,38 +216,167 @@ typedef void(*voidCallbackPtr)(void *); /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ #if !defined(USE_HALV2_DRIVER) +/** + * @brief Returns the HAL RTC handle. + * @return Pointer to the RTC handle. + * @note Available only with the HAL driver version 1. + */ RTC_HandleTypeDef *RTC_GetHandle(void); #endif +/** + * @brief Selects the RTC clock source. + * @param source RTC clock source. + */ void RTC_SetClockSource(sourceClock_t source); +/** + * @brief Reads the configured or calculated RTC prescalers. + * @param asynch Receives the asynchronous prescaler. + * @param synch Receives the synchronous prescaler; unused on STM32F1. + */ void RTC_getPrediv(uint32_t *asynch, uint32_t *synch); +/** + * @brief Configures the RTC prescalers. + * @param asynch Asynchronous prescaler value. + * @param synch Synchronous prescaler value; unused on STM32F1. + */ void RTC_setPrediv(uint32_t asynch, uint32_t synch); +/** + * @brief Initializes the RTC hardware and calendar. + * @param format 12-hour or 24-hour format. + * @param mode BCD, binary, or mixed RTC mode. + * @param source RTC clock source. + * @param reset Forces RTC initialization, even if it is already configured. + * @return True when the RTC required initialization; otherwise false. + * @note Initialization sets the default calendar date to 2001-01-01. + */ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool reset); +/** + * @brief Deinitializes the RTC and disables its interrupts. + * @param reset_cb If true, clears the registered RTC callbacks. + */ void RTC_DeInit(bool reset_cb); +/** + * @brief Checks whether the RTC has been configured. + * @return True if the RTC is configured; otherwise false. + */ bool RTC_IsConfigured(void); +/** + * @brief Sets the RTC time. + * @param hours Hour value in the selected hour format. + * @param minutes Minute value in the range 0-59. + * @param seconds Second value in the range 0-59. + * @param subSeconds Subsecond value; currently unused by the HAL setter. + * @param period AM or PM when using 12-hour format. + */ void RTC_SetTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, hourAM_PM_t period); +/** + * @brief Reads the RTC time. + * @param hours Receives the hour value. + * @param minutes Receives the minute value. + * @param seconds Receives the second value. + * @param subSeconds Optional pointer receiving subseconds in milliseconds. + * @param period Optional pointer receiving AM or PM. + * @note The hours, minutes, and seconds pointers must all be non-null. + */ void RTC_GetTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, hourAM_PM_t *period); +/** + * @brief Sets the RTC calendar date. + * @param year Year value in the range 0-99. + * @param month Month value in the range 1-12. + * @param day Day value in the range 1-31. + * @param wday Weekday value in the range 1-7. + */ void RTC_SetDate(uint8_t year, uint8_t month, uint8_t day, uint8_t wday); +/** + * @brief Reads the RTC calendar date. + * @param year Receives the year value. + * @param month Receives the month value. + * @param day Receives the day value. + * @param wday Receives the weekday value. + * @note All output pointers must be non-null. + */ void RTC_GetDate(uint8_t *year, uint8_t *month, uint8_t *day, uint8_t *wday); +/** + * @brief Configures and enables an RTC alarm interrupt. + * @param name Alarm to configure. + * @param day Day of the month, in the range 1-31. + * @param hours Hour value in the selected hour format. + * @param minutes Minute value in the range 0-59. + * @param seconds Second value in the range 0-59. + * @param subSeconds Subsecond value in milliseconds. + * @param period AM or PM when using 12-hour format. + * @param mask Alarm field-match mask. + */ void RTC_StartAlarm(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, hourAM_PM_t period, uint8_t mask); +/** + * @brief Configures and enables an RTC alarm with 64-bit subsecond precision. + * @param name Alarm to configure. + * @param day Day of the month, in the range 1-31. + * @param hours Hour value in the selected hour format. + * @param minutes Minute value in the range 0-59. + * @param seconds Second value in the range 0-59. + * @param subSeconds Subsecond value in milliseconds. + * @param period AM or PM when using 12-hour format. + * @param mask Alarm field-match mask. + * @note Used by binary and mixed RTC modes for extended subsecond values. + */ void RTC_StartAlarm64(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds, uint64_t subSeconds, hourAM_PM_t period, uint8_t mask); +/** @brief Disables an RTC alarm. + * @param name Alarm to disable. + */ void RTC_StopAlarm(alarm_t name); +/** + * @brief Checks whether an RTC alarm interrupt is enabled. + * @param name Alarm to check. + * @return True if the alarm interrupt is enabled; otherwise false. + */ bool RTC_IsAlarmSet(alarm_t name); +/** + * @brief Reads the configured RTC alarm. + * @param name Alarm to read. + * @param day Optional pointer receiving the alarm day. + * @param hours Receives the alarm hour. + * @param minutes Receives the alarm minute. + * @param seconds Receives the alarm second. + * @param subSeconds Optional pointer receiving subseconds in milliseconds. + * @param period Optional pointer receiving AM or PM. + * @param mask Optional pointer receiving the alarm field-match mask. + * @note The hours, minutes, and seconds pointers must all be non-null. + */ void RTC_GetAlarm(alarm_t name, uint8_t *day, uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, hourAM_PM_t *period, uint8_t *mask); +/** + * @brief Registers the callback and user data for an RTC alarm. + * @param func Callback invoked when the alarm interrupt fires. + * @param data User data passed to the callback. + * @param name Alarm whose callback is registered. + */ void attachAlarmCallback(voidCallbackPtr func, void *data, alarm_t name); +/** @brief Clears the callback and user data for an RTC alarm. + * @param name Alarm whose callback is cleared. + */ void detachAlarmCallback(alarm_t name); #ifdef ONESECOND_IRQn +/** @brief Registers a callback for the RTC one-second interrupt. + * @param func Callback invoked on each one-second event. + */ void attachSecondsIrqCallback(voidCallbackPtr func); +/** @brief Clears the RTC one-second interrupt callback. */ void detachSecondsIrqCallback(void); #endif /* ONESECOND_IRQn */ #ifdef STM32WLxx +/** @brief Registers a callback for the RTC subsecond-underflow interrupt. + * @param func Callback invoked when the subsecond counter underflows. + */ void attachSubSecondsUnderflowIrqCallback(voidCallbackPtr func); +/** @brief Clears the RTC subsecond-underflow interrupt callback. */ void detachSubSecondsUnderflowIrqCallback(void); #endif /* STM32WLxx */ #if defined(STM32F1xx) +/** @brief Stores the RTC date in backup registers on STM32F1. */ void RTC_StoreDate(void); #endif