UI_Lib  a1366e08a59cc549a65fa26081e6409aa12f26d5
This is a user interface library for graphical LCDs. It offers many different controls and indicators that can be nested depending on the element types.
Loading...
Searching...
No Matches
XPT2046.h
1// https://github.com/median-dispersion/XPT2046-Driver
2// Release 1.0.2 (Commit ID: 7607973)
3
4#ifndef _XPT2046_H
5#define _XPT2046_H
6
7#include "Arduino.h"
8#include "SPI.h"
9
10class XPT2046 {
11
12 //-----------------------------------------------------------------------------------------------
13 // Public
14
15 public:
16
17 // Point structure
18 struct Point {
19
20 uint16_t x;
21 uint16_t y;
22
23 };
24
25 // Calibration structure
26 struct Calibration {
27
28 float A;
29 float B;
30 float C;
31 float D;
32 float E;
33 float F;
34 uint16_t width;
35 uint16_t height;
36 uint8_t rotation;
37
38 };
39
40 XPT2046(uint8_t csPin, uint8_t irqPin); // Constructor
41
42 void begin(); // Initialize everything
43 void setRotation(uint8_t rotation); // Set the rotation
44 void setCalibration(Calibration calibration); // Set the calibration matrix
45 void setSampleCount(uint8_t samples); // Set the number of samples to average over
46 void setDebounceTimeout(uint16_t timeoutMilliseconds); // Set the debounce timeout in milliseconds
47 void setTouchPressure(float pressure); // Set the touch pressure
48 void setDeadZone(uint16_t deadZone); // Set the touch area dead zone
49 void setPowerDown(bool state); // Set power-down state after SPI transaction
50 bool touched(); // Returns if the touchscreen is being touched
51 bool released(); // Returns if a touch event has been released
52 Point getTouchPosition(); // Return the touch position
53 bool valid(Point position); // Check if a given position is a valid touch position
54
55 //-----------------------------------------------------------------------------------------------
56 // Private
57
58 private:
59
60 uint8_t _csPin; // CS pin
61 uint8_t _irqPin; // IRQ pin
62 uint8_t _rotation; // Current rotation
63 Calibration _calibration; // Calibration matrix
64 bool _calibrated; // Flag for checking if calibration was set
65 uint8_t _sampleCount; // Current number of samples to average over
66 uint16_t _debounceTimeoutMilliseconds; // Debounce timeout in milliseconds
67 uint64_t _lastTouchMilliseconds; // Last touch event time in milliseconds
68 float _touchPressure; // Touch pressure
69 uint16_t _deadZone; // Dead zone
70 bool _powerDown; // Flag for setting power-down state after SPI communication
71 bool _touched; // Flag for if touch area is being touched
72 bool _released; // Flag for if a touch event has been released
73 bool _updated; // Flag for checking update status of touched and released flags
74 bool _transferEnabled; // Flag for if SPI data transfer is enabled
75
76 bool _enableDataTransfer(); // Enable SPI data transfer
77 bool _disableDataTransfer(); // Disable SPI data transfer
78 uint16_t _readData(uint8_t data); // Read data via SPI
79 bool _getTouchStatus(); // Return the touch status
80 void _updateTouchStatus(); // Update the touched and released flags
81 Point _readTouchPosition(); // Read the touch position via SPI
82 Point _averageTouchSamples(Point *samples); // Average touch samples
83 Point _rotateTouchPosition(Point position); // Rotate the raw touch position
84 Point _mapTouchPosition(Point position); // Map the position based on the calibration matrix
85 Point _rotateMappedPosition(Point position); // Rotate the mapped position
86
87};
88
89#endif
Definition XPT2046.h:10
Definition XPT2046.h:26
Definition XPT2046.h:18