1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
28
29
32
33
36
37
40
43
44
47
50
51
54
57
58
61
62
63
66
67
70
73
74
77
78
85
86
87
88
89
90
91
92
93
94
101
102
108
109
110
111
112
116
123
124
128
133
134
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
158
159
160
161
162
166
167
168
169
170
171
172
176
180
182
183
184
185
189
193
194
195
196
197
198
202
206
208
209
210
211
212
213
218
219
220
221
222
223
224
225
226
227
230
235
236
239
240
243
244
247
248
/* ... */
#include "stm32f429i_discovery_ts.h"
#include "stm32f429i_discovery_io.h"
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
static TS_DrvTypeDef *TsDrv;
static uint16_t TsXBoundary, TsYBoundary;
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
uint8_t BSP_TS_Init(uint16_t XSize, uint16_t YSize)
{
uint8_t ret = TS_ERROR;
TsXBoundary = XSize;
TsYBoundary = YSize;
if (stmpe811_ts_drv.ReadID(TS_I2C_ADDRESS) == STMPE811_ID)
{
TsDrv = &stmpe811_ts_drv;
ret = TS_OK;
}if (stmpe811_ts_drv.ReadID(TS_I2C_ADDRESS) == STMPE811_ID) { ... }
if (ret == TS_OK)
{
TsDrv->Init(TS_I2C_ADDRESS);
TsDrv->Start(TS_I2C_ADDRESS);
}if (ret == TS_OK) { ... }
return ret;
}{ ... }
/* ... */
uint8_t BSP_TS_ITConfig(void)
{
TsDrv->EnableIT(TS_I2C_ADDRESS);
return TS_OK;
}{ ... }
/* ... */
uint8_t BSP_TS_ITGetStatus(void)
{
return (TsDrv->GetITStatus(TS_I2C_ADDRESS));
}{ ... }
/* ... */
void BSP_TS_GetState(TS_StateTypeDef *TsState)
{
static uint32_t _x = 0, _y = 0;
uint16_t xDiff, yDiff, x, y, xr, yr;
TsState->TouchDetected = TsDrv->DetectTouch(TS_I2C_ADDRESS);
if (TsState->TouchDetected)
{
TsDrv->GetXY(TS_I2C_ADDRESS, &x, &y);
#if defined (USE_STM32F429I_DISCOVERY_REVD)
if (y > 3700)
{
y = 3700;
}if (y > 3700) { ... }
else if (y < 180)
{
y = 180;
}else if (y < 180) { ... }
y = 3700 - y;/* ... */
#else
y -= 360;
/* ... */
#endif
yr = y / 11;
if (yr <= 0)
{
yr = 0;
}if (yr <= 0) { ... }
else if (yr > TsYBoundary)
{
yr = TsYBoundary - 1;
}else if (yr > TsYBoundary) { ... }
else
{}else { ... }
y = yr;
if (x <= 3000)
{
x = 3870 - x;
}if (x <= 3000) { ... }
else
{
x = 3800 - x;
}else { ... }
xr = x / 15;
if (xr <= 0)
{
xr = 0;
}if (xr <= 0) { ... }
else if (xr > TsXBoundary)
{
xr = TsXBoundary - 1;
}else if (xr > TsXBoundary) { ... }
else
{}else { ... }
x = xr;
xDiff = x > _x ? (x - _x): (_x - x);
yDiff = y > _y ? (y - _y) : (_y - y);
if (xDiff + yDiff > 5)
{
_x = x;
_y = y;
}if (xDiff + yDiff > 5) { ... }
TsState->X = _x;
TsState->Y = _y;
}if (TsState->TouchDetected) { ... }
}{ ... }
/* ... */
void BSP_TS_ITClear(void)
{
TsDrv->ClearIT(TS_I2C_ADDRESS);
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */