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
64
65
68
69
72
73
76
79
80
83
86
87
90
93
94
97
98
99
100
101
104
105
108
111
112
115
116
123
124
125
126
127
128
129
130
131
132
133
134
135
142
143
144
145
146
147
148
149
150
151
155
160
161
165
171
172
176
182
183
187
188
189
190
191
192
193
194
195
196
197
198
201
206
207
211
216
217
220
221
222
223
224
225
226
227
228
229
234
235
236
237
238
239
240
241
242
243
244
245
246
250
251
255
256
262
263
264
265
266
271
272
273
274
275
276
277
278
279
280
283
284
287
288
291
292
/* ... */
/* ... */
#include "stm32446e_eval_ts.h"
#include "stm32446e_eval_io.h"
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
static TS_DrvTypeDef *ts_driver;
static uint16_t tsBundaryX, tsBundaryY;
static uint8_t tsOrientation;
static uint8_t AddressI2C;
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
uint8_t BSP_TS_Init(uint16_t xSize, uint16_t ySize)
{
uint8_t mfxstm32l152_id = 0;
tsBundaryX = xSize;
tsBundaryY = ySize;
BSP_IO_Init();
mfxstm32l152_id = mfxstm32l152_io_drv.ReadID(IO_I2C_ADDRESS);
if((mfxstm32l152_id == MFXSTM32L152_ID_1) || (mfxstm32l152_id == MFXSTM32L152_ID_2))
{
ts_driver = &mfxstm32l152_ts_drv;
AddressI2C = TS_I2C_ADDRESS;
tsOrientation = TS_SWAP_NONE;
}if ((mfxstm32l152_id == MFXSTM32L152_ID_1) || (mfxstm32l152_id == MFXSTM32L152_ID_2)) { ... }
ts_driver->Init(AddressI2C);
ts_driver->Start(AddressI2C);
return TS_OK;
}{ ... }
/* ... */
uint8_t BSP_TS_DeInit(void)
{
return TS_OK;
}{ ... }
/* ... */
uint8_t BSP_TS_ITEnable(void)
{
ts_driver->EnableIT(AddressI2C);
return TS_OK;
}{ ... }
/* ... */
uint8_t BSP_TS_ITDisable(void)
{
ts_driver->DisableIT(AddressI2C);
return TS_OK;
}{ ... }
/* ... */
uint8_t BSP_TS_ITConfig(void)
{
BSP_IO_Init();
ts_driver->EnableIT(AddressI2C);
return TS_OK;
}{ ... }
/* ... */
void BSP_TS_ITClear(void)
{
ts_driver->ClearIT(AddressI2C);
}{ ... }
/* ... */
uint8_t BSP_TS_ITGetStatus(void)
{
return (ts_driver->GetITStatus(AddressI2C));
}{ ... }
/* ... */
void BSP_TS_FIFOClear(void)
{
}{ ... }
/* ... */
uint8_t BSP_TS_GetState(TS_StateTypeDef *TS_State)
{
static uint32_t _x = 0, _y = 0;
uint16_t x_diff, y_diff , x , y;
uint16_t swap;
TS_State->TouchDetected = ts_driver->DetectTouch(AddressI2C);
if(TS_State->TouchDetected)
{
ts_driver->GetXY(AddressI2C, &x, &y);
if(tsOrientation & TS_SWAP_X)
{
x = 4096 - x;
}if (tsOrientation & TS_SWAP_X) { ... }
if(tsOrientation & TS_SWAP_Y)
{
y = 4096 - y;
}if (tsOrientation & TS_SWAP_Y) { ... }
if(tsOrientation & TS_SWAP_XY)
{
swap = y;
y = x;
x = swap;
}if (tsOrientation & TS_SWAP_XY) { ... }
x_diff = x > _x? (x - _x): (_x - x);
y_diff = y > _y? (y - _y): (_y - y);
if (x_diff + y_diff > 5)
{
_x = x;
_y = y;
}if (x_diff + y_diff > 5) { ... }
TS_State->x = (tsBundaryX * _x) >> 12;
TS_State->y = (tsBundaryY * _y) >> 12;
}if (TS_State->TouchDetected) { ... }
return TS_OK;
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */