From 95a292824ff9188f013fc230f432acf1a8b1092f Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 9 Sep 2015 23:30:16 +0000 Subject: [PATCH 01/20] Build system: Add missing set -e So that shell scripts do not blunder on after errors. Signed-off-by: Ian Jackson --- build | 2 +- examples/blink.sh | 2 +- examples/q2w/blink.sh | 2 +- gpio/newVersion | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build b/build index d38ad1b..7c05087 100755 --- a/build +++ b/build @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/sh -e # build # Simple wiringPi build and install script diff --git a/examples/blink.sh b/examples/blink.sh index 7755383..3975bb7 100644 --- a/examples/blink.sh +++ b/examples/blink.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/sh -e # # blink.sh: # Standard "blink" program in wiringPi. Blinks an LED connected diff --git a/examples/q2w/blink.sh b/examples/q2w/blink.sh index 2dee6c7..bb6107a 100755 --- a/examples/q2w/blink.sh +++ b/examples/q2w/blink.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/sh -e # # blink.sh: # Standard "blink" program in wiringPi. Blinks an LED connected diff --git a/gpio/newVersion b/gpio/newVersion index b8728a5..b919743 100755 --- a/gpio/newVersion +++ b/gpio/newVersion @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/sh -e # # newVersion: # Utility to create the version.h include file for the gpio command. From 2ab836ecea3ba1f9cfef762cff0669be4d9bcf1c Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 9 Sep 2015 23:31:15 +0000 Subject: [PATCH 02/20] Build system: Add a .gitignore Signed-off-by: Ian Jackson --- .gitignore | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c1855e9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*.o +*.so +lib*.so.* +*~ +debian/wiringPi +debian/wiringpi-*.deb +gpio/gpio From cf6f38107e9d0f656ac8f1d3f99121781a7ed17c Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 9 Sep 2015 23:34:18 +0000 Subject: [PATCH 03/20] Build system: Add a formulaic setting of Q from V for debugging We want to be able to disable the many @'s in the Makefiles so that we can see what they are doing, when things go wrong. It is conventional to arrange for setting V=1 to have this effect. Here we supply a formulaic stanza for either setting Q?=@ or doing nothing. (There is sadly no standard place which is included in all the Makefiles so this is probably best). In this patch we do not introduce any users of Q yet. This is because the next patch, which introduces all the users of Q, can be generated entirely automatically. (This is also convenient in case something needs to be rebased across it.) Signed-off-by: Ian Jackson --- devLib/Makefile | 4 ++++ examples/Gertboard/Makefile | 4 ++++ examples/Makefile | 3 +++ examples/PiFace/Makefile | 3 +++ examples/PiGlow/Makefile | 3 +++ examples/q2w/Makefile | 3 +++ gpio/Makefile | 4 ++++ pins/Makefile | 4 ++++ wiringPi/Makefile | 4 ++++ 9 files changed, 32 insertions(+) diff --git a/devLib/Makefile b/devLib/Makefile index d62b532..21ea512 100644 --- a/devLib/Makefile +++ b/devLib/Makefile @@ -25,6 +25,10 @@ VERSION=$(shell cat ../VERSION) DESTDIR=/usr PREFIX=/local +ifneq ($V,1) +Q ?= @ +endif + STATIC=libwiringPiDev.a DYNAMIC=libwiringPiDev.so.$(VERSION) diff --git a/examples/Gertboard/Makefile b/examples/Gertboard/Makefile index 7569261..7be81ab 100644 --- a/examples/Gertboard/Makefile +++ b/examples/Gertboard/Makefile @@ -5,6 +5,10 @@ # Copyright (c) 2013 Gordon Henderson ################################################################################# +ifneq ($V,1) +Q ?= @ +endif + #DEBUG = -g -O0 DEBUG = -O3 CC = gcc diff --git a/examples/Makefile b/examples/Makefile index c9967dc..7671b08 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -22,6 +22,9 @@ # along with wiringPi. If not, see . ################################################################################# +ifneq ($V,1) +Q ?= @ +endif #DEBUG = -g -O0 DEBUG = -O3 diff --git a/examples/PiFace/Makefile b/examples/PiFace/Makefile index 0bde334..7bab7ce 100644 --- a/examples/PiFace/Makefile +++ b/examples/PiFace/Makefile @@ -22,6 +22,9 @@ # along with wiringPi. If not, see . ################################################################################# +ifneq ($V,1) +Q ?= @ +endif #DEBUG = -g -O0 DEBUG = -O3 diff --git a/examples/PiGlow/Makefile b/examples/PiGlow/Makefile index 8d31141..6d8d5bf 100644 --- a/examples/PiGlow/Makefile +++ b/examples/PiGlow/Makefile @@ -22,6 +22,9 @@ # along with wiringPi. If not, see . ################################################################################# +ifneq ($V,1) +Q ?= @ +endif #DEBUG = -g -O0 DEBUG = -O3 diff --git a/examples/q2w/Makefile b/examples/q2w/Makefile index 150c825..a7bc337 100644 --- a/examples/q2w/Makefile +++ b/examples/q2w/Makefile @@ -22,6 +22,9 @@ # along with wiringPi. If not, see . ################################################################################# +ifneq ($V,1) +Q ?= @ +endif #DEBUG = -g -O0 DEBUG = -O3 diff --git a/gpio/Makefile b/gpio/Makefile index 449986e..df05dbe 100644 --- a/gpio/Makefile +++ b/gpio/Makefile @@ -26,6 +26,10 @@ DESTDIR=/usr PREFIX=/local +ifneq ($V,1) +Q ?= @ +endif + #DEBUG = -g -O0 DEBUG = -O2 CC = gcc diff --git a/pins/Makefile b/pins/Makefile index fd34ee9..649961b 100644 --- a/pins/Makefile +++ b/pins/Makefile @@ -1,6 +1,10 @@ SRC = pins.tex +ifneq ($V,1) +Q ?= @ +endif + all: ${SRC} @echo Generating DVI diff --git a/wiringPi/Makefile b/wiringPi/Makefile index 015a894..a04f907 100644 --- a/wiringPi/Makefile +++ b/wiringPi/Makefile @@ -25,6 +25,10 @@ VERSION=$(shell cat ../VERSION) DESTDIR=/usr PREFIX=/local +ifneq ($V,1) +Q ?= @ +endif + STATIC=libwiringPi.a DYNAMIC=libwiringPi.so.$(VERSION) From da03f9ed2f5eaeafc154cdadfa9a1c8c9816798d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 9 Sep 2015 23:38:36 +0000 Subject: [PATCH 04/20] Build system: Enable V=1 to disable @'s This patch is autogenerated, with: git-ls-files | grep Makefile | xargs perl -i~ -pe 's/^\t\@/\t\$Q /' Signed-off-by: Ian Jackson --- devLib/Makefile | 66 +++++++++++++------------- examples/Gertboard/Makefile | 40 ++++++++-------- examples/Makefile | 110 ++++++++++++++++++++++---------------------- examples/PiFace/Makefile | 36 +++++++-------- examples/PiGlow/Makefile | 32 ++++++------- examples/q2w/Makefile | 32 ++++++------- gpio/Makefile | 40 ++++++++-------- pins/Makefile | 10 ++-- wiringPi/Makefile | 66 +++++++++++++------------- 9 files changed, 216 insertions(+), 216 deletions(-) diff --git a/devLib/Makefile b/devLib/Makefile index 21ea512..227568c 100644 --- a/devLib/Makefile +++ b/devLib/Makefile @@ -57,66 +57,66 @@ all: $(DYNAMIC) static: $(STATIC) $(STATIC): $(OBJ) - @echo "[Link (Static)]" - @ar rcs $(STATIC) $(OBJ) - @ranlib $(STATIC) + $Q echo "[Link (Static)]" + $Q ar rcs $(STATIC) $(OBJ) + $Q ranlib $(STATIC) # @size $(STATIC) $(DYNAMIC): $(OBJ) - @echo "[Link (Dynamic)]" - @$(CC) -shared -Wl,-soname,libwiringPiDev.so -o libwiringPiDev.so.$(VERSION) -lpthread $(OBJ) + $Q echo "[Link (Dynamic)]" + $Q $(CC) -shared -Wl,-soname,libwiringPiDev.so -o libwiringPiDev.so.$(VERSION) -lpthread $(OBJ) .c.o: - @echo [Compile] $< - @$(CC) -c $(CFLAGS) $< -o $@ + $Q echo [Compile] $< + $Q $(CC) -c $(CFLAGS) $< -o $@ .PHONY: clean clean: - @echo "[Clean]" - @rm -f $(OBJ) $(OBJ_I2C) *~ core tags Makefile.bak libwiringPiDev.* + $Q echo "[Clean]" + $Q rm -f $(OBJ) $(OBJ_I2C) *~ core tags Makefile.bak libwiringPiDev.* .PHONY: tags tags: $(SRC) - @echo [ctags] - @ctags $(SRC) + $Q echo [ctags] + $Q ctags $(SRC) .PHONY: install install: $(DYNAMIC) - @echo "[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 + $Q echo "[Install Headers]" + $Q install -m 0755 -d $(DESTDIR)$(PREFIX)/include + $Q install -m 0644 $(HEADERS) $(DESTDIR)$(PREFIX)/include + $Q echo "[Install Dynamic Lib]" + $Q install -m 0755 -d $(DESTDIR)$(PREFIX)/lib + $Q install -m 0755 libwiringPiDev.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib/libwiringPiDev.so.$(VERSION) + $Q ln -sf $(DESTDIR)$(PREFIX)/lib/libwiringPiDev.so.$(VERSION) $(DESTDIR)/lib/libwiringPiDev.so + $Q ldconfig .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 + $Q echo "[Install Headers]" + $Q install -m 0755 -d $(DESTDIR)$(PREFIX)/include + $Q install -m 0644 $(HEADERS) $(DESTDIR)$(PREFIX)/include + $Q echo "[Install Static Lib]" + $Q install -m 0755 -d $(DESTDIR)$(PREFIX)/lib + $Q 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]" + $Q echo "[Install Headers: deb]" + $Q install -m 0755 -d ~/wiringPi/debian/wiringPi/usr/include + $Q install -m 0644 $(HEADERS) ~/wiringPi/debian/wiringPi/usr/include + $Q 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]" - @cd $(DESTDIR)$(PREFIX)/include/ && rm -f $(HEADERS) - @cd $(DESTDIR)$(PREFIX)/lib/ && rm -f libwiringPiDev.* - @ldconfig + $Q echo "[UnInstall]" + $Q cd $(DESTDIR)$(PREFIX)/include/ && rm -f $(HEADERS) + $Q cd $(DESTDIR)$(PREFIX)/lib/ && rm -f libwiringPiDev.* + $Q ldconfig .PHONY: depend diff --git a/examples/Gertboard/Makefile b/examples/Gertboard/Makefile index 7be81ab..1939ad6 100644 --- a/examples/Gertboard/Makefile +++ b/examples/Gertboard/Makefile @@ -33,44 +33,44 @@ BINS = $(SRC:.c=) all: $(BINS) gertboard: gertboard.o - @echo [link] - @$(CC) -o $@ gertboard.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ gertboard.o $(LDFLAGS) $(LDLIBS) buttons: buttons.o - @echo [link] - @$(CC) -o $@ buttons.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ buttons.o $(LDFLAGS) $(LDLIBS) 7segments: 7segments.o - @echo [link] - @$(CC) -o $@ 7segments.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ 7segments.o $(LDFLAGS) $(LDLIBS) voltmeter: voltmeter.o - @echo [link] - @$(CC) -o $@ voltmeter.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ voltmeter.o $(LDFLAGS) $(LDLIBS) temperature: temperature.o - @echo [link] - @$(CC) -o $@ temperature.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ temperature.o $(LDFLAGS) $(LDLIBS) vumeter: vumeter.o - @echo [link] - @$(CC) -o $@ vumeter.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ vumeter.o $(LDFLAGS) $(LDLIBS) record: record.o - @echo [link] - @$(CC) -o $@ record.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ record.o $(LDFLAGS) $(LDLIBS) .c.o: - @echo [CC] $< - @$(CC) -c $(CFLAGS) $< -o $@ + $Q echo [CC] $< + $Q $(CC) -c $(CFLAGS) $< -o $@ clean: - @echo [Clean] - @rm -f $(OBJ) *~ core tags $(BINS) + $Q echo [Clean] + $Q rm -f $(OBJ) *~ core tags $(BINS) tags: $(SRC) - @echo [ctags] - @ctags $(SRC) + $Q echo [ctags] + $Q ctags $(SRC) depend: makedepend -Y $(SRC) diff --git a/examples/Makefile b/examples/Makefile index 7671b08..60659f5 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -54,116 +54,116 @@ OBJ = $(SRC:.c=.o) BINS = $(SRC:.c=) all: - @cat README.TXT - @echo " $(BINS)" | fmt - @echo "" + $Q cat README.TXT + $Q echo " $(BINS)" | fmt + $Q echo "" really-all: $(BINS) blink: blink.o - @echo [link] - @$(CC) -o $@ blink.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ blink.o $(LDFLAGS) $(LDLIBS) blink8: blink8.o - @echo [link] - @$(CC) -o $@ blink8.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ blink8.o $(LDFLAGS) $(LDLIBS) blink12drcs: blink12drcs.o - @echo [link] - @$(CC) -o $@ blink12drcs.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ blink12drcs.o $(LDFLAGS) $(LDLIBS) blink12: blink12.o - @echo [link] - @$(CC) -o $@ blink12.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ blink12.o $(LDFLAGS) $(LDLIBS) speed: speed.o - @echo [link] - @$(CC) -o $@ speed.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ speed.o $(LDFLAGS) $(LDLIBS) lcd: lcd.o - @echo [link] - @$(CC) -o $@ lcd.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ lcd.o $(LDFLAGS) $(LDLIBS) lcd-adafruit: lcd-adafruit.o - @echo [link] - @$(CC) -o $@ lcd-adafruit.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ lcd-adafruit.o $(LDFLAGS) $(LDLIBS) clock: clock.o - @echo [link] - @$(CC) -o $@ clock.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ clock.o $(LDFLAGS) $(LDLIBS) wfi: wfi.o - @echo [link] - @$(CC) -o $@ wfi.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ wfi.o $(LDFLAGS) $(LDLIBS) isr: isr.o - @echo [link] - @$(CC) -o $@ isr.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ isr.o $(LDFLAGS) $(LDLIBS) isr-osc: isr-osc.o - @echo [link] - @$(CC) -o $@ isr-osc.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ isr-osc.o $(LDFLAGS) $(LDLIBS) nes: nes.o - @echo [link] - @$(CC) -o $@ nes.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ nes.o $(LDFLAGS) $(LDLIBS) rht03: rht03.o - @echo [link] - @$(CC) -o $@ rht03.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ rht03.o $(LDFLAGS) $(LDLIBS) pwm: pwm.o - @echo [link] - @$(CC) -o $@ pwm.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ pwm.o $(LDFLAGS) $(LDLIBS) softPwm: softPwm.o - @echo [link] - @$(CC) -o $@ softPwm.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ softPwm.o $(LDFLAGS) $(LDLIBS) softTone: softTone.o - @echo [link] - @$(CC) -o $@ softTone.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ softTone.o $(LDFLAGS) $(LDLIBS) delayTest: delayTest.o - @echo [link] - @$(CC) -o $@ delayTest.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ delayTest.o $(LDFLAGS) $(LDLIBS) serialRead: serialRead.o - @echo [link] - @$(CC) -o $@ serialRead.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ serialRead.o $(LDFLAGS) $(LDLIBS) serialTest: serialTest.o - @echo [link] - @$(CC) -o $@ serialTest.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ serialTest.o $(LDFLAGS) $(LDLIBS) okLed: okLed.o - @echo [link] - @$(CC) -o $@ okLed.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ okLed.o $(LDFLAGS) $(LDLIBS) tone: tone.o - @echo [link] - @$(CC) -o $@ tone.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ tone.o $(LDFLAGS) $(LDLIBS) ds1302: ds1302.o - @echo [link] - @$(CC) -o $@ ds1302.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ ds1302.o $(LDFLAGS) $(LDLIBS) piglow: piglow.o - @echo [link] - @$(CC) -o $@ piglow.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ piglow.o $(LDFLAGS) $(LDLIBS) .c.o: - @echo [CC] $< - @$(CC) -c $(CFLAGS) $< -o $@ + $Q echo [CC] $< + $Q $(CC) -c $(CFLAGS) $< -o $@ clean: - @echo "[Clean]" - @rm -f $(OBJ) *~ core tags $(BINS) + $Q echo "[Clean]" + $Q rm -f $(OBJ) *~ core tags $(BINS) tags: $(SRC) - @echo [ctags] - @ctags $(SRC) + $Q echo [ctags] + $Q ctags $(SRC) depend: makedepend -Y $(SRC) diff --git a/examples/PiFace/Makefile b/examples/PiFace/Makefile index 7bab7ce..4685adc 100644 --- a/examples/PiFace/Makefile +++ b/examples/PiFace/Makefile @@ -47,40 +47,40 @@ BINS = $(SRC:.c=) all: $(BINS) blink: blink.o - @echo [link] - @$(CC) -o $@ blink.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ blink.o $(LDFLAGS) $(LDLIBS) buttons: buttons.o - @echo [link] - @$(CC) -o $@ buttons.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ buttons.o $(LDFLAGS) $(LDLIBS) reaction: reaction.o - @echo [link] - @$(CC) -o $@ reaction.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ reaction.o $(LDFLAGS) $(LDLIBS) ladder: ladder.o - @echo [link] - @$(CC) -o $@ ladder.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ ladder.o $(LDFLAGS) $(LDLIBS) metro: metro.o - @echo [link] - @$(CC) -o $@ metro.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ metro.o $(LDFLAGS) $(LDLIBS) motor: motor.o - @echo [link] - @$(CC) -o $@ motor.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ motor.o $(LDFLAGS) $(LDLIBS) .c.o: - @echo [CC] $< - @$(CC) -c $(CFLAGS) $< -o $@ + $Q echo [CC] $< + $Q $(CC) -c $(CFLAGS) $< -o $@ clean: - @echo "[Clean]" - @rm -f $(OBJ) *~ core tags $(BINS) + $Q echo "[Clean]" + $Q rm -f $(OBJ) *~ core tags $(BINS) tags: $(SRC) - @echo [ctags] - @ctags $(SRC) + $Q echo [ctags] + $Q ctags $(SRC) depend: makedepend -Y $(SRC) diff --git a/examples/PiGlow/Makefile b/examples/PiGlow/Makefile index 6d8d5bf..b7a8595 100644 --- a/examples/PiGlow/Makefile +++ b/examples/PiGlow/Makefile @@ -47,34 +47,34 @@ BINS = $(SRC:.c=) all: $(BINS) piGlow0: piGlow0.o - @echo [link] - @$(CC) -o $@ piGlow0.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ piGlow0.o $(LDFLAGS) $(LDLIBS) piGlow1: piGlow1.o - @echo [link] - @$(CC) -o $@ piGlow1.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ piGlow1.o $(LDFLAGS) $(LDLIBS) piglow: piglow.o - @echo [link] - @$(CC) -o $@ piglow.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ piglow.o $(LDFLAGS) $(LDLIBS) .c.o: - @echo [CC] $< - @$(CC) -c $(CFLAGS) $< -o $@ + $Q echo [CC] $< + $Q $(CC) -c $(CFLAGS) $< -o $@ clean: - @echo "[Clean]" - @rm -f $(OBJ) *~ core tags $(BINS) + $Q echo "[Clean]" + $Q rm -f $(OBJ) *~ core tags $(BINS) tags: $(SRC) - @echo [ctags] - @ctags $(SRC) + $Q echo [ctags] + $Q ctags $(SRC) install: piglow - @echo Installing piglow into /usr/local/bin - @cp -a piglow /usr/local/bin/piglow - @chmod 755 /usr/local/bin/piglow - @echo Done. Remember to load the I2C drivers! + $Q echo Installing piglow into /usr/local/bin + $Q cp -a piglow /usr/local/bin/piglow + $Q chmod 755 /usr/local/bin/piglow + $Q echo Done. Remember to load the I2C drivers! depend: makedepend -Y $(SRC) diff --git a/examples/q2w/Makefile b/examples/q2w/Makefile index a7bc337..6f50fa0 100644 --- a/examples/q2w/Makefile +++ b/examples/q2w/Makefile @@ -46,37 +46,37 @@ BINS = $(SRC:.c=) all: $(BINS) blink: blink.o - @echo [link] - @$(CC) -o $@ blink.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ blink.o $(LDFLAGS) $(LDLIBS) blink-io: blink-io.o - @echo [link] - @$(CC) -o $@ blink-io.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ blink-io.o $(LDFLAGS) $(LDLIBS) button: button.o - @echo [link] - @$(CC) -o $@ button.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ button.o $(LDFLAGS) $(LDLIBS) volts: volts.o - @echo [link] - @$(CC) -o $@ volts.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ volts.o $(LDFLAGS) $(LDLIBS) bright: bright.o - @echo [link] - @$(CC) -o $@ bright.o $(LDFLAGS) $(LDLIBS) + $Q echo [link] + $Q $(CC) -o $@ bright.o $(LDFLAGS) $(LDLIBS) .c.o: - @echo [CC] $< - @$(CC) -c $(CFLAGS) $< -o $@ + $Q echo [CC] $< + $Q $(CC) -c $(CFLAGS) $< -o $@ clean: - @echo "[Clean]" - @rm -f $(OBJ) *~ core tags $(BINS) + $Q echo "[Clean]" + $Q rm -f $(OBJ) *~ core tags $(BINS) tags: $(SRC) - @echo [ctags] - @ctags $(SRC) + $Q echo [ctags] + $Q ctags $(SRC) depend: makedepend -Y $(SRC) diff --git a/gpio/Makefile b/gpio/Makefile index df05dbe..09a9cc9 100644 --- a/gpio/Makefile +++ b/gpio/Makefile @@ -52,43 +52,43 @@ version.h: ../VERSION ./newVersion gpio: $(OBJ) - @echo [Link] - @$(CC) -o $@ $(OBJ) $(LDFLAGS) $(LIBS) + $Q echo [Link] + $Q $(CC) -o $@ $(OBJ) $(LDFLAGS) $(LIBS) .c.o: - @echo [Compile] $< - @$(CC) -c $(CFLAGS) $< -o $@ + $Q echo [Compile] $< + $Q $(CC) -c $(CFLAGS) $< -o $@ .PHONY: clean clean: - @echo "[Clean]" - @rm -f $(OBJ) gpio *~ core tags *.bak + $Q echo "[Clean]" + $Q rm -f $(OBJ) gpio *~ core tags *.bak .PHONY: tags tags: $(SRC) - @echo [ctags] - @ctags $(SRC) + $Q echo [ctags] + $Q ctags $(SRC) .PHONY: install install: gpio - @echo "[Install]" - @cp gpio $(DESTDIR)$(PREFIX)/bin - @chown root.root $(DESTDIR)$(PREFIX)/bin/gpio - @chmod 4755 $(DESTDIR)$(PREFIX)/bin/gpio - @mkdir -p $(DESTDIR)$(PREFIX)/man/man1 - @cp gpio.1 $(DESTDIR)$(PREFIX)/man/man1 + $Q echo "[Install]" + $Q cp gpio $(DESTDIR)$(PREFIX)/bin + $Q chown root.root $(DESTDIR)$(PREFIX)/bin/gpio + $Q chmod 4755 $(DESTDIR)$(PREFIX)/bin/gpio + $Q mkdir -p $(DESTDIR)$(PREFIX)/man/man1 + $Q 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 + $Q echo "[Install: deb]" + $Q install -m 0755 -d ~/wiringPi/debian/wiringPi/usr/bin + $Q install -m 0755 gpio ~/wiringPi/debian/wiringPi/usr/bin .PHONY: uninstall uninstall: - @echo "[UnInstall]" - @rm -f $(DESTDIR)$(PREFIX)/bin/gpio - @rm -f $(DESTDIR)$(PREFIX)/man/man1/gpio.1 + $Q echo "[UnInstall]" + $Q rm -f $(DESTDIR)$(PREFIX)/bin/gpio + $Q rm -f $(DESTDIR)$(PREFIX)/man/man1/gpio.1 .PHONY: depend depend: diff --git a/pins/Makefile b/pins/Makefile index 649961b..9535fb5 100644 --- a/pins/Makefile +++ b/pins/Makefile @@ -7,16 +7,16 @@ endif all: ${SRC} - @echo Generating DVI - @latex pins.tex + $Q echo Generating DVI + $Q latex pins.tex pins.dvi: pins.tex - @latex pins.tex + $Q latex pins.tex pdf: pins.dvi - @dvipdf pins.dvi + $Q dvipdf pins.dvi .PHONY: clean clean: - @rm -f *.dvi *.aux *.log *.ps *.toc *.bak *~ + $Q rm -f *.dvi *.aux *.log *.ps *.toc *.bak *~ diff --git a/wiringPi/Makefile b/wiringPi/Makefile index a04f907..bc8c848 100644 --- a/wiringPi/Makefile +++ b/wiringPi/Makefile @@ -80,67 +80,67 @@ all: $(DYNAMIC) static: $(STATIC) $(STATIC): $(OBJ) - @echo "[Link (Static)]" - @ar rcs $(STATIC) $(OBJ) - @ranlib $(STATIC) + $Q echo "[Link (Static)]" + $Q ar rcs $(STATIC) $(OBJ) + $Q ranlib $(STATIC) # @size $(STATIC) $(DYNAMIC): $(OBJ) - @echo "[Link (Dynamic)]" - @$(CC) -shared -Wl,-soname,libwiringPi.so -o libwiringPi.so.$(VERSION) -lpthread $(OBJ) + $Q echo "[Link (Dynamic)]" + $Q $(CC) -shared -Wl,-soname,libwiringPi.so -o libwiringPi.so.$(VERSION) -lpthread $(OBJ) .c.o: - @echo [Compile] $< - @$(CC) -c $(CFLAGS) $< -o $@ + $Q echo [Compile] $< + $Q $(CC) -c $(CFLAGS) $< -o $@ .PHONY: clean clean: - @echo "[Clean]" - @rm -f $(OBJ) $(OBJ_I2C) *~ core tags Makefile.bak libwiringPi.* + $Q echo "[Clean]" + $Q rm -f $(OBJ) $(OBJ_I2C) *~ core tags Makefile.bak libwiringPi.* .PHONY: tags tags: $(SRC) - @echo [ctags] - @ctags $(SRC) + $Q echo [ctags] + $Q ctags $(SRC) .PHONY: install install: $(DYNAMIC) - @echo "[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 + $Q echo "[Install Headers]" + $Q install -m 0755 -d $(DESTDIR)$(PREFIX)/include + $Q install -m 0644 $(HEADERS) $(DESTDIR)$(PREFIX)/include + $Q echo "[Install Dynamic Lib]" + $Q install -m 0755 -d $(DESTDIR)$(PREFIX)/lib + $Q install -m 0755 libwiringPi.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib/libwiringPi.so.$(VERSION) + $Q ln -sf $(DESTDIR)$(PREFIX)/lib/libwiringPi.so.$(VERSION) $(DESTDIR)/lib/libwiringPi.so + $Q ldconfig .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 + $Q echo "[Install Headers]" + $Q install -m 0755 -d $(DESTDIR)$(PREFIX)/include + $Q install -m 0644 $(HEADERS) $(DESTDIR)$(PREFIX)/include + $Q echo "[Install Static Lib]" + $Q install -m 0755 -d $(DESTDIR)$(PREFIX)/lib + $Q 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]" + $Q echo "[Install Headers: deb]" + $Q install -m 0755 -d ~/wiringPi/debian/wiringPi/usr/include + $Q install -m 0644 $(HEADERS) ~/wiringPi/debian/wiringPi/usr/include + $Q 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]" - @cd $(DESTDIR)$(PREFIX)/include/ && rm -f $(HEADERS) - @cd $(DESTDIR)$(PREFIX)/lib/ && rm -f libwiringPi.* - @ldconfig + $Q echo "[UnInstall]" + $Q cd $(DESTDIR)$(PREFIX)/include/ && rm -f $(HEADERS) + $Q cd $(DESTDIR)$(PREFIX)/lib/ && rm -f libwiringPi.* + $Q ldconfig .PHONY: depend From 5f7dc3263bc2a286f1bc940c94c7e1b44c294076 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 9 Sep 2015 23:39:59 +0000 Subject: [PATCH 05/20] Build system: Remove a trailing tab from gpio/Makefile emacs complains about this line, because it thinks lines with just a tab on in Makefiles are suspicious. Remove the needless tab. No functional change. Signed-off-by: Ian Jackson --- gpio/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpio/Makefile b/gpio/Makefile index 09a9cc9..82416a7 100644 --- a/gpio/Makefile +++ b/gpio/Makefile @@ -54,7 +54,7 @@ version.h: ../VERSION gpio: $(OBJ) $Q echo [Link] $Q $(CC) -o $@ $(OBJ) $(LDFLAGS) $(LIBS) - + .c.o: $Q echo [Compile] $< $Q $(CC) -c $(CFLAGS) $< -o $@ From a6ee925df67de60c1e0d9fe9a09318c775c43fd6 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 10 Sep 2015 00:09:36 +0000 Subject: [PATCH 06/20] Build system: Fix ./build debian We need to -I and -L the build tree directories, not the directories in /usr/local or wheveever. Otherwise (a) the `./debian build' fails if wiringPi is not installed (b) if it _is_ installed, the build picks up the installed versions rather than the versions being built, which is wrong. Signed-off-by: Ian Jackson --- build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build b/build index 7c05087..00a366b 100755 --- a/build +++ b/build @@ -82,9 +82,9 @@ if [ x$1 = "xdebian" ]; then cd $here/wiringPi make install-deb cd $here/devLib - make install-deb + make install-deb INCLUDE='-I. -I../wiringPi' cd $here/gpio - make install-deb + make install-deb INCLUDE='-I../wiringPi -I../devLib' LDFLAGS=-L../debian/wiringPi/usr/lib cd $here/debian fakeroot dpkg-deb --build wiringPi mv wiringPi.deb wiringpi-`cat $here/VERSION`-1.deb From f8a025189f8c9b4bd21c9d2077a08d0179a4236c Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 10 Sep 2015 00:11:33 +0000 Subject: [PATCH 07/20] Build system: Fix erroneous symlink in devLib/Makefile The symlink libwiringPiDev.so was mistakenly created pointing to libwiringPi.so.$(VERSION) (note lack of Dev), ie to the wrong library. Signed-off-by: Ian Jackson --- devLib/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devLib/Makefile b/devLib/Makefile index 227568c..5cac38e 100644 --- a/devLib/Makefile +++ b/devLib/Makefile @@ -109,7 +109,7 @@ install-deb: $(DYNAMIC) $Q 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 + ln -sf ~/wiringPi/debian/wiringPi/usr/lib/libwiringPiDev.so.$(VERSION) ~/wiringPi/debian/wiringPi/usr/lib/libwiringPiDev.so .PHONY: uninstall uninstall: From a19bfb579804db76c11ac41a47a097f53ec25ea8 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 12 Sep 2015 16:38:12 +0000 Subject: [PATCH 08/20] examples/blink.sh: Add missing +x bit with chmod Signed-off-by: Ian Jackson --- examples/blink.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 examples/blink.sh diff --git a/examples/blink.sh b/examples/blink.sh old mode 100644 new mode 100755 From 532083f4741214ed9b23ccc4fa5b0b24db2d32a5 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 12 Sep 2015 19:16:50 +0000 Subject: [PATCH 09/20] Manpage gpio(1): Regularise header Signed-off-by: Ian Jackson --- gpio/gpio.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpio/gpio.1 b/gpio/gpio.1 index 77b41bf..8949442 100644 --- a/gpio/gpio.1 +++ b/gpio/gpio.1 @@ -1,4 +1,4 @@ -.TH "GPIO" "January 2015" "Command-Line access to Raspberry Pi's GPIO" +.TH gpio 1 "January 2015" wiringPi "Command-Line access to Raspberry Pi's GPIO" .SH NAME gpio \- Command-line access to Raspberry Pi's GPIO From ac0f074ff7b79eb5201fdbbb5a44200ada2a6f99 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 12 Sep 2015 17:25:39 +0000 Subject: [PATCH 10/20] Build system: Move template-based debian build into debian-template We are going to want to introduce a real Debian source package build system. But that needs to contain a lot of things in debian/ which ought not to appear in the .deb made by the existing ad-hoc `./build debian' arrangements, which we want to keep so as not to unduly disturb existing users. So rename the whole debian/ directory to debian-template/ and change all references in the build system. Signed-off-by: Ian Jackson --- .gitignore | 4 ++-- build | 6 +++--- debian-template/wiringPi/DEBIAN/control | 10 ++++++++++ debian-template/wiringPi/DEBIAN/postinst | 5 +++++ debian-template/wiringPi/DEBIAN/postrm | 2 ++ debian/wiringPi/DEBIAN/control | 10 ---------- debian/wiringPi/DEBIAN/postinst | 5 ----- debian/wiringPi/DEBIAN/postrm | 2 -- devLib/Makefile | 10 +++++----- gpio/Makefile | 4 ++-- wiringPi/Makefile | 10 +++++----- 11 files changed, 34 insertions(+), 34 deletions(-) create mode 100644 debian-template/wiringPi/DEBIAN/control create mode 100755 debian-template/wiringPi/DEBIAN/postinst create mode 100755 debian-template/wiringPi/DEBIAN/postrm delete mode 100644 debian/wiringPi/DEBIAN/control delete mode 100755 debian/wiringPi/DEBIAN/postinst delete mode 100755 debian/wiringPi/DEBIAN/postrm diff --git a/.gitignore b/.gitignore index c1855e9..ed2ec80 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,6 @@ *.so lib*.so.* *~ -debian/wiringPi -debian/wiringpi-*.deb +debian-template/wiringPi +debian-template/wiringpi-*.deb gpio/gpio diff --git a/build b/build index 00a366b..524c14a 100755 --- a/build +++ b/build @@ -77,15 +77,15 @@ fi if [ x$1 = "xdebian" ]; then here=`pwd` - cd debian/wiringPi + cd debian-template/wiringPi rm -rf usr cd $here/wiringPi make install-deb cd $here/devLib make install-deb INCLUDE='-I. -I../wiringPi' cd $here/gpio - make install-deb INCLUDE='-I../wiringPi -I../devLib' LDFLAGS=-L../debian/wiringPi/usr/lib - cd $here/debian + make install-deb INCLUDE='-I../wiringPi -I../devLib' LDFLAGS=-L../debian-template/wiringPi/usr/lib + cd $here/debian-template fakeroot dpkg-deb --build wiringPi mv wiringPi.deb wiringpi-`cat $here/VERSION`-1.deb exit diff --git a/debian-template/wiringPi/DEBIAN/control b/debian-template/wiringPi/DEBIAN/control new file mode 100644 index 0000000..73ee094 --- /dev/null +++ b/debian-template/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/debian-template/wiringPi/DEBIAN/postinst b/debian-template/wiringPi/DEBIAN/postinst new file mode 100755 index 0000000..4997e98 --- /dev/null +++ b/debian-template/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/debian-template/wiringPi/DEBIAN/postrm b/debian-template/wiringPi/DEBIAN/postrm new file mode 100755 index 0000000..4be8c58 --- /dev/null +++ b/debian-template/wiringPi/DEBIAN/postrm @@ -0,0 +1,2 @@ +#!/bin/sh +/sbin/ldconfig diff --git a/debian/wiringPi/DEBIAN/control b/debian/wiringPi/DEBIAN/control deleted file mode 100644 index 73ee094..0000000 --- a/debian/wiringPi/DEBIAN/control +++ /dev/null @@ -1,10 +0,0 @@ -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/debian/wiringPi/DEBIAN/postinst b/debian/wiringPi/DEBIAN/postinst deleted file mode 100755 index 4997e98..0000000 --- a/debian/wiringPi/DEBIAN/postinst +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -set -e -/bin/chown root.root /usr/bin/gpio -/bin/chmod 4755 /usr/bin/gpio -/sbin/ldconfig diff --git a/debian/wiringPi/DEBIAN/postrm b/debian/wiringPi/DEBIAN/postrm deleted file mode 100755 index 4be8c58..0000000 --- a/debian/wiringPi/DEBIAN/postrm +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -/sbin/ldconfig diff --git a/devLib/Makefile b/devLib/Makefile index 5cac38e..48cf3ae 100644 --- a/devLib/Makefile +++ b/devLib/Makefile @@ -104,12 +104,12 @@ install-static: $(STATIC) .PHONY: install-deb install-deb: $(DYNAMIC) $Q echo "[Install Headers: deb]" - $Q install -m 0755 -d ~/wiringPi/debian/wiringPi/usr/include - $Q install -m 0644 $(HEADERS) ~/wiringPi/debian/wiringPi/usr/include + $Q install -m 0755 -d ~/wiringPi/debian-template/wiringPi/usr/include + $Q install -m 0644 $(HEADERS) ~/wiringPi/debian-template/wiringPi/usr/include $Q 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/libwiringPiDev.so.$(VERSION) ~/wiringPi/debian/wiringPi/usr/lib/libwiringPiDev.so + install -m 0755 -d ~/wiringPi/debian-template/wiringPi/usr/lib + install -m 0755 libwiringPiDev.so.$(VERSION) ~/wiringPi/debian-template/wiringPi/usr/lib/libwiringPiDev.so.$(VERSION) + ln -sf ~/wiringPi/debian-template/wiringPi/usr/lib/libwiringPiDev.so.$(VERSION) ~/wiringPi/debian-template/wiringPi/usr/lib/libwiringPiDev.so .PHONY: uninstall uninstall: diff --git a/gpio/Makefile b/gpio/Makefile index 82416a7..82a817c 100644 --- a/gpio/Makefile +++ b/gpio/Makefile @@ -81,8 +81,8 @@ install: gpio .PHONY: install-deb install-deb: gpio $Q echo "[Install: deb]" - $Q install -m 0755 -d ~/wiringPi/debian/wiringPi/usr/bin - $Q install -m 0755 gpio ~/wiringPi/debian/wiringPi/usr/bin + $Q install -m 0755 -d ~/wiringPi/debian-template/wiringPi/usr/bin + $Q install -m 0755 gpio ~/wiringPi/debian-template/wiringPi/usr/bin .PHONY: uninstall uninstall: diff --git a/wiringPi/Makefile b/wiringPi/Makefile index bc8c848..3a1b99f 100644 --- a/wiringPi/Makefile +++ b/wiringPi/Makefile @@ -128,12 +128,12 @@ install-static: $(STATIC) .PHONY: install-deb install-deb: $(DYNAMIC) $Q echo "[Install Headers: deb]" - $Q install -m 0755 -d ~/wiringPi/debian/wiringPi/usr/include - $Q install -m 0644 $(HEADERS) ~/wiringPi/debian/wiringPi/usr/include + $Q install -m 0755 -d ~/wiringPi/debian-template/wiringPi/usr/include + $Q install -m 0644 $(HEADERS) ~/wiringPi/debian-template/wiringPi/usr/include $Q 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 + install -m 0755 -d ~/wiringPi/debian-template/wiringPi/usr/lib + install -m 0755 libwiringPi.so.$(VERSION) ~/wiringPi/debian-template/wiringPi/usr/lib/libwiringPi.so.$(VERSION) + ln -sf ~/wiringPi/debian-template/wiringPi/usr/lib/libwiringPi.so.$(VERSION) ~/wiringPi/debian-template/wiringPi/usr/lib/libwiringPi.so .PHONY: uninstall uninstall: From 73aa8956c543777c048c185132abe585fcb9ded8 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 12 Sep 2015 16:41:38 +0000 Subject: [PATCH 11/20] build: Introduce a variable "$sudo" and honour WIRINGPI_SUDO We are going to want to not run sudo sometimes. So replace literal invocations of sudo with a variable, which is set to `sudo' by default, but can be overridden from the environment. No functional change if the environment variable is not set. Signed-off-by: Ian Jackson --- build | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/build b/build index 524c14a..c2a589c 100755 --- a/build +++ b/build @@ -43,6 +43,8 @@ check_make_ok() { fi } +sudo=${WIRINGPI_SUDO-sudo} + if [ x$1 = "xclean" ]; then cd wiringPi echo -n "wiringPi: " ; make clean @@ -65,11 +67,11 @@ fi if [ x$1 = "xuninstall" ]; then cd wiringPi - echo -n "wiringPi: " ; sudo make uninstall + echo -n "wiringPi: " ; $sudo make uninstall cd ../devLib - echo -n "DevLib: " ; sudo make uninstall + echo -n "DevLib: " ; $sudo make uninstall cd ../gpio - echo -n "gpio: " ; sudo make uninstall + echo -n "gpio: " ; $sudo make uninstall exit fi @@ -121,30 +123,30 @@ fi echo echo "WiringPi Library" cd wiringPi - sudo make uninstall + $sudo make uninstall if [ x$1 = "xstatic" ]; then make -j5 static check_make_ok - sudo make install-static + $sudo make install-static else make -j5 check_make_ok - sudo make install + $sudo make install fi check_make_ok echo echo "WiringPi Devices Library" cd ../devLib - sudo make uninstall + $sudo make uninstall if [ x$1 = "xstatic" ]; then make -j5 static check_make_ok - sudo make install-static + $sudo make install-static else make -j5 check_make_ok - sudo make install + $sudo make install fi check_make_ok @@ -153,7 +155,7 @@ fi cd ../gpio make -j5 check_make_ok - sudo make install + $sudo make install check_make_ok # echo From 508d6b31bd9564fa2f0a6676089d4495d2917a2d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 12 Sep 2015 17:15:44 +0000 Subject: [PATCH 12/20] Makefiles: Do not override PREFIX or DESTDIR from the environment These are not set in normal shell sessions. Honouring existing settings allows the caller of ./build to specify alternative values. Signed-off-by: Ian Jackson --- devLib/Makefile | 4 ++-- gpio/Makefile | 4 ++-- wiringPi/Makefile | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/devLib/Makefile b/devLib/Makefile index 48cf3ae..9ec163d 100644 --- a/devLib/Makefile +++ b/devLib/Makefile @@ -22,8 +22,8 @@ ################################################################################# VERSION=$(shell cat ../VERSION) -DESTDIR=/usr -PREFIX=/local +DESTDIR?=/usr +PREFIX?=/local ifneq ($V,1) Q ?= @ diff --git a/gpio/Makefile b/gpio/Makefile index 82a817c..095ec48 100644 --- a/gpio/Makefile +++ b/gpio/Makefile @@ -23,8 +23,8 @@ # along with wiringPi. If not, see . ################################################################################# -DESTDIR=/usr -PREFIX=/local +DESTDIR?=/usr +PREFIX?=/local ifneq ($V,1) Q ?= @ diff --git a/wiringPi/Makefile b/wiringPi/Makefile index 3a1b99f..c0623ce 100644 --- a/wiringPi/Makefile +++ b/wiringPi/Makefile @@ -22,8 +22,8 @@ ################################################################################# VERSION=$(shell cat ../VERSION) -DESTDIR=/usr -PREFIX=/local +DESTDIR?=/usr +PREFIX?=/local ifneq ($V,1) Q ?= @ From f5dd04b5aea2a26bf393013f33a99b1ccaae864f Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 12 Sep 2015 17:16:46 +0000 Subject: [PATCH 13/20] Makefiles: Honour LDCONFIG from the environment This is not set in normal shell sessions. Honouring an existing setting of LDCONFIG allows the caller of ./build to specify an alternative program to run. Signed-off-by: Ian Jackson --- devLib/Makefile | 6 ++++-- wiringPi/Makefile | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/devLib/Makefile b/devLib/Makefile index 9ec163d..38ab9d9 100644 --- a/devLib/Makefile +++ b/devLib/Makefile @@ -25,6 +25,8 @@ VERSION=$(shell cat ../VERSION) DESTDIR?=/usr PREFIX?=/local +LDCONFIG?=ldconfig + ifneq ($V,1) Q ?= @ endif @@ -90,7 +92,7 @@ install: $(DYNAMIC) $Q install -m 0755 -d $(DESTDIR)$(PREFIX)/lib $Q install -m 0755 libwiringPiDev.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib/libwiringPiDev.so.$(VERSION) $Q ln -sf $(DESTDIR)$(PREFIX)/lib/libwiringPiDev.so.$(VERSION) $(DESTDIR)/lib/libwiringPiDev.so - $Q ldconfig + $Q $(LDCONFIG) .PHONY: install-static install-static: $(STATIC) @@ -116,7 +118,7 @@ uninstall: $Q echo "[UnInstall]" $Q cd $(DESTDIR)$(PREFIX)/include/ && rm -f $(HEADERS) $Q cd $(DESTDIR)$(PREFIX)/lib/ && rm -f libwiringPiDev.* - $Q ldconfig + $Q $(LDCONFIG) .PHONY: depend diff --git a/wiringPi/Makefile b/wiringPi/Makefile index c0623ce..5518c9e 100644 --- a/wiringPi/Makefile +++ b/wiringPi/Makefile @@ -25,6 +25,8 @@ VERSION=$(shell cat ../VERSION) DESTDIR?=/usr PREFIX?=/local +LDCONFIG?=ldconfig + ifneq ($V,1) Q ?= @ endif @@ -114,7 +116,7 @@ install: $(DYNAMIC) $Q install -m 0755 -d $(DESTDIR)$(PREFIX)/lib $Q install -m 0755 libwiringPi.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib/libwiringPi.so.$(VERSION) $Q ln -sf $(DESTDIR)$(PREFIX)/lib/libwiringPi.so.$(VERSION) $(DESTDIR)/lib/libwiringPi.so - $Q ldconfig + $Q $(LDCONFIG) .PHONY: install-static install-static: $(STATIC) @@ -140,7 +142,7 @@ uninstall: $Q echo "[UnInstall]" $Q cd $(DESTDIR)$(PREFIX)/include/ && rm -f $(HEADERS) $Q cd $(DESTDIR)$(PREFIX)/lib/ && rm -f libwiringPi.* - $Q ldconfig + $Q $(LDCONFIG) .PHONY: depend From 3ceb07a9a65b4bcbe54a80001522327cfdb9d91d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 12 Sep 2015 17:17:36 +0000 Subject: [PATCH 14/20] Makefiles: Honour WIRINGPI_SUDO=0 This makes it possible for the caller of ./build to suppress the chown/chmod of the gpio utility. Signed-off-by: Ian Jackson --- gpio/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gpio/Makefile b/gpio/Makefile index 095ec48..fa78421 100644 --- a/gpio/Makefile +++ b/gpio/Makefile @@ -73,8 +73,10 @@ tags: $(SRC) install: gpio $Q echo "[Install]" $Q cp gpio $(DESTDIR)$(PREFIX)/bin +ifneq ($(WIRINGPI_SUID),0) $Q chown root.root $(DESTDIR)$(PREFIX)/bin/gpio $Q chmod 4755 $(DESTDIR)$(PREFIX)/bin/gpio +endif $Q mkdir -p $(DESTDIR)$(PREFIX)/man/man1 $Q cp gpio.1 $(DESTDIR)$(PREFIX)/man/man1 From ae421d4a9ccc09c440d5a30cca6f1a206ffec89d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 12 Sep 2015 18:45:09 +0000 Subject: [PATCH 15/20] Makefiles: Honour WIRINGPI_SONAME_SUFFIX This makes it possible for the caller of ./build to add a version number to the sonames of the shared libraries. (This is required for Debian packages.) Signed-off-by: Ian Jackson --- devLib/Makefile | 2 +- wiringPi/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/devLib/Makefile b/devLib/Makefile index 38ab9d9..0fb0033 100644 --- a/devLib/Makefile +++ b/devLib/Makefile @@ -66,7 +66,7 @@ $(STATIC): $(OBJ) $(DYNAMIC): $(OBJ) $Q echo "[Link (Dynamic)]" - $Q $(CC) -shared -Wl,-soname,libwiringPiDev.so -o libwiringPiDev.so.$(VERSION) -lpthread $(OBJ) + $Q $(CC) -shared -Wl,-soname,libwiringPiDev.so$(WIRINGPI_SONAME_SUFFIX) -o libwiringPiDev.so.$(VERSION) -lpthread $(OBJ) .c.o: $Q echo [Compile] $< diff --git a/wiringPi/Makefile b/wiringPi/Makefile index 5518c9e..6bbcc5d 100644 --- a/wiringPi/Makefile +++ b/wiringPi/Makefile @@ -89,7 +89,7 @@ $(STATIC): $(OBJ) $(DYNAMIC): $(OBJ) $Q echo "[Link (Dynamic)]" - $Q $(CC) -shared -Wl,-soname,libwiringPi.so -o libwiringPi.so.$(VERSION) -lpthread $(OBJ) + $Q $(CC) -shared -Wl,-soname,libwiringPi.so$(WIRINGPI_SONAME_SUFFIX) -o libwiringPi.so.$(VERSION) -lpthread $(OBJ) .c.o: $Q echo [Compile] $< From a776e6b0e834189b69bd5d33a9bcc5e07ad6cc03 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 12 Sep 2015 17:13:42 +0000 Subject: [PATCH 16/20] Introduce a proper Debian source package build system It's not perfect - there is no symbol versioning, and I have had to make some (perhaps false) assumptions about library ABI stability, but it does produce something vaguely resembling what would be expected from a library package found in Debian, and it does so using the standard Debian source format. Signed-off-by: Ian Jackson --- debian/.gitignore | 9 ++++++++ debian/changelog | 6 ++++++ debian/compat | 1 + debian/control | 29 +++++++++++++++++++++++++ debian/copyright | 15 +++++++++++++ debian/libwiringpi-dev.dirs | 2 ++ debian/libwiringpi-dev.install | 3 +++ debian/libwiringpi2.install | 1 + debian/libwiringpi2.shlibs | 2 ++ debian/rules | 49 ++++++++++++++++++++++++++++++++++++++++++ debian/wiringpi.dirs | 1 + debian/wiringpi.install | 4 ++++ 12 files changed, 122 insertions(+) create mode 100644 debian/.gitignore create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/libwiringpi-dev.dirs create mode 100644 debian/libwiringpi-dev.install create mode 100644 debian/libwiringpi2.install create mode 100644 debian/libwiringpi2.shlibs create mode 100755 debian/rules create mode 100644 debian/wiringpi.dirs create mode 100644 debian/wiringpi.install diff --git a/debian/.gitignore b/debian/.gitignore new file mode 100644 index 0000000..6296064 --- /dev/null +++ b/debian/.gitignore @@ -0,0 +1,9 @@ +*.debhelper.log +*.substvars +tmp +wiringpi +libwiringpi2 +libwiringpi-dev +files +*.postinst.debhelper +*.postrm.debhelper diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..7f04ad5 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,6 @@ +wiringpi (2.26~iwj) rpi-unstable; urgency=low + + * Initial version with real Debian source package build. + + -- Ian Jackson Sat, 12 Sep 2015 18:31:35 +0100 + diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +8 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..1d6d228 --- /dev/null +++ b/debian/control @@ -0,0 +1,29 @@ +Source: wiringpi +Section: electronics +Priority: optional +Maintainer: Ian Jackson +Standards-Version: 3.8.0 +Homepage: http://wiringpi.com/ +Build-Depends: debhelper (>= 8) + +Package: libwiringpi2 +Section: libs +Architecture: armhf +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: GPIO librariees for Raspberry Pi (runtime). + Runtime for the popular wiringPi library. + +Package: wiringpi +Architecture: armhf +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: gpio utility for Raspberry Pi + The wiringPi gpio command line utility, for GPIO access on a + Raspberry Pi from the command line. + +Package: libwiringpi-dev +Architecture: armhf +Depends: libwiringpi2 (= ${binary:Version}), libc6-dev, ${misc:Depends} +Suggests: wiringpi +Description: GPIO development library for Raspberry Pi + Development libraries to allow GPIO access on a Raspberry Pi from C + and C++ programs. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..de82701 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,15 @@ +wiringPi is Copyright (C) 2012-2015 Gordon Henderson. + +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. + +On all Debian and Raspbian systems, a copy of the GNU Lesser General +Public License version 3 can be found in +`/usr/share/common-licenses/LGPL-3'. diff --git a/debian/libwiringpi-dev.dirs b/debian/libwiringpi-dev.dirs new file mode 100644 index 0000000..4418816 --- /dev/null +++ b/debian/libwiringpi-dev.dirs @@ -0,0 +1,2 @@ +usr/lib +usr/include diff --git a/debian/libwiringpi-dev.install b/debian/libwiringpi-dev.install new file mode 100644 index 0000000..d7ea901 --- /dev/null +++ b/debian/libwiringpi-dev.install @@ -0,0 +1,3 @@ +debian/tmp/usr/include +debian/tmp/usr/lib/*.so +examples usr/share/doc/libwiringpi-dev diff --git a/debian/libwiringpi2.install b/debian/libwiringpi2.install new file mode 100644 index 0000000..c45ebcf --- /dev/null +++ b/debian/libwiringpi2.install @@ -0,0 +1 @@ +debian/tmp/usr/lib/lib*.so.* diff --git a/debian/libwiringpi2.shlibs b/debian/libwiringpi2.shlibs new file mode 100644 index 0000000..0be8db1 --- /dev/null +++ b/debian/libwiringpi2.shlibs @@ -0,0 +1,2 @@ +libwiringPi 2 libwiringpi2 +libwiringPiDev 2 libwiringpi2 diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..423a473 --- /dev/null +++ b/debian/rules @@ -0,0 +1,49 @@ +#!/usr/bin/make -f + +.PHONY: build + +VERSION:=$(shell cat VERSION) +export VERSION + +soname:=$(shell echo $${VERSION%%.*}) +WIRINGPI_SONAME_SUFFIX:=.$(soname) +export soname +export WIRINGPI_SONAME_SUFFIX + +build: + dh $@ + +override_dh_auto_configure: + +override_dh_prep: + dh_prep -Xdebian/tmp + +dirs: + dh_installdirs -A + mkdir debian/tmp + set -e; for p in `dh_listpackages`; do \ + (cd debian/$$p; find -type d) | \ + (cd debian/tmp; xargs mkdir -p) \ + done + +override_dh_clean: + dh_clean + WIRINGPI_SUDO= bash -xe ./build clean + +override_dh_auto_build: dirs + V=1 LDCONFIG=: WIRINGPI_SUDO= WIRINGPI_SUID=0 \ + DESTDIR=`pwd`/debian/tmp/usr \ + PREFIX= WIRINGPI_SUDO= \ + bash -xe ./build + +override_dh_auto_install: + dh_install + set -ex; for l in libwiringPi libwiringPiDev; do \ + ln -sf $$l.so.$${VERSION} \ + debian/libwiringpi$$soname/usr/lib/$$l.so.$$soname; \ + ln -sf $$l.so.$${VERSION} \ + debian/libwiringpi-dev/usr/lib/$$l.so; \ + done + +%: + dh $@ diff --git a/debian/wiringpi.dirs b/debian/wiringpi.dirs new file mode 100644 index 0000000..e772481 --- /dev/null +++ b/debian/wiringpi.dirs @@ -0,0 +1 @@ +usr/bin diff --git a/debian/wiringpi.install b/debian/wiringpi.install new file mode 100644 index 0000000..41ae22d --- /dev/null +++ b/debian/wiringpi.install @@ -0,0 +1,4 @@ +debian/tmp/usr/bin +debian/tmp/usr/man usr/share +README.TXT usr/share/doc/wiringpi +People usr/share/doc/wiringpi From 170dce5f1939a3629bbc2329c5557cbaa0bc278f Mon Sep 17 00:00:00 2001 From: Gordon Henderson Date: Sun, 20 Sep 2015 19:30:38 +0100 Subject: [PATCH 17/20] Updated the Debian build system thanks to Ian Jackson for the help. --- VERSION | 2 +- debian-template/wiringPi/DEBIAN/control | 2 +- gpio/Makefile | 4 +- gpio/gpio.c | 11 +++++ gpio/newVersion | 26 ----------- gpio/version.h | 2 +- newVersion | 43 ++++++++++++++++++ wiringPi/max31855.c | 59 ++++++++++++++++--------- wiringPi/wiringPi.c | 78 ++++++++++++++++++++++++--------- 9 files changed, 156 insertions(+), 71 deletions(-) delete mode 100755 gpio/newVersion create mode 100755 newVersion diff --git a/VERSION b/VERSION index 8bd2249..7dba3a2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.25 +2.27 diff --git a/debian-template/wiringPi/DEBIAN/control b/debian-template/wiringPi/DEBIAN/control index 73ee094..2a65ff5 100644 --- a/debian-template/wiringPi/DEBIAN/control +++ b/debian-template/wiringPi/DEBIAN/control @@ -1,5 +1,5 @@ Package: wiringpi -Version: 2.24 +Version: 2.27 Section: libraries Priority: optional Architecture: armhf diff --git a/gpio/Makefile b/gpio/Makefile index fa78421..e998d84 100644 --- a/gpio/Makefile +++ b/gpio/Makefile @@ -49,7 +49,7 @@ OBJ = $(SRC:.c=.o) all: gpio version.h: ../VERSION - ./newVersion + $Q echo Need to run newVersion above. gpio: $(OBJ) $Q echo [Link] @@ -97,3 +97,5 @@ depend: makedepend -Y $(SRC) # DO NOT DELETE + +gpio.o: version.h diff --git a/gpio/gpio.c b/gpio/gpio.c index 6dc6113..a25f454 100644 --- a/gpio/gpio.c +++ b/gpio/gpio.c @@ -1194,6 +1194,17 @@ int main (int argc, char *argv []) printf ("Raspberry Pi Details:\n") ; printf (" Type: %s, Revision: %s, Memory: %dMB, Maker: %s %s\n", piModelNames [model], piRevisionNames [rev], mem, piMakerNames [maker], overVolted ? "[OV]" : "") ; + +// Quick check for /dev/gpiomem + + if ((i = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) >= 0) + printf (" This Raspberry Pi supports user-level GPIO access via /dev/gpiomem.\n") ; + else + { + printf (" You need to run your programs as root for GPIO access\n") ; + printf (" (Old /dev/mem method - consider upgrading)\n") ; + } + } return 0 ; } diff --git a/gpio/newVersion b/gpio/newVersion deleted file mode 100755 index b919743..0000000 --- a/gpio/newVersion +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -e -# -# 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/gpio/version.h b/gpio/version.h index be8e84c..ac80bc5 100644 --- a/gpio/version.h +++ b/gpio/version.h @@ -1 +1 @@ -#define VERSION "2.26" +#define VERSION "2.27" diff --git a/newVersion b/newVersion new file mode 100755 index 0000000..bab6dc5 --- /dev/null +++ b/newVersion @@ -0,0 +1,43 @@ +#!/bin/sh -e +# +# newVersion: +# Utility to create the version.h include file for the gpio command. +# and the Debian package +# +# 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 . +################################################################################# + +echo Updating to version: `cat VERSION` + +rm -f gpio/version.h +echo "#define VERSION \"`cat VERSION`\"" > gpio/version.h + +rm -f debian-template/wiringPi/DEBIAN/control +cat > debian-template/wiringPi/DEBIAN/control < +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 +EOF diff --git a/wiringPi/max31855.c b/wiringPi/max31855.c index 2185839..702d7c0 100644 --- a/wiringPi/max31855.c +++ b/wiringPi/max31855.c @@ -22,39 +22,58 @@ *********************************************************************** */ +#include +#include +#include + #include #include #include "max31855.h" -/* - * myAnalogRead: - * Return the analog value of the given pin - * Note: The chip really only has one read "channel", but we're faking it - * here so we can read the error registers. Channel 0 will be the data - * channel, and 1 is the error register code. - * Note: Temperature returned is temp in C * 4, so divide result by 4 - ********************************************************************************* - */ - static int myAnalogRead (struct wiringPiNodeStruct *node, int pin) { - unsigned int spiData ; + uint32_t spiData ; int temp ; int chan = pin - node->pinBase ; wiringPiSPIDataRW (node->fd, (unsigned char *)&spiData, 4) ; - if (chan == 0) // Read temp in C + spiData = __bswap_32(spiData) ; + + switch (chan) { - spiData >>= 18 ; - temp = spiData & 0x3FFF ; // Bottom 13 bits - if ((spiData & 0x2000) != 0) // Negative - temp = -temp ; - return temp ; + case 0: // Existing read - return raw value * 4 + spiData >>= 18 ; + temp = spiData & 0x1FFF ; // Bottom 13 bits + if ((spiData & 0x2000) != 0) // Negative + temp = -temp ; + + return temp ; + + case 1: // Return error bits + return spiData & 0x7 ; + + case 2: // Return temp in C * 10 + spiData >>= 18 ; + temp = spiData & 0x1FFF ; // Bottom 13 bits + if ((spiData & 0x2000) != 0) // Negative + temp = -temp ; + + return (int)rint ((double)temp * 2.5) ; + + case 3: // Return temp in F * 10 + spiData >>= 18 ; + temp = spiData & 0x1FFF ; // Bottom 13 bits + if ((spiData & 0x2000) != 0) // Negative + temp = -temp ; + + return (int)rint ((((double)temp * 0.25 * 9.0 / 5.0) + 32.0) * 10.0) ; + + default: // Who knows... + return 0 ; + } - else // Return error bits - return spiData & 0x7 ; } @@ -72,7 +91,7 @@ int max31855Setup (const int pinBase, int spiChannel) if (wiringPiSPISetup (spiChannel, 5000000) < 0) // 5MHz - prob 4 on the Pi return -1 ; - node = wiringPiNewNode (pinBase, 2) ; + node = wiringPiNewNode (pinBase, 4) ; node->fd = spiChannel ; node->analogRead = myAnalogRead ; diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 2382112..7c899ea 100644 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -130,13 +130,16 @@ struct wiringPiNodeStruct *wiringPiNodes = NULL ; // Access from ARM Running Linux // Taken from Gert/Doms code. Some of this is not in the manual // that I can find )-: +// +// Updates in September 2015 - all now static variables (and apologies for the caps) +// due to the Pi v2 and the new /dev/gpiomem interface -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) -#define GPIO_TIMER (BCM2708_PERI_BASE + 0x0000B000) -#define GPIO_PWM (BCM2708_PERI_BASE + 0x0020C000) +static volatile unsigned int RASPBERRY_PI_PERI_BASE ; +static volatile unsigned int GPIO_PADS ; +static volatile unsigned int GPIO_CLOCK_BASE ; +static volatile unsigned int GPIO_BASE ; +static volatile unsigned int GPIO_TIMER ; +static volatile unsigned int GPIO_PWM ; #define PAGE_SIZE (4*1024) #define BLOCK_SIZE (4*1024) @@ -628,6 +631,7 @@ int wiringPiFailure (int fatal, const char *message, ...) * 0011 - Pi CM, Rev 1.2, 512MB, Sony * 0012 - Model A+ Rev 1.2, 256MB, Sony * 0014 - Pi CM, Rev 1.1, 512MB, Sony (Actual Revision might be different) + * 0015 - Model A+ Rev 1.1, 256MB, Sony * * For the Pi 2: * 0010 - Model 2, Rev 1.1, Quad Core, 1GB, Sony @@ -685,7 +689,11 @@ int piBoardRev (void) 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") ; + fprintf (stderr, " - expecting BCM2708 or BCM2709.\n") ; + fprintf (stderr, "If this is a genuine Raspberry Pi then please report this\n") ; + fprintf (stderr, "to projects@drogon.net. If this is not a Raspberry Pi then you\n") ; + fprintf (stderr, "are on your own as wiringPi is designed to support the\n") ; + fprintf (stderr, "Raspberry Pi ONLY.\n") ; exit (EXIT_FAILURE) ; } @@ -860,6 +868,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) 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 if (strcmp (c, "0014") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; } + else if (strcmp (c, "0015") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_1 ; *mem = 256 ; *maker = PI_MAKER_SONY ; } else { *model = 0 ; *rev = 0 ; *mem = 0 ; *maker = 0 ; } } } @@ -1829,9 +1838,6 @@ int wiringPiSetup (void) if (getenv (ENV_CODES) != NULL) wiringPiReturnCodes = TRUE ; - if (geteuid () != 0) - (void)wiringPiFailure (WPI_FATAL, "wiringPiSetup: Must be root. (Did you forget sudo?)\n") ; - if (wiringPiDebug) printf ("wiringPi: wiringPiSetup called\n") ; @@ -1844,43 +1850,73 @@ int wiringPiSetup (void) } else // A, B, Rev 2, B+, CM, Pi2 { - if (piModel2) - BCM2708_PERI_BASE = 0x3F000000 ; pinToGpio = pinToGpioR2 ; physToGpio = physToGpioR2 ; } -// Open the master /dev/memory device + if (piModel2) + RASPBERRY_PI_PERI_BASE = 0x3F000000 ; + else + RASPBERRY_PI_PERI_BASE = 0x20000000 ; + +// Open the master /dev/ memory control device + +// See if /dev/gpiomem exists and we can open it... + + if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) >= 0) + RASPBERRY_PI_PERI_BASE = 0 ; + +// ... otherwise fall back to the original /dev/mem which requires root level access + + else + { + +// This check is here because people are too stupid to check for themselves or read +// error messages. + + if (geteuid () != 0) + (void)wiringPiFailure (WPI_FATAL, "wiringPiSetup: Must be root. (Did you forget sudo?)\n") ; + + if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0) + return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/mem: %s\n", strerror (errno)) ; + } + +// Set the offsets into the memory interface. - if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0) - return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/mem: %s\n", strerror (errno)) ; + GPIO_PADS = RASPBERRY_PI_PERI_BASE + 0x00100000 ; + GPIO_CLOCK_BASE = RASPBERRY_PI_PERI_BASE + 0x00101000 ; + GPIO_BASE = RASPBERRY_PI_PERI_BASE + 0x00200000 ; + GPIO_TIMER = RASPBERRY_PI_PERI_BASE + 0x0000B000 ; + GPIO_PWM = RASPBERRY_PI_PERI_BASE + 0x0020C000 ; -// GPIO: +// Map the individual hardware components + +// GPIO: gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_BASE) ; if ((int32_t)gpio == -1) return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror (errno)) ; -// PWM +// PWM pwm = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PWM) ; if ((int32_t)pwm == -1) return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (PWM) failed: %s\n", strerror (errno)) ; -// Clock control (needed for PWM) +// Clock control (needed for PWM) - clk = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, CLOCK_BASE) ; + clk = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_CLOCK_BASE) ; if ((int32_t)clk == -1) return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (CLOCK) failed: %s\n", strerror (errno)) ; -// The drive pads +// The drive pads pads = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PADS) ; if ((int32_t)pads == -1) return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (PADS) failed: %s\n", strerror (errno)) ; #ifdef USE_TIMER -// The system timer +// The system timer timer = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_TIMER) ; if ((int32_t)timer == -1) From f6c40cb2a69a43de97903c9fdd6f24a4f32f8eae Mon Sep 17 00:00:00 2001 From: Gordon Henderson Date: Thu, 24 Sep 2015 22:35:31 +0100 Subject: [PATCH 18/20] Fixed the requirement for -lm Updated the gpio program to be device tree aware. --- VERSION | 2 +- debian-template/wiringPi/DEBIAN/control | 2 +- examples/Makefile | 10 +++---- examples/PiGlow/Makefile | 2 +- examples/max31855.c | 49 +++++++++++++++++++++++++++++++++ gpio/gpio.1 | 20 +++++--------- gpio/gpio.c | 38 +++++++++++++++++++------ gpio/version.h | 2 +- wiringPi/max31855.c | 7 ++--- 9 files changed, 98 insertions(+), 34 deletions(-) create mode 100644 examples/max31855.c diff --git a/VERSION b/VERSION index 7dba3a2..410158a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.27 +2.28 diff --git a/debian-template/wiringPi/DEBIAN/control b/debian-template/wiringPi/DEBIAN/control index 2a65ff5..9def8c5 100644 --- a/debian-template/wiringPi/DEBIAN/control +++ b/debian-template/wiringPi/DEBIAN/control @@ -1,5 +1,5 @@ Package: wiringpi -Version: 2.27 +Version: 2.28 Section: libraries Priority: optional Architecture: armhf diff --git a/examples/Makefile b/examples/Makefile index 60659f5..04bcaec 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -3,7 +3,7 @@ # wiringPi - Wiring Compatable library for the Raspberry Pi # https://projects.drogon.net/wiring-pi # -# Copyright (c) 2012 Gordon Henderson +# Copyright (c) 2012-2015 Gordon Henderson ################################################################################# # This file is part of wiringPi: # Wiring Compatable library for the Raspberry Pi @@ -47,7 +47,8 @@ SRC = blink.c blink8.c blink12.c \ softPwm.c softTone.c \ delayTest.c serialRead.c serialTest.c okLed.c ds1302.c \ lowPower.c \ - rht03.c piglow.c + max31855.c \ + rht03.c OBJ = $(SRC:.c=.o) @@ -148,10 +149,9 @@ ds1302: ds1302.o $Q echo [link] $Q $(CC) -o $@ ds1302.o $(LDFLAGS) $(LDLIBS) -piglow: piglow.o +max31855: max31855.o $Q echo [link] - $Q $(CC) -o $@ piglow.o $(LDFLAGS) $(LDLIBS) - + $Q $(CC) -o $@ max31855.c.o $(LDFLAGS) $(LDLIBS) .c.o: $Q echo [CC] $< diff --git a/examples/PiGlow/Makefile b/examples/PiGlow/Makefile index b7a8595..acd4818 100644 --- a/examples/PiGlow/Makefile +++ b/examples/PiGlow/Makefile @@ -3,7 +3,7 @@ # wiringPi - Wiring Compatable library for the Raspberry Pi # 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 diff --git a/examples/max31855.c b/examples/max31855.c new file mode 100644 index 0000000..2060a55 --- /dev/null +++ b/examples/max31855.c @@ -0,0 +1,49 @@ +/* + * max31855.c: + * SPI Thermocouple interface chip + * + * Copyright (c) 2015 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 + +int main (int argc, char *argv []) +{ + int i ; + + wiringPiSetup () ; + max31855Setup (200, 0) ; + max31855Setup (400, 1) ; + + for (;;) + { + printf ("%6d, %6d, %6d, %6d ::::", analogRead (200), analogRead (201), analogRead (202), analogRead (203)) ; + printf ("%6d, %6d, %6d, %6d\n", analogRead (400), analogRead (401), analogRead (402), analogRead (403)) ; + delay (500) ; + } + +} diff --git a/gpio/gpio.1 b/gpio/gpio.1 index 8949442..673ebbe 100644 --- a/gpio/gpio.1 +++ b/gpio/gpio.1 @@ -1,4 +1,4 @@ -.TH gpio 1 "January 2015" wiringPi "Command-Line access to Raspberry Pi's GPIO" +.TH GPIO 1 "September 2015" wiringPi "Command-Line access to Raspberry Pi's GPIO" .SH NAME gpio \- Command-line access to Raspberry Pi's GPIO @@ -251,12 +251,9 @@ 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. +Note: On recent kernels with the device tree enabled you should use the +raspi-config program to load/unload the I2C device at boot time. +(or disable the device tree to continue to use this method) .TP .B load spi @@ -269,12 +266,9 @@ 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. +Note: On recent kernels with the device tree enabled you should use the +raspi-config program to load/unload the SPI device at boot time. +(or disable the device tree to continue to use this method) .TP .B gbr diff --git a/gpio/gpio.c b/gpio/gpio.c index a25f454..5c87a7e 100644 --- a/gpio/gpio.c +++ b/gpio/gpio.c @@ -116,7 +116,7 @@ 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 (not an error): File not present: %s\n", cmd, file) ; + fprintf (stderr, "%s: Warning (not an error, do not report): File not present: %s\n", cmd, file) ; else fprintf (stderr, "%s: Warning (not an error): Unable to change ownership of %s: %s\n", cmd, file, strerror (errno)) ; } @@ -163,6 +163,22 @@ static int moduleLoaded (char *modName) ********************************************************************************* */ +static void checkDevTree (char *argv []) +{ + struct stat statBuf ; + + if (stat ("/proc/device-tree", &statBuf) == 0) // We're on a devtree system ... + { + fprintf (stderr, +"%s: Unable to load/unload modules as this Pi has the device tree enabled.\n" +" You need to run the raspi-config program (as root) and select the\n" +" modules (SPI or I2C) that you wish to load/unload there and reboot.\n" +" There is more information here:\n" +" https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=97314\n", argv [0]) ; + exit (1) ; + } +} + static void _doLoadUsage (char *argv []) { fprintf (stderr, "Usage: %s load [I2C baudrate in Kb/sec]\n", argv [0]) ; @@ -176,6 +192,8 @@ static void doLoad (int argc, char *argv []) char *file1, *file2 ; char args1 [32], args2 [32] ; + checkDevTree (argv) ; + if (argc < 3) _doLoadUsage (argv) ; @@ -251,6 +269,8 @@ static void doUnLoad (int argc, char *argv []) char *module1, *module2 ; char cmd [80] ; + checkDevTree (argv) ; + if (argc != 3) _doUnLoadUsage (argv) ; @@ -1138,6 +1158,8 @@ int main (int argc, char *argv []) { int i ; int model, rev, mem, maker, overVolted ; + struct stat statBuf ; + if (getenv ("WIRINGPI_DEBUG") != NULL) { @@ -1195,15 +1217,15 @@ int main (int argc, char *argv []) printf (" Type: %s, Revision: %s, Memory: %dMB, Maker: %s %s\n", piModelNames [model], piRevisionNames [rev], mem, piMakerNames [maker], overVolted ? "[OV]" : "") ; -// Quick check for /dev/gpiomem +// Check for device tree + + if (stat ("/proc/device-tree", &statBuf) == 0) // We're on a devtree system ... + printf (" Device tree is enabled.\n") ; - if ((i = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) >= 0) - printf (" This Raspberry Pi supports user-level GPIO access via /dev/gpiomem.\n") ; + if (stat ("/dev/gpiomem", &statBuf) == 0) // User level GPIO is GO + printf (" This Raspberry Pi supports user-level GPIO access.\n") ; else - { - printf (" You need to run your programs as root for GPIO access\n") ; - printf (" (Old /dev/mem method - consider upgrading)\n") ; - } + printf (" * Root or sudo required for GPIO access.\n") ; } return 0 ; diff --git a/gpio/version.h b/gpio/version.h index ac80bc5..704c10d 100644 --- a/gpio/version.h +++ b/gpio/version.h @@ -1 +1 @@ -#define VERSION "2.27" +#define VERSION "2.28" diff --git a/wiringPi/max31855.c b/wiringPi/max31855.c index 702d7c0..ea184d8 100644 --- a/wiringPi/max31855.c +++ b/wiringPi/max31855.c @@ -1,7 +1,7 @@ /* * max31855.c: * Extend wiringPi with the max31855 SPI Analog to Digital convertor - * 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/ @@ -24,7 +24,6 @@ #include #include -#include #include #include @@ -60,7 +59,7 @@ static int myAnalogRead (struct wiringPiNodeStruct *node, int pin) if ((spiData & 0x2000) != 0) // Negative temp = -temp ; - return (int)rint ((double)temp * 2.5) ; + return (int)((((double)temp * 25) + 0.5) / 10.0) ; case 3: // Return temp in F * 10 spiData >>= 18 ; @@ -68,7 +67,7 @@ static int myAnalogRead (struct wiringPiNodeStruct *node, int pin) if ((spiData & 0x2000) != 0) // Negative temp = -temp ; - return (int)rint ((((double)temp * 0.25 * 9.0 / 5.0) + 32.0) * 10.0) ; + return (int)((((((double)temp * 0.25 * 9.0 / 5.0) + 32.0) * 100.0) + 0.5) / 10.0) ; default: // Who knows... return 0 ; From d79506694d7ba1c3da865d095238289d6175057d Mon Sep 17 00:00:00 2001 From: Gordon Henderson Date: Wed, 30 Sep 2015 16:11:42 +0100 Subject: [PATCH 19/20] Fixing a few issues - makefile goofs. Also adding in the stuff for /dev/gpiomem with warnings and information in the gpio manual page (who reads that though!) --- VERSION | 2 +- debian-template/wiringPi/DEBIAN/control | 2 +- examples/Makefile | 4 +-- examples/max31855.c | 17 ++++++++++--- gpio/Makefile | 2 +- gpio/gpio.1 | 14 +++++++++- gpio/gpio.c | 3 +++ gpio/version.h | 2 +- wiringPi/wiringPi.c | 45 ++++++++++++++++++++++++++++++++- 9 files changed, 80 insertions(+), 11 deletions(-) diff --git a/VERSION b/VERSION index 410158a..072e651 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.28 +2.29 diff --git a/debian-template/wiringPi/DEBIAN/control b/debian-template/wiringPi/DEBIAN/control index 9def8c5..3b15a24 100644 --- a/debian-template/wiringPi/DEBIAN/control +++ b/debian-template/wiringPi/DEBIAN/control @@ -1,5 +1,5 @@ Package: wiringpi -Version: 2.28 +Version: 2.29 Section: libraries Priority: optional Architecture: armhf diff --git a/examples/Makefile b/examples/Makefile index 04bcaec..e6b9b71 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -45,7 +45,7 @@ SRC = blink.c blink8.c blink12.c \ lcd.c lcd-adafruit.c clock.c \ nes.c \ softPwm.c softTone.c \ - delayTest.c serialRead.c serialTest.c okLed.c ds1302.c \ + delayTest.c serialRead.c serialTestc okLed.c ds1302.c \ lowPower.c \ max31855.c \ rht03.c @@ -151,7 +151,7 @@ ds1302: ds1302.o max31855: max31855.o $Q echo [link] - $Q $(CC) -o $@ max31855.c.o $(LDFLAGS) $(LDLIBS) + $Q $(CC) -o $@ max31855.o $(LDFLAGS) $(LDLIBS) .c.o: $Q echo [CC] $< diff --git a/examples/max31855.c b/examples/max31855.c index 2060a55..36b3cf6 100644 --- a/examples/max31855.c +++ b/examples/max31855.c @@ -33,7 +33,7 @@ int main (int argc, char *argv []) { - int i ; + int i = 0 ; wiringPiSetup () ; max31855Setup (200, 0) ; @@ -41,9 +41,20 @@ int main (int argc, char *argv []) for (;;) { - printf ("%6d, %6d, %6d, %6d ::::", analogRead (200), analogRead (201), analogRead (202), analogRead (203)) ; - printf ("%6d, %6d, %6d, %6d\n", analogRead (400), analogRead (401), analogRead (402), analogRead (403)) ; + if (i == 0) + { + printf ("+------+------+------+------++------+------+------+------+\n") ; + printf ("| Raw | Err | C | F || Raw | Err | C | F |\n") ; + printf ("+------+------+------+------++------+------+------+------+\n") ; + } + + printf ("| %4d | %4d | %4d | %4d |", analogRead (200), analogRead (201), analogRead (202), analogRead (203)) ; + printf ("| %4d | %4d | %4d | %4d |\n", analogRead (400), analogRead (401), analogRead (402), analogRead (403)) ; delay (500) ; + + if (++i == 10) + i = 0 ; + } } diff --git a/gpio/Makefile b/gpio/Makefile index e998d84..7dcd090 100644 --- a/gpio/Makefile +++ b/gpio/Makefile @@ -37,7 +37,7 @@ INCLUDE = -I$(DESTDIR)$(PREFIX)/include CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe LDFLAGS = -L$(DESTDIR)$(PREFIX)/lib -LIBS = -lwiringPi -lwiringPiDev -lpthread -lm +LIBS = -lwiringPi -lwiringPiDev -lpthread # May not need to alter anything below this line ############################################################################### diff --git a/gpio/gpio.1 b/gpio/gpio.1 index 673ebbe..e5fe181 100644 --- a/gpio/gpio.1 +++ b/gpio/gpio.1 @@ -260,7 +260,7 @@ raspi-config program to load/unload the I2C device at boot time. 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. 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 +default of 4096 bytes to an arbitrary 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 @@ -321,6 +321,18 @@ When using the \fIexport\fR, \fIedge\fR or \fIunexport\fR commands, the pin numbers are \fBalways\fR native BCM_GPIO numbers and never wiringPi pin numbers. +As of kernels 4.1.7, a user-level GPIO access mechanism is available, +however wiringPi will not use this by default - because at this time +there appears to be issues when trying to program the PWM or clock output +hardware. If you can live without PWM or GPIO clocks and you want to use +the GPIO from a non-root program, then you need to make sure that the +module \fIbcm2835_gpiomem\fR is loaded at boot time. This should happen +automatically when you enable the device tree in raspi-config. You may +also need some additional information in /etc/udev/rules.d/ to change the +mode and ownership of the /dev/gpiomem file. Finally, you need to set +the environment variable \fIWIRINGPI_GPIOMEM\fR. This will go-away +in future releases once the /dev/gpiomem interface is fully operational. + .SH "SEE ALSO" .LP diff --git a/gpio/gpio.c b/gpio/gpio.c index 5c87a7e..4eef19d 100644 --- a/gpio/gpio.c +++ b/gpio/gpio.c @@ -1223,7 +1223,10 @@ int main (int argc, char *argv []) printf (" Device tree is enabled.\n") ; if (stat ("/dev/gpiomem", &statBuf) == 0) // User level GPIO is GO + { printf (" This Raspberry Pi supports user-level GPIO access.\n") ; + printf (" -> See the man-page for more details\n") ; + } else printf (" * Root or sudo required for GPIO access.\n") ; diff --git a/gpio/version.h b/gpio/version.h index 704c10d..ac09492 100644 --- a/gpio/version.h +++ b/gpio/version.h @@ -1 +1 @@ -#define VERSION "2.28" +#define VERSION "2.29" diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 7c899ea..32e5100 100644 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -84,6 +84,7 @@ #define ENV_DEBUG "WIRINGPI_DEBUG" #define ENV_CODES "WIRINGPI_CODES" +#define ENV_GPIOMEM "WIRINGPI_GPIOMEM" // Mask for the bottom 64 pins which belong to the Raspberry Pi @@ -253,6 +254,10 @@ static pthread_mutex_t pinMutex ; int wiringPiDebug = FALSE ; int wiringPiReturnCodes = FALSE ; +// Use /dev/gpiomem ? + +int wiringPiTryGpioMem = FALSE ; + // sysFds: // Map a file descriptor from the /sys/class/gpio/gpioX/value @@ -913,6 +918,9 @@ void setPadDrive (int group, int value) if ((wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO)) { + if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now + return ; + if ((group < 0) || (group > 2)) return ; @@ -986,6 +994,9 @@ void pwmSetRange (unsigned int range) { if ((wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO)) { + if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now + return ; + *(pwm + PWM0_RANGE) = range ; delayMicroseconds (10) ; *(pwm + PWM1_RANGE) = range ; delayMicroseconds (10) ; } @@ -1007,6 +1018,9 @@ void pwmSetClock (int divisor) if ((wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO)) { + if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now + return ; + if (wiringPiDebug) printf ("Setting to: %d. Current: 0x%08X\n", divisor, *(clk + PWMCLK_DIV)) ; @@ -1059,6 +1073,9 @@ void gpioClockSet (int pin, int freq) else if (wiringPiMode != WPI_MODE_GPIO) return ; + if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now + return ; + divi = 19200000 / freq ; divr = 19200000 % freq ; divf = (int)((double)divr * 4096.0 / 19200000.0) ; @@ -1231,11 +1248,17 @@ void pinMode (int pin, int mode) softToneCreate (origPin) ; else if (mode == PWM_TONE_OUTPUT) { + if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now + return ; + pinMode (origPin, PWM_OUTPUT) ; // Call myself to enable PWM mode pwmSetMode (PWM_MODE_MS) ; } else if (mode == PWM_OUTPUT) { + if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now + return ; + if ((alt = gpioToPwmALT [pin]) == 0) // Not a hardware capable PWM pin return ; @@ -1250,6 +1273,9 @@ void pinMode (int pin, int mode) } else if (mode == GPIO_CLOCK) { + if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now + return ; + if ((alt = gpioToGpClkALT0 [pin]) == 0) // Not a GPIO_CLOCK pin return ; @@ -1404,6 +1430,9 @@ void pwmWrite (int pin, int value) if ((pin & PI_GPIO_MASK) == 0) // On-Board Pin { + if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now + return ; + /**/ if (wiringPiMode == WPI_MODE_PINS) pin = pinToGpio [pin] ; else if (wiringPiMode == WPI_MODE_PHYS) @@ -1470,6 +1499,9 @@ void pwmToneWrite (int pin, int freq) { int range ; + if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now + return ; + if (freq == 0) pwmWrite (pin, 0) ; // Off else @@ -1838,8 +1870,15 @@ int wiringPiSetup (void) if (getenv (ENV_CODES) != NULL) wiringPiReturnCodes = TRUE ; + if (getenv (ENV_GPIOMEM) != NULL) + wiringPiTryGpioMem = TRUE ; + if (wiringPiDebug) + { printf ("wiringPi: wiringPiSetup called\n") ; + if (wiringPiTryGpioMem) + printf ("wiringPi: Using /dev/gpiomem\n") ; + } boardRev = piBoardRev () ; @@ -1863,8 +1902,12 @@ int wiringPiSetup (void) // See if /dev/gpiomem exists and we can open it... - if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) >= 0) + if (wiringPiTryGpioMem) + { + if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0) + return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/gpiomem: %s\n", strerror (errno)) ; RASPBERRY_PI_PERI_BASE = 0 ; + } // ... otherwise fall back to the original /dev/mem which requires root level access From bb6f08487cc8025c8e7d0260cfb493f2a07452a5 Mon Sep 17 00:00:00 2001 From: Gordon Henderson Date: Sun, 29 Nov 2015 21:08:04 +0000 Subject: [PATCH 20/20] Updated wiringPi for the new Pi Zero. Also affects the Pi v2 which also uses the new Revision encoding scheme (It was slightly bodged before) This ought to be relatively future proof, but who knows. Fixed a minor thing in the examples Makefile (not that anyone bothers to use it, judging by the emails I get )-: --- VERSION | 2 +- debian-template/wiringPi/DEBIAN/control | 2 +- examples/Makefile | 2 +- gpio/gpio.c | 99 +++++----- gpio/version.h | 2 +- wiringPi/wiringPi.c | 317 +++++++++++++++++++++----------- wiringPi/wiringPi.h | 38 ++-- 7 files changed, 289 insertions(+), 173 deletions(-) diff --git a/VERSION b/VERSION index 072e651..81b133a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.29 +2.30 diff --git a/debian-template/wiringPi/DEBIAN/control b/debian-template/wiringPi/DEBIAN/control index 3b15a24..7b739c6 100644 --- a/debian-template/wiringPi/DEBIAN/control +++ b/debian-template/wiringPi/DEBIAN/control @@ -1,5 +1,5 @@ Package: wiringpi -Version: 2.29 +Version: 2.30 Section: libraries Priority: optional Architecture: armhf diff --git a/examples/Makefile b/examples/Makefile index e6b9b71..4278b6d 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -45,7 +45,7 @@ SRC = blink.c blink8.c blink12.c \ lcd.c lcd-adafruit.c clock.c \ nes.c \ softPwm.c softTone.c \ - delayTest.c serialRead.c serialTestc okLed.c ds1302.c \ + delayTest.c serialRead.c serialTest.c okLed.c ds1302.c \ lowPower.c \ max31855.c \ rht03.c diff --git a/gpio/gpio.c b/gpio/gpio.c index 4eef19d..6c95b21 100644 --- a/gpio/gpio.c +++ b/gpio/gpio.c @@ -1149,6 +1149,56 @@ static void doPwmClock (int argc, char *argv []) /* + * doVersion: + * Handle the ever more complicated version command + ********************************************************************************* + */ + +static void doVersion (char *argv []) +{ + int model, rev, mem, maker, warranty ; + struct stat statBuf ; + + printf ("gpio version: %s\n", VERSION) ; + 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") ; + piBoardId (&model, &rev, &mem, &maker, &warranty) ; + +/************* + if (model == PI_MODEL_UNKNOWN) + { + printf ("Your Raspberry Pi has an unknown model type. Please report this to\n") ; + printf (" projects@drogon.net\n") ; + printf ("with a copy of your /proc/cpuinfo if possible\n") ; + } + else +***************/ + + { + printf ("Raspberry Pi Details:\n") ; + printf (" Type: %s, Revision: %s, Memory: %dMB, Maker: %s %s\n", + piModelNames [model], piRevisionNames [rev], piMemorySize [mem], piMakerNames [maker], warranty ? "[Out of Warranty]" : "") ; + +// Check for device tree + + if (stat ("/proc/device-tree", &statBuf) == 0) // We're on a devtree system ... + printf (" Device tree is enabled.\n") ; + + if (stat ("/dev/gpiomem", &statBuf) == 0) // User level GPIO is GO + { + printf (" This Raspberry Pi supports user-level GPIO access.\n") ; + printf (" -> See the man-page for more details\n") ; + } + else + printf (" * Root or sudo required for GPIO access.\n") ; + + } +} + + +/* * main: * Start here ********************************************************************************* @@ -1157,9 +1207,6 @@ static void doPwmClock (int argc, char *argv []) int main (int argc, char *argv []) { int i ; - int model, rev, mem, maker, overVolted ; - struct stat statBuf ; - if (getenv ("WIRINGPI_DEBUG") != NULL) { @@ -1181,56 +1228,20 @@ int main (int argc, char *argv []) return 0 ; } -// Sort of a special: - - if (strcmp (argv [1], "-R") == 0) - { - printf ("%d\n", piBoardRev ()) ; - return 0 ; - } - // Version & Warranty +// Wish I could remember why I have both -R and -V ... - if (strcmp (argv [1], "-V") == 0) + if ((strcmp (argv [1], "-R") == 0) || (strcmp (argv [1], "-V") == 0)) { printf ("%d\n", piBoardRev ()) ; return 0 ; } +// Version and information + if (strcmp (argv [1], "-v") == 0) { - printf ("gpio version: %s\n", VERSION) ; - 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") ; - piBoardId (&model, &rev, &mem, &maker, &overVolted) ; - if (model == PI_MODEL_UNKNOWN) - { - printf ("Your Raspberry Pi has an unknown model type. Please report this to\n") ; - printf (" projects@drogon.net\n") ; - printf ("with a copy of your /proc/cpuinfo if possible\n") ; - } - else - { - printf ("Raspberry Pi Details:\n") ; - printf (" Type: %s, Revision: %s, Memory: %dMB, Maker: %s %s\n", - piModelNames [model], piRevisionNames [rev], mem, piMakerNames [maker], overVolted ? "[OV]" : "") ; - -// Check for device tree - - if (stat ("/proc/device-tree", &statBuf) == 0) // We're on a devtree system ... - printf (" Device tree is enabled.\n") ; - - if (stat ("/dev/gpiomem", &statBuf) == 0) // User level GPIO is GO - { - printf (" This Raspberry Pi supports user-level GPIO access.\n") ; - printf (" -> See the man-page for more details\n") ; - } - else - printf (" * Root or sudo required for GPIO access.\n") ; - - } + doVersion (argv) ; return 0 ; } diff --git a/gpio/version.h b/gpio/version.h index ac09492..a46348a 100644 --- a/gpio/version.h +++ b/gpio/version.h @@ -1 +1 @@ -#define VERSION "2.29" +#define VERSION "2.30" diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 32e5100..503151f 100644 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -209,35 +209,77 @@ static volatile uint32_t *timerIrqRaw ; static int piModel2 = FALSE ; -const char *piModelNames [7] = +const char *piModelNames [16] = { - "Unknown", - "Model A", - "Model B", - "Model B+", - "Compute Module", - "Model A+", - "Model 2", // Quad Core + "Model A", // 0 + "Model B", // 1 + "Model A+", // 2 + "Model B+", // 3 + "Pi 2", // 4 + "Alpha", // 5 + "CM", // 6 + "Unknown07", // 07 + "Unknown08", // 08 + "Pi Zero", // 09 + "Unknown10", // 10 + "Unknown11", // 11 + "Unknown12", // 12 + "Unknown13", // 13 + "Unknown14", // 14 + "Unknown15", // 15 } ; -const char *piRevisionNames [5] = +const char *piRevisionNames [16] = { - "Unknown", - "1", - "1.1", - "1.2", - "2", + "00", + "01", + "02", + "03", + "04", + "05", + "06", + "07", + "08", + "09", + "10", + "11", + "12", + "13", + "14", + "15", } ; -const char *piMakerNames [5] = +const char *piMakerNames [16] = { - "Unknown", - "Egoman", - "Sony", - "Qusda", - "MBest", + "Sony", // 0 + "Egoman", // 1 + "Embest", // 2 + "Unknown", // 3 + "Embest", // 4 + "Unknown05", // 5 + "Unknown06", // 6 + "Unknown07", // 7 + "Unknown08", // 8 + "Unknown09", // 9 + "Unknown10", // 10 + "Unknown11", // 11 + "Unknown12", // 12 + "Unknown13", // 13 + "Unknown14", // 14 + "Unknown15", // 15 } ; +const int piMemorySize [8] = +{ + 256, // 0 + 512, // 1 + 1024, // 2 + 0, // 3 + 0, // 4 + 0, // 5 + 0, // 6 + 0, // 7 +} ; // Time for easy calculations @@ -612,43 +654,20 @@ int wiringPiFailure (int fatal, const char *message, ...) /* * piBoardRev: * Return a number representing the hardware revision of the board. + * This is not strictly the board revision but is used to check the + * layout of the GPIO connector - and there are 2 types that we are + * really interested in here. The very earliest Pi's and the + * ones that came after that which switched some pins .... * - * Revision 1 really means the early Model B's. + * Revision 1 really means the early Model A and B's. * Revision 2 is everything else - it covers the B, B+ and CM. * ... and the Pi 2 - which is a B+ ++ ... + * ... and the Pi 0 - which is an A+ ... * - * Seems there are some boards with 0000 in them (mistake in manufacture) - * So the distinction between boards that I can see is: - * 0000 - Error - * 0001 - Not used - * 0002 - Model B, Rev 1, 256MB, Egoman - * 0003 - Model B, Rev 1.1, 256MB, Egoman, Fuses/D14 removed. - * 0004 - Model B, Rev 2, 256MB, Sony - * 0005 - Model B, Rev 2, 256MB, Qisda - * 0006 - Model B, Rev 2, 256MB, Egoman - * 0007 - Model A, Rev 2, 256MB, Egoman - * 0008 - Model A, Rev 2, 256MB, Sony - * 0009 - Model A, Rev 2, 256MB, Qisda - * 000d - Model B, Rev 2, 512MB, Egoman - * 000e - Model B, Rev 2, 512MB, Sony - * 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 - * 0014 - Pi CM, Rev 1.1, 512MB, Sony (Actual Revision might be different) - * 0015 - Model A+ Rev 1.1, 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 - * - * The Pi compute module has an revision of 0011 - since we only check the - * last digit, then it's 1, therefore it'll default to not 2 or 3 for a - * Rev 1, so will appear as a Rev 2. This is fine for the most part, but - * we'll properly detect the Compute Module later and adjust accordingly. - * And the next rev of the CN is 0014 ... + * The main difference between the revision 1 and 2 system that I use here + * is the mapping of the GPIO pins. From revision 2, the Pi Foundation changed + * 3 GPIO pins on the (original) 26-way header - BCM_GPIO 22 was dropped and + * replaced with 27, and 0 + 1 - I2C bus 0 was changed to 2 + 3; I2C bus 1. * ********************************************************************************* */ @@ -675,22 +694,28 @@ 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.... +// Start by looking for the Architecture to make sure we're really running +// on a Pi. I'm getting fed-up with people whinging at me because +// they can't get it to work on weirdFruitPi boards... while (fgets (line, 120, cpuFd) != NULL) if (strncmp (line, "Hardware", 8) == 0) break ; if (strncmp (line, "Hardware", 8) != 0) - piBoardRevOops ("No \"Hardware\" line") ; + piBoardRevOops ("No hardware line") ; if (wiringPiDebug) printf ("piboardRev: Hardware: %s\n", line) ; // See if it's BCM2708 or BCM2709 - if (strstr (line, "BCM2709") != NULL) + if (strstr (line, "BCM2709") != NULL) // Pi v2 - no point doing anything more at this point + { piModel2 = TRUE ; + fclose (cpuFd) ; + return boardRev = 2 ; + } else if (strstr (line, "BCM2708") == NULL) { fprintf (stderr, "Unable to determine hardware version. I see: %s,\n", line) ; @@ -702,10 +727,12 @@ int piBoardRev (void) exit (EXIT_FAILURE) ; } -// Now do the rest of it as before +// Now do the rest of it as before - we just need to see if it's an older +// Rev 1 as anything else is rev 2. - rewind (cpuFd) ; +// Isolate the Revision line + rewind (cpuFd) ; while (fgets (line, 120, cpuFd) != NULL) if (strncmp (line, "Revision", 8) == 0) break ; @@ -723,28 +750,43 @@ int piBoardRev (void) if (wiringPiDebug) printf ("piboardRev: Revision string: %s\n", line) ; -// Scan to first digit +// Scan to the first character of the revision number for (c = line ; *c ; ++c) - if (isdigit (*c)) + if (*c == ':') break ; - if (!isdigit (*c)) - piBoardRevOops ("No numeric revision string") ; + if (*c != ':') + piBoardRevOops ("Bogus \"Revision\" line (no colon)") ; + +// Chomp spaces + + ++c ; + while (isspace (*c)) + ++c ; + + if (!isxdigit (*c)) + piBoardRevOops ("Bogus \"Revision\" line (no hex digit at start of revision)") ; // Make sure its long enough if (strlen (c) < 4) - piBoardRevOops ("Bogus \"Revision\" line (too small)") ; - + piBoardRevOops ("Bogus revision line (too small)") ; + // 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 + +// This test is not correct for the new encoding scheme, so we'll remove it here as +// we don't really need it at this point. + +/******************** if (wiringPiDebug) if (strlen (c) != 4) printf ("piboardRev: This Pi has/is (force_turbo || current_limit_override || temp_limit>85) && over_voltage>0\n") ; +*******************/ // Isolate last 4 characters: @@ -767,12 +809,49 @@ int piBoardRev (void) /* * piBoardId: - * Do more digging into the board revision string as above, but return - * as much details as we can. + * Return the real details of the board we have. + * * This is undocumented and really only intended for the GPIO command. * Use at your own risk! * - * for Pi v2: + * Seems there are some boards with 0000 in them (mistake in manufacture) + * So the distinction between boards that I can see is: + * + * 0000 - Error + * 0001 - Not used + * + * Original Pi boards: + * 0002 - Model B, Rev 1, 256MB, Egoman + * 0003 - Model B, Rev 1.1, 256MB, Egoman, Fuses/D14 removed. + * + * Newer Pi's with remapped GPIO: + * 0004 - Model B, Rev 2, 256MB, Sony + * 0005 - Model B, Rev 2, 256MB, Qisda + * 0006 - Model B, Rev 2, 256MB, Egoman + * 0007 - Model A, Rev 2, 256MB, Egoman + * 0008 - Model A, Rev 2, 256MB, Sony + * 0009 - Model A, Rev 2, 256MB, Qisda + * 000d - Model B, Rev 2, 512MB, Egoman (Red Pi, Blue Pi?) + * 000e - Model B, Rev 2, 512MB, Sony + * 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 + * 0014 - Pi CM, Rev 1.1, 512MB, Sony (Actual Revision might be different) + * 0015 - Model A+ Rev 1.1, 256MB, Sony + * + * A small thorn is the olde style overvolting - that will add in + * 1000000 + * + * The Pi compute module has an revision of 0011 or 0014 - since we only + * check the last digit, then it's 1, therefore it'll default to not 2 or + * 3 for a Rev 1, so will appear as a Rev 2. This is fine for the most part, but + * we'll properly detect the Compute Module later and adjust accordingly. + * + * And then things changed with the introduction of the v2... + * + * For Pi v2 and subsequent models - e.g. the Zero: + * * [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 @@ -783,11 +862,13 @@ int piBoardRev (void) ********************************************************************************* */ -void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) +void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty) { FILE *cpuFd ; char line [120] ; char *c ; + unsigned int revision ; + int bRev, bType, bProc, bMfg, bMem, bWarranty ; // Will deal with the properly later on - for now, lets just get it going... // unsigned int modelNum ; @@ -814,33 +895,59 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) if (wiringPiDebug) printf ("piboardId: Revision string: %s\n", line) ; - if (piModel2) - { +// Need to work out if it's using the new or old encoding scheme: -// Scan to the colon +// Scan to the first character of the revision number - for (c = line ; *c ; ++c) - if (*c == ':') - break ; + for (c = line ; *c ; ++c) + if (*c == ':') + break ; - if (*c != ':') - piBoardRevOops ("Bogus \"Revision\" line (no colon)") ; + if (*c != ':') + piBoardRevOops ("Bogus \"Revision\" line (no colon)") ; -// modelNum = (unsigned int)strtol (++c, NULL, 16) ; // Hex number with no leading 0x +// Chomp spaces + + ++c ; + while (isspace (*c)) + ++c ; + + if (!isxdigit (*c)) + piBoardRevOops ("Bogus \"Revision\" line (no hex digit at start of revision)") ; + + revision = (unsigned int)strtol (c, NULL, 16) ; // Hex number with no leading 0x + +// Check for new way: + + if ((revision & (1 << 23)) != 0) // New way + { + if (wiringPiDebug) + printf ("piBoardId: New Way: revision is: 0x%08X\n", revision) ; + + bRev = (revision & (0x0F << 0)) >> 0 ; + bType = (revision & (0xFF << 4)) >> 4 ; + bProc = (revision & (0x0F << 12)) >> 12 ; // Not used for now. + bMfg = (revision & (0x0F << 16)) >> 16 ; + bMem = (revision & (0x07 << 20)) >> 20 ; + bWarranty = (revision & (0x03 << 24)) != 0 ; - *model = PI_MODEL_2 ; - *rev = PI_VERSION_1_1 ; - *mem = 1024 ; - *maker = PI_MAKER_SONY ; + *model = bType ; + *rev = bRev ; + *mem = bMem ; + *maker = bMfg ; + *warranty = bWarranty ; + + if (wiringPiDebug) + printf ("piboardId: rev: %d, type: %d, proc: %d, mfg: %d, mem: %d, warranty: %d\n", + bRev, bType, bProc, bMfg, bMem, bWarranty) ; } - else + else // Old way { + if (wiringPiDebug) + printf ("piBoardId: Old Way: revision is: %s\n", c) ; -// Scan to first digit - - for (c = line ; *c ; ++c) - if (isdigit (*c)) - break ; + if (!isdigit (*c)) + piBoardRevOops ("Bogus \"Revision\" line (no digit at start of revision)") ; // Make sure its long enough @@ -849,7 +956,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) // If longer than 4, we'll assume it's been overvolted - *overVolted = strlen (c) > 4 ; + *warranty = strlen (c) > 4 ; // Extract last 4 characters: @@ -857,23 +964,23 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) // 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 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 if (strcmp (c, "0014") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; } - else if (strcmp (c, "0015") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_1 ; *mem = 256 ; *maker = PI_MAKER_SONY ; } + /**/ if (strcmp (c, "0002") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; } + else if (strcmp (c, "0003") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_1 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; } + else if (strcmp (c, "0004") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 0 ; *maker = PI_MAKER_SONY ; } + else if (strcmp (c, "0005") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 0 ; *maker = PI_MAKER_UNKNOWN ; } + else if (strcmp (c, "0006") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; } + else if (strcmp (c, "0007") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; } + else if (strcmp (c, "0008") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem = 0 ; *maker = PI_MAKER_SONY ; ; } + else if (strcmp (c, "0009") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 0 ; *maker = PI_MAKER_UNKNOWN ; } + else if (strcmp (c, "000d") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 1 ; *maker = PI_MAKER_EGOMAN ; } + else if (strcmp (c, "000e") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 1 ; *maker = PI_MAKER_SONY ; } + else if (strcmp (c, "000f") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 1 ; *maker = PI_MAKER_EGOMAN ; } + else if (strcmp (c, "0010") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_SONY ; } + else if (strcmp (c, "0011") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_SONY ; } + else if (strcmp (c, "0012") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_2 ; *mem = 0 ; *maker = PI_MAKER_SONY ; } + else if (strcmp (c, "0013") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_EGOMAN ; } + else if (strcmp (c, "0014") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_SONY ; } + else if (strcmp (c, "0015") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_1 ; *mem = 0 ; *maker = PI_MAKER_SONY ; } else { *model = 0 ; *rev = 0 ; *mem = 0 ; *maker = 0 ; } } } diff --git a/wiringPi/wiringPi.h b/wiringPi/wiringPi.h index dd110fa..e09d06a 100644 --- a/wiringPi/wiringPi.h +++ b/wiringPi/wiringPi.h @@ -26,8 +26,7 @@ // Handy defines -// Deprecated -#define NUM_PINS 17 +// wiringPi modes #define WPI_MODE_PINS 0 #define WPI_MODE_GPIO 1 @@ -70,29 +69,28 @@ // Pi model types and version numbers // Intended for the GPIO program Use at your own risk. -#define PI_MODEL_UNKNOWN 0 -#define PI_MODEL_A 1 -#define PI_MODEL_B 2 +#define PI_MODEL_A 0 +#define PI_MODEL_B 1 +#define PI_MODEL_AP 2 #define PI_MODEL_BP 3 -#define PI_MODEL_CM 4 -#define PI_MODEL_AP 5 -#define PI_MODEL_2 6 +#define PI_MODEL_2 4 +#define PI_ALPHA 5 +#define PI_MODEL_CM 6 -#define PI_VERSION_UNKNOWN 0 -#define PI_VERSION_1 1 -#define PI_VERSION_1_1 2 -#define PI_VERSION_1_2 3 -#define PI_VERSION_2 4 +#define PI_VERSION_1 0 +#define PI_VERSION_1_1 1 +#define PI_VERSION_1_2 2 +#define PI_VERSION_2 3 -#define PI_MAKER_UNKNOWN 0 +#define PI_MAKER_SONY 0 #define PI_MAKER_EGOMAN 1 -#define PI_MAKER_SONY 2 -#define PI_MAKER_QISDA 3 -#define PI_MAKER_MBEST 4 +#define PI_MAKER_MBEST 2 +#define PI_MAKER_UNKNOWN 3 -extern const char *piModelNames [7] ; -extern const char *piRevisionNames [5] ; -extern const char *piMakerNames [5] ; +extern const char *piModelNames [16] ; +extern const char *piRevisionNames [16] ; +extern const char *piMakerNames [16] ; +extern const int piMemorySize [ 8] ; // Intended for the GPIO program Use at your own risk.