2021-10-03 06:09:53 -07:00
|
|
|
#include "globals.h"
|
2021-10-12 18:42:52 -07:00
|
|
|
#include RTC_LIB_H //Defined in each boards .h file
|
2021-02-03 17:22:30 -08:00
|
|
|
#ifdef RTC_ENABLED
|
2021-01-22 13:49:44 -08:00
|
|
|
#include "rtc_common.h"
|
2021-10-12 18:42:52 -07:00
|
|
|
|
2021-01-21 21:16:30 -08:00
|
|
|
|
|
|
|
void initRTC()
|
|
|
|
{
|
|
|
|
|
2021-10-12 18:42:52 -07:00
|
|
|
#if defined(CORE_TEENSY35) || defined(CORE_TEENSY36)
|
2021-10-12 17:53:46 -07:00
|
|
|
setSyncProvider(getTeensy3Time);
|
|
|
|
#elif defined(CORE_STM32)
|
2021-10-12 18:42:52 -07:00
|
|
|
|
2021-10-12 17:53:46 -07:00
|
|
|
#endif
|
2021-01-21 21:16:30 -08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t rtc_getSecond()
|
|
|
|
{
|
|
|
|
uint8_t tempSecond = 0;
|
|
|
|
#ifdef RTC_ENABLED
|
|
|
|
#if defined(CORE_TEENSY)
|
|
|
|
tempSecond = second();
|
|
|
|
#elif defined(CORE_STM32)
|
|
|
|
tempSecond = rtc.getSeconds();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
return tempSecond;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t rtc_getMinute()
|
|
|
|
{
|
|
|
|
uint8_t tempMinute = 0;
|
|
|
|
#ifdef RTC_ENABLED
|
|
|
|
#if defined(CORE_TEENSY)
|
|
|
|
tempMinute = minute();
|
|
|
|
#elif defined(CORE_STM32)
|
|
|
|
tempMinute = rtc.getMinutes();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
return tempMinute;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t rtc_getHour()
|
|
|
|
{
|
|
|
|
uint8_t tempHour = 0;
|
|
|
|
#ifdef RTC_ENABLED
|
|
|
|
#if defined(CORE_TEENSY)
|
|
|
|
tempHour = hour();
|
|
|
|
#elif defined(CORE_STM32)
|
|
|
|
tempHour = rtc.getHours();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
return tempHour;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t rtc_getDay()
|
|
|
|
{
|
|
|
|
uint8_t tempDay = 0;
|
|
|
|
#ifdef RTC_ENABLED
|
|
|
|
#if defined(CORE_TEENSY)
|
|
|
|
tempDay = day();
|
|
|
|
#elif defined(CORE_STM32)
|
|
|
|
tempDay = rtc.getDay();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
return tempDay;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t rtc_getDOW()
|
|
|
|
{
|
|
|
|
uint8_t dow = 0;
|
|
|
|
#ifdef RTC_ENABLED
|
|
|
|
#if defined(CORE_TEENSY)
|
|
|
|
dow = weekday();
|
|
|
|
#elif defined(CORE_STM32)
|
|
|
|
dow = rtc.getWeekDay();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
return dow;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t rtc_getMonth()
|
|
|
|
{
|
|
|
|
uint8_t tempMonth = 0;
|
|
|
|
#ifdef RTC_ENABLED
|
|
|
|
#if defined(CORE_TEENSY)
|
|
|
|
tempMonth = month();
|
|
|
|
#elif defined(CORE_STM32)
|
|
|
|
tempMonth = rtc.getMonth();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
return tempMonth;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t rtc_getYear()
|
|
|
|
{
|
|
|
|
uint16_t tempYear = 0;
|
|
|
|
#ifdef RTC_ENABLED
|
|
|
|
#if defined(CORE_TEENSY)
|
|
|
|
tempYear = year();
|
|
|
|
#elif defined(CORE_STM32)
|
2021-10-03 06:09:53 -07:00
|
|
|
//year in stm32 rtc is a byte. So add year 2000 to make it correct
|
|
|
|
tempYear = (2000+rtc.getYear());
|
2021-01-21 21:16:30 -08:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
return tempYear;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rtc_setTime(byte second, byte minute, byte hour, byte day, byte month, uint16_t year)
|
|
|
|
{
|
|
|
|
#ifdef RTC_ENABLED
|
|
|
|
#if defined(CORE_TEENSY)
|
2021-12-09 19:26:13 -08:00
|
|
|
setTime(hour, minute, second, day, month, year);
|
2021-01-21 21:16:30 -08:00
|
|
|
#elif defined(CORE_STM32)
|
|
|
|
rtc.setTime(hour, minute, second);
|
2022-04-10 17:49:58 -07:00
|
|
|
//year in stm32 rtc is a byte. so subtract year 2000 to fit
|
2021-10-03 06:09:53 -07:00
|
|
|
rtc.setDate(day, month, (year-2000));
|
2021-01-21 21:16:30 -08:00
|
|
|
#endif
|
|
|
|
#endif
|
2021-02-03 17:22:30 -08:00
|
|
|
}
|
2022-04-10 17:49:58 -07:00
|
|
|
#endif
|