max44000: Added new sensor module
[contrib/upm.git] / src / max44000 / max44000.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 <maa/i2c.h>
28
29 #define ADDR               0x4A // device address
30
31 // registers address
32 #define ALSDATA_HIGH       0x04 // ambient sensor data high byte
33 #define ALSDATA_LOW        0x05 // ambient sensor data low byte
34 #define PRXDATA            0x15 // proximity sensor data
35 #define MCR                0x01 // Main Configuration Register
36 #define RCR                0x02 // Receive Configuration Register
37 #define TCR                0x03 // Transmit Configuration Register
38
39 #define HIGH               1
40 #define LOW                0
41
42 namespace upm {
43
44 /**
45  * @brief C++ API for MAX44000 chip (Ambient and Infrared Proximity Sensor)
46  *
47  * This file defines the MAX44000 C++ interface for libmax44000
48  *
49  * @snippet proximity.cxx Interesting
50  *
51  * PMOD pins for MAX44000PMB1 board
52  *
53  * ( -= J1 =- )
54  * (1) - NUL
55  * (2) - IRQ
56  * (3) - SCL
57  * (4) - SDA
58  * (5) - GND
59  * (6) - VCC
60  *
61  */
62 class MAX44000 {
63     public:
64         /**
65          * Instanciates a MAX44000 object
66          *
67          * @param bus number of used bus
68          * @param devAddr addres of used i2c device
69          */
70         MAX44000 (int bus, int devAddr);
71
72         /**
73          * MAX44000 object destructor, basicaly it close i2c connection.
74          */
75         ~MAX44000 ();
76
77         /**
78          * Read the proximity value from the chip (based on ambient data).
79          */
80         uint16_t getProximity ();
81         /**
82          * Read the ambient value from the chip (based on ambient data).
83          */
84         uint16_t getAmbient ();
85
86         /**
87          * Return name of the component
88          */
89         std::string name()
90         {
91             return m_name;
92         }
93     private:
94         uint16_t getALSData ();
95         uint16_t getPRXData ();
96
97         uint8_t i2cReadReg_8 (int reg);
98         uint16_t i2cReadReg_16 (int reg);
99         maa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
100
101         std::string m_name;
102
103         int m_maxControlAddr;
104         int m_bus;
105         maa_i2c_context m_i2cMaxControlCtx;
106 };
107
108 }