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

Revision:
0:98b84d9c8c96
Child:
5:d71d6e5a7eee
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RTclock.h	Sat Aug 09 09:18:38 2014 +0000
@@ -0,0 +1,61 @@
+#ifndef __RTCLOCK_H__
+#define __RTCLOCK_H__
+
+#include <time.h>
+
+typedef I2C RTclock_parent;
+
+class RTclock
+    : public RTclock_parent
+{
+public:
+    // Frequency values for the square wave output
+    enum ESquareWaveRates
+    {
+        eSWR_1Hz = 0,
+        eSWR_4kHz = 1,
+        eSWR_8kHz = 2,
+        eSWR_32Hz = 3
+    };
+
+public:
+                            RTclock
+                            (
+                                PinName             in_nSDA,
+                                PinName             in_nSCL,
+                                bool                in_bHiSpeed = false
+                            );
+    virtual                 ~RTclock();
+
+    virtual bool            MapTime();                     // Maps RTC chip to C time.h time system
+    virtual bool            GetTime(tm & out_sTM);          // Get a TM structure directly
+    static  const char *    GetWeekday(int in_nWeekDay);
+    virtual bool            SetSquareWaveOutput
+                            (
+                                bool                in_bEnable,
+                                ESquareWaveRates    in_nRateSelect
+                            );
+    virtual bool            SetTime(const tm & in_sTM);    // Set time time using a TM structure (always starts)
+
+protected:
+    static int              BcdToDecimal(int in_nBCD);
+    static int              DecimalToBcd(int in_nDecimal);
+    virtual bool            read
+                            (
+                                int                 in_nAddress,
+                                char *              out_pBuffer,
+                                int                 in_nLength
+                            );
+    virtual bool            SetRunning(bool in_nEnable);
+    virtual bool            write
+                            (
+                                int                 in_nAddress,
+                                const char *        in_pBuffer,
+                                int                 in_nLength
+                            );
+
+private:
+    static const char *     m_aWeekDays[];              // Days of the week
+};
+
+#endif // __RTCLOCK_H__