Simple RTC class based on DS1307. Emphasis on simple. Allows you to run at 100k or 400k Hz (for newer DS1307 capable devices). MapTime() allows you to set the time() service to the same as the RTC. Uses struct tm throughout so you can use traditional time functions for manipulation.

Dependents:   AdaFruit_RGBLCD

Committer:
vtraveller
Date:
Sat Aug 09 17:02:40 2014 +0000
Revision:
5:d71d6e5a7eee
Parent:
0:98b84d9c8c96
Child:
6:984fd3ba519a
Added 12/24 hour am/pm support.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vtraveller 0:98b84d9c8c96 1 #ifndef __RTCLOCK_H__
vtraveller 0:98b84d9c8c96 2 #define __RTCLOCK_H__
vtraveller 0:98b84d9c8c96 3
vtraveller 0:98b84d9c8c96 4 #include <time.h>
vtraveller 0:98b84d9c8c96 5
vtraveller 0:98b84d9c8c96 6 typedef I2C RTclock_parent;
vtraveller 0:98b84d9c8c96 7
vtraveller 0:98b84d9c8c96 8 class RTclock
vtraveller 0:98b84d9c8c96 9 : public RTclock_parent
vtraveller 0:98b84d9c8c96 10 {
vtraveller 0:98b84d9c8c96 11 public:
vtraveller 0:98b84d9c8c96 12 // Frequency values for the square wave output
vtraveller 0:98b84d9c8c96 13 enum ESquareWaveRates
vtraveller 0:98b84d9c8c96 14 {
vtraveller 0:98b84d9c8c96 15 eSWR_1Hz = 0,
vtraveller 0:98b84d9c8c96 16 eSWR_4kHz = 1,
vtraveller 0:98b84d9c8c96 17 eSWR_8kHz = 2,
vtraveller 0:98b84d9c8c96 18 eSWR_32Hz = 3
vtraveller 0:98b84d9c8c96 19 };
vtraveller 0:98b84d9c8c96 20
vtraveller 0:98b84d9c8c96 21 public:
vtraveller 0:98b84d9c8c96 22 RTclock
vtraveller 0:98b84d9c8c96 23 (
vtraveller 0:98b84d9c8c96 24 PinName in_nSDA,
vtraveller 0:98b84d9c8c96 25 PinName in_nSCL,
vtraveller 0:98b84d9c8c96 26 bool in_bHiSpeed = false
vtraveller 0:98b84d9c8c96 27 );
vtraveller 0:98b84d9c8c96 28 virtual ~RTclock();
vtraveller 0:98b84d9c8c96 29
vtraveller 5:d71d6e5a7eee 30 bool IsTwelveHour(); // true if set to a 12hr clock
vtraveller 5:d71d6e5a7eee 31 virtual bool MapTime(); // Maps RTC chip to C time.h time system
vtraveller 0:98b84d9c8c96 32 virtual bool GetTime(tm & out_sTM); // Get a TM structure directly
vtraveller 0:98b84d9c8c96 33 static const char * GetWeekday(int in_nWeekDay);
vtraveller 0:98b84d9c8c96 34 virtual bool SetSquareWaveOutput
vtraveller 0:98b84d9c8c96 35 (
vtraveller 0:98b84d9c8c96 36 bool in_bEnable,
vtraveller 0:98b84d9c8c96 37 ESquareWaveRates in_nRateSelect
vtraveller 0:98b84d9c8c96 38 );
vtraveller 5:d71d6e5a7eee 39 virtual bool SetTime // Set time time using a TM structure (always starts)
vtraveller 5:d71d6e5a7eee 40 (
vtraveller 5:d71d6e5a7eee 41 const tm & in_sTM,
vtraveller 5:d71d6e5a7eee 42 bool in_bTwelveHour
vtraveller 5:d71d6e5a7eee 43 );
vtraveller 0:98b84d9c8c96 44
vtraveller 0:98b84d9c8c96 45 protected:
vtraveller 0:98b84d9c8c96 46 static int BcdToDecimal(int in_nBCD);
vtraveller 0:98b84d9c8c96 47 static int DecimalToBcd(int in_nDecimal);
vtraveller 0:98b84d9c8c96 48 virtual bool read
vtraveller 0:98b84d9c8c96 49 (
vtraveller 0:98b84d9c8c96 50 int in_nAddress,
vtraveller 0:98b84d9c8c96 51 char * out_pBuffer,
vtraveller 0:98b84d9c8c96 52 int in_nLength
vtraveller 0:98b84d9c8c96 53 );
vtraveller 0:98b84d9c8c96 54 virtual bool SetRunning(bool in_nEnable);
vtraveller 0:98b84d9c8c96 55 virtual bool write
vtraveller 0:98b84d9c8c96 56 (
vtraveller 0:98b84d9c8c96 57 int in_nAddress,
vtraveller 0:98b84d9c8c96 58 const char * in_pBuffer,
vtraveller 0:98b84d9c8c96 59 int in_nLength
vtraveller 0:98b84d9c8c96 60 );
vtraveller 0:98b84d9c8c96 61
vtraveller 0:98b84d9c8c96 62 private:
vtraveller 5:d71d6e5a7eee 63 static const char * m_aWeekDays[]; // Days of the week
vtraveller 5:d71d6e5a7eee 64 bool m_bTwelveHour;
vtraveller 0:98b84d9c8c96 65 };
vtraveller 0:98b84d9c8c96 66
vtraveller 0:98b84d9c8c96 67 #endif // __RTCLOCK_H__