changed to pin mode to support softPwm.

bugfix in blink.sh - wring pin
improving the maxdetect routing - a little.
gpio pins
This commit is contained in:
Gordon Henderson
2014-05-20 11:43:07 +01:00
parent f18c8f7204
commit 05e2f67e7f
11 changed files with 281 additions and 21 deletions

View File

@@ -38,7 +38,7 @@ LIBS = -lwiringPi -lwiringPiDev -lpthread -lm
# May not need to alter anything below this line
###############################################################################
SRC = gpio.c extensions.c readall.c
SRC = gpio.c extensions.c readall.c pins.c
OBJ = $(SRC:.c=.o)
@@ -52,17 +52,17 @@ gpio: $(OBJ)
@echo [Compile] $<
@$(CC) -c $(CFLAGS) $< -o $@
.PHONEY: clean
.PHONY: clean
clean:
@echo "[Clean]"
@rm -f $(OBJ) gpio *~ core tags *.bak
.PHONEY: tags
.PHONY: tags
tags: $(SRC)
@echo [ctags]
@ctags $(SRC)
.PHONEY: install
.PHONY: install
install:
@echo "[Install]"
@cp gpio $(DESTDIR)$(PREFIX)/bin
@@ -71,13 +71,13 @@ install:
@mkdir -p $(DESTDIR)$(PREFIX)/man/man1
@cp gpio.1 $(DESTDIR)$(PREFIX)/man/man1
.PHONEY: uninstall
.PHONY: uninstall
uninstall:
@echo "[UnInstall]"
@rm -f $(DESTDIR)$(PREFIX)/bin/gpio
@rm -f $(DESTDIR)$(PREFIX)/man/man1/gpio.1
.PHONEY: depend
.PHONY: depend
depend:
makedepend -Y $(SRC)

View File

@@ -114,6 +114,28 @@ respective logic levels.
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
@@ -132,8 +154,9 @@ 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).
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

View File

@@ -43,15 +43,19 @@
extern int wiringPiDebug ;
// External functions I can't be bothered creating a separate .h file for:
extern void doReadall (void) ;
extern void doReadallOld (void) ;
extern void doPins (void) ;
#ifndef TRUE
# define TRUE (1==1)
# define FALSE (1==2)
#endif
#define VERSION "2.13"
#define VERSION "2.14"
#define I2CDETECT "/usr/sbin/i2cdetect"
int wpMode ;
@@ -1078,7 +1082,7 @@ int main (int argc, char *argv [])
if (strcmp (argv [1], "-v") == 0)
{
printf ("gpio version: %s\n", VERSION) ;
printf ("Copyright (c) 2012-2013 Gordon Henderson\n") ;
printf ("Copyright (c) 2012-2014 Gordon Henderson\n") ;
printf ("This is free software with ABSOLUTELY NO WARRANTY.\n") ;
printf ("For details type: %s -warranty\n", argv [0]) ;
printf ("\n") ;
@@ -1220,6 +1224,7 @@ int main (int argc, char *argv [])
else if (strcasecmp (argv [1], "drive" ) == 0) doPadDrive (argc, argv) ;
else if (strcasecmp (argv [1], "readall" ) == 0) doReadallOld () ;
else if (strcasecmp (argv [1], "nreadall" ) == 0) doReadall () ;
else if (strcasecmp (argv [1], "pins" ) == 0) doPins () ;
else if (strcasecmp (argv [1], "i2cdetect") == 0) doI2Cdetect (argc, argv) ;
else if (strcasecmp (argv [1], "i2cd" ) == 0) doI2Cdetect (argc, argv) ;
else if (strcasecmp (argv [1], "reset" ) == 0) doReset (argv [0]) ;

70
gpio/pins.c Normal file
View File

@@ -0,0 +1,70 @@
/*
* 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>
#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 ;
void doPins (void)
{
printf ("This Raspberry Pi is a revision %d board.\n", piBoardRev ()) ;
printf (
" +-----+--------+------------+--------+-----+\n"
" | Pin | Name || P1 Pin || Name | Pin |\n"
" +-----+--------+------------+--------+-----+\n"
" | | 3.3v || 1 oo 2 || 5v | |\n"
" | 8 | SDA || 3 oo 4 || 5v | |\n"
" | 9 | SCL || 5 oo 6 || Gnd | |\n"
" | 7 | GPIO 7 || 7 oo 8 || TxD | 15 |\n"
" | | GND || 9 oo 10 || RxD | 16 |\n"
" | 0 | GPIO 0 || 11 oo 12 || GPIO 1 | 1 |\n"
" | 2 | GPIO 2 || 13 oo 14 || Gnd | |\n"
" | 3 | GPIO 3 || 15 oo 16 || GPIO 4 | 4 |\n"
" | | 3.3v || 17 oo 18 || GPIO 5 | 5 |\n"
" | 12 | MOSI || 19 oo 20 || Gnd | |\n"
" | 13 | MISO || 21 oo 22 || GPIO 6 | 6 |\n"
" | 14 | SCLK || 23 oo 24 || CE 0 | 10 |\n"
" | | Gnd || 25 oo 26 || CE 1 | 11 |\n"
" +-----+--------+------------+--------+-----+\n") ;
/***
+---
| 5v| 5v| Gnd | TxD | RxD | G1 | Gnd | G4 | G5 | G
| 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 |\n"
| 1 | 3 | 5 | 7 | 9 | 11 | 13 | 15 | 17 | 19 | 21 | 23 | 25 |\n"
***/
}