chiark / gitweb /
Added some tweaks to gpio to set alt modes on pins (sssh!)
[wiringPi.git] / gpio / gpio.c
index fab003618e7f764b037304246bfb6c6034bcbacb..b65af0eb8d63ca3c1fc56eab46d88159d9553c96 100644 (file)
@@ -51,7 +51,7 @@ extern void doReadallOld (void) ;
 #  define      FALSE   (1==2)
 #endif
 
-#define        VERSION         "2.12"
+#define        VERSION         "2.13"
 #define        I2CDETECT       "/usr/sbin/i2cdetect"
 
 int wpMode ;
@@ -75,6 +75,25 @@ char *usage = "Usage: gpio -v\n"
              "       gpio gbw <channel> <value>" ;     // No trailing newline needed here.
 
 
+/*
+ * decodePin:
+ *     Decode a pin "number" which can actually be a pin name to represent
+ *     one of the Pi's on-board pins.
+ *********************************************************************************
+ */
+
+static int decodePin (const char *str)
+{
+
+// The first case - see if it's a number:
+
+  if (isdigit (str [0]))
+    return atoi (str) ;
+
+  return 0 ;
+}
+
+
 /*
  * changeOwner:
  *     Change the ownership of the file to the real userId of the calling
@@ -639,6 +658,15 @@ void doMode (int argc, char *argv [])
   else if (strcasecmp (mode, "down")   == 0) pullUpDnControl (pin, PUD_DOWN) ;
   else if (strcasecmp (mode, "tri")    == 0) pullUpDnControl (pin, PUD_OFF) ;
   else if (strcasecmp (mode, "off")    == 0) pullUpDnControl (pin, PUD_OFF) ;
+
+// Undocumented
+
+  else if (strcasecmp (mode, "alt0")    == 0) pinModeAlt (pin, 0b100) ;
+  else if (strcasecmp (mode, "alt1")    == 0) pinModeAlt (pin, 0b101) ;
+  else if (strcasecmp (mode, "alt2")    == 0) pinModeAlt (pin, 0b110) ;
+  else if (strcasecmp (mode, "alt3")    == 0) pinModeAlt (pin, 0b111) ;
+  else if (strcasecmp (mode, "alt4")    == 0) pinModeAlt (pin, 0b011) ;
+  else if (strcasecmp (mode, "alt5")    == 0) pinModeAlt (pin, 0b010) ;
   else
   {
     fprintf (stderr, "%s: Invalid mode: %s. Should be in/out/pwm/clock/up/down/tri\n", argv [1], mode) ;