upm  0.1.8
Sensor/Actuator repository for libmraa (v0.4.5)
 All Data Structures Files Functions Variables Macros 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.h>
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 
71 class MAXDS3231M {
72  public:
79  MAXDS3231M (int bus, int devAddr);
80 
84  ~MAXDS3231M ();
85 
91  void setDate (Time3231 &time);
92 
98  bool getDate (Time3231 &time);
99 
103  uint16_t getTemperature ();
104 
108  std::string name()
109  {
110  return m_name;
111  }
112  private:
113  std::string m_name;
114 
115  int m_i2cAddr;
116  int m_bus;
117  mraa_i2c_context m_i2Ctx;
118 
119  uint16_t i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer);
120  mraa_result_t i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer);
121  uint8_t DECtoBSD (uint8_t data);
122  uint8_t BCDtoDEC (uint8_t data);
123 };
124 
125 }
void setDate(Time3231 &time)
Definition: maxds3231m.cxx:59
bool getDate(Time3231 &time)
Definition: maxds3231m.cxx:66
uint16_t getTemperature()
Definition: maxds3231m.cxx:88
std::string name()
Definition: maxds3231m.h:108
Definition: maxds3231m.h:55
MAXDS3231M(int bus, int devAddr)
Definition: maxds3231m.cxx:40
~MAXDS3231M()
Definition: maxds3231m.cxx:54
C++ API for MAXDS3231M chip (Ambient and Infrared Proximity Sensor)
Definition: maxds3231m.h:71