source: azure_iot_hub_f767zi/trunk/asp_baseplatform/gdic/stts_ft5336/stts_ft5336.h@ 457

Last change on this file since 457 was 457, checked in by coas-nagasima, 4 years ago

ファイルを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 16.3 KB
Line 
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>&copy; 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#ifndef _STTS_FT5336_H_
70#define _STTS_FT5336_H_
71
72#ifdef __cplusplus
73 extern "C" {
74#endif
75
76#include <kernel.h>
77#include <t_syslog.h>
78#include <t_stdlib.h>
79#include "syssvc/serial.h"
80#include "syssvc/syslog.h"
81#include "device.h"
82#include "i2c.h"
83
84/* Set Multi-touch as supported */
85#if !defined(TS_MONO_TOUCH_SUPPORTED)
86#define TS_MULTI_TOUCH_SUPPORTED 1
87#endif /* TS_MONO_TOUCH_SUPPORTED */
88
89
90 /* I2C Slave address of touchscreen FocalTech FT5336 */
91#define FT5336_I2C_SLAVE_ADDRESS 0x70
92
93 /* Maximum border values of the touchscreen pad */
94#define FT5336_MAX_WIDTH 480 /* Touchscreen pad max width */
95#define FT5336_MAX_HEIGHT 272 /* Touchscreen pad max height */
96
97 /* Max detectable simultaneous touches */
98#define FT5336_MAX_DETECTABLE_TOUCH 0x05
99
100 /**
101 * @brief : Definitions for FT5336 I2C register addresses on 8 bit
102 **/
103
104 /* Current mode register of the FT5336 (R/W) */
105#define FT5336_DEV_MODE_REG 0x00
106
107 /* Possible values of FT5336_DEV_MODE_REG */
108#define FT5336_DEV_MODE_WORKING 0x00
109#define FT5336_DEV_MODE_FACTORY 0x04
110
111#define FT5336_DEV_MODE_MASK 0x07
112#define FT5336_DEV_MODE_SHIFT 0x04
113
114 /* Gesture ID register */
115#define FT5336_GEST_ID_REG 0x01
116
117 /* Possible values of FT5336_GEST_ID_REG */
118#define FT5336_GEST_ID_NO_GESTURE 0x00
119#define FT5336_GEST_ID_MOVE_UP 0x10
120#define FT5336_GEST_ID_MOVE_RIGHT 0x14
121#define FT5336_GEST_ID_MOVE_DOWN 0x18
122#define FT5336_GEST_ID_MOVE_LEFT 0x1C
123#define FT5336_GEST_ID_SINGLE_CLICK 0x20
124#define FT5336_GEST_ID_DOUBLE_CLICK 0x22
125#define FT5336_GEST_ID_ROTATE_CLOCKWISE 0x28
126#define FT5336_GEST_ID_ROTATE_C_CLOCKWISE 0x29
127#define FT5336_GEST_ID_ZOOM_IN 0x40
128#define FT5336_GEST_ID_ZOOM_OUT 0x49
129
130 /* Touch Data Status register : gives number of active touch points (0..5) */
131#define FT5336_TD_STAT_REG 0x02
132
133 /* Values related to FT5336_TD_STAT_REG */
134#define FT5336_TD_STAT_MASK 0x0F
135#define FT5336_TD_STAT_SHIFT 0x00
136
137 /* Values Pn_XH and Pn_YH related */
138#define FT5336_TOUCH_EVT_FLAG_PRESS_DOWN 0x00
139#define FT5336_TOUCH_EVT_FLAG_LIFT_UP 0x01
140#define FT5336_TOUCH_EVT_FLAG_CONTACT 0x02
141#define FT5336_TOUCH_EVT_FLAG_NO_EVENT 0x03
142
143#define FT5336_TOUCH_EVT_FLAG_SHIFT 0x06
144#define FT5336_TOUCH_EVT_FLAG_MASK (3 << FT5336_TOUCH_EVT_FLAG_SHIFT)
145
146#define FT5336_TOUCH_POS_MSB_MASK 0x0F
147#define FT5336_TOUCH_POS_MSB_SHIFT 0x00
148
149 /* Values Pn_XL and Pn_YL related */
150#define FT5336_TOUCH_POS_LSB_MASK 0xFF
151#define FT5336_TOUCH_POS_LSB_SHIFT 0x00
152
153#define FT5336_P1_XH_REG 0x03
154#define FT5336_P1_XL_REG 0x04
155#define FT5336_P1_YH_REG 0x05
156#define FT5336_P1_YL_REG 0x06
157
158/* Touch Pressure register value (R) */
159#define FT5336_P1_WEIGHT_REG 0x07
160
161/* Values Pn_WEIGHT related */
162#define FT5336_TOUCH_WEIGHT_MASK 0xFF
163#define FT5336_TOUCH_WEIGHT_SHIFT 0x00
164
165/* Touch area register */
166#define FT5336_P1_MISC_REG 0x08
167
168/* Values related to FT5336_Pn_MISC_REG */
169#define FT5336_TOUCH_AREA_MASK (0x04 << 4)
170#define FT5336_TOUCH_AREA_SHIFT 0x04
171
172#define FT5336_P2_XH_REG 0x09
173#define FT5336_P2_XL_REG 0x0A
174#define FT5336_P2_YH_REG 0x0B
175#define FT5336_P2_YL_REG 0x0C
176#define FT5336_P2_WEIGHT_REG 0x0D
177#define FT5336_P2_MISC_REG 0x0E
178
179#define FT5336_P3_XH_REG 0x0F
180#define FT5336_P3_XL_REG 0x10
181#define FT5336_P3_YH_REG 0x11
182#define FT5336_P3_YL_REG 0x12
183#define FT5336_P3_WEIGHT_REG 0x13
184#define FT5336_P3_MISC_REG 0x14
185
186#define FT5336_P4_XH_REG 0x15
187#define FT5336_P4_XL_REG 0x16
188#define FT5336_P4_YH_REG 0x17
189#define FT5336_P4_YL_REG 0x18
190#define FT5336_P4_WEIGHT_REG 0x19
191#define FT5336_P4_MISC_REG 0x1A
192
193#define FT5336_P5_XH_REG 0x1B
194#define FT5336_P5_XL_REG 0x1C
195#define FT5336_P5_YH_REG 0x1D
196#define FT5336_P5_YL_REG 0x1E
197#define FT5336_P5_WEIGHT_REG 0x1F
198#define FT5336_P5_MISC_REG 0x20
199
200#define FT5336_P6_XH_REG 0x21
201#define FT5336_P6_XL_REG 0x22
202#define FT5336_P6_YH_REG 0x23
203#define FT5336_P6_YL_REG 0x24
204#define FT5336_P6_WEIGHT_REG 0x25
205#define FT5336_P6_MISC_REG 0x26
206
207#define FT5336_P7_XH_REG 0x27
208#define FT5336_P7_XL_REG 0x28
209#define FT5336_P7_YH_REG 0x29
210#define FT5336_P7_YL_REG 0x2A
211#define FT5336_P7_WEIGHT_REG 0x2B
212#define FT5336_P7_MISC_REG 0x2C
213
214#define FT5336_P8_XH_REG 0x2D
215#define FT5336_P8_XL_REG 0x2E
216#define FT5336_P8_YH_REG 0x2F
217#define FT5336_P8_YL_REG 0x30
218#define FT5336_P8_WEIGHT_REG 0x31
219#define FT5336_P8_MISC_REG 0x32
220
221#define FT5336_P9_XH_REG 0x33
222#define FT5336_P9_XL_REG 0x34
223#define FT5336_P9_YH_REG 0x35
224#define FT5336_P9_YL_REG 0x36
225#define FT5336_P9_WEIGHT_REG 0x37
226#define FT5336_P9_MISC_REG 0x38
227
228#define FT5336_P10_XH_REG 0x39
229#define FT5336_P10_XL_REG 0x3A
230#define FT5336_P10_YH_REG 0x3B
231#define FT5336_P10_YL_REG 0x3C
232#define FT5336_P10_WEIGHT_REG 0x3D
233#define FT5336_P10_MISC_REG 0x3E
234
235 /* Threshold for touch detection */
236#define FT5336_TH_GROUP_REG 0x80
237
238 /* Values FT5336_TH_GROUP_REG : threshold related */
239#define FT5336_THRESHOLD_MASK 0xFF
240#define FT5336_THRESHOLD_SHIFT 0x00
241
242 /* Filter function coefficients */
243#define FT5336_TH_DIFF_REG 0x85
244
245 /* Control register */
246#define FT5336_CTRL_REG 0x86
247
248 /* Values related to FT5336_CTRL_REG */
249
250 /* Will keep the Active mode when there is no touching */
251#define FT5336_CTRL_KEEP_ACTIVE_MODE 0x00
252
253 /* Switching from Active mode to Monitor mode automatically when there is no touching */
254#define FT5336_CTRL_KEEP_AUTO_SWITCH_MONITOR_MODE 0x01
255
256 /* The time period of switching from Active mode to Monitor mode when there is no touching */
257#define FT5336_TIMEENTERMONITOR_REG 0x87
258
259 /* Report rate in Active mode */
260#define FT5336_PERIODACTIVE_REG 0x88
261
262 /* Report rate in Monitor mode */
263#define FT5336_PERIODMONITOR_REG 0x89
264
265 /* The value of the minimum allowed angle while Rotating gesture mode */
266#define FT5336_RADIAN_VALUE_REG 0x91
267
268 /* Maximum offset while Moving Left and Moving Right gesture */
269#define FT5336_OFFSET_LEFT_RIGHT_REG 0x92
270
271 /* Maximum offset while Moving Up and Moving Down gesture */
272#define FT5336_OFFSET_UP_DOWN_REG 0x93
273
274 /* Minimum distance while Moving Left and Moving Right gesture */
275#define FT5336_DISTANCE_LEFT_RIGHT_REG 0x94
276
277 /* Minimum distance while Moving Up and Moving Down gesture */
278#define FT5336_DISTANCE_UP_DOWN_REG 0x95
279
280 /* Maximum distance while Zoom In and Zoom Out gesture */
281#define FT5336_DISTANCE_ZOOM_REG 0x96
282
283 /* High 8-bit of LIB Version info */
284#define FT5336_LIB_VER_H_REG 0xA1
285
286 /* Low 8-bit of LIB Version info */
287#define FT5336_LIB_VER_L_REG 0xA2
288
289 /* Chip Selecting */
290#define FT5336_CIPHER_REG 0xA3
291
292 /* Interrupt mode register (used when in interrupt mode) */
293#define FT5336_GMODE_REG 0xA4
294
295#define FT5336_G_MODE_INTERRUPT_MASK 0x03
296#define FT5336_G_MODE_INTERRUPT_SHIFT 0x00
297
298 /* Possible values of FT5336_GMODE_REG */
299#define FT5336_G_MODE_INTERRUPT_POLLING 0x00
300#define FT5336_G_MODE_INTERRUPT_TRIGGER 0x01
301
302 /* Current power mode the FT5336 system is in (R) */
303#define FT5336_PWR_MODE_REG 0xA5
304
305 /* FT5336 firmware version */
306#define FT5336_FIRMID_REG 0xA6
307
308 /* FT5336 Chip identification register */
309#define FT5336_CHIP_ID_REG 0xA8
310
311 /* Possible values of FT5336_CHIP_ID_REG */
312#define FT5336_ID_VALUE 0x51
313
314 /* Release code version */
315#define FT5336_RELEASE_CODE_ID_REG 0xAF
316
317 /* Current operating mode the FT5336 system is in (R) */
318#define FT5336_STATE_REG 0xBC
319
320
321/** @typedef TouchScreen_Handle_t
322 * TouchScreen Handle definition.
323 */
324typedef struct
325{
326 I2C_Handle_t *hi2c;
327 uint16_t tsXBoundary;
328 uint16_t tsYBoundary;
329 uint8_t tsOrientation;
330 uint8_t I2C_Address;
331
332 /* field holding the current number of simultaneous active touches */
333 uint8_t currActiveTouchNb;
334
335 /* field holding the touch index currently managed */
336 uint8_t currActiveTouchIdx;
337
338} TouchScreen_Handle_t;
339
340/** @brief With FT5336 : maximum 5 touches detected simultaneously
341 */
342#define TS_MAX_NB_TOUCH ((uint32_t) FT5336_MAX_DETECTABLE_TOUCH)
343
344#define TS_NO_IRQ_PENDING ((uint8_t) 0)
345#define TS_IRQ_PENDING ((uint8_t) 1)
346
347#define TS_SWAP_NONE ((uint8_t) 0x01)
348#define TS_SWAP_X ((uint8_t) 0x02)
349#define TS_SWAP_Y ((uint8_t) 0x04)
350#define TS_SWAP_XY ((uint8_t) 0x08)
351
352#define TS_ORIENTATION_PORTRAIT ((uint8_t) 0x00)
353#define TS_ORIENTATION_LANDSCAPE ((uint8_t) 0x01)
354#define TS_ORIENTATION_LANDSCAPE_ROT180 ((uint8_t) 0x02)
355
356/**
357* @brief TS_StateTypeDef
358* Define TS State structure
359*/
360typedef struct
361{
362 uint8_t touchDetected; /* Total number of active touches detected at last scan */
363 uint16_t touchX[TS_MAX_NB_TOUCH]; /* Touch X[0], X[1] coordinates on 12 bits */
364 uint16_t touchY[TS_MAX_NB_TOUCH]; /* Touch Y[0], Y[1] coordinates on 12 bits */
365
366#if (TS_MULTI_TOUCH_SUPPORTED == 1)
367 uint8_t touchWeight[TS_MAX_NB_TOUCH]; /* Touch_Weight[0], Touch_Weight[1] : weight property of touches */
368 uint8_t touchEventId[TS_MAX_NB_TOUCH]; /* Touch_EventId[0], Touch_EventId[1] : take value of type @ref TS_TouchEventTypeDef */
369 uint8_t touchArea[TS_MAX_NB_TOUCH]; /*!< Touch_Area[0], Touch_Area[1] : touch area of each touch */
370 uint32_t gestureId; /*!< type of gesture detected : take value of type @ref TS_GestureIdTypeDef */
371#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
372} TS_StateTypeDef;
373
374
375/**
376 * @brief TS_GestureIdTypeDef
377 * Define Possible managed gesture identification values returned by touch screen
378 * driver.
379 */
380typedef enum
381{
382 GEST_ID_NO_GESTURE = 0x00, /*!< Gesture not defined / recognized */
383 GEST_ID_MOVE_UP = 0x01, /*!< Gesture Move Up */
384 GEST_ID_MOVE_RIGHT = 0x02, /*!< Gesture Move Right */
385 GEST_ID_MOVE_DOWN = 0x03, /*!< Gesture Move Down */
386 GEST_ID_MOVE_LEFT = 0x04, /*!< Gesture Move Left */
387 GEST_ID_ZOOM_IN = 0x05, /*!< Gesture Zoom In */
388 GEST_ID_ZOOM_OUT = 0x06, /*!< Gesture Zoom Out */
389 GEST_ID_NB_MAX = 0x07 /*!< max number of gesture id */
390} TS_GestureIdTypeDef;
391
392/**
393 * @brief TS_TouchEventTypeDef
394 * Define Possible touch events kind as returned values
395 * by touch screen IC Driver.
396 */
397typedef enum
398{
399 TOUCH_EVENT_NO_EVT = 0x00, /*!< Touch Event : undetermined */
400 TOUCH_EVENT_PRESS_DOWN = 0x01, /*!< Touch Event Press Down */
401 TOUCH_EVENT_LIFT_UP = 0x02, /*!< Touch Event Lift Up */
402 TOUCH_EVENT_CONTACT = 0x03, /*!< Touch Event Contact */
403 TOUCH_EVENT_NB_MAX = 0x04 /*!< max number of touch events kind */
404} TS_TouchEventTypeDef;
405
406/**
407 * @brief Table for touchscreen event information display on LCD :
408 * table indexed on enum @ref TS_TouchEventTypeDef information
409 */
410extern char * ts_event_string_tab[TOUCH_EVENT_NB_MAX];
411
412/**
413 * @brief Table for touchscreen gesture Id information display on LCD : table indexed
414 * on enum @ref TS_GestureIdTypeDef information
415 */
416extern char * ts_gesture_id_string_tab[GEST_ID_NB_MAX];
417
418extern ER touchscreen_init(TouchScreen_Handle_t *hts, uint16_t ts_SizeX, uint16_t ts_SizeY, uint8_t orientation);
419extern ER touchscreen_getstate(TouchScreen_Handle_t *hts, TS_StateTypeDef *TS_State);
420extern ER touchscreen_reset_data(TS_StateTypeDef *TS_State);
421
422
423#ifdef __cplusplus
424}
425#endif
426
427#endif /* _STTS_FT5336_H_ */
428
Note: See TracBrowser for help on using the repository browser.