upm  1.3.0
Sensor/Actuator repository for libmraa (v1.7.0)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ds1307.hpp
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 {
72  class DS1307 {
73  public:
79  DS1307(int bus);
80 
86  bool loadTime();
87 
94  bool setTime();
95 
101  mraa::Result enableClock();
102 
109  mraa::Result disableClock();
110 
119  mraa::Result writeBytes(uint8_t reg, uint8_t *buffer, int len);
120 
129  int readBytes(uint8_t reg, uint8_t *buffer, int len);
130 
137  unsigned int bcdToDec(uint8_t val);
138 
145  uint8_t decToBcd(unsigned int val);
146 
147  // These variables store the time data loaded with loadTime(), and
148  // are the source of data when setTime() is called. It is a
149  // good idea to call loadTime() to set up the current values before
150  // calling setTime() to ensure RTC data is consistent
151 
155  unsigned int seconds;
159  unsigned int minutes;
163  unsigned int hours;
167  unsigned int dayOfWeek;
171  unsigned int dayOfMonth;
175  unsigned int month;
179  unsigned int year;
183  bool amPmMode;
187  bool pm;
188 
189  private:
190  mraa::I2c m_i2c;
191  };
192 }
193 
194 
uint8_t decToBcd(unsigned int val)
Definition: ds1307.cxx:190
unsigned int minutes
Definition: ds1307.hpp:159
bool pm
Definition: ds1307.hpp:187
unsigned int dayOfWeek
Definition: ds1307.hpp:167
mraa::Result disableClock()
Definition: ds1307.cxx:175
unsigned int dayOfMonth
Definition: ds1307.hpp:171
unsigned int seconds
Definition: ds1307.hpp:155
API for the DS1307 Real-Time CLock.
Definition: ds1307.hpp:72
unsigned int bcdToDec(uint8_t val)
Definition: ds1307.cxx:196
bool setTime()
Definition: ds1307.cxx:123
int readBytes(uint8_t reg, uint8_t *buffer, int len)
Definition: ds1307.cxx:67
mraa::Result writeBytes(uint8_t reg, uint8_t *buffer, int len)
Definition: ds1307.cxx:49
mraa::Result enableClock()
Definition: ds1307.cxx:162
unsigned int year
Definition: ds1307.hpp:179
DS1307(int bus)
Definition: ds1307.cxx:38
bool loadTime()
Definition: ds1307.cxx:77
bool amPmMode
Definition: ds1307.hpp:183
unsigned int month
Definition: ds1307.hpp:175
unsigned int hours
Definition: ds1307.hpp:163