my prototype PCF8563's library

Dependents:   Nucleo_rtos_basic

Fork of PCF8563 by irsan julfikar

Committer:
irsanjul
Date:
Fri Jan 22 08:50:40 2016 +0000
Revision:
0:47c63ed3af91
my prototype PCF8563's library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
irsanjul 0:47c63ed3af91 1 #ifndef PCF8563_H
irsanjul 0:47c63ed3af91 2 #define PCF8563_H
irsanjul 0:47c63ed3af91 3
irsanjul 0:47c63ed3af91 4 #define W8563_ADDR 0xA2 // I2C address for write
irsanjul 0:47c63ed3af91 5 #define R8563_ADDR 0xA3 // I2C address for read
irsanjul 0:47c63ed3af91 6 #define PCF8563_FREQ 400000 // bus speed 400 kHz
irsanjul 0:47c63ed3af91 7
irsanjul 0:47c63ed3af91 8 class PCF8563
irsanjul 0:47c63ed3af91 9 {
irsanjul 0:47c63ed3af91 10 public:
irsanjul 0:47c63ed3af91 11 PCF8563(PinName sda, PinName scl);
irsanjul 0:47c63ed3af91 12
irsanjul 0:47c63ed3af91 13 /** Read current real time from PCF8563
irsanjul 0:47c63ed3af91 14 *
irsanjul 0:47c63ed3af91 15 * @returns
irsanjul 0:47c63ed3af91 16 * current time on success,
irsanjul 0:47c63ed3af91 17 * 0 on error (I2C fail, clock not set)
irsanjul 0:47c63ed3af91 18 */
irsanjul 0:47c63ed3af91 19 time_t now();
irsanjul 0:47c63ed3af91 20
irsanjul 0:47c63ed3af91 21 /** Write current real time to PCF8563
irsanjul 0:47c63ed3af91 22 *
irsanjul 0:47c63ed3af91 23 * @param time Real time to set up
irsanjul 0:47c63ed3af91 24 * @returns
irsanjul 0:47c63ed3af91 25 * true on success,
irsanjul 0:47c63ed3af91 26 * false on error (I2C fail)
irsanjul 0:47c63ed3af91 27 */
irsanjul 0:47c63ed3af91 28 bool set_time(time_t time);
irsanjul 0:47c63ed3af91 29
irsanjul 0:47c63ed3af91 30 /** Write alarm time to PCF8563
irsanjul 0:47c63ed3af91 31 * @param time is set time for alarm
irsanjul 0:47c63ed3af91 32 * @returns
irsanjul 0:47c63ed3af91 33 * true on success,
irsanjul 0:47c63ed3af91 34 * false on error
irsanjul 0:47c63ed3af91 35 */
irsanjul 0:47c63ed3af91 36 bool set_alarm(time_t time);
irsanjul 0:47c63ed3af91 37
irsanjul 0:47c63ed3af91 38 /**
irsanjul 0:47c63ed3af91 39 */
irsanjul 0:47c63ed3af91 40 bool alarmOff();
irsanjul 0:47c63ed3af91 41
irsanjul 0:47c63ed3af91 42 /**
irsanjul 0:47c63ed3af91 43 */
irsanjul 0:47c63ed3af91 44 bool check_alarm();
irsanjul 0:47c63ed3af91 45
irsanjul 0:47c63ed3af91 46 /**
irsanjul 0:47c63ed3af91 47 */
irsanjul 0:47c63ed3af91 48
irsanjul 0:47c63ed3af91 49 private:
irsanjul 0:47c63ed3af91 50 I2C pcf8563_i2c;
irsanjul 0:47c63ed3af91 51
irsanjul 0:47c63ed3af91 52 static int bcdToDecimal(int bcd) {
irsanjul 0:47c63ed3af91 53 return ((bcd & 0xF0) >> 4) * 10 + (bcd & 0x0F);
irsanjul 0:47c63ed3af91 54 }
irsanjul 0:47c63ed3af91 55
irsanjul 0:47c63ed3af91 56 static int decimalToBcd(int dec) {
irsanjul 0:47c63ed3af91 57 return (dec % 10) + ((dec / 10) << 4);
irsanjul 0:47c63ed3af91 58 }
irsanjul 0:47c63ed3af91 59 };
irsanjul 0:47c63ed3af91 60
irsanjul 0:47c63ed3af91 61 #endif