upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
maxds3231m.h
1 /*
2  * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3  * Copyright (c) 2014 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <string>
27 #include <mraa/i2c.hpp>
28 
29 #define ADDR 0x68 // device address
30 
31 // timekeeping registers
32 #define TIME_CAL_ADDR 0x00
33 #define ALARM1_ADDR 0x07
34 #define ALARM2_ADDR 0x0B
35 #define CONTROL_ADDR 0x0E
36 #define STATUS_ADDR 0x0F
37 #define AGING_OFFSET_ADDR 0x10
38 #define TEMPERATURE_ADDR 0x11
39 
40 // control register bits
41 #define A1IE 0x1
42 #define A2IE 0x2
43 #define INTCN 0x4
44 
45 // status register bits
46 #define A1F 0x1
47 #define A2F 0x2
48 #define OSF 0x80
49 
50 #define HIGH 1
51 #define LOW 0
52 
53 namespace upm {
54 
55 struct Time3231 {
56  uint8_t second;
57  uint8_t minute;
58  uint8_t hour;
59  uint8_t day;
60  uint8_t month;
61  int16_t year;
62  uint8_t weekDay;
63 };
64 
84 class MAXDS3231M {
85  public:
92  MAXDS3231M (int bus=0, int devAddr=0x68);
93 
99  void setDate (Time3231 &time);
100 
106  bool getDate (Time3231 &time);
107 
111  uint16_t getTemperature ();
112 
116  std::string name()
117  {
118  return m_name;
119  }
120  private:
121  std::string m_name;
122 
123  int m_i2cAddr;
124  int m_bus;
125  mraa::I2c m_i2Ctx;
126 
127  uint16_t i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer);
128  mraa::Result i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer);
129  uint8_t DECtoBSD (uint8_t data);
130  uint8_t BCDtoDEC (uint8_t data);
131 };
132 
133 }
MAXDS3231M(int bus=0, int devAddr=0x68)
Definition: maxds3231m.cxx:34
void setDate(Time3231 &time)
Definition: maxds3231m.cxx:48
bool getDate(Time3231 &time)
Definition: maxds3231m.cxx:55
uint16_t getTemperature()
Definition: maxds3231m.cxx:77
std::string name()
Definition: maxds3231m.h:116
Definition: maxds3231m.h:55
API for the MAXDS3231M I2C Real-Time Clock.
Definition: maxds3231m.h:84