touch screen handler for the microchip AR1020

Revision:
3:b7eb3b3fe79f
Parent:
2:1a436d154c84
Child:
4:510ea5b28a05
diff -r 1a436d154c84 -r b7eb3b3fe79f ar1020.cpp
--- a/ar1020.cpp	Tue Feb 22 22:11:49 2011 +0000
+++ b/ar1020.cpp	Tue Feb 22 22:54:25 2011 +0000
@@ -63,24 +63,36 @@
 }
 
 void AR1020::init() {
-    _power->write(1);
-    wait_ms(100);
-    int r=cmd(0x13,NULL,0);
-    printf("disable touch=%i\n",r);
-
-    int regStart=cmd(0x22,NULL,0);
-    printf("reg offset=%i\n",regStart);
-
-    if (regStart<0)
-        return;
-
-    char cid2[4]={0x00,0x0d+regStart,0x01,0x01};
-    r=cmd(0x21,cid2,4);
-    printf("set mode=1 => %i\n",r);
-
-
-    r=cmd(0x12,NULL,0);
-    printf("enable touch=%i\n",r);
+    bool ok=false;
+    while (!ok)
+    {
+        _power->write(0);
+        wait_ms(200);
+        _power->write(1);
+        wait_ms(100);
+        int r=cmd(0x13,NULL,0);
+        printf("disable touch=%i\n",r);
+        if (0!=r)
+            continue;
+    
+        int regStart=cmd(0x22,NULL,0);
+        printf("reg offset=%i\n",regStart);
+    
+        if (regStart<0)
+            continue;
+    
+        char cid2[4]={0x00,0x0d+regStart,0x01,0x01};
+        r=cmd(0x21,cid2,4);
+        printf("set mode=1 => %i\n",r);
+        if (0!=r)
+            continue;
+    
+        r=cmd(0x12,NULL,0);
+        printf("enable touch=%i\n",r);
+        if (0!=r)
+            continue;
+        ok=true;
+    }
     _irq->rise(this, &AR1020::read);
 }