chiark / gitweb /
Added some tweaks to gpio to set alt modes on pins (sssh!)
[wiringPi.git] / wiringPi / wiringPi.c
index ba61d9fab64efa3e3593c2c9b00b7ff67907096e..b54ad292cfb91c2d4908781ebdc2c538e7d1f0a6 100644 (file)
@@ -118,7 +118,6 @@ struct wiringPiNodeStruct *wiringPiNodes = NULL ;
 #define        FSEL_INPT               0b000
 #define        FSEL_OUTP               0b001
 #define        FSEL_ALT0               0b100
-#define        FSEL_ALT0               0b100
 #define        FSEL_ALT1               0b101
 #define        FSEL_ALT2               0b110
 #define        FSEL_ALT3               0b111
@@ -925,6 +924,32 @@ void pinEnableED01Pi (int pin)
  *********************************************************************************
  */
 
+/*
+ * pinModeAlt:
+ *     This is an un-documented special to let you set any pin to any mode
+ *********************************************************************************
+ */
+
+void pinModeAlt (int pin, int mode)
+{
+  int fSel, shift ;
+
+  if ((pin & PI_GPIO_MASK) == 0)               // On-board pin
+  {
+    /**/ if (wiringPiMode == WPI_MODE_PINS)
+      pin = pinToGpio [pin] ;
+    else if (wiringPiMode == WPI_MODE_PHYS)
+      pin = physToGpio [pin] ;
+    else if (wiringPiMode != WPI_MODE_GPIO)
+      return ;
+
+    fSel  = gpioToGPFSEL [pin] ;
+    shift = gpioToShift  [pin] ;
+
+    *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) | ((mode & 0x7) << shift) ;
+  }
+}
+
 
 /*
  * pinMode: