rpi_gpio 0.2.0 → 0.3.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.
Binary file
metadata CHANGED
@@ -1,41 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rpi_gpio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Nick Lowery
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-08-18 00:00:00.000000000 Z
12
+ date: 2016-07-07 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rake-compiler
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - ">="
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0'
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - ">="
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0'
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rspec
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - ">="
35
+ - - ! '>='
32
36
  - !ruby/object:Gem::Version
33
37
  version: '0'
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - ">="
43
+ - - ! '>='
39
44
  - !ruby/object:Gem::Version
40
45
  version: '0'
41
46
  description: Ruby conversion of RPi.GPIO Python module
@@ -45,66 +50,52 @@ extensions:
45
50
  - ext/rpi_gpio/extconf.rb
46
51
  extra_rdoc_files: []
47
52
  files:
48
- - Gemfile
49
- - Gemfile.lock
50
- - LICENSE
51
- - README.md
52
- - Rakefile
53
- - ext/new/c_gpio.c
54
- - ext/new/c_gpio.h
55
- - ext/new/common.c
56
- - ext/new/common.h
57
- - ext/new/constants.c
58
- - ext/new/constants.h
59
- - ext/new/cpuinfo.c
60
- - ext/new/cpuinfo.h
61
- - ext/new/event_gpio.c
62
- - ext/new/event_gpio.h
63
- - ext/new/py_gpio.c
64
- - ext/new/py_pwm.c
65
- - ext/new/py_pwm.h
66
- - ext/new/soft_pwm.c
67
- - ext/new/soft_pwm.h
68
- - ext/rpi_gpio/c_gpio.c
53
+ - lib/rpi_gpio.so
54
+ - ext/rpi_gpio/event_gpio.c
55
+ - ext/rpi_gpio/soft_pwm.h
69
56
  - ext/rpi_gpio/c_gpio.h
70
- - ext/rpi_gpio/common.c
71
- - ext/rpi_gpio/common.h
57
+ - ext/rpi_gpio/soft_pwm.c
58
+ - ext/rpi_gpio/rpi_gpio.h
72
59
  - ext/rpi_gpio/cpuinfo.c
73
- - ext/rpi_gpio/cpuinfo.h
74
- - ext/rpi_gpio/event_gpio.c
75
- - ext/rpi_gpio/event_gpio.h
76
- - ext/rpi_gpio/extconf.rb
60
+ - ext/rpi_gpio/common.h
77
61
  - ext/rpi_gpio/rb_gpio.c
62
+ - ext/rpi_gpio/common.c
63
+ - ext/rpi_gpio/extconf.rb
78
64
  - ext/rpi_gpio/rb_gpio.h
79
- - ext/rpi_gpio/rb_pwm.c
80
- - ext/rpi_gpio/rb_pwm.h
81
65
  - ext/rpi_gpio/rpi_gpio.c
82
- - ext/rpi_gpio/rpi_gpio.h
83
- - ext/rpi_gpio/soft_pwm.c
84
- - ext/rpi_gpio/soft_pwm.h
85
- - lib/rpi_gpio.so
66
+ - ext/rpi_gpio/event_gpio.h
67
+ - ext/rpi_gpio/c_gpio.c
68
+ - ext/rpi_gpio/rb_pwm.h
69
+ - ext/rpi_gpio/cpuinfo.h
70
+ - ext/rpi_gpio/rb_pwm.c
71
+ - Gemfile
72
+ - Gemfile.lock
73
+ - Rakefile
74
+ - LICENSE
75
+ - README.md
86
76
  homepage: https://github.com/ClockVapor/rpi_gpio
87
77
  licenses:
88
78
  - MIT
89
- metadata: {}
90
79
  post_install_message:
91
80
  rdoc_options: []
92
81
  require_paths:
93
82
  - lib
94
83
  required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
95
85
  requirements:
96
- - - ">="
86
+ - - ! '>='
97
87
  - !ruby/object:Gem::Version
98
88
  version: '0'
99
89
  required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
100
91
  requirements:
101
- - - ">="
92
+ - - ! '>='
102
93
  - !ruby/object:Gem::Version
103
94
  version: '0'
104
95
  requirements: []
105
96
  rubyforge_project:
106
- rubygems_version: 2.4.8
97
+ rubygems_version: 1.8.23
107
98
  signing_key:
108
- specification_version: 4
99
+ specification_version: 3
109
100
  summary: Ruby conversion of RPi.GPIO Python module
110
101
  test_files: []
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: a0e5676feb3143ba7430bcfced058ac5e986c2ee
4
- data.tar.gz: b916d55ecf73e17325cc630324c035dd7b6fa85b
5
- SHA512:
6
- metadata.gz: 15364745c0cf985293b27ab07f6bbbad9566a7c5c20de7c4bdf496c61419a860171bbacfe3153666d3f91e9587a5031562376ecba7606bd245d01b1f61e4a5c4
7
- data.tar.gz: e904851064c95e2268815255b30b821be6e9a7b8565b7b704001bc6a41f7280df9aae0e91d97b1917e71335896dc756e8bce423cb671166ca19b25823859e139
@@ -1,237 +0,0 @@
1
- /*
2
- Copyright (c) 2012-2015 Ben Croston
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of
5
- this software and associated documentation files (the "Software"), to deal in
6
- the Software without restriction, including without limitation the rights to
7
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
- of the Software, and to permit persons to whom the Software is furnished to do
9
- so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in all
12
- copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- SOFTWARE.
21
- */
22
-
23
- #include <stdio.h>
24
- #include <stdint.h>
25
- #include <stdlib.h>
26
- #include <fcntl.h>
27
- #include <sys/mman.h>
28
- #include "c_gpio.h"
29
-
30
- #define BCM2708_PERI_BASE_DEFAULT 0x20000000
31
- #define GPIO_BASE_OFFSET 0x200000
32
- #define FSEL_OFFSET 0 // 0x0000
33
- #define SET_OFFSET 7 // 0x001c / 4
34
- #define CLR_OFFSET 10 // 0x0028 / 4
35
- #define PINLEVEL_OFFSET 13 // 0x0034 / 4
36
- #define EVENT_DETECT_OFFSET 16 // 0x0040 / 4
37
- #define RISING_ED_OFFSET 19 // 0x004c / 4
38
- #define FALLING_ED_OFFSET 22 // 0x0058 / 4
39
- #define HIGH_DETECT_OFFSET 25 // 0x0064 / 4
40
- #define LOW_DETECT_OFFSET 28 // 0x0070 / 4
41
- #define PULLUPDN_OFFSET 37 // 0x0094 / 4
42
- #define PULLUPDNCLK_OFFSET 38 // 0x0098 / 4
43
-
44
- #define PAGE_SIZE (4*1024)
45
- #define BLOCK_SIZE (4*1024)
46
-
47
- static volatile uint32_t *gpio_map;
48
-
49
- void short_wait(void)
50
- {
51
- int i;
52
-
53
- for (i=0; i<150; i++) { // wait 150 cycles
54
- asm volatile("nop");
55
- }
56
- }
57
-
58
- int setup(void)
59
- {
60
- int mem_fd;
61
- uint8_t *gpio_mem;
62
- uint32_t peri_base = BCM2708_PERI_BASE_DEFAULT;
63
- uint32_t gpio_base;
64
- unsigned char buf[4];
65
- FILE *fp;
66
-
67
- // get peri base from device tree
68
- if ((fp = fopen("/proc/device-tree/soc/ranges", "rb")) != NULL) {
69
- fseek(fp, 4, SEEK_SET);
70
- if (fread(buf, 1, sizeof buf, fp) == sizeof buf) {
71
- peri_base = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3] << 0;
72
- }
73
- fclose(fp);
74
- }
75
-
76
- gpio_base = peri_base + GPIO_BASE_OFFSET;
77
-
78
- // mmap the GPIO memory registers
79
- if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0)
80
- return SETUP_DEVMEM_FAIL;
81
-
82
- if ((gpio_mem = malloc(BLOCK_SIZE + (PAGE_SIZE-1))) == NULL)
83
- return SETUP_MALLOC_FAIL;
84
-
85
- if ((uint32_t)gpio_mem % PAGE_SIZE)
86
- gpio_mem += PAGE_SIZE - ((uint32_t)gpio_mem % PAGE_SIZE);
87
-
88
- gpio_map = (uint32_t *)mmap( (caddr_t)gpio_mem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, mem_fd, gpio_base);
89
-
90
- if ((uint32_t)gpio_map < 0)
91
- return SETUP_MMAP_FAIL;
92
-
93
- return SETUP_OK;
94
- }
95
-
96
- void clear_event_detect(int gpio)
97
- {
98
- int offset = EVENT_DETECT_OFFSET + (gpio/32);
99
- int shift = (gpio%32);
100
-
101
- *(gpio_map+offset) |= (1 << shift);
102
- short_wait();
103
- *(gpio_map+offset) = 0;
104
- }
105
-
106
- int eventdetected(int gpio)
107
- {
108
- int offset, value, bit;
109
-
110
- offset = EVENT_DETECT_OFFSET + (gpio/32);
111
- bit = (1 << (gpio%32));
112
- value = *(gpio_map+offset) & bit;
113
- if (value)
114
- clear_event_detect(gpio);
115
- return value;
116
- }
117
-
118
- void set_rising_event(int gpio, int enable)
119
- {
120
- int offset = RISING_ED_OFFSET + (gpio/32);
121
- int shift = (gpio%32);
122
-
123
- if (enable)
124
- *(gpio_map+offset) |= 1 << shift;
125
- else
126
- *(gpio_map+offset) &= ~(1 << shift);
127
- clear_event_detect(gpio);
128
- }
129
-
130
- void set_falling_event(int gpio, int enable)
131
- {
132
- int offset = FALLING_ED_OFFSET + (gpio/32);
133
- int shift = (gpio%32);
134
-
135
- if (enable) {
136
- *(gpio_map+offset) |= (1 << shift);
137
- *(gpio_map+offset) = (1 << shift);
138
- } else {
139
- *(gpio_map+offset) &= ~(1 << shift);
140
- }
141
- clear_event_detect(gpio);
142
- }
143
-
144
- void set_high_event(int gpio, int enable)
145
- {
146
- int offset = HIGH_DETECT_OFFSET + (gpio/32);
147
- int shift = (gpio%32);
148
-
149
- if (enable)
150
- *(gpio_map+offset) |= (1 << shift);
151
- else
152
- *(gpio_map+offset) &= ~(1 << shift);
153
- clear_event_detect(gpio);
154
- }
155
-
156
- void set_low_event(int gpio, int enable)
157
- {
158
- int offset = LOW_DETECT_OFFSET + (gpio/32);
159
- int shift = (gpio%32);
160
-
161
- if (enable)
162
- *(gpio_map+offset) |= 1 << shift;
163
- else
164
- *(gpio_map+offset) &= ~(1 << shift);
165
- clear_event_detect(gpio);
166
- }
167
-
168
- void set_pullupdn(int gpio, int pud)
169
- {
170
- int clk_offset = PULLUPDNCLK_OFFSET + (gpio/32);
171
- int shift = (gpio%32);
172
-
173
- if (pud == PUD_DOWN)
174
- *(gpio_map+PULLUPDN_OFFSET) = (*(gpio_map+PULLUPDN_OFFSET) & ~3) | PUD_DOWN;
175
- else if (pud == PUD_UP)
176
- *(gpio_map+PULLUPDN_OFFSET) = (*(gpio_map+PULLUPDN_OFFSET) & ~3) | PUD_UP;
177
- else // pud == PUD_OFF
178
- *(gpio_map+PULLUPDN_OFFSET) &= ~3;
179
-
180
- short_wait();
181
- *(gpio_map+clk_offset) = 1 << shift;
182
- short_wait();
183
- *(gpio_map+PULLUPDN_OFFSET) &= ~3;
184
- *(gpio_map+clk_offset) = 0;
185
- }
186
-
187
- void setup_gpio(int gpio, int direction, int pud)
188
- {
189
- int offset = FSEL_OFFSET + (gpio/10);
190
- int shift = (gpio%10)*3;
191
-
192
- set_pullupdn(gpio, pud);
193
- if (direction == OUTPUT)
194
- *(gpio_map+offset) = (*(gpio_map+offset) & ~(7<<shift)) | (1<<shift);
195
- else // direction == INPUT
196
- *(gpio_map+offset) = (*(gpio_map+offset) & ~(7<<shift));
197
- }
198
-
199
- // Contribution by Eric Ptak <trouch@trouch.com>
200
- int gpio_function(int gpio)
201
- {
202
- int offset = FSEL_OFFSET + (gpio/10);
203
- int shift = (gpio%10)*3;
204
- int value = *(gpio_map+offset);
205
- value >>= shift;
206
- value &= 7;
207
- return value; // 0=input, 1=output, 4=alt0
208
- }
209
-
210
- void output_gpio(int gpio, int value)
211
- {
212
- int offset, shift;
213
-
214
- if (value) // value == HIGH
215
- offset = SET_OFFSET + (gpio/32);
216
- else // value == LOW
217
- offset = CLR_OFFSET + (gpio/32);
218
-
219
- shift = (gpio%32);
220
-
221
- *(gpio_map+offset) = 1 << shift;
222
- }
223
-
224
- int input_gpio(int gpio)
225
- {
226
- int offset, value, mask;
227
-
228
- offset = PINLEVEL_OFFSET + (gpio/32);
229
- mask = (1 << gpio%32);
230
- value = *(gpio_map+offset) & mask;
231
- return value;
232
- }
233
-
234
- void cleanup(void)
235
- {
236
- munmap((caddr_t)gpio_map, BLOCK_SIZE);
237
- }
@@ -1,49 +0,0 @@
1
- /*
2
- Copyright (c) 2012-2013 Ben Croston
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of
5
- this software and associated documentation files (the "Software"), to deal in
6
- the Software without restriction, including without limitation the rights to
7
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
- of the Software, and to permit persons to whom the Software is furnished to do
9
- so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in all
12
- copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- SOFTWARE.
21
- */
22
-
23
- int setup(void);
24
- void setup_gpio(int gpio, int direction, int pud);
25
- int gpio_function(int gpio);
26
- void output_gpio(int gpio, int value);
27
- int input_gpio(int gpio);
28
- void set_rising_event(int gpio, int enable);
29
- void set_falling_event(int gpio, int enable);
30
- void set_high_event(int gpio, int enable);
31
- void set_low_event(int gpio, int enable);
32
- int eventdetected(int gpio);
33
- void cleanup(void);
34
-
35
- #define SETUP_OK 0
36
- #define SETUP_DEVMEM_FAIL 1
37
- #define SETUP_MALLOC_FAIL 2
38
- #define SETUP_MMAP_FAIL 3
39
-
40
- #define INPUT 1 // is really 0 for control register!
41
- #define OUTPUT 0 // is really 1 for control register!
42
- #define ALT0 4
43
-
44
- #define HIGH 1
45
- #define LOW 0
46
-
47
- #define PUD_OFF 0
48
- #define PUD_DOWN 1
49
- #define PUD_UP 2
@@ -1,87 +0,0 @@
1
- /*
2
- Copyright (c) 2013-2014 Ben Croston
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of
5
- this software and associated documentation files (the "Software"), to deal in
6
- the Software without restriction, including without limitation the rights to
7
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
- of the Software, and to permit persons to whom the Software is furnished to do
9
- so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in all
12
- copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- SOFTWARE.
21
- */
22
-
23
- #include "Python.h"
24
- #include "c_gpio.h"
25
- #include "common.h"
26
-
27
- int gpio_mode = MODE_UNKNOWN;
28
- const int pin_to_gpio_rev1[41] = {-1, -1, -1, 0, -1, 1, -1, 4, 14, -1, 15, 17, 18, 21, -1, 22, 23, -1, 24, 10, -1, 9, 25, 11, 8, -1, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
29
- const int pin_to_gpio_rev2[41] = {-1, -1, -1, 2, -1, 3, -1, 4, 14, -1, 15, 17, 18, 27, -1, 22, 23, -1, 24, 10, -1, 9, 25, 11, 8, -1, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
30
- const int pin_to_gpio_rev3[41] = {-1, -1, -1, 2, -1, 3, -1, 4, 14, -1, 15, 17, 18, 27, -1, 22, 23, -1, 24, 10, -1, 9, 25, 11, 8, -1, 7, -1, -1, 5, -1, 6, 12, 13, -1, 19, 16, 26, 20, -1, 21 };
31
- int setup_error = 0;
32
- int module_setup = 0;
33
-
34
- int check_gpio_priv(void)
35
- {
36
- // check module has been imported cleanly
37
- if (setup_error)
38
- {
39
- PyErr_SetString(PyExc_RuntimeError, "Module not imported correctly!");
40
- return 1;
41
- }
42
-
43
- // check mmap setup has worked
44
- if (!module_setup)
45
- {
46
- PyErr_SetString(PyExc_RuntimeError, "No access to /dev/mem. Try running as root!");
47
- return 2;
48
- }
49
- return 0;
50
- }
51
-
52
- int get_gpio_number(int channel, unsigned int *gpio)
53
- {
54
- // check setmode() has been run
55
- if (gpio_mode != BOARD && gpio_mode != BCM)
56
- {
57
- PyErr_SetString(PyExc_RuntimeError, "Please set pin numbering mode using GPIO.setmode(GPIO.BOARD) or GPIO.setmode(GPIO.BCM)");
58
- return 3;
59
- }
60
-
61
- // check channel number is in range
62
- if ( (gpio_mode == BCM && (channel < 0 || channel > 53))
63
- || (gpio_mode == BOARD && (channel < 1 || channel > 26) && rpiinfo.p1_revision != 3)
64
- || (gpio_mode == BOARD && (channel < 1 || channel > 40) && rpiinfo.p1_revision == 3) )
65
- {
66
- PyErr_SetString(PyExc_ValueError, "The channel sent is invalid on a Raspberry Pi");
67
- return 4;
68
- }
69
-
70
- // convert channel to gpio
71
- if (gpio_mode == BOARD)
72
- {
73
- if (*(*pin_to_gpio+channel) == -1)
74
- {
75
- PyErr_SetString(PyExc_ValueError, "The channel sent is invalid on a Raspberry Pi");
76
- return 5;
77
- } else {
78
- *gpio = *(*pin_to_gpio+channel);
79
- }
80
- }
81
- else // gpio_mode == BCM
82
- {
83
- *gpio = channel;
84
- }
85
-
86
- return 0;
87
- }