mirror of
https://github.com/clockworkpi/WiringPi.git
synced 2025-12-12 16:08:49 +01:00
Quite a few changes here.
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.
This commit is contained in:
parent
db925cea18
commit
e8f6258004
@ -35,27 +35,26 @@ LDLIBS = -lwiringPi -lpthread -lm
|
||||
# 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)
|
||||
@ -80,6 +79,10 @@ 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)
|
||||
|
||||
@ -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:
|
||||
|
||||
|
||||
50
examples/blink.c
Normal file
50
examples/blink.c
Normal file
@ -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 ;
|
||||
}
|
||||
30
examples/blink.rtb
Normal file
30
examples/blink.rtb
Normal file
@ -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
|
||||
37
examples/blink.sh
Normal file
37
examples/blink.sh
Normal file
@ -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>
|
||||
|
||||
23
examples/header.h
Normal file
23
examples/header.h
Normal file
@ -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/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
118
examples/isr-osc.c
Normal file
118
examples/isr-osc.c
Normal file
@ -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 ;
|
||||
}
|
||||
@ -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>
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -3,6 +3,24 @@
|
||||
* 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>
|
||||
|
||||
@ -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) ;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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:
|
||||
|
||||
20
gpio/gpio.1
20
gpio/gpio.1
@ -38,7 +38,7 @@ group value
|
||||
range
|
||||
.PP
|
||||
.B gpio
|
||||
.B load \ i2c/spi
|
||||
.B load \ i2c/spi ...
|
||||
.PP
|
||||
.B gpio
|
||||
.B gbr
|
||||
@ -168,9 +168,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 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
|
||||
@ -275,4 +284,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.
|
||||
|
||||
79
gpio/gpio.c
79
gpio/gpio.c
@ -42,7 +42,7 @@ extern int wiringPiDebug ;
|
||||
# define FALSE (1==2)
|
||||
#endif
|
||||
|
||||
#define VERSION "1.8"
|
||||
#define VERSION "1.10"
|
||||
|
||||
static int wpMode ;
|
||||
|
||||
@ -129,7 +129,7 @@ static int moduleLoaded (char *modName)
|
||||
|
||||
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) ;
|
||||
}
|
||||
|
||||
@ -138,12 +138,12 @@ static void doLoad (int argc, char *argv [])
|
||||
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)
|
||||
{
|
||||
@ -152,10 +152,9 @@ static void doLoad (int argc, char *argv [])
|
||||
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)
|
||||
{
|
||||
@ -163,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%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) ;
|
||||
}
|
||||
|
||||
@ -200,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 ", "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",
|
||||
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") ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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) ;
|
||||
|
||||
@ -51,9 +51,6 @@
|
||||
// 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>
|
||||
@ -68,15 +65,16 @@
|
||||
#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) ;
|
||||
@ -84,7 +82,6 @@ void (*pwmWrite) (int pin, 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) ;
|
||||
@ -177,7 +174,7 @@ static volatile uint32_t *timerIrqRaw ;
|
||||
|
||||
// Time for easy calculations
|
||||
|
||||
static unsigned long long epoch ;
|
||||
static uint64_t epochMilli, epochMicro ;
|
||||
|
||||
// Misc
|
||||
|
||||
@ -586,6 +583,38 @@ void pinModeSys (int pin, int mode)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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
|
||||
@ -627,7 +656,7 @@ void pwmSetRangeSys (unsigned int range)
|
||||
|
||||
void pwmSetClockWPi (int divisor)
|
||||
{
|
||||
unsigned int pwm_control ;
|
||||
uint32_t pwm_control ;
|
||||
divisor &= 4095 ;
|
||||
|
||||
if (wiringPiDebug)
|
||||
@ -811,10 +840,11 @@ void setPadDriveWPi (int group, int value)
|
||||
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)
|
||||
@ -913,22 +943,12 @@ void pullUpDnControlSys (int pin, int pud)
|
||||
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 ;
|
||||
@ -936,7 +956,14 @@ int waitForInterruptSys (int pin, int mS)
|
||||
|
||||
// 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)
|
||||
@ -986,6 +1013,8 @@ int wiringPiISR (int pin, int mode, void (*function)(void))
|
||||
char *modeS ;
|
||||
char pinS [8] ;
|
||||
pid_t pid ;
|
||||
int count, i ;
|
||||
uint8_t c ;
|
||||
|
||||
pin &= 63 ;
|
||||
|
||||
@ -1027,12 +1056,18 @@ int wiringPiISR (int pin, int mode, void (*function)(void))
|
||||
}
|
||||
|
||||
// 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) ;
|
||||
@ -1043,6 +1078,22 @@ int wiringPiISR (int pin, int mode, void (*function)(void))
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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
|
||||
@ -1078,28 +1129,8 @@ void delay (unsigned int howLong)
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
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) ;
|
||||
@ -1109,10 +1140,9 @@ void delayMicrosecondsHard (unsigned int howLong)
|
||||
|
||||
while (timercmp (&tNow, &tEnd, <))
|
||||
gettimeofday (&tNow, NULL) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
void delayMicrosecondsWPi (unsigned int howLong)
|
||||
void delayMicroseconds (unsigned int howLong)
|
||||
{
|
||||
struct timespec sleeper ;
|
||||
|
||||
@ -1138,13 +1168,30 @@ void delayMicrosecondsWPi (unsigned int howLong)
|
||||
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) ;
|
||||
}
|
||||
|
||||
return (uint32_t)(t1 - epoch) ;
|
||||
|
||||
/*
|
||||
* micros:
|
||||
* Return a number of microseconds as an unsigned int.
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
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) ;
|
||||
}
|
||||
|
||||
|
||||
@ -1161,8 +1208,6 @@ int wiringPiSetup (void)
|
||||
{
|
||||
int fd ;
|
||||
int boardRev ;
|
||||
//uint8_t *gpioMem, *pwmMem, *clkMem, *padsMem, *timerMem ;
|
||||
struct timeval tv ;
|
||||
|
||||
if (geteuid () != 0)
|
||||
{
|
||||
@ -1180,6 +1225,7 @@ int wiringPiSetup (void)
|
||||
printf ("wiringPi: wiringPiSetup called\n") ;
|
||||
|
||||
pinMode = pinModeWPi ;
|
||||
getAlt = getAltWPi ;
|
||||
pullUpDnControl = pullUpDnControlWPi ;
|
||||
digitalWrite = digitalWriteWPi ;
|
||||
digitalWriteByte = digitalWriteByteGpio ; // Same code
|
||||
@ -1187,7 +1233,6 @@ int wiringPiSetup (void)
|
||||
setPadDrive = setPadDriveWPi ;
|
||||
digitalRead = digitalReadWPi ;
|
||||
waitForInterrupt = waitForInterruptWPi ;
|
||||
delayMicroseconds = delayMicrosecondsWPi ;
|
||||
pwmSetMode = pwmSetModeWPi ;
|
||||
pwmSetRange = pwmSetRangeWPi ;
|
||||
pwmSetClock = pwmSetClockWPi ;
|
||||
@ -1268,11 +1313,6 @@ int wiringPiSetup (void)
|
||||
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) ;
|
||||
@ -1295,10 +1335,7 @@ int wiringPiSetup (void)
|
||||
*(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 ;
|
||||
|
||||
@ -1332,6 +1369,7 @@ int wiringPiSetupGpio (void)
|
||||
printf ("wiringPi: wiringPiSetupGpio called\n") ;
|
||||
|
||||
pinMode = pinModeGpio ;
|
||||
getAlt = getAltGpio ;
|
||||
pullUpDnControl = pullUpDnControlGpio ;
|
||||
digitalWrite = digitalWriteGpio ;
|
||||
digitalWriteByte = digitalWriteByteGpio ;
|
||||
@ -1339,7 +1377,6 @@ int wiringPiSetupGpio (void)
|
||||
setPadDrive = setPadDriveGpio ;
|
||||
digitalRead = digitalReadGpio ;
|
||||
waitForInterrupt = waitForInterruptGpio ;
|
||||
delayMicroseconds = delayMicrosecondsWPi ; // Same
|
||||
pwmSetMode = pwmSetModeWPi ;
|
||||
pwmSetRange = pwmSetRangeWPi ;
|
||||
pwmSetClock = pwmSetClockWPi ;
|
||||
@ -1363,7 +1400,6 @@ int wiringPiSetupSys (void)
|
||||
{
|
||||
int boardRev ;
|
||||
int pin ;
|
||||
struct timeval tv ;
|
||||
char fName [128] ;
|
||||
|
||||
if (getenv ("WIRINGPI_DEBUG") != NULL)
|
||||
@ -1373,6 +1409,7 @@ int wiringPiSetupSys (void)
|
||||
printf ("wiringPi: wiringPiSetupSys called\n") ;
|
||||
|
||||
pinMode = pinModeSys ;
|
||||
getAlt = getAltSys ;
|
||||
pullUpDnControl = pullUpDnControlSys ;
|
||||
digitalWrite = digitalWriteSys ;
|
||||
digitalWriteByte = digitalWriteByteSys ;
|
||||
@ -1380,7 +1417,6 @@ int wiringPiSetupSys (void)
|
||||
setPadDrive = setPadDriveSys ;
|
||||
digitalRead = digitalReadSys ;
|
||||
waitForInterrupt = waitForInterruptSys ;
|
||||
delayMicroseconds = delayMicrosecondsSys ;
|
||||
pwmSetMode = pwmSetModeSys ;
|
||||
pwmSetRange = pwmSetRangeSys ;
|
||||
pwmSetClock = pwmSetClockSys ;
|
||||
@ -1401,10 +1437,7 @@ int wiringPiSetupSys (void)
|
||||
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 ;
|
||||
|
||||
|
||||
@ -81,13 +81,13 @@ 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 (*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) ;
|
||||
@ -111,7 +111,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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user