upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
at42qt1070.hpp
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 {
64 {
65  public:
66  // registers
67  typedef enum {
68  REG_CHIPID = 0,
69  REG_FWVERS = 1,
70 
71  REG_DETSTATUS = 2, // detection status
72  REG_KEYSTATUS = 3, // key status
73 
74  REG_KEYSIG0_H = 4, // key signal
75  REG_KEYSIG0_L = 5,
76  REG_KEYSIG1_H = 6,
77  REG_KEYSIG1_L = 7,
78  REG_KEYSIG2_H = 8,
79  REG_KEYSIG2_L = 9,
80  REG_KEYSIG3_H = 10,
81  REG_KEYSIG3_L = 11,
82  REG_KEYSIG4_H = 12,
83  REG_KEYSIG4_L = 13,
84  REG_KEYSIG5_H = 14,
85  REG_KEYSIG5_L = 15,
86  REG_KEYSIG6_H = 16,
87  REG_KEYSIG6_L = 17,
88 
89  REG_REFDATA0_H = 18, // key reference data
90  REG_REFDATA0_L = 19,
91  REG_REFDATA1_H = 20,
92  REG_REFDATA1_L = 21,
93  REG_REFDATA2_H = 22,
94  REG_REFDATA2_L = 23,
95  REG_REFDATA3_H = 24,
96  REG_REFDATA3_L = 25,
97  REG_REFDATA4_H = 26,
98  REG_REFDATA4_L = 27,
99  REG_REFDATA5_H = 28,
100  REG_REFDATA5_L = 29,
101  REG_REFDATA6_H = 30,
102  REG_REFDATA6_L = 31,
103 
104  REG_NTHR0 = 32, // negative threshold level
105  REG_NTHR1 = 33,
106  REG_NTHR2 = 34,
107  REG_NTHR3 = 35,
108  REG_NTHR4 = 36,
109  REG_NTHR5 = 37,
110  REG_NTHR6 = 38,
111 
112  REG_AVE0 = 39, // key suppression
113  REG_AVE1 = 40,
114  REG_AVE2 = 41,
115  REG_AVE3 = 42,
116  REG_AVE4 = 43,
117  REG_AVE5 = 44,
118  REG_AVE6 = 45,
119 
120  REG_DI0 = 46, // detection integrator
121  REG_DI1 = 47,
122  REG_DI2 = 48,
123  REG_DI3 = 49,
124  REG_DI4 = 50,
125  REG_DI5 = 51,
126  REG_DI6 = 52,
127 
128  REG_GUARD = 53, // FastOutDI/Max Cal/Guard channel
129  REG_LP = 54, // low power
130  REG_MAXON = 55, // max on duration
131  REG_CALIBRATE = 56,
132  REG_RESET = 57
133  } AT42QT1070_REG_T;
134 
135  // detection register bits
136  typedef enum {
137  DET_TOUCH = 0x01,
138  // 0x02-0x20 reserved
139  DET_OVERFLOW = 0x40,
140  DET_CALIBRATE = 0x80
141  } AT42QT1070_DET_T;
142 
143 
150  AT42QT1070(int bus, uint8_t address = AT42QT1070_DEFAULT_I2C_ADDR);
151 
155  ~AT42QT1070();
156 
164  bool writeByte(uint8_t reg, uint8_t byte);
165 
174  bool writeWord(uint8_t reg, uint16_t word);
175 
182  uint8_t readByte(uint8_t reg);
183 
191  uint16_t readWord(uint8_t reg);
192 
193 
199  uint8_t readChipID(void);
200 
206  void updateState();
207 
208 
214  uint8_t getLPMode(void);
215 
222  uint8_t setLPMode(uint8_t mode);
223 
224 
231  uint8_t getAVE(uint8_t key);
232 
240  uint8_t setAVE(uint8_t key, uint8_t ave);
241 
248  uint8_t getAKSGroup(uint8_t key);
249 
257  uint8_t setAKSGroup(uint8_t key, uint8_t group);
258 
264  bool
266  {
267  return m_overflow;
268  };
269 
275  bool
277  {
278  return m_calibrating;
279  };
280 
286  bool reset();
287 
293  bool calibrate();
294 
300  uint8_t
302  {
303  return m_buttonStates;
304  };
305 
306  private:
307  uint8_t m_buttonStates;
308  bool m_calibrating;
309  bool m_overflow;
310 
311  mraa_i2c_context m_i2c;
312  uint8_t m_addr;
313 };
314 }
bool isCalibrating()
Definition: at42qt1070.hpp:276
uint8_t getAVE(uint8_t key)
Definition: at42qt1070.cxx:167
uint8_t setLPMode(uint8_t mode)
Definition: at42qt1070.cxx:159
bool writeByte(uint8_t reg, uint8_t byte)
Definition: at42qt1070.cxx:71
AT42QT1070(int bus, uint8_t address=AT42QT1070_DEFAULT_I2C_ADDR)
Definition: at42qt1070.cxx:37
bool reset()
Definition: at42qt1070.cxx:249
bool calibrate()
Definition: at42qt1070.cxx:256
bool isOverflowed()
Definition: at42qt1070.hpp:265
uint16_t readWord(uint8_t reg)
Definition: at42qt1070.cxx:109
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
void updateState()
Definition: at42qt1070.cxx:125
~AT42QT1070()
Definition: at42qt1070.cxx:65
uint8_t readChipID(void)
Definition: at42qt1070.cxx:119
bool writeWord(uint8_t reg, uint16_t word)
Definition: at42qt1070.cxx:85
uint8_t getLPMode(void)
Definition: at42qt1070.cxx:153
uint8_t getButtons()
Definition: at42qt1070.hpp:301
uint8_t setAKSGroup(uint8_t key, uint8_t group)
Definition: at42qt1070.cxx:227
uint8_t readByte(uint8_t reg)
Definition: at42qt1070.cxx:99
API for the Atmel AT42QT1070 QTouch Sensor.
Definition: at42qt1070.hpp:63
uint8_t setAVE(uint8_t key, uint8_t ave)
Definition: at42qt1070.cxx:182
uint8_t getAKSGroup(uint8_t key)
Definition: at42qt1070.cxx:212