Implementation file for XPT2046 touch screen controller driver. More...
Macros | |
#define | CMD_X_READ 0b10010000 |
#define | CMD_Y_READ 0b11010000 |
Functions | |
static uint8_t | transmit_receive_byte (uint8_t data) |
Transmits and receives a byte via SPI. | |
static void | manage_cs (uint8_t state) |
Manages the chip select (CS) pin state. | |
static void | draw_target (uint32_t x, uint32_t y, uint16_t color) |
Draws a target on the screen at the specified coordinates. | |
uint8_t | XPT2046_ReadIRQPin (void) |
Reads the IRQ pin state of the XPT2046. | |
void | XPT2046_ReadData (XPT2046Handle_t *handle) |
Reads calibrated touch coordinates from the XPT2046. | |
void | XPT2046_ReadRawData (uint16_t *x, uint16_t *y) |
Reads raw touch data from the XPT2046. | |
void | XPT2046_IRQHandler (XPT2046Handle_t *handle) |
Handles touch interrupt for the XPT2046. | |
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. | |
__attribute__ ((weak)) | |
Weak callback function for the XPT2046 touch controller. | |
Variables | |
SPI_HandleTypeDef * | xpt2046_spi |
static const float | XPT2046_VER_COEF = (float)XPT2046_VER_RES / 4096 |
static const float | XPT2046_HOR_COEF = (float)XPT2046_HOR_RES / 4096 |
Implementation file for XPT2046 touch screen controller driver.
This file contains the implementation of the XPT2046 touch screen controller driver. It includes functions 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 CMD_X_READ 0b10010000 |
Command for reading X position
#define CMD_Y_READ 0b11010000 |
Command for reading Y position
__attribute__ | ( | (weak) | ) |
Weak callback function for the XPT2046 touch controller.
This function is a weakly defined callback that can be overridden by the user. It is called when a touch event is processed.
handle | Pointer to the XPT2046 handle structure. |
|
static |
Draws a target on the screen at the specified coordinates.
This function draws a small target at the specified (x, y) coordinates on the screen with the given color.
x | X coordinate of the target. |
y | Y coordinate of the target. |
color | Color of the target. |
|
static |
Manages the chip select (CS) pin state.
This function sets the state of the CS pin to either low (active) or high (inactive).
state | Desired state of the CS pin (GPIO_PIN_RESET or GPIO_PIN_SET). |
|
static |
Transmits and receives a byte via SPI.
This function transmits a byte of data via SPI and receives a byte of data in response.
data | Byte of data to be transmitted. |
uint8_t | Byte of data received in response. |
void XPT2046_Calibrate | ( | XPT2046Handle_t * | handle | ) |
Calibrates the XPT2046 touch controller.
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_GetCalibrationValues | ( | XPT2046Handle_t * | handle, |
XPT2046CalibrationValues_t * | x_calib, | ||
XPT2046CalibrationValues_t * | y_calib ) |
Gets the calibration values from the XPT2046 touch controller.
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.
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.
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.
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.
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.
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.
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. |
|
extern |
SPI handle for the XPT2046 touch screen