diff --git a/WiringPi/VERSION b/WiringPi/VERSION
new file mode 100644
index 0000000..8bd2249
--- /dev/null
+++ b/WiringPi/VERSION
@@ -0,0 +1 @@
+2.25
diff --git a/WiringPi/build b/WiringPi/build
index bac483a..d38ad1b 100755
--- a/WiringPi/build
+++ b/WiringPi/build
@@ -1,5 +1,36 @@
#!/bin/sh
+# build
+# Simple wiringPi build and install script
+#
+# Copyright (c) 2012-2015 Gordon Henderson
+#################################################################################
+# This file is part of wiringPi:
+# Wiring Compatable library for the Raspberry Pi
+#
+# wiringPi is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# wiringPi is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with wiringPi. If not, see .
+#################################################################################
+#
+# wiringPi is designed to run on a Raspberry Pi only.
+# However if you're clever enough to actually look at this script to
+# see why it's not building for you, then good luck.
+#
+# To everyone else: Stop using cheap alternatives. Support the
+# Raspberry Pi Foundation as they're the only ones putting money
+# back into education!
+#################################################################################
+
check_make_ok() {
if [ $? != 0 ]; then
echo ""
@@ -42,21 +73,61 @@ if [ x$1 = "xuninstall" ]; then
exit
fi
+# Only if you know what you're doing!
+
+if [ x$1 = "xdebian" ]; then
+ here=`pwd`
+ cd debian/wiringPi
+ rm -rf usr
+ cd $here/wiringPi
+ make install-deb
+ cd $here/devLib
+ make install-deb
+ cd $here/gpio
+ make install-deb
+ cd $here/debian
+ fakeroot dpkg-deb --build wiringPi
+ mv wiringPi.deb wiringpi-`cat $here/VERSION`-1.deb
+ exit
+fi
+
+if [ x$1 != "x" ]; then
+ echo "Usage: $0 [clean | uninstall]"
+ exit 1
+fi
echo "wiringPi Build script"
echo "====================="
echo
+ hardware=`fgrep Hardware /proc/cpuinfo | head -1 | awk '{ print $3 }'`
+
+# if [ x$hardware != "xBCM2708" ]; then
+# echo ""
+# echo " +------------------------------------------------------------+"
+# echo " | wiringPi is designed to run on the Raspberry Pi only. |"
+# echo " | This processor does not appear to be a Raspberry Pi. |"
+# echo " +------------------------------------------------------------+"
+# echo " | In the unlikely event that you think it is a Raspberry Pi, |"
+# echo " | then please accept my apologies and email the contents of |"
+# echo " | /proc/cpuinfo to projects@drogon.net. |"
+# echo " | - Thanks, Gordon |"
+# echo " +------------------------------------------------------------+"
+# echo ""
+# exit 1
+# fi
+
+
echo
echo "WiringPi Library"
cd wiringPi
sudo make uninstall
if [ x$1 = "xstatic" ]; then
- make static
+ make -j5 static
check_make_ok
sudo make install-static
else
- make
+ make -j5
check_make_ok
sudo make install
fi
@@ -67,11 +138,11 @@ fi
cd ../devLib
sudo make uninstall
if [ x$1 = "xstatic" ]; then
- make static
+ make -j5 static
check_make_ok
sudo make install-static
else
- make
+ make -j5
check_make_ok
sudo make install
fi
@@ -80,7 +151,7 @@ fi
echo
echo "GPIO Utility"
cd ../gpio
- make
+ make -j5
check_make_ok
sudo make install
check_make_ok
diff --git a/WiringPi/debian/wiringPi/DEBIAN/control b/WiringPi/debian/wiringPi/DEBIAN/control
new file mode 100644
index 0000000..73ee094
--- /dev/null
+++ b/WiringPi/debian/wiringPi/DEBIAN/control
@@ -0,0 +1,10 @@
+Package: wiringpi
+Version: 2.24
+Section: libraries
+Priority: optional
+Architecture: armhf
+Depends: libc6
+Maintainer: Gordon Henderson
+Description: The wiringPi libraries, headers and gpio command
+ Libraries to allow GPIO access on a Raspberry Pi from C and C++
+ programs as well as from the command-line
diff --git a/WiringPi/debian/wiringPi/DEBIAN/postinst b/WiringPi/debian/wiringPi/DEBIAN/postinst
new file mode 100755
index 0000000..4997e98
--- /dev/null
+++ b/WiringPi/debian/wiringPi/DEBIAN/postinst
@@ -0,0 +1,5 @@
+#!/bin/sh
+set -e
+/bin/chown root.root /usr/bin/gpio
+/bin/chmod 4755 /usr/bin/gpio
+/sbin/ldconfig
diff --git a/WiringPi/debian/wiringPi/DEBIAN/postrm b/WiringPi/debian/wiringPi/DEBIAN/postrm
new file mode 100755
index 0000000..4be8c58
--- /dev/null
+++ b/WiringPi/debian/wiringPi/DEBIAN/postrm
@@ -0,0 +1,2 @@
+#!/bin/sh
+/sbin/ldconfig
diff --git a/WiringPi/devLib/Makefile b/WiringPi/devLib/Makefile
index a3c0d42..d62b532 100644
--- a/WiringPi/devLib/Makefile
+++ b/WiringPi/devLib/Makefile
@@ -1,7 +1,8 @@
+#
# Makefile:
# wiringPi device - Wiring Compatable library for the Raspberry Pi
#
-# Copyright (c) 2012-2013 Gordon Henderson
+# Copyright (c) 2012-2015 Gordon Henderson
#################################################################################
# This file is part of wiringPi:
# https://projects.drogon.net/raspberry-pi/wiringpi/
@@ -20,10 +21,7 @@
# along with wiringPi. If not, see .
#################################################################################
-DYN_VERS_MAJ=2
-DYN_VERS_MIN=0
-
-VERSION=$(DYN_VERS_MAJ).$(DYN_VERS_MIN)
+VERSION=$(shell cat ../VERSION)
DESTDIR=/usr
PREFIX=/local
@@ -34,7 +32,8 @@ DYNAMIC=libwiringPiDev.so.$(VERSION)
DEBUG = -O2
CC = gcc
INCLUDE = -I.
-CFLAGS = $(DEBUG) -Wformat=2 -Wall $(INCLUDE) -Winline -pipe -fPIC
+DEFS = -D_GNU_SOURCE
+CFLAGS = $(DEBUG) $(DEFS) -Wformat=2 -Wall -Winline $(INCLUDE) -pipe -fPIC
LIBS =
@@ -47,6 +46,8 @@ SRC = ds1302.c maxdetect.c piNes.c \
OBJ = $(SRC:.c=.o)
+HEADERS = ds1302.h gertboard.h lcd128x64.h lcd.h maxdetect.h piFace.h piGlow.h piNes.h
+
all: $(DYNAMIC)
static: $(STATIC)
@@ -65,60 +66,56 @@ $(DYNAMIC): $(OBJ)
@echo [Compile] $<
@$(CC) -c $(CFLAGS) $< -o $@
-.PHONEY: clean
+.PHONY: clean
clean:
@echo "[Clean]"
@rm -f $(OBJ) $(OBJ_I2C) *~ core tags Makefile.bak libwiringPiDev.*
-.PHONEY: tags
+.PHONY: tags
tags: $(SRC)
@echo [ctags]
@ctags $(SRC)
-.PHONEY: install-headers
-install-headers:
+.PHONY: install
+install: $(DYNAMIC)
@echo "[Install Headers]"
- @install -m 0755 -d $(DESTDIR)$(PREFIX)/include
- @install -m 0644 ds1302.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 maxdetect.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 piNes.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 gertboard.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 piFace.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 lcd128x64.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 lcd.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 piGlow.h $(DESTDIR)$(PREFIX)/include
-
-.PHONEY: install
-install: $(DYNAMIC) install-headers
+ @install -m 0755 -d $(DESTDIR)$(PREFIX)/include
+ @install -m 0644 $(HEADERS) $(DESTDIR)$(PREFIX)/include
@echo "[Install Dynamic Lib]"
@install -m 0755 -d $(DESTDIR)$(PREFIX)/lib
@install -m 0755 libwiringPiDev.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib/libwiringPiDev.so.$(VERSION)
@ln -sf $(DESTDIR)$(PREFIX)/lib/libwiringPiDev.so.$(VERSION) $(DESTDIR)/lib/libwiringPiDev.so
@ldconfig
-.PHONEY: install-static
-install-static: $(STATIC) install-headers
+.PHONY: install-static
+install-static: $(STATIC)
+ @echo "[Install Headers]"
+ @install -m 0755 -d $(DESTDIR)$(PREFIX)/include
+ @install -m 0644 $(HEADERS) $(DESTDIR)$(PREFIX)/include
@echo "[Install Static Lib]"
- @install -m 0755 -d $(DESTDIR)$(PREFIX)/lib
- @install -m 0755 libwiringPiDev.a $(DESTDIR)$(PREFIX)/lib
-
-.PHONEY: uninstall
+ @install -m 0755 -d $(DESTDIR)$(PREFIX)/lib
+ @install -m 0755 libwiringPiDev.a $(DESTDIR)$(PREFIX)/lib
+
+.PHONY: install-deb
+install-deb: $(DYNAMIC)
+ @echo "[Install Headers: deb]"
+ @install -m 0755 -d ~/wiringPi/debian/wiringPi/usr/include
+ @install -m 0644 $(HEADERS) ~/wiringPi/debian/wiringPi/usr/include
+ @echo "[Install Dynamic Lib: deb]"
+ install -m 0755 -d ~/wiringPi/debian/wiringPi/usr/lib
+ install -m 0755 libwiringPiDev.so.$(VERSION) ~/wiringPi/debian/wiringPi/usr/lib/libwiringPiDev.so.$(VERSION)
+ ln -sf ~/wiringPi/debian/wiringPi/usr/lib/libwiringPi.so.$(VERSION) ~/wiringPi/debian/wiringPi/usr/lib/libwiringPiDev.so
+
+.PHONY: uninstall
uninstall:
@echo "[UnInstall]"
- @rm -f $(DESTDIR)$(PREFIX)/include/ds1302.h
- @rm -f $(DESTDIR)$(PREFIX)/include/maxdetect.h
- @rm -f $(DESTDIR)$(PREFIX)/include/piNes.h
- @rm -f $(DESTDIR)$(PREFIX)/include/gertboard.h
- @rm -f $(DESTDIR)$(PREFIX)/include/piFace.h
- @rm -f $(DESTDIR)$(PREFIX)/include/lcd128x64.h
- @rm -f $(DESTDIR)$(PREFIX)/include/lcd.h
- @rm -f $(DESTDIR)$(PREFIX)/include/piGlow.h
- @rm -f $(DESTDIR)$(PREFIX)/lib/libwiringPiDev.*
+ @cd $(DESTDIR)$(PREFIX)/include/ && rm -f $(HEADERS)
+ @cd $(DESTDIR)$(PREFIX)/lib/ && rm -f libwiringPiDev.*
@ldconfig
-.PHONEY: depend
+.PHONY: depend
depend:
makedepend -Y $(SRC)
diff --git a/WiringPi/devLib/piGlow.h b/WiringPi/devLib/piGlow.h
index d501c2c..a4d89d0 100644
--- a/WiringPi/devLib/piGlow.h
+++ b/WiringPi/devLib/piGlow.h
@@ -24,8 +24,8 @@
#define PIGLOW_RED 0
-#define PIGLOW_YELLOW 1
-#define PIGLOW_ORANGE 2
+#define PIGLOW_ORANGE 1
+#define PIGLOW_YELLOW 2
#define PIGLOW_GREEN 3
#define PIGLOW_BLUE 4
#define PIGLOW_WHITE 5
diff --git a/WiringPi/examples/Makefile b/WiringPi/examples/Makefile
index 571e341..c9967dc 100644
--- a/WiringPi/examples/Makefile
+++ b/WiringPi/examples/Makefile
@@ -43,6 +43,7 @@ SRC = blink.c blink8.c blink12.c \
nes.c \
softPwm.c softTone.c \
delayTest.c serialRead.c serialTest.c okLed.c ds1302.c \
+ lowPower.c \
rht03.c piglow.c
OBJ = $(SRC:.c=.o)
diff --git a/WiringPi/examples/lowPower.c b/WiringPi/examples/lowPower.c
new file mode 100644
index 0000000..e901e7f
--- /dev/null
+++ b/WiringPi/examples/lowPower.c
@@ -0,0 +1,68 @@
+/*
+ * lowPower.c:
+ * Check the Pi's LOW-Power signal.
+ *
+ * This is a demonstration program that could be turned into some sort
+ * of logger via e.g. syslog - however it's also probably something
+ * that might be better handled by a future kernel - who knows.
+ *
+ * Copyright (c) 2014 Gordon Henderson.
+ ***********************************************************************
+ * This file is part of wiringPi:
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
+ *
+ * wiringPi is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * wiringPi is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with wiringPi. If not, see .
+ ***********************************************************************
+ */
+
+#include
+#include
+#include
+
+
+#define LOW_POWER 35
+
+/*
+ * lowPower:
+ * This is an ISR that waits for the low-power signal going low and
+ * prints the result.
+ *********************************************************************************
+ */
+
+void lowPower (void)
+{
+ time_t t ;
+
+ time (&t) ;
+ printf ("%s: LOW POWER DETECTED\n", ctime (&t)) ;
+}
+
+
+/*
+ *********************************************************************************
+ * main
+ *********************************************************************************
+ */
+
+int main (void)
+{
+ wiringPiSetupGpio () ; // GPIO mode as it's an internal pin
+
+ wiringPiISR (LOW_POWER, INT_EDGE_FALLING, &lowPower) ;
+
+ for (;;)
+ delay (1000) ;
+
+ return 0 ;
+}
diff --git a/WiringPi/examples/spiSpeed.c b/WiringPi/examples/spiSpeed.c
new file mode 100644
index 0000000..0208f0a
--- /dev/null
+++ b/WiringPi/examples/spiSpeed.c
@@ -0,0 +1,118 @@
+/*
+ * spiSpeed.c:
+ * Code to measure the SPI speed/latency.
+ * Copyright (c) 2014 Gordon Henderson
+ ***********************************************************************
+ * This file is part of wiringPi:
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
+ *
+ * wiringPi is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * wiringPi is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with wiringPi.
+ * If not, see .
+ ***********************************************************************
+ */
+
+
+#include
+#include
+#include
+#include
+#include
+#include
+//#include
+//#include
+//#include
+
+#include
+#include
+
+#define TRUE (1==1)
+#define FALSE (!TRUE)
+
+#define SPI_CHAN 0
+#define NUM_TIMES 100
+#define MAX_SIZE (1024*1024)
+
+static int myFd ;
+
+
+void spiSetup (int speed)
+{
+ if ((myFd = wiringPiSPISetup (SPI_CHAN, speed)) < 0)
+ {
+ fprintf (stderr, "Can't open the SPI bus: %s\n", strerror (errno)) ;
+ exit (EXIT_FAILURE) ;
+ }
+}
+
+
+int main (void)
+{
+ int speed, times, size ;
+ unsigned int start, end ;
+ int spiFail ;
+ unsigned char *myData ;
+ double timePerTransaction, perfectTimePerTransaction, dataSpeed ;
+
+ if ((myData = malloc (MAX_SIZE)) == NULL)
+ {
+ fprintf (stderr, "Unable to allocate buffer: %s\n", strerror (errno)) ;
+ exit (EXIT_FAILURE) ;
+ }
+
+ wiringPiSetup () ;
+
+ for (speed = 1 ; speed <= 32 ; speed *= 2)
+ {
+ printf ("+-------+--------+----------+----------+-----------+------------+\n") ;
+ printf ("| MHz | Size | mS/Trans | TpS | Mb/Sec | Latency mS |\n") ;
+ printf ("+-------+--------+----------+----------+-----------+------------+\n") ;
+
+ spiFail = FALSE ;
+ spiSetup (speed * 1000000) ;
+ for (size = 1 ; size <= MAX_SIZE ; size *= 2)
+ {
+ printf ("| %5d | %6d ", speed, size) ;
+
+ start = millis () ;
+ for (times = 0 ; times < NUM_TIMES ; ++times)
+ if (wiringPiSPIDataRW (SPI_CHAN, myData, size) == -1)
+ {
+ printf ("SPI failure: %s\n", strerror (errno)) ;
+ spiFail = TRUE ;
+ break ;
+ }
+ end = millis () ;
+
+ if (spiFail)
+ break ;
+
+ timePerTransaction = ((double)(end - start) / (double)NUM_TIMES) / 1000.0 ;
+ dataSpeed = (double)(size * 8) / (1024.0 * 1024.0) / timePerTransaction ;
+ perfectTimePerTransaction = ((double)(size * 8)) / ((double)(speed * 1000000)) ;
+
+ printf ("| %8.3f ", timePerTransaction * 1000.0) ;
+ printf ("| %8.1f ", 1.0 / timePerTransaction) ;
+ printf ("| %9.5f ", dataSpeed) ;
+ printf ("| %8.5f ", (timePerTransaction - perfectTimePerTransaction) * 1000.0) ;
+ printf ("|\n") ;
+
+ }
+
+ close (myFd) ;
+ printf ("+-------+--------+----------+----------+-----------+------------+\n") ;
+ printf ("\n") ;
+ }
+
+ return 0 ;
+}
diff --git a/WiringPi/gpio/Makefile b/WiringPi/gpio/Makefile
index 37b4887..449986e 100644
--- a/WiringPi/gpio/Makefile
+++ b/WiringPi/gpio/Makefile
@@ -4,7 +4,7 @@
# A swiss-army knige of GPIO shenanigans.
# https://projects.drogon.net/wiring-pi
#
-# Copyright (c) 2012-2013 Gordon Henderson
+# Copyright (c) 2012-2015 Gordon Henderson
#################################################################################
# This file is part of wiringPi:
# Wiring Compatable library for the Raspberry Pi
@@ -38,12 +38,15 @@ LIBS = -lwiringPi -lwiringPiDev -lpthread -lm
# May not need to alter anything below this line
###############################################################################
-SRC = gpio.c extensions.c readall.c pins.c
+SRC = gpio.c readall.c pins.c
OBJ = $(SRC:.c=.o)
all: gpio
+version.h: ../VERSION
+ ./newVersion
+
gpio: $(OBJ)
@echo [Link]
@$(CC) -o $@ $(OBJ) $(LDFLAGS) $(LIBS)
@@ -63,7 +66,7 @@ tags: $(SRC)
@ctags $(SRC)
.PHONY: install
-install:
+install: gpio
@echo "[Install]"
@cp gpio $(DESTDIR)$(PREFIX)/bin
@chown root.root $(DESTDIR)$(PREFIX)/bin/gpio
@@ -71,6 +74,12 @@ install:
@mkdir -p $(DESTDIR)$(PREFIX)/man/man1
@cp gpio.1 $(DESTDIR)$(PREFIX)/man/man1
+.PHONY: install-deb
+install-deb: gpio
+ @echo "[Install: deb]"
+ @install -m 0755 -d ~/wiringPi/debian/wiringPi/usr/bin
+ @install -m 0755 gpio ~/wiringPi/debian/wiringPi/usr/bin
+
.PHONY: uninstall
uninstall:
@echo "[UnInstall]"
@@ -82,6 +91,3 @@ depend:
makedepend -Y $(SRC)
# DO NOT DELETE
-
-gpio.o: extensions.h
-extensions.o: extensions.h
diff --git a/WiringPi/gpio/gpio.1 b/WiringPi/gpio/gpio.1
index e7131c1..77b41bf 100644
--- a/WiringPi/gpio/gpio.1
+++ b/WiringPi/gpio/gpio.1
@@ -1,4 +1,4 @@
-.TH "GPIO" "March 2013" "Command-Line access to Raspberry Pi's GPIO"
+.TH "GPIO" "January 2015" "Command-Line access to Raspberry Pi's GPIO"
.SH NAME
gpio \- Command-line access to Raspberry Pi's GPIO
@@ -21,7 +21,7 @@ gpio \- Command-line access to Raspberry Pi's GPIO
.B ...
.PP
.B gpio
-.B readall/reset
+.B readall
.PP
.B gpio
.B unexportall/exports
@@ -156,16 +156,6 @@ The readall command is usable with an extension module (via the -x parameter),
but it's unable to determine pin modes or states, so will perform both a
digital and analog read on each pin in-turn.
-.TP
-.B reset
-Resets the GPIO - As much as it's possible to do. All pins are set to
-input mode and all the internal pull-up/down resistors are disconnected
-(tristate mode).
-
-The reset command is usable with an extension module (via the -x parameter),
-but it's limited to turning the pin into input mode (if applicable) and
-removing any pull up/down resistor.
-
.TP
.B pwm
Write a PWM value (0-1023) to the given pin. The pin needs to be put
@@ -182,6 +172,8 @@ Set a pin into \fIinput\fR, \fIoutput\fR or \fIpwm\fR mode. Can also
use the literals \fIup\fR, \fIdown\fR or \fItri\fR to set the internal
pull-up, pull-down or tristate (off) controls.
+The ALT modes can also be set using \fIalt0\fR, \fIalt1\fR, ... \fIalt5\fR.
+
.TP
.B unexportall
Un-Export all the GPIO pins in the /sys/class/gpio directory.
@@ -193,9 +185,11 @@ Print a list (if any) of all the exported GPIO pins and their current values.
.TP
.B export
Export a GPIO pin in the \fI/sys/class/gpio\fR directory. Use like the
-mode command above however only \fIin\fR and \fIout\fR are supported at
-this time. Note that the pin number is the \fBBCM_GPIO\fR number and
-not the wiringPi number.
+mode command above however only \fIin\fR, \fIout\fR, \fIhigh\fR and
+\fRlow\fR are supported at this time. Note that the pin number is the
+\fBBCM_GPIO\fR number and not the wiringPi number. The \fIhigh\fR and
+\fIlow\fR commands pre-set the output value at the same time as the
+export to output mode.
Once a GPIO pin has been exported, the \fBgpio\fR program changes the
ownership of the \fI/sys/class/gpio/gpioX/value\fR and if present in
@@ -257,12 +251,30 @@ on the associated /dev/ entries so that the current user has access to
them. Optionally it will set the I2C baudrate to that supplied in Kb/sec
(or as close as the Pi can manage) The default speed is 100Kb/sec.
+Note that on a Pi with a recent 3.18 kernel with the device-tree structure
+enable, the load may fail until you add:
+
+.I dtparam=i2c=on
+
+into \fB/boot/config.txt\fR to allow user use of the I2C bus.
+
.TP
-.B load spi [buffer size in KB]
+.B load spi
This loads the spi drivers into the kernel and changes the permissions
on the associated /dev/ entries so that the current user has access to
-them. Optionally it will set the SPI buffer size to that supplied. The
-default is 4KB.
+them. It used to have the ability to change the buffer size from the
+default of 4096 bytes to an arbitary value, however for some time the
+Pi Foundation have compiled the SPI device driver into the kernel and
+this has fixed the buffer size. The way to change it now is to edit
+the /boot/cmdline.txt file and add on spdev.bufsiz=8192 to set it to
+e.g. 8192 bytes then reboot.
+
+Note that on a Pi with a recent 3.18 kernel with the device-tree structure
+enable, the load may fail until you add:
+
+.I dtparam=spi=on
+
+into \fB/boot/config.txt\fR to allow user use of the I2C bus.
.TP
.B gbr
@@ -280,41 +292,12 @@ SPI digital to analogue converter.
The board jumpers need to be in-place to do this operation.
-.SH "WiringPi vs. BCM_GPIO Pin numbering"
+.SH "WiringPi vs. BCM_GPIO Pin numbering vs. Physical pin numbering"
.PP
-.TS
-c c c c l.
-WiringPi GPIO-r1 GPIO-r2 P1-Phys Function
-_
- 0 17 17 11
- 1 18 18 12 (PWM)
- 2 21 27 13
- 3 22 22 15
- 4 23 23 16
- 5 24 24 18
- 6 25 25 22
- 7 4 4 7
- 8 0 2 3 I2C: SDA0
- 9 1 3 5 I2C: SCL0
-10 8 8 24 SPI: CE0
-11 7 7 26 SPI: CE1
-12 10 10 19 SPI: MOSI
-13 9 9 21 SPI: MISO
-14 11 11 23 SPI: SCLK
-15 14 14 8 TxD
-16 15 16 10 RxD
-17 - 28
-18 - 29
-19 - 30
-20 - 31
-.TE
-
-Note that "r1" and "r2" above refers to the board revision. Normally
-wiringPi detects the correct board revision with use for it's own
-numbering scheme, but if you are using a Revision 2 board with some
-of the pins which change numbers between revisions you will need
-to alter your software.
+The quickest way to get a list of the pin differences is to run the command
+.TP
+gpio readall
.SH FILES
@@ -361,7 +344,7 @@ Please report bugs to
.SH COPYRIGHT
-Copyright (c) 2012-2013 Gordon Henderson
+Copyright (c) 2012-2015 Gordon Henderson
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
diff --git a/WiringPi/gpio/gpio.c b/WiringPi/gpio/gpio.c
index c440874..6dc6113 100644
--- a/WiringPi/gpio/gpio.c
+++ b/WiringPi/gpio/gpio.c
@@ -2,7 +2,7 @@
* gpio.c:
* Swiss-Army-Knife, Set-UID command-line interface to the Raspberry
* Pi's GPIO.
- * Copyright (c) 2012-2013 Gordon Henderson
+ * Copyright (c) 2012-2015 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
@@ -35,11 +35,12 @@
#include
#include
+#include
#include
#include
-#include "extensions.h"
+#include "version.h"
extern int wiringPiDebug ;
@@ -53,7 +54,6 @@ extern void doPins (void) ;
# define FALSE (1==2)
#endif
-#define VERSION "2.20"
#define PI_USB_POWER_CONTROL 38
#define I2CDETECT "/usr/sbin/i2cdetect"
@@ -73,6 +73,7 @@ char *usage = "Usage: gpio -v\n"
" gpio pwmr \n"
" gpio pwmc \n"
" gpio load spi/i2c\n"
+ " gpio unload spi/i2c\n"
" gpio i2cd/i2cdetect\n"
" gpio usbp high/low\n"
" gpio gbr \n"
@@ -115,12 +116,9 @@ static void changeOwner (char *cmd, char *file)
if (chown (file, uid, gid) != 0)
{
if (errno == ENOENT) // Warn that it's not there
- fprintf (stderr, "%s: Warning: File not present: %s\n", cmd, file) ;
+ fprintf (stderr, "%s: Warning (not an error): File not present: %s\n", cmd, file) ;
else
- {
- fprintf (stderr, "%s: Unable to change ownership of %s: %s\n", cmd, file, strerror (errno)) ;
- exit (1) ;
- }
+ fprintf (stderr, "%s: Warning (not an error): Unable to change ownership of %s: %s\n", cmd, file, strerror (errno)) ;
}
}
@@ -167,7 +165,7 @@ static int moduleLoaded (char *modName)
static void _doLoadUsage (char *argv [])
{
- fprintf (stderr, "Usage: %s load [SPI bufferSize in KB | I2C baudrate in Kb/sec]\n", argv [0]) ;
+ fprintf (stderr, "Usage: %s load [I2C baudrate in Kb/sec]\n", argv [0]) ;
exit (1) ;
}
@@ -190,7 +188,10 @@ static void doLoad (int argc, char *argv [])
file1 = "/dev/spidev0.0" ;
file2 = "/dev/spidev0.1" ;
if (argc == 4)
- sprintf (args1, " bufsiz=%d", atoi (argv [3]) * 1024) ;
+ {
+ fprintf (stderr, "%s: Unable to set the buffer size now. Load aborted. Please see the man page.\n", argv [0]) ;
+ exit (1) ;
+ }
else if (argc > 4)
_doLoadUsage (argv) ;
}
@@ -210,13 +211,13 @@ static void doLoad (int argc, char *argv [])
if (!moduleLoaded (module1))
{
- sprintf (cmd, "modprobe %s%s", module1, args1) ;
+ sprintf (cmd, "/sbin/modprobe %s%s", module1, args1) ;
system (cmd) ;
}
if (!moduleLoaded (module2))
{
- sprintf (cmd, "modprobe %s%s", module2, args2) ;
+ sprintf (cmd, "/sbin/modprobe %s%s", module2, args2) ;
system (cmd) ;
}
@@ -233,6 +234,53 @@ static void doLoad (int argc, char *argv [])
}
+/*
+ * doUnLoad:
+ * Un-Load either the spi or i2c modules and change device ownerships, etc.
+ *********************************************************************************
+ */
+
+static void _doUnLoadUsage (char *argv [])
+{
+ fprintf (stderr, "Usage: %s unload \n", argv [0]) ;
+ exit (1) ;
+}
+
+static void doUnLoad (int argc, char *argv [])
+{
+ char *module1, *module2 ;
+ char cmd [80] ;
+
+ if (argc != 3)
+ _doUnLoadUsage (argv) ;
+
+ /**/ if (strcasecmp (argv [2], "spi") == 0)
+ {
+ module1 = "spidev" ;
+ module2 = "spi_bcm2708" ;
+ }
+ else if (strcasecmp (argv [2], "i2c") == 0)
+ {
+ module1 = "i2c_dev" ;
+ module2 = "i2c_bcm2708" ;
+ }
+ else
+ _doUnLoadUsage (argv) ;
+
+ if (moduleLoaded (module1))
+ {
+ sprintf (cmd, "/sbin/rmmod %s", module1) ;
+ system (cmd) ;
+ }
+
+ if (moduleLoaded (module2))
+ {
+ sprintf (cmd, "/sbin/rmmod %s", module2) ;
+ system (cmd) ;
+ }
+}
+
+
/*
* doI2Cdetect:
* Run the i2cdetect command with the right runes for this Pi revision
@@ -386,19 +434,23 @@ void doExport (int argc, char *argv [])
exit (1) ;
}
- /**/ if ((strcasecmp (mode, "in") == 0) || (strcasecmp (mode, "input") == 0))
+ /**/ if ((strcasecmp (mode, "in") == 0) || (strcasecmp (mode, "input") == 0))
fprintf (fd, "in\n") ;
- else if ((strcasecmp (mode, "out") == 0) || (strcasecmp (mode, "output") == 0))
+ else if ((strcasecmp (mode, "out") == 0) || (strcasecmp (mode, "output") == 0))
fprintf (fd, "out\n") ;
+ else if ((strcasecmp (mode, "high") == 0) || (strcasecmp (mode, "up") == 0))
+ fprintf (fd, "high\n") ;
+ else if ((strcasecmp (mode, "low") == 0) || (strcasecmp (mode, "down") == 0))
+ fprintf (fd, "low\n") ;
else
{
- fprintf (stderr, "%s: Invalid mode: %s. Should be in or out\n", argv [1], mode) ;
+ fprintf (stderr, "%s: Invalid mode: %s. Should be in, out, high or low\n", argv [1], mode) ;
exit (1) ;
}
fclose (fd) ;
-// Change ownership so the current user can actually use it!
+// Change ownership so the current user can actually use it
sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ;
changeOwner (argv [0], fName) ;
@@ -586,24 +638,6 @@ void doUnexportall (char *progName)
}
-/*
- * doResetExternal:
- * Load readallExternal, we try to do this with an external device.
- *********************************************************************************
- */
-
-static void doResetExternal (void)
-{
- int pin ;
-
- for (pin = wiringPiNodes->pinBase ; pin <= wiringPiNodes->pinMax ; ++pin)
- {
- pinMode (pin, INPUT) ;
- pullUpDnControl (pin, PUD_OFF) ;
- }
-}
-
-
/*
* doReset:
* Reset the GPIO pins - as much as we can do
@@ -612,24 +646,9 @@ static void doResetExternal (void)
static void doReset (char *progName)
{
- int pin ;
-
- if (wiringPiNodes != NULL) // External reset
- doResetExternal () ;
- else
- {
- doUnexportall (progName) ;
-
- for (pin = 0 ; pin < 64 ; ++pin)
- {
- if (wpiPinToGpio (pin) == -1)
- continue ;
-
- digitalWrite (pin, LOW) ;
- pinMode (pin, INPUT) ;
- pullUpDnControl (pin, PUD_OFF) ;
- }
- }
+ printf ("GPIO Reset is dangerous and has been removed from the gpio command.\n") ;
+ printf (" - Please write a shell-script to reset the GPIO pins into the state\n") ;
+ printf (" that you need them in for your applications.\n") ;
}
@@ -665,9 +684,6 @@ 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) ;
@@ -1162,7 +1178,7 @@ int main (int argc, char *argv [])
if (strcmp (argv [1], "-v") == 0)
{
printf ("gpio version: %s\n", VERSION) ;
- printf ("Copyright (c) 2012-2014 Gordon Henderson\n") ;
+ printf ("Copyright (c) 2012-2015 Gordon Henderson\n") ;
printf ("This is free software with ABSOLUTELY NO WARRANTY.\n") ;
printf ("For details type: %s -warranty\n", argv [0]) ;
printf ("\n") ;
@@ -1185,7 +1201,7 @@ int main (int argc, char *argv [])
if (strcasecmp (argv [1], "-warranty") == 0)
{
printf ("gpio version: %s\n", VERSION) ;
- printf ("Copyright (c) 2012-2014 Gordon Henderson\n") ;
+ printf ("Copyright (c) 2012-2015 Gordon Henderson\n") ;
printf ("\n") ;
printf (" This program is free software; you can redistribute it and/or modify\n") ;
printf (" it under the terms of the GNU Leser General Public License as published\n") ;
@@ -1219,7 +1235,8 @@ int main (int argc, char *argv [])
// Check for load command:
- if (strcasecmp (argv [1], "load" ) == 0) { doLoad (argc, argv) ; return 0 ; }
+ if (strcasecmp (argv [1], "load" ) == 0) { doLoad (argc, argv) ; return 0 ; }
+ if (strcasecmp (argv [1], "unload" ) == 0) { doUnLoad (argc, argv) ; return 0 ; }
// Gertboard commands
@@ -1280,7 +1297,7 @@ int main (int argc, char *argv [])
exit (EXIT_FAILURE) ;
}
- if (!doExtension (argv [0], argv [2])) // Prints its own error messages
+ if (!loadWPiExtension (argv [0], argv [2], TRUE)) // Prints its own error messages
exit (EXIT_FAILURE) ;
for (i = 3 ; i < argc ; ++i)
diff --git a/WiringPi/gpio/newVersion b/WiringPi/gpio/newVersion
new file mode 100755
index 0000000..b8728a5
--- /dev/null
+++ b/WiringPi/gpio/newVersion
@@ -0,0 +1,26 @@
+#!/bin/sh
+#
+# newVersion:
+# Utility to create the version.h include file for the gpio command.
+#
+# Copyright (c) 2012-2015 Gordon Henderson
+#################################################################################
+# This file is part of wiringPi:
+# Wiring Compatable library for the Raspberry Pi
+#
+# wiringPi is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# wiringPi is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with wiringPi. If not, see .
+#################################################################################
+
+rm -f version.h
+echo "#define VERSION \"`cat ../VERSION`\"" > version.h
diff --git a/WiringPi/gpio/pins.c b/WiringPi/gpio/pins.c
index 19fcc1a..d889a45 100644
--- a/WiringPi/gpio/pins.c
+++ b/WiringPi/gpio/pins.c
@@ -1,7 +1,7 @@
/*
* pins.c:
* Just display a handy Pi pinnout diagram.
- * Copyright (c) 2012-2013 Gordon Henderson
+ * Copyright (c) 2012-2015 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
diff --git a/WiringPi/gpio/pintest b/WiringPi/gpio/pintest
index 83ca12a..4da3d94 100755
--- a/WiringPi/gpio/pintest
+++ b/WiringPi/gpio/pintest
@@ -2,7 +2,7 @@
#
# pintest
# Test the Pi's GPIO port
-# Copyright (c) 2013 Gordon Henderson
+# Copyright (c) 2013-2015 Gordon Henderson
#################################################################################
# This file is part of wiringPi:
# Wiring Compatable library for the Raspberry Pi
@@ -104,13 +104,11 @@ testPins()
intro()
{
- revision=`gpio -V`
cat <.
#################################################################################
-DYN_VERS_MAJ=2
-DYN_VERS_MIN=0
-
-VERSION=$(DYN_VERS_MAJ).$(DYN_VERS_MIN)
+VERSION=$(shell cat ../VERSION)
DESTDIR=/usr
PREFIX=/local
@@ -40,7 +37,6 @@ CFLAGS = $(DEBUG) $(DEFS) -Wformat=2 -Wall -Winline $(INCLUDE) -pipe -fPIC
LIBS =
-# Should not alter anything below this line
###############################################################################
SRC = wiringPi.c \
@@ -55,7 +51,23 @@ SRC = wiringPi.c \
mcp3002.c mcp3004.c mcp4802.c mcp3422.c \
max31855.c max5322.c \
sn3218.c \
- drcSerial.c
+ drcSerial.c \
+ wpiExtensions.c
+
+HEADERS = wiringPi.h \
+ wiringSerial.h wiringShift.h \
+ wiringPiSPI.h wiringPiI2C.h \
+ softPwm.h softTone.h \
+ mcp23008.h mcp23016.h mcp23017.h \
+ mcp23s08.h mcp23s17.h \
+ sr595.h \
+ pcf8574.h pcf8591.h \
+ mcp3002.h mcp3004.h mcp4802.h mcp3422.h \
+ max31855.h max5322.h \
+ sn3218.h \
+ drcSerial.h \
+ wpiExtensions.h
+
OBJ = $(SRC:.c=.o)
@@ -77,90 +89,57 @@ $(DYNAMIC): $(OBJ)
@echo [Compile] $<
@$(CC) -c $(CFLAGS) $< -o $@
-.PHONEY: clean
+
+.PHONY: clean
clean:
@echo "[Clean]"
@rm -f $(OBJ) $(OBJ_I2C) *~ core tags Makefile.bak libwiringPi.*
-.PHONEY: tags
+.PHONY: tags
tags: $(SRC)
@echo [ctags]
@ctags $(SRC)
-.PHONEY: install-headers
-install-headers:
+.PHONY: install
+install: $(DYNAMIC)
@echo "[Install Headers]"
- @install -m 0755 -d $(DESTDIR)$(PREFIX)/include
- @install -m 0644 wiringPi.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 wiringSerial.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 wiringShift.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 softPwm.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 softTone.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 wiringPiSPI.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 wiringPiI2C.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 drcSerial.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 mcp23008.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 mcp23016.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 mcp23017.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 mcp23s08.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 mcp23s17.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 max31855.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 max5322.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 mcp3002.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 mcp3004.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 mcp4802.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 mcp3422.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 sr595.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 pcf8574.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 pcf8591.h $(DESTDIR)$(PREFIX)/include
- @install -m 0644 sn3218.h $(DESTDIR)$(PREFIX)/include
-
-.PHONEY: install
-install: $(DYNAMIC) install-headers
+ @install -m 0755 -d $(DESTDIR)$(PREFIX)/include
+ @install -m 0644 $(HEADERS) $(DESTDIR)$(PREFIX)/include
@echo "[Install Dynamic Lib]"
@install -m 0755 -d $(DESTDIR)$(PREFIX)/lib
@install -m 0755 libwiringPi.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib/libwiringPi.so.$(VERSION)
@ln -sf $(DESTDIR)$(PREFIX)/lib/libwiringPi.so.$(VERSION) $(DESTDIR)/lib/libwiringPi.so
@ldconfig
-.PHONEY: install-static
-install-static: $(STATIC) install-headers
+.PHONY: install-static
+install-static: $(STATIC)
+ @echo "[Install Headers]"
+ @install -m 0755 -d $(DESTDIR)$(PREFIX)/include
+ @install -m 0644 $(HEADERS) $(DESTDIR)$(PREFIX)/include
@echo "[Install Static Lib]"
- @install -m 0755 -d $(DESTDIR)$(PREFIX)/lib
- @install -m 0755 libwiringPi.a $(DESTDIR)$(PREFIX)/lib
-
-.PHONEY: uninstall
+ @install -m 0755 -d $(DESTDIR)$(PREFIX)/lib
+ @install -m 0755 libwiringPi.a $(DESTDIR)$(PREFIX)/lib
+
+.PHONY: install-deb
+install-deb: $(DYNAMIC)
+ @echo "[Install Headers: deb]"
+ @install -m 0755 -d ~/wiringPi/debian/wiringPi/usr/include
+ @install -m 0644 $(HEADERS) ~/wiringPi/debian/wiringPi/usr/include
+ @echo "[Install Dynamic Lib: deb]"
+ install -m 0755 -d ~/wiringPi/debian/wiringPi/usr/lib
+ install -m 0755 libwiringPi.so.$(VERSION) ~/wiringPi/debian/wiringPi/usr/lib/libwiringPi.so.$(VERSION)
+ ln -sf ~/wiringPi/debian/wiringPi/usr/lib/libwiringPi.so.$(VERSION) ~/wiringPi/debian/wiringPi/usr/lib/libwiringPi.so
+
+.PHONY: uninstall
uninstall:
@echo "[UnInstall]"
- @rm -f $(DESTDIR)$(PREFIX)/include/wiringPi.h
- @rm -f $(DESTDIR)$(PREFIX)/include/wiringSerial.h
- @rm -f $(DESTDIR)$(PREFIX)/include/wiringShift.h
- @rm -f $(DESTDIR)$(PREFIX)/include/softPwm.h
- @rm -f $(DESTDIR)$(PREFIX)/include/softTone.h
- @rm -f $(DESTDIR)$(PREFIX)/include/wiringPiSPI.h
- @rm -f $(DESTDIR)$(PREFIX)/include/wiringPiI2C.h
- @rm -f $(DESTDIR)$(PREFIX)/include/drcSerial.h
- @rm -f $(DESTDIR)$(PREFIX)/include/mcp23008.h
- @rm -f $(DESTDIR)$(PREFIX)/include/mcp23016.h
- @rm -f $(DESTDIR)$(PREFIX)/include/mcp23017.h
- @rm -f $(DESTDIR)$(PREFIX)/include/mcp23s08.h
- @rm -f $(DESTDIR)$(PREFIX)/include/mcp23s17.h
- @rm -f $(DESTDIR)$(PREFIX)/include/max31855.h
- @rm -f $(DESTDIR)$(PREFIX)/include/max5322.h
- @rm -f $(DESTDIR)$(PREFIX)/include/mcp3002.h
- @rm -f $(DESTDIR)$(PREFIX)/include/mcp3004.h
- @rm -f $(DESTDIR)$(PREFIX)/include/mcp4802.h
- @rm -f $(DESTDIR)$(PREFIX)/include/mcp3422.h
- @rm -f $(DESTDIR)$(PREFIX)/include/sr595.h
- @rm -f $(DESTDIR)$(PREFIX)/include/pcf8574.h
- @rm -f $(DESTDIR)$(PREFIX)/include/pcf8591.h
- @rm -f $(DESTDIR)$(PREFIX)/include/sn3218.h
- @rm -f $(DESTDIR)$(PREFIX)/lib/libwiringPi.*
+ @cd $(DESTDIR)$(PREFIX)/include/ && rm -f $(HEADERS)
+ @cd $(DESTDIR)$(PREFIX)/lib/ && rm -f libwiringPi.*
@ldconfig
-.PHONEY: depend
+.PHONY: depend
depend:
makedepend -Y $(SRC) $(SRC_I2C)
@@ -191,3 +170,7 @@ max31855.o: wiringPi.h wiringPiSPI.h max31855.h
max5322.o: wiringPi.h wiringPiSPI.h max5322.h
sn3218.o: wiringPi.h wiringPiI2C.h sn3218.h
drcSerial.o: wiringPi.h wiringSerial.h drcSerial.h
+wpiExtensions.o: wiringPi.h mcp23008.h mcp23016.h mcp23017.h mcp23s08.h
+wpiExtensions.o: mcp23s17.h sr595.h pcf8574.h pcf8591.h mcp3002.h mcp3004.h
+wpiExtensions.o: mcp4802.h mcp3422.h max31855.h max5322.h sn3218.h
+wpiExtensions.o: drcSerial.h wpiExtensions.h
diff --git a/WiringPi/wiringPi/softPwm.c b/WiringPi/wiringPi/softPwm.c
index 3c79ba7..98b408f 100644
--- a/WiringPi/wiringPi/softPwm.c
+++ b/WiringPi/wiringPi/softPwm.c
@@ -51,11 +51,10 @@
#define PULSE_TIME 100
-static int marks [MAX_PINS] ;
-static int range [MAX_PINS] ;
-static pthread_t threads [MAX_PINS] ;
-
-int newPin = -1 ;
+static volatile int marks [MAX_PINS] ;
+static volatile int range [MAX_PINS] ;
+static volatile pthread_t threads [MAX_PINS] ;
+static volatile int newPin = -1 ;
/*
diff --git a/WiringPi/wiringPi/wiringPi.c b/WiringPi/wiringPi/wiringPi.c
index e7ae386..be636a0 100644
--- a/WiringPi/wiringPi/wiringPi.c
+++ b/WiringPi/wiringPi/wiringPi.c
@@ -1,7 +1,7 @@
/*
* wiringPi:
- * Arduino compatable (ish) Wiring library for the Raspberry Pi
- * Copyright (c) 2012 Gordon Henderson
+ * Arduino look-a-like Wiring library for the Raspberry Pi
+ * Copyright (c) 2012-2015 Gordon Henderson
* Additional code for pwmSetClock by Chris Hall
*
* Thanks to code samples from Gert Jan van Loo and the
@@ -131,7 +131,7 @@ struct wiringPiNodeStruct *wiringPiNodes = NULL ;
// Taken from Gert/Doms code. Some of this is not in the manual
// that I can find )-:
-#define BCM2708_PERI_BASE 0x20000000
+static volatile unsigned int BCM2708_PERI_BASE = 0x20000000 ; // Variable for Pi2
#define GPIO_PADS (BCM2708_PERI_BASE + 0x00100000)
#define CLOCK_BASE (BCM2708_PERI_BASE + 0x00101000)
#define GPIO_BASE (BCM2708_PERI_BASE + 0x00200000)
@@ -203,13 +203,17 @@ static volatile uint32_t *timerIrqRaw ;
// and PI_VERSION_X defines in wiringPi.h
// Only intended for the gpio command - use at your own risk!
-const char *piModelNames [5] =
+static int piModel2 = FALSE ;
+
+const char *piModelNames [7] =
{
"Unknown",
"Model A",
"Model B",
"Model B+",
"Compute Module",
+ "Model A+",
+ "Model 2", // Quad Core
} ;
const char *piRevisionNames [5] =
@@ -221,12 +225,13 @@ const char *piRevisionNames [5] =
"2",
} ;
-const char *piMakerNames [4] =
+const char *piMakerNames [5] =
{
"Unknown",
"Egoman",
"Sony",
"Qusda",
+ "MBest",
} ;
@@ -602,6 +607,7 @@ int wiringPiFailure (int fatal, const char *message, ...)
*
* Revision 1 really means the early Model B's.
* Revision 2 is everything else - it covers the B, B+ and CM.
+ * ... and the Pi 2 - which is a B+ ++ ...
*
* Seems there are some boards with 0000 in them (mistake in manufacture)
* So the distinction between boards that I can see is:
@@ -620,6 +626,10 @@ int wiringPiFailure (int fatal, const char *message, ...)
* 000f - Model B, Rev 2, 512MB, Qisda
* 0010 - Model B+, Rev 1.2, 512MB, Sony
* 0011 - Pi CM, Rev 1.2, 512MB, Sony
+ * 0012 - Model A+ Rev 1.2, 256MB, Sony
+ *
+ * For the Pi 2:
+ * 0010 - Model 2, Rev 1.1, Quad Core, 1GB, Sony
*
* A small thorn is the olde style overvolting - that will add in
* 1000000
@@ -654,6 +664,33 @@ int piBoardRev (void)
if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL)
piBoardRevOops ("Unable to open /proc/cpuinfo") ;
+// Start by looking for the Architecture, then we can look for a B2 revision....
+
+ while (fgets (line, 120, cpuFd) != NULL)
+ if (strncmp (line, "Hardware", 8) == 0)
+ break ;
+
+ if (strncmp (line, "Hardware", 8) != 0)
+ piBoardRevOops ("No \"Hardware\" line") ;
+
+ if (wiringPiDebug)
+ printf ("piboardRev: Hardware: %s\n", line) ;
+
+// See if it's BCM2708 or BCM2709
+
+ if (strstr (line, "BCM2709") != NULL)
+ piModel2 = TRUE ;
+ else if (strstr (line, "BCM2708") == NULL)
+ {
+ fprintf (stderr, "Unable to determine hardware version. I see: %s,\n", line) ;
+ fprintf (stderr, " - expecting BCM2708 or BCM2709. Please report this to projects@drogon.net\n") ;
+ exit (EXIT_FAILURE) ;
+ }
+
+// Now do the rest of it as before
+
+ rewind (cpuFd) ;
+
while (fgets (line, 120, cpuFd) != NULL)
if (strncmp (line, "Revision", 8) == 0)
break ;
@@ -687,10 +724,12 @@ int piBoardRev (void)
// If you have overvolted the Pi, then it appears that the revision
// has 100000 added to it!
+// The actual condition for it being set is:
+// (force_turbo || current_limit_override || temp_limit>85) && over_voltage>0
if (wiringPiDebug)
if (strlen (c) != 4)
- printf ("piboardRev: This Pi has/is overvolted!\n") ;
+ printf ("piboardRev: This Pi has/is (force_turbo || current_limit_override || temp_limit>85) && over_voltage>0\n") ;
// Isolate last 4 characters:
@@ -717,6 +756,15 @@ int piBoardRev (void)
* as much details as we can.
* This is undocumented and really only intended for the GPIO command.
* Use at your own risk!
+ *
+ * for Pi v2:
+ * [USER:8] [NEW:1] [MEMSIZE:3] [MANUFACTURER:4] [PROCESSOR:4] [TYPE:8] [REV:4]
+ * NEW 23: will be 1 for the new scheme, 0 for the old scheme
+ * MEMSIZE 20: 0=256M 1=512M 2=1G
+ * MANUFACTURER 16: 0=SONY 1=EGOMAN 2=EMBEST
+ * PROCESSOR 12: 0=2835 1=2836
+ * TYPE 04: 0=MODELA 1=MODELB 2=MODELA+ 3=MODELB+ 4=Pi2 MODEL B 5=ALPHA 6=CM
+ * REV 00: 0=REV0 1=REV1 2=REV2
*********************************************************************************
*/
@@ -726,6 +774,9 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted)
char line [120] ;
char *c ;
+// Will deal with the properly later on - for now, lets just get it going...
+// unsigned int modelNum ;
+
(void)piBoardRev () ; // Call this first to make sure all's OK. Don't care about the result.
if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL)
@@ -748,41 +799,66 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted)
if (wiringPiDebug)
printf ("piboardId: Revision string: %s\n", line) ;
+ if (piModel2)
+ {
+
+// Scan to the colon
+
+ for (c = line ; *c ; ++c)
+ if (*c == ':')
+ break ;
+
+ if (*c != ':')
+ piBoardRevOops ("Bogus \"Revision\" line") ;
+
+// modelNum = (unsigned int)strtol (++c, NULL, 16) ; // Hex number with no leading 0x
+
+ *model = PI_MODEL_2 ;
+ *rev = PI_VERSION_1_1 ;
+ *mem = 1024 ;
+ *maker = PI_MAKER_SONY ;
+ }
+ else
+ {
+
// Scan to first digit
- for (c = line ; *c ; ++c)
- if (isdigit (*c))
- break ;
+ for (c = line ; *c ; ++c)
+ if (isdigit (*c))
+ break ;
// Make sure its long enough
- if (strlen (c) < 4)
- piBoardRevOops ("Bogus \"Revision\" line") ;
+ if (strlen (c) < 4)
+ piBoardRevOops ("Bogus \"Revision\" line") ;
// If longer than 4, we'll assume it's been overvolted
- *overVolted = strlen (c) > 4 ;
+ *overVolted = strlen (c) > 4 ;
// Extract last 4 characters:
- c = c + strlen (c) - 4 ;
+ c = c + strlen (c) - 4 ;
// Fill out the replys as appropriate
- /**/ if (strcmp (c, "0002") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
- else if (strcmp (c, "0003") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_1 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
- else if (strcmp (c, "0004") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; }
- else if (strcmp (c, "0005") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_QISDA ; }
- else if (strcmp (c, "0006") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
- else if (strcmp (c, "0007") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
- else if (strcmp (c, "0008") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; ; }
- else if (strcmp (c, "0009") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_QISDA ; }
- else if (strcmp (c, "000d") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 512 ; *maker = PI_MAKER_EGOMAN ; }
- else if (strcmp (c, "000e") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
- else if (strcmp (c, "000f") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 512 ; *maker = PI_MAKER_EGOMAN ; }
- else if (strcmp (c, "0010") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
- else if (strcmp (c, "0011") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
- else { *model = 0 ; *rev = 0 ; *mem = 0 ; *maker = 0 ; }
+ /**/ if (strcmp (c, "0002") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
+ else if (strcmp (c, "0003") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_1 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
+ else if (strcmp (c, "0004") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; }
+ else if (strcmp (c, "0005") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_QISDA ; }
+ else if (strcmp (c, "0006") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
+ else if (strcmp (c, "0007") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
+ else if (strcmp (c, "0008") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; ; }
+ else if (strcmp (c, "0009") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_QISDA ; }
+ else if (strcmp (c, "000d") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 512 ; *maker = PI_MAKER_EGOMAN ; }
+ else if (strcmp (c, "000e") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
+ else if (strcmp (c, "000f") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 512 ; *maker = PI_MAKER_EGOMAN ; }
+ else if (strcmp (c, "0010") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
+ else if (strcmp (c, "0011") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
+ else if (strcmp (c, "0012") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; }
+ else if (strcmp (c, "0013") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_MBEST ; }
+ else { *model = 0 ; *rev = 0 ; *mem = 0 ; *maker = 0 ; }
+ }
}
@@ -1474,8 +1550,10 @@ int waitForInterrupt (int pin, int mS)
// Do a dummy read to clear the interrupt
// A one character read appars to be enough.
+// Followed by a seek to reset it.
(void)read (fd, &c, 1) ;
+ lseek (fd, 0, SEEK_SET) ;
return x ;
}
@@ -1761,8 +1839,10 @@ int wiringPiSetup (void)
pinToGpio = pinToGpioR1 ;
physToGpio = physToGpioR1 ;
}
- else // A, B, Rev 2, B+, CM
+ else // A, B, Rev 2, B+, CM, Pi2
{
+ if (piModel2)
+ BCM2708_PERI_BASE = 0x3F000000 ;
pinToGpio = pinToGpioR2 ;
physToGpio = physToGpioR2 ;
}
diff --git a/WiringPi/wiringPi/wiringPi.h b/WiringPi/wiringPi/wiringPi.h
index 2bc63ba..dd110fa 100644
--- a/WiringPi/wiringPi/wiringPi.h
+++ b/WiringPi/wiringPi/wiringPi.h
@@ -75,6 +75,8 @@
#define PI_MODEL_B 2
#define PI_MODEL_BP 3
#define PI_MODEL_CM 4
+#define PI_MODEL_AP 5
+#define PI_MODEL_2 6
#define PI_VERSION_UNKNOWN 0
#define PI_VERSION_1 1
@@ -86,10 +88,11 @@
#define PI_MAKER_EGOMAN 1
#define PI_MAKER_SONY 2
#define PI_MAKER_QISDA 3
+#define PI_MAKER_MBEST 4
-extern const char *piModelNames [5] ;
+extern const char *piModelNames [7] ;
extern const char *piRevisionNames [5] ;
-extern const char *piMakerNames [4] ;
+extern const char *piMakerNames [5] ;
// Intended for the GPIO program Use at your own risk.
@@ -147,9 +150,6 @@ extern "C" {
// Data
-//extern const char *piModelNames [] ;
-//extern const char *piRevisionNames[] ;
-
// Internal
extern int wiringPiFailure (int fatal, const char *message, ...) ;
diff --git a/WiringPi/wiringPi/wiringPiSPI.c b/WiringPi/wiringPi/wiringPiSPI.c
index 215a027..453df31 100644
--- a/WiringPi/wiringPi/wiringPiSPI.c
+++ b/WiringPi/wiringPi/wiringPiSPI.c
@@ -1,7 +1,7 @@
/*
* wiringPiSPI.c:
* Simplified SPI access routines
- * Copyright (c) 2012 Gordon Henderson
+ * Copyright (c) 2012-2015 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
@@ -40,7 +40,6 @@
const static char *spiDev0 = "/dev/spidev0.0" ;
const static char *spiDev1 = "/dev/spidev0.1" ;
-const static uint8_t spiMode = 0 ;
const static uint8_t spiBPW = 8 ;
const static uint16_t spiDelay = 0 ;
@@ -75,6 +74,11 @@ int wiringPiSPIDataRW (int channel, unsigned char *data, int len)
channel &= 1 ;
+// Mentioned in spidev.h but not used in the original kernel documentation
+// test program )-:
+
+ memset (&spi, 0, sizeof (spi)) ;
+
spi.tx_buf = (unsigned long)data ;
spi.rx_buf = (unsigned long)data ;
spi.len = len ;
@@ -87,16 +91,17 @@ int wiringPiSPIDataRW (int channel, unsigned char *data, int len)
/*
- * wiringPiSPISetup:
- * Open the SPI device, and set it up, etc.
+ * wiringPiSPISetupMode:
+ * Open the SPI device, and set it up, with the mode, etc.
*********************************************************************************
*/
-int wiringPiSPISetup (int channel, int speed)
+int wiringPiSPISetupMode (int channel, int speed, int mode)
{
int fd ;
- channel &= 1 ;
+ mode &= 3 ; // Mode is 0, 1, 2 or 3
+ channel &= 1 ; // Channel is 0 or 1
if ((fd = open (channel == 0 ? spiDev0 : spiDev1, O_RDWR)) < 0)
return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ;
@@ -105,10 +110,8 @@ int wiringPiSPISetup (int channel, int speed)
spiFds [channel] = fd ;
// Set SPI parameters.
-// Why are we reading it afterwriting it? I've no idea, but for now I'm blindly
-// copying example code I've seen online...
- if (ioctl (fd, SPI_IOC_WR_MODE, &spiMode) < 0)
+ if (ioctl (fd, SPI_IOC_WR_MODE, &mode) < 0)
return wiringPiFailure (WPI_ALMOST, "SPI Mode Change failure: %s\n", strerror (errno)) ;
if (ioctl (fd, SPI_IOC_WR_BITS_PER_WORD, &spiBPW) < 0)
@@ -119,3 +122,15 @@ int wiringPiSPISetup (int channel, int speed)
return fd ;
}
+
+
+/*
+ * wiringPiSPISetup:
+ * Open the SPI device, and set it up, etc. in the default MODE 0
+ *********************************************************************************
+ */
+
+int wiringPiSPISetup (int channel, int speed)
+{
+ return wiringPiSPISetupMode (channel, speed, 0) ;
+}
diff --git a/WiringPi/wiringPi/wiringPiSPI.h b/WiringPi/wiringPi/wiringPiSPI.h
index f53697d..3980321 100644
--- a/WiringPi/wiringPi/wiringPiSPI.h
+++ b/WiringPi/wiringPi/wiringPiSPI.h
@@ -1,7 +1,7 @@
/*
* wiringPiSPI.h:
* Simplified SPI access routines
- * Copyright (c) 2012 Gordon Henderson
+ * Copyright (c) 2012-2015 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
@@ -26,9 +26,10 @@
extern "C" {
#endif
-int wiringPiSPIGetFd (int channel) ;
-int wiringPiSPIDataRW (int channel, unsigned char *data, int len) ;
-int wiringPiSPISetup (int channel, int speed) ;
+int wiringPiSPIGetFd (int channel) ;
+int wiringPiSPIDataRW (int channel, unsigned char *data, int len) ;
+int wiringPiSPISetupMode (int channel, int speed, int mode) ;
+int wiringPiSPISetup (int channel, int speed) ;
#ifdef __cplusplus
}
diff --git a/WiringPi/gpio/extensions.c b/WiringPi/wiringPi/wpiExtensions.c
similarity index 77%
rename from WiringPi/gpio/extensions.c
rename to WiringPi/wiringPi/wpiExtensions.c
index 96d6255..4cae9c4 100644
--- a/WiringPi/gpio/extensions.c
+++ b/WiringPi/wiringPi/wpiExtensions.c
@@ -1,8 +1,10 @@
/*
* extensions.c:
- * Part of the GPIO program to test, peek, poke and otherwise
+ * Originally part of the GPIO program to test, peek, poke and otherwise
* noodle with the GPIO hardware on the Raspberry Pi.
- * Copyright (c) 2012-2013 Gordon Henderson
+ * Now used as a general purpose library to allow systems to dynamically
+ * add in new devices into wiringPi at program run-time.
+ * Copyright (c) 2012-2015 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
@@ -26,6 +28,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -35,27 +38,31 @@
#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "extensions.h"
+#include "mcp23008.h"
+#include "mcp23016.h"
+#include "mcp23017.h"
+#include "mcp23s08.h"
+#include "mcp23s17.h"
+#include "sr595.h"
+#include "pcf8574.h"
+#include "pcf8591.h"
+#include "mcp3002.h"
+#include "mcp3004.h"
+#include "mcp4802.h"
+#include "mcp3422.h"
+#include "max31855.h"
+#include "max5322.h"
+#include "sn3218.h"
+#include "drcSerial.h"
+
+#include "wpiExtensions.h"
extern int wiringPiDebug ;
+static int verbose ;
+static char errorMessage [1024] ;
+
+
#ifndef TRUE
# define TRUE (1==1)
# define FALSE (1==2)
@@ -70,6 +77,24 @@ struct extensionFunctionStruct
} ;
+/*
+ * verbError:
+ * Convenient error handling
+ *********************************************************************************
+ */
+
+static void verbError (const char *message, ...)
+{
+ va_list argp ;
+ va_start (argp, message) ;
+ vsnprintf (errorMessage, 1023, message, argp) ;
+ va_end (argp) ;
+
+ if (verbose)
+ fprintf (stderr, "%s\n", errorMessage) ;
+}
+
+
/*
* extractInt:
* Check & return an integer at the given location (prefixed by a :)
@@ -80,7 +105,7 @@ static char *extractInt (char *progName, char *p, int *num)
{
if (*p != ':')
{
- fprintf (stderr, "%s: colon expected\n", progName) ;
+ verbError ("%s: colon expected", progName) ;
return NULL ;
}
@@ -88,7 +113,7 @@ static char *extractInt (char *progName, char *p, int *num)
if (!isdigit (*p))
{
- fprintf (stderr, "%s: digit expected\n", progName) ;
+ verbError ("%s: digit expected", progName) ;
return NULL ;
}
@@ -112,7 +137,7 @@ static char *extractStr (char *progName, char *p, char **str)
if (*p != ':')
{
- fprintf (stderr, "%s: colon expected\n", progName) ;
+ verbError ("%s: colon expected", progName) ;
return NULL ;
}
@@ -120,7 +145,7 @@ static char *extractStr (char *progName, char *p, char **str)
if (!isprint (*p))
{
- fprintf (stderr, "%s: character expected\n", progName) ;
+ verbError ("%s: character expected", progName) ;
return NULL ;
}
@@ -152,9 +177,9 @@ static int doExtensionMcp23008 (char *progName, int pinBase, char *params)
if ((params = extractInt (progName, params, &i2c)) == NULL)
return FALSE ;
- if ((i2c < 0x03) || (i2c > 0x77))
+ if ((i2c < 0x01) || (i2c > 0x77))
{
- fprintf (stderr, "%s: i2c address (0x%X) out of range\n", progName, i2c) ;
+ verbError ("%s: i2c address (0x%X) out of range", progName, i2c) ;
return FALSE ;
}
@@ -180,7 +205,7 @@ static int doExtensionMcp23016 (char *progName, int pinBase, char *params)
if ((i2c < 0x03) || (i2c > 0x77))
{
- fprintf (stderr, "%s: i2c address (0x%X) out of range\n", progName, i2c) ;
+ verbError ("%s: i2c address (0x%X) out of range", progName, i2c) ;
return FALSE ;
}
@@ -206,7 +231,7 @@ static int doExtensionMcp23017 (char *progName, int pinBase, char *params)
if ((i2c < 0x03) || (i2c > 0x77))
{
- fprintf (stderr, "%s: i2c address (0x%X) out of range\n", progName, i2c) ;
+ verbError ("%s: i2c address (0x%X) out of range", progName, i2c) ;
return FALSE ;
}
@@ -232,7 +257,7 @@ static int doExtensionMcp23s08 (char *progName, int pinBase, char *params)
if ((spi < 0) || (spi > 1))
{
- fprintf (stderr, "%s: SPI address (%d) out of range\n", progName, spi) ;
+ verbError ("%s: SPI address (%d) out of range", progName, spi) ;
return FALSE ;
}
@@ -241,7 +266,7 @@ static int doExtensionMcp23s08 (char *progName, int pinBase, char *params)
if ((port < 0) || (port > 7))
{
- fprintf (stderr, "%s: port address (%d) out of range\n", progName, port) ;
+ verbError ("%s: port address (%d) out of range", progName, port) ;
return FALSE ;
}
@@ -267,7 +292,7 @@ static int doExtensionMcp23s17 (char *progName, int pinBase, char *params)
if ((spi < 0) || (spi > 1))
{
- fprintf (stderr, "%s: SPI address (%d) out of range\n", progName, spi) ;
+ verbError ("%s: SPI address (%d) out of range", progName, spi) ;
return FALSE ;
}
@@ -276,7 +301,7 @@ static int doExtensionMcp23s17 (char *progName, int pinBase, char *params)
if ((port < 0) || (port > 7))
{
- fprintf (stderr, "%s: port address (%d) out of range\n", progName, port) ;
+ verbError ("%s: port address (%d) out of range", progName, port) ;
return FALSE ;
}
@@ -304,7 +329,7 @@ static int doExtensionSr595 (char *progName, int pinBase, char *params)
if ((pins < 8) || (pins > 32))
{
- fprintf (stderr, "%s: pin count (%d) out of range - 8-32 expected.\n", progName, pins) ;
+ verbError ("%s: pin count (%d) out of range - 8-32 expected.", progName, pins) ;
return FALSE ;
}
@@ -339,7 +364,7 @@ static int doExtensionPcf8574 (char *progName, int pinBase, char *params)
if ((i2c < 0x03) || (i2c > 0x77))
{
- fprintf (stderr, "%s: i2c address (0x%X) out of range\n", progName, i2c) ;
+ verbError ("%s: i2c address (0x%X) out of range", progName, i2c) ;
return FALSE ;
}
@@ -365,7 +390,7 @@ static int doExtensionPcf8591 (char *progName, int pinBase, char *params)
if ((i2c < 0x03) || (i2c > 0x77))
{
- fprintf (stderr, "%s: i2c address (0x%X) out of range\n", progName, i2c) ;
+ verbError ("%s: i2c address (0x%X) out of range", progName, i2c) ;
return FALSE ;
}
@@ -391,7 +416,7 @@ static int doExtensionMax31855 (char *progName, int pinBase, char *params)
if ((spi < 0) || (spi > 1))
{
- fprintf (stderr, "%s: SPI channel (%d) out of range\n", progName, spi) ;
+ verbError ("%s: SPI channel (%d) out of range", progName, spi) ;
return FALSE ;
}
@@ -417,7 +442,7 @@ static int doExtensionMcp3002 (char *progName, int pinBase, char *params)
if ((spi < 0) || (spi > 1))
{
- fprintf (stderr, "%s: SPI channel (%d) out of range\n", progName, spi) ;
+ verbError ("%s: SPI channel (%d) out of range", progName, spi) ;
return FALSE ;
}
@@ -443,7 +468,7 @@ static int doExtensionMcp3004 (char *progName, int pinBase, char *params)
if ((spi < 0) || (spi > 1))
{
- fprintf (stderr, "%s: SPI channel (%d) out of range\n", progName, spi) ;
+ verbError ("%s: SPI channel (%d) out of range", progName, spi) ;
return FALSE ;
}
@@ -469,7 +494,7 @@ static int doExtensionMax5322 (char *progName, int pinBase, char *params)
if ((spi < 0) || (spi > 1))
{
- fprintf (stderr, "%s: SPI channel (%d) out of range\n", progName, spi) ;
+ verbError ("%s: SPI channel (%d) out of range", progName, spi) ;
return FALSE ;
}
@@ -495,7 +520,7 @@ static int doExtensionMcp4802 (char *progName, int pinBase, char *params)
if ((spi < 0) || (spi > 1))
{
- fprintf (stderr, "%s: SPI channel (%d) out of range\n", progName, spi) ;
+ verbError ("%s: SPI channel (%d) out of range", progName, spi) ;
return FALSE ;
}
@@ -535,7 +560,7 @@ static int doExtensionMcp3422 (char *progName, int pinBase, char *params)
if ((i2c < 0x03) || (i2c > 0x77))
{
- fprintf (stderr, "%s: i2c address (0x%X) out of range\n", progName, i2c) ;
+ verbError ("%s: i2c address (0x%X) out of range", progName, i2c) ;
return FALSE ;
}
@@ -544,7 +569,7 @@ static int doExtensionMcp3422 (char *progName, int pinBase, char *params)
if ((sampleRate < 0) || (sampleRate > 3))
{
- fprintf (stderr, "%s: sample rate (%d) out of range\n", progName, sampleRate) ;
+ verbError ("%s: sample rate (%d) out of range", progName, sampleRate) ;
return FALSE ;
}
@@ -553,7 +578,7 @@ static int doExtensionMcp3422 (char *progName, int pinBase, char *params)
if ((gain < 0) || (gain > 3))
{
- fprintf (stderr, "%s: gain (%d) out of range\n", progName, gain) ;
+ verbError ("%s: gain (%d) out of range", progName, gain) ;
return FALSE ;
}
@@ -562,6 +587,7 @@ static int doExtensionMcp3422 (char *progName, int pinBase, char *params)
return TRUE ;
}
+
/*
* doExtensionDrcS:
* Interface to a DRC Serial system
@@ -579,7 +605,7 @@ static int doExtensionDrcS (char *progName, int pinBase, char *params)
if ((pins < 1) || (pins > 100))
{
- fprintf (stderr, "%s: pins (%d) out of range (2-100)\n", progName, pins) ;
+ verbError ("%s: pins (%d) out of range (2-100)", progName, pins) ;
return FALSE ;
}
@@ -588,7 +614,7 @@ static int doExtensionDrcS (char *progName, int pinBase, char *params)
if (strlen (port) == 0)
{
- fprintf (stderr, "%s: serial port device name required\n", progName) ;
+ verbError ("%s: serial port device name required", progName) ;
return FALSE ;
}
@@ -597,7 +623,7 @@ static int doExtensionDrcS (char *progName, int pinBase, char *params)
if ((baud < 1) || (baud > 4000000))
{
- fprintf (stderr, "%s: baud rate (%d) out of range\n", progName, baud) ;
+ verbError ("%s: baud rate (%d) out of range", progName, baud) ;
return FALSE ;
}
@@ -613,7 +639,7 @@ static int doExtensionDrcS (char *progName, int pinBase, char *params)
*********************************************************************************
*/
-struct extensionFunctionStruct extensionFunctions [] =
+static struct extensionFunctionStruct extensionFunctions [] =
{
{ "mcp23008", &doExtensionMcp23008 },
{ "mcp23016", &doExtensionMcp23016 },
@@ -636,44 +662,49 @@ struct extensionFunctionStruct extensionFunctions [] =
/*
- * doExtension:
+ * loadWPiExtension:
* Load in a wiringPi extension
+ * The extensionData always starts with the name, a colon then the pinBase
+ * number. Other parameters after that are decoded by the module in question.
*********************************************************************************
*/
-int doExtension (char *progName, char *extensionData)
+int loadWPiExtension (char *progName, char *extensionData, int printErrors)
{
char *p ;
char *extension = extensionData ;
struct extensionFunctionStruct *extensionFn ;
int pinBase = 0 ;
-// Get the extension extension name by finding the first colon
+ verbose = printErrors ;
+
+// Get the extension name by finding the first colon
p = extension ;
while (*p != ':')
{
if (!*p) // ran out of characters
{
- fprintf (stderr, "%s: extension name not terminated by a colon\n", progName) ;
+ verbError ("%s: extension name not terminated by a colon", progName) ;
return FALSE ;
}
++p ;
}
-
*p++ = 0 ;
+// Simple ATOI code
+
if (!isdigit (*p))
{
- fprintf (stderr, "%s: pinBase number expected after extension name\n", progName) ;
+ verbError ("%s: pinBase number expected after extension name", progName) ;
return FALSE ;
}
while (isdigit (*p))
{
- if (pinBase > 1000000000)
+ if (pinBase > 1000000000) // Lets be realistic here...
{
- fprintf (stderr, "%s: pinBase too large\n", progName) ;
+ verbError ("%s: pinBase too large", progName) ;
return FALSE ;
}
@@ -683,7 +714,7 @@ int doExtension (char *progName, char *extensionData)
if (pinBase < 64)
{
- fprintf (stderr, "%s: pinBase (%d) too small. Minimum is 64.\n", progName, pinBase) ;
+ verbError ("%s: pinBase (%d) too small. Minimum is 64.", progName, pinBase) ;
return FALSE ;
}
@@ -695,6 +726,6 @@ int doExtension (char *progName, char *extensionData)
return extensionFn->function (progName, pinBase, p) ;
}
- fprintf (stderr, "%s: extension %s not found\n", progName, extension) ;
+ verbError ("%s: extension %s not found", progName, extension) ;
return FALSE ;
}
diff --git a/WiringPi/gpio/extensions.h b/WiringPi/wiringPi/wpiExtensions.h
similarity index 89%
rename from WiringPi/gpio/extensions.h
rename to WiringPi/wiringPi/wpiExtensions.h
index 5d27123..fcaec96 100644
--- a/WiringPi/gpio/extensions.h
+++ b/WiringPi/wiringPi/wpiExtensions.h
@@ -2,7 +2,7 @@
* extensions.h:
* Part of the GPIO program to test, peek, poke and otherwise
* noodle with the GPIO hardware on the Raspberry Pi.
- * Copyright (c) 2012-2013 Gordon Henderson
+ * Copyright (c) 2012-2015 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
@@ -23,4 +23,4 @@
*/
-extern int doExtension (char *progName, char *extensionData) ;
+extern int loadWPiExtension (char *progName, char *extensionData, int verbose) ;
diff --git a/setup.py b/setup.py
old mode 100644
new mode 100755
index e967647..18e8d52
--- a/setup.py
+++ b/setup.py
@@ -41,8 +41,7 @@ _wiringpi2 = Extension(
'WiringPi/wiringPi/wiringSerial.c',
'WiringPi/wiringPi/wiringShift.c',
'wiringpi_wrap.c'
- ],
- include_dirs=["WiringPi/wiringPi"],
+ ]
)
setup(
diff --git a/wiringpi.i b/wiringpi.i
index 89832b4..92ca76a 100644
--- a/wiringpi.i
+++ b/wiringpi.i
@@ -193,6 +193,16 @@ extern void softToneStop (int pin) ;
extern void softToneWrite (int pin, int freq) ;
// SPI
+
+%typemap(in) (unsigned char *data, int len) {
+ $1 = (unsigned char *) PyString_AsString($input);
+ $2 = PyString_Size($input);
+};
+
+%typemap(argout) (unsigned char *data) {
+ $result = SWIG_Python_AppendOutput($result, PyString_FromStringAndSize((char *) $1, result));
+};
+
int wiringPiSPIGetFd (int channel) ;
int wiringPiSPIDataRW (int channel, unsigned char *data, int len) ;
int wiringPiSPISetup (int channel, int speed) ;