1 | /*
|
---|
2 | * TOPPERS BASE PLATFORM MIDDLEWARE
|
---|
3 | *
|
---|
4 | * Copyright (C) 2017-2018 by TOPPERS PROJECT
|
---|
5 | * Educational Working Group.
|
---|
6 | *
|
---|
7 | * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
8 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
9 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
10 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
11 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
12 | * スコード中に含まれていること.
|
---|
13 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
14 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
15 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
16 | * の無保証規定を掲載すること.
|
---|
17 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
18 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
19 | * と.
|
---|
20 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
21 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
22 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
23 | * 報告すること.
|
---|
24 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
25 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
26 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
27 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
28 | * 免責すること.
|
---|
29 | *
|
---|
30 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
31 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
32 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
33 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
34 | * の責任を負わない.
|
---|
35 | *
|
---|
36 | * @(#) $Id$
|
---|
37 | */
|
---|
38 | /**
|
---|
39 | ******************************************************************************
|
---|
40 | * @attention
|
---|
41 | *
|
---|
42 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
|
---|
43 | *
|
---|
44 | * Redistribution and use in source and binary forms, with or without modification,
|
---|
45 | * are permitted provided that the following conditions are met:
|
---|
46 | * 1. Redistributions of source code must retain the above copyright notice,
|
---|
47 | * this list of conditions and the following disclaimer.
|
---|
48 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
49 | * this list of conditions and the following disclaimer in the documentation
|
---|
50 | * and/or other materials provided with the distribution.
|
---|
51 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
|
---|
52 | * may be used to endorse or promote products derived from this software
|
---|
53 | * without specific prior written permission.
|
---|
54 | *
|
---|
55 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
---|
56 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
57 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
58 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
---|
59 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
60 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
---|
61 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
---|
62 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
63 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
64 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
65 | *
|
---|
66 | ******************************************************************************
|
---|
67 | */
|
---|
68 |
|
---|
69 |
|
---|
70 | /* Includes ------------------------------------------------------------------*/
|
---|
71 | #include <kernel.h>
|
---|
72 | #include <t_syslog.h>
|
---|
73 | #include <t_stdlib.h>
|
---|
74 | #include <sil.h>
|
---|
75 | #include <target_syssvc.h>
|
---|
76 | #include "device.h"
|
---|
77 | #include "i2c.h"
|
---|
78 | #include "stts_ft06x06.h"
|
---|
79 |
|
---|
80 | #define sil_orw_mem(a, b) sil_wrw_mem((a), sil_rew_mem(a) | (b))
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * @brief TouchScreen FT6206 Slave I2C address
|
---|
84 | */
|
---|
85 | #define TS_I2C_ADDRESS ((uint16_t)0x70)
|
---|
86 |
|
---|
87 |
|
---|
88 | /* Table for touchscreen event information display on LCD : table indexed on enum @ref TS_TouchEventTypeDef information */
|
---|
89 | char * ts_event_string_tab[TOUCH_EVENT_NB_MAX] = { "None",
|
---|
90 | "Press down",
|
---|
91 | "Lift up",
|
---|
92 | "Contact"
|
---|
93 | };
|
---|
94 |
|
---|
95 | /* Table for touchscreen gesture Id information display on LCD : table indexed on enum @ref TS_GestureIdTypeDef information */
|
---|
96 | char * ts_gesture_id_string_tab[GEST_ID_NB_MAX] = { "None",
|
---|
97 | "Move Up",
|
---|
98 | "Move Right",
|
---|
99 | "Move Down",
|
---|
100 | "Move Left",
|
---|
101 | "Zoom In",
|
---|
102 | "Zoom Out"
|
---|
103 | };
|
---|
104 |
|
---|
105 |
|
---|
106 |
|
---|
107 |
|
---|
108 | /* Private functions prototypes-----------------------------------------------*/
|
---|
109 | /**
|
---|
110 | * @}
|
---|
111 | */
|
---|
112 |
|
---|
113 | /** @defgroup ft6x06_Private_Functions ft6x06 Private Functions
|
---|
114 | * @{
|
---|
115 | */
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * @brief Read the ft6x06 device ID, pre initialize I2C in case of need to be
|
---|
119 | * able to read the FT6206 device ID, and verify this is a FT6206.
|
---|
120 | * @param DeviceAddr: I2C FT6x06 Slave address.
|
---|
121 | * @retval The Device ID (two bytes).
|
---|
122 | */
|
---|
123 | static ER
|
---|
124 | ft6x06_ReadID(TouchScreen_Handle_t *hts, uint8_t *ts_id)
|
---|
125 | {
|
---|
126 | uint8_t read_value = 0;
|
---|
127 | ER ercd = E_OK;
|
---|
128 |
|
---|
129 | ercd = i2c_memread(hts->hi2c, hts->I2C_Address, (uint16_t)FT6206_CHIP_ID_REG, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&read_value, 1, 1000);
|
---|
130 | *ts_id = read_value;
|
---|
131 | return ercd;
|
---|
132 | }
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * @brief Return if there is touches detected or not.
|
---|
136 | * Try to detect new touches and forget the old ones (reset internal global
|
---|
137 | * variables).
|
---|
138 | * @param DeviceAddr: Device address on communication Bus.
|
---|
139 | * @retval : Number of active touches detected (can be 0, 1 or 2).
|
---|
140 | */
|
---|
141 | static ER_UINT
|
---|
142 | ft6x06_TS_DetectTouch(TouchScreen_Handle_t *hts)
|
---|
143 | {
|
---|
144 | ER ercd = E_OK;
|
---|
145 | volatile uint8_t nbTouch = 0;
|
---|
146 |
|
---|
147 | /* Read register FT6206_TD_STAT_REG to check number of touches detection */
|
---|
148 | ercd = i2c_memread(hts->hi2c, hts->I2C_Address, (uint16_t)FT6206_TD_STAT_REG, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&nbTouch, 1, 1000);
|
---|
149 | /* Check the communication status */
|
---|
150 | if(ercd != E_OK)
|
---|
151 | return ercd;
|
---|
152 |
|
---|
153 | nbTouch &= FT6206_TD_STAT_MASK;
|
---|
154 |
|
---|
155 | if(nbTouch > FT6206_MAX_DETECTABLE_TOUCH){
|
---|
156 | /* If invalid number of touch detected, set it to zero */
|
---|
157 | nbTouch = 0;
|
---|
158 | }
|
---|
159 |
|
---|
160 | /* Update ft6x06 driver internal global : current number of active touches */
|
---|
161 | hts->currActiveTouchNb = nbTouch;
|
---|
162 |
|
---|
163 | /* Reset current active touch index on which to work on */
|
---|
164 | hts->currActiveTouchIdx = 0;
|
---|
165 | return nbTouch;
|
---|
166 | }
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * @brief Get the touch screen X and Y positions values
|
---|
170 | * Manage multi touch thanks to touch Index global
|
---|
171 | * variable 'ft6x06_handle.currActiveTouchIdx'.
|
---|
172 | * @param DeviceAddr: Device address on communication Bus.
|
---|
173 | * @param X: Pointer to X position value
|
---|
174 | * @param Y: Pointer to Y position value
|
---|
175 | * @retval None.
|
---|
176 | */
|
---|
177 | static ER
|
---|
178 | ft6x06_TS_GetXY(TouchScreen_Handle_t *hts, uint16_t *X, uint16_t *Y)
|
---|
179 | {
|
---|
180 | uint8_t regAddress = 0;
|
---|
181 | uint8_t dataxy[4];
|
---|
182 | ER ercd = E_OK;
|
---|
183 |
|
---|
184 | if(hts->currActiveTouchIdx < hts->currActiveTouchNb){
|
---|
185 | switch(hts->currActiveTouchIdx){
|
---|
186 | case 0 :
|
---|
187 | regAddress = FT6206_P1_XH_REG;
|
---|
188 | break;
|
---|
189 | case 1 :
|
---|
190 | regAddress = FT6206_P2_XH_REG;
|
---|
191 | break;
|
---|
192 |
|
---|
193 | default :
|
---|
194 | break;
|
---|
195 | }
|
---|
196 |
|
---|
197 | /* Read X and Y positions */
|
---|
198 | ercd = i2c_memread(hts->hi2c, hts->I2C_Address, (uint16_t)regAddress, I2C_MEMADD_SIZE_8BIT, dataxy, sizeof(dataxy), 1000);
|
---|
199 | if(ercd != E_OK)
|
---|
200 | return ercd;
|
---|
201 | /* Send back ready X position to caller */
|
---|
202 | *X = ((dataxy[0] & FT6206_MSB_MASK) << 8) | (dataxy[1] & FT6206_LSB_MASK);
|
---|
203 |
|
---|
204 | /* Send back ready Y position to caller */
|
---|
205 | *Y = ((dataxy[2] & FT6206_MSB_MASK) << 8) | (dataxy[3] & FT6206_LSB_MASK);
|
---|
206 | hts->currActiveTouchIdx++;
|
---|
207 | }
|
---|
208 | return ercd;
|
---|
209 | }
|
---|
210 |
|
---|
211 | /**** NEW FEATURES enabled when Multi-touch support is enabled ****/
|
---|
212 |
|
---|
213 | #if (TS_MULTI_TOUCH_SUPPORTED == 1)
|
---|
214 | /**
|
---|
215 | * @brief Get the touch detailed informations on touch number 'touchIdx' (0..1)
|
---|
216 | * This touch detailed information contains :
|
---|
217 | * - weight that was applied to this touch
|
---|
218 | * - sub-area of the touch in the touch panel
|
---|
219 | * - event of linked to the touch (press down, lift up, ...)
|
---|
220 | * @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6x06).
|
---|
221 | * @param touchIdx : Passed index of the touch (0..1) on which we want to get the
|
---|
222 | * detailed information.
|
---|
223 | * @param pWeight : Pointer to to get the weight information of 'touchIdx'.
|
---|
224 | * @param pArea : Pointer to to get the sub-area information of 'touchIdx'.
|
---|
225 | * @param pEvent : Pointer to to get the event information of 'touchIdx'.
|
---|
226 |
|
---|
227 | * @retval None.
|
---|
228 | */
|
---|
229 | static ER
|
---|
230 | ft6x06_TS_GetTouchInfo(TouchScreen_Handle_t *hts,
|
---|
231 | uint32_t touchIdx,
|
---|
232 | uint32_t * pWeight,
|
---|
233 | uint32_t * pArea,
|
---|
234 | uint32_t * pEvent)
|
---|
235 | {
|
---|
236 | uint8_t regAddress = 0;
|
---|
237 | uint8_t dataxy[3];
|
---|
238 | ER ercd = E_OK;
|
---|
239 |
|
---|
240 | if(touchIdx < hts->currActiveTouchNb){
|
---|
241 | switch(touchIdx){
|
---|
242 | case 0 :
|
---|
243 | regAddress = FT6206_P1_WEIGHT_REG;
|
---|
244 | break;
|
---|
245 | case 1 :
|
---|
246 | regAddress = FT6206_P2_WEIGHT_REG;
|
---|
247 | break;
|
---|
248 | default :
|
---|
249 | break;
|
---|
250 | } /* end switch(touchIdx) */
|
---|
251 |
|
---|
252 | /* Read weight, area and Event Id of touch index */
|
---|
253 | ercd = i2c_memread(hts->hi2c, hts->I2C_Address, (uint16_t)regAddress, I2C_MEMADD_SIZE_8BIT, dataxy, sizeof(dataxy), 1000);
|
---|
254 |
|
---|
255 | /* Return weight of touch index */
|
---|
256 | *pWeight = (dataxy[0] & FT6206_TOUCH_WEIGHT_MASK) >> FT6206_TOUCH_WEIGHT_SHIFT;
|
---|
257 | /* Return area of touch index */
|
---|
258 | *pArea = (dataxy[1] & FT6206_TOUCH_AREA_MASK) >> FT6206_TOUCH_AREA_SHIFT;
|
---|
259 | /* Return Event Id of touch index */
|
---|
260 | *pEvent = (dataxy[2] & FT6206_TOUCH_EVT_FLAG_MASK) >> FT6206_TOUCH_EVT_FLAG_SHIFT;
|
---|
261 | } /* of if(touchIdx < ft6x06_handle.currActiveTouchNb) */
|
---|
262 | return ercd;
|
---|
263 | }
|
---|
264 |
|
---|
265 | #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
|
---|
266 |
|
---|
267 | #if (TS_AUTO_CALIBRATION_SUPPORTED == 1)
|
---|
268 | /**
|
---|
269 | * @brief Start TouchScreen calibration phase
|
---|
270 | * @param DeviceAddr: FT6206 Device address for communication on I2C Bus.
|
---|
271 | * @retval Status FT6206_STATUS_OK or FT6206_STATUS_NOT_OK.
|
---|
272 | */
|
---|
273 | static ER
|
---|
274 | ft6x06_TS_Calibration(TouchScreen_Handle_t *hts)
|
---|
275 | {
|
---|
276 | uint32_t nbAttempt = 0;
|
---|
277 | volatile uint8_t ucReadData;
|
---|
278 | volatile uint8_t regValue;
|
---|
279 | uint8_t bEndCalibration = 0;
|
---|
280 | ER ercd = E_OK;
|
---|
281 |
|
---|
282 | /* >> Calibration sequence start */
|
---|
283 |
|
---|
284 | /* Switch FT6206 back to factory mode to calibrate */
|
---|
285 | regValue = (FT6206_DEV_MODE_FACTORY & FT6206_DEV_MODE_MASK) << FT6206_DEV_MODE_SHIFT;
|
---|
286 | ercd = i2c_memwrite(hts->hi2c, hts->I2C_Address, (uint16_t)FT6206_DEV_MODE_REG, I2C_MEMADD_SIZE_8BIT, (uint8_t*)®Value, 1, 1000);
|
---|
287 | if(ercd != E_OK)
|
---|
288 | return ercd;
|
---|
289 |
|
---|
290 | /* Read back the same register FT6206_DEV_MODE_REG */
|
---|
291 | ercd = i2c_memread(hts->hi2c, hts->I2C_Address, (uint16_t)FT6206_GEST_ID_REG, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&ucReadData, 1, 1000);
|
---|
292 | if(ercd != E_OK)
|
---|
293 | return ercd;
|
---|
294 |
|
---|
295 | dly_tsk(300); /* Wait 300 ms */
|
---|
296 |
|
---|
297 | if(((ucReadData & (FT6206_DEV_MODE_MASK << FT6206_DEV_MODE_SHIFT)) >> FT6206_DEV_MODE_SHIFT) != FT6206_DEV_MODE_FACTORY ){
|
---|
298 | /* Return error to caller */
|
---|
299 | return E_OBJ;
|
---|
300 | }
|
---|
301 |
|
---|
302 | /* Start calibration command */
|
---|
303 | regValue = 0x04;
|
---|
304 | ercd = i2c_memwrite(hts->hi2c, hts->I2C_Address, (uint16_t)FT6206_TD_STAT_REG, I2C_MEMADD_SIZE_8BIT, (uint8_t*)®Value, 1, 1000);
|
---|
305 | if(ercd != E_OK)
|
---|
306 | return ercd;
|
---|
307 |
|
---|
308 | dly_tsk(300); /* Wait 300 ms */
|
---|
309 |
|
---|
310 | /* 100 attempts to wait switch from factory mode (calibration) to working mode */
|
---|
311 | for (nbAttempt=0; ((nbAttempt < 100) && (!bEndCalibration)) ; nbAttempt++){
|
---|
312 | ercd = i2c_memread(hts->hi2c, hts->I2C_Address, (uint16_t)FT6206_DEV_MODE_REG, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&ucReadData, 1, 1000);
|
---|
313 | if(ercd != E_OK)
|
---|
314 | return ercd;
|
---|
315 |
|
---|
316 | ucReadData = (ucReadData & (FT6206_DEV_MODE_MASK << FT6206_DEV_MODE_SHIFT)) >> FT6206_DEV_MODE_SHIFT;
|
---|
317 | if(ucReadData == FT6206_DEV_MODE_WORKING){
|
---|
318 | /* Auto Switch to FT6206_DEV_MODE_WORKING : means calibration have ended */
|
---|
319 | bEndCalibration = 1; /* exit for loop */
|
---|
320 | }
|
---|
321 | dly_tsk(200); /* Wait 200 ms */
|
---|
322 | }
|
---|
323 |
|
---|
324 | /* Calibration sequence end << */
|
---|
325 | return ercd;
|
---|
326 | }
|
---|
327 | #endif /* TS_AUTO_CALIBRATION_SUPPORTED == 1 */
|
---|
328 |
|
---|
329 | /**
|
---|
330 | * @brief Initializes and configures the touch screen functionalities and
|
---|
331 | * configures all necessary hardware resources (GPIOs, I2C, clocks..)
|
---|
332 | * with a given orientation
|
---|
333 | * @param ts_SizeX : Maximum X size of the TS area on LCD
|
---|
334 | * @param ts_SizeY : Maximum Y size of the TS area on LCD
|
---|
335 | * @param orientation : TS_ORIENTATION_LANDSCAPE or TS_ORIENTATION_PORTRAIT
|
---|
336 | * @retval TS_OK if all initializations are OK. Other value if error.
|
---|
337 | */
|
---|
338 | ER
|
---|
339 | touchscreen_init(TouchScreen_Handle_t *hts, uint16_t ts_SizeX, uint16_t ts_SizeY, uint8_t orientation)
|
---|
340 | {
|
---|
341 | GPIO_Init_t GPIO_Init_Data;
|
---|
342 | ER ercd = E_OK;
|
---|
343 | uint8_t ts_id = 0;
|
---|
344 |
|
---|
345 | /* Note : I2C_Address is un-initialized here, but is not used at all in init function */
|
---|
346 | /* but the prototype of Init() is like that in template and should be respected */
|
---|
347 |
|
---|
348 | /* Initialize the communication channel to sensor (I2C) if necessary */
|
---|
349 | /* that is initialization is done only once after a power up */
|
---|
350 | hts->tsOrientation = TS_SWAP_NONE;
|
---|
351 | if(hts->I2C_Address == 0)
|
---|
352 | hts->I2C_Address = TS_I2C_ADDRESS;
|
---|
353 | hts->initialized = false;
|
---|
354 | if(hts->pcb->reset_gpio_base){
|
---|
355 | sil_orw_mem((uint32_t *)(hts->pcb->reset_clk_base), hts->pcb->reset_clk_bit);
|
---|
356 | GPIO_Init_Data.mode = hts->pcb->reset_gpio_mode;
|
---|
357 | GPIO_Init_Data.otype = hts->pcb->reset_gpio_otype;
|
---|
358 | GPIO_Init_Data.pull = hts->pcb->reset_gpio_pull;
|
---|
359 | GPIO_Init_Data.speed = hts->pcb->reset_gpio_speed;
|
---|
360 | gpio_setup(hts->pcb->reset_gpio_base, &GPIO_Init_Data, hts->pcb->reset_gpio_pinno);
|
---|
361 | if(hts->pcb->reset_gpio_release == 0)
|
---|
362 | sil_wrw_mem((uint32_t *)(hts->pcb->reset_gpio_base+TOFF_GPIO_BSRR), (1<<hts->pcb->reset_gpio_pinno)<<16);
|
---|
363 | else
|
---|
364 | sil_wrw_mem((uint32_t *)(hts->pcb->reset_gpio_base+TOFF_GPIO_BSRR), (1<<hts->pcb->reset_gpio_pinno));
|
---|
365 | }
|
---|
366 |
|
---|
367 | /* Scan FT6x36 TouchScreen IC controller ID register by I2C Read */
|
---|
368 | /* Verify this is a FT6x36, otherwise this is an error case */
|
---|
369 | ercd = ft6x06_ReadID(hts, &ts_id);
|
---|
370 | if(ercd != E_OK)
|
---|
371 | return ercd;
|
---|
372 | if(ts_id == FT6x36_ID_VALUE){
|
---|
373 | /* Found FT6x36 : Initialize the TS driver structure */
|
---|
374 | /* Get LCD chosen orientation */
|
---|
375 | if(orientation == TS_ORIENTATION_PORTRAIT){
|
---|
376 | hts->tsOrientation = TS_SWAP_X | TS_SWAP_Y;
|
---|
377 | }
|
---|
378 | else if(orientation == TS_ORIENTATION_LANDSCAPE_ROT180){
|
---|
379 | hts->tsOrientation = TS_SWAP_XY;
|
---|
380 | }
|
---|
381 | else{
|
---|
382 | hts->tsOrientation = TS_SWAP_XY | TS_SWAP_Y;
|
---|
383 | }
|
---|
384 | hts->max_width = FT_6206_MAX_WIDTH_HEIGHT;
|
---|
385 | hts->max_height = FT_6206_MAX_WIDTH_HEIGHT;
|
---|
386 | }
|
---|
387 | /* Scan FT6xx6 TouchScreen IC controller ID register by I2C Read */
|
---|
388 | /* Verify this is a FT6206 or FT6336G, otherwise this is an error case */
|
---|
389 | else if(ts_id == FT6206_ID_VALUE){
|
---|
390 | /* Found FT6206 : Initialize the TS driver structure */
|
---|
391 | /* Get LCD chosen orientation */
|
---|
392 | if(ts_SizeX < ts_SizeY){
|
---|
393 | hts->tsOrientation = TS_SWAP_NONE;
|
---|
394 | }
|
---|
395 | else{
|
---|
396 | hts->tsOrientation = TS_SWAP_XY | TS_SWAP_Y;
|
---|
397 | }
|
---|
398 | hts->max_width = FT_6206_MAX_WIDTH;
|
---|
399 | hts->max_height = FT_6206_MAX_HEIGHT;
|
---|
400 | }
|
---|
401 |
|
---|
402 | if(ercd == E_OK){
|
---|
403 | /* Software reset the TouchScreen */
|
---|
404 | /* Calibrate, Configure and Start the TouchScreen driver */
|
---|
405 | #if (TS_AUTO_CALIBRATION_SUPPORTED == 1)
|
---|
406 | /* Hw Calibration sequence start : should be done once after each power up */
|
---|
407 | /* This is called internal calibration of the touch screen */
|
---|
408 | ft6x06_TS_Calibration(hts);
|
---|
409 | #endif
|
---|
410 |
|
---|
411 | /* By default set FT6206 IC in Polling mode : no INT generation on FT6206 for new touch available */
|
---|
412 | /* Note TS_INT is active low */
|
---|
413 | ercd = touchscreen_disable_it(hts);
|
---|
414 | /* Configure Interrupt mode for TS_INT pin falling edge : when a new touch is available */
|
---|
415 | /* TS_INT pin is active on low level on new touch available */
|
---|
416 | if(ercd == E_OK && hts->pcb->int_gpio_base != 0){
|
---|
417 | exti_func[hts->pcb->int_gpio_pinno] = hts->ifunc;
|
---|
418 | sil_orw_mem((uint32_t *)hts->pcb->int_clk_base, hts->pcb->int_clk_bit);
|
---|
419 | GPIO_Init_Data.mode = hts->pcb->int_gpio_mode;
|
---|
420 | GPIO_Init_Data.pull = hts->pcb->int_gpio_pull;
|
---|
421 | GPIO_Init_Data.speed = hts->pcb->int_gpio_speed;
|
---|
422 | gpio_setup(hts->pcb->int_gpio_base, &GPIO_Init_Data, hts->pcb->int_gpio_pinno);
|
---|
423 | if(hts->enable_it)
|
---|
424 | ercd = touchscreen_enable_it(hts);
|
---|
425 | }
|
---|
426 | if(ercd == E_OK)
|
---|
427 | hts->initialized = true;
|
---|
428 | }
|
---|
429 | return (ercd);
|
---|
430 | }
|
---|
431 |
|
---|
432 | /**
|
---|
433 | * @brief Returns status and positions of the touch screen.
|
---|
434 | * @param TS_State: Pointer to touch screen current state structure
|
---|
435 | * @retval TS_OK if all initializations are OK. Other value if error.
|
---|
436 | */
|
---|
437 | ER
|
---|
438 | touchscreen_getstate(TouchScreen_Handle_t *hts, TS_StateTypeDef *TS_State)
|
---|
439 | {
|
---|
440 | static uint32_t _x[TS_MAX_NB_TOUCH] = {0, 0};
|
---|
441 | static uint32_t _y[TS_MAX_NB_TOUCH] = {0, 0};
|
---|
442 | uint16_t tmp;
|
---|
443 | uint16_t Raw_x[TS_MAX_NB_TOUCH];
|
---|
444 | uint16_t Raw_y[TS_MAX_NB_TOUCH];
|
---|
445 | uint16_t xDiff;
|
---|
446 | uint16_t yDiff;
|
---|
447 | uint32_t index;
|
---|
448 | #if (TS_MULTI_TOUCH_SUPPORTED == 1)
|
---|
449 | uint32_t weight = 0;
|
---|
450 | uint32_t area = 0;
|
---|
451 | uint32_t event = 0;
|
---|
452 | #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
|
---|
453 | ER ercd = E_OK;
|
---|
454 |
|
---|
455 | /* Check and update the number of touches active detected */
|
---|
456 | ercd = ft6x06_TS_DetectTouch(hts);
|
---|
457 | if(ercd < 0)
|
---|
458 | return ercd;
|
---|
459 | if((TS_State->touchDetected = (uint8_t)ercd)){
|
---|
460 | for(index=0; index < TS_State->touchDetected; index++){
|
---|
461 | /* Get each touch coordinates */
|
---|
462 | ft6x06_TS_GetXY(hts, &(Raw_x[index]), &(Raw_y[index]));
|
---|
463 |
|
---|
464 | if(hts->tsOrientation & TS_SWAP_XY){
|
---|
465 | tmp = Raw_x[index];
|
---|
466 | Raw_x[index] = Raw_y[index];
|
---|
467 | Raw_y[index] = tmp;
|
---|
468 | }
|
---|
469 | if(hts->tsOrientation & TS_SWAP_X){
|
---|
470 | Raw_x[index] = hts->max_width - 1 - Raw_x[index];
|
---|
471 | }
|
---|
472 | if(hts->tsOrientation & TS_SWAP_Y){
|
---|
473 | Raw_y[index] = hts->max_height - 1 - Raw_y[index];
|
---|
474 | }
|
---|
475 |
|
---|
476 | xDiff = Raw_x[index] > _x[index]? (Raw_x[index] - _x[index]): (_x[index] - Raw_x[index]);
|
---|
477 | yDiff = Raw_y[index] > _y[index]? (Raw_y[index] - _y[index]): (_y[index] - Raw_y[index]);
|
---|
478 |
|
---|
479 | if((xDiff + yDiff) > 5){
|
---|
480 | _x[index] = Raw_x[index];
|
---|
481 | _y[index] = Raw_y[index];
|
---|
482 | }
|
---|
483 |
|
---|
484 | TS_State->touchX[index] = _x[index];
|
---|
485 | TS_State->touchY[index] = _y[index];
|
---|
486 |
|
---|
487 | #if (TS_MULTI_TOUCH_SUPPORTED == 1)
|
---|
488 |
|
---|
489 | /* Get touch info related to the current touch */
|
---|
490 | ercd = ft6x06_TS_GetTouchInfo(hts, index, &weight, &area, &event);
|
---|
491 |
|
---|
492 | /* Update TS_State structure */
|
---|
493 | TS_State->touchWeight[index] = weight;
|
---|
494 | TS_State->touchArea[index] = area;
|
---|
495 |
|
---|
496 | /* Remap touch event */
|
---|
497 | switch(event){
|
---|
498 | case FT6206_TOUCH_EVT_FLAG_PRESS_DOWN :
|
---|
499 | TS_State->touchEventId[index] = TOUCH_EVENT_PRESS_DOWN;
|
---|
500 | break;
|
---|
501 | case FT6206_TOUCH_EVT_FLAG_LIFT_UP :
|
---|
502 | TS_State->touchEventId[index] = TOUCH_EVENT_LIFT_UP;
|
---|
503 | break;
|
---|
504 | case FT6206_TOUCH_EVT_FLAG_CONTACT :
|
---|
505 | TS_State->touchEventId[index] = TOUCH_EVENT_CONTACT;
|
---|
506 | break;
|
---|
507 | case FT6206_TOUCH_EVT_FLAG_NO_EVENT :
|
---|
508 | TS_State->touchEventId[index] = TOUCH_EVENT_NO_EVT;
|
---|
509 | break;
|
---|
510 | default :
|
---|
511 | ercd = E_SYS;
|
---|
512 | break;
|
---|
513 | } /* of switch(event) */
|
---|
514 | if(ercd < 0)
|
---|
515 | return ercd;
|
---|
516 |
|
---|
517 | #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
|
---|
518 |
|
---|
519 | } /* of for(index=0; index < TS_State->touchDetected; index++) */
|
---|
520 |
|
---|
521 | #if (TS_MULTI_TOUCH_SUPPORTED == 1)
|
---|
522 | /* Get gesture Id */
|
---|
523 | ercd = touchscreen_get_gestureid(hts, TS_State);
|
---|
524 | #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
|
---|
525 |
|
---|
526 | } /* end of if(TS_State->touchDetected != 0) */
|
---|
527 | return ercd;
|
---|
528 | }
|
---|
529 |
|
---|
530 | /**
|
---|
531 | * @brief Configure the FT6206 device to generate IT on given INT pin
|
---|
532 | * connected to MCU as EXTI.
|
---|
533 | * @param DeviceAddr: Device address on communication Bus (Slave I2C address of FT6206).
|
---|
534 | * @retval None
|
---|
535 | */
|
---|
536 | ER
|
---|
537 | touchscreen_enable_it(TouchScreen_Handle_t *hts)
|
---|
538 | {
|
---|
539 | ER ercd;
|
---|
540 | uint8_t regValue = 0;
|
---|
541 | regValue = (FT6206_G_MODE_INTERRUPT_TRIGGER & (FT6206_G_MODE_INTERRUPT_MASK >> FT6206_G_MODE_INTERRUPT_SHIFT)) << FT6206_G_MODE_INTERRUPT_SHIFT;
|
---|
542 |
|
---|
543 | /* Set interrupt trigger mode in FT6206_GMODE_REG */
|
---|
544 | ercd = i2c_memwrite(hts->hi2c, hts->I2C_Address, (uint16_t)FT6206_GMODE_REG, I2C_MEMADD_SIZE_8BIT, (uint8_t*)®Value, 1, 1000);
|
---|
545 | return ercd;
|
---|
546 | }
|
---|
547 |
|
---|
548 | /**
|
---|
549 | * @brief Configure the FT6206 device to stop generating IT on the given INT pin
|
---|
550 | * connected to MCU as EXTI.
|
---|
551 | * @param DeviceAddr: Device address on communication Bus (Slave I2C address of FT6206).
|
---|
552 | * @retval None
|
---|
553 | */
|
---|
554 | ER touchscreen_disable_it(TouchScreen_Handle_t *hts)
|
---|
555 | {
|
---|
556 | ER ercd;
|
---|
557 | uint8_t regValue = 0;
|
---|
558 | regValue = (FT6206_G_MODE_INTERRUPT_POLLING | (FT6206_G_MODE_INTERRUPT_MASK >> FT6206_G_MODE_INTERRUPT_SHIFT)) << FT6206_G_MODE_INTERRUPT_SHIFT;
|
---|
559 |
|
---|
560 | /* Set interrupt polling mode in FT6206_GMODE_REG */
|
---|
561 | ercd = i2c_memwrite(hts->hi2c, hts->I2C_Address, (uint16_t)FT6206_GMODE_REG, I2C_MEMADD_SIZE_8BIT, (uint8_t*)®Value, 1, 1000);
|
---|
562 | return ercd;
|
---|
563 | }
|
---|
564 |
|
---|
565 | #if (TS_MULTI_TOUCH_SUPPORTED == 1)
|
---|
566 | /**
|
---|
567 | * @brief Update gesture Id following a touch detected.
|
---|
568 | * @param TS_State: Pointer to touch screen current state structure
|
---|
569 | * @retval TS_OK if all initializations are OK. Other value if error.
|
---|
570 | */
|
---|
571 | ER
|
---|
572 | touchscreen_get_gestureid(TouchScreen_Handle_t *hts, TS_StateTypeDef *TS_State)
|
---|
573 | {
|
---|
574 | uint32_t gestureId = 0;
|
---|
575 | volatile uint8_t ucReadData = 0;
|
---|
576 | ER ercd = E_OK;
|
---|
577 |
|
---|
578 | /* Get gesture Id */
|
---|
579 | ercd = i2c_memread(hts->hi2c, hts->I2C_Address, (uint16_t)FT6206_GEST_ID_REG, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&ucReadData, 1, 1000);
|
---|
580 | if(ercd != E_OK)
|
---|
581 | return ercd;
|
---|
582 |
|
---|
583 | gestureId = hts->I2C_Address;
|
---|
584 |
|
---|
585 | /* Remap gesture Id to a TS_GestureIdTypeDef value */
|
---|
586 | switch(gestureId){
|
---|
587 | case FT6206_GEST_ID_NO_GESTURE :
|
---|
588 | TS_State->gestureId = GEST_ID_NO_GESTURE;
|
---|
589 | break;
|
---|
590 | case FT6206_GEST_ID_MOVE_UP :
|
---|
591 | TS_State->gestureId = GEST_ID_MOVE_UP;
|
---|
592 | break;
|
---|
593 | case FT6206_GEST_ID_MOVE_RIGHT :
|
---|
594 | TS_State->gestureId = GEST_ID_MOVE_RIGHT;
|
---|
595 | break;
|
---|
596 | case FT6206_GEST_ID_MOVE_DOWN :
|
---|
597 | TS_State->gestureId = GEST_ID_MOVE_DOWN;
|
---|
598 | break;
|
---|
599 | case FT6206_GEST_ID_MOVE_LEFT :
|
---|
600 | TS_State->gestureId = GEST_ID_MOVE_LEFT;
|
---|
601 | break;
|
---|
602 | case FT6206_GEST_ID_ZOOM_IN :
|
---|
603 | TS_State->gestureId = GEST_ID_ZOOM_IN;
|
---|
604 | break;
|
---|
605 | case FT6206_GEST_ID_ZOOM_OUT :
|
---|
606 | TS_State->gestureId = GEST_ID_ZOOM_OUT;
|
---|
607 | break;
|
---|
608 | default :
|
---|
609 | ercd = E_OBJ;
|
---|
610 | break;
|
---|
611 | } /* of switch(gestureId) */
|
---|
612 | return ercd;
|
---|
613 | }
|
---|
614 | #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
|
---|
615 |
|
---|
616 |
|
---|
617 | /** @defgroup STM32F723E-DISCOVERY_TS_Private_Functions TS Private Functions
|
---|
618 | * @{
|
---|
619 | */
|
---|
620 |
|
---|
621 | #if (TS_MULTI_TOUCH_SUPPORTED == 1)
|
---|
622 | /**
|
---|
623 | * @brief Function used to reset all touch data before a new acquisition
|
---|
624 | * of touch information.
|
---|
625 | * @param TS_State: Pointer to touch screen current state structure
|
---|
626 | * @retval TS_OK if OK, TE_ERROR if problem found.
|
---|
627 | */
|
---|
628 | ER
|
---|
629 | touchscreen_reset_data(TS_StateTypeDef *TS_State)
|
---|
630 | {
|
---|
631 | uint32_t index;
|
---|
632 |
|
---|
633 | if(TS_State != (TS_StateTypeDef *)NULL){
|
---|
634 | TS_State->gestureId = GEST_ID_NO_GESTURE;
|
---|
635 | TS_State->touchDetected = 0;
|
---|
636 |
|
---|
637 | for(index = 0; index < TS_MAX_NB_TOUCH; index++){
|
---|
638 | TS_State->touchX[index] = 0;
|
---|
639 | TS_State->touchY[index] = 0;
|
---|
640 | TS_State->touchArea[index] = 0;
|
---|
641 | TS_State->touchEventId[index] = TOUCH_EVENT_NO_EVT;
|
---|
642 | TS_State->touchWeight[index] = 0;
|
---|
643 | }
|
---|
644 | return E_OK;
|
---|
645 | }
|
---|
646 | else
|
---|
647 | return E_PAR;
|
---|
648 | }
|
---|
649 | #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
|
---|
650 |
|
---|