upm  1.6.0
Sensor/Actuator repository for libmraa (v1.9.0)
maxds3231m.hpp
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 
85 class MAXDS3231M {
86  public:
93  MAXDS3231M (int bus=0, int devAddr=0x68);
94 
100  void setDate (Time3231 &time);
101 
107  bool getDate (Time3231 &time);
108 
112  uint16_t getTemperature ();
113 
117  std::string name()
118  {
119  return m_name;
120  }
121  private:
122  std::string m_name;
123 
124  int m_i2cAddr;
125  int m_bus;
126  mraa::I2c m_i2Ctx;
127 
128  uint16_t i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer);
129  mraa::Result i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer);
130  uint8_t DECtoBSD (uint8_t data);
131  uint8_t BCDtoDEC (uint8_t data);
132 };
133 
134 }
C++ API for the kxtj3 driver.
Definition: a110x.hpp:29
std::string name()
Definition: maxds3231m.hpp:117
Definition: maxds3231m.hpp:55
API for the MAXDS3231M I2C Real-Time Clock.
Definition: maxds3231m.hpp:85