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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41a03541797f88a175d5cfb495246278d7c012ee
4
- data.tar.gz: 9ed2b04036c93156d325b05936fc923c67453245
3
+ metadata.gz: b8bea316b90fd80539ea4cf858e05e127c42627a
4
+ data.tar.gz: 17a8bc451e22a595f6542816689e3564ef6ea8c3
5
5
  SHA512:
6
- metadata.gz: 6764feff02419af5495fecfca88a5667fbdcb714d58143b908e9ac49e484fefe152f4cbf04b579092dd0aa8858e115a98b1e44eca14457c6ac9d5d4ba6327ad2
7
- data.tar.gz: a4d1e92da324fd02a96df7a6c701795eae84a03e75fd20961684f4a354cdc02438a746dc4025e181731356e8c81f5bfb0927e686cf294ae9350e2832bc116b04
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
- Sunxi::GPIO.open
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
- Sunxi::GPIO.close
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
- Sunxi::GPIO.open
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
- ### Watching
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
- Sunxi::GPIO.open
57
+ SunxiGPIO::Pin.open
58
+
52
59
  pin = SunxiGPIO::Pin.new(pin: :PB2, direction: :out)
53
60
 
54
- pin.watch do
55
- puts "Pin changed from #{last_value} to #{value}"
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
- Sunxi::GPIO.close
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
 
@@ -148,7 +148,7 @@ int sunxi_gpio_input(unsigned int pin) {
148
148
  return (dat & 0x1);
149
149
  }
150
150
 
151
- // http://www.cubieforums.com/index.php?topic=2881.15
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);
@@ -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)
@@ -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
- #### Not working yet
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
 
@@ -8,8 +8,8 @@ module SunxiGPIO
8
8
  ]
9
9
 
10
10
  GPIO_PUD_OFF = 0
11
- GPIO_PUD_DOWN = 1
12
- GPIO_PUD_UP = 2
11
+ GPIO_PUD_DOWN = 2
12
+ GPIO_PUD_UP = 1
13
13
 
14
14
  GPIO_HIGH = 1
15
15
  GPIO_LOW = 0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunxi_gpio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - phortx