Realtime clock library for DS1307 and DS3231m
Dependents: vfd_modular_clock_mbed
rtc.h@2:6119507e6713, 2015-08-10 (annotated)
- 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?
User | Revision | Line number | New 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 __RTC_H_ |
Backstrom | 0:1602fdac44ec | 17 | #define __RTC_H_ |
Backstrom | 0:1602fdac44ec | 18 | |
Backstrom | 0:1602fdac44ec | 19 | #include "mbed.h" |
Backstrom | 0:1602fdac44ec | 20 | |
Backstrom | 0:1602fdac44ec | 21 | class RTC { |
Backstrom | 0:1602fdac44ec | 22 | protected: |
Backstrom | 0:1602fdac44ec | 23 | struct tm m_tm; |
Backstrom | 0:1602fdac44ec | 24 | time_t m_time; |
Backstrom | 0:1602fdac44ec | 25 | uint8_t m_tenths; |
Backstrom | 0:1602fdac44ec | 26 | |
Backstrom | 0:1602fdac44ec | 27 | public: |
Backstrom | 0:1602fdac44ec | 28 | RTC(); |
Backstrom | 0:1602fdac44ec | 29 | |
Backstrom | 0:1602fdac44ec | 30 | enum RTC_SQW_FREQ { FREQ_1 = 0, FREQ_1024, FREQ_4096, FREQ_8192 }; |
Backstrom | 0:1602fdac44ec | 31 | |
Backstrom | 0:1602fdac44ec | 32 | virtual void begin(); |
Backstrom | 0:1602fdac44ec | 33 | |
Backstrom | 0:1602fdac44ec | 34 | void tick(); |
Backstrom | 0:1602fdac44ec | 35 | void tenth_tick(); |
Backstrom | 0:1602fdac44ec | 36 | |
Backstrom | 0:1602fdac44ec | 37 | virtual time_t time(); |
Backstrom | 0:1602fdac44ec | 38 | virtual struct tm* getTime(); |
Backstrom | 0:1602fdac44ec | 39 | virtual void getTime(uint8_t* hour, uint8_t* min, uint8_t* sec); |
Backstrom | 0:1602fdac44ec | 40 | |
Backstrom | 0:1602fdac44ec | 41 | virtual void setTime(time_t t); |
Backstrom | 0:1602fdac44ec | 42 | virtual void setTime(uint8_t hour, uint8_t min, uint8_t sec); |
Backstrom | 0:1602fdac44ec | 43 | virtual void setTime(struct tm* tm); |
Backstrom | 0:1602fdac44ec | 44 | |
Backstrom | 0:1602fdac44ec | 45 | virtual void setAlarm(time_t t); |
Backstrom | 0:1602fdac44ec | 46 | virtual void setAlarm(uint8_t hour, uint8_t min, uint8_t sec); |
Backstrom | 0:1602fdac44ec | 47 | virtual struct tm* getAlarm(void); |
Backstrom | 0:1602fdac44ec | 48 | virtual void getAlarm(uint8_t* hour, uint8_t* min, uint8_t* sec); |
Backstrom | 0:1602fdac44ec | 49 | virtual bool checkAlarm(void); |
Backstrom | 0:1602fdac44ec | 50 | |
Backstrom | 0:1602fdac44ec | 51 | virtual void SQWEnable(bool enable); |
Backstrom | 0:1602fdac44ec | 52 | virtual void SQWSetFreq(enum RTC_SQW_FREQ freq); |
Backstrom | 0:1602fdac44ec | 53 | |
Backstrom | 0:1602fdac44ec | 54 | uint8_t getTenths() { return m_tenths; } |
Backstrom | 0:1602fdac44ec | 55 | |
Backstrom | 0:1602fdac44ec | 56 | protected: |
Backstrom | 0:1602fdac44ec | 57 | uint8_t bcd2dec(uint8_t d); |
Backstrom | 0:1602fdac44ec | 58 | uint8_t dec2bcd(uint8_t d); |
Backstrom | 0:1602fdac44ec | 59 | }; |
Backstrom | 0:1602fdac44ec | 60 | |
Backstrom | 0:1602fdac44ec | 61 | #endif // __RTC_H_ |