Akafugu / Mbed 2 deprecated vfd_modular_clock_mbed Featured

Dependencies:   DipCortex-EEprom RTC flw mbed

Committer:
Backstrom
Date:
Mon Feb 09 13:40:46 2015 +0000
Revision:
0:f6e68b4ce169
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Backstrom 0:f6e68b4ce169 1 /*
Backstrom 0:f6e68b4ce169 2 * VFD Modular Clock - mbed
Backstrom 0:f6e68b4ce169 3 * (C) 2011-14 Akafugu Corporation
Backstrom 0:f6e68b4ce169 4 *
Backstrom 0:f6e68b4ce169 5 * This program is free software; you can redistribute it and/or modify it under the
Backstrom 0:f6e68b4ce169 6 * terms of the GNU General Public License as published by the Free Software
Backstrom 0:f6e68b4ce169 7 * Foundation; either version 2 of the License, or (at your option) any later
Backstrom 0:f6e68b4ce169 8 * version.
Backstrom 0:f6e68b4ce169 9 *
Backstrom 0:f6e68b4ce169 10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
Backstrom 0:f6e68b4ce169 11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
Backstrom 0:f6e68b4ce169 12 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
Backstrom 0:f6e68b4ce169 13 *
Backstrom 0:f6e68b4ce169 14 */
Backstrom 0:f6e68b4ce169 15
Backstrom 0:f6e68b4ce169 16 #ifndef __DS3231M_H_
Backstrom 0:f6e68b4ce169 17 #define __DS3231M_H_
Backstrom 0:f6e68b4ce169 18
Backstrom 0:f6e68b4ce169 19 #include "rtc.h"
Backstrom 0:f6e68b4ce169 20
Backstrom 0:f6e68b4ce169 21 // leap year calulator expects year argument as years offset from 1970
Backstrom 0:f6e68b4ce169 22 #define LEAP_YEAR(Y) ( ((1970+Y)>0) && !((1970+Y)%4) && ( ((1970+Y)%100) || !((1970+Y)%400) ) )
Backstrom 0:f6e68b4ce169 23 /* Useful Constants */
Backstrom 0:f6e68b4ce169 24 #define SECS_PER_MIN (60UL)
Backstrom 0:f6e68b4ce169 25 #define SECS_PER_HOUR (3600UL)
Backstrom 0:f6e68b4ce169 26 #define SECS_PER_DAY (SECS_PER_HOUR * 24UL)
Backstrom 0:f6e68b4ce169 27 #define DAYS_PER_WEEK (7UL)
Backstrom 0:f6e68b4ce169 28 #define SECS_PER_WEEK (SECS_PER_DAY * DAYS_PER_WEEK)
Backstrom 0:f6e68b4ce169 29 #define SECS_PER_YEAR (SECS_PER_WEEK * 52UL)
Backstrom 0:f6e68b4ce169 30 #define SECS_YR_2000 (946684800UL) // the time at the start of y2k
Backstrom 0:f6e68b4ce169 31
Backstrom 0:f6e68b4ce169 32 class DS3231M : public RTC {
Backstrom 0:f6e68b4ce169 33 public:
Backstrom 0:f6e68b4ce169 34 DS3231M(I2C& i2c);
Backstrom 0:f6e68b4ce169 35
Backstrom 0:f6e68b4ce169 36 virtual void begin();
Backstrom 0:f6e68b4ce169 37
Backstrom 0:f6e68b4ce169 38 virtual time_t time();
Backstrom 0:f6e68b4ce169 39 virtual struct tm* getTime();
Backstrom 0:f6e68b4ce169 40 virtual void getTime(uint8_t* hour, uint8_t* min, uint8_t* sec);
Backstrom 0:f6e68b4ce169 41
Backstrom 0:f6e68b4ce169 42 virtual void setTime(time_t t);
Backstrom 0:f6e68b4ce169 43 virtual void setTime(struct tm* tm);
Backstrom 0:f6e68b4ce169 44 virtual void setTime(uint8_t hour, uint8_t min, uint8_t sec);
Backstrom 0:f6e68b4ce169 45
Backstrom 0:f6e68b4ce169 46 virtual void setAlarm(time_t t);
Backstrom 0:f6e68b4ce169 47 virtual void setAlarm(uint8_t hour, uint8_t min, uint8_t sec);
Backstrom 0:f6e68b4ce169 48 virtual struct tm* getAlarm(void);
Backstrom 0:f6e68b4ce169 49 virtual void getAlarm(uint8_t* hour, uint8_t* min, uint8_t* sec);
Backstrom 0:f6e68b4ce169 50 virtual bool checkAlarm(void);
Backstrom 0:f6e68b4ce169 51
Backstrom 0:f6e68b4ce169 52 virtual void SQWEnable(bool enable);
Backstrom 0:f6e68b4ce169 53 virtual void SQWSetFreq(enum RTC_SQW_FREQ freq);
Backstrom 0:f6e68b4ce169 54 virtual void Osc32kHzEnable(bool enable);
Backstrom 0:f6e68b4ce169 55
Backstrom 0:f6e68b4ce169 56 private:
Backstrom 0:f6e68b4ce169 57 I2C& m_i2c;
Backstrom 0:f6e68b4ce169 58
Backstrom 0:f6e68b4ce169 59 bool m_is_ds1307;
Backstrom 0:f6e68b4ce169 60 bool m_is_ds3231;
Backstrom 0:f6e68b4ce169 61
Backstrom 0:f6e68b4ce169 62 uint8_t read_byte(uint8_t offset);
Backstrom 0:f6e68b4ce169 63 void write_byte(uint8_t b, uint8_t offset);
Backstrom 0:f6e68b4ce169 64 void write_addr(uint8_t addr);
Backstrom 0:f6e68b4ce169 65 };
Backstrom 0:f6e68b4ce169 66
Backstrom 0:f6e68b4ce169 67 #endif // __DS3231M_H_