PS_Fgen_FW  4da88f4073c1cc65ea45c3a652a2751e495e50db
Firmware for an Power Supply and Function Generator build from an ATX power supply
Loading...
Searching...
No Matches
XPT2046.h
1// https://github.com/median-dispersion/XPT2046-Driver/blob/main/XPT2046.h
2
3#ifndef _XPT2046_H
4#define _XPT2046_H
5
6#include "Arduino.h"
7#include "SPI.h"
8
9class XPT2046 {
10
11 //-----------------------------------------------------------------------------------------------
12 // Public
13
14 public:
15
16 // Point structure
17 struct Point {
18
19 uint16_t x;
20 uint16_t y;
21
22 };
23
24 // Calibration structure
25 struct Calibration {
26
27 float A;
28 float B;
29 float C;
30 float D;
31 float E;
32 float F;
33 uint16_t width;
34 uint16_t height;
35
36 };
37
38 XPT2046(uint8_t csPin, uint8_t irqPin); // Constructor
39
40 void begin(); // Initialize everything
41 void setSampleCount(uint8_t samples); // Set the number of samples to average over
42 void setRotation(uint8_t rotation); // Set the rotation
43 void setCalibration(Calibration calibration); // Set the calibration matrix
44 void setDebounceTimeout(uint16_t timeoutMilliseconds); // Set the debounce timeout in milliseconds
45 bool touched(); // Returns if the touchscreen is being touched
46 bool released(); // Returns if a touch event has been released
47 Point getTouchPosition(); // Return the touch position
48
49 //-----------------------------------------------------------------------------------------------
50 // Private
51
52 private:
53
54 uint8_t _csPin; // CS pin
55 uint8_t _irqPin; // IRQ pin
56 SPIClass *_spi; // SPI pointer
57 uint8_t _sampleCount; // Current number of samples to average over
58 uint8_t _rotation; // Current rotation
59 Calibration _calibration; // Calibration matrix
60 bool _calibrated; // Flag for checking if calibration was set
61 uint16_t _debounceTimeoutMilliseconds; // Debounce timeout in milliseconds
62 uint64_t _lastTouchMilliseconds; // Last touch event time in milliseconds
63 bool _released; // Flag for if a touch event has been released
64
65 uint16_t _readValue(uint8_t command); // Read a value from the XPT2046 via SPI
66 Point _averageSamples(Point *samples); // Average samples
67 Point _readTouchPosition(); // Read the touch position via SPI
68 Point _rotatePosition(Point position); // Rotate a position
69 Point _calibratePosition(Point position); // Map the position based on the calibration matrix
70 bool _touched(); // Return the touch status and resets the released flag
71
72};
73
74#endif
Containing defines and functions for basic SPI initialization and handling.
Definition XPT2046.h:25
Definition XPT2046.h:17