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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
67
68
71
72
75
76
79
80
81
82
83
86
87
90
91
98
99
100
101
102
103
104
105
112
113
114
115
116
118
124
130
131
132
133
134
135
136
137
138
139
140
144
149
150
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
172
177
178
183
184
185
186
187
188
189
190
191
192
193
194
195
199
200
204
205
211
212
213
214
215
220
221
222
223
224
225
226
227
230
231
232
233
234
235
236
237
238
239
242
243
246
247
250
251
/* ... */
/* ... */
#include "stm324x9i_eval_ts.h"
#include "stm324x9i_eval_io.h"
/* ... */
/* ... */
/* ... */
/* ... */
static TS_DrvTypeDef *ts_driver;
static uint16_t ts_x_boundary, ts_y_boundary;
static uint8_t ts_orientation;
static uint8_t I2C_Address;
/* ... */
/* ... */
/* ... */
uint8_t BSP_TS_Init(uint16_t xSize, uint16_t ySize)
{
uint8_t status = TS_OK;
ts_x_boundary = xSize;
ts_y_boundary = ySize;
if(stmpe811_ts_drv.ReadID(TS_I2C_ADDRESS) == STMPE811_ID)
{
ts_driver = &stmpe811_ts_drv;
I2C_Address = TS_I2C_ADDRESS;
ts_orientation = TS_SWAP_Y;
}if (stmpe811_ts_drv.ReadID(TS_I2C_ADDRESS) == STMPE811_ID) { ... }
else
{
IOE_Init();
/* ... */
if(BSP_TS3510_IsDetected() == 0)
{
ts_driver = &ts3510_ts_drv;
I2C_Address = TS3510_I2C_ADDRESS;
}if (BSP_TS3510_IsDetected() == 0) { ... }
else
{
ts_driver = &exc7200_ts_drv;
I2C_Address = EXC7200_I2C_ADDRESS;
}else { ... }
ts_orientation = TS_SWAP_NONE;
}else { ... }
ts_driver->Init(I2C_Address);
ts_driver->Start(I2C_Address);
return status;
}{ ... }
/* ... */
uint8_t BSP_TS_DeInit(void)
{
return TS_OK;
}{ ... }
/* ... */
uint8_t BSP_TS_ITConfig(void)
{
BSP_IO_Init();
BSP_IO_ConfigPin(TS_INT_PIN, IO_MODE_IT_FALLING_EDGE);
ts_driver->EnableIT(I2C_Address);
return TS_OK;
}{ ... }
/* ... */
uint8_t BSP_TS_ITGetStatus(void)
{
return (ts_driver->GetITStatus(I2C_Address));
}{ ... }
/* ... */
uint8_t BSP_TS_GetState(TS_StateTypeDef *TS_State)
{
static uint32_t _x = 0, _y = 0;
uint16_t xDiff, yDiff , x , y;
uint16_t swap;
TS_State->TouchDetected = ts_driver->DetectTouch(I2C_Address);
if(TS_State->TouchDetected)
{
ts_driver->GetXY(I2C_Address, &x, &y);
if(ts_orientation & TS_SWAP_X)
{
x = 4096 - x;
}if (ts_orientation & TS_SWAP_X) { ... }
if(ts_orientation & TS_SWAP_Y)
{
y = 4096 - y;
}if (ts_orientation & TS_SWAP_Y) { ... }
if(ts_orientation & TS_SWAP_XY)
{
swap = y;
y = x;
x = swap;
}if (ts_orientation & TS_SWAP_XY) { ... }
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) { ... }
TS_State->x = (ts_x_boundary * _x) >> 12;
TS_State->y = (ts_y_boundary * _y) >> 12;
}if (TS_State->TouchDetected) { ... }
return TS_OK;
}{ ... }
/* ... */
void BSP_TS_ITClear(void)
{
BSP_IO_ITClear();
ts_driver->ClearIT(I2C_Address);
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */