]> Git Repo - qemu.git/blobdiff - hw/ads7846.c
Remove duplicate device index calculations.
[qemu.git] / hw / ads7846.c
index d63a91541943bcd3779a79def56527972aae31b3..b39c00f51502c3e4428334e292e819666db9899a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * TI ADS7846 chip emulation.
+ * TI ADS7846 / TSC2046 chip emulation.
  *
  * Copyright (c) 2006 Openedhand Ltd.
  * Written by Andrzej Zaborowski <[email protected]>
@@ -7,7 +7,9 @@
  * This code is licensed under the GNU GPL v2.
  */
 
-#include <vl.h>
+#include "hw.h"
+#include "devices.h"
+#include "console.h"
 
 struct ads7846_state_s {
     qemu_irq interrupt;
@@ -30,10 +32,10 @@ struct ads7846_state_s {
 #define CB_A2          (1 << 6)
 #define CB_START       (1 << 7)
 
-#define X_AXIS_DMAX    3680
-#define X_AXIS_MIN     150
-#define Y_AXIS_DMAX    3640
-#define Y_AXIS_MIN     190
+#define X_AXIS_DMAX    3470
+#define X_AXIS_MIN     290
+#define Y_AXIS_DMAX    3450
+#define Y_AXIS_MIN     200
 
 #define ADS_VBAT       2000
 #define ADS_VAUX       2000
@@ -95,19 +97,49 @@ static void ads7846_ts_event(void *opaque,
     struct ads7846_state_s *s = opaque;
 
     if (buttons_state) {
-        s->input[1] = ADS_YPOS(x, y);
+        x = 0x7fff - x;
+        s->input[1] = ADS_XPOS(x, y);
         s->input[3] = ADS_Z1POS(x, y);
         s->input[4] = ADS_Z2POS(x, y);
-        s->input[5] = ADS_XPOS(x, y);
+        s->input[5] = ADS_YPOS(x, y);
     }
 
     if (s->pressure == !buttons_state) {
         s->pressure = !!buttons_state;
 
-         ads7846_int_update(s);
+        ads7846_int_update(s);
     }
 }
 
+static void ads7846_save(QEMUFile *f, void *opaque)
+{
+    struct ads7846_state_s *s = (struct ads7846_state_s *) opaque;
+    int i;
+
+    for (i = 0; i < 8; i ++)
+        qemu_put_be32(f, s->input[i]);
+    qemu_put_be32(f, s->noise);
+    qemu_put_be32(f, s->cycle);
+    qemu_put_be32(f, s->output);
+}
+
+static int ads7846_load(QEMUFile *f, void *opaque, int version_id)
+{
+    struct ads7846_state_s *s = (struct ads7846_state_s *) opaque;
+    int i;
+
+    for (i = 0; i < 8; i ++)
+        s->input[i] = qemu_get_be32(f);
+    s->noise = qemu_get_be32(f);
+    s->cycle = qemu_get_be32(f);
+    s->output = qemu_get_be32(f);
+
+    s->pressure = 0;
+    ads7846_int_update(s);
+
+    return 0;
+}
+
 struct ads7846_state_s *ads7846_init(qemu_irq penirq)
 {
     struct ads7846_state_s *s;
@@ -127,5 +159,8 @@ struct ads7846_state_s *ads7846_init(qemu_irq penirq)
                     "QEMU ADS7846-driven Touchscreen");
 
     ads7846_int_update(s);
+
+    register_savevm("ads7846", -1, 0, ads7846_save, ads7846_load, s);
+
     return s;
 }
This page took 0.026604 seconds and 4 git commands to generate.