Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: 2a 2b 2c 2d1 ... more
stm32f429i_discovery_ts.c
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f429i_discovery_ts.c 00004 * @author MCD Application Team 00005 * @brief This file provides a set of functions needed to manage Touch 00006 * screen available with STMPE811 IO Expander device mounted on 00007 * STM32F429I-Discovery Kit. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 /* Includes ------------------------------------------------------------------*/ 00039 #include "stm32f429i_discovery_ts.h" 00040 #include "stm32f429i_discovery_io.h" 00041 00042 /** @addtogroup BSP 00043 * @{ 00044 */ 00045 00046 /** @addtogroup STM32F429I_DISCOVERY 00047 * @{ 00048 */ 00049 00050 /** @defgroup STM32F429I_DISCOVERY_TS STM32F429I DISCOVERY TS 00051 * @{ 00052 */ 00053 00054 /** @defgroup STM32F429I_DISCOVERY_TS_Private_Types_Definitions STM32F429I DISCOVERY TS Private Types Definitions 00055 * @{ 00056 */ 00057 /** 00058 * @} 00059 */ 00060 00061 /** @defgroup STM32F429I_DISCOVERY_TS_Private_Defines STM32F429I DISCOVERY TS Private Defines 00062 * @{ 00063 */ 00064 /** 00065 * @} 00066 */ 00067 00068 /** @defgroup STM32F429I_DISCOVERY_TS_Private_Macros STM32F429I DISCOVERY TS Private Macros 00069 * @{ 00070 */ 00071 /** 00072 * @} 00073 */ 00074 00075 /** @defgroup STM32F429I_DISCOVERY_TS_Private_Variables STM32F429I DISCOVERY TS Private Variables 00076 * @{ 00077 */ 00078 static TS_DrvTypeDef *TsDrv; 00079 static uint16_t TsXBoundary, TsYBoundary; 00080 /** 00081 * @} 00082 */ 00083 00084 /** @defgroup STM32F429I_DISCOVERY_TS_Private_Function_Prototypes STM32F429I DISCOVERY TS Private Function Prototypes 00085 * @{ 00086 */ 00087 /** 00088 * @} 00089 */ 00090 00091 /** @defgroup STM32F429I_DISCOVERY_TS_Private_Functions STM32F429I DISCOVERY TS Private Functions 00092 * @{ 00093 */ 00094 00095 /** 00096 * @brief Initializes and configures the touch screen functionalities and 00097 * configures all necessary hardware resources (GPIOs, clocks..). 00098 * @param XSize: The maximum X size of the TS area on LCD 00099 * @param YSize: The maximum Y size of the TS area on LCD 00100 * @retval TS_OK: if all initializations are OK. Other value if error. 00101 */ 00102 uint8_t BSP_TS_Init(uint16_t XSize, uint16_t YSize) 00103 { 00104 uint8_t ret = TS_ERROR; 00105 00106 /* Initialize x and y positions boundaries */ 00107 TsXBoundary = XSize; 00108 TsYBoundary = YSize; 00109 00110 /* Read ID and verify if the IO expander is ready */ 00111 if(stmpe811_ts_drv.ReadID(TS_I2C_ADDRESS) == STMPE811_ID) 00112 { 00113 /* Initialize the TS driver structure */ 00114 TsDrv = &stmpe811_ts_drv; 00115 00116 ret = TS_OK; 00117 } 00118 00119 if(ret == TS_OK) 00120 { 00121 /* Initialize the LL TS Driver */ 00122 TsDrv->Init(TS_I2C_ADDRESS); 00123 TsDrv->Start(TS_I2C_ADDRESS); 00124 } 00125 00126 return ret; 00127 } 00128 00129 /** 00130 * @brief Configures and enables the touch screen interrupts. 00131 * @retval TS_OK: if ITconfig is OK. Other value if error. 00132 */ 00133 uint8_t BSP_TS_ITConfig(void) 00134 { 00135 /* Enable the TS ITs */ 00136 TsDrv->EnableIT(TS_I2C_ADDRESS); 00137 00138 return TS_OK; 00139 } 00140 00141 /** 00142 * @brief Gets the TS IT status. 00143 * @retval Interrupt status. 00144 */ 00145 uint8_t BSP_TS_ITGetStatus(void) 00146 { 00147 /* Return the TS IT status */ 00148 return (TsDrv->GetITStatus(TS_I2C_ADDRESS)); 00149 } 00150 00151 /** 00152 * @brief Returns status and positions of the touch screen. 00153 * @param TsState: Pointer to touch screen current state structure 00154 */ 00155 void BSP_TS_GetState(TS_StateTypeDef* TsState) 00156 { 00157 static uint32_t _x = 0, _y = 0; 00158 uint16_t xDiff, yDiff , x , y, xr, yr; 00159 00160 TsState->TouchDetected = TsDrv->DetectTouch(TS_I2C_ADDRESS); 00161 00162 if(TsState->TouchDetected) 00163 { 00164 TsDrv->GetXY(TS_I2C_ADDRESS, &x, &y); 00165 00166 /* Y value first correction */ 00167 y -= 360; 00168 00169 /* Y value second correction */ 00170 yr = y / 11; 00171 00172 /* Return y position value */ 00173 if(yr <= 0) 00174 { 00175 yr = 0; 00176 } 00177 else if (yr > TsYBoundary) 00178 { 00179 yr = TsYBoundary - 1; 00180 } 00181 else 00182 {} 00183 y = yr; 00184 00185 /* X value first correction */ 00186 if(x <= 3000) 00187 { 00188 x = 3870 - x; 00189 } 00190 else 00191 { 00192 x = 3800 - x; 00193 } 00194 00195 /* X value second correction */ 00196 xr = x / 15; 00197 00198 /* Return X position value */ 00199 if(xr <= 0) 00200 { 00201 xr = 0; 00202 } 00203 else if (xr > TsXBoundary) 00204 { 00205 xr = TsXBoundary - 1; 00206 } 00207 else 00208 {} 00209 00210 x = xr; 00211 xDiff = x > _x? (x - _x): (_x - x); 00212 yDiff = y > _y? (y - _y): (_y - y); 00213 00214 if (xDiff + yDiff > 5) 00215 { 00216 _x = x; 00217 _y = y; 00218 } 00219 00220 /* Update the X position */ 00221 TsState->X = _x; 00222 00223 /* Update the Y position */ 00224 TsState->Y = _y; 00225 } 00226 } 00227 00228 /** 00229 * @brief Clears all touch screen interrupts. 00230 */ 00231 void BSP_TS_ITClear(void) 00232 { 00233 /* Clear TS IT pending bits */ 00234 TsDrv->ClearIT(TS_I2C_ADDRESS); 00235 } 00236 00237 /** 00238 * @} 00239 */ 00240 00241 /** 00242 * @} 00243 */ 00244 00245 /** 00246 * @} 00247 */ 00248 00249 /** 00250 * @} 00251 */ 00252 00253 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 16:29:23 by
