@@ -19,9 +19,11 @@ extern USBD_HandleTypeDef hUsbDeviceFS;
19
19
extern uint8_t USBD_HID_SendReport (USBD_HandleTypeDef * pdev , uint8_t * report , uint16_t len );
20
20
21
21
static uint8_t touchIrq = 0 ;
22
- static uint16_t oldX [max_point_num ]= {0 ,};
23
- static uint16_t oldY [max_point_num ]= {0 ,};
24
- static uint8_t p_point_num = 0 ;
22
+ //static uint16_t oldX[max_point_num]={0,};
23
+ //static uint16_t oldY[max_point_num]={0,};
24
+ static uint16_t oldid [max_point_num ];
25
+ //static uint8_t p_point_num = 0;
26
+
25
27
26
28
//https://docs.microsoft.com/en-us/windows-hardware/design/component-guidelines/touch-and-pen-support
27
29
const uint8_t touchQualityKey [] = {
@@ -64,24 +66,26 @@ struct multiTouchHid_t multiTouch;
64
66
65
67
void tpd_down (uint16_t x , uint16_t y , uint16_t p )
66
68
{
67
- multiTouch .touch [p ].tip = 0x01 ;
68
- multiTouch .touch [p ].num = p ; //contact id
69
- multiTouch .touch [p ].x = x ;
70
- multiTouch .touch [p ].y = y ;
71
- multiTouch .touch [p ].width = 0x30 ; //width of contact
72
- multiTouch .touch [p ].height = 0x30 ;
69
+ multiTouch .touch [multiTouch . id ].tip = 0x01 ;
70
+ multiTouch .touch [multiTouch . id ].num = p ; //contact id
71
+ multiTouch .touch [multiTouch . id ].x = x ;
72
+ multiTouch .touch [multiTouch . id ].y = y ;
73
+ multiTouch .touch [multiTouch . id ].width = 0x30 ; //width of contact
74
+ multiTouch .touch [multiTouch . id ].height = 0x30 ;
73
75
multiTouch .id ++ ;
74
76
75
77
}
76
78
void tpd_up (uint16_t x , uint16_t y , uint16_t p )
77
79
{
78
80
multiTouch .touch [multiTouch .id ].tip = 0x00 ;
79
- multiTouch .touch [multiTouch .id ].num = multiTouch .id ;
80
- multiTouch .touch [multiTouch .id ].x = x ;
81
- multiTouch .touch [multiTouch .id ].y = y ;
82
- multiTouch .touch [multiTouch .id ].width = 0x30 ;
83
- multiTouch .touch [multiTouch .id ].height = 0x30 ;
81
+ //multiTouch.touch[multiTouch.id].num = multiTouch.id;
82
+ multiTouch .touch [multiTouch .id ].num = p ;
83
+ //multiTouch.touch[multiTouch.id].x = x;
84
+ //multiTouch.touch[multiTouch.id].y = y;
85
+ multiTouch .touch [multiTouch .id ].width = 0 ;
86
+ multiTouch .touch [multiTouch .id ].height = 0 ;
84
87
multiTouch .id ++ ;
88
+
85
89
}
86
90
87
91
void input_sync ()
@@ -93,6 +97,7 @@ void input_sync()
93
97
{
94
98
printf("\n[%d:%d] x : %d, y : %d, %d\n",multiTouch.id, multiTouch.touch[i].tip, multiTouch.touch[i].x,multiTouch.touch[i].y, multiTouch.count);
95
99
}*/
100
+ //HAL_UART_Transmit_IT(&huart3, (uint8_t*)&multiTouch, sizeof(multiTouch));
96
101
USBD_HID_SendReport (& hUsbDeviceFS , (uint8_t * )& multiTouch , sizeof (struct multiTouchHid_t ));
97
102
multiTouch .id = 0 ;
98
103
for (int i = 0 ;i < max_point_num ;i ++ )
@@ -142,19 +147,26 @@ void initTouch()
142
147
}
143
148
}
144
149
150
+ //void toucuProc(I2C_HandleTypeDef hi2c1)
145
151
void toucuProc ()
146
152
{
147
153
uint8_t point_num ;
148
154
uint8_t i ;
149
155
uint16_t x [max_point_num ];
150
156
uint16_t y [max_point_num ];
157
+
158
+ uint16_t id [max_point_num ];
159
+
151
160
uint8_t dat [100 ];
161
+
152
162
if (touchIrq )
153
163
{
154
164
touchIrq = 0 ;
155
165
156
- readI2C (TOUCH_I2C_ID , 0x00 , dat , 33 );
166
+ readI2C (TOUCH_I2C_ID , 0x00 , dat , 40 );
167
+ //HAL_I2C_Mem_Read(&hi2c1, TOUCH_I2C_ID, 0x00, I2C_MEMADD_SIZE_8BIT, (uint8_t *)dat, 40, 200);
157
168
169
+ //HAL_I2C_Master_Receive_DMA()
158
170
//device mode[6:4]
159
171
//0 Work Mode
160
172
//4 Factory Mode
@@ -184,14 +196,59 @@ void toucuProc()
184
196
185
197
x [i ] = (((uint16_t )dat [3 + 6 * i ]& 0x0F )<<8 )|dat [3 + 6 * i + 1 ];
186
198
y [i ] = (((uint16_t )dat [3 + 6 * i + 2 ]& 0x0F )<<8 )|dat [3 + 6 * i + 3 ];
199
+
200
+ id [i ] = dat [5 + 6 * i ]>>4 ;
201
+
187
202
if (x [i ] > 1024 )
188
203
x [i ] = 1024 ;
189
204
if (y [i ] > 600 )
190
205
y [i ] = 600 ;
191
206
x [i ] = (x [i ]* 2048 )/1024 ;// touch range ( 0 ~ 1024 ) to USB HID range (0 ~ 2048)
192
207
y [i ] = (y [i ]* 2048 )/600 ; // touch range ( 0 ~ 1024 ) to USB HID range (0 ~ 2048)
208
+
209
+ tpd_down (x [i ], y [i ], id [i ]);
210
+
211
+
212
+ for (uint8_t c = 0 ; c < point_num ; c ++ )
213
+ {
214
+ if (id [i ] == oldid [c ])
215
+ {
216
+ oldid [c ]= 255 ;
217
+ }
218
+
219
+ }
220
+
221
+ }
222
+ //input_sync();
223
+
224
+
225
+ for (i = 0 ; i < point_num ; i ++ )
226
+ {
227
+ if (oldid [i ]!= 255 )
228
+ {
229
+ tpd_up (x [i ], y [i ], oldid [i ]);
230
+
231
+ }
232
+ oldid [i ] = id [i ];
193
233
}
234
+ input_sync ();
194
235
236
+ /*
237
+ input_sync();
238
+ for(i = 0; i < point_num; i++)
239
+ {
240
+ if(id[i]!=oldid[i])
241
+ {
242
+ tpd_up(x[i], y[i], oldid[i]);
243
+ //input_sync();
244
+ }
245
+ oldid[i] = id[i];
246
+ }
247
+ input_sync();
248
+ */
249
+
250
+
251
+ /*
195
252
if(point_num > 0)
196
253
{
197
254
// pressed
@@ -225,5 +282,7 @@ void toucuProc()
225
282
input_sync();
226
283
}
227
284
p_point_num = point_num;
285
+ */
286
+
228
287
}
229
288
}
0 commit comments