Header file for XPT2046 touch screen controller driver. More...
#include "main.h"
Go to the source code of this file.
Data Structures | |
struct | XPT2046CalibrationValues_t |
Calibration values for XPT2046. More... | |
struct | XPT2046Coordinates_t |
Coordinates structure for XPT2046. More... | |
struct | XPT2046Handle_t |
Handle structure for XPT2046. More... | |
Macros | |
#define | XPT2046_HOR_RES 240 |
#define | XPT2046_VER_RES 320 |
#define | XPT2046_MAX_SAMPLES 100 |
Enumerations | |
enum | XPT2046States_t { XPT2046_PRESSED , XPT2046_NOT_PRESSED } |
Touch states for XPT2046. More... | |
Functions | |
uint8_t | XPT2046_ReadIRQPin (void) |
Reads the IRQ pin state of the XPT2046. | |
void | XPT2046_ReadRawData (uint16_t *x, uint16_t *y) |
Reads raw touch data from the XPT2046. | |
void | XPT2046_ReadData (XPT2046Handle_t *handle) |
Reads calibrated touch coordinates from the XPT2046. | |
void | XPT2046_IRQHandler (XPT2046Handle_t *handle) |
Handles touch interrupt for the XPT2046. | |
void | XPT2046_CallBack (XPT2046Handle_t *handle) __attribute__((weak)) |
Callback function for the XPT2046 touch controller. | |
void | XPT2046_Calibrate (XPT2046Handle_t *handle) |
Calibrates the XPT2046 touch controller. | |
void | XPT2046_SetCalibrationValues (XPT2046Handle_t *handle, XPT2046CalibrationValues_t *x_calib, XPT2046CalibrationValues_t *y_calib) |
Sets the calibration values for the XPT2046 touch controller. | |
void | XPT2046_GetCalibrationValues (XPT2046Handle_t *handle, XPT2046CalibrationValues_t *x_calib, XPT2046CalibrationValues_t *y_calib) |
Gets the calibration values from the XPT2046 touch controller. | |
void | XPT2046_Test (XPT2046Handle_t *handle) |
Tests the XPT2046 touch controller. | |
Header file for XPT2046 touch screen controller driver.
This file contains the declarations for the XPT2046 touch screen controller driver. It includes function prototypes for reading touch coordinates, handling interrupts, calibrating the touch screen, and performing basic tests. The calibration procedure is implemented based on Texas Instruments' application note SLYT277 "Calibration in touch-screen systems".
#define XPT2046_HOR_RES 240 |
Horizontal resolution of the touch screen
#define XPT2046_MAX_SAMPLES 100 |
Maximum number of samples for touch averaging
#define XPT2046_VER_RES 320 |
Vertical resolution of the touch screen
enum XPT2046States_t |
void XPT2046_Calibrate | ( | XPT2046Handle_t * | handle | ) |
Calibrates the XPT2046 touch controller.
handle | Pointer to the XPT2046 handle structure. |
This function performs calibration of the XPT2046 touch controller using three reference points on the screen. The calibration process is based on the method described in the TI application note SLYT277.
handle | Pointer to the XPT2046 handle structure. |
void XPT2046_CallBack | ( | XPT2046Handle_t * | handle | ) |
Callback function for the XPT2046 touch controller.
This is a weak function that can be overridden by the user. It is called when a touch event is processed.
handle | Pointer to the XPT2046 handle structure. |
void XPT2046_GetCalibrationValues | ( | XPT2046Handle_t * | handle, |
XPT2046CalibrationValues_t * | x_calib, | ||
XPT2046CalibrationValues_t * | y_calib ) |
Gets the calibration values from the XPT2046 touch controller.
handle | Pointer to the XPT2046 handle structure. |
x_calib | Pointer to store the calibration values for the X axis. |
y_calib | Pointer to store the calibration values for the Y axis. |
This function retrieves the current calibration values from the XPT2046 touch controller.
handle | Pointer to the XPT2046 handle structure. |
x_calib | Pointer to store the calibration values for the X axis. |
y_calib | Pointer to store the calibration values for the Y axis. |
void XPT2046_IRQHandler | ( | XPT2046Handle_t * | handle | ) |
Handles touch interrupt for the XPT2046.
handle | Pointer to the XPT2046 handle structure. |
This function is the interrupt handler for the XPT2046 touch controller. It reads the touch data and updates the touch state.
handle | Pointer to the XPT2046 handle structure. |
void XPT2046_ReadData | ( | XPT2046Handle_t * | handle | ) |
Reads calibrated touch coordinates from the XPT2046.
handle | Pointer to the XPT2046 handle structure. |
This function reads raw touch data from the XPT2046 and applies calibration coefficients to convert them to screen coordinates.
handle | Pointer to the XPT2046 handle structure. |
uint8_t XPT2046_ReadIRQPin | ( | void | ) |
Reads the IRQ pin state of the XPT2046.
uint8_t | 1 if the pin is high, 0 if the pin is low. |
This function reads the state of the IRQ pin of the XPT2046 touch controller.
uint8_t | 1 if the pin is high, 0 if the pin is low. |
void XPT2046_ReadRawData | ( | uint16_t * | x, |
uint16_t * | y ) |
Reads raw touch data from the XPT2046.
x | Pointer to store the raw x-coordinate. |
y | Pointer to store the raw y-coordinate. |
This function reads the raw touch data from the XPT2046 touch controller by sending appropriate commands via SPI and processing the received data. It implements a simple averaging filter to improve the touch data quality.
x | Pointer to store the raw x-coordinate. |
y | Pointer to store the raw y-coordinate. |
void XPT2046_SetCalibrationValues | ( | XPT2046Handle_t * | handle, |
XPT2046CalibrationValues_t * | x_calib, | ||
XPT2046CalibrationValues_t * | y_calib ) |
Sets the calibration values for the XPT2046 touch controller.
handle | Pointer to the XPT2046 handle structure. |
x_calib | Pointer to the calibration values for the X axis. |
y_calib | Pointer to the calibration values for the Y axis. |
This function updates the calibration values for the XPT2046 touch controller.
handle | Pointer to the XPT2046 handle structure. |
x_calib | Pointer to the calibration values for the X axis. |
y_calib | Pointer to the calibration values for the Y axis. |
void XPT2046_Test | ( | XPT2046Handle_t * | handle | ) |
Tests the XPT2046 touch controller.
handle | Pointer to the XPT2046 handle structure. |
This function tests the XPT2046 touch controller by reading the touch coordinates and drawing a target on the screen at the touch location.
handle | Pointer to the XPT2046 handle structure. |