FT5XX6 Library

This library covers the usage of the FT5x06, FT5x16, FT5x26 and FT5x46 series single-chip capacitive touch panel controllers. They adopt the mutual capacitance approach, which supports true multi-touch capability.
In conjunction with a mutual capacitive touchpanel, the FT5xx6 have user-friendly input functions, which can be applied on many portable devices, such as cellular phones, MIDs, netbook and notebook personal computers.


  Important :

Library Routines

FT5XX6_SetI2CAddress

Prototype

void FT5XX6_SetI2CAddress(unsigned short DeviceAddr) ;

Description

This routine sets the I²C address of the FT5xx6 touch panel.

Parameters
  • DeviceAddr: I²C address of the FT5xx6 touch panel.
Returns

Nothing.

Requires

Nothing.

Example
// Set FT5XX6 device address
FT5XX6_SetI2CAddress(0x38);
Notes
  • None.

FT5XX6_WriteRegister

Prototype

unsigned short FT5XX6_WriteRegister(unsigned short RegisterAddr, unsigned short RegisterValue) ;

Description

This routine writes a value into touch panel register.

Parameters
  • RegisterAddr: The target register address.
  • RegisterValue: The target register value to be written.
Returns
  • FT5XX6_OK: if all operations are OK.
  • other value: if an error occured.
Requires

Nothing.

Example
// write 0xAA into the touch detect threshold register
FT5XX6_WriteRegister(FT5XX6_TOUCH_DET_TH_REG, 0xAA);
Notes
  • None.

FT5XX6_ReadRegister

Prototype

unsigned short FT5XX6_ReadRegister(unsigned short RegisterAddr) ;

Description

This routine reads a value from the touch panel register.

Parameters
  • RegisterAddr: The target register address.
Returns

The value of the read register.

Requires

Nothing.

Example
// read touch detect threshold register
read_value = FT5XX6_ReadRegister(FT5XX6_TOUCH_DET_TH_REG);
Notes
  • None.

FT5XX6_GetRunningState

Prototype

unsigned short FT5XX6_GetRunningState();

Description

This routine reads the running state mode register.

Parameters

None.

Returns
  • 0: configure state.
  • 1: work state.
  • 2: calibration state.
  • 3: factory state.
  • 4: auto-calibration state.
Requires

Nothing.

Example
// get running state
running_state = FT5XX6_GetRunningState();

if (running_state == 0) {
  // configure state
}

if (running_state == 1) {
  // work state
}

if (running_state == 2) {
  // calibration state
}

if (running_state == 3) {
  // factory state
}

if (running_state == 4) {
  // auto-calibration state
}
Notes
  • None.

FT5XX6_IsOperational

Prototype

unsigned short FT5XX6_IsOperational();

Description

This routine checks if the controller is running.

Parameters

None.

Returns
  • FT5XX6_OK: if all operations are OK.
  • FT5XX6_FAILURE: if an error occured.
Requires

Nothing.

Example
// if the controller is running 
if (FT5XX6_IsOperational() == FT5XX6_OK) {
  ...
}	
Notes
  • None.

FT5XX6_SetTouchPanelOrientation

Prototype

void FT5XX6_SetTouchPanelOrientation(unsigned short rotation);

Description

This routine sets touch panel orientation.

Parameters
  • rotation: Rotation angle. Valid values :
    Value Description
    0 0 degree rotation (CCW).
    1 90 degrees rotation (CCW).
    2 180 degrees rotation (CCW).
    3 270 degrees rotation (CCW).
Returns

Nothing.

Requires

Nothing.

Example
// rotate touch panel by 90 degrees (CCW)
FT5XX6_SetTouchPanelOrientation(1);
Notes
  • None.

FT5XX6_GetTouchPanelOrientation

Prototype

unsigned short FT5XX6_GetTouchPanelOrientation();

Description

This routine returns the current touch panel orientation.

Parameters

None.

Returns
  • 0: 0 degree rotation (CCW).
  • 1: 90 degrees rotation (CCW).
  • 2: 180 degrees rotation (CCW).
  • 3: 270 degrees rotation (CCW).
Requires

Nothing.

Example
// get touch panel orientation
tp_orientation = FT5XX6_GetTouchPanelOrientation();

if (orientation == 0) {
  // 0 degree rotation (CCW)
}

if (orientation == 1) {
  // 90 degree rotation (CCW)
}

if (orientation == 2) {
  // 180 degree rotation (CCW)
}

if (orientation == 3) {
  // 270 degree rotation (CCW)
}
Notes
  • None.

FT5XX6_SetSize

Prototype

void FT5XX6_SetSize(unsigned int display_width, unsigned int display_height);

Description

This routine sets the touch panel dimensions (should be same as display dimensions).

Parameters
  • display_width: touch panel width (in pixels).
  • display_height: touch panel height (in pixels).
Returns

Nothing.

Requires

Nothing.

Example
// set touch panel area size to 320x240
FT5XX6_SetSize(320,240);	
Notes
  • None.

FT5XX6_SetSizeAndRotation

Prototype

void FT5XX6_SetSizeAndRotation(unsigned int display_width, unsigned int display_height, unsigned short rotation);

Description

This routine sets the touch panel dimensions (should be same as display dimensions) and rotation.

Parameters
  • display_width: touch panel width (in pixels).
  • display_height: touch panel height (in pixels).
  • rotation: Rotation angle. Valid values :
    Value Description
    0 0 degree rotation (CCW).
    1 90 degrees rotation (CCW).
    2 180 degrees rotation (CCW).
    3 270 degrees rotation (CCW).
Returns

Nothing.

Requires

Nothing.

Example
// set touch panel area size to 320x240 with 180 degrees rotation (CCW)
FT5XX6_SetSizeAndRotation(320,240,2);	
Notes
  • None.

FT5XX6_GetRawCoordinates

Prototype

unsigned short FT5XX6_GetRawCoordinates(unsigned int *x_coordinate, unsigned int *y_coordinate);

Description

This routine gets the raw touch coordinates disregarding the touch panel orientation. By default, the landscape orientation is assumed.

Parameters
  • x_coordinate: pointer to the raw X coordinate of the touch.
  • y_coordinate: pointer to the raw y coordinate of the touch.
Returns
  • FT5XX6_OK: if coordinates are OK.
  • FT5XX6_FAILURE: if an error occured.
Requires

Nothing.

Example
// get raw coordinates 
FT5XX6_GetRawCoordinates(&Xcoord, &Ycoord);
Notes
  • None.

FT5XX6_GetCoordinates

Prototype

unsigned short FT5XX6_GetCoordinates(unsigned int *x_coordinate, unsigned int *y_coordinate);

Description

This routine gets the touch coordinates taking into the account touch panel orientation.

Parameters
  • x_coordinate: pointer to the X coordinate of the touch.
  • y_coordinate: pointer to the y coordinate of the touch.
Returns
  • FT5XX6_OK: if coordinates are OK.
  • FT5XX6_FAILURE: if an error occured.
Requires

Nothing.

Example
// get touch panel coordinates
if (FT5XX6_GetCoordinates(&Xcoord, &Ycoord) == FT5XX6_OK) {
  ...
}
Notes
  • None.

FT5XX6_PressDetect

Prototype

unsigned short FT5XX6_PressDetect();

Description

This routine detects if touch panel has been pressed.

Parameters

None.

Returns
  • 0: if the touch panel hasn't been pressed.
  • 1: if the touch panel has been pressed.
Requires

Nothing.

Example
// if touch panel has been pressed
if (FT5XX6_PressDetect()) {
  ...
}	
Notes
  • None.

FT5XX6_Rotate180

Prototype

void FT5XX6_Rotate180(unsigned short rotate);

Description

This routine rotates touch panel orientation by 0 or 180 degrees.

Parameters
  • rotate: rotating parameter. Valid values :
    Value Description
    FT5XX6_ROTATE_0 Rotate by 0 degrees.
    FT5XX6_ROTATE_180 Rotate by 180 degrees (CCW).
Returns

Nothing.

Requires

Nothing.

Example
// rotate touch panel by 180 degrees
FT5XX6_Rotate180(FT5XX6_ROTATE_0);
Notes
  • None.

FT5XX6_SetController

Prototype

void FT5XX6_SetController(unsigned short FT_type);

Description

This routine sets the specific controller from FT5xx6 family.

Parameters
  • FT_type: desired FT5xx6 controller to be set. Valid values :
    Value Description
    _TC_NONE No controller is set.
    _TC_FT5X06 FT5x06 controller.
    _TC_FT5X16 FT5x16 controller.
    _TC_FT5X26 FT5x26 controller.
    _TC_FT5x46 FT5x46 controller.
Returns

Nothing.

Requires

Nothing.

Example
// set FT5x46 controller
FT5XX6_SetController(_TC_FT5x46);	
Notes
  • None.

FT5XX6_GetController

Prototype

unsigned short FT5XX6_GetController();

Description

This routine gets the specific controller from FT5xx6 family.

Parameters

None.

Returns

Value of controller that is set. Valid values :

  • _TC_NONE: No controller was set.
  • _TC_FT5X06:_TC_FT5x06 controller was set.
  • _TC_FT5X16:_TC_FT5x16 controller was set
  • _TC_FT5X26:_TC_FT5x26 controller was set
  • _TC_FT5x46:_TC_FT5x46 controller was set
Requires

Nothing.

Example
// if the FT5x46 controller was set
if (FT5XX6_GetController() == _TC_FT5x46) {
  ...
}		
Notes
  • None.

FT5XX6_SetDefaultMode

Prototype

void FT5XX6_SetDefaultMode();

Description

This routine sets default values needed by the library - touch panel rotation set to 0 degrees and no touch panel controller selected.

Parameters

None.

Returns

Nothing.

Requires

Nothing.

Example
FT5XX6_SetDefaultMode();
Notes
  • Always call this routine at the beggining of the application code.

FT5XX6_GetGesture

Prototype

unsigned short FT5XX6_GetGesture();

Description

This routine detects the gesture performed on the touch panel.

Parameters

None.

Returns
  • 0: No gesture detected.
  • ft5xx6_gest_move_up: Swipe up gesture detected.
  • ft5xx6_gest_move_left: Swipe left gesture detected.
  • ft5xx6_gest_move_down: Swipe down gesture detected.
  • ft5xx6_gest_move_right: Swipe right gesture detected.
  • FT5XX6_GEST_ZOOM_IN: Zoom in gesture detected.
  • FT5XX6_GEST_ZOOM_OUT: Zoom out gesture detected.
Requires

Nothing.

Example
// get gesture ID
gestureid = FT5XX6_GetGesture();

if (gestureid == ft5xx6_gest_move_up) {
  // if Swipe up gesture detected
}

if (gestureid == ft5xx6_gest_move_left) {
  // if Swipe left gesture detected
}
                        
if (gestureid == ft5xx6_gest_move_down) {
  // if Swipe down gesture detected
}

if (gestureid == ft5xx6_gest_move_right) {
  // if Swipe right gesture detected
}

if (gestureid == FT5XX6_GEST_ZOOM_IN) {
  // if Zoom in gesture detected
}

if (gestureid == FT5XX6_GEST_ZOOM_OUT) {
  // if Zoom out gesture detected
}
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