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

RTclock.h

Committer:
vtraveller
Date:
2014-08-10
Revision:
7:3621025e7949
Parent:
6:984fd3ba519a
Child:
9:3a0ba8364ef2

File content as of revision 7:3621025e7949:

#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();

            bool            isTwelveHour();                 // true if set to a 12hr clock (adjust tm.tm_hour as appropraite)
    virtual bool            mapTime();                      // Maps RTC chip to C time.h time system
    virtual bool            getTime(tm & out_sTM);          // Get a TM structure directly
    virtual bool            setSquareWaveOutput
                            (
                                bool                in_bEnable,
                                ESquareWaveRates    in_nRateSelect
                            );
    virtual bool            setTime                         // Set time time using a TM structure (always starts)
                            (
                                const tm &          in_sTM,
                                bool                in_bTwelveHour
                            );

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
            bool            m_bTwelveHour;
};

#endif // __RTCLOCK_H__