initial cleanup and mapping

This commit is contained in:
unknown
2016-08-18 21:52:18 +03:00
parent 1d89a05234
commit faf062af8b
155 changed files with 23233 additions and 0 deletions

165
gpio/COPYING.LESSER Normal file
View 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.

87
gpio/Makefile Normal file
View File

@@ -0,0 +1,87 @@
#
# Makefile:
# The gpio command:
# A swiss-army knige of GPIO shenanigans.
# https://projects.drogon.net/wiring-pi
#
# Copyright (c) 2012-2013 Gordon Henderson
#################################################################################
# This file is part of wiringPi:
# Wiring Compatable library for the Raspberry Pi
#
# wiringPi is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wiringPi is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
#################################################################################
DESTDIR=/usr
PREFIX=/local
#DEBUG = -g -O0
DEBUG = -O2
CC = gcc
INCLUDE = -I$(DESTDIR)$(PREFIX)/include
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
LDFLAGS = -L$(DESTDIR)$(PREFIX)/lib
LIBS = -lwiringPi -lwiringPiDev -lpthread -lm
# May not need to alter anything below this line
###############################################################################
SRC = gpio.c extensions.c readall.c pins.c
OBJ = $(SRC:.c=.o)
all: gpio
gpio: $(OBJ)
@echo [Link]
@$(CC) -o $@ $(OBJ) $(LDFLAGS) $(LIBS)
.c.o:
@echo [Compile] $<
@$(CC) -c $(CFLAGS) $< -o $@
.PHONY: clean
clean:
@echo "[Clean]"
@rm -f $(OBJ) gpio *~ core tags *.bak
.PHONY: tags
tags: $(SRC)
@echo [ctags]
@ctags $(SRC)
.PHONY: install
install:
@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
.PHONY: uninstall
uninstall:
@echo "[UnInstall]"
@rm -f $(DESTDIR)$(PREFIX)/bin/gpio
@rm -f $(DESTDIR)$(PREFIX)/man/man1/gpio.1
.PHONY: depend
depend:
makedepend -Y $(SRC)
# DO NOT DELETE
gpio.o: extensions.h
extensions.o: extensions.h

700
gpio/extensions.c Normal file
View File

@@ -0,0 +1,700 @@
/*
* extensions.c:
* Part of the GPIO program to test, peek, poke and otherwise
* noodle with the GPIO hardware on the Raspberry Pi.
* Copyright (c) 2012-2013 Gordon Henderson
***********************************************************************
* 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 <sys/types.h>
#include <fcntl.h>
#include <wiringPi.h>
#include <mcp23008.h>
#include <mcp23016.h>
#include <mcp23017.h>
#include <mcp23s08.h>
#include <mcp23s17.h>
#include <sr595.h>
#include <pcf8591.h>
#include <pcf8574.h>
#include <max31855.h>
#include <max5322.h>
#include <mcp3002.h>
#include <mcp3004.h>
#include <mcp4802.h>
#include <mcp3422.h>
#include <sn3218.h>
#include <drcSerial.h>
#include "extensions.h"
extern int wiringPiDebug ;
#ifndef TRUE
# define TRUE (1==1)
# define FALSE (1==2)
#endif
// Local structure to hold details
struct extensionFunctionStruct
{
const char *name ;
int (*function)(char *progName, int pinBase, char *params) ;
} ;
/*
* extractInt:
* Check & return an integer at the given location (prefixed by a :)
*********************************************************************************
*/
static char *extractInt (char *progName, char *p, int *num)
{
if (*p != ':')
{
fprintf (stderr, "%s: colon expected\n", progName) ;
return NULL ;
}
++p ;
if (!isdigit (*p))
{
fprintf (stderr, "%s: digit expected\n", progName) ;
return NULL ;
}
*num = strtol (p, NULL, 0) ;
while (isdigit (*p))
++p ;
return p ;
}
/*
* extractStr:
* Check & return a string at the given location (prefixed by a :)
*********************************************************************************
*/
static char *extractStr (char *progName, char *p, char **str)
{
char *q, *r ;
if (*p != ':')
{
fprintf (stderr, "%s: colon expected\n", progName) ;
return NULL ;
}
++p ;
if (!isprint (*p))
{
fprintf (stderr, "%s: character expected\n", progName) ;
return NULL ;
}
q = p ;
while ((*q != 0) && (*q != ':'))
++q ;
*str = r = calloc (q - p + 2, 1) ; // Zeros it
while (p != q)
*r++ = *p++ ;
return p ;
}
/*
* doExtensionMcp23008:
* MCP23008 - 8-bit I2C GPIO expansion chip
* mcp23002:base:i2cAddr
*********************************************************************************
*/
static int doExtensionMcp23008 (char *progName, int pinBase, char *params)
{
int i2c ;
if ((params = extractInt (progName, params, &i2c)) == NULL)
return FALSE ;
if ((i2c < 0x03) || (i2c > 0x77))
{
fprintf (stderr, "%s: i2c address (0x%X) out of range\n", progName, i2c) ;
return FALSE ;
}
mcp23008Setup (pinBase, i2c) ;
return TRUE ;
}
/*
* doExtensionMcp23016:
* MCP230016- 16-bit I2C GPIO expansion chip
* mcp23016:base:i2cAddr
*********************************************************************************
*/
static int doExtensionMcp23016 (char *progName, int pinBase, char *params)
{
int i2c ;
if ((params = extractInt (progName, params, &i2c)) == NULL)
return FALSE ;
if ((i2c < 0x03) || (i2c > 0x77))
{
fprintf (stderr, "%s: i2c address (0x%X) out of range\n", progName, i2c) ;
return FALSE ;
}
mcp23016Setup (pinBase, i2c) ;
return TRUE ;
}
/*
* doExtensionMcp23017:
* MCP230017- 16-bit I2C GPIO expansion chip
* mcp23017:base:i2cAddr
*********************************************************************************
*/
static int doExtensionMcp23017 (char *progName, int pinBase, char *params)
{
int i2c ;
if ((params = extractInt (progName, params, &i2c)) == NULL)
return FALSE ;
if ((i2c < 0x03) || (i2c > 0x77))
{
fprintf (stderr, "%s: i2c address (0x%X) out of range\n", progName, i2c) ;
return FALSE ;
}
mcp23017Setup (pinBase, i2c) ;
return TRUE ;
}
/*
* doExtensionMcp23s08:
* MCP23s08 - 8-bit SPI GPIO expansion chip
* mcp23s08:base:spi:port
*********************************************************************************
*/
static int doExtensionMcp23s08 (char *progName, int pinBase, char *params)
{
int spi, port ;
if ((params = extractInt (progName, params, &spi)) == NULL)
return FALSE ;
if ((spi < 0) || (spi > 1))
{
fprintf (stderr, "%s: SPI address (%d) out of range\n", progName, spi) ;
return FALSE ;
}
if ((params = extractInt (progName, params, &port)) == NULL)
return FALSE ;
if ((port < 0) || (port > 7))
{
fprintf (stderr, "%s: port address (%d) out of range\n", progName, port) ;
return FALSE ;
}
mcp23s08Setup (pinBase, spi, port) ;
return TRUE ;
}
/*
* doExtensionMcp23s17:
* MCP23s17 - 16-bit SPI GPIO expansion chip
* mcp23s17:base:spi:port
*********************************************************************************
*/
static int doExtensionMcp23s17 (char *progName, int pinBase, char *params)
{
int spi, port ;
if ((params = extractInt (progName, params, &spi)) == NULL)
return FALSE ;
if ((spi < 0) || (spi > 1))
{
fprintf (stderr, "%s: SPI address (%d) out of range\n", progName, spi) ;
return FALSE ;
}
if ((params = extractInt (progName, params, &port)) == NULL)
return FALSE ;
if ((port < 0) || (port > 7))
{
fprintf (stderr, "%s: port address (%d) out of range\n", progName, port) ;
return FALSE ;
}
mcp23s17Setup (pinBase, spi, port) ;
return TRUE ;
}
/*
* doExtensionSr595:
* Shift Register 74x595
* sr595:base:pins:data:clock:latch
*********************************************************************************
*/
static int doExtensionSr595 (char *progName, int pinBase, char *params)
{
int pins, data, clock, latch ;
// Extract pins
if ((params = extractInt (progName, params, &pins)) == NULL)
return FALSE ;
if ((pins < 8) || (pins > 32))
{
fprintf (stderr, "%s: pin count (%d) out of range - 8-32 expected.\n", progName, pins) ;
return FALSE ;
}
if ((params = extractInt (progName, params, &data)) == NULL)
return FALSE ;
if ((params = extractInt (progName, params, &clock)) == NULL)
return FALSE ;
if ((params = extractInt (progName, params, &latch)) == NULL)
return FALSE ;
sr595Setup (pinBase, pins, data, clock, latch) ;
return TRUE ;
}
/*
* doExtensionPcf8574:
* Digital IO (Crude!)
* pcf8574:base:i2cAddr
*********************************************************************************
*/
static int doExtensionPcf8574 (char *progName, int pinBase, char *params)
{
int i2c ;
if ((params = extractInt (progName, params, &i2c)) == NULL)
return FALSE ;
if ((i2c < 0x03) || (i2c > 0x77))
{
fprintf (stderr, "%s: i2c address (0x%X) out of range\n", progName, i2c) ;
return FALSE ;
}
pcf8574Setup (pinBase, i2c) ;
return TRUE ;
}
/*
* doExtensionPcf8591:
* Analog IO
* pcf8591:base:i2cAddr
*********************************************************************************
*/
static int doExtensionPcf8591 (char *progName, int pinBase, char *params)
{
int i2c ;
if ((params = extractInt (progName, params, &i2c)) == NULL)
return FALSE ;
if ((i2c < 0x03) || (i2c > 0x77))
{
fprintf (stderr, "%s: i2c address (0x%X) out of range\n", progName, i2c) ;
return FALSE ;
}
pcf8591Setup (pinBase, i2c) ;
return TRUE ;
}
/*
* doExtensionMax31855:
* Analog IO
* max31855:base:spiChan
*********************************************************************************
*/
static int doExtensionMax31855 (char *progName, int pinBase, char *params)
{
int spi ;
if ((params = extractInt (progName, params, &spi)) == NULL)
return FALSE ;
if ((spi < 0) || (spi > 1))
{
fprintf (stderr, "%s: SPI channel (%d) out of range\n", progName, spi) ;
return FALSE ;
}
max31855Setup (pinBase, spi) ;
return TRUE ;
}
/*
* doExtensionMcp3002:
* Analog IO
* mcp3002:base:spiChan
*********************************************************************************
*/
static int doExtensionMcp3002 (char *progName, int pinBase, char *params)
{
int spi ;
if ((params = extractInt (progName, params, &spi)) == NULL)
return FALSE ;
if ((spi < 0) || (spi > 1))
{
fprintf (stderr, "%s: SPI channel (%d) out of range\n", progName, spi) ;
return FALSE ;
}
mcp3002Setup (pinBase, spi) ;
return TRUE ;
}
/*
* doExtensionMcp3004:
* Analog IO
* mcp3004:base:spiChan
*********************************************************************************
*/
static int doExtensionMcp3004 (char *progName, int pinBase, char *params)
{
int spi ;
if ((params = extractInt (progName, params, &spi)) == NULL)
return FALSE ;
if ((spi < 0) || (spi > 1))
{
fprintf (stderr, "%s: SPI channel (%d) out of range\n", progName, spi) ;
return FALSE ;
}
mcp3004Setup (pinBase, spi) ;
return TRUE ;
}
/*
* doExtensionMax5322:
* Analog O
* max5322:base:spiChan
*********************************************************************************
*/
static int doExtensionMax5322 (char *progName, int pinBase, char *params)
{
int spi ;
if ((params = extractInt (progName, params, &spi)) == NULL)
return FALSE ;
if ((spi < 0) || (spi > 1))
{
fprintf (stderr, "%s: SPI channel (%d) out of range\n", progName, spi) ;
return FALSE ;
}
max5322Setup (pinBase, spi) ;
return TRUE ;
}
/*
* doExtensionMcp4802:
* Analog IO
* mcp4802:base:spiChan
*********************************************************************************
*/
static int doExtensionMcp4802 (char *progName, int pinBase, char *params)
{
int spi ;
if ((params = extractInt (progName, params, &spi)) == NULL)
return FALSE ;
if ((spi < 0) || (spi > 1))
{
fprintf (stderr, "%s: SPI channel (%d) out of range\n", progName, spi) ;
return FALSE ;
}
mcp4802Setup (pinBase, spi) ;
return TRUE ;
}
/*
* doExtensionSn3218:
* Analog Output (LED Driver)
* sn3218:base
*********************************************************************************
*/
static int doExtensionSn3218 (char *progName, int pinBase, char *params)
{
sn3218Setup (pinBase) ;
return TRUE ;
}
/*
* doExtensionMcp3422:
* Analog IO
* mcp3422:base:i2cAddr
*********************************************************************************
*/
static int doExtensionMcp3422 (char *progName, int pinBase, char *params)
{
int i2c, sampleRate, gain ;
if ((params = extractInt (progName, params, &i2c)) == NULL)
return FALSE ;
if ((i2c < 0x03) || (i2c > 0x77))
{
fprintf (stderr, "%s: i2c address (0x%X) out of range\n", progName, i2c) ;
return FALSE ;
}
if ((params = extractInt (progName, params, &sampleRate)) == NULL)
return FALSE ;
if ((sampleRate < 0) || (sampleRate > 3))
{
fprintf (stderr, "%s: sample rate (%d) out of range\n", progName, sampleRate) ;
return FALSE ;
}
if ((params = extractInt (progName, params, &gain)) == NULL)
return FALSE ;
if ((gain < 0) || (gain > 3))
{
fprintf (stderr, "%s: gain (%d) out of range\n", progName, gain) ;
return FALSE ;
}
mcp3422Setup (pinBase, i2c, sampleRate, gain) ;
return TRUE ;
}
/*
* doExtensionDrcS:
* Interface to a DRC Serial system
* drcs:base:pins:serialPort:baud
*********************************************************************************
*/
static int doExtensionDrcS (char *progName, int pinBase, char *params)
{
char *port ;
int pins, baud ;
if ((params = extractInt (progName, params, &pins)) == NULL)
return FALSE ;
if ((pins < 1) || (pins > 100))
{
fprintf (stderr, "%s: pins (%d) out of range (2-100)\n", progName, pins) ;
return FALSE ;
}
if ((params = extractStr (progName, params, &port)) == NULL)
return FALSE ;
if (strlen (port) == 0)
{
fprintf (stderr, "%s: serial port device name required\n", progName) ;
return FALSE ;
}
if ((params = extractInt (progName, params, &baud)) == NULL)
return FALSE ;
if ((baud < 1) || (baud > 4000000))
{
fprintf (stderr, "%s: baud rate (%d) out of range\n", progName, baud) ;
return FALSE ;
}
drcSetupSerial (pinBase, pins, port, baud) ;
return TRUE ;
}
/*
* Function list
*********************************************************************************
*/
struct extensionFunctionStruct extensionFunctions [] =
{
{ "mcp23008", &doExtensionMcp23008 },
{ "mcp23016", &doExtensionMcp23016 },
{ "mcp23017", &doExtensionMcp23017 },
{ "mcp23s08", &doExtensionMcp23s08 },
{ "mcp23s17", &doExtensionMcp23s17 },
{ "sr595", &doExtensionSr595 },
{ "pcf8574", &doExtensionPcf8574 },
{ "pcf8591", &doExtensionPcf8591 },
{ "mcp3002", &doExtensionMcp3002 },
{ "mcp3004", &doExtensionMcp3004 },
{ "mcp4802", &doExtensionMcp4802 },
{ "mcp3422", &doExtensionMcp3422 },
{ "max31855", &doExtensionMax31855 },
{ "max5322", &doExtensionMax5322 },
{ "sn3218", &doExtensionSn3218 },
{ "drcs", &doExtensionDrcS },
{ NULL, NULL },
} ;
/*
* doExtension:
* Load in a wiringPi extension
*********************************************************************************
*/
int doExtension (char *progName, char *extensionData)
{
char *p ;
char *extension = extensionData ;
struct extensionFunctionStruct *extensionFn ;
int pinBase = 0 ;
// Get the extension extension name by finding the first colon
p = extension ;
while (*p != ':')
{
if (!*p) // ran out of characters
{
fprintf (stderr, "%s: extension name not terminated by a colon\n", progName) ;
return FALSE ;
}
++p ;
}
*p++ = 0 ;
if (!isdigit (*p))
{
fprintf (stderr, "%s: pinBase number expected after extension name\n", progName) ;
return FALSE ;
}
while (isdigit (*p))
{
if (pinBase > 1000000000)
{
fprintf (stderr, "%s: pinBase too large\n", progName) ;
return FALSE ;
}
pinBase = pinBase * 10 + (*p - '0') ;
++p ;
}
if (pinBase < 64)
{
fprintf (stderr, "%s: pinBase (%d) too small. Minimum is 64.\n", progName, pinBase) ;
return FALSE ;
}
// Search for extensions:
for (extensionFn = extensionFunctions ; extensionFn->name != NULL ; ++extensionFn)
{
if (strcmp (extensionFn->name, extension) == 0)
return extensionFn->function (progName, pinBase, p) ;
}
fprintf (stderr, "%s: extension %s not found\n", progName, extension) ;
return FALSE ;
}

26
gpio/extensions.h Normal file
View File

@@ -0,0 +1,26 @@
/*
* extensions.h:
* Part of the GPIO program to test, peek, poke and otherwise
* noodle with the GPIO hardware on the Raspberry Pi.
* Copyright (c) 2012-2013 Gordon Henderson
***********************************************************************
* 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/>.
***********************************************************************
*/
extern int doExtension (char *progName, char *extensionData) ;

371
gpio/gpio.1 Normal file
View File

@@ -0,0 +1,371 @@
.TH "GPIO" "March 2013" "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/clock ...
.PP
.B gpio
.B [ \-x extension:params ]
.B mode/read/write/aread/awrite/pwm/pwmTone ...
.PP
.B gpio
.B [ \-p ]
.B read/write/toggle/wb
.B ...
.PP
.B gpio
.B readall/reset
.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 aread <pin>
Read the analog value of the given pin. This needs to be uses in
conjunction with a -x flag to add in an extension that handles analog
inputs. respective logic levels.
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. respective logic levels.
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 reset
Resets the GPIO - As much as it's possible to do. All pins are set to
input mode and all the internal pull-up/down resistors are disconnected
(tristate mode).
The reset command is usable with an extension module (via the -x parameter),
but it's limited to turning the pin into input mode (if applicable) and
removing any pull up/down resistor.
.TP
.B pwm <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.
.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 and \fIout\fR are supported at
this time. Note that the pin number is the \fBBCM_GPIO\fR number and
not the wiringPi number.
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+
.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 load i2c [baudrate]
This loads the i2c or drivers into the kernel and changes the permissions
on the associated /dev/ entries so that the current user has access to
them. Optionally it will set the I2C baudrate to that supplied in Kb/sec
(or as close as the Pi can manage) The default speed is 100Kb/sec.
.TP
.B load spi [buffer size in KB]
This loads the spi drivers into the kernel and changes the permissions
on the associated /dev/ entries so that the current user has access to
them. Optionally it will set the SPI buffer size to that supplied. The
default is 4KB.
.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"
.PP
.TS
c c c c l.
WiringPi GPIO-r1 GPIO-r2 P1-Phys Function
_
0 17 17 11
1 18 18 12 (PWM)
2 21 27 13
3 22 22 15
4 23 23 16
5 24 24 18
6 25 25 22
7 4 4 7
8 0 2 3 I2C: SDA0
9 1 3 5 I2C: SCL0
10 8 8 24 SPI: CE0
11 7 7 26 SPI: CE1
12 10 10 19 SPI: MOSI
13 9 9 21 SPI: MISO
14 11 11 23 SPI: SCLK
15 14 14 8 TxD
16 15 16 10 RxD
17 - 28
18 - 29
19 - 30
20 - 31
.TE
Note that "r1" and "r2" above refers to the board revision. Normally
wiringPi detects the correct board revision with use for it's own
numbering scheme, but if you are using a Revision 2 board with some
of the pins which change numbers between revisions you will need
to alter your software.
.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.
.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-2013 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.

1453
gpio/gpio.c Normal file

File diff suppressed because it is too large Load Diff

33
gpio/pins.c Normal file
View File

@@ -0,0 +1,33 @@
/*
* pins.c:
* Just display a handy Pi pinnout diagram.
* Copyright (c) 2012-2013 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>
void doPins (void)
{
printf ("The pins command has been deprecated - sorry. Please use the\n") ;
printf (" gpio readall\n") ;
printf ("command to get a list of the pinnouts for your Pi.\n") ;
}

193
gpio/pintest Normal file
View File

@@ -0,0 +1,193 @@
#!/bin/bash
#
# pintest
# Test the Pi's GPIO port
# Copyright (c) 2013 Gordon Henderson
#################################################################################
# This file is part of wiringPi:
# Wiring Compatable library for the Raspberry Pi
#
# wiringPi is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wiringPi is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with wiringPi. If not, see <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()
{
revision=`gpio -V`
cat <<EOF
PinTest
=======
This is a simple utility to test the GPIO pins on your revision $revision
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.
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
gpio reset
errs=0
totErrs=0
echo ""
# Main pins
testPins 0 7 "The main 8 GPIO pins"
# P5 pins, if a rev 2:
if [ $revision = 2 ]; then
testPins 17 20 "The 4 pins on the P5 connector"
fi
# 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

381
gpio/readall.c Normal file
View File

@@ -0,0 +1,381 @@
/*
* readall.c:
* The readall functions - getting a bit big, so split them out.
* Copyright (c) 2012-2013 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>
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", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3"
} ;
/* guenter 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,
-1, -1,
-1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1
} ;
guenter ende */
// guenter anfang
static int physToWpi [64] =
{
-1, // 0
-1, -1, // 1, 2
8, -1, // 3, 4
9, -1, // 5, 6
7, 15, // 7, 8
-1, 16, // 9, 10
0, 1, //11, 12
2, -1, //13, 14
3, 4, //15, 16
-1, 5, //17, 18
12, -1, //19, 20
13, 6, //21, 22
14, 10, //23, 24
-1, 11, //25, 26
30, 31, //27, 28
21, -1, //29, 30
22, 26, //31, 32
23, -1, //33, 34
24, 27, //35, 36
25, 28, //37, 38
-1, 29, //39, 40
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //41-> 55
-1, -1, -1, -1, -1, -1, -1, -1 // 56-> 63
} ;
//guenter ende
/* guenter 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,
} ; guenter ende */
//guenter orange pi
static char *physNames [64] =
{
NULL,
" 3.3v", "5v ",
" SDA.0", "5V ",
" SCL.0", "0v ",
" GPIO.7", "TxD3 ",
" 0v", "RxD3 ",
" RxD2", "GPIO.1 ",
" TxD2", "0v ",
" CTS2", "GPIO.4 ",
" 3.3v", "GPIO.5 ",
" MOSI", "0v ",
" MISO", "RTS2 ",
" SCLK", "CE0 ",
" 0v", "GPIO.11 ",
" SDA.1", "SCL.1 ",
" GPIO.21", "0v ",
" GPIO.22", "RTS1 ",
" GPIO.23", "0v ",
" GPIO.24", "CTS1 ",
" GPIO.25", "TxD1 ",
" 0v", "RxD1 ",
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,
} ;
// guenter ende
/*
* 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 |
*********************************************************************************
*/
static void readallPhys (int physPin)
{
int pin ;
if (physPinToGpio (physPin) == -1)
printf (" | | ") ;
else
printf (" | %3d | %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 | %-3d", physToWpi [physPin], physPinToGpio (physPin)) ;
printf (" |\n") ;
}
void cmReadall (void)
{
int pin ;
printf ("+-----+------+-------+ +-----+------+-------+\n") ;
printf ("| Pin | Mode | Value | | Pin | Mode | Value |\n") ;
printf ("+-----+------+-------+ +-----+------+-------+\n") ;
for (pin = 0 ; pin < 28 ; ++pin)
{
printf ("| %3d ", pin) ;
printf ("| %-4s ", alts [getAlt (pin)]) ;
printf ("| %s ", digitalRead (pin) == HIGH ? "High" : "Low ") ;
printf ("| ") ;
printf ("| %3d ", pin + 28) ;
printf ("| %-4s ", alts [getAlt (pin + 28)]) ;
printf ("| %s ", digitalRead (pin + 28) == HIGH ? "High" : "Low ") ;
printf ("|\n") ;
}
printf ("+-----+------+-------+ +-----+------+-------+\n") ;
}
/*
* bPlusReadall:
* Read all the pins on the model B+
*********************************************************************************
*/
void bPlusReadall (void)
{
int pin ;
printf (" +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\n") ;
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") ;
printf (" +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\n") ;
}
//add for BananaPro by lemaker team
void BPReadAll(void)
{
int pin ;
printf (" +-----+-----+---------+------+---+--Banana Pro--+---+------+---------+-----+-----+\n") ;
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") ;
printf (" +-----+-----+---------+------+---+--Banana Pro--+---+------+---------+-----+-----+\n") ;
}
//end 2014.09.26
//guenter
void NanoPiReadAll(void)
{
int pin ;
printf (" +-----+-----+----------+------+---+--NanoPI M1---+---+------+---------+-----+--+\n") ;
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") ;
printf (" +-----+-----+----------+------+---+--NanoPI M1---+------+----------+-----+-----+\n") ;
}
//guenter ende
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_M1) {
NanoPiReadAll();
}
else
printf ("Oops - unable to determine board type... model: %d\n", model) ;
}

44
gpio/test.sh Normal file
View 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:
# 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.
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