@@ -185,6 +185,112 @@ void DS3231Detected(void) {
185
185
}
186
186
#endif // USE_DS3231
187
187
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
+
188
294
/* ********************************************************************************************\
189
295
* BM8563 - Real Time Clock
190
296
*
@@ -500,6 +606,9 @@ void RtcChipDetect(void) {
500
606
#ifdef USE_RX8010
501
607
Rx8010Detected ();
502
608
#endif // USE_RX8010
609
+ #ifdef USE_PCF85063
610
+ Pcf85063Detected ();
611
+ #endif // USE_PCF85063
503
612
504
613
if (!RtcChip.detected ) { return ; }
505
614
0 commit comments