wiringpi2 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/wiringpi/WiringPi/examples/blink.c +50 -0
- data/ext/wiringpi/WiringPi/examples/delayTest.c +107 -0
- data/ext/wiringpi/WiringPi/examples/ds1302.c +238 -0
- data/ext/wiringpi/WiringPi/examples/gertboard.c +94 -0
- data/ext/wiringpi/WiringPi/examples/header.h +23 -0
- data/ext/wiringpi/WiringPi/examples/isr-osc.c +118 -0
- data/ext/wiringpi/WiringPi/examples/isr.c +99 -0
- data/ext/wiringpi/WiringPi/examples/lcd.c +129 -0
- data/ext/wiringpi/WiringPi/examples/nes.c +67 -0
- data/ext/wiringpi/WiringPi/examples/okLed.c +83 -0
- data/ext/wiringpi/WiringPi/examples/piface.c +74 -0
- data/ext/wiringpi/WiringPi/examples/pwm.c +93 -0
- data/ext/wiringpi/WiringPi/examples/serialRead.c +48 -0
- data/ext/wiringpi/WiringPi/examples/serialTest.c +75 -0
- data/ext/wiringpi/WiringPi/examples/servo.c +57 -0
- data/ext/wiringpi/WiringPi/examples/speed.c +123 -0
- data/ext/wiringpi/WiringPi/examples/test1.c +111 -0
- data/ext/wiringpi/WiringPi/examples/test2.c +58 -0
- data/ext/wiringpi/WiringPi/examples/tone.c +59 -0
- data/ext/wiringpi/WiringPi/examples/wfi.c +161 -0
- data/ext/wiringpi/WiringPi/gpio/gpio.c +1371 -0
- data/ext/wiringpi/WiringPi/wiringPi/ds1302.c +239 -0
- data/ext/wiringpi/WiringPi/wiringPi/ds1302.h +44 -0
- data/ext/wiringpi/WiringPi/wiringPi/gertboard.c +166 -0
- data/ext/wiringpi/WiringPi/wiringPi/gertboard.h +40 -0
- data/ext/wiringpi/WiringPi/wiringPi/lcd.c +380 -0
- data/ext/wiringpi/WiringPi/wiringPi/lcd.h +46 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +155 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +195 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23017.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +195 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +236 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23x08.h +73 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23x0817.h +87 -0
- data/ext/wiringpi/WiringPi/wiringPi/piFace.c +179 -0
- data/ext/wiringpi/WiringPi/wiringPi/piFace.h +32 -0
- data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +50 -0
- data/ext/wiringpi/WiringPi/wiringPi/piNes.c +113 -0
- data/ext/wiringpi/WiringPi/wiringPi/piNes.h +45 -0
- data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +130 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/softServo.c +211 -0
- data/ext/wiringpi/WiringPi/wiringPi/softServo.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/softTone.c +121 -0
- data/ext/wiringpi/WiringPi/wiringPi/softTone.h +38 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.c +108 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +1664 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +168 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +227 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +119 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.c +213 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringShift.c +83 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringShift.h +41 -0
- data/ext/wiringpi/extconf.rb +8 -0
- data/ext/wiringpi/wiringpi_wrap.c +4378 -0
- data/lib/wiringpi/event.rb +21 -0
- data/lib/wiringpi/gpio.rb +131 -0
- data/lib/wiringpi/i2c.rb +26 -0
- data/lib/wiringpi/mcp23x17.rb +31 -0
- data/lib/wiringpi/serial.rb +49 -0
- data/lib/wiringpi/spi.rb +15 -0
- data/lib/wiringpi2.rb +42 -0
- metadata +122 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* piFace.c:
|
|
3
|
+
* Simple test for the PiFace interface board.
|
|
4
|
+
*
|
|
5
|
+
* Read the buttons and output the same to the LEDs
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
|
8
|
+
***********************************************************************
|
|
9
|
+
* This file is part of wiringPi:
|
|
10
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
11
|
+
*
|
|
12
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
13
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
14
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
15
|
+
* (at your option) any later version.
|
|
16
|
+
*
|
|
17
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
18
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20
|
+
* GNU Lesser General Public License for more details.
|
|
21
|
+
*
|
|
22
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
23
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
24
|
+
***********************************************************************
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
#include <wiringPi.h>
|
|
28
|
+
#include <piFace.h>
|
|
29
|
+
|
|
30
|
+
#include <stdio.h>
|
|
31
|
+
#include <stdlib.h>
|
|
32
|
+
#include <stdint.h>
|
|
33
|
+
|
|
34
|
+
int outputs [4] = { 0,0,0,0 } ;
|
|
35
|
+
|
|
36
|
+
#define PIFACE_BASE 200
|
|
37
|
+
|
|
38
|
+
void scanButton (int button)
|
|
39
|
+
{
|
|
40
|
+
if (digitalRead (PIFACE_BASE + button) == LOW)
|
|
41
|
+
{
|
|
42
|
+
outputs [button] ^= 1 ;
|
|
43
|
+
digitalWrite (PIFACE_BASE + button, outputs [button]) ;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
while (digitalRead (PIFACE_BASE + button) == LOW)
|
|
47
|
+
delay (1) ;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
int main (void)
|
|
52
|
+
{
|
|
53
|
+
int pin, button ;
|
|
54
|
+
|
|
55
|
+
printf ("Raspberry Pi wiringPiFace test program\n") ;
|
|
56
|
+
printf ("======================================\n") ;
|
|
57
|
+
|
|
58
|
+
if (piFaceSetup (200) == -1)
|
|
59
|
+
exit (1) ;
|
|
60
|
+
|
|
61
|
+
// Enable internal pull-ups
|
|
62
|
+
|
|
63
|
+
for (pin = PIFACE_BASE ; pin < (PIFACE_BASE + 8) ; ++pin)
|
|
64
|
+
pullUpDnControl (pin, PUD_UP) ;
|
|
65
|
+
|
|
66
|
+
for (;;)
|
|
67
|
+
{
|
|
68
|
+
for (button = 0 ; button < 4 ; ++button)
|
|
69
|
+
scanButton (button) ;
|
|
70
|
+
delay (1) ;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return 0 ;
|
|
74
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* pwm.c:
|
|
3
|
+
* Test of the software PWM driver. Needs 12 LEDs connected
|
|
4
|
+
* to the Pi.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
|
7
|
+
***********************************************************************
|
|
8
|
+
* This file is part of wiringPi:
|
|
9
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
10
|
+
*
|
|
11
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
12
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
13
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
14
|
+
* (at your option) any later version.
|
|
15
|
+
*
|
|
16
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
* GNU Lesser General Public License for more details.
|
|
20
|
+
*
|
|
21
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
22
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
+
***********************************************************************
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#include <stdio.h>
|
|
27
|
+
#include <errno.h>
|
|
28
|
+
#include <string.h>
|
|
29
|
+
|
|
30
|
+
#include <wiringPi.h>
|
|
31
|
+
#include <softPwm.h>
|
|
32
|
+
|
|
33
|
+
#define RANGE 100
|
|
34
|
+
#define NUM_LEDS 12
|
|
35
|
+
|
|
36
|
+
int ledMap [NUM_LEDS] = { 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13 } ;
|
|
37
|
+
|
|
38
|
+
int values [NUM_LEDS] = { 0, 17, 32, 50, 67, 85, 100, 85, 67, 50, 32, 17 } ;
|
|
39
|
+
|
|
40
|
+
int main ()
|
|
41
|
+
{
|
|
42
|
+
int i, j ;
|
|
43
|
+
char buf [80] ;
|
|
44
|
+
|
|
45
|
+
if (wiringPiSetup () == -1)
|
|
46
|
+
{
|
|
47
|
+
fprintf (stdout, "oops: %s\n", strerror (errno)) ;
|
|
48
|
+
return 1 ;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
for (i = 0 ; i < NUM_LEDS ; ++i)
|
|
52
|
+
{
|
|
53
|
+
softPwmCreate (ledMap [i], 0, RANGE) ;
|
|
54
|
+
printf ("%3d, %3d, %3d\n", i, ledMap [i], values [i]) ;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
fgets (buf, 80, stdin) ;
|
|
58
|
+
|
|
59
|
+
// Bring all up one by one:
|
|
60
|
+
|
|
61
|
+
for (i = 0 ; i < NUM_LEDS ; ++i)
|
|
62
|
+
for (j = 0 ; j <= 100 ; ++j)
|
|
63
|
+
{
|
|
64
|
+
softPwmWrite (ledMap [i], j) ;
|
|
65
|
+
delay (10) ;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
fgets (buf, 80, stdin) ;
|
|
69
|
+
|
|
70
|
+
// Down fast
|
|
71
|
+
|
|
72
|
+
for (i = 100 ; i > 0 ; --i)
|
|
73
|
+
{
|
|
74
|
+
for (j = 0 ; j < NUM_LEDS ; ++j)
|
|
75
|
+
softPwmWrite (ledMap [j], i) ;
|
|
76
|
+
delay (10) ;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
fgets (buf, 80, stdin) ;
|
|
80
|
+
|
|
81
|
+
for (;;)
|
|
82
|
+
{
|
|
83
|
+
for (i = 0 ; i < NUM_LEDS ; ++i)
|
|
84
|
+
softPwmWrite (ledMap [i], values [i]) ;
|
|
85
|
+
|
|
86
|
+
delay (50) ;
|
|
87
|
+
|
|
88
|
+
i = values [0] ;
|
|
89
|
+
for (j = 0 ; j < NUM_LEDS - 1 ; ++j)
|
|
90
|
+
values [j] = values [j + 1] ;
|
|
91
|
+
values [NUM_LEDS - 1] = i ;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* serial.c:
|
|
3
|
+
* Example program to read bytes from the Serial line
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
|
6
|
+
***********************************************************************
|
|
7
|
+
* This file is part of wiringPi:
|
|
8
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
9
|
+
*
|
|
10
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
11
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
12
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
13
|
+
* (at your option) any later version.
|
|
14
|
+
*
|
|
15
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
16
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18
|
+
* GNU Lesser General Public License for more details.
|
|
19
|
+
*
|
|
20
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
21
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
22
|
+
***********************************************************************
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
#include <stdio.h>
|
|
26
|
+
#include <string.h>
|
|
27
|
+
#include <errno.h>
|
|
28
|
+
|
|
29
|
+
#include <wiringSerial.h>
|
|
30
|
+
|
|
31
|
+
int main ()
|
|
32
|
+
{
|
|
33
|
+
int fd ;
|
|
34
|
+
|
|
35
|
+
if ((fd = serialOpen ("/dev/ttyAMA0", 115200)) < 0)
|
|
36
|
+
{
|
|
37
|
+
fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
|
|
38
|
+
return 1 ;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Loop, getting and printing characters
|
|
42
|
+
|
|
43
|
+
for (;;)
|
|
44
|
+
{
|
|
45
|
+
putchar (serialGetchar (fd)) ;
|
|
46
|
+
fflush (stdout) ;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* serialTest.c:
|
|
3
|
+
* Very simple program to test the serial port. Expects
|
|
4
|
+
* the port to be looped back to itself
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
|
7
|
+
***********************************************************************
|
|
8
|
+
* This file is part of wiringPi:
|
|
9
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
10
|
+
*
|
|
11
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
12
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
13
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
14
|
+
* (at your option) any later version.
|
|
15
|
+
*
|
|
16
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
* GNU Lesser General Public License for more details.
|
|
20
|
+
*
|
|
21
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
22
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
+
***********************************************************************
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#include <stdio.h>
|
|
27
|
+
#include <string.h>
|
|
28
|
+
#include <errno.h>
|
|
29
|
+
|
|
30
|
+
#include <wiringPi.h>
|
|
31
|
+
#include <wiringSerial.h>
|
|
32
|
+
|
|
33
|
+
int main ()
|
|
34
|
+
{
|
|
35
|
+
int fd ;
|
|
36
|
+
int count ;
|
|
37
|
+
unsigned int nextTime ;
|
|
38
|
+
|
|
39
|
+
if ((fd = serialOpen ("/dev/ttyAMA0", 115200)) < 0)
|
|
40
|
+
{
|
|
41
|
+
fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
|
|
42
|
+
return 1 ;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (wiringPiSetup () == -1)
|
|
46
|
+
{
|
|
47
|
+
fprintf (stdout, "Unable to start wiringPi: %s\n", strerror (errno)) ;
|
|
48
|
+
return 1 ;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
nextTime = millis () + 300 ;
|
|
52
|
+
|
|
53
|
+
for (count = 0 ; count < 256 ; )
|
|
54
|
+
{
|
|
55
|
+
if (millis () > nextTime)
|
|
56
|
+
{
|
|
57
|
+
printf ("\nOut: %3d: ", count) ;
|
|
58
|
+
fflush (stdout) ;
|
|
59
|
+
serialPutchar (fd, count) ;
|
|
60
|
+
nextTime += 300 ;
|
|
61
|
+
++count ;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
delay (3) ;
|
|
65
|
+
|
|
66
|
+
while (serialDataAvail (fd))
|
|
67
|
+
{
|
|
68
|
+
printf (" -> %3d", serialGetchar (fd)) ;
|
|
69
|
+
fflush (stdout) ;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
printf ("\n") ;
|
|
74
|
+
return 0 ;
|
|
75
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* servo.c:
|
|
3
|
+
* Test of the softServo code.
|
|
4
|
+
* Do not use this code - use the servoBlaster kernel module instead
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
|
7
|
+
***********************************************************************
|
|
8
|
+
* This file is part of wiringPi:
|
|
9
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
10
|
+
*
|
|
11
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
12
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
13
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
14
|
+
* (at your option) any later version.
|
|
15
|
+
*
|
|
16
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
* GNU Lesser General Public License for more details.
|
|
20
|
+
*
|
|
21
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
22
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
+
***********************************************************************
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#include <stdio.h>
|
|
27
|
+
#include <errno.h>
|
|
28
|
+
#include <string.h>
|
|
29
|
+
|
|
30
|
+
#include <wiringPi.h>
|
|
31
|
+
#include <softServo.h>
|
|
32
|
+
|
|
33
|
+
int main ()
|
|
34
|
+
{
|
|
35
|
+
if (wiringPiSetup () == -1)
|
|
36
|
+
{
|
|
37
|
+
fprintf (stdout, "oops: %s\n", strerror (errno)) ;
|
|
38
|
+
return 1 ;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
softServoSetup (0, 1, 2, 3, 4, 5, 6, 7) ;
|
|
42
|
+
|
|
43
|
+
softServoWrite (0, 0) ;
|
|
44
|
+
/*
|
|
45
|
+
softServoWrite (1, 1000) ;
|
|
46
|
+
softServoWrite (2, 1100) ;
|
|
47
|
+
softServoWrite (3, 1200) ;
|
|
48
|
+
softServoWrite (4, 1300) ;
|
|
49
|
+
softServoWrite (5, 1400) ;
|
|
50
|
+
softServoWrite (6, 1500) ;
|
|
51
|
+
softServoWrite (7, 2200) ;
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
for (;;)
|
|
55
|
+
delay (10) ;
|
|
56
|
+
|
|
57
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* speed.c:
|
|
3
|
+
* Simple program to measure the speed of the various GPIO
|
|
4
|
+
* access mechanisms.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
|
7
|
+
***********************************************************************
|
|
8
|
+
* This file is part of wiringPi:
|
|
9
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
10
|
+
*
|
|
11
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
12
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
13
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
14
|
+
* (at your option) any later version.
|
|
15
|
+
*
|
|
16
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
* GNU Lesser General Public License for more details.
|
|
20
|
+
*
|
|
21
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
22
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
+
***********************************************************************
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#include <wiringPi.h>
|
|
27
|
+
|
|
28
|
+
#include <stdio.h>
|
|
29
|
+
#include <stdlib.h>
|
|
30
|
+
#include <stdint.h>
|
|
31
|
+
|
|
32
|
+
#define FAST_COUNT 10000000
|
|
33
|
+
#define SLOW_COUNT 1000000
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
int main (void)
|
|
37
|
+
{
|
|
38
|
+
int i ;
|
|
39
|
+
uint32_t start, end, count, sum, perSec ;
|
|
40
|
+
|
|
41
|
+
printf ("Raspberry Pi wiringPi speed test program\n") ;
|
|
42
|
+
|
|
43
|
+
// Start the standard way
|
|
44
|
+
|
|
45
|
+
if (wiringPiSetup () == -1)
|
|
46
|
+
exit (1) ;
|
|
47
|
+
|
|
48
|
+
printf ("Native wiringPi method: (%8d iterations)\n", FAST_COUNT) ;
|
|
49
|
+
|
|
50
|
+
pinMode (0, OUTPUT) ;
|
|
51
|
+
|
|
52
|
+
sum = 0 ;
|
|
53
|
+
for (i = 0 ; i < 3 ; ++i)
|
|
54
|
+
{
|
|
55
|
+
printf (" Pass: %d: ", i) ;
|
|
56
|
+
fflush (stdout) ;
|
|
57
|
+
|
|
58
|
+
start = millis () ;
|
|
59
|
+
for (count = 0 ; count < FAST_COUNT ; ++count)
|
|
60
|
+
digitalWrite (0, 1) ;
|
|
61
|
+
end = millis () ;
|
|
62
|
+
printf (" %8dmS\n", end - start) ;
|
|
63
|
+
sum += (end - start) ;
|
|
64
|
+
}
|
|
65
|
+
digitalWrite (0, 0) ;
|
|
66
|
+
printf (" Average: %8dmS", sum / 3) ;
|
|
67
|
+
perSec = (int)(double)FAST_COUNT / (double)((double)sum / 3.0) * 1000.0 ;
|
|
68
|
+
printf (": %6d/sec\n", perSec) ;
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
printf ("Native GPIO method: (%8d iterations)\n", FAST_COUNT) ;
|
|
72
|
+
|
|
73
|
+
if (wiringPiSetupGpio () == -1)
|
|
74
|
+
exit (1) ;
|
|
75
|
+
|
|
76
|
+
pinMode (17, OUTPUT) ;
|
|
77
|
+
|
|
78
|
+
sum = 0 ;
|
|
79
|
+
for (i = 0 ; i < 3 ; ++i)
|
|
80
|
+
{
|
|
81
|
+
printf (" Pass: %d: ", i) ;
|
|
82
|
+
fflush (stdout) ;
|
|
83
|
+
|
|
84
|
+
start = millis () ;
|
|
85
|
+
for (count = 0 ; count < 10000000 ; ++count)
|
|
86
|
+
digitalWrite (17, 1) ;
|
|
87
|
+
end = millis () ;
|
|
88
|
+
printf (" %8dmS\n", end - start) ;
|
|
89
|
+
sum += (end - start) ;
|
|
90
|
+
}
|
|
91
|
+
digitalWrite (17, 0) ;
|
|
92
|
+
printf (" Average: %8dmS", sum / 3) ;
|
|
93
|
+
perSec = (int)(double)FAST_COUNT / (double)((double)sum / 3.0) * 1000.0 ;
|
|
94
|
+
printf (": %6d/sec\n", perSec) ;
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
// Switch to SYS mode:
|
|
98
|
+
|
|
99
|
+
if (wiringPiSetupSys () == -1)
|
|
100
|
+
exit (1) ;
|
|
101
|
+
|
|
102
|
+
printf ("/sys/class/gpio method: (%8d iterations)\n", SLOW_COUNT) ;
|
|
103
|
+
|
|
104
|
+
sum = 0 ;
|
|
105
|
+
for (i = 0 ; i < 3 ; ++i)
|
|
106
|
+
{
|
|
107
|
+
printf (" Pass: %d: ", i) ;
|
|
108
|
+
fflush (stdout) ;
|
|
109
|
+
|
|
110
|
+
start = millis () ;
|
|
111
|
+
for (count = 0 ; count < SLOW_COUNT ; ++count)
|
|
112
|
+
digitalWrite (17, 1) ;
|
|
113
|
+
end = millis () ;
|
|
114
|
+
printf (" %8dmS\n", end - start) ;
|
|
115
|
+
sum += (end - start) ;
|
|
116
|
+
}
|
|
117
|
+
digitalWrite (17, 0) ;
|
|
118
|
+
printf (" Average: %8dmS", sum / 3) ;
|
|
119
|
+
perSec = (int)(double)SLOW_COUNT / (double)((double)sum / 3.0) * 1000.0 ;
|
|
120
|
+
printf (": %6d/sec\n", perSec) ;
|
|
121
|
+
|
|
122
|
+
return 0 ;
|
|
123
|
+
}
|