+// Minimum pin base is 64
+
+ if (pinBase < 64)
+ (void)wiringPiFailure (WPI_FATAL, "wiringPiNewNode: pinBase of %d is < 64\n", pinBase) ;
+
+// Check all pins in-case there is overlap:
+
+ for (pin = pinBase ; pin < (pinBase + numPins) ; ++pin)
+ if (wiringPiFindNode (pin) != NULL)
+ (void)wiringPiFailure (WPI_FATAL, "wiringPiNewNode: Pin %d overlaps with existing definition\n", pin) ;
+
+ node = (struct wiringPiNodeStruct *)calloc (sizeof (struct wiringPiNodeStruct), 1) ; // calloc zeros
+ if (node == NULL)
+ (void)wiringPiFailure (WPI_FATAL, "wiringPiNewNode: Unable to allocate memory: %s\n", strerror (errno)) ;
+
+ node->pinBase = pinBase ;
+ node->pinMax = pinBase + numPins - 1 ;
+ node->pinMode = pinModeDummy ;
+ node->pullUpDnControl = pullUpDnControlDummy ;
+ node->digitalRead = digitalReadDummy ;
+ node->digitalWrite = digitalWriteDummy ;
+ node->pwmWrite = pwmWriteDummy ;
+ node->analogRead = analogReadDummy ;
+ node->analogWrite = analogWriteDummy ;
+ node->next = wiringPiNodes ;
+ wiringPiNodes = node ;
+
+ return node ;
+}
+
+
+#ifdef notYetReady
+/*
+ * pinED01:
+ * pinED10:
+ * Enables edge-detect mode on a pin - from a 0 to a 1 or 1 to 0
+ * Pin must already be in input mode with appropriate pull up/downs set.
+ *********************************************************************************
+ */
+
+void pinEnableED01Pi (int pin)
+{
+ pin = pinToGpio [pin & 63] ;
+}
+#endif
+
+
+/*
+ *********************************************************************************
+ * Core Functions
+ *********************************************************************************
+ */
+
+/*
+ * 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:
+ * Sets the mode of a pin to be input, output or PWM output
+ *********************************************************************************
+ */
+
+void pinMode (int pin, int mode)
+{
+ int fSel, shift, alt ;
+ struct wiringPiNodeStruct *node = wiringPiNodes ;
+ int origPin = pin ;
+
+ 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 ;
+
+ softPwmStop (origPin) ;
+ softToneStop (origPin) ;
+
+ fSel = gpioToGPFSEL [pin] ;
+ shift = gpioToShift [pin] ;
+
+ /**/ if (mode == INPUT)
+ *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) ; // Sets bits to zero = input
+ else if (mode == OUTPUT)
+ *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) | (1 << shift) ;
+ else if (mode == SOFT_PWM_OUTPUT)
+ softPwmCreate (origPin, 0, 100) ;
+ else if (mode == SOFT_TONE_OUTPUT)
+ softToneCreate (origPin) ;
+ else if (mode == PWM_TONE_OUTPUT)
+ {
+ pinMode (origPin, PWM_OUTPUT) ; // Call myself to enable PWM mode
+ pwmSetMode (PWM_MODE_MS) ;
+ }
+ else if (mode == PWM_OUTPUT)
+ {
+ if ((alt = gpioToPwmALT [pin]) == 0) // Not a hardware capable PWM pin
+ return ;
+
+// Set pin to PWM mode
+
+ *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) | (alt << shift) ;
+ delayMicroseconds (110) ; // See comments in pwmSetClockWPi
+
+ pwmSetMode (PWM_MODE_BAL) ; // Pi default mode
+ pwmSetRange (1024) ; // Default range of 1024
+ pwmSetClock (32) ; // 19.2 / 32 = 600KHz - Also starts the PWM
+ }
+ else if (mode == GPIO_CLOCK)
+ {
+ if ((alt = gpioToGpClkALT0 [pin]) == 0) // Not a GPIO_CLOCK pin
+ return ;
+
+// Set pin to GPIO_CLOCK mode and set the clock frequency to 100KHz
+
+ *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) | (alt << shift) ;
+ delayMicroseconds (110) ;
+ gpioClockSet (pin, 100000) ;
+ }
+ }
+ else
+ {
+ if ((node = wiringPiFindNode (pin)) != NULL)
+ node->pinMode (node, pin, mode) ;
+ return ;
+ }