_BSP_User_Manual
|
stm3210c_eval_ts.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm3210c_eval_ts.c 00004 * @author MCD Application Team 00005 * @version V2.0.0 00006 * @date 18-February-2014 00007 * @brief This file provides a set of functions needed to manage the touch 00008 * screen on STM324x9I-EVAL evaluation board. 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> 00013 * 00014 * Redistribution and use in source and binary forms, with or without modification, 00015 * are permitted provided that the following conditions are met: 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 2. Redistributions in binary form must reproduce the above copyright notice, 00019 * this list of conditions and the following disclaimer in the documentation 00020 * and/or other materials provided with the distribution. 00021 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00022 * may be used to endorse or promote products derived from this software 00023 * without specific prior written permission. 00024 * 00025 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00026 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00028 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00029 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00030 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00031 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00033 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00034 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 ****************************************************************************** 00037 */ 00038 00039 /* File Info : ----------------------------------------------------------------- 00040 User NOTES 00041 1. How To use this driver: 00042 -------------------------- 00043 - This driver is used to drive the touch screen module of the STM3210C-EVAL 00044 evaluation board on the ILI9325 LCD mounted on MB785 daughter board . 00045 - The STMPE811 IO expander device component driver must be included with this 00046 driver in order to run the TS module commanded by the IO expander device 00047 mounted on the evaluation board. 00048 00049 2. Driver description: 00050 --------------------- 00051 + Initialization steps: 00052 o Initialize the TS module using the BSP_TS_Init() function. This 00053 function includes the MSP layer hardware resources initialization and the 00054 communication layer configuration to start the TS use. The LCD size properties 00055 (x and y) are passed as parameters. 00056 o If TS interrupt mode is desired, you must configure the TS interrupt mode 00057 by calling the function BSP_TS_ITConfig(). The TS interrupt mode is generated 00058 as an external interrupt whenever a touch is detected. 00059 00060 + Touch screen use 00061 o The touch screen state is captured whenever the function BSP_TS_GetState() is 00062 used. This function returns information about the last LCD touch occurred 00063 in the TS_StateTypeDef structure. 00064 o If TS interrupt mode is used, the function BSP_TS_ITGetStatus() is needed to get 00065 the interrupt status. To clear the IT pending bits, you should call the 00066 function BSP_TS_ITClear(). 00067 o The IT is handled using the corresponding external interrupt IRQ handler, 00068 the user IT callback treatment is implemented on the same external interrupt 00069 callback. 00070 00071 ------------------------------------------------------------------------------*/ 00072 00073 /* Includes ------------------------------------------------------------------*/ 00074 #include "stm3210c_eval_ts.h" 00075 00076 /** @addtogroup BSP 00077 * @{ 00078 */ 00079 00080 /** @addtogroup STM3210C_EVAL 00081 * @{ 00082 */ 00083 00084 /** @defgroup STM3210C_EVAL_TS STM3210C_EVAL Touch Screen 00085 * @{ 00086 */ 00087 00088 /* Private typedef -----------------------------------------------------------*/ 00089 00090 /** @defgroup STM3210C_EVAL_TS_Private_Types_Definitions Private_Types_Definitions 00091 * @{ 00092 */ 00093 00094 /** 00095 * @} 00096 */ 00097 00098 /* Private define ------------------------------------------------------------*/ 00099 00100 /** @defgroup STM3210C_EVAL_TS_Private_Defines Private_Defines 00101 * @{ 00102 */ 00103 00104 /** 00105 * @} 00106 */ 00107 00108 /* Private macro -------------------------------------------------------------*/ 00109 00110 /** @defgroup STM3210C_EVAL_TS_Private_Macros Private_Macros 00111 * @{ 00112 */ 00113 00114 /** 00115 * @} 00116 */ 00117 00118 /* Private variables ---------------------------------------------------------*/ 00119 00120 /** @defgroup STM3210C_EVAL_TS_Private_Variables Private_Variables 00121 * @{ 00122 */ 00123 static TS_DrvTypeDef *ts_driver; 00124 static uint16_t ts_x_boundary, ts_y_boundary; 00125 static uint8_t ts_orientation; 00126 00127 /** 00128 * @} 00129 */ 00130 00131 /* Private function prototypes -----------------------------------------------*/ 00132 00133 /** @defgroup STM3210C_EVAL_TS_Private_Function_Prototypes Private_Function_Prototypes 00134 * @{ 00135 */ 00136 00137 /** 00138 * @} 00139 */ 00140 00141 /* Private functions ---------------------------------------------------------*/ 00142 00143 /** @defgroup STM3210C_EVAL_TS_Exported_Functions Exported_Functions 00144 * @{ 00145 */ 00146 00147 /** 00148 * @brief Initializes and configures the touch screen functionalities and 00149 * configures all necessary hardware resources (GPIOs, clocks..). 00150 * @param xSize: Maximum X size of the TS area on LCD 00151 * @param ySize: Maximum Y size of the TS area on LCD 00152 * @retval TS_OK: if all initializations are OK. Other value if error. 00153 */ 00154 uint8_t BSP_TS_Init(uint16_t xSize, uint16_t ySize) 00155 { 00156 uint8_t ret = TS_ERROR; 00157 00158 if(stmpe811_ts_drv.ReadID(TS_I2C_ADDRESS) == STMPE811_ID) 00159 { 00160 /* Initialize the TS driver structure */ 00161 ts_driver = &stmpe811_ts_drv; 00162 00163 /* Initialize x and y positions boundaries */ 00164 ts_x_boundary = xSize; 00165 ts_y_boundary = ySize; 00166 ts_orientation = TS_SWAP_XY; 00167 ret = TS_OK; 00168 } 00169 00170 if(ret == TS_OK) 00171 { 00172 /* Initialize the LL TS Driver */ 00173 ts_driver->Reset(TS_I2C_ADDRESS); 00174 ts_driver->Init(TS_I2C_ADDRESS); 00175 ts_driver->Start(TS_I2C_ADDRESS); 00176 } 00177 00178 return ret; 00179 } 00180 00181 /** 00182 * @brief Configures and enables the touch screen interrupts. 00183 * @retval TS_OK: if all initializations are OK. Other value if error. 00184 */ 00185 uint8_t BSP_TS_ITConfig(void) 00186 { 00187 /* Call component driver to enable TS ITs */ 00188 ts_driver->EnableIT(TS_I2C_ADDRESS); 00189 00190 return TS_OK; 00191 } 00192 00193 /** 00194 * @brief Gets the touch screen interrupt status. 00195 * @retval TS_OK: if all initializations are OK. Other value if error. 00196 */ 00197 uint8_t BSP_TS_ITGetStatus(void) 00198 { 00199 /* Call component driver to enable TS ITs */ 00200 return (ts_driver->GetITStatus(TS_I2C_ADDRESS)); 00201 } 00202 00203 /** 00204 * @brief Returns status and positions of the touch screen. 00205 * @param TS_State: Pointer to touch screen current state structure 00206 * @retval TS_OK: if all initializations are OK. Other value if error. 00207 */ 00208 uint8_t BSP_TS_GetState(TS_StateTypeDef *TS_State) 00209 { 00210 static uint32_t _x = 0, _y = 0; 00211 uint16_t xDiff, yDiff , x , y; 00212 uint16_t swap; 00213 00214 TS_State->TouchDetected = ts_driver->DetectTouch(TS_I2C_ADDRESS); 00215 00216 if(TS_State->TouchDetected) 00217 { 00218 ts_driver->GetXY(TS_I2C_ADDRESS, &x, &y); 00219 00220 if(ts_orientation & TS_SWAP_X) 00221 { 00222 x = 4096 - x; 00223 } 00224 00225 if(ts_orientation & TS_SWAP_Y) 00226 { 00227 y = 4096 - y; 00228 } 00229 00230 if(ts_orientation & TS_SWAP_XY) 00231 { 00232 swap = y; 00233 y = x; 00234 x = swap; 00235 } 00236 00237 xDiff = x > _x? (x - _x): (_x - x); 00238 yDiff = y > _y? (y - _y): (_y - y); 00239 00240 if (xDiff + yDiff > 5) 00241 { 00242 _x = x; 00243 _y = y; 00244 } 00245 00246 TS_State->x = (ts_x_boundary * _x) >> 12; 00247 TS_State->y = (ts_y_boundary * _y) >> 12; 00248 } 00249 00250 return TS_OK; 00251 } 00252 00253 /** 00254 * @brief Clears all touch screen interrupts. 00255 * @retval None 00256 */ 00257 void BSP_TS_ITClear(void) 00258 { 00259 ts_driver->ClearIT(TS_I2C_ADDRESS); 00260 } 00261 00262 /** 00263 * @} 00264 */ 00265 00266 /** 00267 * @} 00268 */ 00269 00270 /** 00271 * @} 00272 */ 00273 00274 /** 00275 * @} 00276 */ 00277 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Thu Dec 11 2014 15:38:29 for _BSP_User_Manual by 1.7.5.1