Browse Source

Merge commit 'bb6f084'

pull/47/head^2
sndnvaps 9 years ago
parent
commit
4dbd1f8749
37 changed files with 969 additions and 466 deletions
  1. +7
    -0
      .gitignore
  2. +1
    -1
      VERSION
  3. +17
    -15
      build
  4. +1
    -1
      debian-template/wiringPi/DEBIAN/control
  5. +0
    -0
      debian-template/wiringPi/DEBIAN/postinst
  6. +0
    -0
      debian-template/wiringPi/DEBIAN/postrm
  7. +9
    -0
      debian/.gitignore
  8. +6
    -0
      debian/changelog
  9. +1
    -0
      debian/compat
  10. +29
    -0
      debian/control
  11. +15
    -0
      debian/copyright
  12. +2
    -0
      debian/libwiringpi-dev.dirs
  13. +3
    -0
      debian/libwiringpi-dev.install
  14. +1
    -0
      debian/libwiringpi2.install
  15. +2
    -0
      debian/libwiringpi2.shlibs
  16. +49
    -0
      debian/rules
  17. +1
    -0
      debian/wiringpi.dirs
  18. +4
    -0
      debian/wiringpi.install
  19. +44
    -38
      devLib/Makefile
  20. +24
    -20
      examples/Gertboard/Makefile
  21. +62
    -59
      examples/Makefile
  22. +21
    -18
      examples/PiFace/Makefile
  23. +20
    -17
      examples/PiGlow/Makefile
  24. +1
    -1
      examples/blink.sh
  25. +60
    -0
      examples/max31855.c
  26. +19
    -16
      examples/q2w/Makefile
  27. +1
    -1
      examples/q2w/blink.sh
  28. +33
    -25
      gpio/Makefile
  29. +20
    -14
      gpio/gpio.1
  30. +76
    -29
      gpio/gpio.c
  31. +1
    -1
      gpio/version.h
  32. +20
    -3
      newVersion
  33. +9
    -5
      pins/Makefile
  34. +44
    -38
      wiringPi/Makefile
  35. +39
    -21
      wiringPi/max31855.c
  36. +309
    -123
      wiringPi/wiringPi.c
  37. +18
    -20
      wiringPi/wiringPi.h

+ 7
- 0
.gitignore View File

@@ -0,0 +1,7 @@
*.o
*.so
lib*.so.*
*~
debian-template/wiringPi
debian-template/wiringpi-*.deb
gpio/gpio

+ 1
- 1
VERSION View File

@@ -1 +1 @@
2.25
2.30

+ 17
- 15
build View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/sh -e

# build
# Simple wiringPi build and install script
@@ -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

@@ -77,15 +79,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
make install-deb INCLUDE='-I. -I../wiringPi'
cd $here/gpio
make install-deb
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
@@ -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


debian/wiringPi/DEBIAN/control → debian-template/wiringPi/DEBIAN/control View File

@@ -1,5 +1,5 @@
Package: wiringpi
Version: 2.24
Version: 2.30
Section: libraries
Priority: optional
Architecture: armhf

debian/wiringPi/DEBIAN/postinst → debian-template/wiringPi/DEBIAN/postinst View File


debian/wiringPi/DEBIAN/postrm → debian-template/wiringPi/DEBIAN/postrm View File


+ 9
- 0
debian/.gitignore View File

@@ -0,0 +1,9 @@
*.debhelper.log
*.substvars
tmp
wiringpi
libwiringpi2
libwiringpi-dev
files
*.postinst.debhelper
*.postrm.debhelper

+ 6
- 0
debian/changelog View File

@@ -0,0 +1,6 @@
wiringpi (2.26~iwj) rpi-unstable; urgency=low

* Initial version with real Debian source package build.

-- Ian Jackson <ijackson@chiark.greenend.org.uk> Sat, 12 Sep 2015 18:31:35 +0100


+ 1
- 0
debian/compat View File

@@ -0,0 +1 @@
8

+ 29
- 0
debian/control View File

@@ -0,0 +1,29 @@
Source: wiringpi
Section: electronics
Priority: optional
Maintainer: Ian Jackson <ijackson@chiark.greenend.org.uk>
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.

+ 15
- 0
debian/copyright View File

@@ -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'.

+ 2
- 0
debian/libwiringpi-dev.dirs View File

@@ -0,0 +1,2 @@
usr/lib
usr/include

+ 3
- 0
debian/libwiringpi-dev.install View File

@@ -0,0 +1,3 @@
debian/tmp/usr/include
debian/tmp/usr/lib/*.so
examples usr/share/doc/libwiringpi-dev

+ 1
- 0
debian/libwiringpi2.install View File

@@ -0,0 +1 @@
debian/tmp/usr/lib/lib*.so.*

+ 2
- 0
debian/libwiringpi2.shlibs View File

@@ -0,0 +1,2 @@
libwiringPi 2 libwiringpi2
libwiringPiDev 2 libwiringpi2

+ 49
- 0
debian/rules View File

@@ -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 $@

+ 1
- 0
debian/wiringpi.dirs View File

@@ -0,0 +1 @@
usr/bin

+ 4
- 0
debian/wiringpi.install View File

@@ -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

+ 44
- 38
devLib/Makefile View File

@@ -22,8 +22,14 @@
#################################################################################

VERSION=$(shell cat ../VERSION)
DESTDIR=/usr
PREFIX=/local
DESTDIR?=/usr
PREFIX?=/local

LDCONFIG?=ldconfig

ifneq ($V,1)
Q ?= @
endif

STATIC=libwiringPiDev.a
DYNAMIC=libwiringPiDev.so.$(VERSION)
@@ -53,66 +59,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$(WIRINGPI_SONAME_SUFFIX) -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]"
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
$Q echo "[Install Headers: deb]"
$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-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:
@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


+ 24
- 20
examples/Gertboard/Makefile View File

@@ -5,6 +5,10 @@
# Copyright (c) 2013 Gordon Henderson
#################################################################################

ifneq ($V,1)
Q ?= @
endif

#DEBUG = -g -O0
DEBUG = -O3
CC = gcc
@@ -29,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)


+ 62
- 59
examples/Makefile View File

@@ -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
@@ -22,6 +22,9 @@
# along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
#################################################################################

ifneq ($V,1)
Q ?= @
endif

#DEBUG = -g -O0
DEBUG = -O3
@@ -44,123 +47,123 @@ 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)

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)

piglow: piglow.o
@echo [link]
@$(CC) -o $@ piglow.o $(LDFLAGS) $(LDLIBS)
$Q echo [link]
$Q $(CC) -o $@ ds1302.o $(LDFLAGS) $(LDLIBS)

max31855: max31855.o
$Q echo [link]
$Q $(CC) -o $@ max31855.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)


+ 21
- 18
examples/PiFace/Makefile View File

@@ -22,6 +22,9 @@
# along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
#################################################################################

ifneq ($V,1)
Q ?= @
endif

#DEBUG = -g -O0
DEBUG = -O3
@@ -44,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)


+ 20
- 17
examples/PiGlow/Makefile View File

@@ -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
@@ -22,6 +22,9 @@
# along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
#################################################################################

ifneq ($V,1)
Q ?= @
endif

#DEBUG = -g -O0
DEBUG = -O3
@@ -44,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)


+ 1
- 1
examples/blink.sh View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/sh -e
#
# blink.sh:
# Standard "blink" program in wiringPi. Blinks an LED connected


+ 60
- 0
examples/max31855.c View File

@@ -0,0 +1,60 @@
/*
* 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 <http://www.gnu.org/licenses/>.
***********************************************************************
*/

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <time.h>

#include <wiringPi.h>
#include <max31855.h>

int main (int argc, char *argv [])
{
int i = 0 ;

wiringPiSetup () ;
max31855Setup (200, 0) ;
max31855Setup (400, 1) ;

for (;;)
{
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 ;

}

}

+ 19
- 16
examples/q2w/Makefile View File

@@ -22,6 +22,9 @@
# along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
#################################################################################

ifneq ($V,1)
Q ?= @
endif

#DEBUG = -g -O0
DEBUG = -O3
@@ -43,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)


+ 1
- 1
examples/q2w/blink.sh View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/sh -e
#
# blink.sh:
# Standard "blink" program in wiringPi. Blinks an LED connected


+ 33
- 25
gpio/Makefile View File

@@ -23,8 +23,12 @@
# along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
#################################################################################

DESTDIR=/usr
PREFIX=/local
DESTDIR?=/usr
PREFIX?=/local

ifneq ($V,1)
Q ?= @
endif

#DEBUG = -g -O0
DEBUG = -O2
@@ -33,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
###############################################################################
@@ -45,49 +49,53 @@ OBJ = $(SRC:.c=.o)
all: gpio

version.h: ../VERSION
./newVersion
$Q echo Need to run newVersion above.

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
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

.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-template/wiringPi/usr/bin
$Q install -m 0755 gpio ~/wiringPi/debian-template/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:
makedepend -Y $(SRC)

# DO NOT DELETE

gpio.o: version.h

+ 20
- 14
gpio/gpio.1 View File

@@ -1,4 +1,4 @@
.TH "GPIO" "January 2015" "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,30 +251,24 @@ 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
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
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
@@ -327,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


+ 76
- 29
gpio/gpio.c View File

@@ -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 <spi/i2c> [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) ;

@@ -1129,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
*********************************************************************************
@@ -1137,7 +1207,6 @@ static void doPwmClock (int argc, char *argv [])
int main (int argc, char *argv [])
{
int i ;
int model, rev, mem, maker, overVolted ;

if (getenv ("WIRINGPI_DEBUG") != NULL)
{
@@ -1159,42 +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]" : "") ;
}
doVersion (argv) ;
return 0 ;
}



+ 1
- 1
gpio/version.h View File

@@ -1 +1 @@
#define VERSION "2.26"
#define VERSION "2.30"

gpio/newVersion → newVersion View File

@@ -1,7 +1,8 @@
#!/bin/sh
#!/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
#################################################################################
@@ -22,5 +23,21 @@
# along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
#################################################################################

rm -f version.h
echo "#define VERSION \"`cat ../VERSION`\"" > version.h
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 <<EOF
Package: wiringpi
Version: `cat VERSION`
Section: libraries
Priority: optional
Architecture: armhf
Depends: libc6
Maintainer: Gordon Henderson <projects@drogon.net>
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

+ 9
- 5
pins/Makefile View File

@@ -1,18 +1,22 @@

SRC = pins.tex

ifneq ($V,1)
Q ?= @
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 *~

+ 44
- 38
wiringPi/Makefile View File

@@ -22,8 +22,14 @@
#################################################################################

VERSION=$(shell cat ../VERSION)
DESTDIR=/usr
PREFIX=/local
DESTDIR?=/usr
PREFIX?=/local

LDCONFIG?=ldconfig

ifneq ($V,1)
Q ?= @
endif

STATIC=libwiringPi.a
DYNAMIC=libwiringPi.so.$(VERSION)
@@ -76,67 +82,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$(WIRINGPI_SONAME_SUFFIX) -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]"
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
$Q echo "[Install Headers: deb]"
$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-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:
@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


+ 39
- 21
wiringPi/max31855.c View File

@@ -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/
@@ -22,39 +22,57 @@
***********************************************************************
*/

#include <byteswap.h>
#include <stdint.h>

#include <wiringPi.h>
#include <wiringPiSPI.h>

#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)((((double)temp * 25) + 0.5) / 10.0) ;

case 3: // Return temp in F * 10
spiData >>= 18 ;
temp = spiData & 0x1FFF ; // Bottom 13 bits
if ((spiData & 0x2000) != 0) // Negative
temp = -temp ;

return (int)((((((double)temp * 0.25 * 9.0 / 5.0) + 32.0) * 100.0) + 0.5) / 10.0) ;

default: // Who knows...
return 0 ;

}
else // Return error bits
return spiData & 0x7 ;
}


@@ -72,7 +90,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 ;


+ 309
- 123
wiringPi/wiringPi.c View File

@@ -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
@@ -130,13 +131,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)
@@ -205,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

@@ -250,6 +296,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

@@ -604,42 +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)
*
* 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.
*
*********************************************************************************
*/
@@ -666,33 +694,45 @@ 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) ;
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) ;
}

// 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 ;
@@ -710,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:

@@ -754,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
@@ -770,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 ;
@@ -801,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 first character of the revision number

for (c = line ; *c ; ++c)
if (*c == ':')
break ;

if (*c != ':')
piBoardRevOops ("Bogus \"Revision\" line (no colon)") ;

// Chomp spaces

// Scan to the colon
++c ;
while (isspace (*c))
++c ;

for (c = line ; *c ; ++c)
if (*c == ':')
break ;
if (!isxdigit (*c))
piBoardRevOops ("Bogus \"Revision\" line (no hex digit at start of revision)") ;

if (*c != ':')
piBoardRevOops ("Bogus \"Revision\" line (no colon)") ;
revision = (unsigned int)strtol (c, NULL, 16) ; // Hex number with no leading 0x

// modelNum = (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

@@ -836,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:

@@ -844,22 +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 ; }
/**/ 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 ; }
}
}
@@ -904,6 +1025,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 ;

@@ -977,6 +1101,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) ;
}
@@ -998,6 +1125,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)) ;

@@ -1050,6 +1180,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) ;
@@ -1222,11 +1355,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 ;

@@ -1241,6 +1380,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 ;

@@ -1395,6 +1537,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)
@@ -1461,6 +1606,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
@@ -1829,11 +1977,15 @@ 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 (getenv (ENV_GPIOMEM) != NULL)
wiringPiTryGpioMem = TRUE ;

if (wiringPiDebug)
{
printf ("wiringPi: wiringPiSetup called\n") ;
if (wiringPiTryGpioMem)
printf ("wiringPi: Using /dev/gpiomem\n") ;
}

boardRev = piBoardRev () ;

@@ -1844,43 +1996,77 @@ 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/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/mem: %s\n", strerror (errno)) ;
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 ;
}

// GPIO:
// ... 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.

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 ;

// 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)


+ 18
- 20
wiringPi/wiringPi.h View File

@@ -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.


Loading…
Cancel
Save