@@ -237,13 +237,27 @@ void STM32RTC::enableAlarm(Alarm_Match match, Alarm name)
237
237
RTC_StopAlarm (::ALARM_A);
238
238
}
239
239
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 ;
240
255
case MATCH_YYMMDDHHMMSS:// kept for compatibility
241
256
case MATCH_MMDDHHMMSS: // kept for compatibility
242
257
case MATCH_DHHMMSS:
243
258
case MATCH_HHMMSS:
244
259
case MATCH_MMSS:
245
260
case MATCH_SS:
246
- case MATCH_SUBSEC:
247
261
#ifdef RTC_ALARM_B
248
262
if (name == ALARM_B) {
249
263
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
845
859
*/
846
860
void STM32RTC::setAlarmSubSeconds (uint32_t subSeconds, Alarm name)
847
861
{
848
- if (subSeconds < 1000 ) {
862
+
863
+ if (getRTCMode () == MODE_MIX) {
849
864
#ifdef RTC_ALARM_B
850
- if (name == ALARM_B) {
851
- _alarmBSubSeconds = subSeconds;
852
- }
865
+ if (name == ALARM_B) {
866
+ _alarmBSubSeconds = subSeconds;
867
+ }
853
868
#else
854
- UNUSED (name);
869
+ UNUSED (name);
855
870
#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
+ }
858
886
}
859
887
}
860
888
}
@@ -1268,7 +1296,8 @@ bool STM32RTC::isAlarmEnabled(Alarm name)
1268
1296
void STM32RTC::syncTime (void )
1269
1297
{
1270
1298
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);
1272
1301
_hoursPeriod = (p == HOUR_AM) ? AM : PM;
1273
1302
}
1274
1303
@@ -1292,18 +1321,19 @@ void STM32RTC::syncDate(void)
1292
1321
void STM32RTC::syncAlarmTime (Alarm name)
1293
1322
{
1294
1323
hourAM_PM_t p = HOUR_AM;
1324
+ rtcMode_t mode = (getRTCMode () == MODE_MIX) ? MODE_BINARY_MIX : MODE_BINARY_ONLY;
1295
1325
uint8_t match;
1296
1326
#ifdef RTC_ALARM_B
1297
1327
if (name == ALARM_B) {
1298
- RTC_GetAlarm (::ALARM_B, &_alarmBDay, &_alarmBHours, &_alarmBMinutes, &_alarmBSeconds,
1328
+ RTC_GetAlarm (mode, ::ALARM_B, &_alarmBDay, &_alarmBHours, &_alarmBMinutes, &_alarmBSeconds,
1299
1329
&_alarmBSubSeconds, &p, &match);
1300
1330
_alarmBPeriod = (p == HOUR_AM) ? AM : PM;
1301
1331
} else
1302
1332
#else
1303
1333
UNUSED (name);
1304
1334
#endif
1305
1335
{
1306
- RTC_GetAlarm (::ALARM_A, &_alarmDay, &_alarmHours, &_alarmMinutes, &_alarmSeconds,
1336
+ RTC_GetAlarm (mode, ::ALARM_A, &_alarmDay, &_alarmHours, &_alarmMinutes, &_alarmSeconds,
1307
1337
&_alarmSubSeconds, &p, &match);
1308
1338
_alarmPeriod = (p == HOUR_AM) ? AM : PM;
1309
1339
}
0 commit comments