Added in generic 'blink' programs in the examples in C, RTB and Shell.
Updated wiringPi with a little big-file on the millis() function and
added in a new micros() function too.
Updated the examples with standard LGPL headers.
Added a new isr-osc.c test program - just for ISR timing purposes.
# Should not alter anything below this line
###############################################################################
-SRC = test1.c test2.c speed.c lcd.c wfi.c isr.c \
- piface.c gertboard.c nes.c \
- pwm.c tone.c servo.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)
BINS = $(SRC:.c=)
-# Note:
-# Please don't waste your time by emailling me or doing a
-# pull request with changes to make all these targets. It
-# is intentional that I do it this way as it now takes too
-# long to compile them all and most people will not run
-# them anyway... -GH-
-
all:
@cat README.TXT
@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)
@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)
make exampleName
-Where exampleName is one of:
+To really compile everything:
+
+ make really-all
+
+The individual tests are:
--- /dev/null
+/*
+ * 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 ;
+}
--- /dev/null
+// 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
--- /dev/null
+#!/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
+/*
+ * 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>
-
/*
* gertboard.c:
* Simple test for the SPI bus on the Gertboard
* 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>
--- /dev/null
+/*
+ * 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/>.
+ ***********************************************************************
+ */
+
--- /dev/null
+/*
+ * 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 ;
+}
+/*
+ * 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>
/*
- * 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
* 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>
-
/*
- * 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>
+/*
+ * 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>
-
/*
- * 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>
* 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>
+/*
+ * 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>
-
/*
* 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>
-
/*
* 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>
-
/*
* 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>
+/*
+ * 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>
#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)
{
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) ;
}
}
.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:
range
.PP
.B gpio
-.B load \ i2c/spi
+.B load \ i2c/spi ...
.PP
.B gpio
.B gbr
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 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
.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.
# define FALSE (1==2)
#endif
-#define VERSION "1.8"
+#define VERSION "1.10"
static int wpMode ;
static void _doLoadUsage (char *argv [])
{
- fprintf (stderr, "Usage: %s load <spi/i2c> [bufferSize in KB for spi]\n", argv [0]) ;
+ fprintf (stderr, "Usage: %s load <spi/i2c> [SPI bufferSize in KB | I2C baudrate in Kb/sec]\n", argv [0]) ;
exit (1) ;
}
char *module1, *module2 ;
char cmd [80] ;
char *file1, *file2 ;
- char spiBuf [32] ;
+ char args1 [32], args2 [32] ;
if (argc < 3)
_doLoadUsage (argv) ;
- spiBuf [0] = 0 ;
+ args1 [0] = args2 [0] = 0 ;
/**/ if (strcasecmp (argv [2], "spi") == 0)
{
file1 = "/dev/spidev0.0" ;
file2 = "/dev/spidev0.1" ;
if (argc == 4)
- sprintf (spiBuf, " bufsize=%d", atoi (argv [3]) * 1024) ;
+ sprintf (args1, " bufsize=%d", atoi (argv [3]) * 1024) ;
else if (argc > 4)
_doLoadUsage (argv) ;
-
}
else if (strcasecmp (argv [2], "i2c") == 0)
{
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%s", module1, spiBuf) ;
+ 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) ;
}
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 ", "ALT0", "ALT1", "ALT2", "ALT3", "ALT4", "ALT5", "XXXX"
} ;
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",
- pin, wpiPinToGpio (pin),
- pinNames [pin],
- digitalRead (pin) == HIGH ? "High" : "Low ") ;
-
- printf ("+----------+------+--------+-------+\n") ;
-
- if (piBoardRev () == 1)
- return ;
+ for (pin = 0 ; pin < 64 ; ++pin)
+ {
+ if (wpiPinToGpio (pin) == -1)
+ continue ;
- for (pin = 17 ; pin <= 20 ; ++pin)
- printf ("| %6d | %3d | %s | %s |\n",
+ printf ("| %6d | %3d | %s | %s | %s |\n",
pin, wpiPinToGpio (pin),
pinNames [pin],
+ alts [getAlt (pin)],
digitalRead (pin) == HIGH ? "High" : "Low ") ;
+ }
- printf ("+----------+------+--------+-------+\n") ;
+ printf ("+----------+------+--------+------+------+\n") ;
}
}
+/*
+ * 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
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) ;
// Added in the 2 UART pins
// Change maxPins to numPins to more accurately reflect purpose
-// Pad drive current fiddling
-
-#undef DEBUG_PADS
#include <stdio.h>
#include <stdint.h>
#include <pthread.h>
#include <sys/time.h>
#include <sys/mman.h>
-#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
+#include <sys/ioctl.h>
#include "wiringPi.h"
// Function stubs
void (*pinMode) (int pin, int mode) ;
+int (*getAlt) (int pin) ;
void (*pullUpDnControl) (int pin, int pud) ;
void (*digitalWrite) (int pin, int value) ;
void (*digitalWriteByte) (int value) ;
void (*setPadDrive) (int group, int value) ;
int (*digitalRead) (int pin) ;
int (*waitForInterrupt) (int pin, int mS) ;
-void (*delayMicroseconds) (unsigned int howLong) ;
void (*pwmSetMode) (int mode) ;
void (*pwmSetRange) (unsigned int range) ;
void (*pwmSetClock) (int divisor) ;
// Time for easy calculations
-static unsigned long long epoch ;
+static uint64_t epochMilli, epochMicro ;
// Misc
}
+/*
+ * getAlt:
+ * Returns the ALT bits for a given port. Only really of-use
+ * for the gpio readall command (I think)
+ *********************************************************************************
+ */
+
+int getAltGpio (int pin)
+{
+ int fSel, shift, alt ;
+
+ pin &= 63 ;
+
+ fSel = gpioToGPFSEL [pin] ;
+ shift = gpioToShift [pin] ;
+
+ alt = (*(gpio + fSel) >> shift) & 7 ;
+
+ return alt ;
+}
+
+int getAltWPi (int pin)
+{
+ return getAltGpio (pinToGpio [pin & 63]) ;
+}
+
+int getAltSys (int pin)
+{
+ return 0 ;
+}
+
+
/*
* pwmControl:
* Allow the user to control some of the PWM functions
void pwmSetClockWPi (int divisor)
{
- unsigned int pwm_control ;
+ uint32_t pwm_control ;
divisor &= 4095 ;
if (wiringPiDebug)
wrVal = BCM_PASSWORD | 0x18 | (value & 7) ;
*(pads + group + 11) = wrVal ;
-#ifdef DEBUG_PADS
- printf ("setPadDrive: Group: %d, value: %d (%08X)\n", group, value, wrVal) ;
- printf ("Read : %08X\n", *(pads + group + 11)) ;
-#endif
+ if (wiringPiDebug)
+ {
+ printf ("setPadDrive: Group: %d, value: %d (%08X)\n", group, value, wrVal) ;
+ printf ("Read : %08X\n", *(pads + group + 11)) ;
+ }
}
void setPadDriveGpio (int group, int value)
int waitForInterruptSys (int pin, int mS)
{
int fd, x ;
- char buf [8] ;
+ uint8_t c ;
struct pollfd polls ;
if ((fd = sysFds [pin & 63]) == -1)
return -2 ;
-// Do a dummy read
-
- x = read (fd, buf, 6) ;
- if (x < 0)
- return x ;
-
-// And seek
-
- lseek (fd, 0, SEEK_SET) ;
-
// Setup poll structure
polls.fd = fd ;
// Wait for it ...
- return poll (&polls, 1, mS) ;
+ x = poll (&polls, 1, mS) ;
+
+// Do a dummy read to clear the interrupt
+// A one character read appars to be enough.
+
+ (void)read (fd, &c, 1) ;
+
+ return x ;
}
int waitForInterruptWPi (int pin, int mS)
char *modeS ;
char pinS [8] ;
pid_t pid ;
+ int count, i ;
+ uint8_t c ;
pin &= 63 ;
}
// Now pre-open the /sys/class node - it may already be open if
-// we had set it up earlier, but this will do no harm.
+// we are in Sys mode, but this will do no harm.
sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ;
if ((sysFds [pin] = open (fName, O_RDWR)) < 0)
return -1 ;
+// Clear any initial pending interrupt
+
+ ioctl (sysFds [pin], FIONREAD, &count) ;
+ for (i = 0 ; i < count ; ++i)
+ read (sysFds [pin], &c, 1) ;
+
isrFunctions [pin] = function ;
pthread_create (&threadId, NULL, interruptHandler, &pin) ;
}
+/*
+ * initialiseEpoch:
+ * Initialise our start-of-time variable to be the current unix
+ * time in milliseconds.
+ *********************************************************************************
+ */
+
+static void initialiseEpoch (void)
+{
+ struct timeval tv ;
+
+ gettimeofday (&tv, NULL) ;
+ epochMilli = (uint64_t)tv.tv_sec * (uint64_t)1000 + (uint64_t)(tv.tv_usec / 1000) ;
+ epochMicro = (uint64_t)tv.tv_sec * (uint64_t)1000000 + (uint64_t)(tv.tv_usec) ;
+}
+
/*
* delay:
* Wait for some number of milli seconds
*********************************************************************************
*/
-void delayMicrosecondsSys (unsigned int howLong)
-{
- struct timespec sleeper, dummy ;
-
- sleeper.tv_sec = 0 ;
- sleeper.tv_nsec = (long)(howLong * 1000) ;
-
- nanosleep (&sleeper, &dummy) ;
-}
-
void delayMicrosecondsHard (unsigned int howLong)
{
-#ifdef HARD_TIMER
- volatile unsigned int dummy ;
-
- *(timer + TIMER_LOAD) = howLong ;
- *(timer + TIMER_IRQ_CLR) = 0 ;
-
- dummy = *timerIrqRaw ;
- while (dummy == 0)
- dummy = *timerIrqRaw ;
-#else
struct timeval tNow, tLong, tEnd ;
gettimeofday (&tNow, NULL) ;
while (timercmp (&tNow, &tEnd, <))
gettimeofday (&tNow, NULL) ;
-#endif
}
-void delayMicrosecondsWPi (unsigned int howLong)
+void delayMicroseconds (unsigned int howLong)
{
struct timespec sleeper ;
unsigned int millis (void)
{
struct timeval tv ;
- unsigned long long t1 ;
+ uint64_t now ;
gettimeofday (&tv, NULL) ;
+ now = (uint64_t)tv.tv_sec * (uint64_t)1000 + (uint64_t)(tv.tv_usec / 1000) ;
- t1 = (tv.tv_sec * 1000000 + tv.tv_usec) / 1000 ;
+ return (uint32_t)(now - epochMilli) ;
+}
+
+
+/*
+ * micros:
+ * Return a number of microseconds as an unsigned int.
+ *********************************************************************************
+ */
- return (uint32_t)(t1 - epoch) ;
+unsigned int micros (void)
+{
+ struct timeval tv ;
+ uint64_t now ;
+
+ gettimeofday (&tv, NULL) ;
+ now = (uint64_t)tv.tv_sec * (uint64_t)1000000 + (uint64_t)tv.tv_usec ;
+
+ return (uint32_t)(now - epochMicro) ;
}
{
int fd ;
int boardRev ;
- //uint8_t *gpioMem, *pwmMem, *clkMem, *padsMem, *timerMem ;
- struct timeval tv ;
if (geteuid () != 0)
{
printf ("wiringPi: wiringPiSetup called\n") ;
pinMode = pinModeWPi ;
+ getAlt = getAltWPi ;
pullUpDnControl = pullUpDnControlWPi ;
digitalWrite = digitalWriteWPi ;
digitalWriteByte = digitalWriteByteGpio ; // Same code
setPadDrive = setPadDriveWPi ;
digitalRead = digitalReadWPi ;
waitForInterrupt = waitForInterruptWPi ;
- delayMicroseconds = delayMicrosecondsWPi ;
pwmSetMode = pwmSetModeWPi ;
pwmSetRange = pwmSetRangeWPi ;
pwmSetClock = pwmSetClockWPi ;
return -1 ;
}
-#ifdef DEBUG_PADS
- printf ("Checking pads @ 0x%08X\n", (unsigned int)pads) ;
- printf (" -> %08X %08X %08X\n", *(pads + 11), *(pads + 12), *(pads + 13)) ;
-#endif
-
// The system timer
timer = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_TIMER) ;
*(timer + TIMER_PRE_DIV) = 0x00000F9 ;
timerIrqRaw = timer + TIMER_IRQ_RAW ;
-// Initialise our epoch for millis()
-
- gettimeofday (&tv, NULL) ;
- epoch = (tv.tv_sec * 1000000 + tv.tv_usec) / 1000 ;
+ initialiseEpoch () ;
wiringPiMode = WPI_MODE_PINS ;
printf ("wiringPi: wiringPiSetupGpio called\n") ;
pinMode = pinModeGpio ;
+ getAlt = getAltGpio ;
pullUpDnControl = pullUpDnControlGpio ;
digitalWrite = digitalWriteGpio ;
digitalWriteByte = digitalWriteByteGpio ;
setPadDrive = setPadDriveGpio ;
digitalRead = digitalReadGpio ;
waitForInterrupt = waitForInterruptGpio ;
- delayMicroseconds = delayMicrosecondsWPi ; // Same
pwmSetMode = pwmSetModeWPi ;
pwmSetRange = pwmSetRangeWPi ;
pwmSetClock = pwmSetClockWPi ;
{
int boardRev ;
int pin ;
- struct timeval tv ;
char fName [128] ;
if (getenv ("WIRINGPI_DEBUG") != NULL)
printf ("wiringPi: wiringPiSetupSys called\n") ;
pinMode = pinModeSys ;
+ getAlt = getAltSys ;
pullUpDnControl = pullUpDnControlSys ;
digitalWrite = digitalWriteSys ;
digitalWriteByte = digitalWriteByteSys ;
setPadDrive = setPadDriveSys ;
digitalRead = digitalReadSys ;
waitForInterrupt = waitForInterruptSys ;
- delayMicroseconds = delayMicrosecondsSys ;
pwmSetMode = pwmSetModeSys ;
pwmSetRange = pwmSetRangeSys ;
pwmSetClock = pwmSetClockSys ;
sysFds [pin] = open (fName, O_RDWR) ;
}
-// Initialise the epoch for mills() ...
-
- gettimeofday (&tv, NULL) ;
- epoch = (tv.tv_sec * 1000000 + tv.tv_usec) / 1000 ;
+ initialiseEpoch () ;
wiringPiMode = WPI_MODE_GPIO_SYS ;
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 (*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) ;
// 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
}