mirror of
https://github.com/clockworkpi/WiringPi.git
synced 2025-12-12 16:08:49 +01:00
More changes to help reflect usage on Rev 2 / 512MB Raspberry Pi's.
Also Makefile tweaks to help improve things somewhat - decided to read the Makefile manual after some 15 years to updated my make grey cells somewhat. New command in the gpio command - readall
This commit is contained in:
parent
86a5c68e08
commit
183c5a6b5c
10
People
Normal file
10
People
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
Just a quick note to some people who've provided help, suggestions,
|
||||||
|
bug-fixes, etc. along the way...
|
||||||
|
|
||||||
|
Nick Lott: (And others)
|
||||||
|
Hints about making it work with C++
|
||||||
|
|
||||||
|
Philipp Stefan Neininger:
|
||||||
|
Minor bug in the Makefile to do with cross compiling
|
||||||
|
|
||||||
16
build
16
build
@ -10,15 +10,31 @@ if [ x$1 = "xclean" ]; then
|
|||||||
cd ../examples
|
cd ../examples
|
||||||
make clean
|
make clean
|
||||||
cd ..
|
cd ..
|
||||||
|
elif [ x$1 = "xuninstall" ]; then
|
||||||
|
echo Uninstalling
|
||||||
|
echo
|
||||||
|
echo "WiringPi library"
|
||||||
|
cd wiringPi
|
||||||
|
sudo make uninstall
|
||||||
|
echo
|
||||||
|
echo "GPIO Utility"
|
||||||
|
cd ../gpio
|
||||||
|
sudo make uninstall
|
||||||
|
cd ..
|
||||||
else
|
else
|
||||||
echo wiringPi Build script - please wait...
|
echo wiringPi Build script - please wait...
|
||||||
echo
|
echo
|
||||||
|
echo "WiringPi library"
|
||||||
cd wiringPi
|
cd wiringPi
|
||||||
make
|
make
|
||||||
sudo make install
|
sudo make install
|
||||||
|
echo
|
||||||
|
echo "GPIO Utility"
|
||||||
cd ../gpio
|
cd ../gpio
|
||||||
make
|
make
|
||||||
sudo make install
|
sudo make install
|
||||||
|
echo
|
||||||
|
echo "Examples"
|
||||||
cd ../examples
|
cd ../examples
|
||||||
make
|
make
|
||||||
cd ..
|
cd ..
|
||||||
|
|||||||
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#DEBUG = -g -O0
|
#DEBUG = -g -O0
|
||||||
DEBUG = -O3
|
DEBUG = -O2
|
||||||
CC = gcc
|
CC = gcc
|
||||||
INCLUDE = -I/usr/local/include
|
INCLUDE = -I/usr/local/include
|
||||||
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
|
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
|
||||||
@ -32,45 +32,49 @@ CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
|
|||||||
LDFLAGS = -L/usr/local/lib
|
LDFLAGS = -L/usr/local/lib
|
||||||
LIBS = -lwiringPi
|
LIBS = -lwiringPi
|
||||||
|
|
||||||
# Should not alter anything below this line
|
# May not need to alter anything below this line
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
SRC = gpio.c
|
SRC = gpio.c
|
||||||
|
|
||||||
OBJ = gpio.o
|
OBJ = $(SRC:.c=.o)
|
||||||
|
|
||||||
all: gpio
|
all: gpio
|
||||||
|
|
||||||
gpio: gpio.o /usr/local/lib/libwiringPi.a /usr/local/lib/libwiringPi.so.1.0
|
gpio: gpio.o
|
||||||
@echo [LD]
|
@echo [Link]
|
||||||
@$(CC) -o $@ gpio.o $(LDFLAGS) $(LIBS)
|
@$(CC) -o $@ gpio.o $(LDFLAGS) $(LIBS)
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
@echo [CC] $<
|
@echo [Compile] $<
|
||||||
@$(CC) -c $(CFLAGS) $< -o $@
|
@$(CC) -c $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
.PHONEY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJ) gpio *~ core tags
|
rm -f $(OBJ) gpio *~ core tags *.bak
|
||||||
|
|
||||||
|
.PHONEY: tags
|
||||||
tags: $(SRC)
|
tags: $(SRC)
|
||||||
@echo [ctags]
|
@echo [ctags]
|
||||||
@ctags $(SRC)
|
@ctags $(SRC)
|
||||||
|
|
||||||
depend:
|
.PHONEY: install
|
||||||
makedepend -Y $(SRC)
|
|
||||||
|
|
||||||
install:
|
install:
|
||||||
@echo -n "Installing... "
|
@echo "[Install]"
|
||||||
@cp gpio /usr/local/bin
|
@cp gpio /usr/local/bin
|
||||||
@chown root.root /usr/local/bin/gpio
|
@chown root.root /usr/local/bin/gpio
|
||||||
@chmod 4755 /usr/local/bin/gpio
|
@chmod 4755 /usr/local/bin/gpio
|
||||||
@mkdir -p /usr/local/man/man1
|
@mkdir -p /usr/local/man/man1
|
||||||
@cp gpio.1 /usr/local/man/man1
|
@cp gpio.1 /usr/local/man/man1
|
||||||
@echo "Done."
|
|
||||||
|
|
||||||
|
|
||||||
|
.PHONEY: uninstall
|
||||||
uninstall:
|
uninstall:
|
||||||
|
@echo "[UnInstall]"
|
||||||
rm -f /usr/local/bin/gpio
|
rm -f /usr/local/bin/gpio
|
||||||
rm -f /usr/local/man/man1/gpio.1
|
rm -f /usr/local/man/man1/gpio.1
|
||||||
|
|
||||||
|
.PHONEY: depend
|
||||||
|
depend:
|
||||||
|
makedepend -Y $(SRC)
|
||||||
|
|
||||||
# DO NOT DELETE
|
# DO NOT DELETE
|
||||||
|
|||||||
27
gpio/gpio.1
27
gpio/gpio.1
@ -1,4 +1,4 @@
|
|||||||
.TH "GPIO" "14 June 2012" "Command-Line access to Raspberry Pi and PiFace GPIO"
|
.TH "GPIO" "21st October 2012" "Command-Line access to Raspberry Pi and PiFace GPIO"
|
||||||
|
|
||||||
.SH NAME
|
.SH NAME
|
||||||
gpio \- Command-line access to Raspberry Pi and PiFace GPIO
|
gpio \- Command-line access to Raspberry Pi and PiFace GPIO
|
||||||
@ -17,6 +17,9 @@ gpio \- Command-line access to Raspberry Pi and PiFace GPIO
|
|||||||
.B ...
|
.B ...
|
||||||
.PP
|
.PP
|
||||||
.B gpio
|
.B gpio
|
||||||
|
.B readall
|
||||||
|
.PP
|
||||||
|
.B gpio
|
||||||
.B unexportall/exports
|
.B unexportall/exports
|
||||||
.PP
|
.PP
|
||||||
.B gpio
|
.B gpio
|
||||||
@ -62,7 +65,7 @@ interface without needing to be run as root.
|
|||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B \-v
|
.B \-v
|
||||||
Output the current version
|
Output the current version including the board revision of the Raspberry Pi.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B \-g
|
.B \-g
|
||||||
@ -73,20 +76,26 @@ Use the BCM_GPIO pins numbers rather than wiringPi pin numbers.
|
|||||||
Use the PiFace interface board and its corresponding pin numbers.
|
Use the PiFace interface board and its corresponding pin numbers.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B read
|
.B read <pin>
|
||||||
Read the digital value of the given pin and print 0 or 1 to represent the
|
Read the digital value of the given pin and print 0 or 1 to represent the
|
||||||
respective logic levels.
|
respective logic levels.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B write
|
.B write <pin> <value>
|
||||||
Write the given value (0 or 1) to the pin.
|
Write the given value (0 or 1) to the pin.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B pwm
|
.B readall
|
||||||
|
Output a table of all GPIO pins values. The values represent the actual values read
|
||||||
|
if the pin is in input mode, or the last value written if the pin is in output
|
||||||
|
mode.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.B pwm <pin> <value>
|
||||||
Write a PWM value (0-1023) to the given pin.
|
Write a PWM value (0-1023) to the given pin.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B mode
|
.B mode <pin> <mode>
|
||||||
Set a pin into \fIinput\fR, \fIoutput\fR or \fIpwm\fR mode. Can also
|
Set a pin into \fIinput\fR, \fIoutput\fR or \fIpwm\fR mode. Can also
|
||||||
use the literals \fIup\fR, \fIdown\fR or \fItri\fR to set the internal
|
use the literals \fIup\fR, \fIdown\fR or \fItri\fR to set the internal
|
||||||
pull-up, pull-down or tristate (off) controls.
|
pull-up, pull-down or tristate (off) controls.
|
||||||
@ -238,10 +247,14 @@ Gordon Henderson
|
|||||||
|
|
||||||
.SH "REPORTING BUGS"
|
.SH "REPORTING BUGS"
|
||||||
|
|
||||||
Report bugs to <projects@drogon.net>
|
Please report bugs to <projects@drogon.net>
|
||||||
|
|
||||||
.SH COPYRIGHT
|
.SH COPYRIGHT
|
||||||
|
|
||||||
Copyright (c) 2012 Gordon Henderson
|
Copyright (c) 2012 Gordon Henderson
|
||||||
This is free software; see the source for copying conditions. There is NO
|
This is free software; see the source for copying conditions. There is NO
|
||||||
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
.SH TRADEMARKS AND ACKNOWLEDGEMENTS
|
||||||
|
|
||||||
|
Raspberry Pi is a trademark of the Raspberry Pi Foundation.
|
||||||
|
|||||||
74
gpio/gpio.c
74
gpio/gpio.c
@ -40,7 +40,7 @@
|
|||||||
# define FALSE (1==2)
|
# define FALSE (1==2)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define VERSION "1.3"
|
#define VERSION "1.4"
|
||||||
|
|
||||||
static int wpMode ;
|
static int wpMode ;
|
||||||
|
|
||||||
@ -48,7 +48,9 @@ char *usage = "Usage: gpio -v\n"
|
|||||||
" gpio -h\n"
|
" gpio -h\n"
|
||||||
" gpio [-g] <read/write/pwm/mode> ...\n"
|
" gpio [-g] <read/write/pwm/mode> ...\n"
|
||||||
" gpio [-p] <read/write/mode> ...\n"
|
" gpio [-p] <read/write/mode> ...\n"
|
||||||
" gpio export/edge/unexport/unexportall/exports ...\n"
|
" gpio readall\n"
|
||||||
|
" gpio unexportall/exports ...\n"
|
||||||
|
" gpio export/edge/unexport ...\n"
|
||||||
" gpio drive <group> <value>\n"
|
" gpio drive <group> <value>\n"
|
||||||
" gpio pwm-bal/pwm-ms \n"
|
" gpio pwm-bal/pwm-ms \n"
|
||||||
" gpio pwmr <range> \n"
|
" gpio pwmr <range> \n"
|
||||||
@ -172,6 +174,65 @@ static void doLoad (int argc, char *argv [])
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* doReadall:
|
||||||
|
* Read all the GPIO pins
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
static char *pinNames [] =
|
||||||
|
{
|
||||||
|
"GPIO 0",
|
||||||
|
"GPIO 1",
|
||||||
|
"GPIO 2",
|
||||||
|
"GPIO 3",
|
||||||
|
"GPIO 4",
|
||||||
|
"GPIO 5",
|
||||||
|
"GPIO 6",
|
||||||
|
"GPIO 7",
|
||||||
|
"SDA ",
|
||||||
|
"SCL ",
|
||||||
|
"CE0 ",
|
||||||
|
"CE1 ",
|
||||||
|
"MOSI ",
|
||||||
|
"MISO ",
|
||||||
|
"SCLK ",
|
||||||
|
"TxD ",
|
||||||
|
"RxD ",
|
||||||
|
"GPIO 8",
|
||||||
|
"GPIO 9",
|
||||||
|
"GPIO10",
|
||||||
|
"GPIO11",
|
||||||
|
} ;
|
||||||
|
|
||||||
|
static void doReadall (void)
|
||||||
|
{
|
||||||
|
int pin ;
|
||||||
|
|
||||||
|
printf ("+----------+------+--------+-------+\n") ;
|
||||||
|
printf ("| wiringPi | GPIO | Name | Value |\n") ;
|
||||||
|
printf ("+----------+------+--------+-------+\n") ;
|
||||||
|
|
||||||
|
for (pin = 0 ; pin < NUM_PINS ; ++pin)
|
||||||
|
printf ("| %6d | %3d | %s | %s |\n",
|
||||||
|
pin, wpiPinToGpio (pin),
|
||||||
|
pinNames [pin],
|
||||||
|
digitalRead (pin) == HIGH ? "High" : "Low ") ;
|
||||||
|
|
||||||
|
printf ("+----------+------+--------+-------+\n") ;
|
||||||
|
|
||||||
|
if (piBoardRev () == 1)
|
||||||
|
return ;
|
||||||
|
|
||||||
|
for (pin = 17 ; pin <= 20 ; ++pin)
|
||||||
|
printf ("| %6d | %3d | %s | %s |\n",
|
||||||
|
pin, wpiPinToGpio (pin),
|
||||||
|
pinNames [pin],
|
||||||
|
digitalRead (pin) == HIGH ? "High" : "Low ") ;
|
||||||
|
|
||||||
|
printf ("+----------+------+--------+-------+\n") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* doExports:
|
* doExports:
|
||||||
@ -875,10 +936,11 @@ int main (int argc, char *argv [])
|
|||||||
|
|
||||||
// Check for wiring commands
|
// Check for wiring commands
|
||||||
|
|
||||||
/**/ if (strcasecmp (argv [1], "read" ) == 0) doRead (argc, argv) ;
|
/**/ if (strcasecmp (argv [1], "readall" ) == 0) doReadall () ;
|
||||||
else if (strcasecmp (argv [1], "write") == 0) doWrite (argc, argv) ;
|
else if (strcasecmp (argv [1], "read" ) == 0) doRead (argc, argv) ;
|
||||||
else if (strcasecmp (argv [1], "pwm" ) == 0) doPwm (argc, argv) ;
|
else if (strcasecmp (argv [1], "write") == 0) doWrite (argc, argv) ;
|
||||||
else if (strcasecmp (argv [1], "mode" ) == 0) doMode (argc, argv) ;
|
else if (strcasecmp (argv [1], "pwm" ) == 0) doPwm (argc, argv) ;
|
||||||
|
else if (strcasecmp (argv [1], "mode" ) == 0) doMode (argc, argv) ;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s: Unknown command: %s.\n", argv [0], argv [1]) ;
|
fprintf (stderr, "%s: Unknown command: %s.\n", argv [0], argv [1]) ;
|
||||||
|
|||||||
21
gpio/test.sh
21
gpio/test.sh
@ -1,4 +1,25 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# test.sh:
|
||||||
|
# Simple test: Assumes LEDs on Pins 0-7 and lights them
|
||||||
|
# in-turn.
|
||||||
|
#################################################################################
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
#################################################################################
|
||||||
|
|
||||||
# Simple test - assumes LEDs on Pins 0-7.
|
# Simple test - assumes LEDs on Pins 0-7.
|
||||||
|
|
||||||
|
|||||||
@ -43,40 +43,37 @@ SRC = wiringPi.c wiringPiFace.c wiringSerial.c wiringShift.c \
|
|||||||
piNes.c \
|
piNes.c \
|
||||||
lcd.c piHiPri.c piThread.c softPwm.c wiringPiSPI.c
|
lcd.c piHiPri.c piThread.c softPwm.c wiringPiSPI.c
|
||||||
|
|
||||||
OBJ = wiringPi.o wiringPiFace.o wiringSerial.o wiringShift.o \
|
OBJ = $(SRC:.c=.o)
|
||||||
gertboard.o \
|
|
||||||
piNes.o \
|
|
||||||
lcd.o piHiPri.o piThread.o softPwm.o wiringPiSPI.o
|
|
||||||
|
|
||||||
all: $(STATIC) $(DYNAMIC)
|
#all: $(STATIC) $(DYNAMIC)
|
||||||
|
all: $(DYNAMIC)
|
||||||
|
|
||||||
$(STATIC): $(OBJ)
|
$(STATIC): $(OBJ)
|
||||||
@echo [STATIC]
|
@echo [Link (Static)]
|
||||||
@ar rcs $(STATIC) $(OBJ)
|
@ar rcs $(STATIC) $(OBJ)
|
||||||
@ranlib $(STATIC)
|
@ranlib $(STATIC)
|
||||||
|
@size $(STATIC)
|
||||||
# @size $(STATIC)
|
|
||||||
|
|
||||||
$(DYNAMIC): $(OBJ)
|
$(DYNAMIC): $(OBJ)
|
||||||
@echo [DYNAMIC]
|
@echo [Link]
|
||||||
@gcc -shared -Wl,-soname,libwiringPi.so.1 -o libwiringPi.so.1.0 -lpthread $(OBJ)
|
@$(CC) -shared -Wl,-soname,libwiringPi.so.1 -o libwiringPi.so.1.0 -lpthread $(OBJ)
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
@echo [CC] $<
|
@echo [Compile] $<
|
||||||
@$(CC) -c $(CFLAGS) $< -o $@
|
@$(CC) -c $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
.PHONEY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJ) *~ core tags Makefile.bak libwiringPi.*
|
rm -f $(OBJ) *~ core tags Makefile.bak libwiringPi.*
|
||||||
|
|
||||||
|
.PHONEY: tags
|
||||||
tags: $(SRC)
|
tags: $(SRC)
|
||||||
@echo [ctags]
|
@echo [ctags]
|
||||||
@ctags $(SRC)
|
@ctags $(SRC)
|
||||||
|
|
||||||
depend:
|
.PHONEY: install
|
||||||
makedepend -Y $(SRC)
|
|
||||||
|
|
||||||
install: $(TARGET)
|
install: $(TARGET)
|
||||||
@echo [install]
|
@echo "[Install]"
|
||||||
@install -m 0755 -d /usr/local/lib
|
@install -m 0755 -d /usr/local/lib
|
||||||
@install -m 0755 -d /usr/local/include
|
@install -m 0755 -d /usr/local/include
|
||||||
@install -m 0644 wiringPi.h /usr/local/include
|
@install -m 0644 wiringPi.h /usr/local/include
|
||||||
@ -87,14 +84,15 @@ install: $(TARGET)
|
|||||||
@install -m 0644 softPwm.h /usr/local/include
|
@install -m 0644 softPwm.h /usr/local/include
|
||||||
@install -m 0644 lcd.h /usr/local/include
|
@install -m 0644 lcd.h /usr/local/include
|
||||||
@install -m 0644 wiringPiSPI.h /usr/local/include
|
@install -m 0644 wiringPiSPI.h /usr/local/include
|
||||||
@install -m 0644 libwiringPi.a /usr/local/lib
|
# @install -m 0644 libwiringPi.a /usr/local/lib
|
||||||
@install -m 0755 libwiringPi.so.1.0 /usr/local/lib
|
@install -m 0755 libwiringPi.so.1.0 /usr/local/lib
|
||||||
@ln -sf /usr/local/lib/libwiringPi.so.1.0 /usr/local/lib/libwiringPi.so
|
@ln -sf /usr/local/lib/libwiringPi.so.1.0 /usr/local/lib/libwiringPi.so
|
||||||
@ln -sf /usr/local/lib/libwiringPi.so.1.0 /usr/local/lib/libwiringPi.so.1
|
@ln -sf /usr/local/lib/libwiringPi.so.1.0 /usr/local/lib/libwiringPi.so.1
|
||||||
@ldconfig
|
@ldconfig
|
||||||
|
|
||||||
|
.PHONEY: uninstall
|
||||||
uninstall:
|
uninstall:
|
||||||
@echo [uninstall]
|
@echo "[UnInstall]"
|
||||||
@rm -f /usr/local/include/wiringPi.h
|
@rm -f /usr/local/include/wiringPi.h
|
||||||
@rm -f /usr/local/include/wiringSerial.h
|
@rm -f /usr/local/include/wiringSerial.h
|
||||||
@rm -f /usr/local/include/wiringShift.h
|
@rm -f /usr/local/include/wiringShift.h
|
||||||
@ -107,6 +105,10 @@ uninstall:
|
|||||||
@ldconfig
|
@ldconfig
|
||||||
|
|
||||||
|
|
||||||
|
.PHONEY: depend
|
||||||
|
depend:
|
||||||
|
makedepend -Y $(SRC)
|
||||||
|
|
||||||
# DO NOT DELETE
|
# DO NOT DELETE
|
||||||
|
|
||||||
wiringPi.o: wiringPi.h
|
wiringPi.o: wiringPi.h
|
||||||
|
|||||||
@ -397,15 +397,31 @@ int wpiPinToGpio (int wpiPin)
|
|||||||
* piBoardRev:
|
* piBoardRev:
|
||||||
* Return a number representing the hardware revision of the board.
|
* Return a number representing the hardware revision of the board.
|
||||||
* Revision is currently 1 or 2. -1 is returned on error.
|
* Revision is currently 1 or 2. -1 is returned on error.
|
||||||
|
*
|
||||||
|
* Much confusion here )-:
|
||||||
|
* Seems there ar esome boards with 0000 in them (mistake in manufacture)
|
||||||
|
* and some board with 0005 in them (another mistake in manufacture).
|
||||||
|
* So the distinction between boards that I can see is:
|
||||||
|
* 0000 - Error
|
||||||
|
* 0001 - Not used
|
||||||
|
* 0002 - Rev 1
|
||||||
|
* 0003 - Rev 1
|
||||||
|
* 0004 - Rev 2
|
||||||
|
* 0005 - Rev 2
|
||||||
|
* 0006 - Rev 2
|
||||||
|
* 000f - Rev 2 + 512MB
|
||||||
|
*
|
||||||
|
* A small thorn is the olde style overvolting - that will add in
|
||||||
|
* 1000000
|
||||||
|
*
|
||||||
*********************************************************************************
|
*********************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int piBoardRev (void)
|
int piBoardRev (void)
|
||||||
{
|
{
|
||||||
FILE *cpuFd ;
|
FILE *cpuFd ;
|
||||||
char line [80] ;
|
char line [120] ;
|
||||||
char *c ;
|
char *c, lastChar ;
|
||||||
int r = -1 ;
|
|
||||||
static int boardRev = -1 ;
|
static int boardRev = -1 ;
|
||||||
|
|
||||||
// No point checking twice...
|
// No point checking twice...
|
||||||
@ -416,21 +432,28 @@ int piBoardRev (void)
|
|||||||
if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL)
|
if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL)
|
||||||
return -1 ;
|
return -1 ;
|
||||||
|
|
||||||
while (fgets (line, 80, cpuFd) != NULL)
|
while (fgets (line, 120, cpuFd) != NULL)
|
||||||
if (strncmp (line, "Revision", 8) == 0)
|
if (strncmp (line, "Revision", 8) == 0)
|
||||||
for (c = line ; *c ; ++c)
|
break ;
|
||||||
{
|
|
||||||
if (!isdigit (*c))
|
|
||||||
continue ;
|
|
||||||
r = atoi (c) ;
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose (cpuFd) ;
|
fclose (cpuFd) ;
|
||||||
|
|
||||||
if (r == -1)
|
if (line == NULL)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "piBoardRev: Unable to determine board revision from /proc/cpuinfo\n") ;
|
fprintf (stderr, "piBoardRev: Unable to determine board revision from /proc/cpuinfo\n") ;
|
||||||
|
fprintf (stderr, " (No \"Revision\" line)\n") ;
|
||||||
|
errno = 0 ;
|
||||||
|
return -1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (c = line ; *c ; ++c)
|
||||||
|
if (isdigit (*c))
|
||||||
|
break ;
|
||||||
|
|
||||||
|
if (!isdigit (*c))
|
||||||
|
{
|
||||||
|
fprintf (stderr, "piBoardRev: Unable to determine board revision from /proc/cpuinfo\n") ;
|
||||||
|
fprintf (stderr, " (No numeric revision string in: \"%s\"\n", line) ;
|
||||||
errno = 0 ;
|
errno = 0 ;
|
||||||
return -1 ;
|
return -1 ;
|
||||||
}
|
}
|
||||||
@ -439,15 +462,17 @@ int piBoardRev (void)
|
|||||||
// has 100000 added to it!
|
// has 100000 added to it!
|
||||||
|
|
||||||
if (wiringPiDebug)
|
if (wiringPiDebug)
|
||||||
if (r > 1000)
|
if (strlen (c) != 4)
|
||||||
printf ("piboardRev: This Pi has/is overvolted!\n") ;
|
printf ("piboardRev: This Pi has/is overvolted!\n") ;
|
||||||
|
|
||||||
r %= 100 ;
|
lastChar = c [strlen (c) - 2] ;
|
||||||
|
|
||||||
/**/ if ((r == 2) || (r == 3))
|
/**/ if ((lastChar == '2') || (lastChar == '3'))
|
||||||
boardRev = 1 ;
|
boardRev = 1 ;
|
||||||
else if ((r == 4) || (r == 5) || (r == 6))
|
else
|
||||||
boardRev = 2 ;
|
boardRev = 2 ;
|
||||||
|
|
||||||
|
#ifdef DO_WE_CARE_ABOUT_THIS_NOW
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf (stderr, "WARNING: wiringPi: Unable to determine board revision from \"%d\"\n", r) ;
|
fprintf (stderr, "WARNING: wiringPi: Unable to determine board revision from \"%d\"\n", r) ;
|
||||||
@ -456,9 +481,10 @@ int piBoardRev (void)
|
|||||||
fprintf (stderr, " -> Assuming a Rev 1 board\n") ;
|
fprintf (stderr, " -> Assuming a Rev 1 board\n") ;
|
||||||
boardRev = 1 ;
|
boardRev = 1 ;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (wiringPiDebug)
|
if (wiringPiDebug)
|
||||||
printf ("piboardRev: Revision: %d, board revision: %d\n", r, boardRev) ;
|
printf ("piboardRev: Revision string: %s, board revision: %d\n", c, boardRev) ;
|
||||||
|
|
||||||
return boardRev ;
|
return boardRev ;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user