TSC2006 Touch Panel Library

The mikroC PRO for ARM provides a library for working with TSC2006 Touch Panel controller.

External dependencies of TSC2006 Touch Panel Library

The following variables must be defined in all projects using Touch Panel TSC2006 Library: Description : Example :
extern sfr sbit TSC2006_CS; Chip Select line. sbit TSC2006_CS at GPIO_PORTB_DATA4_bit;
extern sfr sbit TSC2006_RST; Reset line. sbit DriveB at TSC2006_RST;
extern sfr sbit TSC2006_CS_Direction; Direction of the Chip Select pin. sbit TSC2006_CS_Direction at GPIO_PORTB_DIR4_bit;
extern sfr sbit TSC2006_RST_Direction; Direction of the Reset pin. sbit TSC2006_RST_Direction at GPIO_PORTE_DIR0_bit;

Library Routines

TSC2006_Init

Prototype

uint8_t TSC2006_Init();

Description

Initialize the TSC2006 touch panel controller.

Parameters

None.

Returns
  • -1 - if an error occurred.
  • 0 - if successful.
Requires

External dependencies of the library from the top of the page must be defined before using this function.

The appropriate hardware SPI module must be previously initialized.
See the SPIx_Init and SPIx_Init_Advanced routines.

Example
sbit TSC2006_CS at GPIO_PORTB_DATA4_bit;
sbit TSC2006_RST at GPIO_PORTE_DATA0_bit;
sbit TSC2006_CS_Direction at GPIO_PORTB_DIR4_bit
sbit TSC2006_RST_Direction at GPIO_PORTE_DIR0_bit;
...
SPI1_Init();
TSC2006_Init(;)
Notes

None.

TSC2006_Reset

Prototype

void TSC2006_Reset();

Description

This function performs hardware reset of the TSC2006 touch panel controller.

Parameters

None.

Returns

Nothing.

Requires

Nothing.

Example
TSC2006_Reset();
Notes

None.

TSC2006_CalibratePoint

Prototype

void TSC2006_CalibratePoint(uint8_t dispCorner);

Description

This function performs calibration of a corner point displayed on the screen.

Parameters
  • dispCorner: corner points. Valid values :
    Value Description
    _TSC2006_DISP_0_0 Corner point at coordinate (0,0).
    _TSC2006_DISP_XMAX_0 Corner point at coordinate (XMAX,0).
    _TSC2006_DISP_XMAX_YMAX Corner point at coordinate (XMAX,YMAX).
    _TSC2006_DISP_0_YMAX Corner point at coordinate (0,YMAX).
Returns

Nothing.

Requires

Nothing.

Example
TSC2006_CalibratePoint(_TSC2006_DISP_0_0);
Notes

All four corner points should be calibrated, starting from the (0,0) up to the (0,YMAX).

TSC2006_PressDetect

Prototype

uint8_t TSC2006_PressDetect();

Description

Detects if there is a change on the X and Y axis.

Parameters

None.

Returns
  • 1 - if touch panel is pressed.
  • 0 - otherwise.
Requires

Nothing.

Example
if (TSC2006_PressDetect() = 1) then
  ...
Notes

None.

TSC2006_SetCalibrationConsts

Prototype

void TSC2006_SetCalibrationConsts(uint16_t xMin, uint16_t xMax, uint16_t yMin, uint16_t yMax);

Description

Sets calibration constants.

Parameters
  • xMin: minimal calibration value on the X axis.
  • xMax: maximal calibration value on the X axis.
  • yMin: minimal calibration value on the Y axis.
  • yMax: maximal calibration value on the Y axis.
Returns

Nothing.

Requires

Nothing.

Example
TSC2006_SetCalibrationConsts(148, 3590, 519, 3370);    // Set calibration constants
Notes

None.

TSC2006_GetCalibrationConsts

Prototype

void TSC2006_GetCalibrationConsts(uint16_t *xMin, uint16_t *xMax, uint16_t *yMin, uint16_t *yMax);

Description

Gets calibration constants after calibration is done and stores them in xMin, xMax, yMin and yMax parameters.

Parameters
  • xMin: minimal calibration value on the X axis.
  • xMax: maximal calibration value on the X axis.
  • yMin: minimal calibration value on the Y axis.
  • yMax: maximal calibration value on the Y axis.
Returns

Nothing.

Requires

Nothing.

Example
TSC2006_GetCalibrationConsts(&x_min, &y_min, &x_max, &y_max);    // Get calibration constants
Notes

None.

TSC2006_GetCoordinates

Prototype

char TSC2006_GetCoordinates(uint16_t *xCoord, uint16_t *yCoord);

Description

Get touch panel coordinates and store them in xCoord and yCoord parameters.

Parameters
  • xCoord: x coordinate of the place of touch.
  • yCoord: y coordinate of the place of touch.
Returns
  • 0 - if reading is within display dimension range.
  • 1 - if reading is out of display dimension range.
Requires

Nothing.

Example
if (TSC2006_GetCoordinates(&xCoord, &yCoord) == 0) {
 ...
}
Notes

None.

TSC2006_SetDisplaySize

Prototype

void TSC2006_SetDisplaySize(uint16_t width, uint16_t height);

Description

Sets the display size.

Parameters
  • width: width of the display.
  • height: height of the display.
Returns

Nothing.

Requires

Nothing.

Example
TSC2006_SetDisplaySize(320, 240);
Notes

None.

TSC2006_SetDefaultMode

Prototype

void TSC2006_SetDefaultMode();

Description

Sets the touch panel in default mode (threshold set to 6000, 0 degrees rotation).

Parameters

None.

Returns

Nothing.

Requires

Nothing.

Example
TSC2006_SetDefaultMode();
Notes

None.

TSC2006_SetTouchPressureThreshold

Prototype

void TSC2006_SetTouchPressureThreshold(uint16_t threshold);

Description

Sets the touch panel pressure threshold value.

Parameters
  • threshold: threshold value.
Returns

Nothing.

Requires

Nothing.

Example
TSC2006_SetTouchPressureThreshold(6000);
Notes

None.

TSC2006_Rotate180

Prototype

void TSC2006_Rotate180();

Description

Rotates the touch panel by 180 degrees.

Parameters

None.

Returns

Nothing.

Requires

Nothing.

Example
TSC2006_Rotate180();
Notes

None.

TSC2006_SetTPRotation

Prototype

void TSC2006_SetTPRotation(uint8_t rotation);

Description

Rotates the touch panel clockwise by a given parameter angle.

Parameters
  • rotation: angle by which the touch panel shall be rotated. Valid values :
    Value Description
    _TSC2006_ROTATE_0 0 degrees rotation clockwise.
    _TSC2006_ROTATE_90 90 degrees rotation clockwise.
    _TSC2006_ROTATE_180 180 degrees rotation clockwise.
    _TSC2006_ROTATE_270 270 degrees rotation clockwise.
Returns

Nothing.

Requires

Nothing.

Example
TSC2006_SetTPRotation(_TSC2006_ROTATE_180);
Notes

None.

TSC2006_GetTPRotation

Prototype

uint8_t TSC2006_GetTPRotation();

Description

Gets the angle by which the touch panel is rotated.

Parameters

None.

Returns
  • 0 - touch panel is rotated by 0 degrees clockwise.
  • 1 - touch panel is rotated by 90 degrees clockwise..
  • 2 - touch panel is rotated by 180 degrees clockwise.
  • 3 - touch panel is rotated by 270 degrees clockwise.
Requires

Nothing.

Example
rotation_angle = TSC2006_GetTPRotation();
Notes

None.

TSC2006_ReadCB0

Prototype

uint16_t TSC2006_ReadCB0(uint8_t cb0);

Description

Reads the value stored in touch panel controller register using the control byte 0 command format (read data registers and non-conversion-related controls).

Parameters
  • cb0: control byte 0 command.
Returns

Value stored in register.

Requires

Nothing.

Example
read_value = TSC2006_ReadCB0(cb0);
Notes

None.

TSC2006_WriteCB0

Prototype

void TSC2006_WriteCB0(uint8_t cb0, uint16_t value);

Description

Stores the value in touch panel controller register using the control byte 0 command format (write data registers and non-conversion-related controls).

Parameters
  • cb0: control byte 0 command
  • value: value to be stored.
Returns

Nothing.

Requires

Nothing.

Example
TSC2006_WriteCB0(cb0, value);
Notes

None.

TSC2006_WriteCB1

Prototype

void TSC2006_WriteCB1(uint8_t cb1);

Description

Stores the value in touch panel controller register using the control byte 1 command format (start conversion and channel select and conversion-related configuration).

Parameters
  • cb1: control byte 1 command
  • value: value to be stored.
Returns

Nothing.

Requires

Nothing.

Example
TSC2006_WriteCB1(cb1, value);
Notes

None.

Copyright (c) 2002-2019 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code