# define FALSE (1==2)
#endif
-#define VERSION "2.12"
+#define VERSION "2.13"
#define I2CDETECT "/usr/sbin/i2cdetect"
int wpMode ;
" 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
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) ;
#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
*********************************************************************************
*/
+/*
+ * 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:
extern int wiringPiSetupGpio (void) ;
extern int wiringPiSetupPhys (void) ;
+extern void pinModeAlt (int pin, int mode) ;
extern void pinMode (int pin, int mode) ;
extern void pullUpDnControl (int pin, int pud) ;
extern int digitalRead (int pin) ;