sunxi_gpio 0.0.4 → 0.1.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.
- checksums.yaml +4 -4
- data/README.md +29 -9
- data/ext/sunxi_gpio/gpio_lib.c +1 -1
- data/ext/sunxi_gpio/gpio_lib.h +3 -0
- data/lib/sunxi_gpio/pin.rb +2 -3
- data/lib/sunxi_gpio/pin_values.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8bea316b90fd80539ea4cf858e05e127c42627a
|
4
|
+
data.tar.gz: 17a8bc451e22a595f6542816689e3564ef6ea8c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5524fe503a759f13dce9f30c3727ea5773e59810e1fb637d20e687a1af2d5ac9a546d8f27e91389787b50288c3e863c798a3ff30539a751c83276402440bee96
|
7
|
+
data.tar.gz: 1900d7d6970e4f86c12cea69abd332f357684c8515e30b58d8fca3e5626cbf7b74d1f3bbceee8eb883b785d7acbd6f45d5cdf9088a26955421c9bce42715af89
|
data/README.md
CHANGED
@@ -19,12 +19,14 @@ gem install sunxi_gpio
|
|
19
19
|
```ruby
|
20
20
|
require 'sunxi_gpio/pin'
|
21
21
|
|
22
|
-
|
22
|
+
SunxiGPIO::Pin.open
|
23
|
+
|
23
24
|
pin = SunxiGPIO::Pin.new(pin: :PB2, direction: :out)
|
24
25
|
pin.on
|
25
26
|
sleep 1
|
26
27
|
pin.off
|
27
|
-
|
28
|
+
|
29
|
+
SunxiGPIO::Pin.close
|
28
30
|
```
|
29
31
|
|
30
32
|
### Simple reading
|
@@ -32,7 +34,8 @@ Sunxi::GPIO.close
|
|
32
34
|
```ruby
|
33
35
|
require 'sunxi_gpio/pin'
|
34
36
|
|
35
|
-
|
37
|
+
SunxiGPIO::Pin.open
|
38
|
+
|
36
39
|
pin = SunxiGPIO::Pin.new(pin: :PB2, direction: :in)
|
37
40
|
|
38
41
|
10.times do
|
@@ -40,22 +43,39 @@ pin = SunxiGPIO::Pin.new(pin: :PB2, direction: :in)
|
|
40
43
|
puts "result: #{value}"
|
41
44
|
sleep 1
|
42
45
|
end
|
43
|
-
```
|
44
46
|
|
47
|
+
SunxiGPIO::Pin.close
|
48
|
+
```
|
45
49
|
|
46
|
-
###
|
50
|
+
### Watch
|
51
|
+
Watches the pin going to status in parameter and executes the block.
|
52
|
+
Block will only be triggered with a status change is seen.
|
47
53
|
|
48
54
|
```ruby
|
49
55
|
require 'sunxi_gpio/pin'
|
50
56
|
|
51
|
-
|
57
|
+
SunxiGPIO::Pin.open
|
58
|
+
|
52
59
|
pin = SunxiGPIO::Pin.new(pin: :PB2, direction: :out)
|
53
60
|
|
54
|
-
pin.watch do
|
55
|
-
puts "
|
61
|
+
pin.watch(SunxiGPIO::PinValues::GPIO_LOW) do
|
62
|
+
puts "I am in the loop with value #{pin.read}"
|
56
63
|
end
|
57
64
|
|
58
|
-
|
65
|
+
SunxiGPIO::Pin.close
|
66
|
+
|
67
|
+
```
|
68
|
+
### Enable pull for a pin
|
69
|
+
When using pins as input, you can use internal resistors to pull the pin up or pull down. This is important if you use open-collector sensors
|
70
|
+
which have floating output in some states. Pull can be used as :up or :down -depending of the type of layout.
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
SunxiGPIO::Pin.open
|
74
|
+
|
75
|
+
pin = SunxiGPIO::Pin.new(pin: :PI15, direction: :in, pull: :up)
|
76
|
+
value=pin.read
|
77
|
+
|
78
|
+
SunxiGPIO::Pin.close
|
59
79
|
```
|
60
80
|
|
61
81
|
|
data/ext/sunxi_gpio/gpio_lib.c
CHANGED
@@ -148,7 +148,7 @@ int sunxi_gpio_input(unsigned int pin) {
|
|
148
148
|
return (dat & 0x1);
|
149
149
|
}
|
150
150
|
|
151
|
-
//
|
151
|
+
// https://github.com/akarnaukh/gpio_lib_A20
|
152
152
|
int sunxi_gpio_set_pull(unsigned int pin, unsigned int val) {
|
153
153
|
unsigned int pull;
|
154
154
|
unsigned int bank = GPIO_BANK(pin);
|
data/ext/sunxi_gpio/gpio_lib.h
CHANGED
@@ -58,6 +58,9 @@ struct sunxi_gpio_reg {
|
|
58
58
|
#define GPIO_PULL_INDEX(pin) (((pin) & 0x1F) >> 4)
|
59
59
|
#define GPIO_PULL_OFFSET(pin) ((((pin) & 0x1F) & 0xf) << 1)
|
60
60
|
|
61
|
+
#define SUNXI_GPIO_PULL_DISABLE 0
|
62
|
+
#define SUNXI_GPIO_PULL_UP 1
|
63
|
+
#define SUNXI_GPIO_PULL_DOVN 2
|
61
64
|
|
62
65
|
/* GPIO bank sizes */
|
63
66
|
#define SUNXI_GPIO_A_NR (32)
|
data/lib/sunxi_gpio/pin.rb
CHANGED
@@ -66,7 +66,7 @@ module SunxiGPIO
|
|
66
66
|
@value = invert ? (val ^ 1) : val
|
67
67
|
end
|
68
68
|
|
69
|
-
|
69
|
+
#
|
70
70
|
def pull!(state)
|
71
71
|
return nil if @direction != :in
|
72
72
|
|
@@ -82,8 +82,7 @@ module SunxiGPIO
|
|
82
82
|
nil
|
83
83
|
end
|
84
84
|
|
85
|
-
|
86
|
-
# ::Gpio_lib.sunxi_gpio_set_pull(@pin, @pull) if @pull
|
85
|
+
::Gpio_lib.sunxi_gpio_set_pull(@pin, @pull) if @pull
|
87
86
|
@pull
|
88
87
|
end
|
89
88
|
|