Declaration class (driver for) of touchpanel based on ADS7843 or XPT2046
Revision 0:bd11ac9148e2, committed 2014-11-28
- Comitter:
- micchassek
- Date:
- Fri Nov 28 22:33:06 2014 +0000
- Commit message:
- Wersja perwsza v1.0 do rozbudowy
Changed in this revision
MyTouch.cpp | Show annotated file Show diff for this revision Revisions of this file |
MyTouch.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r bd11ac9148e2 MyTouch.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MyTouch.cpp Fri Nov 28 22:33:06 2014 +0000 @@ -0,0 +1,44 @@ +#include "mbed.h" +#include "MyTouch.h" + +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)) + :tp_spi(_tp_mosi,_tp_miso,_tp_sclk),tp_cs(_tp_cs),tp_irqhandler(_tp_irq) + { + tp_cs = 1 ; + tp_spi.frequency(TP_FREQUENCY) ; + tp_spi.format(8,0) ; + + argument_type[0] = TP_GETX_12BIT ; + argument_type[1] = TP_GETY_12BIT ; + argument_type[2] = TP_GETX_8BIT ; + argument_type[3] = TP_GETY_8BIT ; + + if (pointer_To_TP_IRQ_Handler!=NULL) + tp_irqhandler.fall(pointer_To_TP_IRQ_Handler) ; + + tp_mode = _resolution ; + } + +unsigned int MYTOUCH::TP_Get(unsigned char XY) + { + unsigned char hi, low; + unsigned int tmp; + + tmp=0; + tp_cs.write(0); + wait_us(1); + tp_spi.write(argument_type[tp_mode+XY]); + wait_us(1); + if (tp_mode==USE_12BITS) + { + hi = tp_spi.write(0x00); // hi + wait_us(1); + } + low = tp_spi.write(0x00); // low + tp_cs.write(1); + tmp = ((hi << 8 ) | low); + tmp >>= 3; + tmp &= 0xfff; + tmp /= 4; // between 0 and 1024 + return tmp; + }
diff -r 000000000000 -r bd11ac9148e2 MyTouch.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MyTouch.h Fri Nov 28 22:33:06 2014 +0000 @@ -0,0 +1,41 @@ +// MyTouch.h - Declaration class (driver for) of touchpanel based on ADS7843 or XPT2046 +// version: 1.0 +// author: Mchał Pyszka +// date: 28 NOV 2014 +// +#ifndef MyTouch_h +#define MyTOUCH_H + +#include "mbed.h" + +#define USE_12BITS 0 +#define USE_8BITS 2 + +#define TP_GETX_8BIT 0x98 +#define TP_GETY_8BIT 0xD8 +#define TP_GETX_12BIT 0x90 +#define TP_GETY_12BIT 0xD0 + +#define TP_X 0 +#define TP_Y 1 + +#define TP_FREQUENCY 500000 + +class MYTOUCH + { + public: + 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)) ; + unsigned int TP_GetX(){return TP_Get(TP_X);} + unsigned int TP_GetY(){return TP_Get(TP_Y);} + void TP_ChangeMode(unsigned char _tp_mode){tp_mode = _tp_mode ;} + protected: + unsigned int TP_Get(unsigned char XY) ; + + unsigned char tp_mode ; + SPI tp_spi ; + DigitalOut tp_cs ; + InterruptIn tp_irqhandler ; + unsigned char argument_type[4] ; + } ; + +#endif \ No newline at end of file