From 55c8323950397d7bb6829f9fbd1a50a61d4913ce Mon Sep 17 00:00:00 2001 From: Tectu Date: Thu, 9 Aug 2012 02:31:42 +0200 Subject: more touchpad stuff --- halext/src/touchpad.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) (limited to 'halext/src') diff --git a/halext/src/touchpad.c b/halext/src/touchpad.c index 4adb25fe..912e2256 100644 --- a/halext/src/touchpad.c +++ b/halext/src/touchpad.c @@ -60,6 +60,44 @@ volatile static struct cal cal = { /* Driver local functions. */ /*===========================================================================*/ +/** + * @brief returns the uncalibrated readout of the X direction from the controller + * + * @noapi + */ +static uint16_t _tpReadRealX(void) { + uint32_t results = 0; + uint16_t i, x; + + for(i = 0; i < CONVERSIONS; i++) { + tp_lld_read_x(); /* dummy, reduce noise on SPI */ + results += tp_lld_read_x(); + } + + x = (((SCREEN_WIDTH-1) * (results/CONVERSIONS)) / 2048); + + return x; +} + +/** + * @brief return the uncalibrated readout of the Y-direction from the controller + * + * @noapi + */ +static uint16_t _tpReadRealY(void) { + uint32_t results = 0; + uint16_t i, y; + + for(i = 0; i < CONVERSIONS; i++) { + tp_lld_read_y(); /* dummy, reduce noise on SPI */ + results += tp_lld_read_y(); + } + + y = (((SCREEN_HEIGHT-1) * (results/CONVERSIONS)) / 2048); + + return y; +} + /*===========================================================================*/ /* Driver exported functions. */ /*===========================================================================*/ @@ -105,7 +143,8 @@ uint16_t tpReadX(void) { case landscapeInv: return y; } - return x; + + return x; } /** @@ -116,7 +155,24 @@ uint16_t tpReadX(void) { * @api */ uint16_t tpReadY(void) { - return (tp_lld_read_y()); + uint16_t x, y; + + x = cal.xm * _tpReadRealX() + cal.xn; + y = cal.ym * _tpReadRealY() + cal.yn; + + //switch(gdispGetOrientation()) { + switch(portrait) { // implement gdispGetOrientation() + case portrait: + return y; + case landscape: + return x; + case portraitInv: + return SCREEN_HEIGHT - y; + case landscapeInv: + return SCREEN_WIDTH - x; + } + + return y; } #if TOUCHPAD_PRESSURE || defined(__DOXYGEN__) @@ -128,6 +184,7 @@ uint16_t tpReadY(void) { * @api */ uint16_t tpReadZ(void) { + /* ToDo */ return (tp_lld_read_z()); } #endif -- cgit v1.2.3