upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
ds1307.h
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2014 Intel Corporation.
4  *
5  * Adapted from Seeed Studio library:
6  * https://github.com/Seeed-Studio/RTC_DS1307
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27 #pragma once
28 
29 #include <string>
30 #include <mraa/i2c.hpp>
31 
32 #define DS1307_I2C_BUS 0
33 #define DS1307_I2C_ADDR 0x68
34 
35 // Days of the week
36 #define DS1307_DAY_MON 1
37 #define DS1307_DAY_TUE 2
38 #define DS1307_DAY_WED 3
39 #define DS1307_DAY_THU 4
40 #define DS1307_DAY_FRI 5
41 #define DS1307_DAY_SAT 6
42 #define DS1307_DAY_SUN 7
43 
44 namespace upm {
71  class DS1307 {
72  public:
78  DS1307(int bus);
79 
85  bool loadTime();
86 
93  bool setTime();
94 
100  mraa::Result enableClock();
101 
108  mraa::Result disableClock();
109 
118  mraa::Result writeBytes(uint8_t reg, uint8_t *buffer, int len);
119 
128  int readBytes(uint8_t reg, uint8_t *buffer, int len);
129 
136  unsigned int bcdToDec(uint8_t val);
137 
144  uint8_t decToBcd(unsigned int val);
145 
146  // These variables store the time data loaded with loadTime(), and
147  // are the source of data when setTime() is called. It is a
148  // good idea to call loadTime() to set up the current values before
149  // calling setTime() to ensure RTC data is consistent
150 
154  unsigned int seconds;
158  unsigned int minutes;
162  unsigned int hours;
166  unsigned int dayOfWeek;
170  unsigned int dayOfMonth;
174  unsigned int month;
178  unsigned int year;
182  bool amPmMode;
186  bool pm;
187 
188  private:
189  mraa::I2c m_i2c;
190  };
191 }
192 
193 
uint8_t decToBcd(unsigned int val)
Definition: ds1307.cxx:203
unsigned int minutes
Definition: ds1307.h:158
bool pm
Definition: ds1307.h:186
unsigned int dayOfWeek
Definition: ds1307.h:166
mraa::Result disableClock()
Definition: ds1307.cxx:188
unsigned int dayOfMonth
Definition: ds1307.h:170
unsigned int seconds
Definition: ds1307.h:154
API for the DS1307 Real-Time CLock.
Definition: ds1307.h:71
unsigned int bcdToDec(uint8_t val)
Definition: ds1307.cxx:209
bool setTime()
Definition: ds1307.cxx:136
int readBytes(uint8_t reg, uint8_t *buffer, int len)
Definition: ds1307.cxx:74
mraa::Result writeBytes(uint8_t reg, uint8_t *buffer, int len)
Definition: ds1307.cxx:49
mraa::Result enableClock()
Definition: ds1307.cxx:175
unsigned int year
Definition: ds1307.h:178
DS1307(int bus)
Definition: ds1307.cxx:38
bool loadTime()
Definition: ds1307.cxx:90
bool amPmMode
Definition: ds1307.h:182
unsigned int month
Definition: ds1307.h:174
unsigned int hours
Definition: ds1307.h:162