wiringpi 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +7 -0
  2. data/ext/wiringpi/WiringPi/devLib/ds1302.c +240 -0
  3. data/ext/wiringpi/WiringPi/devLib/ds1302.h +44 -0
  4. data/ext/wiringpi/WiringPi/devLib/font.h +2577 -0
  5. data/ext/wiringpi/WiringPi/devLib/gertboard.c +164 -0
  6. data/ext/wiringpi/WiringPi/devLib/gertboard.h +45 -0
  7. data/ext/wiringpi/WiringPi/devLib/lcd.c +495 -0
  8. data/ext/wiringpi/WiringPi/devLib/lcd.h +52 -0
  9. data/ext/wiringpi/WiringPi/devLib/lcd128x64.c +673 -0
  10. data/ext/wiringpi/WiringPi/devLib/lcd128x64.h +39 -0
  11. data/ext/wiringpi/WiringPi/devLib/maxdetect.c +165 -0
  12. data/ext/wiringpi/{serial.h → WiringPi/devLib/maxdetect.h} +14 -15
  13. data/ext/wiringpi/WiringPi/devLib/piFace.c +112 -0
  14. data/ext/wiringpi/WiringPi/devLib/piFace.h +32 -0
  15. data/ext/wiringpi/WiringPi/devLib/piFaceOld.c +178 -0
  16. data/ext/wiringpi/WiringPi/devLib/piGlow.c +118 -0
  17. data/ext/wiringpi/WiringPi/devLib/piGlow.h +45 -0
  18. data/ext/wiringpi/WiringPi/devLib/piNes.c +113 -0
  19. data/ext/wiringpi/WiringPi/devLib/piNes.h +45 -0
  20. data/ext/wiringpi/WiringPi/examples/Gertboard/7segments.c +221 -0
  21. data/ext/wiringpi/WiringPi/examples/Gertboard/buttons.c +83 -0
  22. data/ext/wiringpi/WiringPi/examples/Gertboard/gertboard.c +96 -0
  23. data/ext/wiringpi/WiringPi/examples/Gertboard/record.c +60 -0
  24. data/ext/wiringpi/WiringPi/examples/Gertboard/temperature.c +78 -0
  25. data/ext/wiringpi/WiringPi/examples/Gertboard/voltmeter.c +73 -0
  26. data/ext/wiringpi/WiringPi/examples/Gertboard/vumeter.c +152 -0
  27. data/ext/wiringpi/WiringPi/examples/PiFace/blink.c +59 -0
  28. data/ext/wiringpi/WiringPi/examples/PiFace/buttons.c +103 -0
  29. data/ext/wiringpi/WiringPi/examples/PiFace/ladder.c +337 -0
  30. data/ext/wiringpi/WiringPi/examples/PiFace/metro.c +111 -0
  31. data/ext/wiringpi/WiringPi/examples/PiFace/motor.c +120 -0
  32. data/ext/wiringpi/WiringPi/examples/PiFace/reaction.c +194 -0
  33. data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow0.c +51 -0
  34. data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow1.c +258 -0
  35. data/ext/wiringpi/WiringPi/examples/PiGlow/piglow.c +176 -0
  36. data/ext/wiringpi/WiringPi/examples/blink.c +48 -0
  37. data/ext/wiringpi/WiringPi/examples/blink12.c +111 -0
  38. data/ext/wiringpi/WiringPi/examples/blink12drcs.c +125 -0
  39. data/ext/wiringpi/WiringPi/examples/blink6drcs.c +115 -0
  40. data/ext/wiringpi/WiringPi/examples/blink8.c +57 -0
  41. data/ext/wiringpi/WiringPi/examples/clock.c +201 -0
  42. data/ext/wiringpi/WiringPi/examples/delayTest.c +107 -0
  43. data/ext/wiringpi/WiringPi/examples/ds1302.c +238 -0
  44. data/ext/wiringpi/WiringPi/examples/header.h +23 -0
  45. data/ext/wiringpi/WiringPi/examples/isr-osc.c +118 -0
  46. data/ext/wiringpi/WiringPi/examples/isr.c +110 -0
  47. data/ext/wiringpi/WiringPi/examples/lcd-adafruit.c +347 -0
  48. data/ext/wiringpi/WiringPi/examples/lcd.c +286 -0
  49. data/ext/wiringpi/WiringPi/examples/lowPower.c +68 -0
  50. data/ext/wiringpi/WiringPi/examples/nes.c +67 -0
  51. data/ext/wiringpi/WiringPi/examples/okLed.c +82 -0
  52. data/ext/wiringpi/WiringPi/examples/pwm.c +58 -0
  53. data/ext/wiringpi/WiringPi/examples/q2w/binary.c +79 -0
  54. data/ext/wiringpi/WiringPi/examples/q2w/blink-io.c +61 -0
  55. data/ext/wiringpi/WiringPi/examples/q2w/blink.c +50 -0
  56. data/ext/wiringpi/WiringPi/examples/q2w/bright.c +59 -0
  57. data/ext/wiringpi/WiringPi/examples/q2w/button.c +63 -0
  58. data/ext/wiringpi/WiringPi/examples/q2w/volts.c +62 -0
  59. data/ext/wiringpi/WiringPi/examples/rht03.c +69 -0
  60. data/ext/wiringpi/WiringPi/examples/serialRead.c +48 -0
  61. data/ext/wiringpi/WiringPi/examples/serialTest.c +75 -0
  62. data/ext/wiringpi/WiringPi/examples/servo.c +57 -0
  63. data/ext/wiringpi/WiringPi/examples/softPwm.c +89 -0
  64. data/ext/wiringpi/WiringPi/examples/softTone.c +54 -0
  65. data/ext/wiringpi/WiringPi/examples/speed.c +95 -0
  66. data/ext/wiringpi/WiringPi/examples/spiSpeed.c +118 -0
  67. data/ext/wiringpi/WiringPi/examples/wfi.c +161 -0
  68. data/ext/wiringpi/WiringPi/gpio/gpio.c +1351 -0
  69. data/ext/wiringpi/WiringPi/gpio/pins.c +33 -0
  70. data/ext/wiringpi/WiringPi/gpio/readall.c +334 -0
  71. data/ext/wiringpi/WiringPi/gpio/version.h +1 -0
  72. data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +201 -0
  73. data/ext/wiringpi/WiringPi/wiringPi/drcSerial.h +33 -0
  74. data/ext/wiringpi/WiringPi/wiringPi/max31855.c +81 -0
  75. data/ext/wiringpi/WiringPi/wiringPi/max31855.h +33 -0
  76. data/ext/wiringpi/WiringPi/wiringPi/max5322.c +84 -0
  77. data/ext/wiringpi/WiringPi/wiringPi/max5322.h +33 -0
  78. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +149 -0
  79. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -0
  80. data/ext/wiringpi/WiringPi/wiringPi/mcp23016.c +164 -0
  81. data/ext/wiringpi/WiringPi/wiringPi/mcp23016.h +33 -0
  82. data/ext/wiringpi/WiringPi/wiringPi/mcp23016reg.h +48 -0
  83. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +195 -0
  84. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.h +33 -0
  85. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +189 -0
  86. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
  87. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +236 -0
  88. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.h +33 -0
  89. data/ext/wiringpi/WiringPi/wiringPi/mcp23x08.h +73 -0
  90. data/ext/wiringpi/WiringPi/wiringPi/mcp23x0817.h +87 -0
  91. data/ext/wiringpi/WiringPi/wiringPi/mcp3002.c +76 -0
  92. data/ext/wiringpi/WiringPi/wiringPi/mcp3002.h +33 -0
  93. data/ext/wiringpi/WiringPi/wiringPi/mcp3004.c +76 -0
  94. data/ext/wiringpi/WiringPi/wiringPi/mcp3004.h +33 -0
  95. data/ext/wiringpi/WiringPi/wiringPi/mcp3422.c +110 -0
  96. data/ext/wiringpi/WiringPi/wiringPi/mcp3422.h +43 -0
  97. data/ext/wiringpi/WiringPi/wiringPi/mcp4802.c +76 -0
  98. data/ext/wiringpi/WiringPi/wiringPi/mcp4802.h +33 -0
  99. data/ext/wiringpi/WiringPi/wiringPi/pcf8574.c +126 -0
  100. data/ext/wiringpi/WiringPi/wiringPi/pcf8574.h +33 -0
  101. data/ext/wiringpi/WiringPi/wiringPi/pcf8591.c +90 -0
  102. data/ext/wiringpi/WiringPi/wiringPi/pcf8591.h +33 -0
  103. data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +51 -0
  104. data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
  105. data/ext/wiringpi/WiringPi/wiringPi/sn3218.c +75 -0
  106. data/ext/wiringpi/WiringPi/wiringPi/sn3218.h +33 -0
  107. data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +166 -0
  108. data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +35 -0
  109. data/ext/wiringpi/WiringPi/wiringPi/softServo.c +211 -0
  110. data/ext/wiringpi/WiringPi/wiringPi/softServo.h +35 -0
  111. data/ext/wiringpi/WiringPi/wiringPi/softTone.c +150 -0
  112. data/ext/wiringpi/WiringPi/wiringPi/softTone.h +39 -0
  113. data/ext/wiringpi/WiringPi/wiringPi/sr595.c +109 -0
  114. data/ext/wiringpi/WiringPi/wiringPi/sr595.h +34 -0
  115. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +2007 -0
  116. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +224 -0
  117. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +232 -0
  118. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
  119. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +136 -0
  120. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +36 -0
  121. data/ext/wiringpi/{serial.c → WiringPi/wiringPi/wiringSerial.c} +38 -29
  122. data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
  123. data/ext/wiringpi/{wiringShift.c → WiringPi/wiringPi/wiringShift.c} +3 -4
  124. data/ext/wiringpi/{wiringShift.h → WiringPi/wiringPi/wiringShift.h} +5 -5
  125. data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.c +731 -0
  126. data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.h +26 -0
  127. data/ext/wiringpi/extconf.rb +7 -1
  128. data/ext/wiringpi/wiringpi_wrap.c +1741 -218
  129. data/lib/wiringpi.rb +24 -222
  130. data/lib/wiringpi/event.rb +21 -0
  131. data/lib/wiringpi/gpio.rb +139 -0
  132. data/lib/wiringpi/i2c.rb +26 -0
  133. data/lib/wiringpi/mcp23x17.rb +31 -0
  134. data/lib/wiringpi/serial.rb +49 -0
  135. data/lib/wiringpi/spi.rb +15 -0
  136. metadata +146 -22
  137. data/ext/wiringpi/wiringPi.c +0 -729
  138. data/ext/wiringpi/wiringPi.h +0 -69
@@ -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,89 @@
1
+ /*
2
+ * softPwm.c:
3
+ * Test of the software PWM driver. Needs 8 LEDs connected
4
+ * to the Pi - e.g. Ladder board.
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 8
35
+
36
+ int ledMap [NUM_LEDS] = { 0, 1, 2, 3, 4, 5, 6, 7 } ;
37
+
38
+ int values [NUM_LEDS] = { 0, 25, 50, 75, 100, 75, 50, 25 } ;
39
+
40
+ int main ()
41
+ {
42
+ int i, j ;
43
+ char buf [80] ;
44
+
45
+ wiringPiSetup () ;
46
+
47
+ for (i = 0 ; i < NUM_LEDS ; ++i)
48
+ {
49
+ softPwmCreate (ledMap [i], 0, RANGE) ;
50
+ printf ("%3d, %3d, %3d\n", i, ledMap [i], values [i]) ;
51
+ }
52
+
53
+ fgets (buf, 80, stdin) ;
54
+
55
+ // Bring all up one by one:
56
+
57
+ for (i = 0 ; i < NUM_LEDS ; ++i)
58
+ for (j = 0 ; j <= 100 ; ++j)
59
+ {
60
+ softPwmWrite (ledMap [i], j) ;
61
+ delay (10) ;
62
+ }
63
+
64
+ fgets (buf, 80, stdin) ;
65
+
66
+ // All Down
67
+
68
+ for (i = 100 ; i > 0 ; --i)
69
+ {
70
+ for (j = 0 ; j < NUM_LEDS ; ++j)
71
+ softPwmWrite (ledMap [j], i) ;
72
+ delay (10) ;
73
+ }
74
+
75
+ fgets (buf, 80, stdin) ;
76
+
77
+ for (;;)
78
+ {
79
+ for (i = 0 ; i < NUM_LEDS ; ++i)
80
+ softPwmWrite (ledMap [i], values [i]) ;
81
+
82
+ delay (50) ;
83
+
84
+ i = values [0] ;
85
+ for (j = 0 ; j < NUM_LEDS - 1 ; ++j)
86
+ values [j] = values [j + 1] ;
87
+ values [NUM_LEDS - 1] = i ;
88
+ }
89
+ }
@@ -0,0 +1,54 @@
1
+ /*
2
+ * softTone.c:
3
+ * Test of the softTone module in wiringPi
4
+ * Plays a scale out on pin 3 - connect pizeo disc to pin 3 & 0v
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 <softTone.h>
32
+
33
+ #define PIN 3
34
+
35
+ int scale [8] = { 262, 294, 330, 349, 392, 440, 494, 525 } ;
36
+
37
+ int main ()
38
+ {
39
+ int i ;
40
+
41
+ wiringPiSetup () ;
42
+
43
+ softToneCreate (PIN) ;
44
+
45
+ for (;;)
46
+ {
47
+ for (i = 0 ; i < 8 ; ++i)
48
+ {
49
+ printf ("%3d\n", i) ;
50
+ softToneWrite (PIN, scale [i]) ;
51
+ delay (500) ;
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,95 @@
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
+ #define PASSES 5
35
+
36
+ void speedTest (int pin, int maxCount)
37
+ {
38
+ int count, sum, perSec, i ;
39
+ unsigned int start, end ;
40
+
41
+ sum = 0 ;
42
+
43
+ for (i = 0 ; i < PASSES ; ++i)
44
+ {
45
+ start = millis () ;
46
+ for (count = 0 ; count < maxCount ; ++count)
47
+ digitalWrite (pin, 1) ;
48
+ end = millis () ;
49
+ printf (" %6d", end - start) ;
50
+ fflush (stdout) ;
51
+ sum += (end - start) ;
52
+ }
53
+
54
+ digitalWrite (pin, 0) ;
55
+ printf (". Av: %6dmS", sum / PASSES) ;
56
+ perSec = (int)(double)maxCount / (double)((double)sum / (double)PASSES) * 1000.0 ;
57
+ printf (": %7d/sec\n", perSec) ;
58
+ }
59
+
60
+
61
+ int main (void)
62
+ {
63
+ printf ("Raspberry Pi wiringPi GPIO speed test program\n") ;
64
+ printf ("=============================================\n") ;
65
+
66
+ // Start the standard way
67
+
68
+ printf ("\nNative wiringPi method: (%8d iterations)\n", FAST_COUNT) ;
69
+ wiringPiSetup () ;
70
+ pinMode (0, OUTPUT) ;
71
+ speedTest (0, FAST_COUNT) ;
72
+
73
+ // GPIO
74
+
75
+ printf ("\nNative GPIO method: (%8d iterations)\n", FAST_COUNT) ;
76
+ wiringPiSetupGpio () ;
77
+ pinMode (17, OUTPUT) ;
78
+ speedTest (17, FAST_COUNT) ;
79
+
80
+ // Phys
81
+
82
+ printf ("\nPhysical pin GPIO method: (%8d iterations)\n", FAST_COUNT) ;
83
+ wiringPiSetupPhys () ;
84
+ pinMode (11, OUTPUT) ;
85
+ speedTest (11, FAST_COUNT) ;
86
+
87
+ // Switch to SYS mode:
88
+
89
+ system ("/usr/local/bin/gpio export 17 out") ;
90
+ printf ("\n/sys/class/gpio method: (%8d iterations)\n", SLOW_COUNT) ;
91
+ wiringPiSetupSys () ;
92
+ speedTest (17, SLOW_COUNT) ;
93
+
94
+ return 0 ;
95
+ }
@@ -0,0 +1,118 @@
1
+ /*
2
+ * spiSpeed.c:
3
+ * Code to measure the SPI speed/latency.
4
+ * Copyright (c) 2014 Gordon Henderson
5
+ ***********************************************************************
6
+ * This file is part of wiringPi:
7
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
8
+ *
9
+ * wiringPi is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU Lesser General Public License as
11
+ * published by the Free Software Foundation, either version 3 of the
12
+ * License, or (at your option) any later version.
13
+ *
14
+ * wiringPi is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ * GNU Lesser General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU Lesser General Public
20
+ * License along with wiringPi.
21
+ * If not, see <http://www.gnu.org/licenses/>.
22
+ ***********************************************************************
23
+ */
24
+
25
+
26
+ #include <stdio.h>
27
+ #include <stdlib.h>
28
+ #include <unistd.h>
29
+ #include <stdint.h>
30
+ #include <string.h>
31
+ #include <errno.h>
32
+ //#include <fcntl.h>
33
+ //#include <sys/ioctl.h>
34
+ //#include <linux/spi/spidev.h>
35
+
36
+ #include <wiringPi.h>
37
+ #include <wiringPiSPI.h>
38
+
39
+ #define TRUE (1==1)
40
+ #define FALSE (!TRUE)
41
+
42
+ #define SPI_CHAN 0
43
+ #define NUM_TIMES 100
44
+ #define MAX_SIZE (1024*1024)
45
+
46
+ static int myFd ;
47
+
48
+
49
+ void spiSetup (int speed)
50
+ {
51
+ if ((myFd = wiringPiSPISetup (SPI_CHAN, speed)) < 0)
52
+ {
53
+ fprintf (stderr, "Can't open the SPI bus: %s\n", strerror (errno)) ;
54
+ exit (EXIT_FAILURE) ;
55
+ }
56
+ }
57
+
58
+
59
+ int main (void)
60
+ {
61
+ int speed, times, size ;
62
+ unsigned int start, end ;
63
+ int spiFail ;
64
+ unsigned char *myData ;
65
+ double timePerTransaction, perfectTimePerTransaction, dataSpeed ;
66
+
67
+ if ((myData = malloc (MAX_SIZE)) == NULL)
68
+ {
69
+ fprintf (stderr, "Unable to allocate buffer: %s\n", strerror (errno)) ;
70
+ exit (EXIT_FAILURE) ;
71
+ }
72
+
73
+ wiringPiSetup () ;
74
+
75
+ for (speed = 1 ; speed <= 32 ; speed *= 2)
76
+ {
77
+ printf ("+-------+--------+----------+----------+-----------+------------+\n") ;
78
+ printf ("| MHz | Size | mS/Trans | TpS | Mb/Sec | Latency mS |\n") ;
79
+ printf ("+-------+--------+----------+----------+-----------+------------+\n") ;
80
+
81
+ spiFail = FALSE ;
82
+ spiSetup (speed * 1000000) ;
83
+ for (size = 1 ; size <= MAX_SIZE ; size *= 2)
84
+ {
85
+ printf ("| %5d | %6d ", speed, size) ;
86
+
87
+ start = millis () ;
88
+ for (times = 0 ; times < NUM_TIMES ; ++times)
89
+ if (wiringPiSPIDataRW (SPI_CHAN, myData, size) == -1)
90
+ {
91
+ printf ("SPI failure: %s\n", strerror (errno)) ;
92
+ spiFail = TRUE ;
93
+ break ;
94
+ }
95
+ end = millis () ;
96
+
97
+ if (spiFail)
98
+ break ;
99
+
100
+ timePerTransaction = ((double)(end - start) / (double)NUM_TIMES) / 1000.0 ;
101
+ dataSpeed = (double)(size * 8) / (1024.0 * 1024.0) / timePerTransaction ;
102
+ perfectTimePerTransaction = ((double)(size * 8)) / ((double)(speed * 1000000)) ;
103
+
104
+ printf ("| %8.3f ", timePerTransaction * 1000.0) ;
105
+ printf ("| %8.1f ", 1.0 / timePerTransaction) ;
106
+ printf ("| %9.5f ", dataSpeed) ;
107
+ printf ("| %8.5f ", (timePerTransaction - perfectTimePerTransaction) * 1000.0) ;
108
+ printf ("|\n") ;
109
+
110
+ }
111
+
112
+ close (myFd) ;
113
+ printf ("+-------+--------+----------+----------+-----------+------------+\n") ;
114
+ printf ("\n") ;
115
+ }
116
+
117
+ return 0 ;
118
+ }