This patch modifies cy8ctmg110_touch_pos to map all of the data provided
from the hardware into the cy8ctmg110 data structure for use within the
driver.  In doing so, the patch also cleans up some endian conversions to
use be16_to_cpup()

This gets the driver one step closer to being able to support multi-touch.

Signed-off-by: James Ketrenos <[email protected]>
---
drivers/input/touchscreen/cy8ctmg110_ts.c | 80 ++++++++++++++++++----------
 1 files changed, 51 insertions(+), 29 deletions(-)

diff --git a/drivers/input/touchscreen/cy8ctmg110_ts.c b/drivers/input/touchscreen/cy8ctmg110_ts.c
index c1677f9..1337371 100644
--- a/drivers/input/touchscreen/cy8ctmg110_ts.c
+++ b/drivers/input/touchscreen/cy8ctmg110_ts.c
@@ -57,6 +57,7 @@

 #define CY8CTMG110_POLL_TIMER_DELAY    (1000*1000*100)
 #define TOUCH_MAX_I2C_FAILS        50
+#define MAX_FINGERS            2

 /* Polling mode */
 static int polling;
@@ -72,6 +73,8 @@ struct ts_event {
     int y1;
     int x2;
     int y2;
+    int fingers;
+    int gesture;
 };

 /*
@@ -154,47 +157,66 @@ static int cy8ctmg110_read_req(struct cy8ctmg110 *tsc,
 }

 /*
- * cy8ctmg110_send_event delevery touch event to the userpace
- * function use normal input interface
- */
-static void cy8ctmg110_send_event(void *tsc)
-{
-    struct cy8ctmg110 *ts = tsc;
-    struct input_dev *input = ts->input;
-
-    input_report_key(input, BTN_TOUCH, 1);
-    input_report_abs(input, ABS_X, ts->tc.y1);
-    input_report_abs(input, ABS_Y, ts->tc.x1);
-    input_sync(input);
-}
-
-/*
  * cy8ctmg110_touch_pos check touch position from i2c devices
  */
 static int cy8ctmg110_touch_pos(struct cy8ctmg110 *tsc)
 {
     unsigned char reg_p[CY8CTMG110_REG_MAX];
-    int x, y;

     memset(reg_p, 0, CY8CTMG110_REG_MAX);

     /* Reading coordinates */
-    if (cy8ctmg110_read_req(tsc, reg_p, 9, CY8CTMG110_TOUCH_X1) != 0)
+    if (cy8ctmg110_read_req(tsc, reg_p, CY8CTMG110_REG_MAX, 0) != 0)
         return -EIO;

-    y = reg_p[2] << 8 | reg_p[3];
-    x = reg_p[0] << 8 | reg_p[1];
-
-    /* Number of touch */
-    if (reg_p[8] == 0) {
-        struct input_dev *input = tsc->input;
-        input_report_key(input, BTN_TOUCH, 0);
-        input_sync(input);
-    } else if (tsc->tc.x1 != x || tsc->tc.y1 != y) {
-        tsc->tc.y1 = y;
-        tsc->tc.x1 = x;
-        cy8ctmg110_send_event(tsc);
+    /*
+     * Position coordinates are big-endian
+     *
+     * NOTE:  Protocol byte order is swapped from what the hardware
+     * is reporting, so swap them here.
+     */
+    tsc->tc.y1 = be16_to_cpup((__be16 *)&reg_p[CY8CTMG110_TOUCH_X1]);
+    tsc->tc.x1 = be16_to_cpup((__be16 *)&reg_p[CY8CTMG110_TOUCH_Y1]);
+    tsc->tc.y2 = be16_to_cpup((__be16 *)&reg_p[CY8CTMG110_TOUCH_X2]);
+    tsc->tc.x2 = be16_to_cpup((__be16 *)&reg_p[CY8CTMG110_TOUCH_Y2]);
+
+    /*
+     * TODO:
+     *
+     * Add 'gesture' as ABS_MISC data or ???  Not sure what the
+     * correct input API to use.  The 'gesture' is a magic code that
+     * maps to the Cypress controller detecting a given
+     * gesture...
+     *
+     * Through experimentation, it appears to report:
+     * 0x08 two-finger swipe left [or 'up' if axis swap]
+     * 0x09 two-finger swipe down [or 'right' if axis swap]
+     * 0x0a two-finger swipe right [or 'down' if axis swap]
+     * 0x0b two-finger swipe up [or 'left' if axis swap]
+     * 0x0c pinch
+     * 0x0d unpinch
+     */
+    tsc->tc.gesture = reg_p[CY8CTMG110_GESTURE];
+
+    /* Number of contact points: 0, 1, 2 */
+    tsc->tc.fingers = reg_p[CY8CTMG110_FINGERS];
+    if (tsc->tc.fingers > MAX_FINGERS)
+        tsc->tc.fingers = 0;
+
+    /* Set/Clear BTN_TOUCH bit based on if any contact points */
+    input_event(tsc->input, EV_KEY, BTN_TOUCH, tsc->tc.fingers);
+
+    /*
+     * Track the '1st' finger; this might need to be improved as it
+     * could result in a borken experience when the user presses
+     * with contact 1, presses contact 2, then releases contact 1.
+     */
+    if (tsc->tc.fingers) {
+        input_report_abs(tsc->input, ABS_X, tsc->tc.x1);
+        input_report_abs(tsc->input, ABS_Y, tsc->tc.y1);
     }
+    input_sync(tsc->input);
+
     return 0;
 }

--
1.7.1

_______________________________________________
MeeGo-dev mailing list
[email protected]
http://lists.meego.com/listinfo/meego-dev

Reply via email to