STM32769I_EVAL BSP User Manual
|
stm32f769i_eval_ts.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f769i_eval_ts.c 00004 * @author MCD Application Team 00005 * @version V2.0.1 00006 * @date 06-April-2017 00007 * @brief This file provides a set of functions needed to manage the Touch 00008 * Screen on STM32F769I-EVAL evaluation board. 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT(c) 2017 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 STM32F769I-EVAL 00044 evaluation board on the K.O.D Optica Technology 480x800 TFT-LCD mounted on 00045 MB1166 daughter board. The touch screen driver IC inside the K.O.D module KM-040TMP-02 00046 is a FT6206 by Focal Tech. 00047 00048 2. Driver description: 00049 --------------------- 00050 + Initialization steps: 00051 o Initialize the TS module using the BSP_TS_Init() function. This 00052 function includes the MSP layer hardware resources initialization and the 00053 communication layer configuration to start the TS use. The LCD size properties 00054 (x and y) are passed as parameters. 00055 o If TS interrupt mode is desired, you must configure the TS interrupt mode 00056 by calling the function BSP_TS_ITConfig(). The TS interrupt mode is generated 00057 as an external interrupt whenever a touch is detected. 00058 The interrupt mode internally uses the IO functionalities driver driven by 00059 the IO expander, to configure the IT line. 00060 00061 + Touch screen use 00062 o The touch screen state is captured whenever the function BSP_TS_GetState() is 00063 used. This function returns information about the last LCD touch occurred 00064 in the TS_StateTypeDef structure. 00065 o If TS interrupt mode is used, the function BSP_TS_ITGetStatus() is needed to get 00066 the interrupt status. To clear the IT pending bits, you should call the 00067 function BSP_TS_ITClear(). 00068 o The IT is handled using the corresponding external interrupt IRQ handler, 00069 the user IT callback treatment is implemented on the same external interrupt 00070 callback. 00071 00072 ------------------------------------------------------------------------------*/ 00073 /* Dependencies 00074 - stm32f769i_eval_lcd.c 00075 - ft6x06.c 00076 EndDependencies */ 00077 00078 /* Includes ------------------------------------------------------------------*/ 00079 #include "stm32f769i_eval.h" 00080 #include "stm32f769i_eval_ts.h" 00081 00082 /** @addtogroup BSP 00083 * @{ 00084 */ 00085 00086 /** @addtogroup STM32F769I_EVAL 00087 * @{ 00088 */ 00089 00090 /** @defgroup STM32F769I_EVAL_TS STM32F769I_EVAL TS 00091 * @{ 00092 */ 00093 00094 /** @defgroup STM32F769I_EVAL_TS_Private_Types_Definitions TS Private Types Definitions 00095 * @{ 00096 */ 00097 /** 00098 * @} 00099 */ 00100 00101 /** @defgroup STM32F769I_EVAL_TS_Private_Defines TS Private Types Defines 00102 * @{ 00103 */ 00104 /** 00105 * @} 00106 */ 00107 00108 /** @defgroup STM32F769I_EVAL_TS_Private_Macros TS Private Macros 00109 * @{ 00110 */ 00111 /** 00112 * @} 00113 */ 00114 00115 /** @defgroup STM32F769I_EVAL_TS_Imported_Variables TS Imported Variables 00116 * @{ 00117 */ 00118 /** 00119 * @} 00120 */ 00121 00122 /** @defgroup STM32F769I_EVAL_TS_Private_Variables TS Private Variables 00123 * @{ 00124 */ 00125 static TS_DrvTypeDef *ts_driver; 00126 static uint8_t ts_orientation; 00127 uint8_t I2C_Address = 0; 00128 00129 /* Table for touchscreen event information display on LCD : table indexed on enum @ref TS_TouchEventTypeDef information */ 00130 char * ts_event_string_tab[TOUCH_EVENT_NB_MAX] = { "None", 00131 "Press down", 00132 "Lift up", 00133 "Contact" 00134 }; 00135 00136 /* Table for touchscreen gesture Id information display on LCD : table indexed on enum @ref TS_GestureIdTypeDef information */ 00137 char * ts_gesture_id_string_tab[GEST_ID_NB_MAX] = { "None", 00138 "Move Up", 00139 "Move Right", 00140 "Move Down", 00141 "Move Left", 00142 "Zoom In", 00143 "Zoom Out" 00144 }; 00145 00146 /** 00147 * @} 00148 */ 00149 00150 /** @defgroup STM32F769I_EVAL_TS_Private_Function_Prototypes TS Private Function Prototypes 00151 * @{ 00152 */ 00153 00154 /** 00155 * @} 00156 */ 00157 00158 /** @defgroup STM32F769I_EVAL_TS_Public_Functions TS Public Functions 00159 * @{ 00160 */ 00161 00162 /** 00163 * @brief Initializes and configures the touch screen functionalities and 00164 * configures all necessary hardware resources (GPIOs, I2C, clocks..). 00165 * @param ts_SizeX : Maximum X size of the TS area on LCD 00166 * @param ts_SizeY : Maximum Y size of the TS area on LCD 00167 * @retval TS_OK if all initializations are OK. Other value if error. 00168 */ 00169 uint8_t BSP_TS_Init(uint16_t ts_SizeX, uint16_t ts_SizeY) 00170 { 00171 uint8_t ts_status = TS_OK; 00172 uint8_t ts_id1, ts_id2 = 0; 00173 /* Note : I2C_Address is un-initialized here, but is not used at all in init function */ 00174 /* but the prototype of Init() is like that in template and should be respected */ 00175 00176 /* Initialize the communication channel to sensor (I2C) if necessary */ 00177 /* that is initialization is done only once after a power up */ 00178 ft6x06_ts_drv.Init(I2C_Address); 00179 00180 ts_id1 = ft6x06_ts_drv.ReadID(TS_I2C_ADDRESS); 00181 if(ts_id1 != FT6206_ID_VALUE) 00182 { 00183 ts_id2 = ft6x06_ts_drv.ReadID(TS_I2C_ADDRESS_A02); 00184 I2C_Address = TS_I2C_ADDRESS_A02; 00185 } 00186 else 00187 { 00188 I2C_Address = TS_I2C_ADDRESS; 00189 } 00190 00191 /* Scan FT6xx6 TouchScreen IC controller ID register by I2C Read */ 00192 /* Verify this is a FT6206 or FT6336G, otherwise this is an error case */ 00193 if((ts_id1 == FT6206_ID_VALUE) || (ts_id2 == FT6206_ID_VALUE)) 00194 { 00195 /* Found FT6206 : Initialize the TS driver structure */ 00196 ts_driver = &ft6x06_ts_drv; 00197 00198 /* Get LCD chosen orientation */ 00199 if(ts_SizeX < ts_SizeY) 00200 { 00201 ts_orientation = TS_SWAP_NONE; 00202 } 00203 else 00204 { 00205 ts_orientation = TS_SWAP_XY | TS_SWAP_Y; 00206 } 00207 00208 if(ts_status == TS_OK) 00209 { 00210 /* Software reset the TouchScreen */ 00211 ts_driver->Reset(I2C_Address); 00212 00213 /* Calibrate, Configure and Start the TouchScreen driver */ 00214 ts_driver->Start(I2C_Address); 00215 00216 } /* of if(ts_status == TS_OK) */ 00217 } 00218 else 00219 { 00220 ts_status = TS_DEVICE_NOT_FOUND; 00221 } 00222 00223 return (ts_status); 00224 } 00225 00226 /** 00227 * @brief Configures and enables the touch screen interrupts. 00228 * @retval TS_OK if all initializations are OK. Other value if error. 00229 */ 00230 uint8_t BSP_TS_ITConfig(void) 00231 { 00232 uint8_t ts_status = TS_ERROR; 00233 uint8_t io_status = IO_ERROR; 00234 00235 /* Initialize the IO */ 00236 io_status = BSP_IO_Init(); 00237 if(io_status != IO_OK) 00238 { 00239 return (ts_status); 00240 } 00241 00242 /* Configure TS IT line IO : is active low on FT6206 (see data sheet) */ 00243 /* Configure TS_INT_PIN (MFX_IO_14) low level to generate MFX_IRQ_OUT in EXTI on MCU */ 00244 io_status = BSP_IO_ConfigPin(TS_INT_PIN, IO_MODE_IT_LOW_LEVEL_PU); 00245 if(io_status != IO_OK) 00246 { 00247 return (ts_status); 00248 } 00249 00250 /* Enable the TS in interrupt mode */ 00251 /* In that case the INT output of FT6206 when new touch is available */ 00252 /* is active low and directed on MFX IO14 */ 00253 ts_driver->EnableIT(I2C_Address); 00254 00255 /* If arrived here : set good status on exit */ 00256 ts_status = TS_OK; 00257 00258 return (ts_status); 00259 } 00260 00261 /** 00262 * @brief Gets the touch screen interrupt status. 00263 * @retval TS_IRQ_PENDING if touchscreen IRQ is pending, TS_NO_IRQ_PENDING when no IRQ TS is pending. 00264 */ 00265 uint8_t BSP_TS_ITGetStatus(void) 00266 { 00267 uint8_t itStatus = TS_NO_IRQ_PENDING; /* By default no IRQ TS pending */ 00268 uint32_t mfx_irq_status = 0; /* No MFX IRQ by default */ 00269 00270 /* Check status of MFX_IO14 in particular which is the Touch Screen INT pin active low */ 00271 mfx_irq_status = BSP_IO_ITGetStatus(TS_INT_PIN); 00272 if(mfx_irq_status != 0) /* Note : returned mfx_irq_status = 0x4000 == (1<<TS_INT_PIN) == (1<<14) */ 00273 { 00274 /* This is Touch Screen INT case : so this is a new touch available that produced the IRQ EXTI */ 00275 itStatus = TS_IRQ_PENDING; 00276 } 00277 00278 /* Return the TS IT status */ 00279 return (itStatus); 00280 } 00281 00282 /** 00283 * @brief Returns status and positions of the touch screen. 00284 * @param TS_State: Pointer to touch screen current state structure 00285 * @retval TS_OK if all initializations are OK. Other value if error. 00286 */ 00287 uint8_t BSP_TS_GetState(TS_StateTypeDef *TS_State) 00288 { 00289 static uint32_t _x[TS_MAX_NB_TOUCH] = {0, 0}; 00290 static uint32_t _y[TS_MAX_NB_TOUCH] = {0, 0}; 00291 uint8_t ts_status = TS_OK; 00292 uint16_t tmp; 00293 uint16_t Raw_x[TS_MAX_NB_TOUCH]; 00294 uint16_t Raw_y[TS_MAX_NB_TOUCH]; 00295 uint16_t xDiff; 00296 uint16_t yDiff; 00297 uint32_t index; 00298 #if (TS_MULTI_TOUCH_SUPPORTED == 1) 00299 uint32_t weight = 0; 00300 uint32_t area = 0; 00301 uint32_t event = 0; 00302 #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ 00303 00304 /* Check and update the number of touches active detected */ 00305 TS_State->touchDetected = ts_driver->DetectTouch(I2C_Address); 00306 if(TS_State->touchDetected) 00307 { 00308 for(index=0; index < TS_State->touchDetected; index++) 00309 { 00310 /* Get each touch coordinates */ 00311 ts_driver->GetXY(I2C_Address, &(Raw_x[index]), &(Raw_y[index])); 00312 00313 if(ts_orientation & TS_SWAP_XY) 00314 { 00315 tmp = Raw_x[index]; 00316 Raw_x[index] = Raw_y[index]; 00317 Raw_y[index] = tmp; 00318 } 00319 00320 if(ts_orientation & TS_SWAP_X) 00321 { 00322 Raw_x[index] = FT_6206_MAX_WIDTH - 1 - Raw_x[index]; 00323 } 00324 00325 if(ts_orientation & TS_SWAP_Y) 00326 { 00327 Raw_y[index] = FT_6206_MAX_HEIGHT - 1 - Raw_y[index]; 00328 } 00329 00330 xDiff = Raw_x[index] > _x[index]? (Raw_x[index] - _x[index]): (_x[index] - Raw_x[index]); 00331 yDiff = Raw_y[index] > _y[index]? (Raw_y[index] - _y[index]): (_y[index] - Raw_y[index]); 00332 00333 if ((xDiff + yDiff) > 5) 00334 { 00335 _x[index] = Raw_x[index]; 00336 _y[index] = Raw_y[index]; 00337 } 00338 00339 00340 TS_State->touchX[index] = _x[index]; 00341 TS_State->touchY[index] = _y[index]; 00342 00343 #if (TS_MULTI_TOUCH_SUPPORTED == 1) 00344 00345 /* Get touch info related to the current touch */ 00346 ft6x06_TS_GetTouchInfo(I2C_Address, index, &weight, &area, &event); 00347 00348 /* Update TS_State structure */ 00349 TS_State->touchWeight[index] = weight; 00350 TS_State->touchArea[index] = area; 00351 00352 /* Remap touch event */ 00353 switch(event) 00354 { 00355 case FT6206_TOUCH_EVT_FLAG_PRESS_DOWN : 00356 TS_State->touchEventId[index] = TOUCH_EVENT_PRESS_DOWN; 00357 break; 00358 case FT6206_TOUCH_EVT_FLAG_LIFT_UP : 00359 TS_State->touchEventId[index] = TOUCH_EVENT_LIFT_UP; 00360 break; 00361 case FT6206_TOUCH_EVT_FLAG_CONTACT : 00362 TS_State->touchEventId[index] = TOUCH_EVENT_CONTACT; 00363 break; 00364 case FT6206_TOUCH_EVT_FLAG_NO_EVENT : 00365 TS_State->touchEventId[index] = TOUCH_EVENT_NO_EVT; 00366 break; 00367 default : 00368 ts_status = TS_ERROR; 00369 break; 00370 } /* of switch(event) */ 00371 00372 #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ 00373 00374 } /* of for(index=0; index < TS_State->touchDetected; index++) */ 00375 00376 #if (TS_MULTI_TOUCH_SUPPORTED == 1) 00377 /* Get gesture Id */ 00378 ts_status = BSP_TS_Get_GestureId(TS_State); 00379 #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ 00380 00381 } /* end of if(TS_State->touchDetected != 0) */ 00382 00383 return (ts_status); 00384 } 00385 00386 #if (TS_MULTI_TOUCH_SUPPORTED == 1) 00387 /** 00388 * @brief Update gesture Id following a touch detected. 00389 * @param TS_State: Pointer to touch screen current state structure 00390 * @retval TS_OK if all initializations are OK. Other value if error. 00391 */ 00392 uint8_t BSP_TS_Get_GestureId(TS_StateTypeDef *TS_State) 00393 { 00394 uint32_t gestureId = 0; 00395 uint8_t ts_status = TS_OK; 00396 00397 /* Get gesture Id */ 00398 ft6x06_TS_GetGestureID(I2C_Address, &gestureId); 00399 00400 /* Remap gesture Id to a TS_GestureIdTypeDef value */ 00401 switch(gestureId) 00402 { 00403 case FT6206_GEST_ID_NO_GESTURE : 00404 TS_State->gestureId = GEST_ID_NO_GESTURE; 00405 break; 00406 case FT6206_GEST_ID_MOVE_UP : 00407 TS_State->gestureId = GEST_ID_MOVE_UP; 00408 break; 00409 case FT6206_GEST_ID_MOVE_RIGHT : 00410 TS_State->gestureId = GEST_ID_MOVE_RIGHT; 00411 break; 00412 case FT6206_GEST_ID_MOVE_DOWN : 00413 TS_State->gestureId = GEST_ID_MOVE_DOWN; 00414 break; 00415 case FT6206_GEST_ID_MOVE_LEFT : 00416 TS_State->gestureId = GEST_ID_MOVE_LEFT; 00417 break; 00418 case FT6206_GEST_ID_ZOOM_IN : 00419 TS_State->gestureId = GEST_ID_ZOOM_IN; 00420 break; 00421 case FT6206_GEST_ID_ZOOM_OUT : 00422 TS_State->gestureId = GEST_ID_ZOOM_OUT; 00423 break; 00424 default : 00425 ts_status = TS_ERROR; 00426 break; 00427 } /* of switch(gestureId) */ 00428 00429 return(ts_status); 00430 } 00431 #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ 00432 00433 00434 /** 00435 * @brief Clears all touch screen interrupts. 00436 */ 00437 void BSP_TS_ITClear(void) 00438 { 00439 /* Clear TS_INT_PIN IRQ in MFX */ 00440 BSP_IO_ITClearPin(TS_INT_PIN); 00441 } 00442 00443 00444 /** @defgroup STM32F769I_EVAL_TS_Private_Functions TS Private Functions 00445 * @{ 00446 */ 00447 00448 #if (TS_MULTI_TOUCH_SUPPORTED == 1) 00449 /** 00450 * @brief Function used to reset all touch data before a new acquisition 00451 * of touch information. 00452 * @param TS_State: Pointer to touch screen current state structure 00453 * @retval TS_OK if OK, TE_ERROR if problem found. 00454 */ 00455 uint8_t BSP_TS_ResetTouchData(TS_StateTypeDef *TS_State) 00456 { 00457 uint8_t ts_status = TS_ERROR; 00458 uint32_t index; 00459 00460 if (TS_State != (TS_StateTypeDef *)NULL) 00461 { 00462 TS_State->gestureId = GEST_ID_NO_GESTURE; 00463 TS_State->touchDetected = 0; 00464 00465 for(index = 0; index < TS_MAX_NB_TOUCH; index++) 00466 { 00467 TS_State->touchX[index] = 0; 00468 TS_State->touchY[index] = 0; 00469 TS_State->touchArea[index] = 0; 00470 TS_State->touchEventId[index] = TOUCH_EVENT_NO_EVT; 00471 TS_State->touchWeight[index] = 0; 00472 } 00473 00474 ts_status = TS_OK; 00475 00476 } /* of if (TS_State != (TS_StateTypeDef *)NULL) */ 00477 00478 return (ts_status); 00479 } 00480 #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ 00481 /** 00482 * @} 00483 */ 00484 00485 /** 00486 * @} 00487 */ 00488 00489 /** 00490 * @} 00491 */ 00492 00493 /** 00494 * @} 00495 */ 00496 00497 /** 00498 * @} 00499 */ 00500 00501 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Thu May 25 2017 11:03:12 for STM32769I_EVAL BSP User Manual by
