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.
Diff: RTclock.cpp
- Revision:
- 10:e5eabd3a1ca6
- Parent:
- 9:3a0ba8364ef2
- Child:
- 11:49b987f6ae26
--- a/RTclock.cpp Sat Aug 30 15:55:28 2014 +0000 +++ b/RTclock.cpp Tue Sep 02 07:12:09 2014 +0000 @@ -1,13 +1,11 @@ #include "mbed.h" #include "RTclock.h" -RTclock::RTclock(PinName in_nSDA, PinName in_nSCL, EClockType in_eClockType, bool in_bHiSpeed) - : RTclock_parent(in_nSDA,in_nSCL) - , m_bTwelveHour(false) +RTclock::RTclock(I2C & in_cI2C, EClockType in_eClockType) + : m_bTwelveHour(false) + , m_cI2C(in_cI2C) , m_eClockType(in_eClockType) { - // Frequency depends on chip - most are 100KHz - frequency(in_bHiSpeed ? 400000 : 100000); } RTclock::~RTclock() @@ -78,8 +76,8 @@ { char aBuffer[2] = { (char)in_nAddress, 0 }; - if (0 != RTclock_parent::write(0xd0, aBuffer, 1)) return false; - if (0 != RTclock_parent::read(0xd0, out_pBuffer, in_nLength)) return false; + if (0 != m_cI2C.write(0xd0, aBuffer, 1)) return false; + if (0 != m_cI2C.read(0xd0, out_pBuffer, in_nLength)) return false; return true; } @@ -200,5 +198,5 @@ for (size_t i = 0 ; i < in_nLength; i++) aBuffer[i + 1] = in_pBuffer[i]; - return RTclock_parent::write(0xd0, aBuffer, in_nLength + 1); + return m_cI2C.write(0xd0, aBuffer, in_nLength + 1); }