wiringpi 1.1.0 → 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.
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,31 @@
1
+ module WiringPi
2
+ class Modules
3
+ class Mcp23017 < ModuleBase
4
+
5
+ @i2c_address = 0x0
6
+
7
+ def initialize(pin_base, i2c_address)
8
+ @pin_base = pin_base
9
+ @pin_count = 16
10
+ @i2c_address = i2c_address
11
+ Wiringpi.mcp23017Setup( pin_base, i2c_address )
12
+ super()
13
+ end
14
+ end
15
+ class Mcp23s17 < ModuleBase
16
+
17
+ @spi_port = 0
18
+ @device_id = 0
19
+
20
+ def initialize(pin_base, spi_port, device_id)
21
+ @pin_base = pin_base
22
+ @pin_count = 16
23
+ @spi_port = spi_port
24
+ @device_id = device_id
25
+ Wiringpi.mcp23s17Setup( pin_base, spi_port, device_id )
26
+ super()
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,49 @@
1
+ module WiringPi
2
+ class Serial
3
+
4
+ @id = 0
5
+ @device = '/dev/ttyAMA0'
6
+ @baud = 9600
7
+
8
+ def initialize(device='/dev/ttyAMA0', baud=9600)
9
+
10
+ @device = device
11
+ @baud = baud
12
+
13
+ @id = Wiringpi.serialOpen(@device, @baud)
14
+
15
+ end
16
+
17
+ def serial_close
18
+
19
+ Wiringpi.serialClose(@id)
20
+ @id = 0
21
+
22
+ end
23
+
24
+ def serial_put_char(char)
25
+
26
+ Wiringpi.serialPutchar(@id, char)
27
+
28
+ end
29
+
30
+ def serial_puts(string)
31
+
32
+ Wiringpi.serialPuts(@id, string)
33
+
34
+ end
35
+
36
+ def serial_data_avail
37
+
38
+ Wiringpi.serialDataAvail(@id)
39
+
40
+ end
41
+
42
+ def serial_get_char
43
+
44
+ Wiringpi.serialGetchar(@id)
45
+
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,15 @@
1
+ module WiringPi
2
+ class SPI
3
+ @channel = 0
4
+ def initialize(channel,speed)
5
+ @channel = channel
6
+ Wiringpi.wiringPiSPISetup(channel,speed)
7
+ end
8
+ def wiringPiSPIGetFd()
9
+ return Wiringpi.wiringPiSPIGetFd(@channel)
10
+ end
11
+ def wiringPiSPIDataRW(data)
12
+ return Wiringpi.wiringPiSPIDataRW(@channel,data)
13
+ end
14
+ end
15
+ end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wiringpi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Gordon
@@ -10,51 +9,176 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2012-06-22 00:00:00.000000000 Z
12
+ date: 2013-04-07 00:00:00.000000000 Z
14
13
  dependencies: []
15
- description: ! 'WiringPi library wrapper for the Raspberry Pi only. Wraps up the Arduino
16
- wiring-like WiringPi library into a convinient Ruby gem. Currently includes GPIO
17
- functionality, serial and shiftOut/shiftIn support. Credit to Gordon for the WiringPi
18
- library, which can be found here: http://projects.drogon.net/raspberry-pi/wiringpi/'
14
+ description: 'WiringPi library wrapper for the Raspberry Pi only. Wraps up version
15
+ 2.x of the Arduino wiring-like WiringPi library into a convinient Ruby gem. Currently
16
+ includes GPIO functionality, I2C, SPI, serial and shiftOut/shiftIn support in addition
17
+ to peripheral drivers for things like the MCP23017. Credit to Gordon for the WiringPi
18
+ library, which can be found here: http://www.wiringpi.com'
19
19
  email: phil@gadgetoid.com
20
20
  executables: []
21
21
  extensions:
22
22
  - ext/wiringpi/extconf.rb
23
23
  extra_rdoc_files: []
24
24
  files:
25
- - lib/wiringpi.rb
26
- - ext/wiringpi/wiringShift.c
27
- - ext/wiringpi/wiringPi.c
28
- - ext/wiringpi/serial.c
29
- - ext/wiringpi/wiringpi_wrap.c
30
- - ext/wiringpi/wiringShift.h
31
- - ext/wiringpi/serial.h
32
- - ext/wiringpi/wiringPi.h
25
+ - ext/wiringpi/WiringPi/devLib/ds1302.c
26
+ - ext/wiringpi/WiringPi/devLib/ds1302.h
27
+ - ext/wiringpi/WiringPi/devLib/font.h
28
+ - ext/wiringpi/WiringPi/devLib/gertboard.c
29
+ - ext/wiringpi/WiringPi/devLib/gertboard.h
30
+ - ext/wiringpi/WiringPi/devLib/lcd.c
31
+ - ext/wiringpi/WiringPi/devLib/lcd.h
32
+ - ext/wiringpi/WiringPi/devLib/lcd128x64.c
33
+ - ext/wiringpi/WiringPi/devLib/lcd128x64.h
34
+ - ext/wiringpi/WiringPi/devLib/maxdetect.c
35
+ - ext/wiringpi/WiringPi/devLib/maxdetect.h
36
+ - ext/wiringpi/WiringPi/devLib/piFace.c
37
+ - ext/wiringpi/WiringPi/devLib/piFace.h
38
+ - ext/wiringpi/WiringPi/devLib/piFaceOld.c
39
+ - ext/wiringpi/WiringPi/devLib/piGlow.c
40
+ - ext/wiringpi/WiringPi/devLib/piGlow.h
41
+ - ext/wiringpi/WiringPi/devLib/piNes.c
42
+ - ext/wiringpi/WiringPi/devLib/piNes.h
43
+ - ext/wiringpi/WiringPi/examples/Gertboard/7segments.c
44
+ - ext/wiringpi/WiringPi/examples/Gertboard/buttons.c
45
+ - ext/wiringpi/WiringPi/examples/Gertboard/gertboard.c
46
+ - ext/wiringpi/WiringPi/examples/Gertboard/record.c
47
+ - ext/wiringpi/WiringPi/examples/Gertboard/temperature.c
48
+ - ext/wiringpi/WiringPi/examples/Gertboard/voltmeter.c
49
+ - ext/wiringpi/WiringPi/examples/Gertboard/vumeter.c
50
+ - ext/wiringpi/WiringPi/examples/PiFace/blink.c
51
+ - ext/wiringpi/WiringPi/examples/PiFace/buttons.c
52
+ - ext/wiringpi/WiringPi/examples/PiFace/ladder.c
53
+ - ext/wiringpi/WiringPi/examples/PiFace/metro.c
54
+ - ext/wiringpi/WiringPi/examples/PiFace/motor.c
55
+ - ext/wiringpi/WiringPi/examples/PiFace/reaction.c
56
+ - ext/wiringpi/WiringPi/examples/PiGlow/piGlow0.c
57
+ - ext/wiringpi/WiringPi/examples/PiGlow/piGlow1.c
58
+ - ext/wiringpi/WiringPi/examples/PiGlow/piglow.c
59
+ - ext/wiringpi/WiringPi/examples/blink.c
60
+ - ext/wiringpi/WiringPi/examples/blink12.c
61
+ - ext/wiringpi/WiringPi/examples/blink12drcs.c
62
+ - ext/wiringpi/WiringPi/examples/blink6drcs.c
63
+ - ext/wiringpi/WiringPi/examples/blink8.c
64
+ - ext/wiringpi/WiringPi/examples/clock.c
65
+ - ext/wiringpi/WiringPi/examples/delayTest.c
66
+ - ext/wiringpi/WiringPi/examples/ds1302.c
67
+ - ext/wiringpi/WiringPi/examples/header.h
68
+ - ext/wiringpi/WiringPi/examples/isr-osc.c
69
+ - ext/wiringpi/WiringPi/examples/isr.c
70
+ - ext/wiringpi/WiringPi/examples/lcd-adafruit.c
71
+ - ext/wiringpi/WiringPi/examples/lcd.c
72
+ - ext/wiringpi/WiringPi/examples/lowPower.c
73
+ - ext/wiringpi/WiringPi/examples/nes.c
74
+ - ext/wiringpi/WiringPi/examples/okLed.c
75
+ - ext/wiringpi/WiringPi/examples/pwm.c
76
+ - ext/wiringpi/WiringPi/examples/q2w/binary.c
77
+ - ext/wiringpi/WiringPi/examples/q2w/blink-io.c
78
+ - ext/wiringpi/WiringPi/examples/q2w/blink.c
79
+ - ext/wiringpi/WiringPi/examples/q2w/bright.c
80
+ - ext/wiringpi/WiringPi/examples/q2w/button.c
81
+ - ext/wiringpi/WiringPi/examples/q2w/volts.c
82
+ - ext/wiringpi/WiringPi/examples/rht03.c
83
+ - ext/wiringpi/WiringPi/examples/serialRead.c
84
+ - ext/wiringpi/WiringPi/examples/serialTest.c
85
+ - ext/wiringpi/WiringPi/examples/servo.c
86
+ - ext/wiringpi/WiringPi/examples/softPwm.c
87
+ - ext/wiringpi/WiringPi/examples/softTone.c
88
+ - ext/wiringpi/WiringPi/examples/speed.c
89
+ - ext/wiringpi/WiringPi/examples/spiSpeed.c
90
+ - ext/wiringpi/WiringPi/examples/wfi.c
91
+ - ext/wiringpi/WiringPi/gpio/gpio.c
92
+ - ext/wiringpi/WiringPi/gpio/pins.c
93
+ - ext/wiringpi/WiringPi/gpio/readall.c
94
+ - ext/wiringpi/WiringPi/gpio/version.h
95
+ - ext/wiringpi/WiringPi/wiringPi/drcSerial.c
96
+ - ext/wiringpi/WiringPi/wiringPi/drcSerial.h
97
+ - ext/wiringpi/WiringPi/wiringPi/max31855.c
98
+ - ext/wiringpi/WiringPi/wiringPi/max31855.h
99
+ - ext/wiringpi/WiringPi/wiringPi/max5322.c
100
+ - ext/wiringpi/WiringPi/wiringPi/max5322.h
101
+ - ext/wiringpi/WiringPi/wiringPi/mcp23008.c
102
+ - ext/wiringpi/WiringPi/wiringPi/mcp23008.h
103
+ - ext/wiringpi/WiringPi/wiringPi/mcp23016.c
104
+ - ext/wiringpi/WiringPi/wiringPi/mcp23016.h
105
+ - ext/wiringpi/WiringPi/wiringPi/mcp23016reg.h
106
+ - ext/wiringpi/WiringPi/wiringPi/mcp23017.c
107
+ - ext/wiringpi/WiringPi/wiringPi/mcp23017.h
108
+ - ext/wiringpi/WiringPi/wiringPi/mcp23s08.c
109
+ - ext/wiringpi/WiringPi/wiringPi/mcp23s08.h
110
+ - ext/wiringpi/WiringPi/wiringPi/mcp23s17.c
111
+ - ext/wiringpi/WiringPi/wiringPi/mcp23s17.h
112
+ - ext/wiringpi/WiringPi/wiringPi/mcp23x08.h
113
+ - ext/wiringpi/WiringPi/wiringPi/mcp23x0817.h
114
+ - ext/wiringpi/WiringPi/wiringPi/mcp3002.c
115
+ - ext/wiringpi/WiringPi/wiringPi/mcp3002.h
116
+ - ext/wiringpi/WiringPi/wiringPi/mcp3004.c
117
+ - ext/wiringpi/WiringPi/wiringPi/mcp3004.h
118
+ - ext/wiringpi/WiringPi/wiringPi/mcp3422.c
119
+ - ext/wiringpi/WiringPi/wiringPi/mcp3422.h
120
+ - ext/wiringpi/WiringPi/wiringPi/mcp4802.c
121
+ - ext/wiringpi/WiringPi/wiringPi/mcp4802.h
122
+ - ext/wiringpi/WiringPi/wiringPi/pcf8574.c
123
+ - ext/wiringpi/WiringPi/wiringPi/pcf8574.h
124
+ - ext/wiringpi/WiringPi/wiringPi/pcf8591.c
125
+ - ext/wiringpi/WiringPi/wiringPi/pcf8591.h
126
+ - ext/wiringpi/WiringPi/wiringPi/piHiPri.c
127
+ - ext/wiringpi/WiringPi/wiringPi/piThread.c
128
+ - ext/wiringpi/WiringPi/wiringPi/sn3218.c
129
+ - ext/wiringpi/WiringPi/wiringPi/sn3218.h
130
+ - ext/wiringpi/WiringPi/wiringPi/softPwm.c
131
+ - ext/wiringpi/WiringPi/wiringPi/softPwm.h
132
+ - ext/wiringpi/WiringPi/wiringPi/softServo.c
133
+ - ext/wiringpi/WiringPi/wiringPi/softServo.h
134
+ - ext/wiringpi/WiringPi/wiringPi/softTone.c
135
+ - ext/wiringpi/WiringPi/wiringPi/softTone.h
136
+ - ext/wiringpi/WiringPi/wiringPi/sr595.c
137
+ - ext/wiringpi/WiringPi/wiringPi/sr595.h
138
+ - ext/wiringpi/WiringPi/wiringPi/wiringPi.c
139
+ - ext/wiringpi/WiringPi/wiringPi/wiringPi.h
140
+ - ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c
141
+ - ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h
142
+ - ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c
143
+ - ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h
144
+ - ext/wiringpi/WiringPi/wiringPi/wiringSerial.c
145
+ - ext/wiringpi/WiringPi/wiringPi/wiringSerial.h
146
+ - ext/wiringpi/WiringPi/wiringPi/wiringShift.c
147
+ - ext/wiringpi/WiringPi/wiringPi/wiringShift.h
148
+ - ext/wiringpi/WiringPi/wiringPi/wpiExtensions.c
149
+ - ext/wiringpi/WiringPi/wiringPi/wpiExtensions.h
33
150
  - ext/wiringpi/extconf.rb
151
+ - ext/wiringpi/wiringpi_wrap.c
152
+ - lib/wiringpi.rb
153
+ - lib/wiringpi/event.rb
154
+ - lib/wiringpi/gpio.rb
155
+ - lib/wiringpi/i2c.rb
156
+ - lib/wiringpi/mcp23x17.rb
157
+ - lib/wiringpi/serial.rb
158
+ - lib/wiringpi/spi.rb
34
159
  homepage: http://rubygems.org/gems/wiringpi
35
160
  licenses:
36
- - GNU General Public License
161
+ - GNU Lesser General Public License v3
162
+ metadata: {}
37
163
  post_install_message:
38
164
  rdoc_options: []
39
165
  require_paths:
40
166
  - lib
41
167
  required_ruby_version: !ruby/object:Gem::Requirement
42
- none: false
43
168
  requirements:
44
- - - ! '>='
169
+ - - ">="
45
170
  - !ruby/object:Gem::Version
46
171
  version: '0'
47
172
  required_rubygems_version: !ruby/object:Gem::Requirement
48
- none: false
49
173
  requirements:
50
- - - ! '>='
174
+ - - ">="
51
175
  - !ruby/object:Gem::Version
52
176
  version: '0'
53
177
  requirements: []
54
178
  rubyforge_project:
55
- rubygems_version: 1.8.24
179
+ rubygems_version: 2.2.2
56
180
  signing_key:
57
- specification_version: 3
181
+ specification_version: 4
58
182
  summary: Arduino wiring-like library for Raspberry Pi GPIO. Will only work on a Pi.
59
183
  Alpha version.
60
184
  test_files: []
@@ -1,729 +0,0 @@
1
- /*
2
- * wiringPi:
3
- * Arduino compatable (ish) Wiring library for the Raspberry Pi
4
- * Copyright (c) 2012 Gordon Henderson
5
- *
6
- * Thanks to code samples from Gert Jan van Loo and the
7
- * BCM2835 ARM Peripherals manual, however it's missing
8
- * the clock section /grr/mutter/
9
- ***********************************************************************
10
- * This file is part of wiringPi:
11
- * https://projects.drogon.net/raspberry-pi/wiringpi/
12
- *
13
- * wiringPi is free software: you can redistribute it and/or modify
14
- * it under the terms of the GNU General Public License as published by
15
- * the Free Software Foundation, either version 3 of the License, or
16
- * (at your option) any later version.
17
- *
18
- * wiringPi is distributed in the hope that it will be useful,
19
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- * GNU General Public License for more details.
22
- *
23
- * You should have received a copy of the GNU General Public License
24
- * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
25
- ***********************************************************************
26
- */
27
-
28
- // Revisions:
29
- // 2 Jul 2012:
30
- // Fixed a few more bugs to do with range-checking when in GPIO mode.
31
- // 11 Jun 2012:
32
- // Fixed some typos.
33
- // Added c++ support for the .h file
34
- // Added a new function to allow for using my "pin" numbers, or native
35
- // GPIO pin numbers.
36
- // Removed my busy-loop delay and replaced it with a call to delayMicroseconds
37
- //
38
- // 02 May 2012:
39
- // Added in the 2 UART pins
40
- // Change maxPins to numPins to more accurately reflect purpose
41
-
42
- // Pad drive current fiddling
43
-
44
- #undef DEBUG_PADS
45
-
46
- #include <stdio.h>
47
- #include <stdint.h>
48
- #include <unistd.h>
49
- #include <errno.h>
50
- #include <string.h>
51
- #include <time.h>
52
- #include <fcntl.h>
53
- #include <sys/time.h>
54
- #include <sys/mman.h>
55
- #include <sys/types.h>
56
- #include <sys/stat.h>
57
-
58
-
59
-
60
- #include "wiringPi.h"
61
-
62
- #ifndef TRUE
63
- #define TRUE (1==1)
64
- #define FALSE (1==2)
65
- #endif
66
-
67
- // Port function select bits
68
-
69
- #define FSEL_INPT 0b000
70
- #define FSEL_OUTP 0b001
71
- #define FSEL_ALT0 0b100
72
- #define FSEL_ALT0 0b100
73
- #define FSEL_ALT1 0b101
74
- #define FSEL_ALT2 0b110
75
- #define FSEL_ALT3 0b111
76
- #define FSEL_ALT4 0b011
77
- #define FSEL_ALT5 0b010
78
-
79
- // Access from ARM Running Linux
80
- // Take from Gerts code. Some of this is not in the manual
81
- // that I can find )-:
82
-
83
- #define BCM2708_PERI_BASE 0x20000000
84
- #define GPIO_PADS (BCM2708_PERI_BASE + 0x100000)
85
- #define CLOCK_BASE (BCM2708_PERI_BASE + 0x101000)
86
- #define GPIO_BASE (BCM2708_PERI_BASE + 0x200000)
87
- #define GPIO_PWM (BCM2708_PERI_BASE + 0x20C000)
88
-
89
- #define PAGE_SIZE (4*1024)
90
- #define BLOCK_SIZE (4*1024)
91
-
92
- // PWM
93
-
94
- #define PWM_CONTROL 0
95
- #define PWM_STATUS 1
96
- #define PWM0_RANGE 4
97
- #define PWM0_DATA 5
98
- #define PWM1_RANGE 8
99
- #define PWM1_DATA 9
100
-
101
- #define PWMCLK_CNTL 40
102
- #define PWMCLK_DIV 41
103
-
104
- #define PWM1_MS_MODE 0x8000 // Run in MS mode
105
- #define PWM1_USEFIFO 0x2000 // Data from FIFO
106
- #define PWM1_REVPOLAR 0x1000 // Reverse polarity
107
- #define PWM1_OFFSTATE 0x0800 // Ouput Off state
108
- #define PWM1_REPEATFF 0x0400 // Repeat last value if FIFO empty
109
- #define PWM1_SERIAL 0x0200 // Run in serial mode
110
- #define PWM1_ENABLE 0x0100 // Channel Enable
111
-
112
- #define PWM0_MS_MODE 0x0080 // Run in MS mode
113
- #define PWM0_USEFIFO 0x0020 // Data from FIFO
114
- #define PWM0_REVPOLAR 0x0010 // Reverse polarity
115
- #define PWM0_OFFSTATE 0x0008 // Ouput Off state
116
- #define PWM0_REPEATFF 0x0004 // Repeat last value if FIFO empty
117
- #define PWM0_SERIAL 0x0002 // Run in serial mode
118
- #define PWM0_ENABLE 0x0001 // Channel Enable
119
-
120
-
121
- // Locals to hold pointers to the hardware
122
-
123
- static volatile uint32_t *gpio ;
124
- static volatile uint32_t *pwm ;
125
- static volatile uint32_t *clk ;
126
-
127
- // The BCM2835 has 54 GPIO pins.
128
- // BCM2835 data sheet, Page 90 onwards.
129
- // There are 6 control registers, each control the functions of a block
130
- // of 10 pins.
131
- // Each control register has 10 sets of 3 bits per GPIO pin:
132
- //
133
- // 000 = GPIO Pin X is an input
134
- // 001 = GPIO Pin X is an output
135
- // 100 = GPIO Pin X takes alternate function 0
136
- // 101 = GPIO Pin X takes alternate function 1
137
- // 110 = GPIO Pin X takes alternate function 2
138
- // 111 = GPIO Pin X takes alternate function 3
139
- // 011 = GPIO Pin X takes alternate function 4
140
- // 010 = GPIO Pin X takes alternate function 5
141
- //
142
- // So the 3 bits for port X are:
143
- // X / 10 + ((X % 10) * 3)
144
-
145
- // sysFds:
146
- // Map a file descriptor from the /sys/class/gpio/gpioX/value file
147
-
148
- static int sysFds [64] ;
149
-
150
- // Mode
151
-
152
- static int gpioPinMode ;
153
-
154
- // Doing it the Arduino way with lookup tables...
155
- // Yes, it's probably more innefficient than all the bit-twidling, but it
156
- // does tend to make it all a bit clearer. At least to me!
157
-
158
- // pinToGpio:
159
- // Take a Wiring pin (0 through X) and re-map it to the BCM_GPIO pin
160
-
161
- static int pinToGpio [] =
162
- {
163
- 17, 18, 21, 22, 23, 24, 25, 4, // From the Original Wiki - GPIO 0 through 7
164
- 0, 1, // I2C - SDA0, SCL0
165
- 8, 7, // SPI - CE1, CE0
166
- 10, 9, 11, // SPI - MOSI, MISO, SCLK
167
- 14, 15, // UART - Tx, Rx
168
- } ;
169
-
170
- // gpioToGPFSEL:
171
- // Map a BCM_GPIO pin to it's control port. (GPFSEL 0-5)
172
-
173
- static uint8_t gpioToGPFSEL [] =
174
- {
175
- 0,0,0,0,0,0,0,0,0,0,
176
- 1,1,1,1,1,1,1,1,1,1,
177
- 2,2,2,2,2,2,2,2,2,2,
178
- 3,3,3,3,3,3,3,3,3,3,
179
- 4,4,4,4,4,4,4,4,4,4,
180
- 5,5,5,5,5,5,5,5,5,5,
181
- } ;
182
-
183
- // gpioToShift
184
- // Define the shift up for the 3 bits per pin in each GPFSEL port
185
-
186
- static uint8_t gpioToShift [] =
187
- {
188
- 0,3,6,9,12,15,18,21,24,27,
189
- 0,3,6,9,12,15,18,21,24,27,
190
- 0,3,6,9,12,15,18,21,24,27,
191
- 0,3,6,9,12,15,18,21,24,27,
192
- 0,3,6,9,12,15,18,21,24,27,
193
- } ;
194
-
195
- // gpioToGPSET:
196
- // (Word) offset to the GPIO Set registers for each GPIO pin
197
-
198
- static uint8_t gpioToGPSET [] =
199
- {
200
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
201
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
202
- } ;
203
-
204
- // gpioToGPCLR:
205
- // (Word) offset to the GPIO Clear registers for each GPIO pin
206
-
207
- static uint8_t gpioToGPCLR [] =
208
- {
209
- 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
210
- 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
211
- } ;
212
-
213
- // gpioToGPLEV:
214
- // (Word) offset to the GPIO Input level registers for each GPIO pin
215
-
216
- static uint8_t gpioToGPLEV [] =
217
- {
218
- 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
219
- 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
220
- } ;
221
-
222
- // gpioToPUDCLK
223
- // (Word) offset to the Pull Up Down Clock regsiter
224
-
225
- static uint8_t gpioToPUDCLK [] =
226
- {
227
- 38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,
228
- 39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
229
- } ;
230
-
231
- // gpioToPwmALT
232
- // the ALT value to put a GPIO pin into PWM mode
233
-
234
- static uint8_t gpioToPwmALT [] =
235
- {
236
- 0, 0, 0, 0, 0, 0, 0, 0, // 0 -> 7
237
- 0, 0, 0, 0, FSEL_ALT0, FSEL_ALT0, 0, 0, // 8 -> 15
238
- 0, 0, FSEL_ALT5, FSEL_ALT5, 0, 0, 0, 0, // 16 -> 23
239
- 0, 0, 0, 0, 0, 0, 0, 0, // 24 -> 31
240
- 0, 0, 0, 0, 0, 0, 0, 0, // 32 -> 39
241
- FSEL_ALT0, FSEL_ALT0, 0, 0, 0, FSEL_ALT0, 0, 0, // 40 -> 47
242
- 0, 0, 0, 0, 0, 0, 0, 0, // 48 -> 55
243
- 0, 0, 0, 0, 0, 0, 0, 0, // 56 -> 63
244
- } ;
245
-
246
- static uint8_t gpioToPwmPort [] =
247
- {
248
- 0, 0, 0, 0, 0, 0, 0, 0, // 0 -> 7
249
- 0, 0, 0, 0, PWM0_DATA, PWM1_DATA, 0, 0, // 8 -> 15
250
- 0, 0, PWM0_DATA, PWM1_DATA, 0, 0, 0, 0, // 16 -> 23
251
- 0, 0, 0, 0, 0, 0, 0, 0, // 24 -> 31
252
- 0, 0, 0, 0, 0, 0, 0, 0, // 32 -> 39
253
- PWM0_DATA, PWM1_DATA, 0, 0, 0, PWM1_DATA, 0, 0, // 40 -> 47
254
- 0, 0, 0, 0, 0, 0, 0, 0, // 48 -> 55
255
- 0, 0, 0, 0, 0, 0, 0, 0, // 56 -> 63
256
-
257
- } ;
258
-
259
-
260
- // Time for easy calculations
261
-
262
- static unsigned long long epoch ;
263
-
264
- //////////////////////////////////////////////////////////////////////////////////
265
-
266
-
267
- /*
268
- * wiringPiGpioMode:
269
- * Set the mode - use Pin numbers (0-16) or GPIO number (seemingly random)
270
- *********************************************************************************
271
- */
272
-
273
- void wiringPiGpioMode (int mode)
274
- {
275
- gpioPinMode = mode ;
276
- }
277
-
278
-
279
- /*
280
- * wiringPiSetup:
281
- * Must be called once at the start of your program execution.
282
- *
283
- * Default setup: Initialises the system into wiringPi Pin mode and uses the
284
- * memory mapped hardware directly.
285
- *********************************************************************************
286
- */
287
-
288
- int wiringPiSetup (void)
289
- {
290
- int fd ;
291
- uint8_t *gpioMem, *pwmMem, *clkMem ;
292
- struct timeval tv ;
293
-
294
- #ifdef DEBUG_PADS
295
- uint8_t *gpioMem, *padsMem, *pwmMem, *clkMem ;
296
- uint32_t *pads ;
297
- #endif
298
-
299
- // Set Pin mode by default
300
-
301
- wiringPiGpioMode (WPI_MODE_PINS) ;
302
-
303
- // Open the master /dev/memory device
304
-
305
- if ((fd = open ("/dev/mem", O_RDWR | O_SYNC) ) < 0)
306
- {
307
- fprintf (stderr, "wiringPiSetup: Unable to open /dev/mem: %s\n", strerror (errno)) ;
308
- return -1 ;
309
- }
310
-
311
- // GPIO:
312
-
313
- // Allocate 2 pages - 1 ...
314
-
315
- if ((gpioMem = malloc (BLOCK_SIZE + (PAGE_SIZE-1))) == NULL)
316
- {
317
- fprintf (stderr, "wiringPiSetup: malloc failed: %s\n", strerror (errno)) ;
318
- return -1 ;
319
- }
320
-
321
- // ... presumably to make sure we can round it up to a whole page size
322
-
323
- if (((uint32_t)gpioMem % PAGE_SIZE) != 0)
324
- gpioMem += PAGE_SIZE - ((uint32_t)gpioMem % PAGE_SIZE) ;
325
-
326
- gpio = (uint32_t *)mmap((caddr_t)gpioMem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd, GPIO_BASE) ;
327
-
328
- if ((int32_t)gpio < 0)
329
- {
330
- fprintf (stderr, "wiringPiSetup: mmap failed: %s\n", strerror (errno)) ;
331
- return -1 ;
332
- }
333
-
334
- // PWM
335
-
336
- if ((pwmMem = malloc (BLOCK_SIZE + (PAGE_SIZE-1))) == NULL)
337
- {
338
- fprintf (stderr, "wiringPiSetup: pwmMem malloc failed: %s\n", strerror (errno)) ;
339
- return -1 ;
340
- }
341
-
342
- if (((uint32_t)pwmMem % PAGE_SIZE) != 0)
343
- pwmMem += PAGE_SIZE - ((uint32_t)pwmMem % PAGE_SIZE) ;
344
-
345
- pwm = (uint32_t *)mmap(pwmMem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd, GPIO_PWM) ;
346
-
347
- if ((int32_t)pwm < 0)
348
- {
349
- fprintf (stderr, "wiringPiSetup: mmap failed (pwm): %s\n", strerror (errno)) ;
350
- return -1 ;
351
- }
352
-
353
- // Clock control (needed for PWM)
354
-
355
- if ((clkMem = malloc (BLOCK_SIZE + (PAGE_SIZE-1))) == NULL)
356
- {
357
- fprintf (stderr, "wiringPiSetup: clkMem malloc failed: %s\n", strerror (errno)) ;
358
- return -1 ;
359
- }
360
-
361
- if (((uint32_t)clkMem % PAGE_SIZE) != 0)
362
- clkMem += PAGE_SIZE - ((uint32_t)clkMem % PAGE_SIZE) ;
363
-
364
- clk = (uint32_t *)mmap(clkMem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd, CLOCK_BASE) ;
365
-
366
- if ((int32_t)clk < 0)
367
- {
368
- fprintf (stderr, "wiringPiSetup: mmap failed (clk): %s\n", strerror (errno)) ;
369
- return -1 ;
370
- }
371
-
372
- #ifdef DEBUG_PADS
373
- if ((padsMem = malloc (BLOCK_SIZE + (PAGE_SIZE-1))) == NULL)
374
- {
375
- fprintf (stderr, "wiringPiSetup: padsMem malloc failed: %s\n", strerror (errno)) ;
376
- return -1 ;
377
- }
378
-
379
- if (((uint32_t)padsMem % PAGE_SIZE) != 0)
380
- padsMem += PAGE_SIZE - ((uint32_t)padsMem % PAGE_SIZE) ;
381
-
382
- pads = (uint32_t *)mmap(padsMem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd, GPIO_PADS) ;
383
-
384
- if ((int32_t)pads < 0)
385
- {
386
- fprintf (stderr, "wiringPiSetup: mmap failed (pads): %s\n", strerror (errno)) ;
387
- return -1 ;
388
- }
389
-
390
- printf ("Checking pads @ 0x%08X\n", (unsigned int)pads) ;
391
-
392
- printf ("%08X %08X %08X\n", *(pads + 11), *(pads + 12), *(pads + 13)) ;
393
- // *(pads + 11) = 0x1F ;
394
- printf ("%08X %08X %08X\n", *(pads + 11), *(pads + 12), *(pads + 13)) ;
395
- #endif
396
-
397
- gettimeofday (&tv, NULL) ;
398
- epoch = (tv.tv_sec * 1000000 + tv.tv_usec) / 1000 ;
399
-
400
- return 0 ;
401
- }
402
-
403
-
404
- /*
405
- * wiringPiSetupGpio:
406
- * Must be called once at the start of your program execution.
407
- *
408
- * GPIO setup: Initialises the system into GPIO Pin mode and uses the
409
- * memory mapped hardware directly.
410
- *********************************************************************************
411
- */
412
-
413
- int wiringPiSetupGpio (void)
414
- {
415
- int x = wiringPiSetup () ;
416
-
417
- if (x != 0)
418
- return x ;
419
-
420
- wiringPiGpioMode (WPI_MODE_GPIO) ;
421
- return 0 ;
422
- }
423
-
424
-
425
- /*
426
- * wiringPiSetupSys:
427
- * Must be called once at the start of your program execution.
428
- *
429
- * Initialisation (again), however this time we are using the /sys/class/gpio
430
- * interface to the GPIO systems - slightly slower, but always usable as
431
- * a non-root user, assuming the devices are already exported and setup correctly.
432
- */
433
-
434
- int wiringPiSetupSys (void)
435
- {
436
- int fd, pin ;
437
- struct timeval tv ;
438
- char fName [128] ;
439
-
440
- // Set GPIO_SYS mode by default
441
-
442
- wiringPiGpioMode (WPI_MODE_GPIO_SYS) ;
443
-
444
- // Open and scan the directory, looking for exported GPIOs, and pre-open
445
- // the 'value' part to speed things up for later
446
-
447
- for (pin = 0 ; pin < 64 ; ++pin)
448
- {
449
- sysFds [pin] = -1 ;
450
- sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ;
451
- if ((fd = open (fName, O_RDWR)) == -1)
452
- continue ;
453
- sysFds [pin] = fd ;
454
- }
455
-
456
- gettimeofday (&tv, NULL) ;
457
- epoch = (tv.tv_sec * 1000000 + tv.tv_usec) / 1000 ;
458
-
459
- return 0 ;
460
- }
461
-
462
-
463
- /*
464
- * pinMode:
465
- * Sets the mode of a pin to be input, output or PWM output
466
- *********************************************************************************
467
- */
468
-
469
- void pinMode (int pin, int mode)
470
- {
471
- static int pwmRunning = FALSE ;
472
-
473
- int gpioPin, fSel, shift ;
474
- int alt ;
475
-
476
- // We can't change the mode in GPIO_SYS mode
477
-
478
- if (gpioPinMode == WPI_MODE_GPIO_SYS)
479
- return ;
480
-
481
- if (gpioPinMode == WPI_MODE_PINS)
482
- {
483
- if ((pin < 0) || (pin >= NUM_PINS))
484
- return ;
485
- gpioPin = pinToGpio [pin] ;
486
- }
487
- else
488
- gpioPin = pin ;
489
-
490
- fSel = gpioToGPFSEL [gpioPin] ;
491
- shift = gpioToShift [gpioPin] ;
492
-
493
- /**/ if (mode == INPUT)
494
- *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) ; // Sets bits to zero = input
495
- else if (mode == OUTPUT)
496
- *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) | (1 << shift) ;
497
- else if (mode == PWM_OUTPUT)
498
- {
499
- if ((alt = gpioToPwmALT [gpioPin]) == 0) // Not a PWM pin
500
- return ;
501
-
502
- // Set pin to PWM mode
503
-
504
- *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) | (alt << shift) ;
505
-
506
- // We didn't initialise the PWM hardware at setup time - because it's possible that
507
- // something else is using the PWM - e.g. the Audio systems! So if we use PWM
508
- // here, then we're assuming that nothing else is, otherwise things are going
509
- // to sound a bit funny...
510
-
511
- if (!pwmRunning)
512
- {
513
-
514
- // Gert/Doms Values
515
- *(clk + PWMCLK_DIV) = 0x5A000000 | (32<<12) ; // set pwm div to 32 (19.2/3 = 600KHz)
516
- *(clk + PWMCLK_CNTL) = 0x5A000011 ; // Source=osc and enable
517
- digitalWrite (pin, LOW) ;
518
- *(pwm + PWM_CONTROL) = 0 ; // Disable PWM
519
- delayMicroseconds (10) ;
520
- *(pwm + PWM0_RANGE) = 0x400 ;
521
- delayMicroseconds (10) ;
522
- *(pwm + PWM1_RANGE) = 0x400 ;
523
- delayMicroseconds (10) ;
524
-
525
- // Enable PWMs
526
-
527
- *(pwm + PWM0_DATA) = 512 ;
528
- *(pwm + PWM1_DATA) = 512 ;
529
-
530
- *(pwm + PWM_CONTROL) = PWM0_ENABLE | PWM1_ENABLE ;
531
- }
532
-
533
- }
534
-
535
- // When we change mode of any pin, we remove the pull up/downs
536
-
537
- pullUpDnControl (pin, PUD_OFF) ;
538
- }
539
-
540
-
541
- /*
542
- * digitalWrite:
543
- * Set an output bit
544
- *********************************************************************************
545
- */
546
-
547
- void digitalWrite (int pin, int value)
548
- {
549
- int gpioPin ;
550
-
551
- if (gpioPinMode == WPI_MODE_PINS)
552
- {
553
- if ((pin < 0) || (pin >= NUM_PINS))
554
- return ;
555
- gpioPin = pinToGpio [pin] ;
556
- }
557
- else
558
- gpioPin = pin ;
559
-
560
- if (gpioPinMode == WPI_MODE_GPIO_SYS)
561
- {
562
- if (sysFds [gpioPin] != -1)
563
- {
564
- if (value == LOW)
565
- write (sysFds [gpioPin], "0\n", 2) ;
566
- else
567
- write (sysFds [gpioPin], "1\n", 2) ;
568
- }
569
- }
570
- else
571
- {
572
- if (value == LOW)
573
- *(gpio + gpioToGPCLR [gpioPin]) = 1 << gpioPin ;
574
- else
575
- *(gpio + gpioToGPSET [gpioPin]) = 1 << gpioPin ;
576
- }
577
- }
578
-
579
-
580
- /*
581
- * pwnWrite:
582
- * Set an output PWM value
583
- *********************************************************************************
584
- */
585
-
586
- void pwmWrite (int pin, int value)
587
- {
588
- int port, gpioPin ;
589
-
590
- // We can't do this in GPIO_SYS mode
591
-
592
- if (gpioPinMode == WPI_MODE_GPIO_SYS)
593
- return ;
594
-
595
- if (gpioPinMode == WPI_MODE_PINS)
596
- {
597
- if ((pin < 0) || (pin >= NUM_PINS))
598
- return ;
599
- gpioPin = pinToGpio [pin] ;
600
- }
601
- else
602
- gpioPin = pin ;
603
-
604
- port = gpioToPwmPort [gpioPin] ;
605
-
606
- *(pwm + port) = value & ~0x400 ;
607
- }
608
-
609
-
610
- /*
611
- * digitalRead:
612
- * Read the value of a given Pin, returning HIGH or LOW
613
- *********************************************************************************
614
- */
615
-
616
- int digitalRead (int pin)
617
- {
618
- int gpioPin ;
619
- char c ;
620
-
621
- if (gpioPinMode == WPI_MODE_PINS)
622
- {
623
- if ((pin < 0) || (pin >= NUM_PINS))
624
- return 0 ;
625
- gpioPin = pinToGpio [pin] ;
626
- }
627
- else
628
- gpioPin = pin ;
629
-
630
- if (gpioPinMode == WPI_MODE_GPIO_SYS)
631
- {
632
- if (sysFds [gpioPin] == -1)
633
- return 0 ;
634
- else
635
- {
636
- lseek (sysFds [gpioPin], 0L, SEEK_SET) ;
637
- read (sysFds [gpioPin], &c, 1) ;
638
- return (c == '0') ? 0 : 1 ;
639
- }
640
- }
641
- else
642
- {
643
- if ((*(gpio + gpioToGPLEV [gpioPin]) & (1 << gpioPin)) != 0)
644
- return HIGH ;
645
- else
646
- return LOW ;
647
- }
648
- }
649
-
650
- /*
651
- * pullUpDownCtrl:
652
- * Control the internal pull-up/down resistors on a GPIO pin
653
- * The Arduino only has pull-ups and these are enabled by writing 1
654
- * to a port when in input mode - this paradigm doesn't quite apply
655
- * here though.
656
- *********************************************************************************
657
- */
658
-
659
- void pullUpDnControl (int pin, int pud)
660
- {
661
- int gpioPin ;
662
-
663
- // We can't do this in GPIO_SYS mode
664
-
665
- if (gpioPinMode == WPI_MODE_GPIO_SYS)
666
- return ;
667
-
668
- if (gpioPinMode == WPI_MODE_PINS)
669
- {
670
- if ((pin < 0) || (pin >= NUM_PINS))
671
- return ;
672
- gpioPin = pinToGpio [pin] ;
673
- }
674
- else
675
- gpioPin = pin ;
676
-
677
- *(gpio + 37) = pud ;
678
- delayMicroseconds (10) ;
679
- *(gpio + gpioToPUDCLK [gpioPin]) = 1 << gpioPin ;
680
- delayMicroseconds (10) ;
681
-
682
- *(gpio + 37) = 0 ;
683
- *(gpio + gpioToPUDCLK [gpioPin]) = 0 ;
684
- }
685
-
686
-
687
- /*
688
- * delay: delayMicroseconds
689
- * Wait for some number of milli/micro seconds
690
- *********************************************************************************
691
- */
692
-
693
- void delay (unsigned int howLong)
694
- {
695
- struct timespec sleeper, dummy ;
696
-
697
- sleeper.tv_sec = (time_t)(howLong / 1000) ;
698
- sleeper.tv_nsec = (long)(howLong % 1000) * 1000000 ;
699
-
700
- nanosleep (&sleeper, &dummy) ;
701
- }
702
-
703
- void delayMicroseconds (unsigned int howLong)
704
- {
705
- struct timespec sleeper, dummy ;
706
-
707
- sleeper.tv_sec = 0 ;
708
- sleeper.tv_nsec = (long)(howLong * 1000) ;
709
-
710
- nanosleep (&sleeper, &dummy) ;
711
- }
712
-
713
- /*
714
- * millis:
715
- * Return a number of milliseconds as an unsigned int.
716
- *********************************************************************************
717
- */
718
-
719
- unsigned int millis (void)
720
- {
721
- struct timeval tv ;
722
- unsigned long long t1 ;
723
-
724
- gettimeofday (&tv, NULL) ;
725
-
726
- t1 = (tv.tv_sec * 1000000 + tv.tv_usec) / 1000 ;
727
-
728
- return (uint32_t)(t1 - epoch) ;
729
- }