Skip to content

Naming conventions for member enums #12

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

Merged
merged 2 commits into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ The following functions are not supported:
The following functions have been added to support specific STM32 RTC features:

_RTC hours mode (12 or 24)_
* **`void begin(RTC_Hour_Format format)`**
* **`void begin(Hour_Format format)`**

_RTC clock source_
* **`RTC_Source_Clock setClockSource(void)`** : get current clock source.
* **`void setClockSource(RTC_Source_Clock source)`** : this function must be called before `begin()`.
* **`Source_Clock getClockSource(void)`** : get current clock source.
* **`void setClockSource(Source_Clock source)`** : this function must be called before `begin()`.

_RTC Asynchronous and Synchronous prescaler_
* **`void getPrediv(int8_t *predivA, int16_t *predivS)`** : get user (a)synchronous prescaler values if set else computed ones for the current clock source.
Expand All @@ -42,20 +42,20 @@ _SubSeconds management_
* **`void setSubSeconds(uint32_t subSeconds)`**

_Hour format (AM or PM)_
* **`uint8_t getHours(RTC_AM_PM *period)`**
* **`void setHours(uint8_t hours, RTC_AM_PM period)`**
* **`void setTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, RTC_AM_PM period)`**
* **`void setAlarmHours(uint8_t hours, RTC_AM_PM period)`**
* **`uint8_t getAlarmHours(RTC_AM_PM *period)`**
* **`void setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, RTC_AM_PM period)`**
* **`uint8_t getHours(AM_PM *period)`**
* **`void setHours(uint8_t hours, AM_PM period)`**
* **`void setTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, AM_PM period)`**
* **`void setAlarmHours(uint8_t hours, AM_PM period)`**
* **`uint8_t getAlarmHours(AM_PM *period)`**
* **`void setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, AM_PM period)`**

_Week day configuration_
* **`uint8_t getWeekDay(void)`**
* **`void setWeekDay(uint8_t weekDay)`**
* **`void setDate(uint8_t weekDay, uint8_t day, uint8_t month, uint8_t year)`**

_Time and date configuration (added for convenience)_
* **`void getTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, RTC_AM_PM *period = NULL)`**
* **`void getTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, AM_PM *period = NULL)`**
* **`void getDate(uint8_t *weekDay, uint8_t *day, uint8_t *month, uint8_t *year)`**

Refer to the Arduino RTC documentation for the other functions
Expand Down
4 changes: 2 additions & 2 deletions examples/Epoch/Epoch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ STM32RTC& rtc = STM32RTC::getInstance();
void setup() {
Serial.begin(9600);

// Select RTC clock source: RTC_LSI_CLOCK, RTC_LSE_CLOCK or RTC_HSE_CLOCK.
// Select RTC clock source: LSI_CLOCK, LSE_CLOCK or HSE_CLOCK.
// By default the LSI is selected as source.
//rtc.setClockSource(STM32RTC::RTC_LSE_CLOCK);
//rtc.setClockSource(STM32RTC::LSE_CLOCK);

rtc.begin(); // initialize RTC 24H format

Expand Down
4 changes: 2 additions & 2 deletions examples/RTCClockSelection/RTCClockSelection.ino
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ void setup()
{
Serial.begin(9600);

// Select RTC clock source: RTC_LSI_CLOCK, RTC_LSE_CLOCK or RTC_HSE_CLOCK.
// Select RTC clock source: LSI_CLOCK, LSE_CLOCK or HSE_CLOCK.
// By default the LSI is selected as source.
rtc.setClockSource(STM32RTC::RTC_LSE_CLOCK);
rtc.setClockSource(STM32RTC::LSE_CLOCK);

rtc.begin(); // initialize RTC 24H format

Expand Down
4 changes: 2 additions & 2 deletions examples/SimpleRTC/SimpleRTC.ino
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ void setup()
{
Serial.begin(9600);

// Select RTC clock source: RTC_LSI_CLOCK, RTC_LSE_CLOCK or RTC_HSE_CLOCK.
// Select RTC clock source: LSI_CLOCK, LSE_CLOCK or HSE_CLOCK.
// By default the LSI is selected as source.
//rtc.setClockSource(STM32RTC::RTC_LSE_CLOCK);
//rtc.setClockSource(STM32RTC::LSE_CLOCK);

rtc.begin(); // initialize RTC 24H format

Expand Down
4 changes: 2 additions & 2 deletions examples/advancedRTCAlarm/advancedRTCAlarm.ino
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ void setup()
{
Serial.begin(9600);

// Select RTC clock source: RTC_LSI_CLOCK, RTC_LSE_CLOCK or RTC_HSE_CLOCK.
// Select RTC clock source: LSI_CLOCK, LSE_CLOCK or HSE_CLOCK.
// By default the LSI is selected as source.
//rtc.setClockSource(STM32RTC::RTC_LSE_CLOCK);
//rtc.setClockSource(STM32RTC::LSE_CLOCK);

rtc.begin(); // initialize RTC 24H format

Expand Down
4 changes: 2 additions & 2 deletions examples/simpleRTCAlarm/simpleRTCAlarm.ino
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ void setup()
{
Serial.begin(9600);

// Select RTC clock source: RTC_LSI_CLOCK, RTC_LSE_CLOCK or RTC_HSE_CLOCK.
// Select RTC clock source: LSI_CLOCK, LSE_CLOCK or HSE_CLOCK.
// By default the LSI is selected as source.
//rtc.setClockSource(STM32RTC::RTC_LSE_CLOCK);
//rtc.setClockSource(STM32RTC::LSE_CLOCK);

rtc.begin(); // initialize RTC 24H format

Expand Down
14 changes: 7 additions & 7 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ MATCH_HHMMSS LITERAL1
MATCH_DHHMMSS LITERAL1
MATCH_MMDDHHMMSS LITERAL1
MATCH_YYMMDDHHMMSS LITERAL1
RTC_HOUR_12 LITERAL1
RTC_HOUR_24 LITERAL1
RTC_AM LITERAL1
RTC_PM LITERAL1
RTC_LSE_CLOCK LITERAL1
RTC_LSI_CLOCK LITERAL1
RTC_HSE_CLOCK LITERAL1
HOUR_12 LITERAL1
HOUR_24 LITERAL1
AM LITERAL1
PM LITERAL1
LSE_CLOCK LITERAL1
LSI_CLOCK LITERAL1
HSE_CLOCK LITERAL1
70 changes: 35 additions & 35 deletions src/STM32RTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ bool STM32RTC::_configured = false;
/**
* @brief initializes the RTC
* @param resetTime: if true reconfigures the RTC
* @param format: hour format: RTC_HOUR_12 or RTC_HOUR_24(default)
* @param format: hour format: HOUR_12 or HOUR_24(default)
* @retval None
*/
void STM32RTC::begin(bool resetTime, RTC_Hour_Format format)
void STM32RTC::begin(bool resetTime, Hour_Format format)
{
if(resetTime == true) {
_configured = false;
Expand All @@ -63,15 +63,15 @@ void STM32RTC::begin(bool resetTime, RTC_Hour_Format format)

/**
* @brief initializes the RTC
* @param format: hour format: RTC_HOUR_12 or RTC_HOUR_24(default)
* @param format: hour format: HOUR_12 or HOUR_24(default)
* @retval None
*/
void STM32RTC::begin(RTC_Hour_Format format)
void STM32RTC::begin(Hour_Format format)
{
if(_configured == false) {
RTC_init((format == RTC_HOUR_12)? HOUR_FORMAT_12: HOUR_FORMAT_24,
(_clockSource == RTC_LSE_CLOCK)? LSE_CLOCK:
(_clockSource == RTC_HSE_CLOCK)? HSE_CLOCK : LSI_CLOCK);
RTC_init((format == HOUR_12)? HOUR_FORMAT_12: HOUR_FORMAT_24,
(_clockSource == LSE_CLOCK)? ::LSE_CLOCK:
(_clockSource == HSE_CLOCK)? ::HSE_CLOCK : ::LSI_CLOCK);
// Must be set before call of sync methods
_configured = true;
syncTime();
Expand Down Expand Up @@ -106,25 +106,25 @@ void STM32RTC::end(void)

/**
* @brief get the RTC clock source.
* @retval clock source: RTC_LSI_CLOCK, RTC_LSE_CLOCK or RTC_HSE_CLOCK
* @retval clock source: LSI_CLOCK, LSE_CLOCK or HSE_CLOCK
*/
STM32RTC::RTC_Source_Clock STM32RTC::getClockSource(void)
STM32RTC::Source_Clock STM32RTC::getClockSource(void)
{
return _clockSource;
}

/**
* @brief set the RTC clock source. By default LSI clock is selected. This
* method must be called before begin().
* @param source: clock source: RTC_LSI_CLOCK, RTC_LSE_CLOCK or RTC_HSE_CLOCK
* @param source: clock source: LSI_CLOCK, LSE_CLOCK or HSE_CLOCK
* @retval None
*/
void STM32RTC::setClockSource(RTC_Source_Clock source)
void STM32RTC::setClockSource(Source_Clock source)
{
if(IS_CLOCK_SOURCE(source)) {
_clockSource = source;
RTC_SetClockSource((_clockSource == RTC_LSE_CLOCK)? LSE_CLOCK:
(_clockSource == RTC_HSE_CLOCK)? HSE_CLOCK : LSI_CLOCK);
RTC_SetClockSource((_clockSource == LSE_CLOCK)? ::LSE_CLOCK:
(_clockSource == HSE_CLOCK)? ::HSE_CLOCK : ::LSI_CLOCK);
}
}

Expand Down Expand Up @@ -174,7 +174,7 @@ void STM32RTC::enableAlarm(Alarm_Match match)
case MATCH_MMSS:
case MATCH_SS:
RTC_StartAlarm(_alarmDay, _alarmHours, _alarmMinutes, _alarmSeconds,
_alarmSubSeconds, (_alarmPeriod == RTC_AM)? AM: PM,
_alarmSubSeconds, (_alarmPeriod == AM)? HOUR_AM: HOUR_PM,
static_cast<uint8_t>(_alarmMatch));
_alarmEnabled = true;
break;
Expand Down Expand Up @@ -261,7 +261,7 @@ uint8_t STM32RTC::getMinutes(void)
* 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(RTC_AM_PM *period)
uint8_t STM32RTC::getHours(AM_PM *period)
{
syncTime();
if(period != NULL) {
Expand All @@ -280,7 +280,7 @@ uint8_t STM32RTC::getHours(RTC_AM_PM *period)
* 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, RTC_AM_PM *period)
void STM32RTC::getTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, AM_PM *period)
{
syncTime();
if(hours != NULL) {
Expand Down Expand Up @@ -401,7 +401,7 @@ uint8_t STM32RTC::getAlarmMinutes(void)
* pointer to the current hour format set in the RTC: AM or PM
* @retval return the current alarm hour.
*/
uint8_t STM32RTC::getAlarmHours(RTC_AM_PM *period)
uint8_t STM32RTC::getAlarmHours(AM_PM *period)
{
syncAlarmTime();
if(period != NULL) {
Expand Down Expand Up @@ -458,7 +458,7 @@ void STM32RTC::setSubSeconds(uint32_t subSeconds)
if(subSeconds < 1000) {
_subSeconds = subSeconds;
}
RTC_SetTime(_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == RTC_AM)? AM : PM);
RTC_SetTime(_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == AM)? HOUR_AM : HOUR_PM);
}
}

Expand All @@ -474,7 +474,7 @@ void STM32RTC::setSeconds(uint8_t seconds)
if(seconds < 60) {
_seconds = seconds;
}
RTC_SetTime(_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == RTC_AM)? AM : PM);
RTC_SetTime(_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == AM)? HOUR_AM : HOUR_PM);
}
}

Expand All @@ -490,7 +490,7 @@ void STM32RTC::setMinutes(uint8_t minutes)
if(minutes < 60) {
_minutes = minutes;
}
RTC_SetTime(_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == RTC_AM)? AM : PM);
RTC_SetTime(_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == AM)? HOUR_AM : HOUR_PM);
}
}

Expand All @@ -506,7 +506,7 @@ void STM32RTC::setHours(uint8_t hours)
if(hours < 24) {
_hours = hours;
}
RTC_SetTime(_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == RTC_AM)? AM : PM);
RTC_SetTime(_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == AM)? HOUR_AM : HOUR_PM);
}
}

Expand All @@ -516,15 +516,15 @@ void STM32RTC::setHours(uint8_t hours)
* @param hours format: AM or PM
* @retval none
*/
void STM32RTC::setHours(uint8_t hours, RTC_AM_PM period)
void STM32RTC::setHours(uint8_t hours, AM_PM period)
{
if (_configured) {
syncTime();
if(hours < 24) {
_hours = hours;
}
_hoursPeriod = period;
RTC_SetTime(_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == RTC_AM)? AM : PM);
RTC_SetTime(_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == AM)? HOUR_AM : HOUR_PM);
}
}

Expand All @@ -548,7 +548,7 @@ void STM32RTC::setTime(uint8_t hours, uint8_t minutes, uint8_t seconds)
if(hours < 24) {
_hours = hours;
}
RTC_SetTime(_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == RTC_AM)? AM : PM);
RTC_SetTime(_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == AM)? HOUR_AM : HOUR_PM);
}
}

Expand All @@ -560,7 +560,7 @@ void STM32RTC::setTime(uint8_t hours, uint8_t minutes, uint8_t seconds)
* @param hour format: AM or PM
* @retval none
*/
void STM32RTC::setTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, RTC_AM_PM period)
void STM32RTC::setTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, AM_PM period)
{
if (_configured) {
syncTime();
Expand All @@ -577,7 +577,7 @@ void STM32RTC::setTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t
_hours = hours;
}
_hoursPeriod = period;
RTC_SetTime(_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == RTC_AM)? AM : PM);
RTC_SetTime(_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == AM)? HOUR_AM : HOUR_PM);
}
}

Expand Down Expand Up @@ -744,7 +744,7 @@ void STM32RTC::setAlarmHours(uint8_t hours)
* @param hour format: AM or PM
* @retval none
*/
void STM32RTC::setAlarmHours(uint8_t hours, RTC_AM_PM period)
void STM32RTC::setAlarmHours(uint8_t hours, AM_PM period)
{
if (_configured) {
if(hours < 24) {
Expand Down Expand Up @@ -778,7 +778,7 @@ void STM32RTC::setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds)
* @param hour format: AM or PM
* @retval none
*/
void STM32RTC::setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, RTC_AM_PM period)
void STM32RTC::setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, AM_PM period)
{
if (_configured) {
setAlarmHours(hours, period);
Expand Down Expand Up @@ -925,7 +925,7 @@ void STM32RTC::setEpoch(uint32_t ts)
_seconds = tmp->tm_sec;

RTC_SetDate(_year, _month, _day, _wday);
RTC_SetTime(_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == RTC_AM)? AM : PM);
RTC_SetTime(_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == AM)? HOUR_AM : HOUR_PM);
}
}

Expand All @@ -944,7 +944,7 @@ void STM32RTC::setY2kEpoch(uint32_t ts)
* @brief configure RTC source clock for low power
* @param none
*/
void STM32RTC::configForLowPower(RTC_Source_Clock source)
void STM32RTC::configForLowPower(Source_Clock source)
{
#if defined(HAL_PWR_MODULE_ENABLED)
if (!_configured){
Expand All @@ -954,7 +954,7 @@ void STM32RTC::configForLowPower(RTC_Source_Clock source)
} else {
if (_clockSource != source) {
// Save current config
RTC_AM_PM period, alarmPeriod = _alarmPeriod;
AM_PM period, alarmPeriod = _alarmPeriod;
uint32_t subSeconds;
uint8_t seconds, minutes, hours, weekDay, day, month, years;
uint8_t alarmSeconds, alarmMinutes, alarmHours, alarmDay;
Expand Down Expand Up @@ -993,9 +993,9 @@ void STM32RTC::configForLowPower(RTC_Source_Clock source)
void STM32RTC::syncTime(void)
{
if(_configured) {
hourAM_PM_t p = AM;
hourAM_PM_t p = HOUR_AM;
RTC_GetTime(&_hours, &_minutes, &_seconds, &_subSeconds, &p);
_hoursPeriod = (p == AM)? RTC_AM : RTC_PM;
_hoursPeriod = (p == HOUR_AM)? AM : PM;
}
}

Expand All @@ -1017,11 +1017,11 @@ void STM32RTC::syncDate(void)
void STM32RTC::syncAlarmTime(void)
{
if(_configured) {
hourAM_PM_t p = AM;
hourAM_PM_t p = HOUR_AM;
uint8_t match;
RTC_GetAlarm(&_alarmDay, &_alarmHours, &_alarmMinutes, &_alarmSeconds,
&_alarmSubSeconds, &p, &match);
_alarmPeriod = (p == AM)? RTC_AM : RTC_PM;
_alarmPeriod = (p == HOUR_AM)? AM : PM;
switch (static_cast<Alarm_Match>(match)) {
case MATCH_OFF:
case MATCH_YYMMDDHHMMSS://kept for compatibility
Expand Down
Loading