rpi_gpio 0.3.0 → 0.5.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,48 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rpi_gpio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
5
- prerelease:
4
+ version: 0.5.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Nick Lowery
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2016-07-07 00:00:00.000000000 Z
11
+ date: 2020-08-09 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: epoll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.3'
14
27
  - !ruby/object:Gem::Dependency
15
28
  name: rake-compiler
16
29
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
30
  requirements:
19
- - - ! '>='
31
+ - - "~>"
20
32
  - !ruby/object:Gem::Version
21
- version: '0'
33
+ version: '1.1'
22
34
  type: :development
23
35
  prerelease: false
24
36
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
37
  requirements:
27
- - - ! '>='
38
+ - - "~>"
28
39
  - !ruby/object:Gem::Version
29
- version: '0'
40
+ version: '1.1'
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: rspec
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
- - - ! '>='
45
+ - - "~>"
36
46
  - !ruby/object:Gem::Version
37
- version: '0'
47
+ version: '3.6'
38
48
  type: :development
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
- - - ! '>='
52
+ - - "~>"
44
53
  - !ruby/object:Gem::Version
45
- version: '0'
54
+ version: '3.6'
46
55
  description: Ruby conversion of RPi.GPIO Python module
47
56
  email: nick.a.lowery@gmail.com
48
57
  executables: []
@@ -50,52 +59,34 @@ extensions:
50
59
  - ext/rpi_gpio/extconf.rb
51
60
  extra_rdoc_files: []
52
61
  files:
53
- - lib/rpi_gpio.so
54
- - ext/rpi_gpio/event_gpio.c
55
- - ext/rpi_gpio/soft_pwm.h
56
- - ext/rpi_gpio/c_gpio.h
57
- - ext/rpi_gpio/soft_pwm.c
58
- - ext/rpi_gpio/rpi_gpio.h
59
- - ext/rpi_gpio/cpuinfo.c
60
- - ext/rpi_gpio/common.h
61
- - ext/rpi_gpio/rb_gpio.c
62
- - ext/rpi_gpio/common.c
63
- - ext/rpi_gpio/extconf.rb
64
- - ext/rpi_gpio/rb_gpio.h
65
- - ext/rpi_gpio/rpi_gpio.c
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
62
  - Gemfile
72
- - Gemfile.lock
73
- - Rakefile
74
63
  - LICENSE
75
64
  - README.md
65
+ - Rakefile
66
+ - ext/rpi_gpio/extconf.rb
67
+ - lib/rpi_gpio.rb
68
+ - lib/rpi_gpio/rpi_gpio.so
76
69
  homepage: https://github.com/ClockVapor/rpi_gpio
77
70
  licenses:
78
71
  - MIT
72
+ metadata: {}
79
73
  post_install_message:
80
74
  rdoc_options: []
81
75
  require_paths:
82
76
  - lib
83
77
  required_ruby_version: !ruby/object:Gem::Requirement
84
- none: false
85
78
  requirements:
86
- - - ! '>='
79
+ - - ">="
87
80
  - !ruby/object:Gem::Version
88
81
  version: '0'
89
82
  required_rubygems_version: !ruby/object:Gem::Requirement
90
- none: false
91
83
  requirements:
92
- - - ! '>='
84
+ - - ">="
93
85
  - !ruby/object:Gem::Version
94
86
  version: '0'
95
87
  requirements: []
96
- rubyforge_project:
97
- rubygems_version: 1.8.23
88
+ rubygems_version: 3.1.2
98
89
  signing_key:
99
- specification_version: 3
90
+ specification_version: 4
100
91
  summary: Ruby conversion of RPi.GPIO Python module
101
92
  test_files: []
@@ -1,36 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- rpi_gpio (0.3.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- diff-lcs (1.2.5)
10
- rake (11.2.2)
11
- rake-compiler (1.0.1)
12
- rake
13
- rspec (3.5.0)
14
- rspec-core (~> 3.5.0)
15
- rspec-expectations (~> 3.5.0)
16
- rspec-mocks (~> 3.5.0)
17
- rspec-core (3.5.1)
18
- rspec-support (~> 3.5.0)
19
- rspec-expectations (3.5.0)
20
- diff-lcs (>= 1.2.0, < 2.0)
21
- rspec-support (~> 3.5.0)
22
- rspec-mocks (3.5.0)
23
- diff-lcs (>= 1.2.0, < 2.0)
24
- rspec-support (~> 3.5.0)
25
- rspec-support (3.5.0)
26
-
27
- PLATFORMS
28
- ruby
29
-
30
- DEPENDENCIES
31
- rake-compiler
32
- rpi_gpio!
33
- rspec
34
-
35
- BUNDLED WITH
36
- 1.10.6
@@ -1,292 +0,0 @@
1
- /*
2
- Original code by Ben Croston modified for Ruby by Nick Lowery
3
- (github.com/clockvapor)
4
- Copyright (c) 2014-2016 Nick Lowery
5
-
6
- Copyright (c) 2013-2015 Ben Croston
7
-
8
- Permission is hereby granted, free of charge, to any person obtaining a copy of
9
- this software and associated documentation files (the "Software"), to deal in
10
- the Software without restriction, including without limitation the rights to
11
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12
- of the Software, and to permit persons to whom the Software is furnished to do
13
- so, subject to the following conditions:
14
-
15
- The above copyright notice and this permission notice shall be included in all
16
- copies or substantial portions of the Software.
17
-
18
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- SOFTWARE.
25
- */
26
-
27
- #include <stdio.h>
28
- #include <stdint.h>
29
- #include <stdlib.h>
30
- #include <fcntl.h>
31
- #include <sys/mman.h>
32
- #include <string.h>
33
- #include "c_gpio.h"
34
-
35
- #define BCM2708_PERI_BASE_DEFAULT 0x20000000
36
- #define BCM2709_PERI_BASE_DEFAULT 0x3f000000
37
- #define GPIO_BASE_OFFSET 0x200000
38
- #define FSEL_OFFSET 0 // 0x0000
39
- #define SET_OFFSET 7 // 0x001c / 4
40
- #define CLR_OFFSET 10 // 0x0028 / 4
41
- #define PINLEVEL_OFFSET 13 // 0x0034 / 4
42
- #define EVENT_DETECT_OFFSET 16 // 0x0040 / 4
43
- #define RISING_ED_OFFSET 19 // 0x004c / 4
44
- #define FALLING_ED_OFFSET 22 // 0x0058 / 4
45
- #define HIGH_DETECT_OFFSET 25 // 0x0064 / 4
46
- #define LOW_DETECT_OFFSET 28 // 0x0070 / 4
47
- #define PULLUPDN_OFFSET 37 // 0x0094 / 4
48
- #define PULLUPDNCLK_OFFSET 38 // 0x0098 / 4
49
-
50
- #define PAGE_SIZE (4*1024)
51
- #define BLOCK_SIZE (4*1024)
52
-
53
- static volatile uint32_t *gpio_map;
54
-
55
- void short_wait(void)
56
- {
57
- int i;
58
-
59
- for (i=0; i<150; i++) { // wait 150 cycles
60
- asm volatile("nop");
61
- }
62
- }
63
-
64
- int setup(void)
65
- {
66
- int mem_fd;
67
- uint8_t *gpio_mem;
68
- uint32_t peri_base;
69
- uint32_t gpio_base;
70
- unsigned char buf[4];
71
- FILE *fp;
72
- char buffer[1024];
73
- char hardware[1024];
74
- int found = 0;
75
-
76
- // try /dev/gpiomem first - this does not require root privs
77
- if ((mem_fd = open("/dev/gpiomem", O_RDWR|O_SYNC)) > 0)
78
- {
79
- gpio_map = (uint32_t *)mmap(NULL, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, mem_fd, 0);
80
- if ((uint32_t)gpio_map < 0) {
81
- return SETUP_MMAP_FAIL;
82
- } else {
83
- return SETUP_OK;
84
- }
85
- }
86
-
87
- // revert to /dev/mem method - requires root
88
-
89
- // determine peri_base
90
- if ((fp = fopen("/proc/device-tree/soc/ranges", "rb")) != NULL) {
91
- // get peri base from device tree
92
- fseek(fp, 4, SEEK_SET);
93
- if (fread(buf, 1, sizeof buf, fp) == sizeof buf) {
94
- peri_base = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3] << 0;
95
- }
96
- fclose(fp);
97
- } else {
98
- // guess peri base based on /proc/cpuinfo hardware field
99
- if ((fp = fopen("/proc/cpuinfo", "r")) == NULL)
100
- return SETUP_CPUINFO_FAIL;
101
-
102
- while(!feof(fp) && !found) {
103
- fgets(buffer, sizeof(buffer), fp);
104
- sscanf(buffer, "Hardware : %s", hardware);
105
- if (strcmp(hardware, "BCM2708") == 0 || strcmp(hardware, "BCM2835") == 0) {
106
- // pi 1 hardware
107
- peri_base = BCM2708_PERI_BASE_DEFAULT;
108
- found = 1;
109
- } else if (strcmp(hardware, "BCM2709") == 0 || strcmp(hardware, "BCM2836") == 0) {
110
- // pi 2 hardware
111
- peri_base = BCM2709_PERI_BASE_DEFAULT;
112
- found = 1;
113
- }
114
- }
115
- fclose(fp);
116
- if (!found)
117
- return SETUP_NOT_RPI_FAIL;
118
- }
119
-
120
- gpio_base = peri_base + GPIO_BASE_OFFSET;
121
-
122
- // mmap the GPIO memory registers
123
- if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {
124
- return SETUP_DEVMEM_FAIL;
125
- }
126
-
127
- if ((gpio_mem = malloc(BLOCK_SIZE + (PAGE_SIZE-1))) == NULL) {
128
- return SETUP_MALLOC_FAIL;
129
- }
130
-
131
- if ((uint32_t)gpio_mem % PAGE_SIZE) {
132
- gpio_mem += PAGE_SIZE - ((uint32_t) gpio_mem % PAGE_SIZE);
133
- }
134
-
135
- gpio_map = (uint32_t *) mmap((void *) gpio_mem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, mem_fd, gpio_base);
136
-
137
- if ((uint32_t) gpio_map < 0) {
138
- return SETUP_MMAP_FAIL;
139
- }
140
-
141
- return SETUP_OK;
142
- }
143
-
144
- void clear_event_detect(int gpio)
145
- {
146
- int offset = EVENT_DETECT_OFFSET + (gpio/32);
147
- int shift = (gpio%32);
148
-
149
- *(gpio_map+offset) |= (1 << shift);
150
- short_wait();
151
- *(gpio_map+offset) = 0;
152
- }
153
-
154
- int eventdetected(int gpio)
155
- {
156
- int offset, value, bit;
157
-
158
- offset = EVENT_DETECT_OFFSET + (gpio/32);
159
- bit = (1 << (gpio%32));
160
- value = *(gpio_map+offset) & bit;
161
- if (value) {
162
- clear_event_detect(gpio);
163
- }
164
- return value;
165
- }
166
-
167
- void set_rising_event(int gpio, int enable)
168
- {
169
- int offset = RISING_ED_OFFSET + (gpio/32);
170
- int shift = (gpio%32);
171
-
172
- if (enable) {
173
- *(gpio_map+offset) |= 1 << shift;
174
- } else {
175
- *(gpio_map+offset) &= ~(1 << shift);
176
- }
177
- clear_event_detect(gpio);
178
- }
179
-
180
- void set_falling_event(int gpio, int enable)
181
- {
182
- int offset = FALLING_ED_OFFSET + (gpio/32);
183
- int shift = (gpio%32);
184
-
185
- if (enable) {
186
- *(gpio_map+offset) |= (1 << shift);
187
- *(gpio_map+offset) = (1 << shift);
188
- } else {
189
- *(gpio_map+offset) &= ~(1 << shift);
190
- }
191
- clear_event_detect(gpio);
192
- }
193
-
194
- void set_high_event(int gpio, int enable)
195
- {
196
- int offset = HIGH_DETECT_OFFSET + (gpio/32);
197
- int shift = (gpio%32);
198
-
199
- if (enable) {
200
- *(gpio_map+offset) |= (1 << shift);
201
- } else {
202
- *(gpio_map+offset) &= ~(1 << shift);
203
- }
204
- clear_event_detect(gpio);
205
- }
206
-
207
- void set_low_event(int gpio, int enable)
208
- {
209
- int offset = LOW_DETECT_OFFSET + (gpio/32);
210
- int shift = (gpio%32);
211
-
212
- if (enable) {
213
- *(gpio_map+offset) |= 1 << shift;
214
- } else {
215
- *(gpio_map+offset) &= ~(1 << shift);
216
- }
217
- clear_event_detect(gpio);
218
- }
219
-
220
- void set_pullupdn(int gpio, int pud)
221
- {
222
- int clk_offset = PULLUPDNCLK_OFFSET + (gpio/32);
223
- int shift = (gpio%32);
224
-
225
- if (pud == PUD_DOWN) {
226
- *(gpio_map+PULLUPDN_OFFSET) = (*(gpio_map+PULLUPDN_OFFSET) & ~3) |
227
- PUD_DOWN;
228
- } else if (pud == PUD_UP) {
229
- *(gpio_map+PULLUPDN_OFFSET) = (*(gpio_map+PULLUPDN_OFFSET) & ~3) | PUD_UP;
230
- } else { // pud == PUD_OFF
231
- *(gpio_map+PULLUPDN_OFFSET) &= ~3;
232
- }
233
-
234
- short_wait();
235
- *(gpio_map+clk_offset) = 1 << shift;
236
- short_wait();
237
- *(gpio_map+PULLUPDN_OFFSET) &= ~3;
238
- *(gpio_map+clk_offset) = 0;
239
- }
240
-
241
- void setup_gpio(int gpio, int direction, int pud)
242
- {
243
- int offset = FSEL_OFFSET + (gpio/10);
244
- int shift = (gpio%10)*3;
245
-
246
- set_pullupdn(gpio, pud);
247
- if (direction == OUTPUT)
248
- *(gpio_map+offset) = (*(gpio_map+offset) & ~(7<<shift)) | (1<<shift);
249
- else // direction == INPUT
250
- *(gpio_map+offset) = (*(gpio_map+offset) & ~(7<<shift));
251
- }
252
-
253
- // Contribution by Eric Ptak <trouch@trouch.com>
254
- int gpio_function(int gpio)
255
- {
256
- int offset = FSEL_OFFSET + (gpio/10);
257
- int shift = (gpio%10)*3;
258
- int value = *(gpio_map+offset);
259
- value >>= shift;
260
- value &= 7;
261
- return value; // 0=input, 1=output, 4=alt0
262
- }
263
-
264
- void output_gpio(int gpio, int value)
265
- {
266
- int offset, shift;
267
-
268
- if (value) { // value == HIGH
269
- offset = SET_OFFSET + (gpio/32);
270
- } else { // value == LOW
271
- offset = CLR_OFFSET + (gpio/32);
272
- }
273
-
274
- shift = (gpio%32);
275
-
276
- *(gpio_map+offset) = 1 << shift;
277
- }
278
-
279
- int input_gpio(int gpio)
280
- {
281
- int offset, value, mask;
282
-
283
- offset = PINLEVEL_OFFSET + (gpio/32);
284
- mask = (1 << gpio%32);
285
- value = *(gpio_map+offset) & mask;
286
- return value;
287
- }
288
-
289
- void cleanup(void)
290
- {
291
- munmap((void *) gpio_map, BLOCK_SIZE);
292
- }