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:
Sun Aug 10 12:34:32 2014 +0000
Revision:
7:3621025e7949
Parent:
6:984fd3ba519a
Child:
9:3a0ba8364ef2
Removed weekday support as not useful in a generic class.; Renamed members to patch coding style of other modules.

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 7:3621025e7949 30 bool isTwelveHour(); // true if set to a 12hr clock (adjust tm.tm_hour as appropraite)
vtraveller 7:3621025e7949 31 virtual bool mapTime(); // Maps RTC chip to C time.h time system
vtraveller 7:3621025e7949 32 virtual bool getTime(tm & out_sTM); // Get a TM structure directly
vtraveller 7:3621025e7949 33 virtual bool setSquareWaveOutput
vtraveller 0:98b84d9c8c96 34 (
vtraveller 0:98b84d9c8c96 35 bool in_bEnable,
vtraveller 0:98b84d9c8c96 36 ESquareWaveRates in_nRateSelect
vtraveller 0:98b84d9c8c96 37 );
vtraveller 7:3621025e7949 38 virtual bool setTime // Set time time using a TM structure (always starts)
vtraveller 5:d71d6e5a7eee 39 (
vtraveller 5:d71d6e5a7eee 40 const tm & in_sTM,
vtraveller 5:d71d6e5a7eee 41 bool in_bTwelveHour
vtraveller 5:d71d6e5a7eee 42 );
vtraveller 0:98b84d9c8c96 43
vtraveller 0:98b84d9c8c96 44 protected:
vtraveller 7:3621025e7949 45 static int bcdToDecimal(int in_nBCD);
vtraveller 7:3621025e7949 46 static int decimalToBcd(int in_nDecimal);
vtraveller 0:98b84d9c8c96 47 virtual bool read
vtraveller 0:98b84d9c8c96 48 (
vtraveller 0:98b84d9c8c96 49 int in_nAddress,
vtraveller 0:98b84d9c8c96 50 char * out_pBuffer,
vtraveller 0:98b84d9c8c96 51 int in_nLength
vtraveller 0:98b84d9c8c96 52 );
vtraveller 7:3621025e7949 53 virtual bool setRunning(bool in_nEnable);
vtraveller 0:98b84d9c8c96 54 virtual bool write
vtraveller 0:98b84d9c8c96 55 (
vtraveller 0:98b84d9c8c96 56 int in_nAddress,
vtraveller 0:98b84d9c8c96 57 const char * in_pBuffer,
vtraveller 0:98b84d9c8c96 58 int in_nLength
vtraveller 0:98b84d9c8c96 59 );
vtraveller 0:98b84d9c8c96 60
vtraveller 0:98b84d9c8c96 61 private:
vtraveller 5:d71d6e5a7eee 62 static const char * m_aWeekDays[]; // Days of the week
vtraveller 5:d71d6e5a7eee 63 bool m_bTwelveHour;
vtraveller 0:98b84d9c8c96 64 };
vtraveller 0:98b84d9c8c96 65
vtraveller 0:98b84d9c8c96 66 #endif // __RTCLOCK_H__