Skip to content

Commit d8461ea

Browse files
committed
STM32RTC library configure the alarm depending on the MIX mode
In case the RTC is running in MIX mode (BINary and calendar), the subsecond register is a 32-bit value (and not msec)
1 parent 54b7eea commit d8461ea

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

src/STM32RTC.cpp

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,27 @@ void STM32RTC::enableAlarm(Alarm_Match match, Alarm name)
237237
RTC_StopAlarm(::ALARM_A);
238238
}
239239
break;
240+
case MATCH_SUBSEC:
241+
/* force _alarmday to 0 to go to the right alarm config in MIX mode */
242+
#ifdef RTC_ALARM_B
243+
if (name == ALARM_B) {
244+
RTC_StartAlarm(::ALARM_B, 0, _alarmBHours, _alarmBMinutes, _alarmBSeconds,
245+
(UINT32_MAX - _alarmBSubSeconds), (_alarmBPeriod == AM) ? HOUR_AM : HOUR_PM,
246+
static_cast<uint8_t>(32UL));
247+
} else
248+
#endif
249+
{
250+
RTC_StartAlarm(::ALARM_A, 0, _alarmHours, _alarmMinutes, _alarmSeconds,
251+
(UINT32_MAX -_alarmSubSeconds), (_alarmPeriod == AM) ? HOUR_AM : HOUR_PM,
252+
static_cast<uint8_t>(32UL));
253+
}
254+
break;
240255
case MATCH_YYMMDDHHMMSS://kept for compatibility
241256
case MATCH_MMDDHHMMSS: //kept for compatibility
242257
case MATCH_DHHMMSS:
243258
case MATCH_HHMMSS:
244259
case MATCH_MMSS:
245260
case MATCH_SS:
246-
case MATCH_SUBSEC:
247261
#ifdef RTC_ALARM_B
248262
if (name == ALARM_B) {
249263
RTC_StartAlarm(::ALARM_B, _alarmBDay, _alarmBHours, _alarmBMinutes, _alarmBSeconds,
@@ -845,16 +859,30 @@ void STM32RTC::setDate(uint8_t weekDay, uint8_t day, uint8_t month, uint8_t year
845859
*/
846860
void STM32RTC::setAlarmSubSeconds(uint32_t subSeconds, Alarm name)
847861
{
848-
if (subSeconds < 1000) {
862+
863+
if (getRTCMode() == MODE_MIX) {
849864
#ifdef RTC_ALARM_B
850-
if (name == ALARM_B) {
851-
_alarmBSubSeconds = subSeconds;
852-
}
865+
if (name == ALARM_B) {
866+
_alarmBSubSeconds = subSeconds;
867+
}
853868
#else
854-
UNUSED(name);
869+
UNUSED(name);
855870
#endif
856-
{
857-
_alarmSubSeconds = subSeconds;
871+
{
872+
_alarmSubSeconds = subSeconds;
873+
}
874+
} else {
875+
if (subSeconds < 1000) {
876+
#ifdef RTC_ALARM_B
877+
if (name == ALARM_B) {
878+
_alarmBSubSeconds = subSeconds;
879+
}
880+
#else
881+
UNUSED(name);
882+
#endif
883+
{
884+
_alarmSubSeconds = subSeconds;
885+
}
858886
}
859887
}
860888
}
@@ -1268,7 +1296,8 @@ bool STM32RTC::isAlarmEnabled(Alarm name)
12681296
void STM32RTC::syncTime(void)
12691297
{
12701298
hourAM_PM_t p = HOUR_AM;
1271-
RTC_GetTime(&_hours, &_minutes, &_seconds, &_subSeconds, &p);
1299+
rtcMode_t mode = (getRTCMode() == MODE_MIX) ? MODE_BINARY_MIX : MODE_BINARY_ONLY;
1300+
RTC_GetTime(mode, &_hours, &_minutes, &_seconds, &_subSeconds, &p);
12721301
_hoursPeriod = (p == HOUR_AM) ? AM : PM;
12731302
}
12741303

@@ -1292,18 +1321,19 @@ void STM32RTC::syncDate(void)
12921321
void STM32RTC::syncAlarmTime(Alarm name)
12931322
{
12941323
hourAM_PM_t p = HOUR_AM;
1324+
rtcMode_t mode = (getRTCMode() == MODE_MIX) ? MODE_BINARY_MIX : MODE_BINARY_ONLY;
12951325
uint8_t match;
12961326
#ifdef RTC_ALARM_B
12971327
if (name == ALARM_B) {
1298-
RTC_GetAlarm(::ALARM_B, &_alarmBDay, &_alarmBHours, &_alarmBMinutes, &_alarmBSeconds,
1328+
RTC_GetAlarm(mode, ::ALARM_B, &_alarmBDay, &_alarmBHours, &_alarmBMinutes, &_alarmBSeconds,
12991329
&_alarmBSubSeconds, &p, &match);
13001330
_alarmBPeriod = (p == HOUR_AM) ? AM : PM;
13011331
} else
13021332
#else
13031333
UNUSED(name);
13041334
#endif
13051335
{
1306-
RTC_GetAlarm(::ALARM_A, &_alarmDay, &_alarmHours, &_alarmMinutes, &_alarmSeconds,
1336+
RTC_GetAlarm(mode, ::ALARM_A, &_alarmDay, &_alarmHours, &_alarmMinutes, &_alarmSeconds,
13071337
&_alarmSubSeconds, &p, &match);
13081338
_alarmPeriod = (p == HOUR_AM) ? AM : PM;
13091339
}

0 commit comments

Comments
 (0)