first commit
This commit is contained in:
165
gpio/COPYING.LESSER
Normal file
165
gpio/COPYING.LESSER
Normal file
@@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
177
gpio/Makefile
Normal file
177
gpio/Makefile
Normal file
@@ -0,0 +1,177 @@
|
||||
#
|
||||
# Makefile:
|
||||
# The gpio command:
|
||||
# A swiss-army knige of GPIO shenanigans.
|
||||
# https://projects.drogon.net/wiring-pi
|
||||
#
|
||||
# Copyright (c) 2012-2016 Gordon Henderson
|
||||
#################################################################################
|
||||
# This file is part of wiringPi:
|
||||
# A "wiring" 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/>.
|
||||
#################################################################################
|
||||
|
||||
DESTDIR?=/usr
|
||||
PREFIX?=/local
|
||||
|
||||
ifneq ($V,1)
|
||||
Q ?= @
|
||||
endif
|
||||
|
||||
#DEBUG = -g -O0
|
||||
DEBUG = -O2
|
||||
CC = gcc
|
||||
INCLUDE = -I$(DESTDIR)$(PREFIX)/include
|
||||
CFLAGS = $(DEBUG) -Wall -Wextra $(INCLUDE) -Winline -pipe
|
||||
|
||||
LDFLAGS = -L$(DESTDIR)$(PREFIX)/lib
|
||||
LIBS = -lwiringPi -lwiringPiDev -lpthread -lrt -lm -lcrypt
|
||||
|
||||
ifeq ($(BOARD),)
|
||||
BOARD = orangepioneplus-h6
|
||||
endif
|
||||
|
||||
ifeq ($(BOARD), orangepi2giot)
|
||||
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_2G_IOT
|
||||
endif
|
||||
|
||||
ifneq ($(findstring $(BOARD), "orangepione-h3" "orangepilite-h3" "orangepipc-h3" "orangepiplus-h3" "orangepipcplus-h3" "orangepiplus2e-h3"),)
|
||||
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_H3
|
||||
endif
|
||||
|
||||
ifeq ($(BOARD), orangepipc2-h5)
|
||||
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_PC2
|
||||
endif
|
||||
|
||||
ifeq ($(BOARD), orangepiprime-h5)
|
||||
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_PRIME
|
||||
endif
|
||||
|
||||
ifeq ($(BOARD), orangepizeroplus-h5)
|
||||
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_ZEROPLUS
|
||||
endif
|
||||
|
||||
ifneq ($(findstring $(BOARD), "orangepiwin-a64" "orangepiwinplus-a64"),)
|
||||
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_WIN
|
||||
endif
|
||||
|
||||
ifneq ($(findstring $(BOARD), "orangepizero-h2" "orangepir1-h2"),)
|
||||
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_ZERO
|
||||
endif
|
||||
|
||||
ifneq ($(findstring $(BOARD), "orangepioneplus-h6" "orangepilite2-h6"),)
|
||||
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_LITE2
|
||||
endif
|
||||
|
||||
ifeq ($(BOARD), orangepi3-h6)
|
||||
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_3
|
||||
endif
|
||||
|
||||
ifeq ($(BOARD), orangepizero2-h616)
|
||||
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_ZERO2
|
||||
endif
|
||||
|
||||
ifeq ($(BOARD), orangepizeroplus2h3)
|
||||
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_ZEROPLUS2_H3
|
||||
endif
|
||||
|
||||
ifeq ($(BOARD), orangepizeroplus2h5)
|
||||
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_ZEROPLUS2_H5
|
||||
endif
|
||||
|
||||
ifeq ($(BOARD), orangepirk3399)
|
||||
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_RK3399
|
||||
endif
|
||||
|
||||
ifeq ($(BOARD), orangepi4)
|
||||
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_4
|
||||
endif
|
||||
|
||||
ifeq ($(BOARD), orangepi4-lts)
|
||||
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_4_LTS
|
||||
endif
|
||||
|
||||
ifeq ($(BOARD), orangepi800)
|
||||
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_800
|
||||
endif
|
||||
|
||||
ifeq ($(BOARD), orangepir1plus-rk3328)
|
||||
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_R1PLUS
|
||||
endif
|
||||
|
||||
EXTRA_CFLAGS += -DCONFIG_ORANGEPI
|
||||
|
||||
# May not need to alter anything below this line
|
||||
###############################################################################
|
||||
|
||||
SRC = gpio.c readall.c OrangePi.c
|
||||
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
all: gpio
|
||||
|
||||
version.h: ../VERSION
|
||||
$Q echo Need to run newVersion above.
|
||||
|
||||
gpio: $(OBJ)
|
||||
$Q echo [Link]
|
||||
$Q $(CC) -o $@ $(OBJ) $(LDFLAGS) $(LIBS)
|
||||
|
||||
.c.o:
|
||||
$Q echo [Compile] $<
|
||||
$Q $(CC) -c $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
$Q echo "[Clean]"
|
||||
$Q rm -f $(OBJ) gpio *~ core tags *.bak
|
||||
|
||||
.PHONY: tags
|
||||
tags: $(SRC)
|
||||
$Q echo [ctags]
|
||||
$Q ctags $(SRC)
|
||||
|
||||
.PHONY: install
|
||||
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)/share/man/man1
|
||||
$Q cp gpio.1 $(DESTDIR)$(PREFIX)/share/man/man1/
|
||||
|
||||
.PHONY: install-deb
|
||||
install-deb: gpio
|
||||
$Q echo "[Install: deb]"
|
||||
$Q install -m 0755 -d $(CURDIR)/../debian-template/wiringPi/usr/bin
|
||||
$Q install -m 0755 gpio $(CURDIR)/../debian-template/wiringPi/usr/bin
|
||||
$Q install -m 0755 -d $(CURDIR)/../debian-template/wiringPi/usr/share/man/man1
|
||||
$Q install -m 0644 gpio.1 $(CURDIR)/../debian-template/wiringPi/usr/share/man/man1
|
||||
|
||||
.PHONY: uninstall
|
||||
uninstall:
|
||||
$Q echo "[UnInstall]"
|
||||
$Q rm -f $(DESTDIR)$(PREFIX)/bin/gpio
|
||||
$Q rm -f $(DESTDIR)$(PREFIX)/share/man/man1/gpio.1
|
||||
|
||||
.PHONY: depend
|
||||
depend:
|
||||
makedepend -Y $(SRC)
|
||||
|
||||
# DO NOT DELETE
|
||||
|
||||
gpio.o: ../version.h
|
||||
1373
gpio/OrangePi.c
Normal file
1373
gpio/OrangePi.c
Normal file
File diff suppressed because it is too large
Load Diff
11
gpio/OrangePi.h
Normal file
11
gpio/OrangePi.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef _ORANGEPI_H_
|
||||
#define _ORANGEPI_H_
|
||||
|
||||
extern char *physNames[64];
|
||||
extern int physToWpi[64];
|
||||
extern int pinToGpioOrangePi[64];
|
||||
|
||||
extern void OrangePiReadAll(void);
|
||||
extern void readallPhys(int physPin);
|
||||
|
||||
#endif
|
||||
351
gpio/gpio.1
Normal file
351
gpio/gpio.1
Normal file
@@ -0,0 +1,351 @@
|
||||
.TH GPIO 1 "March 2018" wiringPi "Command-Line access to Raspberry Pi's GPIO"
|
||||
|
||||
.SH NAME
|
||||
gpio \- Command-line access to Raspberry Pi's GPIO
|
||||
|
||||
.SH SYNOPSIS
|
||||
.B gpio
|
||||
.B \-v
|
||||
.PP
|
||||
.B gpio
|
||||
.B [ \-g | \-1 ]
|
||||
.B mode/read/write/aread/awrite/wb/pwm/pwnTone/clock/toggle/blink ...
|
||||
.PP
|
||||
.B gpio
|
||||
.B [ \-x extension:params ]
|
||||
.B mode/read/write/aread/awrite/pwm/toggle/blink ...
|
||||
.PP
|
||||
.B gpio
|
||||
.B [ \-p ]
|
||||
.B read/write/toggle/blink
|
||||
.B ...
|
||||
.PP
|
||||
.B gpio
|
||||
.B [ \-p ]
|
||||
.B pwnTone pin frequency
|
||||
.B ...
|
||||
.PP
|
||||
.B gpio
|
||||
.B readall
|
||||
.PP
|
||||
.B gpio
|
||||
.B unexportall/exports
|
||||
.PP
|
||||
.B gpio
|
||||
.B export/edge/unexport
|
||||
.B ...
|
||||
.PP
|
||||
.B gpio
|
||||
.B wfi
|
||||
.B ...
|
||||
.PP
|
||||
.B gpio
|
||||
.B drive
|
||||
group value
|
||||
.PP
|
||||
.B gpio
|
||||
.B usbp
|
||||
high | low
|
||||
.PP
|
||||
.B gpio
|
||||
.B pwm-bal/pwm-ms
|
||||
.PP
|
||||
.B gpio
|
||||
.B pwmr
|
||||
range
|
||||
.PP
|
||||
.B gpio
|
||||
.B load \ i2c/spi ...
|
||||
.PP
|
||||
.B gpio
|
||||
.B gbr
|
||||
channel
|
||||
.PP
|
||||
.B gpio
|
||||
.B gbw
|
||||
channel value
|
||||
|
||||
.SH DESCRIPTION
|
||||
|
||||
.B GPIO
|
||||
is a swiss army knife of a command line tool to allow the user easy
|
||||
access to the GPIO pins on the Raspberry Pi and the SPI A/D and D/A
|
||||
converters on the Gertboard. It's designed for simple testing and
|
||||
diagnostic purposes, but can be used in shell scripts for general if
|
||||
somewhat slow control of the GPIO pins.
|
||||
|
||||
It can also control the IO's on the PiFace IO board and load the SPI and I2C
|
||||
kernel modules if required.
|
||||
|
||||
Additionally, it can be used to set the exports in the \fI/sys/class/gpio\fR
|
||||
system directory to allow subsequent programs to use the \fR/sys/class/gpio\fR
|
||||
interface without needing to be run as root.
|
||||
|
||||
.SH OPTIONS
|
||||
|
||||
.TP
|
||||
.B \-v
|
||||
Output the current version including the board revision of the Raspberry Pi.
|
||||
|
||||
.TP
|
||||
.B \-g
|
||||
Use the BCM_GPIO pins numbers rather than wiringPi pin numbers.
|
||||
\fINote:\fR The BCM_GPIO pin numbers are always used with the
|
||||
export and edge commands.
|
||||
|
||||
.TP
|
||||
.B \-1
|
||||
Use the physical pin numbers rather than wiringPi pin numbers.
|
||||
\fINote:\fR that this applies to the P1 connector only. It is not possible to
|
||||
use pins on the Revision 2 P5 connector this way, and as with \-g the
|
||||
BCM_GPIO pin numbers are always used with the export and edge commands.
|
||||
|
||||
.TP
|
||||
.B \-x extension
|
||||
This causes the named extension to be initialised. Extensions
|
||||
comprise of a name (e.g. mcp23017) followed by a colon, then the
|
||||
pin-base, then more optional parameters depending on the extension type.
|
||||
See the web page on http://wiringpi.com/the-gpio-utility/
|
||||
|
||||
.TP
|
||||
.B \-p
|
||||
Use the PiFace interface board and its corresponding pin numbers. The PiFace
|
||||
will always appear at pin number 200 in the gpio command. You can assign any
|
||||
pin numbers you like in your own programs though.
|
||||
|
||||
.TP
|
||||
.B read <pin>
|
||||
Read the digital value of the given pin and print 0 or 1 to represent the
|
||||
respective logic levels.
|
||||
|
||||
.TP
|
||||
.B write <pin> <value>
|
||||
Write the given value (0 or 1) to the pin. You need to set the pin
|
||||
to output mode first.
|
||||
|
||||
.TP
|
||||
.B toggle <pin>
|
||||
Changes the state of a GPIO pin; 0 to 1, or 1 to 0.
|
||||
|
||||
Note unlike the blink command, the pin must be in output mode first.
|
||||
|
||||
.TP
|
||||
.B blink <pin>
|
||||
Blinks the given pin on/off. Press Control-C to exit.
|
||||
|
||||
Note: This command explicitly sets the pin to output mode.
|
||||
|
||||
.TP
|
||||
.B aread <pin>
|
||||
Read the analog value of the given pin. This needs to be used in
|
||||
conjunction with a -x flag to add in an extension that handles analog
|
||||
inputs.
|
||||
|
||||
e.g. gpio -x mcp3002:200:0 aread 200
|
||||
|
||||
will read the first analog input on an mcp3002 SPI ADC chip.
|
||||
|
||||
.TP
|
||||
.B awrite <pin> <value>
|
||||
Write the analog value to the given pin. This needs to be used in
|
||||
conjunction with a -x flag to add in an extension that handles analog
|
||||
inputs.
|
||||
|
||||
e.g. gpio -x mcp4802:200:0 awrite 200 128
|
||||
|
||||
will write the value 128 to the first DAC port on an mcp4802 chip on
|
||||
the Pi's SPI bus 0.
|
||||
|
||||
|
||||
.TP
|
||||
.B wb <value>
|
||||
Write the given byte to the 8 main GPIO pins. You can prefix it with 0x
|
||||
to specify a hexadecimal number. You need to set pins to output mode
|
||||
first.
|
||||
|
||||
.TP
|
||||
.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.
|
||||
|
||||
The readall command is usable with an extension module (via the -x parameter),
|
||||
but it's unable to determine pin modes or states, so will perform both a
|
||||
digital and analog read on each pin in-turn.
|
||||
|
||||
.TP
|
||||
.B pwm <pin> <value>
|
||||
Write a PWM value (0-1023) to the given pin. The pin needs to be put
|
||||
into PWM mode first.
|
||||
|
||||
.TP
|
||||
.B clock <pin> <frequency>
|
||||
Set the output frequency on the given pin. The pin needs to be put into
|
||||
clock mode first.
|
||||
|
||||
.TP
|
||||
.B mode <pin> <mode>
|
||||
Set a pin into \fIinput\fR, \fIoutput\fR or \fIpwm\fR mode. Can also
|
||||
use the literals \fIup\fR, \fIdown\fR or \fItri\fR to set the internal
|
||||
pull-up, pull-down or tristate (off) controls.
|
||||
|
||||
The ALT modes can also be set using \fIalt0\fR, \fIalt1\fR, ... \fIalt5\fR.
|
||||
|
||||
.TP
|
||||
.B unexportall
|
||||
Un-Export all the GPIO pins in the /sys/class/gpio directory.
|
||||
|
||||
.TP
|
||||
.B exports
|
||||
Print a list (if any) of all the exported GPIO pins and their current values.
|
||||
|
||||
.TP
|
||||
.B export
|
||||
Export a GPIO pin in the \fI/sys/class/gpio\fR directory. Use like the
|
||||
mode command above however only \fIin\fR, \fIout\fR, \fIhigh\fR and
|
||||
\fRlow\fR are supported at this time. Note that the pin number is the
|
||||
\fBBCM_GPIO\fR number and not the wiringPi number. The \fIhigh\fR and
|
||||
\fIlow\fR commands pre-set the output value at the same time as the
|
||||
export to output mode.
|
||||
|
||||
Once a GPIO pin has been exported, the \fBgpio\fR program changes the
|
||||
ownership of the \fI/sys/class/gpio/gpioX/value\fR and if present in
|
||||
later kernels, the \fI/sys/class/gpio/gpioX/edge\fR pseudo files to
|
||||
that of the user running the \fBgpio\fR program. This means that you
|
||||
can have a small script of gpio exports to setup the gpio pins as your
|
||||
program requires without the need to run anything as root, or with the
|
||||
sudo command.
|
||||
|
||||
.TP
|
||||
.B edge
|
||||
This exports a GPIO pin in the \fI/sys/class/gpio\fR directory, set
|
||||
the direction to input and set the edge interrupt method to \fInone\fR,
|
||||
\fIrising\fR, \fIfalling\fR or \fIboth\fR. Use like the export command
|
||||
above and note that \fBBCM_GPIO\fR pin number is used not not wiringPi pin
|
||||
numbering.
|
||||
|
||||
Like the export commands above, ownership is set to that of the
|
||||
calling user, allowing subsequent access from user programs without
|
||||
requiring root/sudo.
|
||||
|
||||
.TP
|
||||
.B unexport
|
||||
Un-Export a GPIO pin in the /sys/class/gpio directory.
|
||||
|
||||
.TP
|
||||
.B wfi <pin> <mode>
|
||||
This set the given pin to the supplied interrupt mode: rising, falling
|
||||
or both then waits for the interrupt to happen. It's a non-busy wait,
|
||||
so does not consume and CPU while it's waiting.
|
||||
|
||||
.TP
|
||||
.B drive
|
||||
group value
|
||||
|
||||
Change the pad driver value for the given pad group to the supplied drive
|
||||
value. Group is 0, 1 or 2 and value is 0-7. Do not use unless you are
|
||||
absolutely sure you know what you're doing.
|
||||
|
||||
.TP
|
||||
.B usbp
|
||||
high | low
|
||||
|
||||
Change the USB current limiter to high (1.2 amps) or low (the default, 600mA)
|
||||
This is only applicable to the Model B+ and the Model B, v2.
|
||||
|
||||
.TP
|
||||
.B pwm-bal/pwm-ms
|
||||
Change the PWM mode to balanced (the default) or mark:space ratio (traditional)
|
||||
|
||||
.TP
|
||||
.B pwmr
|
||||
Change the PWM range register. The default is 1024.
|
||||
|
||||
.TP
|
||||
.B gbr
|
||||
channel
|
||||
|
||||
This reads the analog to digital converter on the Gertboard on the given
|
||||
channel. The board jumpers need to be in-place to do this operation.
|
||||
|
||||
.TP
|
||||
.B gbw
|
||||
channel value
|
||||
|
||||
This writes the supplied value to the output channel on the Gertboards
|
||||
SPI digital to analogue converter.
|
||||
The board jumpers need to be in-place to do this operation.
|
||||
|
||||
|
||||
.SH "WiringPi vs. BCM_GPIO Pin numbering vs. Physical pin numbering"
|
||||
|
||||
.PP
|
||||
The quickest way to get a list of the pin differences is to run the command
|
||||
.TP
|
||||
gpio readall
|
||||
|
||||
.SH FILES
|
||||
|
||||
.TP 2.2i
|
||||
.I gpio
|
||||
executable
|
||||
|
||||
.SH EXAMPLES
|
||||
.TP 2.2i
|
||||
gpio mode 4 output # Set pin 4 to output
|
||||
.PP
|
||||
gpio -g mode 23 output # Set GPIO pin 23 to output (same as WiringPi pin 4)
|
||||
.PP
|
||||
gpio mode 1 pwm # Set pin 1 to PWM mode
|
||||
.PP
|
||||
gpio pwm 1 512 # Set pin 1 to PWM value 512 - half brightness
|
||||
.PP
|
||||
gpio export 17 out # Set GPIO Pin 17 to output
|
||||
.PP
|
||||
gpio export 0 in # Set GPIO Pin 0 (SDA0) to input.
|
||||
.PP
|
||||
gpio -g read 0 # Read GPIO Pin 0 (SDA0)
|
||||
|
||||
.SH "NOTES"
|
||||
|
||||
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
|
||||
WiringPi's home page
|
||||
.IP
|
||||
http://wiringpi.com/
|
||||
|
||||
.SH AUTHOR
|
||||
|
||||
Gordon Henderson
|
||||
|
||||
.SH "REPORTING BUGS"
|
||||
|
||||
Please report bugs to <projects@drogon.net>
|
||||
|
||||
.SH COPYRIGHT
|
||||
|
||||
Copyright (c) 2012-2018 Gordon Henderson
|
||||
This is free software; see the source for copying conditions. There is NO
|
||||
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
.SH TRADEMARKS AND ACKNOWLEDGEMENTS
|
||||
|
||||
Raspberry Pi is a trademark of the Raspberry Pi Foundation. See
|
||||
http://raspberrypi.org/ for full details.
|
||||
1679
gpio/gpio.c
Normal file
1679
gpio/gpio.c
Normal file
File diff suppressed because it is too large
Load Diff
187
gpio/pintest
Normal file
187
gpio/pintest
Normal file
@@ -0,0 +1,187 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# pintest
|
||||
# Test the Pi's GPIO port
|
||||
# Copyright (c) 2013-2015 Gordon Henderson
|
||||
#################################################################################
|
||||
# This file is part of wiringPi:
|
||||
# A "wiring" 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/>.
|
||||
#################################################################################
|
||||
|
||||
|
||||
# logErr pin, expected got
|
||||
################################################################################
|
||||
|
||||
logErr ()
|
||||
{
|
||||
if [ $errs = 0 ]; then
|
||||
echo ""
|
||||
fi
|
||||
echo " --> Pin $1 failure. Expected $2, got $3"
|
||||
let errs+=1
|
||||
}
|
||||
|
||||
|
||||
# printErrorCount
|
||||
################################################################################
|
||||
|
||||
printErrCount()
|
||||
{
|
||||
if [ $errs = 0 ]; then
|
||||
echo "No faults detected."
|
||||
elif [ $errs = 1 ]; then
|
||||
echo "One fault detected."
|
||||
else
|
||||
echo "$errs faults detected"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# testPins start end
|
||||
################################################################################
|
||||
|
||||
testPins()
|
||||
{
|
||||
start=$1
|
||||
end=$2
|
||||
errs=0
|
||||
|
||||
printf "%30s %2d:%2d: " "$3" $1 $2
|
||||
|
||||
# Set range to inputs
|
||||
|
||||
for i in `seq $start $end`; do
|
||||
gpio mode $i in
|
||||
done
|
||||
|
||||
# Enable internal pull-ups and expect to read high
|
||||
|
||||
for i in `seq $start $end`; do
|
||||
gpio mode $i up
|
||||
if [ `gpio read $i` = 0 ]; then
|
||||
logErr $i 1 0
|
||||
fi
|
||||
done
|
||||
|
||||
# Enable internal pull-downs and expect to read low
|
||||
|
||||
for i in `seq $start $end`; do
|
||||
gpio mode $i down
|
||||
if [ `gpio read $i` = 1 ]; then
|
||||
echo "Pin $i failure - expected 0, got 1"
|
||||
let errs+=1
|
||||
fi
|
||||
done
|
||||
|
||||
# Remove the internal pull up/downs
|
||||
|
||||
for i in `seq $start $end`; do
|
||||
gpio mode $i tri
|
||||
done
|
||||
|
||||
if [ $errs = 0 ]; then
|
||||
echo " OK"
|
||||
else
|
||||
printErrCount
|
||||
fi
|
||||
|
||||
let totErrs+=errs
|
||||
}
|
||||
|
||||
|
||||
intro()
|
||||
{
|
||||
cat <<EOF
|
||||
PinTest
|
||||
=======
|
||||
|
||||
This is a simple utility to test the GPIO pins on your Raspberry Pi.
|
||||
|
||||
NOTE: All GPIO peripherals must be removed to perform this test. This
|
||||
includes serial, I2C and SPI connections. You may get incorrect results
|
||||
if something is connected and it interferes with the test.
|
||||
|
||||
This test can only test the input side of things. It uses the internal
|
||||
pull-up and pull-down resistors to simulate inputs. It does not test
|
||||
the output drivers.
|
||||
|
||||
You will need to reboot your Pi after this test if you wish to use the
|
||||
serial port as it will be left in GPIO mode rather than serial mode.
|
||||
|
||||
This test only tests the original pins present on the Rev A and B. It
|
||||
does not test the extra pins on the Revision A2, B2 nor the A+ or B+
|
||||
|
||||
Please make sure everything is removed and press the ENTER key to continue,
|
||||
EOF
|
||||
|
||||
echo -n "or Control-C to abort... "
|
||||
read a
|
||||
}
|
||||
|
||||
|
||||
# Start here
|
||||
################################################################################
|
||||
|
||||
intro
|
||||
gpio unexportall
|
||||
|
||||
errs=0
|
||||
totErrs=0
|
||||
|
||||
echo ""
|
||||
|
||||
# Main pins
|
||||
|
||||
testPins 0 7 "The main 8 GPIO pins"
|
||||
|
||||
# SPI
|
||||
|
||||
testPins 10 14 "The 5 SPI pins"
|
||||
|
||||
# Serial
|
||||
|
||||
testPins 15 16 "The serial pins"
|
||||
|
||||
# I2C - Needs somewhat different testing
|
||||
# due to the on-board pull-up's
|
||||
|
||||
echo -n " The I2C pins 8: 9: "
|
||||
errs=0
|
||||
gpio mode 8 in
|
||||
gpio mode 9 in
|
||||
|
||||
if [ `gpio read 8` = 0 ]; then
|
||||
echo "Pin 8 failure - expected 1, got 0"
|
||||
let errs+=1
|
||||
fi
|
||||
|
||||
if [ `gpio read 9` = 0 ]; then
|
||||
echo "Pin 9 failure - expected 1, got 0"
|
||||
let errs+=1
|
||||
fi
|
||||
|
||||
if [ $errs = 0 ]; then
|
||||
echo " OK"
|
||||
else
|
||||
printErrCount
|
||||
fi
|
||||
|
||||
echo ""
|
||||
if [ $totErrs != 0 ]; then
|
||||
echo ""
|
||||
echo "Faults detected! Output of 'readall':"
|
||||
gpio readall
|
||||
fi
|
||||
401
gpio/readall.c
Normal file
401
gpio/readall.c
Normal file
@@ -0,0 +1,401 @@
|
||||
/*
|
||||
* readall.c:
|
||||
* The readall functions - getting a bit big, so split them out.
|
||||
* Copyright (c) 2012-2018 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 <ctype.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <wiringPi.h>
|
||||
|
||||
#ifdef CONFIG_ORANGEPI
|
||||
#include "OrangePi.h"
|
||||
#endif
|
||||
|
||||
extern int wpMode ;
|
||||
|
||||
#ifndef TRUE
|
||||
# define TRUE (1==1)
|
||||
# define FALSE (1==2)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* doReadallExternal:
|
||||
* A relatively crude way to read the pins on an external device.
|
||||
* We don't know the input/output mode of pins, but we can tell
|
||||
* if it's an analog pin or a digital one...
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
static void doReadallExternal (void)
|
||||
{
|
||||
int pin ;
|
||||
|
||||
printf ("+------+---------+--------+\n") ;
|
||||
printf ("| Pin | Digital | Analog |\n") ;
|
||||
printf ("+------+---------+--------+\n") ;
|
||||
|
||||
for (pin = wiringPiNodes->pinBase ; pin <= wiringPiNodes->pinMax ; ++pin)
|
||||
printf ("| %4d | %4d | %4d |\n", pin, digitalRead (pin), analogRead (pin)) ;
|
||||
|
||||
printf ("+------+---------+--------+\n") ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* doReadall:
|
||||
* Read all the GPIO pins
|
||||
* We also want to use this to read the state of pins on an externally
|
||||
* connected device, so we need to do some fiddling with the internal
|
||||
* wiringPi node structures - since the gpio command can only use
|
||||
* one external device at a time, we'll use that to our advantage...
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
static char *alts [] =
|
||||
{
|
||||
"IN", "OUT", "ALT2", "ALT3", "ALT4", "ALT5", "ALT6", "OFF"
|
||||
} ;
|
||||
|
||||
#ifndef CONFIG_ORANGEPI
|
||||
static int physToWpi [64] =
|
||||
{
|
||||
-1, // 0
|
||||
-1, -1, // 1, 2
|
||||
8, -1,
|
||||
9, -1,
|
||||
7, 15,
|
||||
-1, 16,
|
||||
0, 1,
|
||||
2, -1,
|
||||
3, 4,
|
||||
-1, 5,
|
||||
12, -1,
|
||||
13, 6,
|
||||
14, 10,
|
||||
-1, 11, // 25, 26
|
||||
30, 31, // Actually I2C, but not used
|
||||
21, -1,
|
||||
22, 26,
|
||||
23, -1,
|
||||
24, 27,
|
||||
25, 28,
|
||||
-1, 29,
|
||||
-1, -1,
|
||||
-1, -1,
|
||||
-1, -1,
|
||||
-1, -1,
|
||||
-1, -1,
|
||||
17, 18,
|
||||
19, 20,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1
|
||||
} ;
|
||||
|
||||
static char *physNames [64] =
|
||||
{
|
||||
NULL,
|
||||
|
||||
" 3.3v", "5v ",
|
||||
" SDA.1", "5v ",
|
||||
" SCL.1", "0v ",
|
||||
"GPIO. 7", "TxD ",
|
||||
" 0v", "RxD ",
|
||||
"GPIO. 0", "GPIO. 1",
|
||||
"GPIO. 2", "0v ",
|
||||
"GPIO. 3", "GPIO. 4",
|
||||
" 3.3v", "GPIO. 5",
|
||||
" MOSI", "0v ",
|
||||
" MISO", "GPIO. 6",
|
||||
" SCLK", "CE0 ",
|
||||
" 0v", "CE1 ",
|
||||
" SDA.0", "SCL.0 ",
|
||||
"GPIO.21", "0v ",
|
||||
"GPIO.22", "GPIO.26",
|
||||
"GPIO.23", "0v ",
|
||||
"GPIO.24", "GPIO.27",
|
||||
"GPIO.25", "GPIO.28",
|
||||
" 0v", "GPIO.29",
|
||||
NULL, NULL,
|
||||
NULL, NULL,
|
||||
NULL, NULL,
|
||||
NULL, NULL,
|
||||
NULL, NULL,
|
||||
"GPIO.17", "GPIO.18",
|
||||
"GPIO.19", "GPIO.20",
|
||||
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
|
||||
} ;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* readallPhys:
|
||||
* Given a physical pin output the data on it and the next pin:
|
||||
*| BCM | wPi | Name | Mode | Val| Physical |Val | Mode | Name | wPi | BCM |
|
||||
*********************************************************************************
|
||||
*/
|
||||
void readallPhys (int physPin)
|
||||
{
|
||||
int pin ;
|
||||
|
||||
if (physPinToGpio (physPin) == -1)
|
||||
printf (" | | ") ;
|
||||
else
|
||||
printf (" | %4d | %3d", physPinToGpio (physPin), physToWpi [physPin]) ;
|
||||
|
||||
printf (" | %s", physNames [physPin]);
|
||||
|
||||
if (physToWpi [physPin] == -1)
|
||||
printf (" | | ") ;
|
||||
else
|
||||
{
|
||||
/**/ if (wpMode == WPI_MODE_GPIO)
|
||||
pin = physPinToGpio (physPin) ;
|
||||
else if (wpMode == WPI_MODE_PHYS)
|
||||
pin = physPin ;
|
||||
else
|
||||
pin = physToWpi [physPin] ;
|
||||
|
||||
printf (" | %4s", alts [getAlt(pin)]) ;
|
||||
printf (" | %d", digitalRead (pin)) ;
|
||||
}
|
||||
|
||||
// Pin numbers:
|
||||
|
||||
printf (" | %2d", physPin) ;
|
||||
++physPin ;
|
||||
printf (" || %-2d", physPin) ;
|
||||
|
||||
// Same, reversed
|
||||
|
||||
if (physToWpi [physPin] == -1)
|
||||
printf (" | | ") ;
|
||||
else
|
||||
{
|
||||
/**/ if (wpMode == WPI_MODE_GPIO)
|
||||
pin = physPinToGpio (physPin) ;
|
||||
else if (wpMode == WPI_MODE_PHYS)
|
||||
pin = physPin ;
|
||||
else
|
||||
pin = physToWpi [physPin] ;
|
||||
|
||||
printf (" | %d", digitalRead (pin)) ;
|
||||
printf (" | %-4s", alts [getAlt (pin)]) ;
|
||||
}
|
||||
|
||||
printf (" | %-5s", physNames [physPin]) ;
|
||||
|
||||
if (physToWpi [physPin] == -1)
|
||||
printf (" | | ") ;
|
||||
else
|
||||
printf (" | %-3d | %-4d", physToWpi [physPin], physPinToGpio (physPin)) ;
|
||||
|
||||
printf (" |\n") ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* allReadall:
|
||||
* Read all the pins regardless of the model. Primarily of use for
|
||||
* the compute module, but handy for other fiddling...
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
static void allReadall (void)
|
||||
{
|
||||
int pin ;
|
||||
|
||||
printf ("+-----+------+-------+ +-----+------+-------+\n") ;
|
||||
printf ("| Pin | Mode | Value | | Pin | Mode | Value |\n") ;
|
||||
printf ("+-----+------+-------+ +-----+------+-------+\n") ;
|
||||
|
||||
for (pin = 0 ; pin < 14 ; ++pin)
|
||||
{
|
||||
printf ("| %3d ", pin) ;
|
||||
printf ("| %-4s ", alts [getAlt (pin)]) ;
|
||||
printf ("| %s ", digitalRead (pin) == HIGH ? "High" : "Low ") ;
|
||||
printf ("| ") ;
|
||||
printf ("| %3d ", pin + 14) ;
|
||||
printf ("| %-4s ", alts [getAlt (pin + 14)]) ;
|
||||
printf ("| %s ", digitalRead (pin + 14) == HIGH ? "High" : "Low ") ;
|
||||
printf ("|\n") ;
|
||||
}
|
||||
|
||||
printf ("+-----+------+-------+ +-----+------+-------+\n") ;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* abReadall:
|
||||
* Read all the pins on the model A or B.
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void abReadall (int model, int rev)
|
||||
{
|
||||
int pin ;
|
||||
char *type ;
|
||||
|
||||
if (model == PI_MODEL_A)
|
||||
type = " A" ;
|
||||
else
|
||||
if (rev == PI_VERSION_2)
|
||||
type = "B2" ;
|
||||
else
|
||||
type = "B1" ;
|
||||
|
||||
printf (" +-----+-----+---------+------+---+-Model %s-+---+------+---------+-----+-----+\n", type) ;
|
||||
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
|
||||
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
|
||||
for (pin = 1 ; pin <= 26 ; pin += 2)
|
||||
readallPhys (pin) ;
|
||||
|
||||
if (rev == PI_VERSION_2) // B version 2
|
||||
{
|
||||
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
|
||||
for (pin = 51 ; pin <= 54 ; pin += 2)
|
||||
readallPhys (pin) ;
|
||||
}
|
||||
|
||||
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
|
||||
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
|
||||
printf (" +-----+-----+---------+------+---+-Model %s-+---+------+---------+-----+-----+\n", type) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* piPlusReadall:
|
||||
* Read all the pins on the model A+ or the B+ or actually, all 40-pin Pi's
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
static void plus2header (int model)
|
||||
{
|
||||
/**/ if (model == PI_MODEL_AP)
|
||||
printf (" +-----+-----+---------+------+---+---Pi A+--+---+------+---------+-----+-----+\n") ;
|
||||
else if (model == PI_MODEL_BP)
|
||||
printf (" +-----+-----+---------+------+---+---Pi B+--+---+------+---------+-----+-----+\n") ;
|
||||
else if (model == PI_MODEL_ZERO)
|
||||
printf (" +-----+-----+---------+------+---+-Pi Zero--+---+------+---------+-----+-----+\n") ;
|
||||
else if (model == PI_MODEL_ZERO_W)
|
||||
printf (" +-----+-----+---------+------+---+-Pi ZeroW-+---+------+---------+-----+-----+\n") ;
|
||||
else if (model == PI_MODEL_2)
|
||||
printf (" +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+\n") ;
|
||||
else if (model == PI_MODEL_3)
|
||||
printf (" +-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+\n") ;
|
||||
else if (model == PI_MODEL_3P)
|
||||
printf (" +-----+-----+---------+------+---+---Pi 3+--+---+------+---------+-----+-----+\n") ;
|
||||
else
|
||||
printf (" +-----+-----+---------+------+---+---Pi ?---+---+------+---------+-----+-----+\n") ;
|
||||
}
|
||||
|
||||
|
||||
static void piPlusReadall (int model)
|
||||
{
|
||||
int pin ;
|
||||
|
||||
plus2header (model) ;
|
||||
|
||||
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
|
||||
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
|
||||
for (pin = 1 ; pin <= 40 ; pin += 2)
|
||||
readallPhys (pin) ;
|
||||
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
|
||||
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
|
||||
|
||||
plus2header (model) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* doReadall:
|
||||
* Generic read all pins called from main program. Works out the Pi type
|
||||
* and calls the appropriate function.
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void doReadall (void)
|
||||
{
|
||||
int model, rev, mem, maker, overVolted ;
|
||||
|
||||
if (wiringPiNodes != NULL) // External readall
|
||||
{
|
||||
doReadallExternal () ;
|
||||
return ;
|
||||
}
|
||||
|
||||
piBoardId (&model, &rev, &mem, &maker, &overVolted) ;
|
||||
|
||||
if ((model == PI_MODEL_A) || (model == PI_MODEL_B))
|
||||
abReadall (model, rev) ;
|
||||
else if ((model == PI_MODEL_BP) || (model == PI_MODEL_AP) ||
|
||||
(model == PI_MODEL_2) ||
|
||||
(model == PI_MODEL_3) || (model == PI_MODEL_3P) ||
|
||||
(model == PI_MODEL_ZERO) || (model == PI_MODEL_ZERO_W))
|
||||
piPlusReadall (model) ;
|
||||
else if ((model == PI_MODEL_CM) || (model == PI_MODEL_CM3))
|
||||
allReadall () ;
|
||||
else if ( model == PI_MODEL_ORANGEPI)
|
||||
OrangePiReadAll();
|
||||
else
|
||||
printf ("Oops - unable to determine board type... model: %d\n", model) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* doAllReadall:
|
||||
* Force reading of all pins regardless of Pi model
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void doAllReadall (void)
|
||||
{
|
||||
allReadall () ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* doQmode:
|
||||
* Query mode on a pin
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void doQmode (int argc, char *argv [])
|
||||
{
|
||||
int pin ;
|
||||
|
||||
if (argc != 3)
|
||||
{
|
||||
fprintf (stderr, "Usage: %s qmode pin\n", argv [0]) ;
|
||||
exit (EXIT_FAILURE) ;
|
||||
}
|
||||
|
||||
pin = atoi (argv [2]) ;
|
||||
printf ("%s\n", alts [getAlt (pin)]) ;
|
||||
}
|
||||
44
gpio/test.sh
Normal file
44
gpio/test.sh
Normal file
@@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# test.sh:
|
||||
# Simple test: Assumes LEDs on Pins 0-7 and lights them
|
||||
# in-turn.
|
||||
#################################################################################
|
||||
# This file is part of wiringPi:
|
||||
# A "wiring" 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.
|
||||
|
||||
for i in `seq 0 7`;
|
||||
do
|
||||
gpio mode $i out
|
||||
done
|
||||
|
||||
while true;
|
||||
do
|
||||
for i in `seq 0 7`;
|
||||
do
|
||||
gpio write $i 1
|
||||
sleep 0.1
|
||||
done
|
||||
|
||||
for i in `seq 0 7`;
|
||||
do
|
||||
gpio write $i 0
|
||||
sleep 0.1
|
||||
done
|
||||
done
|
||||
Reference in New Issue
Block a user