@@ -278,21 +278,78 @@ static int ns2009_rd (struct TWI_DEV *dev, u8 cmd, u32 *dat)
278278int ns2009_read (struct TWI_DEV * dev )
279279{
280280 u32 x , y , z ;
281- struct TS * ts = (struct TS * )dev -> data ;
282- if (ns2009_rd (dev , NS2009_RD_Z1 , & z ) == KO ) return KO ;
283- if (ns2009_rd (dev , NS2009_RD_X , & x ) == KO ) return KO ;
284- if (ns2009_rd (dev , NS2009_RD_Y , & y ) == KO ) return KO ;
281+ struct TS_NS2009 * ts = (struct TS_NS2009 * )dev -> data ;
282+ if (ns2009_rd (dev , NS2009_RD_Z1 , & z ) == KO ) return 0 ;
283+ if (ns2009_rd (dev , NS2009_RD_X , & x ) == KO ) return 0 ;
284+ if (ns2009_rd (dev , NS2009_RD_Y , & y ) == KO ) return 0 ;
285285 ts -> z <<= 1 ;
286- if (z < ts -> dz ) return KO ;
286+ if (z < ts -> dz ) return 0 ;
287287 ts -> z |= 1 ;
288+ //printf("%03d %03d %03d\r", x, y, z);
288289 if (x < ts -> x1 ) x = ts -> x1 ; else if (x > ts -> x2 ) x = ts -> x2 ;
289290 if (y < ts -> y1 ) y = ts -> y1 ; else if (y > ts -> y2 ) y = ts -> y2 ;
290291 x = (x - ts -> x1 ) * (display -> width - 1 ) / (ts -> x2 - ts -> x1 );
291292 y = (y - ts -> y1 ) * (display -> height - 1 ) / (ts -> y2 - ts -> y1 );
292293 ts_buf_update (ts -> bufx , x );
293294 ts_buf_update (ts -> bufy , y );
294- if ((ts -> z & 0x1F ) != 0x1F ) return KO ;
295+ if ((ts -> z & 0x1F ) != 0x1F ) return 0 ;
295296 ts -> x = ts_get_median (ts -> bufx );
296297 ts -> y = display -> height - ts_get_median (ts -> bufy );
297- return OK ;
298+ return 1 ;
299+ }
300+
301+ /*******************************************************************************
302+ TS GT911
303+ *******************************************************************************/
304+ int gt911_rd (struct TWI_DEV * dev , u16 addr , void * dat , u32 len )
305+ {
306+ u8 buf [2 ] = { addr >> 8 , addr };
307+ twi_start (dev -> bus , dev -> addr & 0xFE );
308+ twi_send (dev -> bus , buf , 2 );
309+ twi_stop (dev -> bus );
310+ if (!twi_error )
311+ {
312+ twi_start (dev -> bus , dev -> addr | 1 );
313+ twi_recv (dev -> bus , dat , len );
314+ twi_stop (dev -> bus );
315+ }
316+ return twi_error ? KO : OK ;
317+ }
318+
319+ int gt911_wr (struct TWI_DEV * dev , u16 addr , void * dat , u32 len )
320+ {
321+ u8 buf [2 ] = { addr >> 8 , addr };
322+ twi_start (dev -> bus , dev -> addr & 0xFE );
323+ twi_send (dev -> bus , buf , 2 );
324+ twi_send (dev -> bus , dat , 1 );
325+ twi_stop (dev -> bus );
326+ return twi_error ? KO : OK ;
327+ }
328+
329+ int gt911_read (struct TWI_DEV * dev )
330+ {
331+ u8 stat ;
332+ u16 x , y , z ;
333+ struct TS_GT911 * ts = (struct TS_GT911 * )dev -> data ;
334+ if (gt911_rd (dev , 0x814e , & stat , sizeof (stat )) == KO ) return 0 ;
335+ if (!(stat & 0x80 )) return 0 ;
336+ stat &= 15 ;
337+ for (int addr = 0x8150 , i = 0 ; i < stat ; i ++ )
338+ {
339+ if (gt911_rd (dev , addr , & x , sizeof (x )) == KO ) return 0 ;
340+ if (gt911_rd (dev , addr + 2 , & y , sizeof (y )) == KO ) return 0 ;
341+ if (gt911_rd (dev , addr + 4 , & z , sizeof (z )) == KO ) return 0 ;
342+ addr += 8 ;
343+ //printf("pt%d:%d*%d*%d ", i, x, y, z);
344+ if (x < ts -> x1 ) x = ts -> x1 ; else if (x > ts -> x2 ) x = ts -> x2 ;
345+ if (y < ts -> y1 ) y = ts -> y1 ; else if (y > ts -> y2 ) y = ts -> y2 ;
346+ x = (x - ts -> x1 ) * (display -> width - 1 ) / (ts -> x2 - ts -> x1 );
347+ y = (y - ts -> y1 ) * (display -> height - 1 ) / (ts -> y2 - ts -> y1 );
348+ ts -> pt [i ].x = x ;
349+ ts -> pt [i ].y = y ;
350+ ts -> pt [i ].z = z ;
351+ }
352+ z = 0 ;
353+ gt911_wr (dev , 0x814e , & z , 1 );
354+ return stat ;
298355}
0 commit comments