forked from alex-code/GT911
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGT911.h
77 lines (65 loc) · 1.8 KB
/
GT911.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef GT911_H
#define GT911_H
#include <Arduino.h>
#include <Wire.h>
#include "GT911_Structs.h"
// 0x28/0x29 (0x14 7bit)
#define GT911_I2C_ADDR_28 0x14
// 0xBA/0xBB (0x5D 7bit)
#define GT911_I2C_ADDR_BA 0x5D
#define GT911_MAX_CONTACTS 5
#define GT911_REG_CFG 0x8047
#define GT911_REG_CHECKSUM 0x80FF
#define GT911_REG_DATA 0x8140
#define GT911_REG_ID 0x8140
#define GT911_REG_COORD_ADDR 0x814E
enum : uint8_t {
GT911_MODE_INTERRUPT,
GT911_MODE_POLLING
};
class GT911 {
public:
enum class Rotate {
_0,
_90,
_180,
_270,
};
private:
TwoWire *_wire;
int8_t _intPin;
int8_t _rstPin;
uint8_t _addr;
uint32_t _clk;
bool _configLoaded = false;
GTConfig _config;
GTInfo _info;
GTPoint _points[GT911_MAX_CONTACTS];
Rotate _rotation = Rotate::_0;
//void reset();
void i2cStart(uint16_t reg);
bool write(uint16_t reg, uint8_t data);
uint8_t read(uint16_t reg);
bool writeBytes(uint16_t reg, uint8_t *data, uint16_t size);
bool readBytes(uint16_t reg, uint8_t *data, uint16_t size);
uint8_t calcChecksum(uint8_t *buf, uint8_t len);
uint8_t readChecksum();
int8_t readTouches();
bool readTouchPoints();
public:
GT911(TwoWire *twi = &Wire);
void init(int8_t intPin = -1, int8_t rstPin = -1, uint8_t addr = GT911_I2C_ADDR_BA,uint32_t clk = 400000);
//bool begin(int8_t intPin = -1, int8_t rstPin = -1, uint8_t addr = GT911_I2C_ADDR_BA,
// uint32_t clk = 400000);
bool begin();
bool productID(uint8_t *buf, uint8_t len);
GTConfig* readConfig();
bool writeConfig();
GTInfo* readInfo();
uint8_t touched(uint8_t mode = GT911_MODE_INTERRUPT);
GTPoint getPoint(uint8_t num);
GTPoint *getPoints();
void setRotation(Rotate rotation);
void reset();
};
#endif