Declaration class (driver for) of touchpanel based on ADS7843 or XPT2046

Dependents:   TFT_MyTouch

Committer:
micchassek
Date:
Fri Nov 28 22:33:06 2014 +0000
Revision:
0:bd11ac9148e2
Wersja perwsza v1.0 do rozbudowy

Who changed what in which revision?

UserRevisionLine numberNew contents of line
micchassek 0:bd11ac9148e2 1 #include "mbed.h"
micchassek 0:bd11ac9148e2 2 #include "MyTouch.h"
micchassek 0:bd11ac9148e2 3
micchassek 0:bd11ac9148e2 4 MYTOUCH::MYTOUCH(PinName _tp_mosi, PinName _tp_miso, PinName _tp_sclk, PinName _tp_cs, PinName _tp_irq, unsigned char _resolution, void (*pointer_To_TP_IRQ_Handler)(void))
micchassek 0:bd11ac9148e2 5 :tp_spi(_tp_mosi,_tp_miso,_tp_sclk),tp_cs(_tp_cs),tp_irqhandler(_tp_irq)
micchassek 0:bd11ac9148e2 6 {
micchassek 0:bd11ac9148e2 7 tp_cs = 1 ;
micchassek 0:bd11ac9148e2 8 tp_spi.frequency(TP_FREQUENCY) ;
micchassek 0:bd11ac9148e2 9 tp_spi.format(8,0) ;
micchassek 0:bd11ac9148e2 10
micchassek 0:bd11ac9148e2 11 argument_type[0] = TP_GETX_12BIT ;
micchassek 0:bd11ac9148e2 12 argument_type[1] = TP_GETY_12BIT ;
micchassek 0:bd11ac9148e2 13 argument_type[2] = TP_GETX_8BIT ;
micchassek 0:bd11ac9148e2 14 argument_type[3] = TP_GETY_8BIT ;
micchassek 0:bd11ac9148e2 15
micchassek 0:bd11ac9148e2 16 if (pointer_To_TP_IRQ_Handler!=NULL)
micchassek 0:bd11ac9148e2 17 tp_irqhandler.fall(pointer_To_TP_IRQ_Handler) ;
micchassek 0:bd11ac9148e2 18
micchassek 0:bd11ac9148e2 19 tp_mode = _resolution ;
micchassek 0:bd11ac9148e2 20 }
micchassek 0:bd11ac9148e2 21
micchassek 0:bd11ac9148e2 22 unsigned int MYTOUCH::TP_Get(unsigned char XY)
micchassek 0:bd11ac9148e2 23 {
micchassek 0:bd11ac9148e2 24 unsigned char hi, low;
micchassek 0:bd11ac9148e2 25 unsigned int tmp;
micchassek 0:bd11ac9148e2 26
micchassek 0:bd11ac9148e2 27 tmp=0;
micchassek 0:bd11ac9148e2 28 tp_cs.write(0);
micchassek 0:bd11ac9148e2 29 wait_us(1);
micchassek 0:bd11ac9148e2 30 tp_spi.write(argument_type[tp_mode+XY]);
micchassek 0:bd11ac9148e2 31 wait_us(1);
micchassek 0:bd11ac9148e2 32 if (tp_mode==USE_12BITS)
micchassek 0:bd11ac9148e2 33 {
micchassek 0:bd11ac9148e2 34 hi = tp_spi.write(0x00); // hi
micchassek 0:bd11ac9148e2 35 wait_us(1);
micchassek 0:bd11ac9148e2 36 }
micchassek 0:bd11ac9148e2 37 low = tp_spi.write(0x00); // low
micchassek 0:bd11ac9148e2 38 tp_cs.write(1);
micchassek 0:bd11ac9148e2 39 tmp = ((hi << 8 ) | low);
micchassek 0:bd11ac9148e2 40 tmp >>= 3;
micchassek 0:bd11ac9148e2 41 tmp &= 0xfff;
micchassek 0:bd11ac9148e2 42 tmp /= 4; // between 0 and 1024
micchassek 0:bd11ac9148e2 43 return tmp;
micchassek 0:bd11ac9148e2 44 }