Synced to git.drogon.net
This commit is contained in:
parent
dda3305ce1
commit
3fbc564d00
|
@ -0,0 +1,48 @@
|
|||
|
||||
How to install wiringPi
|
||||
=======================
|
||||
|
||||
The easiest way is to use the supplied 'build' script:
|
||||
|
||||
./build
|
||||
|
||||
that should do a complete install or upgrade of wiringPi for you.
|
||||
|
||||
That will install a dynamic library.
|
||||
|
||||
Some distributions do not have /usr/local/lib in the default LD_LIBRARY_PATH. To
|
||||
fix this, you need to edit /etc/ld.so.conf and add in a single line:
|
||||
|
||||
/usr/local/lib
|
||||
|
||||
then run the ldconfig command.
|
||||
|
||||
sudo ldconfig
|
||||
|
||||
If you want to install a static library, you may need to do this manually:
|
||||
|
||||
cd wiringPi
|
||||
make static
|
||||
sudo make install-static
|
||||
|
||||
|
||||
To un-install wiringPi:
|
||||
|
||||
./build uninstall
|
||||
|
||||
|
||||
I2C:
|
||||
|
||||
If your system has the correct i2c-dev libraries and headers installed,
|
||||
then the I2C helpers will be compiled into wiringPi. If you want to
|
||||
use the I2C helpers and don't have them installed, then under Raspbian,
|
||||
issue the command:
|
||||
|
||||
sudo apt-get install libi2c-dev
|
||||
|
||||
Consult the documentation for your system if you are not running Raspbian.
|
||||
|
||||
Gordon Henderson
|
||||
|
||||
projects@drogon.net
|
||||
https://projects.drogon.net/
|
12
People
12
People
|
@ -13,3 +13,15 @@ Chris McSweeny
|
|||
inside the dealyMicrosecondsHard() function.
|
||||
And spotting a couple of schoolboy errors in the (experimental)
|
||||
softServo code, prompting me to completely re-write it.
|
||||
|
||||
Armin (Via projects website)
|
||||
Some pointers about the i2c-dev.h files.
|
||||
|
||||
Arno Wagner
|
||||
Suggestions for the mmap calls in wiringPiSetup()
|
||||
|
||||
CHARLES Thibaut:
|
||||
A small issue in softTone
|
||||
|
||||
Xian Stannard
|
||||
Fixing some typos in the man page!
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
wiringPi README
|
||||
===============
|
||||
|
||||
Please note that the official way to get wiringPi is via git from
|
||||
git.drogon.net and not GitHub.
|
||||
|
||||
ie.
|
||||
|
||||
git clone git://git.drogon.net/wiringPi
|
||||
|
||||
The version of wiringPi held on GitHub by "Gadgetoid" is used to build the
|
||||
wiringPython, Ruby, Perl, etc. wrappers for these other languages. This
|
||||
version may lag the official Drogon release. Pull requests may not be
|
||||
accepted to Github....
|
||||
|
||||
Please see
|
||||
|
||||
https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
|
||||
for the official documentation, etc. and the best way to submit bug reports, etc.
|
||||
is by sending an email to projects@drogon.net
|
||||
|
||||
Thanks!
|
||||
|
||||
-Gordon
|
63
build
63
build
|
@ -1,5 +1,18 @@
|
|||
#!/bin/bash
|
||||
|
||||
check-make-ok()
|
||||
{
|
||||
if [ $? != 0 ]; then
|
||||
echo ""
|
||||
echo "Make Failed..."
|
||||
echo "Please check the messages and fix any problems. If you're still stuck,"
|
||||
echo "then please email all the output and as many details as you can to"
|
||||
echo " projects@drogon.net"
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
if [ x$1 = "xclean" ]; then
|
||||
echo Cleaning
|
||||
echo
|
||||
|
@ -9,8 +22,10 @@ if [ x$1 = "xclean" ]; then
|
|||
make clean
|
||||
cd ../examples
|
||||
make clean
|
||||
cd ..
|
||||
elif [ x$1 = "xuninstall" ]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ x$1 = "xuninstall" ]; then
|
||||
echo Uninstalling
|
||||
echo
|
||||
echo "WiringPi library"
|
||||
|
@ -21,24 +36,50 @@ elif [ x$1 = "xuninstall" ]; then
|
|||
cd ../gpio
|
||||
sudo make uninstall
|
||||
cd ..
|
||||
else
|
||||
echo wiringPi Build script - please wait...
|
||||
exit
|
||||
fi
|
||||
|
||||
|
||||
echo "wiringPi Build script"
|
||||
echo "====================="
|
||||
echo
|
||||
|
||||
# Check for I2C being installed...
|
||||
# ... and if-so, then automatically make the I2C helpers
|
||||
|
||||
if [ -f /usr/include/linux/i2c-dev.h ]; then
|
||||
grep -q i2c_smbus_read_byte /usr/include/linux/i2c-dev.h
|
||||
if [ $? = 0 ]; then
|
||||
target=i2c
|
||||
echo "Building wiringPi with the I2C helper libraries."
|
||||
else
|
||||
target=all
|
||||
echo "The wiringPi I2C helper libraries will not be built."
|
||||
fi
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "WiringPi library"
|
||||
cd wiringPi
|
||||
make
|
||||
sudo make uninstall
|
||||
make $target
|
||||
check-make-ok
|
||||
sudo make install
|
||||
check-make-ok
|
||||
|
||||
echo
|
||||
echo "GPIO Utility"
|
||||
cd ../gpio
|
||||
make
|
||||
check-make-ok
|
||||
sudo make install
|
||||
echo
|
||||
echo "Examples"
|
||||
cd ../examples
|
||||
make
|
||||
cd ..
|
||||
fi
|
||||
check-make-ok
|
||||
|
||||
# echo
|
||||
# echo "Examples"
|
||||
# cd ../examples
|
||||
# make
|
||||
# cd ..
|
||||
|
||||
echo
|
||||
echo All Done.
|
||||
|
|
|
@ -30,15 +30,15 @@ INCLUDE = -I/usr/local/include
|
|||
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
|
||||
|
||||
LDFLAGS = -L/usr/local/lib
|
||||
LDLIBS = -lwiringPi
|
||||
LDLIBS = -lwiringPi -lpthread -lm
|
||||
|
||||
# Should not alter anything below this line
|
||||
###############################################################################
|
||||
|
||||
SRC = test1.c test2.c speed.c lcd.c wfi.c \
|
||||
piface.c gertboard.c nes.c \
|
||||
pwm.c tone.c servo.c \
|
||||
delayTest.c serialRead.c okLed.c
|
||||
SRC = blink.c test1.c test2.c speed.c lcd.c wfi.c isr.c isr-osc.c \
|
||||
piface.c gertboard.c nes.c \
|
||||
pwm.c tone.c servo.c \
|
||||
delayTest.c serialRead.c serialTest.c okLed.c
|
||||
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
|
@ -49,6 +49,12 @@ all:
|
|||
@echo " $(BINS)" | fmt
|
||||
@echo ""
|
||||
|
||||
really-all: $(BINS)
|
||||
|
||||
blink: blink.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ blink.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
test1: test1.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ test1.o $(LDFLAGS) $(LDLIBS)
|
||||
|
@ -69,21 +75,29 @@ wfi: wfi.o
|
|||
@echo [link]
|
||||
@$(CC) -o $@ wfi.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
isr: isr.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ isr.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
isr-osc: isr-osc.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ isr-osc.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
piface: piface.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ piface.o $(LDFLAGS) $(LDLIBS) -lpthread
|
||||
@$(CC) -o $@ piface.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
gertboard: gertboard.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ gertboard.o $(LDFLAGS) $(LDLIBS) -lm
|
||||
@$(CC) -o $@ gertboard.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
nes: nes.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ nes.o $(LDFLAGS) $(LDLIBS) -lm
|
||||
@$(CC) -o $@ nes.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
pwm: pwm.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ pwm.o $(LDFLAGS) $(LDLIBS) -lm -lpthread
|
||||
@$(CC) -o $@ pwm.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
delayTest: delayTest.o
|
||||
@echo [link]
|
||||
|
@ -93,6 +107,10 @@ serialRead: serialRead.o
|
|||
@echo [link]
|
||||
@$(CC) -o $@ serialRead.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
serialTest: serialTest.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ serialTest.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
okLed: okLed.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ okLed.o $(LDFLAGS) $(LDLIBS)
|
||||
|
|
|
@ -10,5 +10,9 @@ To compile an individual example, just type
|
|||
|
||||
make exampleName
|
||||
|
||||
Where exampleName is one of:
|
||||
To really compile everything:
|
||||
|
||||
make really-all
|
||||
|
||||
The individual tests are:
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* blink.c:
|
||||
* Standard "blink" program in wiringPi. Blinks an LED connected
|
||||
* to the first GPIO pin.
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* 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 <wiringPi.h>
|
||||
|
||||
// LED Pin - wiringPi pin 0 is BCM_GPIO 17.
|
||||
|
||||
#define LED 0
|
||||
|
||||
int main (void)
|
||||
{
|
||||
printf ("Raspberry Pi blink\n") ;
|
||||
|
||||
if (wiringPiSetup () == -1)
|
||||
return 1 ;
|
||||
|
||||
pinMode (LED, OUTPUT) ;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
digitalWrite (LED, 1) ; // On
|
||||
delay (500) ; // mS
|
||||
digitalWrite (LED, 0) ; // Off
|
||||
delay (500) ;
|
||||
}
|
||||
return 0 ;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
// blink.rtb:
|
||||
// Blink program in Return to Basic
|
||||
//
|
||||
// Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
//**********************************************************************
|
||||
// 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/>.
|
||||
***********************************************************************
|
||||
//
|
||||
PinMode (0, 1) // Output
|
||||
CYCLE
|
||||
DigitalWrite (0, 1) // Pin 0 ON
|
||||
WAIT (0.5) // 0.5 seconds
|
||||
DigitalWrite (0, 0)
|
||||
WAIT (0.5)
|
||||
REPEAT
|
||||
END
|
|
@ -0,0 +1,37 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# blink.sh:
|
||||
# Standard "blink" program in wiringPi. Blinks an LED connected
|
||||
# to the first GPIO pin.
|
||||
#
|
||||
# Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
#######################################################################
|
||||
# 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/>.
|
||||
#######################################################################
|
||||
|
||||
# LED Pin - wiringPi pin 0 is BCM_GPIO 17.
|
||||
|
||||
LED=0
|
||||
|
||||
gpio mode $PIN out
|
||||
|
||||
while true; do
|
||||
gpio write $PIN 1
|
||||
sleep 0.5
|
||||
gpio write $PIN 0
|
||||
sleep 0.5
|
||||
done
|
|
@ -1,3 +1,27 @@
|
|||
/*
|
||||
* delayTest.c:
|
||||
* Just a little test program I'm using to experiment with
|
||||
* various timings and latency, etc.
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* 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 <unistd.h>
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/*
|
||||
* gertboard.c:
|
||||
* Simple test for the SPI bus on the Gertboard
|
||||
|
@ -10,6 +9,24 @@
|
|||
* copy this value to D/A port 1 and use a 'scope on both D/A ports
|
||||
* to check all's well.
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* 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>
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* file.c:
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* 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/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* isr-osc.c:
|
||||
* Wait for Interrupt test program - ISR method - interrupt oscillator
|
||||
*
|
||||
* How to test:
|
||||
*
|
||||
* IMPORTANT: To run this test we connect 2 GPIO pins together, but
|
||||
* before we do that YOU must make sure that they are both setup
|
||||
* the right way. If they are set to outputs and one is high and one low,
|
||||
* then you connect the wire, you'll create a short and that won't be good.
|
||||
*
|
||||
* Before making the connection, type:
|
||||
* gpio mode 0 output
|
||||
* gpio write 0 0
|
||||
* gpio mode 1 input
|
||||
* then you can connect them together.
|
||||
*
|
||||
* Run the program, then:
|
||||
* gpio write 0 1
|
||||
* gpio write 0 0
|
||||
*
|
||||
* at which point it will trigger an interrupt and the program will
|
||||
* then do the up/down toggling for itself and run at full speed, and
|
||||
* it will report the number of interrupts recieved every second.
|
||||
*
|
||||
* Copyright (c) 2013 Gordon Henderson. projects@drogon.net
|
||||
***********************************************************************
|
||||
* 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 <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <wiringPi.h>
|
||||
|
||||
|
||||
// What GPIO input are we using?
|
||||
// This is a wiringPi pin number
|
||||
|
||||
#define OUT_PIN 0
|
||||
#define IN_PIN 1
|
||||
|
||||
// globalCounter:
|
||||
// Global variable to count interrupts
|
||||
// Should be declared volatile to make sure the compiler doesn't cache it.
|
||||
|
||||
static volatile int globalCounter = 0 ;
|
||||
|
||||
/*
|
||||
* myInterrupt:
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void myInterrupt (void)
|
||||
{
|
||||
digitalWrite (OUT_PIN, 1) ;
|
||||
++globalCounter ;
|
||||
digitalWrite (OUT_PIN, 0) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************
|
||||
* main
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int myCounter = 0 ;
|
||||
int lastCounter = 0 ;
|
||||
|
||||
if (wiringPiSetup () < 0)
|
||||
{
|
||||
fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno)) ;
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
pinMode (OUT_PIN, OUTPUT) ;
|
||||
pinMode (IN_PIN, INPUT) ;
|
||||
|
||||
if (wiringPiISR (IN_PIN, INT_EDGE_FALLING, &myInterrupt) < 0)
|
||||
{
|
||||
fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
printf ("Waiting ... ") ; fflush (stdout) ;
|
||||
|
||||
while (myCounter == globalCounter)
|
||||
delay (1000) ;
|
||||
|
||||
printf (" Done. counter: %6d: %6d\n",
|
||||
globalCounter, myCounter - lastCounter) ;
|
||||
lastCounter = myCounter ;
|
||||
myCounter = globalCounter ;
|
||||
}
|
||||
|
||||
return 0 ;
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* isr.c:
|
||||
* Wait for Interrupt test program - ISR method
|
||||
*
|
||||
* How to test:
|
||||
* Use the SoC's pull-up and pull down resistors that are avalable
|
||||
* on input pins. So compile & run this program (via sudo), then
|
||||
* in another terminal:
|
||||
* gpio mode 0 up
|
||||
* gpio mode 0 down
|
||||
* at which point it should trigger an interrupt. Toggle the pin
|
||||
* up/down to generate more interrupts to test.
|
||||
*
|
||||
* Copyright (c) 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 <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <wiringPi.h>
|
||||
|
||||
|
||||
// What GPIO input are we using?
|
||||
// This is a wiringPi pin number
|
||||
|
||||
#define BUTTON_PIN 0
|
||||
|
||||
// globalCounter:
|
||||
// Global variable to count interrupts
|
||||
// Should be declared volatile to make sure the compiler doesn't cache it.
|
||||
|
||||
static volatile int globalCounter = 0 ;
|
||||
|
||||
|
||||
/*
|
||||
* myInterrupt:
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void myInterrupt (void)
|
||||
{
|
||||
++globalCounter ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************
|
||||
* main
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int myCounter = 0 ;
|
||||
|
||||
if (wiringPiSetup () < 0)
|
||||
{
|
||||
fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno)) ;
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
if (wiringPiISR (BUTTON_PIN, INT_EDGE_FALLING, &myInterrupt) < 0)
|
||||
{
|
||||
fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
|
||||
for (;;)
|
||||
{
|
||||
printf ("Waiting ... ") ; fflush (stdout) ;
|
||||
|
||||
while (myCounter == globalCounter)
|
||||
delay (100) ;
|
||||
|
||||
printf (" Done. counter: %5d\n", globalCounter) ;
|
||||
myCounter = globalCounter ;
|
||||
}
|
||||
|
||||
return 0 ;
|
||||
}
|
|
@ -1,3 +1,26 @@
|
|||
/*
|
||||
* nes.c:
|
||||
* Test program for an old NES controller connected to the Pi.
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* 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 <errno.h>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/*
|
||||
* okLed:
|
||||
* okLed.c:
|
||||
* Make the OK LED on the Pi Pulsate...
|
||||
* Copyright (c) 2012 gordon Henderson, but please Share and Enjoy!
|
||||
*
|
||||
* Originally posted to the Raspberry Pi forums:
|
||||
* http://www.raspberrypi.org/phpBB3/viewtopic.php?p=162581#p162581
|
||||
|
@ -10,6 +9,24 @@
|
|||
* e.g. by putting it in /etc/rc.local and running it in the
|
||||
* background &
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* 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>
|
||||
|
@ -17,6 +34,7 @@
|
|||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <wiringPi.h>
|
||||
#include <softPwm.h>
|
||||
|
|
|
@ -1,9 +1,27 @@
|
|||
|
||||
/*
|
||||
* piface.c:
|
||||
* Simple test for the PiFace
|
||||
* piFace.c:
|
||||
* Simple test for the PiFace interface board.
|
||||
*
|
||||
* Read the buttons and output the same to the LEDs
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* 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 <wiringPi.h>
|
||||
|
|
|
@ -1,3 +1,27 @@
|
|||
/*
|
||||
* pwm.c:
|
||||
* Test of the software PWM driver. Needs 12 LEDs connected
|
||||
* to the Pi.
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* 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 <errno.h>
|
||||
|
|
|
@ -1,8 +1,25 @@
|
|||
|
||||
/*
|
||||
* serialRead.c:
|
||||
* serial.c:
|
||||
* Example program to read bytes from the Serial line
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* 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>
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* serialTest.c:
|
||||
* Very simple program to test the serial port. Expects
|
||||
* the port to be looped back to itself
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* 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 <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <wiringPi.h>
|
||||
#include <wiringSerial.h>
|
||||
|
||||
int main ()
|
||||
{
|
||||
int fd ;
|
||||
int count ;
|
||||
unsigned int nextTime ;
|
||||
|
||||
if ((fd = serialOpen ("/dev/ttyAMA0", 115200)) < 0)
|
||||
{
|
||||
fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
if (wiringPiSetup () == -1)
|
||||
{
|
||||
fprintf (stdout, "Unable to start wiringPi: %s\n", strerror (errno)) ;
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
nextTime = millis () + 300 ;
|
||||
|
||||
for (count = 0 ; count < 256 ; )
|
||||
{
|
||||
if (millis () > nextTime)
|
||||
{
|
||||
printf ("\nOut: %3d: ", count) ;
|
||||
fflush (stdout) ;
|
||||
serialPutchar (fd, count) ;
|
||||
nextTime += 300 ;
|
||||
++count ;
|
||||
}
|
||||
|
||||
delay (3) ;
|
||||
|
||||
while (serialDataAvail (fd))
|
||||
{
|
||||
printf (" -> %3d", serialGetchar (fd)) ;
|
||||
fflush (stdout) ;
|
||||
}
|
||||
}
|
||||
|
||||
printf ("\n") ;
|
||||
return 0 ;
|
||||
}
|
|
@ -1,3 +1,27 @@
|
|||
/*
|
||||
* servo.c:
|
||||
* Test of the softServo code.
|
||||
* Do not use this code - use the servoBlaster kernel module instead
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* 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 <errno.h>
|
||||
|
|
|
@ -1,8 +1,26 @@
|
|||
|
||||
/*
|
||||
* speed.c:
|
||||
* Simple program to measure the speed of the various GPIO
|
||||
* access mechanisms.
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* 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 <wiringPi.h>
|
||||
|
|
|
@ -1,7 +1,27 @@
|
|||
|
||||
/*
|
||||
* test1.c:
|
||||
* Simple test program to test the wiringPi functions
|
||||
* This is a sequencer to make a patter appear on 8 LEDs
|
||||
* connected to the GPIO pins.
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* 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 <wiringPi.h>
|
||||
|
|
|
@ -1,8 +1,25 @@
|
|||
|
||||
/*
|
||||
* test2.c:
|
||||
* Simple test program to test the wiringPi functions
|
||||
* PWM test
|
||||
* This tests the hardware PWM channel.
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* 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 <wiringPi.h>
|
||||
|
|
|
@ -1,3 +1,27 @@
|
|||
/*
|
||||
* tone.c:
|
||||
* Test of the softTone module in wiringPi
|
||||
* Plays a scale out on pin 3 - connect pizeo disc to pin 3 & 0v
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* 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 <errno.h>
|
||||
|
@ -6,15 +30,13 @@
|
|||
#include <wiringPi.h>
|
||||
#include <softTone.h>
|
||||
|
||||
#define RANGE 100
|
||||
#define NUM_LEDS 12
|
||||
#define PIN 3
|
||||
|
||||
int scale [8] = { 262, 294, 330, 349, 392, 440, 494, 525 } ;
|
||||
|
||||
int main ()
|
||||
{
|
||||
int i, j ;
|
||||
char buf [80] ;
|
||||
int i ;
|
||||
|
||||
if (wiringPiSetup () == -1)
|
||||
{
|
||||
|
@ -22,14 +44,14 @@ int main ()
|
|||
return 1 ;
|
||||
}
|
||||
|
||||
softToneCreate (3) ;
|
||||
softToneCreate (PIN) ;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
for (i = 0 ; i < 8 ; ++i)
|
||||
{
|
||||
printf ("%3d\n", i) ;
|
||||
softToneWrite (3, scale [i]) ;
|
||||
softToneWrite (PIN, scale [i]) ;
|
||||
delay (500) ;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,17 @@
|
|||
* wfi.c:
|
||||
* Wait for Interrupt test program
|
||||
*
|
||||
* Copyright (c) 2012 Gordon Henderson.
|
||||
* This program demonstrates the use of the waitForInterrupt()
|
||||
* function in wiringPi. It listens to a button input on
|
||||
* BCM_GPIO pin 17 (wiringPi pin 0)
|
||||
*
|
||||
* The biggest issue with this method is that it really only works
|
||||
* well in Sys mode.
|
||||
*
|
||||
* Jan 2013: This way of doing things is sort of deprecated now, see
|
||||
* the wiringPiISR() function instead and the isr.c test program here.
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson.
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
|
@ -33,9 +43,8 @@
|
|||
#define COUNT_KEY 0
|
||||
|
||||
// What BCM_GPIO input are we using?
|
||||
// GPIO 0 is one of the I2C pins with an on-board pull-up
|
||||
|
||||
#define BUTTON_PIN 0
|
||||
#define BUTTON_PIN 17
|
||||
|
||||
// Debounce time in mS
|
||||
|
||||
|
@ -63,13 +72,11 @@ PI_THREAD (waitForIt)
|
|||
int debounceTime = 0 ;
|
||||
|
||||
(void)piHiPri (10) ; // Set this thread to be high priority
|
||||
digitalWrite (18, 1) ;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (waitForInterrupt (BUTTON_PIN, -1) > 0) // Got it
|
||||
{
|
||||
|
||||
// Bouncing?
|
||||
|
||||
if (millis () < debounceTime)
|
||||
|
@ -80,7 +87,6 @@ PI_THREAD (waitForIt)
|
|||
|
||||
// We have a valid one
|
||||
|
||||
digitalWrite (17, state) ;
|
||||
state ^= 1 ;
|
||||
|
||||
piLock (COUNT_KEY) ;
|
||||
|
@ -89,7 +95,7 @@ PI_THREAD (waitForIt)
|
|||
|
||||
// Wait for key to be released
|
||||
|
||||
while (digitalRead (0) == LOW)
|
||||
while (digitalRead (BUTTON_PIN) == LOW)
|
||||
delay (1) ;
|
||||
|
||||
debounceTime = millis () + DEBOUNCE_TIME ;
|
||||
|
@ -108,11 +114,9 @@ void setup (void)
|
|||
{
|
||||
|
||||
// Use the gpio program to initialise the hardware
|
||||
// (This is the crude, but effective bit)
|
||||
// (This is the crude, but effective)
|
||||
|
||||
system ("gpio edge 0 falling") ;
|
||||
system ("gpio export 17 out") ;
|
||||
system ("gpio export 18 out") ;
|
||||
system ("gpio edge 17 falling") ;
|
||||
|
||||
// Setup wiringPi
|
||||
|
||||
|
@ -120,9 +124,8 @@ void setup (void)
|
|||
|
||||
// Fire off our interrupt handler
|
||||
|
||||
piThreadCreate (waitForIt) ;
|
||||
piThreadCreate (waitForIt) ;
|
||||
|
||||
digitalWrite (17, 0) ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -147,7 +150,7 @@ int main (void)
|
|||
piLock (COUNT_KEY) ;
|
||||
myCounter = globalCounter ;
|
||||
piUnlock (COUNT_KEY) ;
|
||||
delay (5000) ;
|
||||
delay (500) ;
|
||||
}
|
||||
|
||||
printf (" Done. myCounter: %5d\n", myCounter) ;
|
||||
|
|
|
@ -30,7 +30,7 @@ INCLUDE = -I/usr/local/include
|
|||
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
|
||||
|
||||
LDFLAGS = -L/usr/local/lib
|
||||
LIBS = -lwiringPi
|
||||
LIBS = -lwiringPi -lpthread -lm
|
||||
|
||||
# May not need to alter anything below this line
|
||||
###############################################################################
|
||||
|
@ -70,8 +70,8 @@ install:
|
|||
.PHONEY: uninstall
|
||||
uninstall:
|
||||
@echo "[UnInstall]"
|
||||
rm -f /usr/local/bin/gpio
|
||||
rm -f /usr/local/man/man1/gpio.1
|
||||
@rm -f /usr/local/bin/gpio
|
||||
@rm -f /usr/local/man/man1/gpio.1
|
||||
|
||||
.PHONEY: depend
|
||||
depend:
|
||||
|
|
43
gpio/gpio.1
43
gpio/gpio.1
|
@ -9,7 +9,7 @@ gpio \- Command-line access to Raspberry Pi and PiFace GPIO
|
|||
.PP
|
||||
.B gpio
|
||||
.B [ \-g ]
|
||||
.B read/write/wb/pwm/mode ...
|
||||
.B read/write/wb/pwm/clock/mode ...
|
||||
.PP
|
||||
.B gpio
|
||||
.B [ \-p ]
|
||||
|
@ -38,7 +38,7 @@ group value
|
|||
range
|
||||
.PP
|
||||
.B gpio
|
||||
.B load \ i2c/spi
|
||||
.B load \ i2c/spi ...
|
||||
.PP
|
||||
.B gpio
|
||||
.B gbr
|
||||
|
@ -57,6 +57,9 @@ 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.
|
||||
|
@ -70,6 +73,8 @@ 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 \-p
|
||||
|
@ -99,7 +104,13 @@ mode.
|
|||
|
||||
.TP
|
||||
.B pwm <pin> <value>
|
||||
Write a PWM value (0-1023) to the given pin.
|
||||
Write a PWM value (0-1023) to the given pin. 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>
|
||||
|
@ -163,9 +174,18 @@ Change the PWM mode to balanced (the default) or mark:space ratio (traditional)
|
|||
Change the PWM range register. The default is 1024.
|
||||
|
||||
.TP
|
||||
.B load i2c/spi
|
||||
This loads the i2c or the spi drivers into the system and changes the permissions on
|
||||
the associated /dev/ entries so that the current user has access to them.
|
||||
.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 (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
|
||||
|
@ -183,7 +203,7 @@ SPI digital to analogue converter.
|
|||
The board jumpers need to be in-place to do this operation.
|
||||
|
||||
|
||||
.SH "WiringPi vs. GPIO Pin numbering"
|
||||
.SH "WiringPi vs. BCM_GPIO Pin numbering"
|
||||
|
||||
.PP
|
||||
.TS
|
||||
|
@ -213,6 +233,12 @@ _
|
|||
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
|
||||
|
@ -264,4 +290,5 @@ 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.
|
||||
Raspberry Pi is a trademark of the Raspberry Pi Foundation. See
|
||||
http://raspberrypi.org/ for full details.
|
||||
|
|
134
gpio/gpio.c
134
gpio/gpio.c
|
@ -35,18 +35,20 @@
|
|||
#include <wiringPi.h>
|
||||
#include <gertboard.h>
|
||||
|
||||
extern int wiringPiDebug ;
|
||||
|
||||
#ifndef TRUE
|
||||
# define TRUE (1==1)
|
||||
# define FALSE (1==2)
|
||||
#endif
|
||||
|
||||
#define VERSION "1.5"
|
||||
#define VERSION "1.12"
|
||||
|
||||
static int wpMode ;
|
||||
|
||||
char *usage = "Usage: gpio -v\n"
|
||||
" gpio -h\n"
|
||||
" gpio [-g] <read/write/wb/pwm/mode> ...\n"
|
||||
" gpio [-g] <read/write/wb/pwm/clock/mode> ...\n"
|
||||
" gpio [-p] <read/write/wb> ...\n"
|
||||
" gpio readall\n"
|
||||
" gpio unexportall/exports ...\n"
|
||||
|
@ -127,7 +129,7 @@ static int moduleLoaded (char *modName)
|
|||
|
||||
static void _doLoadUsage (char *argv [])
|
||||
{
|
||||
fprintf (stderr, "Usage: %s load <spi/i2c>\n", argv [0]) ;
|
||||
fprintf (stderr, "Usage: %s load <spi/i2c> [SPI bufferSize in KB | I2C baudrate in Kb/sec]\n", argv [0]) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
|
@ -136,16 +138,23 @@ static void doLoad (int argc, char *argv [])
|
|||
char *module1, *module2 ;
|
||||
char cmd [80] ;
|
||||
char *file1, *file2 ;
|
||||
char args1 [32], args2 [32] ;
|
||||
|
||||
if (argc != 3)
|
||||
if (argc < 3)
|
||||
_doLoadUsage (argv) ;
|
||||
|
||||
args1 [0] = args2 [0] = 0 ;
|
||||
|
||||
/**/ if (strcasecmp (argv [2], "spi") == 0)
|
||||
{
|
||||
module1 = "spidev" ;
|
||||
module2 = "spi_bcm2708" ;
|
||||
file1 = "/dev/spidev0.0" ;
|
||||
file2 = "/dev/spidev0.1" ;
|
||||
if (argc == 4)
|
||||
sprintf (args1, " bufsiz=%d", atoi (argv [3]) * 1024) ;
|
||||
else if (argc > 4)
|
||||
_doLoadUsage (argv) ;
|
||||
}
|
||||
else if (strcasecmp (argv [2], "i2c") == 0)
|
||||
{
|
||||
|
@ -153,19 +162,23 @@ static void doLoad (int argc, char *argv [])
|
|||
module2 = "i2c_bcm2708" ;
|
||||
file1 = "/dev/i2c-0" ;
|
||||
file2 = "/dev/i2c-1" ;
|
||||
if (argc == 4)
|
||||
sprintf (args2, " baudrate=%d", atoi (argv [3]) * 1000) ;
|
||||
else if (argc > 4)
|
||||
_doLoadUsage (argv) ;
|
||||
}
|
||||
else
|
||||
_doLoadUsage (argv) ;
|
||||
|
||||
if (!moduleLoaded (module1))
|
||||
{
|
||||
sprintf (cmd, "modprobe %s", module1) ;
|
||||
sprintf (cmd, "modprobe %s%s", module1, args1) ;
|
||||
system (cmd) ;
|
||||
}
|
||||
|
||||
if (!moduleLoaded (module2))
|
||||
{
|
||||
sprintf (cmd, "modprobe %s", module2) ;
|
||||
sprintf (cmd, "modprobe %s%s", module2, args2) ;
|
||||
system (cmd) ;
|
||||
}
|
||||
|
||||
|
@ -190,55 +203,39 @@ static void doLoad (int argc, char *argv [])
|
|||
|
||||
static char *pinNames [] =
|
||||
{
|
||||
"GPIO 0",
|
||||
"GPIO 1",
|
||||
"GPIO 2",
|
||||
"GPIO 3",
|
||||
"GPIO 4",
|
||||
"GPIO 5",
|
||||
"GPIO 6",
|
||||
"GPIO 7",
|
||||
"SDA ",
|
||||
"SCL ",
|
||||
"CE0 ",
|
||||
"CE1 ",
|
||||
"MOSI ",
|
||||
"MISO ",
|
||||
"SCLK ",
|
||||
"TxD ",
|
||||
"RxD ",
|
||||
"GPIO 8",
|
||||
"GPIO 9",
|
||||
"GPIO10",
|
||||
"GPIO11",
|
||||
"GPIO 0", "GPIO 1", "GPIO 2", "GPIO 3", "GPIO 4", "GPIO 5", "GPIO 6", "GPIO 7",
|
||||
"SDA ", "SCL ",
|
||||
"CE0 ", "CE1 ", "MOSI ", "MISO ", "SCLK ",
|
||||
"TxD ", "RxD ",
|
||||
"GPIO 8", "GPIO 9", "GPIO10", "GPIO11",
|
||||
} ;
|
||||
|
||||
static char *alts [] =
|
||||
{
|
||||
"IN ", "OUT ", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3"
|
||||
} ;
|
||||
|
||||
static void doReadall (void)
|
||||
{
|
||||
int pin ;
|
||||
|
||||
printf ("+----------+------+--------+-------+\n") ;
|
||||
printf ("| wiringPi | GPIO | Name | Value |\n") ;
|
||||
printf ("+----------+------+--------+-------+\n") ;
|
||||
printf ("+----------+------+--------+------+-------+\n") ;
|
||||
printf ("| wiringPi | GPIO | Name | Mode | Value |\n") ;
|
||||
printf ("+----------+------+--------+------+-------+\n") ;
|
||||
|
||||
for (pin = 0 ; pin < NUM_PINS ; ++pin)
|
||||
printf ("| %6d | %3d | %s | %s |\n",
|
||||
for (pin = 0 ; pin < 64 ; ++pin)
|
||||
{
|
||||
if (wpiPinToGpio (pin) == -1)
|
||||
continue ;
|
||||
|
||||
printf ("| %6d | %3d | %s | %s | %s |\n",
|
||||
pin, wpiPinToGpio (pin),
|
||||
pinNames [pin],
|
||||
alts [getAlt (pin)],
|
||||
digitalRead (pin) == HIGH ? "High" : "Low ") ;
|
||||
}
|
||||
|
||||
printf ("+----------+------+--------+-------+\n") ;
|
||||
|
||||
if (piBoardRev () == 1)
|
||||
return ;
|
||||
|
||||
for (pin = 17 ; pin <= 20 ; ++pin)
|
||||
printf ("| %6d | %3d | %s | %s |\n",
|
||||
pin, wpiPinToGpio (pin),
|
||||
pinNames [pin],
|
||||
digitalRead (pin) == HIGH ? "High" : "Low ") ;
|
||||
|
||||
printf ("+----------+------+--------+-------+\n") ;
|
||||
printf ("+----------+------+--------+------+-------+\n") ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -544,15 +541,16 @@ void doMode (int argc, char *argv [])
|
|||
|
||||
mode = argv [3] ;
|
||||
|
||||
/**/ if (strcasecmp (mode, "in") == 0) pinMode (pin, INPUT) ;
|
||||
else if (strcasecmp (mode, "out") == 0) pinMode (pin, OUTPUT) ;
|
||||
else if (strcasecmp (mode, "pwm") == 0) pinMode (pin, PWM_OUTPUT) ;
|
||||
else if (strcasecmp (mode, "up") == 0) pullUpDnControl (pin, PUD_UP) ;
|
||||
else if (strcasecmp (mode, "down") == 0) pullUpDnControl (pin, PUD_DOWN) ;
|
||||
else if (strcasecmp (mode, "tri") == 0) pullUpDnControl (pin, PUD_OFF) ;
|
||||
/**/ if (strcasecmp (mode, "in") == 0) pinMode (pin, INPUT) ;
|
||||
else if (strcasecmp (mode, "out") == 0) pinMode (pin, OUTPUT) ;
|
||||
else if (strcasecmp (mode, "pwm") == 0) pinMode (pin, PWM_OUTPUT) ;
|
||||
else if (strcasecmp (mode, "clock") == 0) pinMode (pin, GPIO_CLOCK) ;
|
||||
else if (strcasecmp (mode, "up") == 0) pullUpDnControl (pin, PUD_UP) ;
|
||||
else if (strcasecmp (mode, "down") == 0) pullUpDnControl (pin, PUD_DOWN) ;
|
||||
else if (strcasecmp (mode, "tri") == 0) pullUpDnControl (pin, PUD_OFF) ;
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "%s: Invalid mode: %s. Should be in/out/pwm/up/down/tri\n", argv [1], mode) ;
|
||||
fprintf (stderr, "%s: Invalid mode: %s. Should be in/out/pwm/clock/up/down/tri\n", argv [1], mode) ;
|
||||
exit (1) ;
|
||||
}
|
||||
}
|
||||
|
@ -757,6 +755,33 @@ void doRead (int argc, char *argv [])
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* doClock:
|
||||
* Output a clock on a pin
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void doClock (int argc, char *argv [])
|
||||
{
|
||||
int pin, freq ;
|
||||
|
||||
if (argc != 4)
|
||||
{
|
||||
fprintf (stderr, "Usage: %s clock <pin> <freq>\n", argv [0]) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
pin = atoi (argv [2]) ;
|
||||
|
||||
if ((wpMode == WPI_MODE_PINS) && ((pin < 0) || (pin >= NUM_PINS)))
|
||||
return ;
|
||||
|
||||
freq = atoi (argv [3]) ;
|
||||
|
||||
gpioClockSet (pin, freq) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* doPwm:
|
||||
* Output a PWM value on a pin
|
||||
|
@ -848,6 +873,12 @@ int main (int argc, char *argv [])
|
|||
{
|
||||
int i ;
|
||||
|
||||
if (getenv ("WIRINGPI_DEBUG") != NULL)
|
||||
{
|
||||
printf ("gpio: wiringPi debug mode enabled\n") ;
|
||||
wiringPiDebug = TRUE ;
|
||||
}
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
fprintf (stderr, "%s\n", usage) ;
|
||||
|
@ -977,6 +1008,7 @@ int main (int argc, char *argv [])
|
|||
else if (strcasecmp (argv [1], "write") == 0) doWrite (argc, argv) ;
|
||||
else if (strcasecmp (argv [1], "wb") == 0) doWriteByte (argc, argv) ;
|
||||
else if (strcasecmp (argv [1], "pwm" ) == 0) doPwm (argc, argv) ;
|
||||
else if (strcasecmp (argv [1], "clock") == 0) doClock (argc, argv) ;
|
||||
else if (strcasecmp (argv [1], "mode" ) == 0) doMode (argc, argv) ;
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#
|
||||
# ;
|
||||
# Makefile:
|
||||
# wiringPi - Wiring Compatable library for the Raspberry Pi
|
||||
#
|
||||
|
@ -45,13 +45,19 @@ LIBS =
|
|||
SRC = wiringPi.c wiringPiFace.c wiringSerial.c wiringShift.c \
|
||||
gertboard.c \
|
||||
piNes.c \
|
||||
lcd.c piHiPri.c piThread.c wiringPiSPI.c \
|
||||
lcd.c piHiPri.c piThread.c \
|
||||
wiringPiSPI.c \
|
||||
softPwm.c softServo.c softTone.c
|
||||
|
||||
SRC_I2C = wiringPiI2C.c
|
||||
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
all: $(STATIC) $(DYNAMIC)
|
||||
#all: $(DYNAMIC)
|
||||
OBJ_I2C = $(SRC_I2C:.c=.o)
|
||||
|
||||
all: $(DYNAMIC)
|
||||
|
||||
static: $(STATIC)
|
||||
|
||||
$(STATIC): $(OBJ)
|
||||
@echo "[Link (Static)]"
|
||||
|
@ -63,13 +69,17 @@ $(DYNAMIC): $(OBJ)
|
|||
@echo "[Link (Dynamic)]"
|
||||
@$(CC) -shared -Wl,-soname,libwiringPi.so.1 -o libwiringPi.so.1.0 -lpthread $(OBJ)
|
||||
|
||||
i2c: $(OBJ) $(OBJ_I2C)
|
||||
@echo "[Link (Dynamic + I2C)]"
|
||||
@$(CC) -shared -Wl,-soname,libwiringPi.so.1 -o libwiringPi.so.1.0 -lpthread $(OBJ) $(OBJ_I2C)
|
||||
|
||||
.c.o:
|
||||
@echo [Compile] $<
|
||||
@$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
.PHONEY: clean
|
||||
clean:
|
||||
rm -f $(OBJ) *~ core tags Makefile.bak libwiringPi.*
|
||||
rm -f $(OBJ) $(OBJ_I2C) *~ core tags Makefile.bak libwiringPi.*
|
||||
|
||||
.PHONEY: tags
|
||||
tags: $(SRC)
|
||||
|
@ -77,7 +87,7 @@ tags: $(SRC)
|
|||
@ctags $(SRC)
|
||||
|
||||
.PHONEY: install
|
||||
install: $(TARGET)
|
||||
install: $(DYNAMIC)
|
||||
@echo "[Install]"
|
||||
@install -m 0755 -d $(DESTDIR)$(PREFIX)/lib
|
||||
@install -m 0755 -d $(DESTDIR)$(PREFIX)/include
|
||||
|
@ -91,12 +101,17 @@ install: $(TARGET)
|
|||
@install -m 0644 softTone.h $(DESTDIR)$(PREFIX)/include
|
||||
@install -m 0644 lcd.h $(DESTDIR)$(PREFIX)/include
|
||||
@install -m 0644 wiringPiSPI.h $(DESTDIR)$(PREFIX)/include
|
||||
@install -m 0755 libwiringPi.a $(DESTDIR)$(PREFIX)/lib
|
||||
@install -m 0644 wiringPiI2C.h $(DESTDIR)$(PREFIX)/include
|
||||
@install -m 0755 libwiringPi.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib
|
||||
@ln -sf $(DESTDIR)$(PREFIX)/lib/libwiringPi.so.$(VERSION) $(DESTDIR)/lib/libwiringPi.so
|
||||
@ln -sf $(DESTDIR)$(PREFIX)/lib/libwiringPi.so.$(VERSION) $(DESTDIR)/lib/libwiringPi.so.1
|
||||
@ldconfig
|
||||
|
||||
.PHONEY: install-static
|
||||
install-static: $(STATIC)
|
||||
@echo "[Install Static]"
|
||||
@install -m 0755 libwiringPi.a $(DESTDIR)$(PREFIX)/lib
|
||||
|
||||
.PHONEY: uninstall
|
||||
uninstall:
|
||||
@echo "[UnInstall]"
|
||||
|
@ -110,13 +125,14 @@ uninstall:
|
|||
@rm -f $(DESTDIR)$(PREFIX)/include/softTone.h
|
||||
@rm -f $(DESTDIR)$(PREFIX)/include/lcd.h
|
||||
@rm -f $(DESTDIR)$(PREFIX)/include/wiringPiSPI.h
|
||||
@rm -f $(DESTDIR)$(PREFIX)/include/wiringPiI2C.h
|
||||
@rm -f $(DESTDIR)$(PREFIX)/lib/libwiringPi.*
|
||||
@ldconfig
|
||||
|
||||
|
||||
.PHONEY: depend
|
||||
depend:
|
||||
makedepend -Y $(SRC)
|
||||
makedepend -Y $(SRC) $(SRC_I2C)
|
||||
|
||||
# DO NOT DELETE
|
||||
|
||||
|
@ -129,5 +145,8 @@ piNes.o: wiringPi.h piNes.h
|
|||
lcd.o: wiringPi.h lcd.h
|
||||
piHiPri.o: wiringPi.h
|
||||
piThread.o: wiringPi.h
|
||||
softPwm.o: wiringPi.h softPwm.h
|
||||
wiringPiSPI.o: wiringPiSPI.h
|
||||
softPwm.o: wiringPi.h softPwm.h
|
||||
softServo.o: wiringPi.h softServo.h
|
||||
softTone.o: wiringPi.h softTone.h
|
||||
wiringPiI2C.o: wiringPi.h wiringPiI2C.h
|
||||
|
|
|
@ -174,6 +174,18 @@ void lcdClear (int fd)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* lcdSendCommand:
|
||||
* Send any arbitary command to the display
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void lcdSendCommand (int fd, uint8_t command)
|
||||
{
|
||||
struct lcdDataStruct *lcd = lcds [fd] ;
|
||||
putCommand (lcd, command) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* lcdPosition:
|
||||
* Update the position of the cursor on the display
|
||||
|
|
|
@ -30,12 +30,13 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void lcdHome (int fd) ;
|
||||
extern void lcdClear (int fd) ;
|
||||
extern void lcdPosition (int fd, int x, int y) ;
|
||||
extern void lcdPutchar (int fd, uint8_t data) ;
|
||||
extern void lcdPuts (int fd, char *string) ;
|
||||
extern void lcdPrintf (int fd, char *message, ...) ;
|
||||
extern void lcdHome (int fd) ;
|
||||
extern void lcdClear (int fd) ;
|
||||
extern void lcdSendCommand (int fd, uint8_t command) ;
|
||||
extern void lcdPosition (int fd, int x, int y) ;
|
||||
extern void lcdPutchar (int fd, uint8_t data) ;
|
||||
extern void lcdPuts (int fd, char *string) ;
|
||||
extern void lcdPrintf (int fd, char *message, ...) ;
|
||||
|
||||
extern int lcdInit (int rows, int cols, int bits, int rs, int strb,
|
||||
int d0, int d1, int d2, int d3, int d4, int d5, int d6, int d7) ;
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* q2w.c:
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <wiringPi.h>
|
||||
#include <wiringPiI2C.h>
|
||||
|
||||
// MCP23S17 Registers
|
||||
|
||||
#define IOCON 0x0A
|
||||
|
||||
#define IODIRA 0x00
|
||||
#define IPOLA 0x02
|
||||
#define GPINTENA 0x04
|
||||
#define DEFVALA 0x06
|
||||
#define INTCONA 0x08
|
||||
#define GPPUA 0x0C
|
||||
#define INTFA 0x0E
|
||||
#define INTCAPA 0x10
|
||||
#define GPIOA 0x12
|
||||
#define OLATA 0x14
|
||||
|
||||
#define IODIRB 0x01
|
||||
#define IPOLB 0x03
|
||||
#define GPINTENB 0x05
|
||||
#define DEFVALB 0x07
|
||||
#define INTCONB 0x09
|
||||
#define GPPUB 0x0D
|
||||
#define INTFB 0x0F
|
||||
#define INTCAPB 0x11
|
||||
#define GPIOB 0x13
|
||||
#define OLATB 0x15
|
||||
|
||||
// Bits in the IOCON register
|
||||
|
||||
#define IOCON_BANK_MODE 0x80
|
||||
#define IOCON_MIRROR 0x40
|
||||
#define IOCON_SEQOP 0x20
|
||||
#define IOCON_DISSLW 0x10
|
||||
#define IOCON_HAEN 0x08
|
||||
#define IOCON_ODR 0x04
|
||||
#define IOCON_INTPOL 0x02
|
||||
#define IOCON_UNUSED 0x01
|
||||
|
||||
// Default initialisation mode
|
||||
|
||||
#define IOCON_INIT (IOCON_SEQOP)
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************
|
||||
* The works
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
int main (int argc, char *argv [])
|
||||
{
|
||||
int q2w ;
|
||||
|
||||
// if (wiringPiSetup () == -1)
|
||||
// { fprintf (stderr, "q2w: Unable to initialise wiringPi: %s\n", strerror (errno)) ; return 1 ; }
|
||||
|
||||
if ((q2w = wiringPiI2CSetup (0x20)) == -1)
|
||||
{ fprintf (stderr, "q2w: Unable to initialise I2C: %s\n", strerror (errno)) ; return 1 ; }
|
||||
|
||||
// Very simple direct control of the MCP23017:
|
||||
|
||||
wiringPiI2CWriteReg8 (q2w, IOCON, IOCON_INIT) ;
|
||||
wiringPiI2CWriteReg8 (q2w, IODIRA, 0x00) ; // Port A -> Outputs
|
||||
wiringPiI2CWriteReg8 (q2w, IODIRB, 0x00) ; // Port B -> Outputs
|
||||
|
||||
for (;;)
|
||||
{
|
||||
wiringPiI2CWriteReg8 (q2w, GPIOA, 0x00) ; // All Off
|
||||
delay (500) ;
|
||||
wiringPiI2CWriteReg8 (q2w, GPIOA, 0xFF) ; // All On
|
||||
delay (500) ;
|
||||
}
|
||||
|
||||
return 0 ;
|
||||
}
|
|
@ -54,6 +54,15 @@
|
|||
// the multipexing, but it does need to be at least 10mS, and preferably 16
|
||||
// from what I've been able to determine.
|
||||
|
||||
// WARNING:
|
||||
// This code is really experimental. It was written in response to some people
|
||||
// asking for a servo driver, however while it works, there is too much
|
||||
// jitter to successfully drive a small servo - I have tried it with a micro
|
||||
// servo and it worked, but the servo ran hot due to the jitter in the signal
|
||||
// being sent to it.
|
||||
//
|
||||
// If you want servo control for the Pi, then use the servoblaster kernel
|
||||
// module.
|
||||
|
||||
#define MAX_SERVOS 8
|
||||
|
||||
|
|
|
@ -59,7 +59,9 @@ static PI_THREAD (softToneThread)
|
|||
for (;;)
|
||||
{
|
||||
frewq = frewqs [pin] ;
|
||||
if (frewq != 0)
|
||||
if (frewq == 0)
|
||||
delay (1) ;
|
||||
else
|
||||
{
|
||||
halfPeriod = 500000 / frewq ;
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -23,32 +23,50 @@
|
|||
|
||||
// Handy defines
|
||||
|
||||
// Deprecated
|
||||
#define NUM_PINS 17
|
||||
|
||||
#define WPI_MODE_PINS 0
|
||||
#define WPI_MODE_GPIO 1
|
||||
#define WPI_MODE_GPIO_SYS 2
|
||||
#define WPI_MODE_PIFACE 3
|
||||
#define WPI_MODE_UNINITIALISED -1
|
||||
|
||||
#define INPUT 0
|
||||
#define OUTPUT 1
|
||||
#define PWM_OUTPUT 2
|
||||
// Pin modes
|
||||
|
||||
#define LOW 0
|
||||
#define HIGH 1
|
||||
#define INPUT 0
|
||||
#define OUTPUT 1
|
||||
#define PWM_OUTPUT 2
|
||||
#define GPIO_CLOCK 3
|
||||
|
||||
#define PUD_OFF 0
|
||||
#define PUD_DOWN 1
|
||||
#define PUD_UP 2
|
||||
#define LOW 0
|
||||
#define HIGH 1
|
||||
|
||||
// Pull up/down/none
|
||||
|
||||
#define PUD_OFF 0
|
||||
#define PUD_DOWN 1
|
||||
#define PUD_UP 2
|
||||
|
||||
// PWM
|
||||
|
||||
#define PWM_MODE_MS 0
|
||||
#define PWM_MODE_BAL 1
|
||||
#define PWM_MODE_MS 0
|
||||
#define PWM_MODE_BAL 1
|
||||
|
||||
// Interrupt levels
|
||||
|
||||
#define INT_EDGE_SETUP 0
|
||||
#define INT_EDGE_FALLING 1
|
||||
#define INT_EDGE_RISING 2
|
||||
#define INT_EDGE_BOTH 3
|
||||
|
||||
// Threads
|
||||
|
||||
#define PI_THREAD(X) void *X (void *dummy)
|
||||
|
||||
|
||||
// Function prototypes
|
||||
// c++ wrappers thanks to a commend by Nick Lott
|
||||
// c++ wrappers thanks to a comment by Nick Lott
|
||||
// (and others on the Raspberry Pi forums)
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -68,13 +86,14 @@ extern int wpiPinToGpio (int wpiPin) ;
|
|||
extern int wiringPiSetupPiFaceForGpioProg (void) ; // Don't use this - for gpio program only
|
||||
|
||||
extern void (*pinMode) (int pin, int mode) ;
|
||||
extern int (*getAlt) (int pin) ;
|
||||
extern void (*pullUpDnControl) (int pin, int pud) ;
|
||||
extern void (*digitalWrite) (int pin, int value) ;
|
||||
extern void (*digitalWriteByte) (int value) ;
|
||||
extern void (*gpioClockSet) (int pin, int freq) ;
|
||||
extern void (*pwmWrite) (int pin, int value) ;
|
||||
extern void (*setPadDrive) (int group, int value) ;
|
||||
extern int (*digitalRead) (int pin) ;
|
||||
extern void (*delayMicroseconds) (unsigned int howLong) ;
|
||||
extern void (*pwmSetMode) (int mode) ;
|
||||
extern void (*pwmSetRange) (unsigned int range) ;
|
||||
extern void (*pwmSetClock) (int divisor) ;
|
||||
|
@ -82,11 +101,10 @@ extern void (*pwmSetClock) (int divisor) ;
|
|||
// Interrupts
|
||||
|
||||
extern int (*waitForInterrupt) (int pin, int mS) ;
|
||||
extern int wiringPiISR (int pin, int mode, void (*function)(void)) ;
|
||||
|
||||
// Threads
|
||||
|
||||
#define PI_THREAD(X) void *X (void *dummy)
|
||||
|
||||
extern int piThreadCreate (void *(*fn)(void *)) ;
|
||||
extern void piLock (int key) ;
|
||||
extern void piUnlock (int key) ;
|
||||
|
@ -99,7 +117,9 @@ extern int piHiPri (int pri) ;
|
|||
// Extras from arduino land
|
||||
|
||||
extern void delay (unsigned int howLong) ;
|
||||
extern void delayMicroseconds (unsigned int howLong) ;
|
||||
extern unsigned int millis (void) ;
|
||||
extern unsigned int micros (void) ;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* wiringPiI2C.c:
|
||||
* Simplified I2C access routines
|
||||
* Copyright (c) 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 <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/i2c-dev.h>
|
||||
|
||||
#include "wiringPi.h"
|
||||
#include "wiringPiI2C.h"
|
||||
|
||||
|
||||
/*
|
||||
* wiringPiI2CRead:
|
||||
* Simple device read
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
int wiringPiI2CRead (int fd)
|
||||
{
|
||||
return i2c_smbus_read_byte (fd) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* wiringPiI2CReadReg8: wiringPiI2CReadReg16:
|
||||
* Read an 8 or 16-bit value from a regsiter on the device
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
int wiringPiI2CReadReg8 (int fd, int reg)
|
||||
{
|
||||
return i2c_smbus_read_byte_data (fd, reg) ;
|
||||
}
|
||||
|
||||
int wiringPiI2CReadReg16 (int fd, int reg)
|
||||
{
|
||||
return i2c_smbus_read_word_data (fd, reg) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* wiringPiI2CWrite:
|
||||
* Simple device write
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
int wiringPiI2CWrite (int fd, int data)
|
||||
{
|
||||
return i2c_smbus_write_byte (fd, data) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* wiringPiI2CWriteReg8: wiringPiI2CWriteReg16:
|
||||
* Write an 8 or 16-bit value to the given register
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
int wiringPiI2CWriteReg8 (int fd, int reg, int data)
|
||||
{
|
||||
return i2c_smbus_write_byte_data (fd, reg, data) ;
|
||||
}
|
||||
|
||||
int wiringPiI2CWriteReg16 (int fd, int reg, int data)
|
||||
{
|
||||
return i2c_smbus_write_word_data (fd, reg, data) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* wiringPiI2CSetup:
|
||||
* Open the I2C device, and regsiter the target device
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
int wiringPiI2CSetup (int devId)
|
||||
{
|
||||
int rev, fd ;
|
||||
char *device ;
|
||||
|
||||
if ((rev = piBoardRev ()) < 0)
|
||||
{
|
||||
fprintf (stderr, "wiringPiI2CSetup: Unable to determine Pi board revision\n") ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
if (rev == 1)
|
||||
device = "/dev/i2c-0" ;
|
||||
else
|
||||
device = "/dev/i2c-1" ;
|
||||
|
||||
if ((fd = open (device, O_RDWR)) < 0)
|
||||
return -1 ;
|
||||
|
||||
if (ioctl (fd, I2C_SLAVE, devId) < 0)
|
||||
return -1 ;
|
||||
|
||||
return fd ;
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* wiringPiI2C.h:
|
||||
* Simplified I2C access routines
|
||||
* Copyright (c) 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/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int wiringPiI2CRead (int fd) ;
|
||||
extern int wiringPiI2CReadReg8 (int fd, int reg) ;
|
||||
extern int wiringPiI2CReadReg16 (int fd, int reg) ;
|
||||
|
||||
extern int wiringPiI2CWrite (int fd, int data) ;
|
||||
extern int wiringPiI2CWriteReg8 (int fd, int reg, int data) ;
|
||||
extern int wiringPiI2CWriteReg16 (int fd, int reg, int data) ;
|
||||
|
||||
int wiringPiI2CSetup (int devId) ;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue