Metal Detector
 
Loading...
Searching...
No Matches
xpt2046.h File Reference

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.
 

Detailed Description

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".

See also
https://www.ti.com/lit/an/slyt277/slyt277.pdf for calibration details.

Macro Definition Documentation

◆ XPT2046_HOR_RES

#define XPT2046_HOR_RES   240

Horizontal resolution of the touch screen

◆ XPT2046_MAX_SAMPLES

#define XPT2046_MAX_SAMPLES   100

Maximum number of samples for touch averaging

◆ XPT2046_VER_RES

#define XPT2046_VER_RES   320

Vertical resolution of the touch screen

Enumeration Type Documentation

◆ XPT2046States_t

Touch states for XPT2046.

Enumerator
XPT2046_PRESSED 

Touch screen is pressed

XPT2046_NOT_PRESSED 

Touch screen is not pressed

Function Documentation

◆ XPT2046_Calibrate()

void XPT2046_Calibrate ( XPT2046Handle_t * handle)

Calibrates the XPT2046 touch controller.

Parameters
handlePointer 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.

Parameters
handlePointer to the XPT2046 handle structure.

◆ XPT2046_CallBack()

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.

Parameters
handlePointer to the XPT2046 handle structure.

◆ XPT2046_GetCalibrationValues()

void XPT2046_GetCalibrationValues ( XPT2046Handle_t * handle,
XPT2046CalibrationValues_t * x_calib,
XPT2046CalibrationValues_t * y_calib )

Gets the calibration values from the XPT2046 touch controller.

Parameters
handlePointer to the XPT2046 handle structure.
x_calibPointer to store the calibration values for the X axis.
y_calibPointer to store the calibration values for the Y axis.

This function retrieves the current calibration values from the XPT2046 touch controller.

Parameters
handlePointer to the XPT2046 handle structure.
x_calibPointer to store the calibration values for the X axis.
y_calibPointer to store the calibration values for the Y axis.

◆ XPT2046_IRQHandler()

void XPT2046_IRQHandler ( XPT2046Handle_t * handle)

Handles touch interrupt for the XPT2046.

Parameters
handlePointer 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.

Parameters
handlePointer to the XPT2046 handle structure.

◆ XPT2046_ReadData()

void XPT2046_ReadData ( XPT2046Handle_t * handle)

Reads calibrated touch coordinates from the XPT2046.

Parameters
handlePointer to the XPT2046 handle structure.

This function reads raw touch data from the XPT2046 and applies calibration coefficients to convert them to screen coordinates.

Parameters
handlePointer to the XPT2046 handle structure.

◆ XPT2046_ReadIRQPin()

uint8_t XPT2046_ReadIRQPin ( void )

Reads the IRQ pin state of the XPT2046.

Return values
uint8_t1 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.

Return values
uint8_t1 if the pin is high, 0 if the pin is low.

◆ XPT2046_ReadRawData()

void XPT2046_ReadRawData ( uint16_t * x,
uint16_t * y )

Reads raw touch data from the XPT2046.

Parameters
xPointer to store the raw x-coordinate.
yPointer 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.

Parameters
xPointer to store the raw x-coordinate.
yPointer to store the raw y-coordinate.

◆ XPT2046_SetCalibrationValues()

void XPT2046_SetCalibrationValues ( XPT2046Handle_t * handle,
XPT2046CalibrationValues_t * x_calib,
XPT2046CalibrationValues_t * y_calib )

Sets the calibration values for the XPT2046 touch controller.

Parameters
handlePointer to the XPT2046 handle structure.
x_calibPointer to the calibration values for the X axis.
y_calibPointer to the calibration values for the Y axis.

This function updates the calibration values for the XPT2046 touch controller.

Parameters
handlePointer to the XPT2046 handle structure.
x_calibPointer to the calibration values for the X axis.
y_calibPointer to the calibration values for the Y axis.

◆ XPT2046_Test()

void XPT2046_Test ( XPT2046Handle_t * handle)

Tests the XPT2046 touch controller.

Parameters
handlePointer 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.

Parameters
handlePointer to the XPT2046 handle structure.