Skip to content

Commit 1ad89cc

Browse files
PCF85063 RTC Chip Support (arendst#22727)
* Create ST7701_480x480_WS_4inch.ini Display driver for 4inch display with ST7701 driver and GT911 touch driver including correct pinout and correct init process trought SPI. Used in WaveShare ESP32-S3-4inch display board. * Update xdrv_56_rtc_chips.ino Added support for PCF85063 RTC Chip. * Update my_user_config.h Added PCF85063 RTC support * Update I2CDEVICES.md Added PCF85063 RTC support
1 parent de3a7f3 commit 1ad89cc

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

I2CDEVICES.md

+1
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,6 @@ Index | Define | Driver | Device | Address(es) | Bus2 | Descrip
129129
89 | USE_HX711_M5SCALES | xsns_34 | M5SCALES | 0x26 | Yes | M5Unit (Mini)Scales(HX711 STM32) U177
130130
90 | USE_RX8010 | xdrv_56 | RX8010 | 0x32 | Yes | RX8010 RTC from IOTTIMER
131131
91 | USE_MS5837 | xsns_116 | MS5837 | 0x76 | | Pressure and temperature sensor
132+
92 | USE_PCF85063 | xdrv_56 | PCF85063 | 0x51 | | PCF85063 Real time clock
132133

133134
NOTE: Bus2 supported on ESP32 only.

tasmota/my_user_config.h

+1
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@
769769
// #define USE_BM8563 // [I2cDriver59] Enable BM8563 RTC - used by M5Stack - support both I2C buses on ESP32 (I2C address 0x51) (+2.5k code)
770770
// #define USE_PCF85363 // [I2cDriver66] Enable PCF85363 RTC - used by Shelly 3EM (I2C address 0x51) (+0k7 code)
771771
// #define USE_RX8010 // [I2cDriver90] Enable RX8010 RTC - used by IOTTIMER - support both I2C buses on ESP32 (I2C address 0x32) (+0k7 code)
772+
// #define USE_PCF85063 // [I2cDriver92] Enable PCF85063 RTC support (I2C address 0x51)
772773

773774
// #define USE_DISPLAY // Add I2C/TM1637/MAX7219 Display Support (+2k code)
774775
#define USE_DISPLAY_MODES1TO5 // Enable display mode 1 to 5 in addition to mode 0

tasmota/tasmota_xdrv_driver/xdrv_56_rtc_chips.ino

+109
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,112 @@ void DS3231Detected(void) {
185185
}
186186
#endif // USE_DS3231
187187

188+
189+
190+
/*********************************************************************************************\
191+
* PCF85063 support
192+
*
193+
* I2C Address: 0x51
194+
\*********************************************************************************************/
195+
#ifdef USE_PCF85063
196+
197+
#define XI2C_92 92 // Unique ID for I2C device search
198+
199+
#define PCF85063_ADDRESS 0x51 // PCF85063 I2C Address
200+
201+
202+
#define PCF85063_REG_CTRL1 0x00
203+
#define PCF85063_REG_CTRL2 0x01
204+
#define PCF85063_REG_OFFSET 0x02
205+
#define PCF85063_REG_SECONDS 0x04
206+
#define PCF85063_REG_MINUTES 0x05
207+
#define PCF85063_REG_HOURS 0x06
208+
#define PCF85063_REG_DAYS 0x07
209+
#define PCF85063_REG_WEEKDAYS 0x08
210+
#define PCF85063_REG_MONTHS 0x09
211+
#define PCF85063_REG_YEARS 0x0A
212+
213+
214+
uint32_t Pcf85063ReadTime(void) {
215+
Wire.beginTransmission(RtcChip.address);
216+
Wire.write(PCF85063_REG_SECONDS);
217+
Wire.endTransmission(false); // false -> repeated start
218+
Wire.requestFrom((uint8_t)RtcChip.address, (uint8_t)7);
219+
220+
uint8_t sec = Wire.read(); // 0x04
221+
uint8_t min = Wire.read(); // 0x05
222+
uint8_t hour = Wire.read(); // 0x06
223+
uint8_t day = Wire.read(); // 0x07
224+
uint8_t wday = Wire.read(); // 0x08
225+
uint8_t month = Wire.read(); // 0x09
226+
uint8_t year = Wire.read(); // 0x0A
227+
228+
TIME_T tm;
229+
tm.second = Bcd2Dec(sec & 0x7F);
230+
tm.minute = Bcd2Dec(min & 0x7F);
231+
tm.hour = Bcd2Dec(hour & 0x3F);
232+
tm.day_of_month = Bcd2Dec(day & 0x3F);
233+
tm.day_of_week = wday & 0x07;
234+
tm.month = Bcd2Dec(month & 0x1F) -1;
235+
uint8_t y = Bcd2Dec(year);
236+
tm.year = (y + 30);
237+
return MakeTime(tm);
238+
}
239+
240+
241+
void Pcf85063SetTime(uint32_t epoch_time) {
242+
TIME_T tm;
243+
BreakTime(epoch_time, tm);
244+
245+
246+
uint8_t year = (tm.year -30);
247+
if (year > 99) { year = 99; }
248+
249+
uint8_t bcd_sec = Dec2Bcd(tm.second);
250+
uint8_t bcd_min = Dec2Bcd(tm.minute);
251+
uint8_t bcd_hour = Dec2Bcd(tm.hour);
252+
uint8_t bcd_day = Dec2Bcd(tm.day_of_month);
253+
uint8_t bcd_wday = tm.day_of_week & 0x07;
254+
uint8_t bcd_month = Dec2Bcd(tm.month +1);
255+
uint8_t bcd_year = Dec2Bcd(year);
256+
257+
Wire.beginTransmission(RtcChip.address);
258+
Wire.write(PCF85063_REG_SECONDS);
259+
Wire.write(bcd_sec);
260+
Wire.write(bcd_min);
261+
Wire.write(bcd_hour);
262+
Wire.write(bcd_day);
263+
Wire.write(bcd_wday);
264+
Wire.write(bcd_month);
265+
Wire.write(bcd_year);
266+
Wire.endTransmission();
267+
}
268+
269+
/*-------------------------------------------------------------------------------------------*\
270+
* Detection
271+
\*-------------------------------------------------------------------------------------------*/
272+
void Pcf85063Detected(void) {
273+
if (!RtcChip.detected && I2cEnabled(XI2C_92)) {
274+
RtcChip.address = PCF85063_ADDRESS;
275+
// Vyskúšame, či vieme prečítať nejaký register
276+
if (I2cSetDevice(RtcChip.address)) {
277+
// Skúsime napr. prečítať PCF85063_REG_CTRL1
278+
if (I2cValidRead(RtcChip.address, PCF85063_REG_CTRL1, 1)) {
279+
RtcChip.detected = 1;
280+
strcpy_P(RtcChip.name, PSTR("PCF85063"));
281+
RtcChip.ReadTime = &Pcf85063ReadTime;
282+
RtcChip.SetTime = &Pcf85063SetTime;
283+
RtcChip.mem_size = -1; // Nemá extra user RAM, ak by si nepotreboval
284+
285+
// Ak by si chcel implementovať MemRead/MemWrite, doplň RtcChip.MemRead a RtcChip.MemWrite
286+
}
287+
}
288+
}
289+
}
290+
#endif // USE_PCF85063
291+
292+
293+
188294
/*********************************************************************************************\
189295
* BM8563 - Real Time Clock
190296
*
@@ -500,6 +606,9 @@ void RtcChipDetect(void) {
500606
#ifdef USE_RX8010
501607
Rx8010Detected();
502608
#endif // USE_RX8010
609+
#ifdef USE_PCF85063
610+
Pcf85063Detected();
611+
#endif // USE_PCF85063
503612

504613
if (!RtcChip.detected) { return; }
505614

0 commit comments

Comments
 (0)