upm  0.1.9
Sensor/Actuator repository for libmraa (v0.6.1)
at42qt1070.h
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2015 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 <stdint.h>
27 #include <sys/time.h>
28 
29 #include <string>
30 #include <mraa/i2c.h>
31 
32 #define AT42QT1070_I2C_BUS 0
33 #define AT42QT1070_DEFAULT_I2C_ADDR 0x1b
34 
35 namespace upm {
36 
60  class AT42QT1070 {
61  public:
62 
63  // registers
64  typedef enum { REG_CHIPID = 0,
65  REG_FWVERS = 1,
66 
67  REG_DETSTATUS = 2, // detection status
68  REG_KEYSTATUS = 3, // key status
69 
70  REG_KEYSIG0_H = 4, // key signal
71  REG_KEYSIG0_L = 5,
72  REG_KEYSIG1_H = 6,
73  REG_KEYSIG1_L = 7,
74  REG_KEYSIG2_H = 8,
75  REG_KEYSIG2_L = 9,
76  REG_KEYSIG3_H = 10,
77  REG_KEYSIG3_L = 11,
78  REG_KEYSIG4_H = 12,
79  REG_KEYSIG4_L = 13,
80  REG_KEYSIG5_H = 14,
81  REG_KEYSIG5_L = 15,
82  REG_KEYSIG6_H = 16,
83  REG_KEYSIG6_L = 17,
84 
85  REG_REFDATA0_H = 18, // key reference data
86  REG_REFDATA0_L = 19,
87  REG_REFDATA1_H = 20,
88  REG_REFDATA1_L = 21,
89  REG_REFDATA2_H = 22,
90  REG_REFDATA2_L = 23,
91  REG_REFDATA3_H = 24,
92  REG_REFDATA3_L = 25,
93  REG_REFDATA4_H = 26,
94  REG_REFDATA4_L = 27,
95  REG_REFDATA5_H = 28,
96  REG_REFDATA5_L = 29,
97  REG_REFDATA6_H = 30,
98  REG_REFDATA6_L = 31,
99 
100  REG_NTHR0 = 32, // negative threshold level
101  REG_NTHR1 = 33,
102  REG_NTHR2 = 34,
103  REG_NTHR3 = 35,
104  REG_NTHR4 = 36,
105  REG_NTHR5 = 37,
106  REG_NTHR6 = 38,
107 
108  REG_AVE0 = 39, // key suppression
109  REG_AVE1 = 40,
110  REG_AVE2 = 41,
111  REG_AVE3 = 42,
112  REG_AVE4 = 43,
113  REG_AVE5 = 44,
114  REG_AVE6 = 45,
115 
116  REG_DI0 = 46, // detection integrator
117  REG_DI1 = 47,
118  REG_DI2 = 48,
119  REG_DI3 = 49,
120  REG_DI4 = 50,
121  REG_DI5 = 51,
122  REG_DI6 = 52,
123 
124  REG_GUARD = 53, // FastOutDI/Max Cal/Guard channel
125  REG_LP = 54, // low power
126  REG_MAXON = 55, // max on duration
127  REG_CALIBRATE = 56,
128  REG_RESET = 57
129  } AT42QT1070_REG_T;
130 
131  // detection register bits
132  typedef enum { DET_TOUCH = 0x01,
133  // 0x02-0x20 reserved
134  DET_OVERFLOW = 0x40,
135  DET_CALIBRATE = 0x80
136  } AT42QT1070_DET_T;
137 
138 
145  AT42QT1070(int bus, uint8_t address = AT42QT1070_DEFAULT_I2C_ADDR);
146 
150  ~AT42QT1070();
151 
159  bool writeByte(uint8_t reg, uint8_t byte);
160 
169  bool writeWord(uint8_t reg, uint16_t word);
170 
177  uint8_t readByte(uint8_t reg);
178 
186  uint16_t readWord(uint8_t reg);
187 
193  void updateState();
194 
200  bool isOverflowed() { return m_overflow; };
201 
207  bool isCalibrating() { return m_calibrating; };
208 
214  bool reset();
215 
221  bool calibrate();
222 
228  uint8_t getButtons() { return m_buttonStates; };
229 
230  private:
231  uint8_t m_buttonStates;
232  bool m_calibrating;
233  bool m_overflow;
234 
235  mraa_i2c_context m_i2c;
236  uint8_t m_addr;
237  };
238 }
239 
240 
bool isCalibrating()
Definition: at42qt1070.h:207
bool writeByte(uint8_t reg, uint8_t byte)
Definition: at42qt1070.cxx:67
AT42QT1070(int bus, uint8_t address=AT42QT1070_DEFAULT_I2C_ADDR)
Definition: at42qt1070.cxx:36
bool reset()
Definition: at42qt1070.cxx:134
bool calibrate()
Definition: at42qt1070.cxx:140
bool isOverflowed()
Definition: at42qt1070.h:200
uint16_t readWord(uint8_t reg)
Definition: at42qt1070.cxx:100
Definition: a110x.h:29
void updateState()
Definition: at42qt1070.cxx:105
~AT42QT1070()
Definition: at42qt1070.cxx:62
bool writeWord(uint8_t reg, uint16_t word)
Definition: at42qt1070.cxx:81
uint8_t getButtons()
Definition: at42qt1070.h:228
uint8_t readByte(uint8_t reg)
Definition: at42qt1070.cxx:95
C++ API for the Atmel AT42QT1070 QTouch sensor.
Definition: at42qt1070.h:60