From e12fc5e3f0bec08274794f954fa114323c874e09 Mon Sep 17 00:00:00 2001 From: Stanley Huang Date: Wed, 25 Nov 2015 22:58:32 +1100 Subject: Add touch screen support --- megalogger/touch.h | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 megalogger/touch.h (limited to 'megalogger/touch.h') diff --git a/megalogger/touch.h b/megalogger/touch.h new file mode 100644 index 0000000..93ba740 --- /dev/null +++ b/megalogger/touch.h @@ -0,0 +1,127 @@ +#define T_CLK 6 +#define T_CS 5 +#define T_DIN 4 +#define T_DOUT 3 +#define T_IRQ 2 + +#define X_CONST 240 +#define Y_CONST 320 + +#define PREC_TOUCH_CONST 10 + +#define PixSizeX 13.78 +#define PixOffsX 411 + +#define PixSizeY 11.01 +#define PixOffsY 378 + +class CTouch { +public: + void init(void) + { + pinMode(T_CLK, OUTPUT); + pinMode(T_CS, OUTPUT); + pinMode(T_DIN, OUTPUT); + pinMode(T_DOUT, INPUT); + pinMode(T_IRQ, INPUT); + + digitalWrite(T_CS, HIGH); + digitalWrite(T_CLK, HIGH); + digitalWrite(T_DIN, HIGH); + digitalWrite(T_CLK, HIGH); + } + + void writeData(unsigned char data) + { + unsigned char temp; + unsigned char nop; + unsigned char count; + + temp=data; + digitalWrite(T_CLK,LOW); + + for(count=0; count<8; count++) + { + if(temp & 0x80) + digitalWrite(T_DIN, HIGH); + else + digitalWrite(T_DIN, LOW); + temp = temp << 1; + digitalWrite(T_CLK, LOW); + nop++; + digitalWrite(T_CLK, HIGH); + nop++; + } + } + + unsigned int readData() + { + unsigned char nop; + unsigned int data = 0; + unsigned char count; + for(count=0; count<12; count++) + { + data <<= 1; + digitalWrite(T_CLK, HIGH); + nop++; + digitalWrite(T_CLK, LOW); + nop++; + if (digitalRead(T_DOUT)) + data++; + } + return(data); + } + + void read() + { + unsigned long tx=0; + unsigned long ty=0; + + digitalWrite(T_CS,LOW); + + for (int i=0; i