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