chiark / gitweb /
Changes to the piNes driver to relect the new delayMicroseconds()
authorGordon Henderson <gordon@drogon.net>
Mon, 20 Aug 2012 10:08:34 +0000 (11:08 +0100)
committerGordon Henderson <gordon@drogon.net>
Mon, 20 Aug 2012 10:08:34 +0000 (11:08 +0100)
code. Seems the old 4011 in the NES controller isn't that fast
afterall!

wiringPi/piNes.c

index 1722d31fd78acf8f12c4c3037e56e2389edc0cc1..a115050e8a96102801aff480b0a0a2b27e7fcf20 100644 (file)
@@ -38,6 +38,8 @@
 #define        NES_A           0x80
 
 
+#define        PULSE_TIME      25
+
 // Data to store the pins for each controller
 
 struct nesPinsStruct
@@ -91,10 +93,8 @@ unsigned int readNesJoystick (int joystick)
  
 // Toggle Latch - which presents the first bit
 
-  digitalWrite (pins->lPin, HIGH) ;
-  delayMicroseconds (1) ;
-  digitalWrite (pins->lPin, LOW) ;
-  delayMicroseconds (1) ;
+  digitalWrite (pins->lPin, HIGH) ; delayMicroseconds (PULSE_TIME) ;
+  digitalWrite (pins->lPin, LOW)  ; delayMicroseconds (PULSE_TIME) ;
 
 // Read first bit
 
@@ -104,12 +104,10 @@ unsigned int readNesJoystick (int joystick)
 
   for (i = 0 ; i < 7 ; ++i)
   {
-    digitalWrite (pins->cPin, HIGH) ;
-    delayMicroseconds (1) ;
-    digitalWrite (pins->cPin, LOW) ;
-    delayMicroseconds (1) ;
+    digitalWrite (pins->cPin, HIGH) ; delayMicroseconds (PULSE_TIME) ;
+    digitalWrite (pins->cPin, LOW)  ; delayMicroseconds (PULSE_TIME) ;
     value = (value << 1) | digitalRead (pins->dPin) ;
   }
 
-  return ~value ;
+  return value ^ 0xFF ;
 }