BSP files for STM32H747I-Discovery Copy from ST Cube delivery
Dependents: DISCO_H747I_LCD_demo DISCO_H747I_AUDIO_demo
STM32H747I-Discovery/stm32h747i_discovery_ts.c@3:bc403474b366, 2019-11-06 (annotated)
- Committer:
- Jerome Coutant
- Date:
- Wed Nov 06 11:32:01 2019 +0100
- Revision:
- 3:bc403474b366
- Parent:
- 0:146cf26a9bbb
Add PDM lib
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jerome Coutant
0:146cf26a9bbb
|
1
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
2
|
******************************************************************************
|
|
Jerome Coutant
0:146cf26a9bbb
|
3
|
* @file stm32h747i_discovery_ts.c
|
|
Jerome Coutant
0:146cf26a9bbb
|
4
|
* @author MCD Application Team
|
|
Jerome Coutant
0:146cf26a9bbb
|
5
|
* @brief This file provides a set of functions needed to manage the Touch
|
|
Jerome Coutant
0:146cf26a9bbb
|
6
|
* Screen on STM32H747I_DISCOVERY discovery board.
|
|
Jerome Coutant
0:146cf26a9bbb
|
7
|
******************************************************************************
|
|
Jerome Coutant
0:146cf26a9bbb
|
8
|
* @attention
|
|
Jerome Coutant
0:146cf26a9bbb
|
9
|
*
|
|
Jerome Coutant
0:146cf26a9bbb
|
10
|
* <h2><center>© Copyright (c) 2019 STMicroelectronics.
|
|
Jerome Coutant
0:146cf26a9bbb
|
11
|
* All rights reserved.</center></h2>
|
|
Jerome Coutant
0:146cf26a9bbb
|
12
|
*
|
|
Jerome Coutant
0:146cf26a9bbb
|
13
|
* This software component is licensed by ST under BSD 3-Clause license,
|
|
Jerome Coutant
0:146cf26a9bbb
|
14
|
* the "License"; You may not use this file except in compliance with the
|
|
Jerome Coutant
0:146cf26a9bbb
|
15
|
* License. You may obtain a copy of the License at:
|
|
Jerome Coutant
0:146cf26a9bbb
|
16
|
* opensource.org/licenses/BSD-3-Clause
|
|
Jerome Coutant
0:146cf26a9bbb
|
17
|
*
|
|
Jerome Coutant
0:146cf26a9bbb
|
18
|
******************************************************************************
|
|
Jerome Coutant
0:146cf26a9bbb
|
19
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
20
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
21
|
/* File Info : -----------------------------------------------------------------
|
|
Jerome Coutant
0:146cf26a9bbb
|
22
|
User NOTES
|
|
Jerome Coutant
0:146cf26a9bbb
|
23
|
1. How To use this driver:
|
|
Jerome Coutant
0:146cf26a9bbb
|
24
|
--------------------------
|
|
Jerome Coutant
0:146cf26a9bbb
|
25
|
- This driver is used to drive the touch screen module of the STM32H747I_DISCOVERY
|
|
Jerome Coutant
0:146cf26a9bbb
|
26
|
discovery board on the K.O.D Optica Technology 480x800 TFT-LCD mounted on
|
|
Jerome Coutant
0:146cf26a9bbb
|
27
|
MB1166 daughter board. The touch screen driver IC inside the K.O.D module KM-040TMP-02
|
|
Jerome Coutant
0:146cf26a9bbb
|
28
|
is a FT6206 by Focal Tech.
|
|
Jerome Coutant
0:146cf26a9bbb
|
29
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
30
|
2. Driver description:
|
|
Jerome Coutant
0:146cf26a9bbb
|
31
|
---------------------
|
|
Jerome Coutant
0:146cf26a9bbb
|
32
|
+ Initialization steps:
|
|
Jerome Coutant
0:146cf26a9bbb
|
33
|
o Initialize the TS module using the BSP_TS_Init() function. This
|
|
Jerome Coutant
0:146cf26a9bbb
|
34
|
function includes the MSP layer hardware resources initialization and the
|
|
Jerome Coutant
0:146cf26a9bbb
|
35
|
communication layer configuration to start the TS use. The LCD size properties
|
|
Jerome Coutant
0:146cf26a9bbb
|
36
|
(x and y) are passed as parameters.
|
|
Jerome Coutant
0:146cf26a9bbb
|
37
|
o If TS interrupt mode is desired, you must configure the TS interrupt mode
|
|
Jerome Coutant
0:146cf26a9bbb
|
38
|
by calling the function BSP_TS_ITConfig(). The TS interrupt mode is generated
|
|
Jerome Coutant
0:146cf26a9bbb
|
39
|
as an external interrupt whenever a touch is detected.
|
|
Jerome Coutant
0:146cf26a9bbb
|
40
|
The interrupt mode internally uses the IO functionalities driver driven by
|
|
Jerome Coutant
0:146cf26a9bbb
|
41
|
the IO expander, to configure the IT line.
|
|
Jerome Coutant
0:146cf26a9bbb
|
42
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
43
|
+ Touch screen use
|
|
Jerome Coutant
0:146cf26a9bbb
|
44
|
o The touch screen state is captured whenever the function BSP_TS_GetState() is
|
|
Jerome Coutant
0:146cf26a9bbb
|
45
|
used. This function returns information about the last LCD touch occurred
|
|
Jerome Coutant
0:146cf26a9bbb
|
46
|
in the TS_StateTypeDef structure.
|
|
Jerome Coutant
0:146cf26a9bbb
|
47
|
o The IT is handled using the corresponding external interrupt IRQ handler,
|
|
Jerome Coutant
0:146cf26a9bbb
|
48
|
the user IT callback treatment is implemented on the same external interrupt
|
|
Jerome Coutant
0:146cf26a9bbb
|
49
|
callback.
|
|
Jerome Coutant
0:146cf26a9bbb
|
50
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
51
|
------------------------------------------------------------------------------*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
52
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
53
|
/* Includes ------------------------------------------------------------------*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
54
|
#include "stm32h747i_discovery.h"
|
|
Jerome Coutant
0:146cf26a9bbb
|
55
|
#include "stm32h747i_discovery_ts.h"
|
|
Jerome Coutant
0:146cf26a9bbb
|
56
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
57
|
/** @addtogroup BSP
|
|
Jerome Coutant
0:146cf26a9bbb
|
58
|
* @{
|
|
Jerome Coutant
0:146cf26a9bbb
|
59
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
60
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
61
|
/** @addtogroup STM32H747I_DISCOVERY
|
|
Jerome Coutant
0:146cf26a9bbb
|
62
|
* @{
|
|
Jerome Coutant
0:146cf26a9bbb
|
63
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
64
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
65
|
/** @defgroup STM32H747I_DISCOVERY_TS STM32H747I_DISCOVERY_TS
|
|
Jerome Coutant
0:146cf26a9bbb
|
66
|
* @{
|
|
Jerome Coutant
0:146cf26a9bbb
|
67
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
68
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
69
|
/** @defgroup STM32H747I_DISCOVERY_TS_Private_Variables Private Variables
|
|
Jerome Coutant
0:146cf26a9bbb
|
70
|
* @{
|
|
Jerome Coutant
0:146cf26a9bbb
|
71
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
72
|
static TS_DrvTypeDef *ts_driver;
|
|
Jerome Coutant
0:146cf26a9bbb
|
73
|
static uint8_t ts_orientation;
|
|
Jerome Coutant
0:146cf26a9bbb
|
74
|
static uint8_t I2C_Address = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
75
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
76
|
/* Table for touchscreen event information display on LCD : table indexed on enum @ref TS_TouchEventTypeDef information */
|
|
Jerome Coutant
0:146cf26a9bbb
|
77
|
char * ts_event_string_tab[TOUCH_EVENT_NB_MAX] = { "None",
|
|
Jerome Coutant
0:146cf26a9bbb
|
78
|
"Press down",
|
|
Jerome Coutant
0:146cf26a9bbb
|
79
|
"Lift up",
|
|
Jerome Coutant
0:146cf26a9bbb
|
80
|
"Contact"
|
|
Jerome Coutant
0:146cf26a9bbb
|
81
|
};
|
|
Jerome Coutant
0:146cf26a9bbb
|
82
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
83
|
/* Table for touchscreen gesture Id information display on LCD : table indexed on enum @ref TS_GestureIdTypeDef information */
|
|
Jerome Coutant
0:146cf26a9bbb
|
84
|
char * ts_gesture_id_string_tab[GEST_ID_NB_MAX] = { "None",
|
|
Jerome Coutant
0:146cf26a9bbb
|
85
|
"Move Up",
|
|
Jerome Coutant
0:146cf26a9bbb
|
86
|
"Move Right",
|
|
Jerome Coutant
0:146cf26a9bbb
|
87
|
"Move Down",
|
|
Jerome Coutant
0:146cf26a9bbb
|
88
|
"Move Left",
|
|
Jerome Coutant
0:146cf26a9bbb
|
89
|
"Zoom In",
|
|
Jerome Coutant
0:146cf26a9bbb
|
90
|
"Zoom Out"
|
|
Jerome Coutant
0:146cf26a9bbb
|
91
|
};
|
|
Jerome Coutant
0:146cf26a9bbb
|
92
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
93
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
94
|
* @}
|
|
Jerome Coutant
0:146cf26a9bbb
|
95
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
96
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
97
|
/** @defgroup STM32H747I_DISCOVERY_TS_Exported_Functions Exported Functions
|
|
Jerome Coutant
0:146cf26a9bbb
|
98
|
* @{
|
|
Jerome Coutant
0:146cf26a9bbb
|
99
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
100
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
101
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
102
|
* @brief Initializes and configures the touch screen functionalities and
|
|
Jerome Coutant
0:146cf26a9bbb
|
103
|
* configures all necessary hardware resources (GPIOs, I2C, clocks..).
|
|
Jerome Coutant
0:146cf26a9bbb
|
104
|
* @param ts_SizeX : Maximum X size of the TS area on LCD
|
|
Jerome Coutant
0:146cf26a9bbb
|
105
|
* @param ts_SizeY : Maximum Y size of the TS area on LCD
|
|
Jerome Coutant
0:146cf26a9bbb
|
106
|
* @retval TS_OK if all initializations are OK. Other value if error.
|
|
Jerome Coutant
0:146cf26a9bbb
|
107
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
108
|
uint8_t BSP_TS_Init(uint16_t ts_SizeX, uint16_t ts_SizeY)
|
|
Jerome Coutant
0:146cf26a9bbb
|
109
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
110
|
uint8_t ts_status = TS_OK;
|
|
Jerome Coutant
0:146cf26a9bbb
|
111
|
uint8_t ts_id1, ts_id2 = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
112
|
/* Note : I2C_Address is un-initialized here, but is not used at all in init function */
|
|
Jerome Coutant
0:146cf26a9bbb
|
113
|
/* but the prototype of Init() is like that in template and should be respected */
|
|
Jerome Coutant
0:146cf26a9bbb
|
114
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
115
|
/* Initialize the communication channel to sensor (I2C) if necessary */
|
|
Jerome Coutant
0:146cf26a9bbb
|
116
|
/* that is initialization is done only once after a power up */
|
|
Jerome Coutant
0:146cf26a9bbb
|
117
|
ft6x06_ts_drv.Init(I2C_Address);
|
|
Jerome Coutant
0:146cf26a9bbb
|
118
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
119
|
ts_id1 = ft6x06_ts_drv.ReadID(TS_I2C_ADDRESS);
|
|
Jerome Coutant
0:146cf26a9bbb
|
120
|
if(ts_id1 != FT6206_ID_VALUE)
|
|
Jerome Coutant
0:146cf26a9bbb
|
121
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
122
|
ts_id2 = ft6x06_ts_drv.ReadID(TS_I2C_ADDRESS_A02);
|
|
Jerome Coutant
0:146cf26a9bbb
|
123
|
I2C_Address = TS_I2C_ADDRESS_A02;
|
|
Jerome Coutant
0:146cf26a9bbb
|
124
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
125
|
else
|
|
Jerome Coutant
0:146cf26a9bbb
|
126
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
127
|
I2C_Address = TS_I2C_ADDRESS;
|
|
Jerome Coutant
0:146cf26a9bbb
|
128
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
129
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
130
|
/* Scan FT6xx6 TouchScreen IC controller ID register by I2C Read */
|
|
Jerome Coutant
0:146cf26a9bbb
|
131
|
/* Verify this is a FT6206 or FT6336G, otherwise this is an error case */
|
|
Jerome Coutant
0:146cf26a9bbb
|
132
|
if((ts_id1 == FT6206_ID_VALUE) || (ts_id2 == FT6206_ID_VALUE))
|
|
Jerome Coutant
0:146cf26a9bbb
|
133
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
134
|
/* Found FT6206 : Initialize the TS driver structure */
|
|
Jerome Coutant
0:146cf26a9bbb
|
135
|
ts_driver = &ft6x06_ts_drv;
|
|
Jerome Coutant
0:146cf26a9bbb
|
136
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
137
|
/* Get LCD chosen orientation */
|
|
Jerome Coutant
0:146cf26a9bbb
|
138
|
if(ts_SizeX < ts_SizeY)
|
|
Jerome Coutant
0:146cf26a9bbb
|
139
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
140
|
ts_orientation = TS_SWAP_NONE;
|
|
Jerome Coutant
0:146cf26a9bbb
|
141
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
142
|
else
|
|
Jerome Coutant
0:146cf26a9bbb
|
143
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
144
|
ts_orientation = TS_SWAP_XY | TS_SWAP_Y;
|
|
Jerome Coutant
0:146cf26a9bbb
|
145
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
146
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
147
|
if(ts_status == TS_OK)
|
|
Jerome Coutant
0:146cf26a9bbb
|
148
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
149
|
/* Software reset the TouchScreen */
|
|
Jerome Coutant
0:146cf26a9bbb
|
150
|
ts_driver->Reset(I2C_Address);
|
|
Jerome Coutant
0:146cf26a9bbb
|
151
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
152
|
/* Calibrate, Configure and Start the TouchScreen driver */
|
|
Jerome Coutant
0:146cf26a9bbb
|
153
|
ts_driver->Start(I2C_Address);
|
|
Jerome Coutant
0:146cf26a9bbb
|
154
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
155
|
} /* of if(ts_status == TS_OK) */
|
|
Jerome Coutant
0:146cf26a9bbb
|
156
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
157
|
else
|
|
Jerome Coutant
0:146cf26a9bbb
|
158
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
159
|
ts_status = TS_DEVICE_NOT_FOUND;
|
|
Jerome Coutant
0:146cf26a9bbb
|
160
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
161
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
162
|
return (ts_status);
|
|
Jerome Coutant
0:146cf26a9bbb
|
163
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
164
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
165
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
166
|
* @brief Configures and enables the touch screen interrupts.
|
|
Jerome Coutant
0:146cf26a9bbb
|
167
|
* @retval TS_OK if all initializations are OK. Other value if error.
|
|
Jerome Coutant
0:146cf26a9bbb
|
168
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
169
|
uint8_t BSP_TS_ITConfig(void)
|
|
Jerome Coutant
0:146cf26a9bbb
|
170
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
171
|
uint8_t ts_status = TS_OK;
|
|
Jerome Coutant
0:146cf26a9bbb
|
172
|
GPIO_InitTypeDef gpio_init_structure;
|
|
Jerome Coutant
0:146cf26a9bbb
|
173
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
174
|
/* Msp Init of GPIO used for TS_INT pin coming from TouchScreen driver IC FT6x06 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
175
|
/* When touchscreen is operated in interrupt mode */
|
|
Jerome Coutant
0:146cf26a9bbb
|
176
|
BSP_TS_INT_MspInit();
|
|
Jerome Coutant
0:146cf26a9bbb
|
177
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
178
|
/* Configure Interrupt mode for TS_INT pin falling edge : when a new touch is available */
|
|
Jerome Coutant
0:146cf26a9bbb
|
179
|
/* TS_INT pin is active on low level on new touch available */
|
|
Jerome Coutant
0:146cf26a9bbb
|
180
|
gpio_init_structure.Pin = TS_INT_PIN;
|
|
Jerome Coutant
0:146cf26a9bbb
|
181
|
gpio_init_structure.Pull = GPIO_PULLUP;
|
|
Jerome Coutant
0:146cf26a9bbb
|
182
|
gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
|
|
Jerome Coutant
0:146cf26a9bbb
|
183
|
gpio_init_structure.Mode = GPIO_MODE_IT_FALLING;
|
|
Jerome Coutant
0:146cf26a9bbb
|
184
|
HAL_GPIO_Init(TS_INT_GPIO_PORT, &gpio_init_structure);
|
|
Jerome Coutant
0:146cf26a9bbb
|
185
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
186
|
/* Enable and set the TS_INT EXTI Interrupt to an intermediate priority */
|
|
Jerome Coutant
0:146cf26a9bbb
|
187
|
HAL_NVIC_SetPriority((IRQn_Type)(TS_INT_EXTI_IRQn), 0x0F, 0x00);
|
|
Jerome Coutant
0:146cf26a9bbb
|
188
|
HAL_NVIC_EnableIRQ((IRQn_Type)(TS_INT_EXTI_IRQn));
|
|
Jerome Coutant
0:146cf26a9bbb
|
189
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
190
|
/* Enable the TS in interrupt mode */
|
|
Jerome Coutant
0:146cf26a9bbb
|
191
|
/* In that case the INT output of FT6206 when new touch is available */
|
|
Jerome Coutant
0:146cf26a9bbb
|
192
|
/* is active on low level and directed on EXTI */
|
|
Jerome Coutant
0:146cf26a9bbb
|
193
|
ts_driver->EnableIT(I2C_Address);
|
|
Jerome Coutant
0:146cf26a9bbb
|
194
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
195
|
return (ts_status);
|
|
Jerome Coutant
0:146cf26a9bbb
|
196
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
197
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
198
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
199
|
* @brief Returns status and positions of the touch screen.
|
|
Jerome Coutant
0:146cf26a9bbb
|
200
|
* @param TS_State: Pointer to touch screen current state structure
|
|
Jerome Coutant
0:146cf26a9bbb
|
201
|
* @retval TS_OK if all initializations are OK. Other value if error.
|
|
Jerome Coutant
0:146cf26a9bbb
|
202
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
203
|
uint8_t BSP_TS_GetState(TS_StateTypeDef *TS_State)
|
|
Jerome Coutant
0:146cf26a9bbb
|
204
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
205
|
static uint32_t _x[TS_MAX_NB_TOUCH] = {0, 0};
|
|
Jerome Coutant
0:146cf26a9bbb
|
206
|
static uint32_t _y[TS_MAX_NB_TOUCH] = {0, 0};
|
|
Jerome Coutant
0:146cf26a9bbb
|
207
|
uint8_t ts_status = TS_OK;
|
|
Jerome Coutant
0:146cf26a9bbb
|
208
|
uint16_t tmp;
|
|
Jerome Coutant
0:146cf26a9bbb
|
209
|
uint16_t Raw_x[TS_MAX_NB_TOUCH];
|
|
Jerome Coutant
0:146cf26a9bbb
|
210
|
uint16_t Raw_y[TS_MAX_NB_TOUCH];
|
|
Jerome Coutant
0:146cf26a9bbb
|
211
|
uint16_t xDiff;
|
|
Jerome Coutant
0:146cf26a9bbb
|
212
|
uint16_t yDiff;
|
|
Jerome Coutant
0:146cf26a9bbb
|
213
|
uint32_t index;
|
|
Jerome Coutant
0:146cf26a9bbb
|
214
|
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
|
|
Jerome Coutant
0:146cf26a9bbb
|
215
|
uint32_t weight = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
216
|
uint32_t area = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
217
|
uint32_t event = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
218
|
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
219
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
220
|
/* Check and update the number of touches active detected */
|
|
Jerome Coutant
0:146cf26a9bbb
|
221
|
TS_State->touchDetected = ts_driver->DetectTouch(I2C_Address);
|
|
Jerome Coutant
0:146cf26a9bbb
|
222
|
if(TS_State->touchDetected)
|
|
Jerome Coutant
0:146cf26a9bbb
|
223
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
224
|
for(index=0; index < TS_State->touchDetected; index++)
|
|
Jerome Coutant
0:146cf26a9bbb
|
225
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
226
|
/* Get each touch coordinates */
|
|
Jerome Coutant
0:146cf26a9bbb
|
227
|
ts_driver->GetXY(I2C_Address, &(Raw_x[index]), &(Raw_y[index]));
|
|
Jerome Coutant
0:146cf26a9bbb
|
228
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
229
|
if(ts_orientation & TS_SWAP_XY)
|
|
Jerome Coutant
0:146cf26a9bbb
|
230
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
231
|
tmp = Raw_x[index];
|
|
Jerome Coutant
0:146cf26a9bbb
|
232
|
Raw_x[index] = Raw_y[index];
|
|
Jerome Coutant
0:146cf26a9bbb
|
233
|
Raw_y[index] = tmp;
|
|
Jerome Coutant
0:146cf26a9bbb
|
234
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
235
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
236
|
if(ts_orientation & TS_SWAP_X)
|
|
Jerome Coutant
0:146cf26a9bbb
|
237
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
238
|
Raw_x[index] = FT_6206_MAX_WIDTH - 1 - Raw_x[index];
|
|
Jerome Coutant
0:146cf26a9bbb
|
239
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
240
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
241
|
if(ts_orientation & TS_SWAP_Y)
|
|
Jerome Coutant
0:146cf26a9bbb
|
242
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
243
|
Raw_y[index] = FT_6206_MAX_HEIGHT - 1 - Raw_y[index];
|
|
Jerome Coutant
0:146cf26a9bbb
|
244
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
245
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
246
|
xDiff = Raw_x[index] > _x[index]? (Raw_x[index] - _x[index]): (_x[index] - Raw_x[index]);
|
|
Jerome Coutant
0:146cf26a9bbb
|
247
|
yDiff = Raw_y[index] > _y[index]? (Raw_y[index] - _y[index]): (_y[index] - Raw_y[index]);
|
|
Jerome Coutant
0:146cf26a9bbb
|
248
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
249
|
if ((xDiff + yDiff) > 5)
|
|
Jerome Coutant
0:146cf26a9bbb
|
250
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
251
|
_x[index] = Raw_x[index];
|
|
Jerome Coutant
0:146cf26a9bbb
|
252
|
_y[index] = Raw_y[index];
|
|
Jerome Coutant
0:146cf26a9bbb
|
253
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
254
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
255
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
256
|
TS_State->touchX[index] = _x[index];
|
|
Jerome Coutant
0:146cf26a9bbb
|
257
|
TS_State->touchY[index] = _y[index];
|
|
Jerome Coutant
0:146cf26a9bbb
|
258
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
259
|
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
|
|
Jerome Coutant
0:146cf26a9bbb
|
260
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
261
|
/* Get touch info related to the current touch */
|
|
Jerome Coutant
0:146cf26a9bbb
|
262
|
ft6x06_TS_GetTouchInfo(I2C_Address, index, &weight, &area, &event);
|
|
Jerome Coutant
0:146cf26a9bbb
|
263
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
264
|
/* Update TS_State structure */
|
|
Jerome Coutant
0:146cf26a9bbb
|
265
|
TS_State->touchWeight[index] = weight;
|
|
Jerome Coutant
0:146cf26a9bbb
|
266
|
TS_State->touchArea[index] = area;
|
|
Jerome Coutant
0:146cf26a9bbb
|
267
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
268
|
/* Remap touch event */
|
|
Jerome Coutant
0:146cf26a9bbb
|
269
|
switch(event)
|
|
Jerome Coutant
0:146cf26a9bbb
|
270
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
271
|
case FT6206_TOUCH_EVT_FLAG_PRESS_DOWN :
|
|
Jerome Coutant
0:146cf26a9bbb
|
272
|
TS_State->touchEventId[index] = TOUCH_EVENT_PRESS_DOWN;
|
|
Jerome Coutant
0:146cf26a9bbb
|
273
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
274
|
case FT6206_TOUCH_EVT_FLAG_LIFT_UP :
|
|
Jerome Coutant
0:146cf26a9bbb
|
275
|
TS_State->touchEventId[index] = TOUCH_EVENT_LIFT_UP;
|
|
Jerome Coutant
0:146cf26a9bbb
|
276
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
277
|
case FT6206_TOUCH_EVT_FLAG_CONTACT :
|
|
Jerome Coutant
0:146cf26a9bbb
|
278
|
TS_State->touchEventId[index] = TOUCH_EVENT_CONTACT;
|
|
Jerome Coutant
0:146cf26a9bbb
|
279
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
280
|
case FT6206_TOUCH_EVT_FLAG_NO_EVENT :
|
|
Jerome Coutant
0:146cf26a9bbb
|
281
|
TS_State->touchEventId[index] = TOUCH_EVENT_NO_EVT;
|
|
Jerome Coutant
0:146cf26a9bbb
|
282
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
283
|
default :
|
|
Jerome Coutant
0:146cf26a9bbb
|
284
|
ts_status = TS_ERROR;
|
|
Jerome Coutant
0:146cf26a9bbb
|
285
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
286
|
} /* of switch(event) */
|
|
Jerome Coutant
0:146cf26a9bbb
|
287
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
288
|
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
289
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
290
|
} /* of for(index=0; index < TS_State->touchDetected; index++) */
|
|
Jerome Coutant
0:146cf26a9bbb
|
291
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
292
|
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
|
|
Jerome Coutant
0:146cf26a9bbb
|
293
|
/* Get gesture Id */
|
|
Jerome Coutant
0:146cf26a9bbb
|
294
|
ts_status = BSP_TS_Get_GestureId(TS_State);
|
|
Jerome Coutant
0:146cf26a9bbb
|
295
|
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
296
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
297
|
} /* end of if(TS_State->touchDetected != 0) */
|
|
Jerome Coutant
0:146cf26a9bbb
|
298
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
299
|
return (ts_status);
|
|
Jerome Coutant
0:146cf26a9bbb
|
300
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
301
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
302
|
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
|
|
Jerome Coutant
0:146cf26a9bbb
|
303
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
304
|
* @brief Update gesture Id following a touch detected.
|
|
Jerome Coutant
0:146cf26a9bbb
|
305
|
* @param TS_State: Pointer to touch screen current state structure
|
|
Jerome Coutant
0:146cf26a9bbb
|
306
|
* @retval TS_OK if all initializations are OK. Other value if error.
|
|
Jerome Coutant
0:146cf26a9bbb
|
307
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
308
|
uint8_t BSP_TS_Get_GestureId(TS_StateTypeDef *TS_State)
|
|
Jerome Coutant
0:146cf26a9bbb
|
309
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
310
|
uint32_t gestureId = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
311
|
uint8_t ts_status = TS_OK;
|
|
Jerome Coutant
0:146cf26a9bbb
|
312
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
313
|
/* Get gesture Id */
|
|
Jerome Coutant
0:146cf26a9bbb
|
314
|
ft6x06_TS_GetGestureID(I2C_Address, &gestureId);
|
|
Jerome Coutant
0:146cf26a9bbb
|
315
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
316
|
/* Remap gesture Id to a TS_GestureIdTypeDef value */
|
|
Jerome Coutant
0:146cf26a9bbb
|
317
|
switch(gestureId)
|
|
Jerome Coutant
0:146cf26a9bbb
|
318
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
319
|
case FT6206_GEST_ID_NO_GESTURE :
|
|
Jerome Coutant
0:146cf26a9bbb
|
320
|
TS_State->gestureId = GEST_ID_NO_GESTURE;
|
|
Jerome Coutant
0:146cf26a9bbb
|
321
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
322
|
case FT6206_GEST_ID_MOVE_UP :
|
|
Jerome Coutant
0:146cf26a9bbb
|
323
|
TS_State->gestureId = GEST_ID_MOVE_UP;
|
|
Jerome Coutant
0:146cf26a9bbb
|
324
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
325
|
case FT6206_GEST_ID_MOVE_RIGHT :
|
|
Jerome Coutant
0:146cf26a9bbb
|
326
|
TS_State->gestureId = GEST_ID_MOVE_RIGHT;
|
|
Jerome Coutant
0:146cf26a9bbb
|
327
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
328
|
case FT6206_GEST_ID_MOVE_DOWN :
|
|
Jerome Coutant
0:146cf26a9bbb
|
329
|
TS_State->gestureId = GEST_ID_MOVE_DOWN;
|
|
Jerome Coutant
0:146cf26a9bbb
|
330
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
331
|
case FT6206_GEST_ID_MOVE_LEFT :
|
|
Jerome Coutant
0:146cf26a9bbb
|
332
|
TS_State->gestureId = GEST_ID_MOVE_LEFT;
|
|
Jerome Coutant
0:146cf26a9bbb
|
333
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
334
|
case FT6206_GEST_ID_ZOOM_IN :
|
|
Jerome Coutant
0:146cf26a9bbb
|
335
|
TS_State->gestureId = GEST_ID_ZOOM_IN;
|
|
Jerome Coutant
0:146cf26a9bbb
|
336
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
337
|
case FT6206_GEST_ID_ZOOM_OUT :
|
|
Jerome Coutant
0:146cf26a9bbb
|
338
|
TS_State->gestureId = GEST_ID_ZOOM_OUT;
|
|
Jerome Coutant
0:146cf26a9bbb
|
339
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
340
|
default :
|
|
Jerome Coutant
0:146cf26a9bbb
|
341
|
ts_status = TS_ERROR;
|
|
Jerome Coutant
0:146cf26a9bbb
|
342
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
343
|
} /* of switch(gestureId) */
|
|
Jerome Coutant
0:146cf26a9bbb
|
344
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
345
|
return(ts_status);
|
|
Jerome Coutant
0:146cf26a9bbb
|
346
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
347
|
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
348
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
349
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
350
|
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
|
|
Jerome Coutant
0:146cf26a9bbb
|
351
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
352
|
* @brief Function used to reset all touch data before a new acquisition
|
|
Jerome Coutant
0:146cf26a9bbb
|
353
|
* of touch information.
|
|
Jerome Coutant
0:146cf26a9bbb
|
354
|
* @param TS_State: Pointer to touch screen current state structure
|
|
Jerome Coutant
0:146cf26a9bbb
|
355
|
* @retval TS_OK if OK, TE_ERROR if problem found.
|
|
Jerome Coutant
0:146cf26a9bbb
|
356
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
357
|
uint8_t BSP_TS_ResetTouchData(TS_StateTypeDef *TS_State)
|
|
Jerome Coutant
0:146cf26a9bbb
|
358
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
359
|
uint8_t ts_status = TS_ERROR;
|
|
Jerome Coutant
0:146cf26a9bbb
|
360
|
uint32_t index;
|
|
Jerome Coutant
0:146cf26a9bbb
|
361
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
362
|
if (TS_State != (TS_StateTypeDef *)NULL)
|
|
Jerome Coutant
0:146cf26a9bbb
|
363
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
364
|
TS_State->gestureId = GEST_ID_NO_GESTURE;
|
|
Jerome Coutant
0:146cf26a9bbb
|
365
|
TS_State->touchDetected = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
366
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
367
|
for(index = 0; index < TS_MAX_NB_TOUCH; index++)
|
|
Jerome Coutant
0:146cf26a9bbb
|
368
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
369
|
TS_State->touchX[index] = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
370
|
TS_State->touchY[index] = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
371
|
TS_State->touchArea[index] = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
372
|
TS_State->touchEventId[index] = TOUCH_EVENT_NO_EVT;
|
|
Jerome Coutant
0:146cf26a9bbb
|
373
|
TS_State->touchWeight[index] = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
374
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
375
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
376
|
ts_status = TS_OK;
|
|
Jerome Coutant
0:146cf26a9bbb
|
377
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
378
|
} /* of if (TS_State != (TS_StateTypeDef *)NULL) */
|
|
Jerome Coutant
0:146cf26a9bbb
|
379
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
380
|
return (ts_status);
|
|
Jerome Coutant
0:146cf26a9bbb
|
381
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
382
|
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
383
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
384
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
385
|
* @brief Initializes the TS_INT pin MSP.
|
|
Jerome Coutant
0:146cf26a9bbb
|
386
|
* @retval None
|
|
Jerome Coutant
0:146cf26a9bbb
|
387
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
388
|
__weak void BSP_TS_INT_MspInit(void)
|
|
Jerome Coutant
0:146cf26a9bbb
|
389
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
390
|
GPIO_InitTypeDef gpio_init_structure;
|
|
Jerome Coutant
0:146cf26a9bbb
|
391
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
392
|
TS_INT_GPIO_CLK_ENABLE();
|
|
Jerome Coutant
0:146cf26a9bbb
|
393
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
394
|
/* GPIO configuration in input for TouchScreen interrupt signal on TS_INT pin */
|
|
Jerome Coutant
0:146cf26a9bbb
|
395
|
gpio_init_structure.Pin = TS_INT_PIN;
|
|
Jerome Coutant
0:146cf26a9bbb
|
396
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
397
|
gpio_init_structure.Mode = GPIO_MODE_INPUT;
|
|
Jerome Coutant
0:146cf26a9bbb
|
398
|
gpio_init_structure.Pull = GPIO_PULLUP;
|
|
Jerome Coutant
0:146cf26a9bbb
|
399
|
gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
Jerome Coutant
0:146cf26a9bbb
|
400
|
HAL_GPIO_Init(TS_INT_GPIO_PORT, &gpio_init_structure);
|
|
Jerome Coutant
0:146cf26a9bbb
|
401
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
402
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
403
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
404
|
* @}
|
|
Jerome Coutant
0:146cf26a9bbb
|
405
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
406
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
407
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
408
|
* @}
|
|
Jerome Coutant
0:146cf26a9bbb
|
409
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
410
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
411
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
412
|
* @}
|
|
Jerome Coutant
0:146cf26a9bbb
|
413
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
414
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
415
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
416
|
* @}
|
|
Jerome Coutant
0:146cf26a9bbb
|
417
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
418
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
419
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|