Adafruit STMPE610 Arduino Library
Adafruit_STMPE610.h
1 
21 #ifndef _ADAFRUIT_STMPE610H_
22 #define _ADAFRUIT_STMPE610H_
23 
24 #include "Arduino.h"
25 
26 #include <SPI.h>
27 #include <Wire.h>
28 
30 #define STMPE_ADDR 0x41
31 
33 #define STMPE_SYS_CTRL1 0x03
34 #define STMPE_SYS_CTRL1_RESET 0x02
35 
37 #define STMPE_SYS_CTRL2 0x04
38 
40 #define STMPE_TSC_CTRL 0x40
41 #define STMPE_TSC_CTRL_EN 0x01
42 #define STMPE_TSC_CTRL_XYZ 0x00
43 #define STMPE_TSC_CTRL_XY 0x02
44 
46 #define STMPE_INT_CTRL 0x09
47 #define STMPE_INT_CTRL_POL_HIGH 0x04
48 #define STMPE_INT_CTRL_POL_LOW 0x00
49 #define STMPE_INT_CTRL_EDGE 0x02
50 #define STMPE_INT_CTRL_LEVEL 0x00
51 #define STMPE_INT_CTRL_ENABLE 0x01
52 #define STMPE_INT_CTRL_DISABLE 0x00
53 
55 #define STMPE_INT_EN 0x0A
56 #define STMPE_INT_EN_TOUCHDET 0x01
57 #define STMPE_INT_EN_FIFOTH 0x02
58 #define STMPE_INT_EN_FIFOOF 0x04
59 #define STMPE_INT_EN_FIFOFULL 0x08
60 #define STMPE_INT_EN_FIFOEMPTY 0x10
61 #define STMPE_INT_EN_ADC 0x40
62 #define STMPE_INT_EN_GPIO 0x80
63 
65 #define STMPE_INT_STA 0x0B
66 #define STMPE_INT_STA_TOUCHDET 0x01
67 
69 #define STMPE_ADC_CTRL1 0x20
70 #define STMPE_ADC_CTRL1_12BIT 0x08
71 #define STMPE_ADC_CTRL1_10BIT 0x00
72 
74 #define STMPE_ADC_CTRL2 0x21
75 #define STMPE_ADC_CTRL2_1_625MHZ 0x00
76 #define STMPE_ADC_CTRL2_3_25MHZ 0x01
77 #define STMPE_ADC_CTRL2_6_5MHZ 0x02
78 
80 #define STMPE_TSC_CFG 0x41
81 #define STMPE_TSC_CFG_1SAMPLE 0x00
82 #define STMPE_TSC_CFG_2SAMPLE 0x40
83 #define STMPE_TSC_CFG_4SAMPLE 0x80
84 #define STMPE_TSC_CFG_8SAMPLE 0xC0
85 #define STMPE_TSC_CFG_DELAY_10US 0x00
86 #define STMPE_TSC_CFG_DELAY_50US 0x08
87 #define STMPE_TSC_CFG_DELAY_100US 0x10
88 #define STMPE_TSC_CFG_DELAY_500US 0x18
89 #define STMPE_TSC_CFG_DELAY_1MS 0x20
90 #define STMPE_TSC_CFG_DELAY_5MS 0x28
91 #define STMPE_TSC_CFG_DELAY_10MS 0x30
92 #define STMPE_TSC_CFG_DELAY_50MS 0x38
93 #define STMPE_TSC_CFG_SETTLE_10US 0x00
94 #define STMPE_TSC_CFG_SETTLE_100US 0x01
95 #define STMPE_TSC_CFG_SETTLE_500US 0x02
96 #define STMPE_TSC_CFG_SETTLE_1MS 0x03
97 #define STMPE_TSC_CFG_SETTLE_5MS 0x04
98 #define STMPE_TSC_CFG_SETTLE_10MS 0x05
99 #define STMPE_TSC_CFG_SETTLE_50MS 0x06
100 #define STMPE_TSC_CFG_SETTLE_100MS 0x07
101 
103 #define STMPE_FIFO_TH 0x4A
104 
106 #define STMPE_FIFO_SIZE 0x4C
107 
109 #define STMPE_FIFO_STA 0x4B
110 #define STMPE_FIFO_STA_RESET 0x01
111 #define STMPE_FIFO_STA_OFLOW 0x80
112 #define STMPE_FIFO_STA_FULL 0x40
113 #define STMPE_FIFO_STA_EMPTY 0x20
114 #define STMPE_FIFO_STA_THTRIG 0x10
115 
117 #define STMPE_TSC_I_DRIVE 0x58
118 #define STMPE_TSC_I_DRIVE_20MA 0x00
119 #define STMPE_TSC_I_DRIVE_50MA 0x01
120 
122 #define STMPE_TSC_DATA_X 0x4D
123 #define STMPE_TSC_DATA_Y 0x4F
124 #define STMPE_TSC_FRACTION_Z 0x56
125 
127 #define STMPE_GPIO_SET_PIN 0x10
128 #define STMPE_GPIO_CLR_PIN 0x11
129 #define STMPE_GPIO_DIR 0x13
130 #define STMPE_GPIO_ALT_FUNCT 0x17
131 
135 class TS_Point {
136 public:
137  TS_Point();
138  TS_Point(int16_t x, int16_t y, int16_t z);
139 
140  bool operator==(TS_Point);
141  bool operator!=(TS_Point);
142 
143  int16_t x;
144  int16_t y;
145  int16_t z;
146 };
147 
153 public:
154  Adafruit_STMPE610(uint8_t cspin, uint8_t mosipin, uint8_t misopin,
155  uint8_t clkpin);
156  Adafruit_STMPE610(uint8_t cspin, SPIClass *theSPI = &SPI);
157  Adafruit_STMPE610(TwoWire *theWire = &Wire);
158 
159  boolean begin(uint8_t i2caddr = STMPE_ADDR);
160 
161  void writeRegister8(uint8_t reg, uint8_t val);
162  uint16_t readRegister16(uint8_t reg);
163  uint8_t readRegister8(uint8_t reg);
164  void readData(uint16_t *x, uint16_t *y, uint8_t *z);
165  uint16_t getVersion();
166  boolean touched();
167  boolean bufferEmpty();
168  uint8_t bufferSize();
169  TS_Point getPoint();
170 
171 private:
172  uint8_t spiIn();
173  void spiOut(uint8_t x);
174 
175  TwoWire *_wire;
176  SPIClass *_spi;
177  int8_t _CS, _MOSI, _MISO, _CLK;
178  uint8_t _i2caddr;
179 
180  int m_spiMode;
181 };
182 
183 #endif
bool operator==(TS_Point)
Equality operator for TS_Point.
Definition: Adafruit_STMPE610.cpp:378
bool operator!=(TS_Point)
Non-equality operator for TS_Point.
Definition: Adafruit_STMPE610.cpp:386
Class that stores state and functions for interacting with STMPE610.
Definition: Adafruit_STMPE610.h:152
int16_t z
Definition: Adafruit_STMPE610.h:145
Class for working with points.
Definition: Adafruit_STMPE610.h:135
int16_t y
Definition: Adafruit_STMPE610.h:144
TS_Point()
TS_Point constructor.
Definition: Adafruit_STMPE610.cpp:357
int16_t x
Definition: Adafruit_STMPE610.h:143