diff --git a/README.txt b/README.txt index cf94dd1..13282f4 100644 --- a/README.txt +++ b/README.txt @@ -1,4 +1,11 @@ This is the 4-wire resistive touch screen firmware for Arduino. Works with all Arduinos and the Mega +I have comoleted the the library in the sense of now the library is pinsafe with LCD. No need to pull LCD pins anymore in sketches. -To install, click DOWNLOAD SOURCE in the top right corner, and rename the uncompressed folder "TouchScreen". See our tutorial at http://www.ladyada.net/library/arduino/libraries.html on Arduino Library installation \ No newline at end of file +I also made in UNO and MEGA the library fully port writes so touch screen would be faster. + +I removed porthandling initializings from getPoint function to seepd up the point fetching. + +I added cleanPins function which is driven on pin affecting functions. + +Added bool isTouching function for looping pressure where needed. diff --git a/TouchScreen.cpp b/TouchScreen.cpp index d4aca3e..b015d34 100644 --- a/TouchScreen.cpp +++ b/TouchScreen.cpp @@ -53,34 +53,27 @@ TSPoint TouchScreen::getPoint(void) { int samples[NUMSAMPLES]; uint8_t i, valid; - - uint8_t xp_port = digitalPinToPort(_xp); - uint8_t yp_port = digitalPinToPort(_yp); - uint8_t xm_port = digitalPinToPort(_xm); - uint8_t ym_port = digitalPinToPort(_ym); - - uint8_t xp_pin = digitalPinToBitMask(_xp); - uint8_t yp_pin = digitalPinToBitMask(_yp); - uint8_t xm_pin = digitalPinToBitMask(_xm); - uint8_t ym_pin = digitalPinToBitMask(_ym); - - valid = 1; pinMode(_yp, INPUT); pinMode(_ym, INPUT); - + #if defined(__arm__) + digitalWrite(_yp, LOW); + digitalWrite(_ym, LOW); + #else *portOutputRegister(yp_port) &= ~yp_pin; *portOutputRegister(ym_port) &= ~ym_pin; - //digitalWrite(_yp, LOW); - //digitalWrite(_ym, LOW); + #endif - pinMode(_xp, OUTPUT); - pinMode(_xm, OUTPUT); - //digitalWrite(_xp, HIGH); - //digitalWrite(_xm, LOW); - *portOutputRegister(xp_port) |= xp_pin; - *portOutputRegister(xm_port) &= ~xm_pin; + pinMode(_xp, OUTPUT); + pinMode(_xm, OUTPUT); + #if defined(__arm__) + digitalWrite(_xp, HIGH); + digitalWrite(_xm, LOW); + #else + *portOutputRegister(xp_port) |= xp_pin; + *portOutputRegister(xm_port) &= ~xm_pin; + #endif for (i=0; i 20 && touch < 980) { + return true; + } + else return false; +} + +//Pin clearing function. This clears used pins for better LCD support on same pins. +void TouchScreen::cleanPins(void) { + #if defined(__arm__) + pinMode(_xm, OUTPUT); + digitalWrite(_xm, LOW); + pinMode(_yp, OUTPUT); + digitalWrite(_yp, HIGH); + pinMode(_ym, OUTPUT); + digitalWrite(_ym, LOW); + pinMode(_xp, OUTPUT); + digitalWrite(_xp, HIGH); + #else + pinMode(_xm, OUTPUT); + *portOutputRegister(xm_port) &= ~xm_pin; + pinMode(_yp, OUTPUT); + *portOutputRegister(yp_port) |= yp_pin; + pinMode(_ym, OUTPUT); + *portOutputRegister(ym_port) &= ~ym_pin + pinMode(_xp, OUTPUT); + *portOutputRegister(xp_port) |= xp_pin; + #endif +} \ No newline at end of file diff --git a/TouchScreen.h b/TouchScreen.h index 39b7a2e..ba4356e 100644 --- a/TouchScreen.h +++ b/TouchScreen.h @@ -25,14 +25,25 @@ class TouchScreen { bool isTouching(void); uint16_t pressure(void); - int readTouchY(); - int readTouchX(); + uint16_t readTouchY(); + uint16_t readTouchX(); TSPoint getPoint(); int16_t pressureThreshhold; private: + //Input pins uint8_t _yp, _ym, _xm, _xp; - uint16_t _rxplate; + #if defined(__arm__) + //No port manipulation in DUE and ARM boards + #elde + //Input pins port registers + uint8_t xp_port, yp_port, xm_port, ym_port; + //Input pins converted to mask + uint8_t xp_pin, yp_pin, xm_pin ,ym_pin; + #endif + uint16_t _rxplate; + //Internal cleanup function + void cleanPins(void); }; #endif