remember which devices were scanned on which bus and set them accordingly.

This commit is contained in:
Thomas Göttgens
2022-11-12 17:12:40 +01:00
parent 7a67388a97
commit 861ded37db
23 changed files with 177 additions and 119 deletions

View File

@@ -20,10 +20,16 @@ void readFromRTC()
{
struct timeval tv; /* btw settimeofday() is helpfull here too*/
#ifdef RV3028_RTC
if(rtc_found == RV3028_RTC) {
if(i2cScanMap[RV3028_RTC].addr == RV3028_RTC) {
uint32_t now = millis();
Melopero_RV3028 rtc;
rtc.initI2C();
if (i2cScanMap[RV3028_RTC].bus == 1) {
#ifdef I2C_SDA1
rtc.initI2C(Wire1);
#endif
} else {
rtc.initI2C();
}
tm t;
t.tm_year = rtc.getYear() - 1900;
t.tm_mon = rtc.getMonth() - 1;
@@ -41,14 +47,16 @@ void readFromRTC()
}
}
#elif defined(PCF8563_RTC)
if(rtc_found == PCF8563_RTC) {
if(i2cScanMap[PCF8563_RTC].addr == PCF8563_RTC) {
uint32_t now = millis();
PCF8563_Class rtc;
#ifdef RTC_USE_WIRE1
rtc.begin(Wire1);
#else
rtc.begin();
if (i2cScanMap[PCF8563_RTC].bus == 1) {
#ifdef I2C_SDA1
rtc.begin(Wire1);
#endif
} else {
rtc.begin();
}
auto tc = rtc.getDateTime();
tm t;
t.tm_year = tc.year - 1900;
@@ -104,21 +112,29 @@ bool perhapsSetRTC(RTCQuality q, const struct timeval *tv)
// If this platform has a setable RTC, set it
#ifdef RV3028_RTC
if(rtc_found == RV3028_RTC) {
if(i2cScanMap[RV3028_RTC].addr == RV3028_RTC) {
Melopero_RV3028 rtc;
rtc.initI2C();
if (i2cScanMap[RV3028_RTC].bus == 1) {
#ifdef I2C_SDA1
rtc.initI2C(Wire1);
#endif
} else {
rtc.initI2C();
}
tm *t = localtime(&tv->tv_sec);
rtc.setTime(t->tm_year + 1900, t->tm_mon + 1, t->tm_wday, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
DEBUG_MSG("RV3028_RTC setTime %02d-%02d-%02d %02d:%02d:%02d %ld\n", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, tv->tv_sec);
}
#elif defined(PCF8563_RTC)
if(rtc_found == PCF8563_RTC) {
if(i2cScanMap[PCF8563_RTC].addr == PCF8563_RTC) {
PCF8563_Class rtc;
#ifdef RTC_USE_WIRE1
rtc.begin(Wire1);
#else
rtc.begin();
if (i2cScanMap[PCF8563_RTC].bus == 1) {
#ifdef I2C_SDA1
rtc.begin(Wire1);
#endif
} else {
rtc.begin();
}
tm *t = localtime(&tv->tv_sec);
rtc.setDateTime(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
DEBUG_MSG("PCF8563_RTC setDateTime %02d-%02d-%02d %02d:%02d:%02d %ld\n", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, tv->tv_sec);