STMPE610 Library
The STMPE610 is a GPIO (general purpose input/output) port expander able to interface a main digital ASIC via the two-line bidirectional bus (I2C). A 4-wire touchscreen controller is built into the STMPE610. The touchscreen controller is enhanced with a movement tracking algorithm to avoid excessive data, 128 x 32 bit buffer and a programmable active window feature. This library will focus on Touchscreen controlling part od the IC.
- STMPE610 library routines use I²C so it is necessary to initialize I²C module of the MCU before working with STMPE610 controller.
Library Routines
- STMPE610_WriteReg
- STMPE610_ReadReg
- STMPE610_ReadID
- STMPE610_IsOperational
- STMPE610_SetI2CAddress
- STMPE610_Reset
- STMPE610_Module
- STMPE610_AlternateFunction
- STMPE610_SetGPIOPin
- STMPE610_EnableInterrupt
- STMPE610_ConfigureInterrupt
- STMPE610_SetADC
- STMPE610_SetADCClock
- STMPE610_ConfigureTSC
- STMPE610_SetFIFOThreshold
- STMPE610_ResetFIFO
- STMPE610_ZDataFraction
- STMPE610_SetTouchPressureThreshold
- STMPE610_TSIDrive
- STMPE610_TSControl
- STMPE610_ClearInterrupts
- STMPE610_ClearInterruptFlagsAndFIFO
- STMPE610_SetSize
- STMPE610_GetRawXYZ
- STMPE610_GetXYZ
- STMPE610_PressDetect
- STMPE610_GetCoordinates
- STMPE610_GetLastCoordinates
- STMPE610_SetCalibrationConsts
- STMPE610_GetCalibrationConsts
- STMPE610_SetDefaultMode
- STMPE610_Rotate180
- STMPE610_CalibratePoint
STMPE610_WriteReg
Prototype |
function STMPE610_WriteReg(RegisterAddr, RegisterValue : byte) : byte; |
---|---|
Description |
This function sets desired STMPE610 register (on RegisterAddr address) with given value (RegisterValue). |
Parameters |
|
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
// Initialize the STMPE610_SYS_CTRL1_REG register with the value 0x02 STMPE610_WriteReg(STMPE610_SYS_CTRL1_REG, 0x02); |
Notes |
|
STMPE610_ReadReg
Prototype |
function STMPE610_ReadReg(RegisterAddr : byte) : byte; |
---|---|
Description |
This function reads desired STMPE610 register (on RegisterAddr address) and returns its value. |
Parameters |
|
Returns |
Value of the STMPE610 register at given address. |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
// Initialize the STMPE610_SYS_CTRL1_REG register with the value 0x02 var temp : byte; ... temp := STMPE610_WriteReg(STMPE610_SYS_CTRL1_REG, 0x02); |
Notes |
|
STMPE610_ReadID
Prototype |
function STMPE610_ReadID() : word; |
---|---|
Description |
This routine reads STMPE610 ID register, and returns its value. |
Parameters |
None. |
Returns |
If I²C, and STMPE610 modules have been properly initialized function should return correct ID nimber and that is 0x0811. |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
var temp : word; temp := STMPE610_ReadID(); |
Notes |
|
STMPE610_IsOperational
Prototype |
function STMPE610_IsOperational() : byte; |
---|---|
Description |
This routine checks if STMPE610 responds correctly via I²C communication. |
Parameters |
None. |
Returns |
STMPE610_OK if STMPE610 responds correctly, otherwise function returns STMPE610_FAILURE. |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
if (STMPE610_IsOperational() = STMPE610_OK) then // STMPE610 initialized OK else // STMPE610 did not initialize OK |
Notes |
|
STMPE610_SetI2CAddress
Prototype |
procedure STMPE610_SetI2CAddress(DeviceAddr : byte); |
---|---|
Description |
This procedure sets default addres which will be used fo all further commnunication with STMPE610 IC. |
Parameters |
|
Requires |
Adress set must be either 0x82 or 0x88, any other values will cause IC to not work properly. |
Example |
// Initialize the STMPE610 I2C communication address at 0x88 STMPE610_SetI2CAddress(STMPE610_I2C_ADDR1); |
Notes |
|
STMPE610_Reset
Prototype |
function STMPE610_Reset() : byte; |
---|---|
Description |
This is a reset routine for STMPE610. |
Parameters |
None. |
Returns |
STMPE610_OK if STMPE610 responds correctly, otherwise function returns STMPE610_FAILURE. |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
STMPE610_Reset(); |
Notes |
|
STMPE610_Module
Prototype |
function STMPE610_Module(module_mask, newState : byte) : byte; |
||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
Enable or Disable the various STMPE610 modules. |
||||||||||||||||
Parameters |
|
||||||||||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||||||||||
Example |
STMPE610_Module(STMPE610_MODULE_TS or STMPE610_MODULE_ADC, STMPE610_ENABLE); |
||||||||||||||||
Notes |
|
STMPE610_AlternateFunction
Prototype |
function STMPE610_AlternateFunction(IO_Pin, NewState : byte) : byte; |
||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
Sets weather STMPE610 GPIO pins will have alternate function(s) or not. |
||||||||||||||||||||||||||
Parameters |
|
||||||||||||||||||||||||||
Returns |
STMPE610_OK if STMPE610 responds correctly, otherwise function returns STMPE610_FAILURE. |
||||||||||||||||||||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||||||||||||||||||||
Example |
STMPE610_AlternateFunction(STMPE610_GPIO_PIN6 or STMPE610_GPIO_PIN4, _STMPE610_ENABLE); |
||||||||||||||||||||||||||
Notes |
|
STMPE610_SetGPIOPin
Prototype |
function STMPE610_SetGPIOPin(IO_Pin, BitVal : byte) : byte; |
||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
Sets or clears STMPE610 GPIO pin. |
||||||||||||||||||||||||||
Parameters |
|
||||||||||||||||||||||||||
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
||||||||||||||||||||||||||
Requires |
MCU with at least one STMPE610 module. Used STMPE610 module must be initialized before using this function. See STMPE610x_Init and STMPE610x_Init_Advanced routines. |
||||||||||||||||||||||||||
Example |
STMPE610_SetGPIOPin(STMPE610_GPIO_PIN7 or STMPE610_GPIO_PIN6, 1); |
||||||||||||||||||||||||||
Notes |
|
STMPE610_EnableInterrupt
Prototype |
function STMPE610_EnableInterrupt(interrupt_mask, enable : byte) : byte; |
||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
Enables/Disables different types of STMPE610 interrupt generation. |
||||||||||||||||||||||||
Parameters |
|
||||||||||||||||||||||||
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
||||||||||||||||||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||||||||||||||||||
Example |
STMPE610_EnableInterrupt(STMPE610_IE_ADC or STMPE610_IE_TOUCH_DET, STMPE610_ENABLE); | ||||||||||||||||||||||||
Notes |
|
STMPE610_ConfigureInterrupt
Prototype |
function STMPE610_ConfigureInterrupt(interrupt_mask : byte) : byte; |
||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
Configure Interrupt Type. |
||||||||||||||
Parameters |
|
||||||||||||||
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
||||||||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||||||||
Example |
STMPE610_ConfigureInterrupt(STMPE610_INT_POLARITY_ACTIVE_HIGH or STMPE610_INT_TYPE_EDGE); | ||||||||||||||
Notes |
|
STMPE610_SetADC
Prototype |
function STMPE610_SetADC(mode : byte) : byte; |
||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
Configure STMPE610 ADC module. |
||||||||||||||||||||||
Parameters |
|
||||||||||||||||||||||
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
||||||||||||||||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||||||||||||||||
Example |
STMPE610_SetADC(STMPE610_ADC_CTRL1_SAMPLETIME_56 or STMPE610_ADC_CTRL1_ADC_12BIT or STMPE610_ADC_CTRL1_INT_REFERENCE); | ||||||||||||||||||||||
Notes |
|
STMPE610_SetADCClock
Prototype |
function STMPE610_SetADCClock(clock : byte) : byte; |
||||||||
---|---|---|---|---|---|---|---|---|---|
Description |
Configure STMPE610 ADC clock. |
||||||||
Parameters |
|
||||||||
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||
Example |
STMPE610_SetADCClock(STMPE610_ADC_CTRL2_6500_kHZ); | ||||||||
Notes |
|
STMPE610_ConfigureTSC
Prototype |
function STMPE610_ConfigureTSC(average_sample, touch_detect_delay, settling_time : byte) : byte; |
||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
Configure various parameters of STMPE610 module. |
||||||||||||||||||||||||||||||||||||||||||||||||
Parameters |
|
||||||||||||||||||||||||||||||||||||||||||||||||
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
||||||||||||||||||||||||||||||||||||||||||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||||||||||||||||||||||||||||||||||||||||||
Example |
STMPE610_ConfigureTSC(STMPE610_TSC_CFG_AVE_CTRL_2S, STMPE610_TSC_CFG_TOUCH_DET_DELAY_500uS, STMPE610_TSC_CFG_TOUCH_DET_DELAY_500uS); | ||||||||||||||||||||||||||||||||||||||||||||||||
Notes |
|
STMPE610_SetFIFOThreshold
Prototype |
function STMPE610_SetFIFOThreshold(point : byte) : byte; |
---|---|
Description |
Configure threshold of STMPE610 FIFO register. |
Parameters |
|
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
Requires |
FIFO threshold value must be within 1-128 range. Properly initialized I²C, and STMPE610 module. |
Example |
STMPE610_SetFIFOThreshold(5); |
Notes |
|
STMPE610_ResetFIFO
Prototype |
function STMPE610_ResetFIFO() : byte; |
---|---|
Description |
Procedure resets STMPE610 FIFO register. |
Parameters |
|
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
STMPE610_ResetFIFO(); |
Notes |
|
STMPE610_ZDataFraction
Prototype |
function STMPE610_ZDataFraction(_value : byte) : byte; |
||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
Procedure sets the range and accuracy of the STMPE610 pressure measurement. |
||||||||||||||||||
Parameters |
|
||||||||||||||||||
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
||||||||||||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||||||||||||
Example |
STMPE610_ZDataFraction(STMPE610_FRACP0_WHOLP8); | ||||||||||||||||||
Notes |
|
STMPE610_SetTouchPressureThreshold
Prototype |
procedure STMPE610_SetTouchPressureThreshold(threshold : byte); |
---|---|
Description |
Use this function to set desired touch panel pressure value. This value is compare with Z readout value, based on result touch is qualified as valid or invalid. If the Z value is lager then trashold value, press is invalid. (Z value decreases with increase of touch pressure) |
Parameters |
|
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
// Discard the press if Z value is grater then 45 STMPE610_SetTouchPressureThreshold(45); |
Notes |
|
STMPE610_TSIDrive
Prototype |
function STMPE610_TSIDrive(_drive : byte) : byte; |
||||||
---|---|---|---|---|---|---|---|
Description |
This function sets the current limit value of the STMPE610 touchscreen drivers. |
||||||
Parameters |
|
||||||
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||
Example |
STMPE610_TSIDrive(STMPE610_TSC_I_DRIVE_50mA); | ||||||
Notes |
|
STMPE610_TSControl
Prototype |
function STMPE610_TSControl(_ctrl : byte) : byte; |
||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
This function sets tracking index, and value ADC acquisition of STMPE610. |
||||||||||||||||||||||||||||
Parameters |
|
||||||||||||||||||||||||||||
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
||||||||||||||||||||||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||||||||||||||||||||||
Example |
STMPE610_TSControl(STMPE610_TSC_CTRL_TRACK4 or STMPE610_TSC_CTRL_ACQU_XYZ); | ||||||||||||||||||||||||||||
Notes |
|
STMPE610_ClearInterrupts
Prototype |
function STMPE610_ClearInterrupts() : byte; |
---|---|
Description |
Procedure clears all STMPE610 interrupts. |
Parameters |
|
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
STMPE610_ClearInterrupts(); |
Notes |
|
STMPE610_ClearInterruptFlagsAndFIFO
Prototype |
procedure STMPE610_ClearInterruptFlagsAndFIFO(); |
---|---|
Description |
Procedure clears all STMPE610 interrupt flags and resets FIFO register. |
Parameters |
|
Returns |
Nothing. |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
STMPE610_ClearInterruptFlagsAndFIFO(); |
Notes |
|
STMPE610_SetSize
Prototype |
function STMPE610_SetSize(display_width, display_height : word) : byte; |
---|---|
Description |
This function sets touch screen size in pixels. |
Parameters |
|
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
STMPE610_SetSize(480, 272); |
Notes |
|
STMPE610_GetRawXYZ
Prototype |
function STMPE610_GetRawXYZ(x_data, y_data : ^word; z_data : ^byte) : byte; |
---|---|
Description |
Function reads raw(ADC values) Touch panel values from FIFO(first in FIFO, last touched) for X, Y, and Z. |
Parameters |
|
Returns |
STMPE610_OK if reading goes OK STMPE610_FAILURE if there are no data sets to be read.(FIFO empty) |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
// Read raw Touch panel (ADC conversion) values (X, Y, and Z) STMPE610_GetRawXYZ(@adc_x, @adc_y, @adc_z ); |
Notes |
|
STMPE610_GetXYZ
Prototype |
function STMPE610_GetXYZ(x_data, y_data : ^word; z_data : ^byte) : byte; |
---|---|
Description |
Function reads Touch panel coordinate(pixel) from FIFO(first in FIFO, last touched), for X, Y, and Z |
Parameters |
|
Returns |
STMPE610_OK if reading goes OK STMPE610_FAILURE if there are no data sets to be read.(FIFO empty) |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
// Read raw Touch panel coordinates(pixel) (X, Y, and Z) STMPE610_GetXYZ(@x_px, @y_px, @z_px); |
Notes |
|
STMPE610_PressDetect
Prototype |
function STMPE610_PressDetect() : byte; |
---|---|
Description |
This function detects it touch panel has been pressed and also returns pendown value. |
Parameters |
|
Returns |
One: if touchscreen has been pressed. Zero: if touchscreen hasn't been pressed. Additionaly, function returns value of PenDown (detects changes on touchscreen, PressDown or PressUp). |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
if (STMPE610_PressDetect() <> 0) then ... |
Notes |
|
STMPE610_GetCoordinates
Prototype |
function STMPE610_GetCoordinates(x_coordinate, y_coordinate : ^word) : byte; |
---|---|
Description |
This function returns coordinates (in pixels) where touchscreen has been pressed. |
Parameters |
|
Returns |
0x00 : if returned values are correct |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
if (STMPE610_GetCoordinates(@Xcoord, @Ycoord) = 0) then ... |
Notes |
|
STMPE610_GetLastCoordinates
Prototype |
function STMPE610_GetLastCoordinates(x_coordinate, y_coordinate : ^word) : byte; |
---|---|
Description |
Returns last display coordinates (from FIFO register) where touch panel has been pressed. |
Parameters |
|
Returns |
0x00 : if returned values are correct |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
// Get last valid value from FIFO STMPE610_GetLastCoordinates(@x_c, @y_c); |
Notes |
|
STMPE610_SetCalibrationConsts
Prototype |
procedure STMPE610_SetCalibrationConsts(TPConstsStruct : ^TTPConstants); |
||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
This function sets calibration constants and orientation by structure defined parameters. |
||||||||||||||||
Parameters |
|
||||||||||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||||||||||
Example |
var TPConstsStruct : TTPConstants; TPConstsStruct.X_Max := 3898; TPConstsStruct.X_Min := 137; TPConstsStruct.Y_Max := 3828; TPConstsStruct.Y_Min := 362; TPConstsStruct.Rotate := 0; STMPE610_SetCalibrationConsts(@TPConstsStruct); | ||||||||||||||||
Notes |
|
STMPE610_GetCalibrationConsts
Prototype |
procedure STMPE610_GetCalibrationConsts(TPConstsStruct : ^TTPConstants); |
||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
This function returns calibration constants and orientation to structure previously defined. |
||||||||||||||||
Parameters |
|
||||||||||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||||||||||
Example |
var TPConstsStruct : TTPConstants; STMPE610_GetCalibrationConsts(@TPConstsStruct); | ||||||||||||||||
Notes |
|
STMPE610_SetDefaultMode
Prototype |
procedure STMPE610_SetDefaultMode(); |
---|---|
Description |
Procedure sets default STMPE610 touchscreen values neccesary for normal operation. |
Parameters |
|
Requires |
None. |
Example |
STMPE610_SetDefaultMode(); |
Notes |
|
STMPE610_Rotate180
Prototype |
procedure STMPE610_Rotate180(rotate : byte); |
||||||
---|---|---|---|---|---|---|---|
Description |
This function rotates touchscreen by 180 degrees. |
||||||
Parameters |
|
||||||
Requires |
None. |
||||||
Example |
STMPE610_Rotate180(STMPE610_ROTATE_180); | ||||||
Notes |
|
STMPE610_CalibratePoint
Prototype |
procedure STMPE610_CalibratePoint(_point : byte); |
||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Description |
This function calibrates touchscreen. |
||||||||||
Parameters |
|
||||||||||
Requires |
None. |
||||||||||
Example |
STMPE610_CalibratePoint(_STMPE610_FIRST_CORNER); | ||||||||||
Notes |
|