forked from kpishere/fbcp-ili9341
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXPT2046.h
108 lines (82 loc) · 2.51 KB
/
XPT2046.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* @file XPT2046.h
* @date 19.02.2016
* @author Markus Sattler
*
* Copyright (c) 2015 Markus Sattler. All rights reserved.
* This file is part of the XPT2046 driver for Arduino.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef XPT2046_H_
#define XPT2046_H_
#include <stdint.h>
#include <fcntl.h> //Needed for SPI port
#include <sys/ioctl.h> //Needed for SPI port
#include <unistd.h> //Needed for SPI port
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <cstring>
#include <sys/types.h>
#include <sys/stat.h>
#include "spi_user.h"
class XPT2046 {
public:
XPT2046();
~XPT2046();
int SpiWriteAndRead(unsigned char *data, int length);
void read_touchscreen(bool interruptEnable);
void setRotation(uint8_t m);
void setCalibration(uint16_t minX, uint16_t minY, uint16_t maxX, uint16_t maxY);
void read(uint16_t * oX, uint16_t * oY, uint16_t * oZ);
void readRaw(uint16_t * oX, uint16_t * oY, uint16_t * oZ);
static void printBits(size_t const size, void const * const ptr)
{
unsigned char *b = (unsigned char*) ptr;
unsigned char byte;
int i, j;
for (i = size - 1; i >= 0; i--)
{
for (j = 7; j >= 0; j--)
{
byte = (b[i] >> j) & 1;
printf("%u", byte);
}
printf(" ");
}
puts("");
}
protected:
uint16_t _width;
uint16_t _height;
uint16_t _rotation;
uint16_t _minX;
uint16_t _minY;
uint16_t _maxX;
uint16_t _maxY;
uint16_t _maxValue;
int _lastX;
int _lastY;
int fd;
uint16_t _minChange;
uint32_t spi_cs ;
uint32_t z_average ;
const char * tcfifo ;
int interruptpoll ;
};
#endif /* XPT2046_H_ */