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
60
61
64
65
68
69
72
73
74
75
78
79
82
85
86
89
90
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
119
120
121
122
123
127
134
135
139
144
145
150
151
152
153
154
155
156
157
158
159
160
161
162
166
167
171
172
178
179
180
181
182
187
188
189
190
191
192
193
194
195
198
202
203
206
207
210
211
214
215
/* ... */
/* ... */
#include "stm324xg_eval_ts.h"
/* ... */
/* ... */
/* ... */
/* ... */
static TS_DrvTypeDef *ts_driver;
static uint16_t ts_x_boundary, ts_y_boundary;
static uint8_t ts_orientation;
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
uint8_t BSP_TS_Init(uint16_t xSize, uint16_t ySize)
{
uint8_t ret = TS_ERROR;
if(stmpe811_ts_drv.ReadID(TS_I2C_ADDRESS) == STMPE811_ID)
{
ts_driver = &stmpe811_ts_drv;
ts_x_boundary = xSize;
ts_y_boundary = ySize;
ts_orientation = TS_SWAP_XY;
ret = TS_OK;
}if (stmpe811_ts_drv.ReadID(TS_I2C_ADDRESS) == STMPE811_ID) { ... }
if(ret == TS_OK)
{
ts_driver->Init(TS_I2C_ADDRESS);
ts_driver->Start(TS_I2C_ADDRESS);
}if (ret == TS_OK) { ... }
return ret;
}{ ... }
/* ... */
uint8_t BSP_TS_ITConfig(void)
{
ts_driver->EnableIT(TS_I2C_ADDRESS);
return TS_OK;
}{ ... }
/* ... */
uint8_t BSP_TS_ITGetStatus(void)
{
return (ts_driver->GetITStatus(TS_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(TS_I2C_ADDRESS);
if(TS_State->TouchDetected)
{
ts_driver->GetXY(TS_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)
{
ts_driver->ClearIT(TS_I2C_ADDRESS);
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */