sforkowany z mirror/meshtastic-firmware
Merge pull request #1419 from meshtastic/PCF8563
RTC Module support for T-Echo and others with PCF8563raytac-diy
commit
bfc2d30a46
|
@ -28,6 +28,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#ifdef RV3028_RTC
|
#ifdef RV3028_RTC
|
||||||
#include "Melopero_RV3028.h"
|
#include "Melopero_RV3028.h"
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef PCF8563_RTC
|
||||||
|
#include "pcf8563.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Version
|
// Version
|
||||||
|
|
|
@ -63,6 +63,12 @@ void scanI2Cdevice(void)
|
||||||
rtc.writeToRegister(0x35,0x07); // no Clkout
|
rtc.writeToRegister(0x35,0x07); // no Clkout
|
||||||
rtc.writeToRegister(0x37,0xB4);
|
rtc.writeToRegister(0x37,0xB4);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef PCF8563_RTC
|
||||||
|
if (addr == PCF8563_RTC){
|
||||||
|
rtc_found = addr;
|
||||||
|
DEBUG_MSG("PCF8563 RTC found\n");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (addr == CARDKB_ADDR) {
|
if (addr == CARDKB_ADDR) {
|
||||||
cardkb_found = addr;
|
cardkb_found = addr;
|
||||||
|
|
|
@ -40,6 +40,28 @@ void readFromRTC()
|
||||||
currentQuality = RTCQualityDevice;
|
currentQuality = RTCQualityDevice;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#elif defined(PCF8563_RTC)
|
||||||
|
if(rtc_found == PCF8563_RTC) {
|
||||||
|
uint32_t now = millis();
|
||||||
|
PCF8563_Class rtc;
|
||||||
|
rtc.begin();
|
||||||
|
auto tc = rtc.getDateTime();
|
||||||
|
tm t;
|
||||||
|
t.tm_year = tc.year;
|
||||||
|
t.tm_mon = tc.month;
|
||||||
|
t.tm_mday = tc.day;
|
||||||
|
t.tm_hour = tc.hour;
|
||||||
|
t.tm_min = tc.minute;
|
||||||
|
t.tm_sec = tc.second;
|
||||||
|
tv.tv_sec = mktime(&t);
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
DEBUG_MSG("Read RTC time from PCF8563 as %ld\n", tv.tv_sec);
|
||||||
|
timeStartMsec = now;
|
||||||
|
zeroOffsetSecs = tv.tv_sec;
|
||||||
|
if (currentQuality == RTCQualityNone) {
|
||||||
|
currentQuality = RTCQualityDevice;
|
||||||
|
}
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
if (!gettimeofday(&tv, NULL)) {
|
if (!gettimeofday(&tv, NULL)) {
|
||||||
uint32_t now = millis();
|
uint32_t now = millis();
|
||||||
|
@ -85,6 +107,14 @@ bool perhapsSetRTC(RTCQuality q, const struct timeval *tv)
|
||||||
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);
|
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);
|
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) {
|
||||||
|
PCF8563_Class rtc;
|
||||||
|
rtc.begin();
|
||||||
|
tm *t = localtime(&tv->tv_sec);
|
||||||
|
rtc.setDateTime(t->tm_year + 1900, t->tm_mon + 1, t->tm_wday, 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);
|
||||||
|
}
|
||||||
#elif !defined(NO_ESP32)
|
#elif !defined(NO_ESP32)
|
||||||
settimeofday(tv, NULL);
|
settimeofday(tv, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -14,4 +14,5 @@ lib_deps =
|
||||||
${nrf52840_base.lib_deps}
|
${nrf52840_base.lib_deps}
|
||||||
https://github.com/meshtastic/GxEPD2
|
https://github.com/meshtastic/GxEPD2
|
||||||
adafruit/Adafruit BusIO
|
adafruit/Adafruit BusIO
|
||||||
|
lewisxhe/PCF8563_Library@^0.0.1
|
||||||
;upload_protocol = fs
|
;upload_protocol = fs
|
||||||
|
|
|
@ -182,6 +182,9 @@ External serial flash WP25R1635FZUIL0
|
||||||
#define PIN_SERIAL1_RX PIN_GPS_TX
|
#define PIN_SERIAL1_RX PIN_GPS_TX
|
||||||
#define PIN_SERIAL1_TX PIN_GPS_RX
|
#define PIN_SERIAL1_TX PIN_GPS_RX
|
||||||
|
|
||||||
|
// PCF8563 RTC Module
|
||||||
|
#define PCF8563_RTC 0x51
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SPI Interfaces
|
* SPI Interfaces
|
||||||
*/
|
*/
|
||||||
|
|
Ładowanie…
Reference in New Issue