+ struct wiringPiNodeStruct *node = wiringPiNodes ;
+
+ if ((pin & PI_GPIO_MASK) == 0) // On-Board Pin
+ {
+ /**/ if (wiringPiMode == WPI_MODE_GPIO_SYS) // Sys mode
+ {
+ if (sysFds [pin] != -1)
+ {
+ if (value == LOW)
+ write (sysFds [pin], "0\n", 2) ;
+ else
+ write (sysFds [pin], "1\n", 2) ;
+ }
+ return ;
+ }
+ else if (wiringPiMode == WPI_MODE_PINS)
+ pin = pinToGpio [pin] ;
+ else if (wiringPiMode == WPI_MODE_PHYS)
+ pin = physToGpio [pin] ;
+ else if (wiringPiMode != WPI_MODE_GPIO)
+ return ;
+
+ if (value == LOW)
+ *(gpio + gpioToGPCLR [pin]) = 1 << (pin & 31) ;
+ else
+ *(gpio + gpioToGPSET [pin]) = 1 << (pin & 31) ;
+ }
+ else
+ {
+ if ((node = wiringPiFindNode (pin)) != NULL)
+ node->digitalWrite (node, pin, value) ;
+ }
+}
+
+
+/*
+ * pwmWrite:
+ * Set an output PWM value
+ *********************************************************************************
+ */
+
+void pwmWrite (int pin, int value)
+{
+ struct wiringPiNodeStruct *node = wiringPiNodes ;
+
+ 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 ;
+
+ *(pwm + gpioToPwmPort [pin]) = value ;
+ }
+ else
+ {
+ if ((node = wiringPiFindNode (pin)) != NULL)
+ node->pwmWrite (node, pin, value) ;
+ }
+}
+
+
+/*
+ * analogRead:
+ * Read the analog value of a given Pin.
+ * There is no on-board Pi analog hardware,
+ * so this needs to go to a new node.
+ *********************************************************************************
+ */
+
+int analogRead (int pin)
+{
+ struct wiringPiNodeStruct *node = wiringPiNodes ;
+
+ if ((node = wiringPiFindNode (pin)) == NULL)
+ return 0 ;
+ else
+ return node->analogRead (node, pin) ;
+}
+
+
+/*
+ * analogWrite:
+ * Write the analog value to the given Pin.
+ * There is no on-board Pi analog hardware,
+ * so this needs to go to a new node.
+ *********************************************************************************
+ */
+
+void analogWrite (int pin, int value)
+{
+ struct wiringPiNodeStruct *node = wiringPiNodes ;
+
+ if ((node = wiringPiFindNode (pin)) == NULL)
+ return ;
+
+ node->analogWrite (node, pin, value) ;
+}
+
+
+/*
+ * pwmToneWrite:
+ * Pi Specific.
+ * Output the given frequency on the Pi's PWM pin
+ *********************************************************************************
+ */
+
+void pwmToneWrite (int pin, int freq)
+{
+ int range ;
+
+ if (freq == 0)
+ pwmWrite (pin, 0) ; // Off
+ else
+ {
+ range = 600000 / freq ;
+ pwmSetRange (range) ;
+ pwmWrite (pin, freq / 2) ;
+ }
+}
+
+
+
+/*
+ * digitalWriteByte:
+ * Pi Specific
+ * Write an 8-bit byte to the first 8 GPIO pins - try to do it as
+ * fast as possible.
+ * However it still needs 2 operations to set the bits, so any external
+ * hardware must not rely on seeing a change as there will be a change
+ * to set the outputs bits to zero, then another change to set the 1's
+ *********************************************************************************
+ */
+
+void digitalWriteByte (int value)
+{
+ uint32_t pinSet = 0 ;
+ uint32_t pinClr = 0 ;
+ int mask = 1 ;
+ int pin ;
+
+ /**/ if (wiringPiMode == WPI_MODE_GPIO_SYS)
+ {
+ for (pin = 0 ; pin < 8 ; ++pin)
+ {
+ digitalWrite (pin, value & mask) ;
+ mask <<= 1 ;
+ }
+ return ;
+ }
+ else
+ {
+ for (pin = 0 ; pin < 8 ; ++pin)
+ {
+ if ((value & mask) == 0)
+ pinClr |= (1 << pinToGpio [pin]) ;
+ else
+ pinSet |= (1 << pinToGpio [pin]) ;
+
+ mask <<= 1 ;
+ }
+
+ *(gpio + gpioToGPCLR [0]) = pinClr ;
+ *(gpio + gpioToGPSET [0]) = pinSet ;
+ }