upm  0.3.1
Sensor/Actuator repository for libmraa (v0.7.2)
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 
62  class AT42QT1070 {
63  public:
64 
65  // registers
66  typedef enum { REG_CHIPID = 0,
67  REG_FWVERS = 1,
68 
69  REG_DETSTATUS = 2, // detection status
70  REG_KEYSTATUS = 3, // key status
71 
72  REG_KEYSIG0_H = 4, // key signal
73  REG_KEYSIG0_L = 5,
74  REG_KEYSIG1_H = 6,
75  REG_KEYSIG1_L = 7,
76  REG_KEYSIG2_H = 8,
77  REG_KEYSIG2_L = 9,
78  REG_KEYSIG3_H = 10,
79  REG_KEYSIG3_L = 11,
80  REG_KEYSIG4_H = 12,
81  REG_KEYSIG4_L = 13,
82  REG_KEYSIG5_H = 14,
83  REG_KEYSIG5_L = 15,
84  REG_KEYSIG6_H = 16,
85  REG_KEYSIG6_L = 17,
86 
87  REG_REFDATA0_H = 18, // key reference data
88  REG_REFDATA0_L = 19,
89  REG_REFDATA1_H = 20,
90  REG_REFDATA1_L = 21,
91  REG_REFDATA2_H = 22,
92  REG_REFDATA2_L = 23,
93  REG_REFDATA3_H = 24,
94  REG_REFDATA3_L = 25,
95  REG_REFDATA4_H = 26,
96  REG_REFDATA4_L = 27,
97  REG_REFDATA5_H = 28,
98  REG_REFDATA5_L = 29,
99  REG_REFDATA6_H = 30,
100  REG_REFDATA6_L = 31,
101 
102  REG_NTHR0 = 32, // negative threshold level
103  REG_NTHR1 = 33,
104  REG_NTHR2 = 34,
105  REG_NTHR3 = 35,
106  REG_NTHR4 = 36,
107  REG_NTHR5 = 37,
108  REG_NTHR6 = 38,
109 
110  REG_AVE0 = 39, // key suppression
111  REG_AVE1 = 40,
112  REG_AVE2 = 41,
113  REG_AVE3 = 42,
114  REG_AVE4 = 43,
115  REG_AVE5 = 44,
116  REG_AVE6 = 45,
117 
118  REG_DI0 = 46, // detection integrator
119  REG_DI1 = 47,
120  REG_DI2 = 48,
121  REG_DI3 = 49,
122  REG_DI4 = 50,
123  REG_DI5 = 51,
124  REG_DI6 = 52,
125 
126  REG_GUARD = 53, // FastOutDI/Max Cal/Guard channel
127  REG_LP = 54, // low power
128  REG_MAXON = 55, // max on duration
129  REG_CALIBRATE = 56,
130  REG_RESET = 57
131  } AT42QT1070_REG_T;
132 
133  // detection register bits
134  typedef enum { DET_TOUCH = 0x01,
135  // 0x02-0x20 reserved
136  DET_OVERFLOW = 0x40,
137  DET_CALIBRATE = 0x80
138  } AT42QT1070_DET_T;
139 
140 
147  AT42QT1070(int bus, uint8_t address = AT42QT1070_DEFAULT_I2C_ADDR);
148 
152  ~AT42QT1070();
153 
161  bool writeByte(uint8_t reg, uint8_t byte);
162 
171  bool writeWord(uint8_t reg, uint16_t word);
172 
179  uint8_t readByte(uint8_t reg);
180 
188  uint16_t readWord(uint8_t reg);
189 
195  void updateState();
196 
202  bool isOverflowed() { return m_overflow; };
203 
209  bool isCalibrating() { return m_calibrating; };
210 
216  bool reset();
217 
223  bool calibrate();
224 
230  uint8_t getButtons() { return m_buttonStates; };
231 
232  private:
233  uint8_t m_buttonStates;
234  bool m_calibrating;
235  bool m_overflow;
236 
237  mraa_i2c_context m_i2c;
238  uint8_t m_addr;
239  };
240 }
241 
242 
bool isCalibrating()
Definition: at42qt1070.h:209
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:202
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:230
uint8_t readByte(uint8_t reg)
Definition: at42qt1070.cxx:95
API for the Atmel AT42QT1070 QTouch sensor.
Definition: at42qt1070.h:62