mirror of
https://github.com/clockworkpi/WiringPi.git
synced 2025-12-13 00:08:51 +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
|
# Should not alter anything below this line
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
SRC = test1.c test2.c speed.c lcd.c wfi.c isr.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 \
|
piface.c gertboard.c nes.c \
|
||||||
pwm.c tone.c servo.c \
|
pwm.c tone.c servo.c \
|
||||||
delayTest.c serialRead.c serialTest.c okLed.c
|
delayTest.c serialRead.c serialTest.c okLed.c
|
||||||
|
|
||||||
OBJ = $(SRC:.c=.o)
|
OBJ = $(SRC:.c=.o)
|
||||||
|
|
||||||
BINS = $(SRC:.c=)
|
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:
|
all:
|
||||||
@cat README.TXT
|
@cat README.TXT
|
||||||
@echo " $(BINS)" | fmt
|
@echo " $(BINS)" | fmt
|
||||||
@echo ""
|
@echo ""
|
||||||
|
|
||||||
|
really-all: $(BINS)
|
||||||
|
|
||||||
|
blink: blink.o
|
||||||
|
@echo [link]
|
||||||
|
@$(CC) -o $@ blink.o $(LDFLAGS) $(LDLIBS)
|
||||||
|
|
||||||
test1: test1.o
|
test1: test1.o
|
||||||
@echo [link]
|
@echo [link]
|
||||||
@$(CC) -o $@ test1.o $(LDFLAGS) $(LDLIBS)
|
@$(CC) -o $@ test1.o $(LDFLAGS) $(LDLIBS)
|
||||||
@ -80,6 +79,10 @@ isr: isr.o
|
|||||||
@echo [link]
|
@echo [link]
|
||||||
@$(CC) -o $@ isr.o $(LDFLAGS) $(LDLIBS)
|
@$(CC) -o $@ isr.o $(LDFLAGS) $(LDLIBS)
|
||||||
|
|
||||||
|
isr-osc: isr-osc.o
|
||||||
|
@echo [link]
|
||||||
|
@$(CC) -o $@ isr-osc.o $(LDFLAGS) $(LDLIBS)
|
||||||
|
|
||||||
piface: piface.o
|
piface: piface.o
|
||||||
@echo [link]
|
@echo [link]
|
||||||
@$(CC) -o $@ piface.o $(LDFLAGS) $(LDLIBS)
|
@$(CC) -o $@ piface.o $(LDFLAGS) $(LDLIBS)
|
||||||
|
|||||||
@ -10,5 +10,9 @@ To compile an individual example, just type
|
|||||||
|
|
||||||
make exampleName
|
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 <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* gertboard.c:
|
* gertboard.c:
|
||||||
* Simple test for the SPI bus on the Gertboard
|
* 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
|
* copy this value to D/A port 1 and use a 'scope on both D/A ports
|
||||||
* to check all's well.
|
* 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>
|
#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 <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* okLed:
|
* okLed.c:
|
||||||
* Make the OK LED on the Pi Pulsate...
|
* 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:
|
* Originally posted to the Raspberry Pi forums:
|
||||||
* http://www.raspberrypi.org/phpBB3/viewtopic.php?p=162581#p162581
|
* 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
|
* e.g. by putting it in /etc/rc.local and running it in the
|
||||||
* background &
|
* 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>
|
#include <stdio.h>
|
||||||
|
|||||||
@ -1,9 +1,27 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* piface.c:
|
* piFace.c:
|
||||||
* Simple test for the PiFace
|
* Simple test for the PiFace interface board.
|
||||||
*
|
*
|
||||||
* Read the buttons and output the same to the LEDs
|
* 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>
|
#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 <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|||||||
@ -1,8 +1,25 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* serialRead.c:
|
* serial.c:
|
||||||
* Example program to read bytes from the Serial line
|
* 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>
|
#include <stdio.h>
|
||||||
|
|||||||
@ -3,6 +3,24 @@
|
|||||||
* Very simple program to test the serial port. Expects
|
* Very simple program to test the serial port. Expects
|
||||||
* the port to be looped back to itself
|
* 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 <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 <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|||||||
@ -1,8 +1,26 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* speed.c:
|
* speed.c:
|
||||||
* Simple program to measure the speed of the various GPIO
|
* Simple program to measure the speed of the various GPIO
|
||||||
* access mechanisms.
|
* 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>
|
#include <wiringPi.h>
|
||||||
|
|||||||
@ -1,7 +1,27 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* test1.c:
|
* test1.c:
|
||||||
* Simple test program to test the wiringPi functions
|
* 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>
|
#include <wiringPi.h>
|
||||||
|
|||||||
@ -1,8 +1,25 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* test2.c:
|
* test2.c:
|
||||||
* Simple test program to test the wiringPi functions
|
* This tests the hardware PWM channel.
|
||||||
* PWM test
|
*
|
||||||
|
* 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>
|
#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 <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -6,15 +30,13 @@
|
|||||||
#include <wiringPi.h>
|
#include <wiringPi.h>
|
||||||
#include <softTone.h>
|
#include <softTone.h>
|
||||||
|
|
||||||
#define RANGE 100
|
#define PIN 3
|
||||||
#define NUM_LEDS 12
|
|
||||||
|
|
||||||
int scale [8] = { 262, 294, 330, 349, 392, 440, 494, 525 } ;
|
int scale [8] = { 262, 294, 330, 349, 392, 440, 494, 525 } ;
|
||||||
|
|
||||||
int main ()
|
int main ()
|
||||||
{
|
{
|
||||||
int i, j ;
|
int i ;
|
||||||
char buf [80] ;
|
|
||||||
|
|
||||||
if (wiringPiSetup () == -1)
|
if (wiringPiSetup () == -1)
|
||||||
{
|
{
|
||||||
@ -22,14 +44,14 @@ int main ()
|
|||||||
return 1 ;
|
return 1 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
softToneCreate (3) ;
|
softToneCreate (PIN) ;
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
for (i = 0 ; i < 8 ; ++i)
|
for (i = 0 ; i < 8 ; ++i)
|
||||||
{
|
{
|
||||||
printf ("%3d\n", i) ;
|
printf ("%3d\n", i) ;
|
||||||
softToneWrite (3, scale [i]) ;
|
softToneWrite (PIN, scale [i]) ;
|
||||||
delay (500) ;
|
delay (500) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -70,8 +70,8 @@ install:
|
|||||||
.PHONEY: uninstall
|
.PHONEY: uninstall
|
||||||
uninstall:
|
uninstall:
|
||||||
@echo "[UnInstall]"
|
@echo "[UnInstall]"
|
||||||
rm -f /usr/local/bin/gpio
|
@rm -f /usr/local/bin/gpio
|
||||||
rm -f /usr/local/man/man1/gpio.1
|
@rm -f /usr/local/man/man1/gpio.1
|
||||||
|
|
||||||
.PHONEY: depend
|
.PHONEY: depend
|
||||||
depend:
|
depend:
|
||||||
|
|||||||
20
gpio/gpio.1
20
gpio/gpio.1
@ -38,7 +38,7 @@ group value
|
|||||||
range
|
range
|
||||||
.PP
|
.PP
|
||||||
.B gpio
|
.B gpio
|
||||||
.B load \ i2c/spi
|
.B load \ i2c/spi ...
|
||||||
.PP
|
.PP
|
||||||
.B gpio
|
.B gpio
|
||||||
.B gbr
|
.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.
|
Change the PWM range register. The default is 1024.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B load i2c/spi
|
.B load i2c [baudrate]
|
||||||
This loads the i2c or the spi drivers into the system and changes the permissions on
|
This loads the i2c or drivers into the kernel and changes the permissions
|
||||||
the associated /dev/ entries so that the current user has access to them.
|
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
|
.TP
|
||||||
.B gbr
|
.B gbr
|
||||||
@ -275,4 +284,5 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|||||||
|
|
||||||
.SH TRADEMARKS AND ACKNOWLEDGEMENTS
|
.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)
|
# define FALSE (1==2)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define VERSION "1.8"
|
#define VERSION "1.10"
|
||||||
|
|
||||||
static int wpMode ;
|
static int wpMode ;
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ static int moduleLoaded (char *modName)
|
|||||||
|
|
||||||
static void _doLoadUsage (char *argv [])
|
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) ;
|
exit (1) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,12 +138,12 @@ static void doLoad (int argc, char *argv [])
|
|||||||
char *module1, *module2 ;
|
char *module1, *module2 ;
|
||||||
char cmd [80] ;
|
char cmd [80] ;
|
||||||
char *file1, *file2 ;
|
char *file1, *file2 ;
|
||||||
char spiBuf [32] ;
|
char args1 [32], args2 [32] ;
|
||||||
|
|
||||||
if (argc < 3)
|
if (argc < 3)
|
||||||
_doLoadUsage (argv) ;
|
_doLoadUsage (argv) ;
|
||||||
|
|
||||||
spiBuf [0] = 0 ;
|
args1 [0] = args2 [0] = 0 ;
|
||||||
|
|
||||||
/**/ if (strcasecmp (argv [2], "spi") == 0)
|
/**/ if (strcasecmp (argv [2], "spi") == 0)
|
||||||
{
|
{
|
||||||
@ -152,10 +152,9 @@ static void doLoad (int argc, char *argv [])
|
|||||||
file1 = "/dev/spidev0.0" ;
|
file1 = "/dev/spidev0.0" ;
|
||||||
file2 = "/dev/spidev0.1" ;
|
file2 = "/dev/spidev0.1" ;
|
||||||
if (argc == 4)
|
if (argc == 4)
|
||||||
sprintf (spiBuf, " bufsize=%d", atoi (argv [3]) * 1024) ;
|
sprintf (args1, " bufsize=%d", atoi (argv [3]) * 1024) ;
|
||||||
else if (argc > 4)
|
else if (argc > 4)
|
||||||
_doLoadUsage (argv) ;
|
_doLoadUsage (argv) ;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (strcasecmp (argv [2], "i2c") == 0)
|
else if (strcasecmp (argv [2], "i2c") == 0)
|
||||||
{
|
{
|
||||||
@ -163,19 +162,23 @@ static void doLoad (int argc, char *argv [])
|
|||||||
module2 = "i2c_bcm2708" ;
|
module2 = "i2c_bcm2708" ;
|
||||||
file1 = "/dev/i2c-0" ;
|
file1 = "/dev/i2c-0" ;
|
||||||
file2 = "/dev/i2c-1" ;
|
file2 = "/dev/i2c-1" ;
|
||||||
|
if (argc == 4)
|
||||||
|
sprintf (args2, " baudrate=%d", atoi (argv [3]) * 1000) ;
|
||||||
|
else if (argc > 4)
|
||||||
|
_doLoadUsage (argv) ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_doLoadUsage (argv) ;
|
_doLoadUsage (argv) ;
|
||||||
|
|
||||||
if (!moduleLoaded (module1))
|
if (!moduleLoaded (module1))
|
||||||
{
|
{
|
||||||
sprintf (cmd, "modprobe %s%s", module1, spiBuf) ;
|
sprintf (cmd, "modprobe %s%s", module1, args1) ;
|
||||||
system (cmd) ;
|
system (cmd) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!moduleLoaded (module2))
|
if (!moduleLoaded (module2))
|
||||||
{
|
{
|
||||||
sprintf (cmd, "modprobe %s", module2) ;
|
sprintf (cmd, "modprobe %s%s", module2, args2) ;
|
||||||
system (cmd) ;
|
system (cmd) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,55 +203,39 @@ static void doLoad (int argc, char *argv [])
|
|||||||
|
|
||||||
static char *pinNames [] =
|
static char *pinNames [] =
|
||||||
{
|
{
|
||||||
"GPIO 0",
|
"GPIO 0", "GPIO 1", "GPIO 2", "GPIO 3", "GPIO 4", "GPIO 5", "GPIO 6", "GPIO 7",
|
||||||
"GPIO 1",
|
"SDA ", "SCL ",
|
||||||
"GPIO 2",
|
"CE0 ", "CE1 ", "MOSI ", "MISO ", "SCLK ",
|
||||||
"GPIO 3",
|
"TxD ", "RxD ",
|
||||||
"GPIO 4",
|
"GPIO 8", "GPIO 9", "GPIO10", "GPIO11",
|
||||||
"GPIO 5",
|
} ;
|
||||||
"GPIO 6",
|
|
||||||
"GPIO 7",
|
static char *alts [] =
|
||||||
"SDA ",
|
{
|
||||||
"SCL ",
|
"IN ", "OUT ", "ALT0", "ALT1", "ALT2", "ALT3", "ALT4", "ALT5", "XXXX"
|
||||||
"CE0 ",
|
|
||||||
"CE1 ",
|
|
||||||
"MOSI ",
|
|
||||||
"MISO ",
|
|
||||||
"SCLK ",
|
|
||||||
"TxD ",
|
|
||||||
"RxD ",
|
|
||||||
"GPIO 8",
|
|
||||||
"GPIO 9",
|
|
||||||
"GPIO10",
|
|
||||||
"GPIO11",
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
static void doReadall (void)
|
static void doReadall (void)
|
||||||
{
|
{
|
||||||
int pin ;
|
int pin ;
|
||||||
|
|
||||||
printf ("+----------+------+--------+-------+\n") ;
|
printf ("+----------+------+--------+------+------+\n") ;
|
||||||
printf ("| wiringPi | GPIO | Name | Value |\n") ;
|
printf ("| wiringPi | GPIO | Name | Mode | Value |\n") ;
|
||||||
printf ("+----------+------+--------+-------+\n") ;
|
printf ("+----------+------+--------+------+------+\n") ;
|
||||||
|
|
||||||
for (pin = 0 ; pin < NUM_PINS ; ++pin)
|
for (pin = 0 ; pin < 64 ; ++pin)
|
||||||
printf ("| %6d | %3d | %s | %s |\n",
|
{
|
||||||
|
if (wpiPinToGpio (pin) == -1)
|
||||||
|
continue ;
|
||||||
|
|
||||||
|
printf ("| %6d | %3d | %s | %s | %s |\n",
|
||||||
pin, wpiPinToGpio (pin),
|
pin, wpiPinToGpio (pin),
|
||||||
pinNames [pin],
|
pinNames [pin],
|
||||||
|
alts [getAlt (pin)],
|
||||||
digitalRead (pin) == HIGH ? "High" : "Low ") ;
|
digitalRead (pin) == HIGH ? "High" : "Low ") ;
|
||||||
|
}
|
||||||
|
|
||||||
printf ("+----------+------+--------+-------+\n") ;
|
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") ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -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:
|
* lcdPosition:
|
||||||
* Update the position of the cursor on the display
|
* Update the position of the cursor on the display
|
||||||
|
|||||||
@ -30,12 +30,13 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void lcdHome (int fd) ;
|
extern void lcdHome (int fd) ;
|
||||||
extern void lcdClear (int fd) ;
|
extern void lcdClear (int fd) ;
|
||||||
extern void lcdPosition (int fd, int x, int y) ;
|
extern void lcdSendCommand (int fd, uint8_t command) ;
|
||||||
extern void lcdPutchar (int fd, uint8_t data) ;
|
extern void lcdPosition (int fd, int x, int y) ;
|
||||||
extern void lcdPuts (int fd, char *string) ;
|
extern void lcdPutchar (int fd, uint8_t data) ;
|
||||||
extern void lcdPrintf (int fd, char *message, ...) ;
|
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,
|
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) ;
|
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
|
// Added in the 2 UART pins
|
||||||
// Change maxPins to numPins to more accurately reflect purpose
|
// Change maxPins to numPins to more accurately reflect purpose
|
||||||
|
|
||||||
// Pad drive current fiddling
|
|
||||||
|
|
||||||
#undef DEBUG_PADS
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@ -68,15 +65,16 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
#include "wiringPi.h"
|
#include "wiringPi.h"
|
||||||
|
|
||||||
// Function stubs
|
// Function stubs
|
||||||
|
|
||||||
void (*pinMode) (int pin, int mode) ;
|
void (*pinMode) (int pin, int mode) ;
|
||||||
|
int (*getAlt) (int pin) ;
|
||||||
void (*pullUpDnControl) (int pin, int pud) ;
|
void (*pullUpDnControl) (int pin, int pud) ;
|
||||||
void (*digitalWrite) (int pin, int value) ;
|
void (*digitalWrite) (int pin, int value) ;
|
||||||
void (*digitalWriteByte) (int value) ;
|
void (*digitalWriteByte) (int value) ;
|
||||||
@ -84,7 +82,6 @@ void (*pwmWrite) (int pin, int value) ;
|
|||||||
void (*setPadDrive) (int group, int value) ;
|
void (*setPadDrive) (int group, int value) ;
|
||||||
int (*digitalRead) (int pin) ;
|
int (*digitalRead) (int pin) ;
|
||||||
int (*waitForInterrupt) (int pin, int mS) ;
|
int (*waitForInterrupt) (int pin, int mS) ;
|
||||||
void (*delayMicroseconds) (unsigned int howLong) ;
|
|
||||||
void (*pwmSetMode) (int mode) ;
|
void (*pwmSetMode) (int mode) ;
|
||||||
void (*pwmSetRange) (unsigned int range) ;
|
void (*pwmSetRange) (unsigned int range) ;
|
||||||
void (*pwmSetClock) (int divisor) ;
|
void (*pwmSetClock) (int divisor) ;
|
||||||
@ -177,7 +174,7 @@ static volatile uint32_t *timerIrqRaw ;
|
|||||||
|
|
||||||
// Time for easy calculations
|
// Time for easy calculations
|
||||||
|
|
||||||
static unsigned long long epoch ;
|
static uint64_t epochMilli, epochMicro ;
|
||||||
|
|
||||||
// Misc
|
// 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:
|
* pwmControl:
|
||||||
* Allow the user to control some of the PWM functions
|
* Allow the user to control some of the PWM functions
|
||||||
@ -627,7 +656,7 @@ void pwmSetRangeSys (unsigned int range)
|
|||||||
|
|
||||||
void pwmSetClockWPi (int divisor)
|
void pwmSetClockWPi (int divisor)
|
||||||
{
|
{
|
||||||
unsigned int pwm_control ;
|
uint32_t pwm_control ;
|
||||||
divisor &= 4095 ;
|
divisor &= 4095 ;
|
||||||
|
|
||||||
if (wiringPiDebug)
|
if (wiringPiDebug)
|
||||||
@ -811,10 +840,11 @@ void setPadDriveWPi (int group, int value)
|
|||||||
wrVal = BCM_PASSWORD | 0x18 | (value & 7) ;
|
wrVal = BCM_PASSWORD | 0x18 | (value & 7) ;
|
||||||
*(pads + group + 11) = wrVal ;
|
*(pads + group + 11) = wrVal ;
|
||||||
|
|
||||||
#ifdef DEBUG_PADS
|
if (wiringPiDebug)
|
||||||
printf ("setPadDrive: Group: %d, value: %d (%08X)\n", group, value, wrVal) ;
|
{
|
||||||
printf ("Read : %08X\n", *(pads + group + 11)) ;
|
printf ("setPadDrive: Group: %d, value: %d (%08X)\n", group, value, wrVal) ;
|
||||||
#endif
|
printf ("Read : %08X\n", *(pads + group + 11)) ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPadDriveGpio (int group, int value)
|
void setPadDriveGpio (int group, int value)
|
||||||
@ -913,22 +943,12 @@ void pullUpDnControlSys (int pin, int pud)
|
|||||||
int waitForInterruptSys (int pin, int mS)
|
int waitForInterruptSys (int pin, int mS)
|
||||||
{
|
{
|
||||||
int fd, x ;
|
int fd, x ;
|
||||||
char buf [8] ;
|
uint8_t c ;
|
||||||
struct pollfd polls ;
|
struct pollfd polls ;
|
||||||
|
|
||||||
if ((fd = sysFds [pin & 63]) == -1)
|
if ((fd = sysFds [pin & 63]) == -1)
|
||||||
return -2 ;
|
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
|
// Setup poll structure
|
||||||
|
|
||||||
polls.fd = fd ;
|
polls.fd = fd ;
|
||||||
@ -936,7 +956,14 @@ int waitForInterruptSys (int pin, int mS)
|
|||||||
|
|
||||||
// Wait for it ...
|
// 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)
|
int waitForInterruptWPi (int pin, int mS)
|
||||||
@ -986,6 +1013,8 @@ int wiringPiISR (int pin, int mode, void (*function)(void))
|
|||||||
char *modeS ;
|
char *modeS ;
|
||||||
char pinS [8] ;
|
char pinS [8] ;
|
||||||
pid_t pid ;
|
pid_t pid ;
|
||||||
|
int count, i ;
|
||||||
|
uint8_t c ;
|
||||||
|
|
||||||
pin &= 63 ;
|
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
|
// 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) ;
|
sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ;
|
||||||
if ((sysFds [pin] = open (fName, O_RDWR)) < 0)
|
if ((sysFds [pin] = open (fName, O_RDWR)) < 0)
|
||||||
return -1 ;
|
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 ;
|
isrFunctions [pin] = function ;
|
||||||
|
|
||||||
pthread_create (&threadId, NULL, interruptHandler, &pin) ;
|
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:
|
* delay:
|
||||||
* Wait for some number of milli seconds
|
* 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)
|
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 ;
|
struct timeval tNow, tLong, tEnd ;
|
||||||
|
|
||||||
gettimeofday (&tNow, NULL) ;
|
gettimeofday (&tNow, NULL) ;
|
||||||
@ -1109,10 +1140,9 @@ void delayMicrosecondsHard (unsigned int howLong)
|
|||||||
|
|
||||||
while (timercmp (&tNow, &tEnd, <))
|
while (timercmp (&tNow, &tEnd, <))
|
||||||
gettimeofday (&tNow, NULL) ;
|
gettimeofday (&tNow, NULL) ;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void delayMicrosecondsWPi (unsigned int howLong)
|
void delayMicroseconds (unsigned int howLong)
|
||||||
{
|
{
|
||||||
struct timespec sleeper ;
|
struct timespec sleeper ;
|
||||||
|
|
||||||
@ -1138,13 +1168,30 @@ void delayMicrosecondsWPi (unsigned int howLong)
|
|||||||
unsigned int millis (void)
|
unsigned int millis (void)
|
||||||
{
|
{
|
||||||
struct timeval tv ;
|
struct timeval tv ;
|
||||||
unsigned long long t1 ;
|
uint64_t now ;
|
||||||
|
|
||||||
gettimeofday (&tv, NULL) ;
|
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 fd ;
|
||||||
int boardRev ;
|
int boardRev ;
|
||||||
//uint8_t *gpioMem, *pwmMem, *clkMem, *padsMem, *timerMem ;
|
|
||||||
struct timeval tv ;
|
|
||||||
|
|
||||||
if (geteuid () != 0)
|
if (geteuid () != 0)
|
||||||
{
|
{
|
||||||
@ -1180,6 +1225,7 @@ int wiringPiSetup (void)
|
|||||||
printf ("wiringPi: wiringPiSetup called\n") ;
|
printf ("wiringPi: wiringPiSetup called\n") ;
|
||||||
|
|
||||||
pinMode = pinModeWPi ;
|
pinMode = pinModeWPi ;
|
||||||
|
getAlt = getAltWPi ;
|
||||||
pullUpDnControl = pullUpDnControlWPi ;
|
pullUpDnControl = pullUpDnControlWPi ;
|
||||||
digitalWrite = digitalWriteWPi ;
|
digitalWrite = digitalWriteWPi ;
|
||||||
digitalWriteByte = digitalWriteByteGpio ; // Same code
|
digitalWriteByte = digitalWriteByteGpio ; // Same code
|
||||||
@ -1187,7 +1233,6 @@ int wiringPiSetup (void)
|
|||||||
setPadDrive = setPadDriveWPi ;
|
setPadDrive = setPadDriveWPi ;
|
||||||
digitalRead = digitalReadWPi ;
|
digitalRead = digitalReadWPi ;
|
||||||
waitForInterrupt = waitForInterruptWPi ;
|
waitForInterrupt = waitForInterruptWPi ;
|
||||||
delayMicroseconds = delayMicrosecondsWPi ;
|
|
||||||
pwmSetMode = pwmSetModeWPi ;
|
pwmSetMode = pwmSetModeWPi ;
|
||||||
pwmSetRange = pwmSetRangeWPi ;
|
pwmSetRange = pwmSetRangeWPi ;
|
||||||
pwmSetClock = pwmSetClockWPi ;
|
pwmSetClock = pwmSetClockWPi ;
|
||||||
@ -1268,11 +1313,6 @@ int wiringPiSetup (void)
|
|||||||
return -1 ;
|
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
|
// The system timer
|
||||||
|
|
||||||
timer = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_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 ;
|
*(timer + TIMER_PRE_DIV) = 0x00000F9 ;
|
||||||
timerIrqRaw = timer + TIMER_IRQ_RAW ;
|
timerIrqRaw = timer + TIMER_IRQ_RAW ;
|
||||||
|
|
||||||
// Initialise our epoch for millis()
|
initialiseEpoch () ;
|
||||||
|
|
||||||
gettimeofday (&tv, NULL) ;
|
|
||||||
epoch = (tv.tv_sec * 1000000 + tv.tv_usec) / 1000 ;
|
|
||||||
|
|
||||||
wiringPiMode = WPI_MODE_PINS ;
|
wiringPiMode = WPI_MODE_PINS ;
|
||||||
|
|
||||||
@ -1332,6 +1369,7 @@ int wiringPiSetupGpio (void)
|
|||||||
printf ("wiringPi: wiringPiSetupGpio called\n") ;
|
printf ("wiringPi: wiringPiSetupGpio called\n") ;
|
||||||
|
|
||||||
pinMode = pinModeGpio ;
|
pinMode = pinModeGpio ;
|
||||||
|
getAlt = getAltGpio ;
|
||||||
pullUpDnControl = pullUpDnControlGpio ;
|
pullUpDnControl = pullUpDnControlGpio ;
|
||||||
digitalWrite = digitalWriteGpio ;
|
digitalWrite = digitalWriteGpio ;
|
||||||
digitalWriteByte = digitalWriteByteGpio ;
|
digitalWriteByte = digitalWriteByteGpio ;
|
||||||
@ -1339,7 +1377,6 @@ int wiringPiSetupGpio (void)
|
|||||||
setPadDrive = setPadDriveGpio ;
|
setPadDrive = setPadDriveGpio ;
|
||||||
digitalRead = digitalReadGpio ;
|
digitalRead = digitalReadGpio ;
|
||||||
waitForInterrupt = waitForInterruptGpio ;
|
waitForInterrupt = waitForInterruptGpio ;
|
||||||
delayMicroseconds = delayMicrosecondsWPi ; // Same
|
|
||||||
pwmSetMode = pwmSetModeWPi ;
|
pwmSetMode = pwmSetModeWPi ;
|
||||||
pwmSetRange = pwmSetRangeWPi ;
|
pwmSetRange = pwmSetRangeWPi ;
|
||||||
pwmSetClock = pwmSetClockWPi ;
|
pwmSetClock = pwmSetClockWPi ;
|
||||||
@ -1363,7 +1400,6 @@ int wiringPiSetupSys (void)
|
|||||||
{
|
{
|
||||||
int boardRev ;
|
int boardRev ;
|
||||||
int pin ;
|
int pin ;
|
||||||
struct timeval tv ;
|
|
||||||
char fName [128] ;
|
char fName [128] ;
|
||||||
|
|
||||||
if (getenv ("WIRINGPI_DEBUG") != NULL)
|
if (getenv ("WIRINGPI_DEBUG") != NULL)
|
||||||
@ -1373,6 +1409,7 @@ int wiringPiSetupSys (void)
|
|||||||
printf ("wiringPi: wiringPiSetupSys called\n") ;
|
printf ("wiringPi: wiringPiSetupSys called\n") ;
|
||||||
|
|
||||||
pinMode = pinModeSys ;
|
pinMode = pinModeSys ;
|
||||||
|
getAlt = getAltSys ;
|
||||||
pullUpDnControl = pullUpDnControlSys ;
|
pullUpDnControl = pullUpDnControlSys ;
|
||||||
digitalWrite = digitalWriteSys ;
|
digitalWrite = digitalWriteSys ;
|
||||||
digitalWriteByte = digitalWriteByteSys ;
|
digitalWriteByte = digitalWriteByteSys ;
|
||||||
@ -1380,7 +1417,6 @@ int wiringPiSetupSys (void)
|
|||||||
setPadDrive = setPadDriveSys ;
|
setPadDrive = setPadDriveSys ;
|
||||||
digitalRead = digitalReadSys ;
|
digitalRead = digitalReadSys ;
|
||||||
waitForInterrupt = waitForInterruptSys ;
|
waitForInterrupt = waitForInterruptSys ;
|
||||||
delayMicroseconds = delayMicrosecondsSys ;
|
|
||||||
pwmSetMode = pwmSetModeSys ;
|
pwmSetMode = pwmSetModeSys ;
|
||||||
pwmSetRange = pwmSetRangeSys ;
|
pwmSetRange = pwmSetRangeSys ;
|
||||||
pwmSetClock = pwmSetClockSys ;
|
pwmSetClock = pwmSetClockSys ;
|
||||||
@ -1401,10 +1437,7 @@ int wiringPiSetupSys (void)
|
|||||||
sysFds [pin] = open (fName, O_RDWR) ;
|
sysFds [pin] = open (fName, O_RDWR) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialise the epoch for mills() ...
|
initialiseEpoch () ;
|
||||||
|
|
||||||
gettimeofday (&tv, NULL) ;
|
|
||||||
epoch = (tv.tv_sec * 1000000 + tv.tv_usec) / 1000 ;
|
|
||||||
|
|
||||||
wiringPiMode = WPI_MODE_GPIO_SYS ;
|
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 int wiringPiSetupPiFaceForGpioProg (void) ; // Don't use this - for gpio program only
|
||||||
|
|
||||||
extern void (*pinMode) (int pin, int mode) ;
|
extern void (*pinMode) (int pin, int mode) ;
|
||||||
|
extern int (*getAlt) (int pin) ;
|
||||||
extern void (*pullUpDnControl) (int pin, int pud) ;
|
extern void (*pullUpDnControl) (int pin, int pud) ;
|
||||||
extern void (*digitalWrite) (int pin, int value) ;
|
extern void (*digitalWrite) (int pin, int value) ;
|
||||||
extern void (*digitalWriteByte) (int value) ;
|
extern void (*digitalWriteByte) (int value) ;
|
||||||
extern void (*pwmWrite) (int pin, int value) ;
|
extern void (*pwmWrite) (int pin, int value) ;
|
||||||
extern void (*setPadDrive) (int group, int value) ;
|
extern void (*setPadDrive) (int group, int value) ;
|
||||||
extern int (*digitalRead) (int pin) ;
|
extern int (*digitalRead) (int pin) ;
|
||||||
extern void (*delayMicroseconds) (unsigned int howLong) ;
|
|
||||||
extern void (*pwmSetMode) (int mode) ;
|
extern void (*pwmSetMode) (int mode) ;
|
||||||
extern void (*pwmSetRange) (unsigned int range) ;
|
extern void (*pwmSetRange) (unsigned int range) ;
|
||||||
extern void (*pwmSetClock) (int divisor) ;
|
extern void (*pwmSetClock) (int divisor) ;
|
||||||
@ -111,7 +111,9 @@ extern int piHiPri (int pri) ;
|
|||||||
// Extras from arduino land
|
// Extras from arduino land
|
||||||
|
|
||||||
extern void delay (unsigned int howLong) ;
|
extern void delay (unsigned int howLong) ;
|
||||||
|
extern void delayMicroseconds (unsigned int howLong) ;
|
||||||
extern unsigned int millis (void) ;
|
extern unsigned int millis (void) ;
|
||||||
|
extern unsigned int micros (void) ;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user