-
Notifications
You must be signed in to change notification settings - Fork 51
Add STM32RTC library source files #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: fpr <[email protected]>
@fprwi6labs |
@fpistm just told me there is a dependency to stm32duino/Arduino_Core_STM32#177 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few questions and comments
@@ -0,0 +1,814 @@ | |||
/** | |||
****************************************************************************** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please edit the commit title to something specific => Like STM32 RTC library
****************************************************************************** | ||
*/ | ||
|
||
#include <time.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is being used from time.h ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Epoch conversion needs time functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok thx
#define EPOCH_TIME_YEAR_OFF 100 // years since 1900 | ||
|
||
// Initialize static variable | ||
bool STM32RTC::_configured = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couldn't this be initialized in the STM32RTC::STM32RTC(void) constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it couldn't because we use a static variable to avoid the overwrite of a previous RTC configuration in case the user create is own object and a library call another. It is the case with the future low power library.
src/STM32RTC.cpp
Outdated
* @retval None | ||
*/ | ||
void STM32RTC::begin(hourFormat_t format) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hourFormat_t is a type of the core - it would be easier to read to have a type defined in the library that will map to the one of the core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
src/STM32RTC.h
Outdated
#endif | ||
|
||
typedef void(*voidFuncPtr)(void); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as proposed in the RTC PR of the core, could make sense to add a (void* data) parameter to the callback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
RTC_StopAlarm(); | ||
break; | ||
case MATCH_YYMMDDHHMMSS://kept for compatibility | ||
case MATCH_MMDDHHMMSS: //kept for compatibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is the limitation about year / months described ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inside the header file.
src/STM32RTC.cpp
Outdated
// Kept for compatibility. | ||
void STM32RTC::setAlarmMonth(uint8_t month) | ||
{ | ||
UNUSED(month); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please explain and document the implication of not using / supporting the month
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
src/STM32RTC.cpp
Outdated
// Kept for compatibility. | ||
void STM32RTC::setAlarmYear(uint8_t year) | ||
{ | ||
UNUSED(year); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please explain and document the implication of not using / supporting the year
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
src/STM32RTC.cpp
Outdated
|
||
// Kept for compatibility. | ||
void STM32RTC::setAlarmDate(uint8_t day, uint8_t month, uint8_t year) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not setting the day ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
src/STM32RTC.h
Outdated
#define HOUR_24 HOUR_FORMAT_24 | ||
|
||
//Hour AM/PM definition | ||
#define HOUR_AM AM //AM or 24 hours |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean that hourAM_PM_t will always be HOUR_AM when hourFormat_t is HOUR_24 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly. It is documented in board datasheet:
Bit 22 PM: AM/PM notation
0: AM or 24-hour format
1: PM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least I would like to have all information in this file so if you can add better comments of each type definition in this header file that would help users. Otherwise they don't know which define corresponds to which type.
README.md
Outdated
The following functions have been added to support specific STM32 RTC features: | ||
|
||
_RTC hours mode (12 or 24)_ | ||
* **`void begin(hourFormat_t format)`** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be RTCHourFormats_t ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
README.md
Outdated
|
||
_Hour format (AM or PM)_ | ||
* **`uint8_t getHours(hourAM_PM_t *format)`** | ||
* **`void setHours(uint8_t hours, hourAM_PM_t format)`** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be Hour12_AM_PM_t now ?
same in below functions ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fprwi6labs Looks all good to me now - thanks for all the quick changes ! Approved from my side.
* @param format: hour format: HOUR_12 or HOUR_24(default) | ||
* @retval None | ||
*/ | ||
void STM32RTC::begin(RTCHourFormats_t format) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should provide a way to select RTC clock source (HSE, LSI, LSE)
Even if all LP is not reachable depending of the clock source.
Not All Nucleo board provide LSE by default.
Need to handle RTC clock config. Currently fixed config.
Signed-off-by: fpr <[email protected]>
Signed-off-by: fpr <[email protected]>
Library updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be fine to add one example with clock source selection.
examples/SimpleRTC/SimpleRTC.ino
Outdated
@@ -0,0 +1,107 @@ | |||
/** | |||
****************************************************************************** | |||
* @file simpleRTC.ino |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: sSimpleRTC.ino
@@ -0,0 +1,77 @@ | |||
/** | |||
****************************************************************************** | |||
* @file Epoch.ino |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
simpleRTCAlarm.ino
README.md
Outdated
This library is based on the Arduino RTCZero library. | ||
You can take control of the internal RTC of the STM32 boards. | ||
|
||
The following functions are not supported: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the reason why not supported
README.md
Outdated
# API | ||
|
||
This library is based on the Arduino RTCZero library. | ||
You can take control of the internal RTC of the STM32 boards. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, use passive form to avoid use of 'you'
README.md
Outdated
* **`void setWeekDay(uint8_t weekDay)`** | ||
* **`void setDate(uint8_t weekDay, uint8_t day, uint8_t month, uint8_t year)`** | ||
|
||
Refer you to the Arduino RTC documentation for the other functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove 'you'
README.md
Outdated
|
||
## Source | ||
|
||
You can find the source files at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
passive form:
Source file available at:
examples/Epoch/Epoch.ino
Outdated
|
||
#include <STM32RTC.h> | ||
|
||
/* Create an rtc object */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a rtc
Signed-off-by: fpr <[email protected]>
Signed-off-by: fpr <[email protected]>
@fpistm |
This PR is corrected and extended by #2 |
Source files of the RTC library.
This library is based on the RTCZero library.
We tried to keep the compatibility as far as possible.
Tested on NUCLEO-L476RG and NUCLEO-L053R8.
Compilation test OK on all variant boards.
Requires the validation of this PR.