upm  0.3.1
Sensor/Actuator repository for libmraa (v0.7.2)
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.h>
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 
83  ~DS1307();
84 
90  bool loadTime();
91 
98  bool setTime();
99 
105  mraa_result_t enableClock();
106 
113  mraa_result_t disableClock();
114 
123  mraa_result_t writeBytes(uint8_t reg, uint8_t *buffer, unsigned int len);
124 
133  uint8_t readBytes(uint8_t reg, uint8_t *buffer, unsigned int len);
134 
141  unsigned int bcdToDec(uint8_t val);
142 
149  uint8_t decToBcd(unsigned int val);
150 
151  // These variables store the time data loaded with loadTime(), and
152  // will be the source of data when setTime() is called. It is a
153  // good idea call loadTime() to setup the current values before
154  // calling setTime() to ensure RTC data is consistent
155 
159  unsigned int seconds;
163  unsigned int minutes;
167  unsigned int hours;
171  unsigned int dayOfWeek;
175  unsigned int dayOfMonth;
179  unsigned int month;
183  unsigned int year;
187  bool amPmMode;
191  bool pm;
192 
193  private:
194  mraa_i2c_context m_i2c;
195  };
196 }
197 
198 
uint8_t decToBcd(unsigned int val)
Definition: ds1307.cxx:197
unsigned int minutes
Definition: ds1307.h:163
bool pm
Definition: ds1307.h:191
uint8_t readBytes(uint8_t reg, uint8_t *buffer, unsigned int len)
Definition: ds1307.cxx:73
unsigned int dayOfWeek
Definition: ds1307.h:171
mraa_result_t writeBytes(uint8_t reg, uint8_t *buffer, unsigned int len)
Definition: ds1307.cxx:53
~DS1307()
Definition: ds1307.cxx:48
unsigned int dayOfMonth
Definition: ds1307.h:175
mraa_result_t disableClock()
Definition: ds1307.cxx:182
Definition: a110x.h:29
unsigned int seconds
Definition: ds1307.h:159
API for the DS1307 Real Time CLock.
Definition: ds1307.h:71
unsigned int bcdToDec(uint8_t val)
Definition: ds1307.cxx:203
bool setTime()
Definition: ds1307.cxx:130
unsigned int year
Definition: ds1307.h:183
DS1307(int bus)
Definition: ds1307.cxx:37
bool loadTime()
Definition: ds1307.cxx:84
bool amPmMode
Definition: ds1307.h:187
mraa_result_t enableClock()
Definition: ds1307.cxx:169
unsigned int month
Definition: ds1307.h:179
unsigned int hours
Definition: ds1307.h:167