ArduinoLibs
|
00001 /* 00002 * Copyright (C) 2012 Southern Storm Software, Pty Ltd. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00019 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00020 * DEALINGS IN THE SOFTWARE. 00021 */ 00022 00023 #ifndef DS3232RTC_h 00024 #define DS3232RTC_h 00025 00026 #include "RTC.h" 00027 00028 class I2CMaster; 00029 00030 class DS3232RTC : public RTC { 00031 public: 00032 DS3232RTC(I2CMaster &bus, uint8_t oneHzPin = 255); 00033 00034 bool isRealTime() const { return _isRealTime; } 00035 00036 bool hasUpdates(); 00037 00038 void readTime(RTCTime *value); 00039 void readDate(RTCDate *value); 00040 00041 void writeTime(const RTCTime *value); 00042 void writeDate(const RTCDate *value); 00043 00044 void readAlarm(uint8_t alarmNum, RTCAlarm *value); 00045 void writeAlarm(uint8_t alarmNum, const RTCAlarm *value); 00046 00047 int byteCount() const; 00048 uint8_t readByte(uint8_t offset); 00049 void writeByte(uint8_t offset, uint8_t value); 00050 00051 int readTemperature(); 00052 00053 void enableAlarmInterrupts(); 00054 void disableAlarmInterrupts(); 00055 int firedAlarm(); 00056 00057 void enable32kHzOutput(); 00058 void disable32kHzOutput(); 00059 00060 private: 00061 I2CMaster *_bus; 00062 uint8_t _oneHzPin; 00063 bool prevOneHz; 00064 bool _isRealTime; 00065 bool alarmInterrupts; 00066 00067 void initAlarms(); 00068 00069 uint8_t readRegister(uint8_t reg); 00070 bool writeRegister(uint8_t reg, uint8_t value); 00071 00072 void updateAlarmInterrupts(); 00073 }; 00074 00075 #endif