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 Jan 24 15:59:29 2015 +0000
Revision:
17:bdc15c054ac1
Parent:
8:2192f2809f59
Fixed bug where tm struct used a month range of 0-11 and the DS3231 uses a range 1-12.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vtraveller 8:2192f2809f59 1 #include "mbed.h"
vtraveller 8:2192f2809f59 2 #include "time_helper.h"
vtraveller 8:2192f2809f59 3
vtraveller 8:2192f2809f59 4 void GetTime(tm & out_sTM)
vtraveller 8:2192f2809f59 5 {
vtraveller 8:2192f2809f59 6 time_t nTime = time(0);
vtraveller 8:2192f2809f59 7 tm * pTM = ::localtime(&nTime);
vtraveller 8:2192f2809f59 8 ::memcpy(&out_sTM,pTM,sizeof(out_sTM));
vtraveller 8:2192f2809f59 9 }
vtraveller 8:2192f2809f59 10
vtraveller 8:2192f2809f59 11 void SetTime(const tm & in_sTM)
vtraveller 8:2192f2809f59 12 {
vtraveller 8:2192f2809f59 13 tm sTM = { 0 };
vtraveller 8:2192f2809f59 14 memcpy(&sTM,&in_sTM,sizeof(sTM));
vtraveller 8:2192f2809f59 15
vtraveller 8:2192f2809f59 16 time_t nTime = mktime(&sTM);
vtraveller 8:2192f2809f59 17 set_time(nTime);
vtraveller 8:2192f2809f59 18 }