Realtime clock library for DS1307 and DS3231m

Dependents:   vfd_modular_clock_mbed

Committer:
perjg
Date:
Mon Aug 10 03:16:52 2015 +0000
Revision:
2:6119507e6713
Parent:
0:1602fdac44ec
Fixed compile error

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Backstrom 0:1602fdac44ec 1 /*
Backstrom 0:1602fdac44ec 2 * RTC library - mbed
Backstrom 0:1602fdac44ec 3 * (C) 2011-15 Akafugu Corporation
Backstrom 0:1602fdac44ec 4 *
Backstrom 0:1602fdac44ec 5 * This program is free software; you can redistribute it and/or modify it under the
Backstrom 0:1602fdac44ec 6 * terms of the GNU General Public License as published by the Free Software
Backstrom 0:1602fdac44ec 7 * Foundation; either version 2 of the License, or (at your option) any later
Backstrom 0:1602fdac44ec 8 * version.
Backstrom 0:1602fdac44ec 9 *
Backstrom 0:1602fdac44ec 10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
Backstrom 0:1602fdac44ec 11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
Backstrom 0:1602fdac44ec 12 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
Backstrom 0:1602fdac44ec 13 *
Backstrom 0:1602fdac44ec 14 */
Backstrom 0:1602fdac44ec 15
Backstrom 0:1602fdac44ec 16 #ifndef __DS1307_H_
Backstrom 0:1602fdac44ec 17 #define __DS1307_H_
Backstrom 0:1602fdac44ec 18
Backstrom 0:1602fdac44ec 19 #include "rtc.h"
Backstrom 0:1602fdac44ec 20
Backstrom 0:1602fdac44ec 21 class DS1307 : public RTC {
Backstrom 0:1602fdac44ec 22 public:
Backstrom 0:1602fdac44ec 23 DS1307(I2C& i2c);
Backstrom 0:1602fdac44ec 24
Backstrom 0:1602fdac44ec 25 virtual void begin();
Backstrom 0:1602fdac44ec 26
Backstrom 0:1602fdac44ec 27 virtual time_t time();
Backstrom 0:1602fdac44ec 28 virtual struct tm* getTime();
Backstrom 0:1602fdac44ec 29 virtual void getTime(uint8_t* hour, uint8_t* min, uint8_t* sec);
Backstrom 0:1602fdac44ec 30
Backstrom 0:1602fdac44ec 31 virtual void setTime(time_t t);
Backstrom 0:1602fdac44ec 32 virtual void setTime(struct tm* tm);
Backstrom 0:1602fdac44ec 33 virtual void setTime(uint8_t hour, uint8_t min, uint8_t sec);
Backstrom 0:1602fdac44ec 34
Backstrom 0:1602fdac44ec 35 virtual void setAlarm(time_t t);
Backstrom 0:1602fdac44ec 36 virtual void setAlarm(uint8_t hour, uint8_t min, uint8_t sec);
Backstrom 0:1602fdac44ec 37 virtual struct tm* getAlarm(void);
Backstrom 0:1602fdac44ec 38 virtual void getAlarm(uint8_t* hour, uint8_t* min, uint8_t* sec);
Backstrom 0:1602fdac44ec 39 virtual bool checkAlarm(void);
Backstrom 0:1602fdac44ec 40
Backstrom 0:1602fdac44ec 41 virtual void SQWEnable(bool enable);
Backstrom 0:1602fdac44ec 42 virtual void SQWSetFreq(enum RTC_SQW_FREQ freq);
Backstrom 0:1602fdac44ec 43
Backstrom 0:1602fdac44ec 44 // start/stop clock running
Backstrom 0:1602fdac44ec 45 void runClock(bool run);
Backstrom 0:1602fdac44ec 46 bool isClockRunning(void);
Backstrom 0:1602fdac44ec 47
Backstrom 0:1602fdac44ec 48 private:
Backstrom 0:1602fdac44ec 49 I2C& m_i2c;
Backstrom 0:1602fdac44ec 50
Backstrom 0:1602fdac44ec 51 uint8_t read_byte(uint8_t offset);
Backstrom 0:1602fdac44ec 52 void write_byte(uint8_t b, uint8_t offset);
Backstrom 0:1602fdac44ec 53
Backstrom 0:1602fdac44ec 54 void writeRam(uint8_t addr, uint8_t data);
Backstrom 0:1602fdac44ec 55 uint8_t readRam(uint8_t addr);
Backstrom 0:1602fdac44ec 56 };
Backstrom 0:1602fdac44ec 57
Backstrom 0:1602fdac44ec 58
Backstrom 0:1602fdac44ec 59 #endif // __DS1307_H_