chip-gpio 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chip-gpio/SoftSpi.rb +8 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d947a58cc0720824366acfc1489e499e0df866f3
|
4
|
+
data.tar.gz: aa47ac588ab2ac5f9621e9919df0c4bca17033c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7298e2dcedd3e0bd35ac87eed2fe62f0dec97439682232b5bc4d5b11c98bf57f387e0bc3e17751c30285e26ea9c2ecdff353b8cdd72b1d67520e90a3b4adfa31
|
7
|
+
data.tar.gz: 512e252e8dc169bffa8522d1aaf17f4986e32a364534c7324367399e67f9f9319e5831d8f95c0edfec0caa38232c2c9a544328c011954eb5fa876390fb75c948
|
data/lib/chip-gpio/SoftSpi.rb
CHANGED
@@ -27,8 +27,9 @@ module ChipGPIO
|
|
27
27
|
attr_reader :polarity
|
28
28
|
attr_reader :phase
|
29
29
|
attr_reader :word_size
|
30
|
+
attr_reader :lsb_first
|
30
31
|
|
31
|
-
def initialize(clock_pin: nil, input_pin: nil, output_pin: nil, polarity: 1, phase: 0, word_size: 8)
|
32
|
+
def initialize(clock_pin: nil, input_pin: nil, output_pin: nil, polarity: 1, phase: 0, word_size: 8, lsb_first: false)
|
32
33
|
raise ArgumentError, "clock_pin is required" if clock_pin == nil
|
33
34
|
raise ArgumentError, "At least input_pin or output_pin must be specified" if ((input_pin == nil) && (output_pin == nil))
|
34
35
|
|
@@ -60,21 +61,21 @@ module ChipGPIO
|
|
60
61
|
@polarity = polarity
|
61
62
|
@phase = phase
|
62
63
|
@word_size = word_size
|
64
|
+
@lsb_first = lsb_first
|
63
65
|
end
|
64
66
|
|
65
67
|
def max_word
|
66
68
|
((2**@word_size) - 1)
|
67
69
|
end
|
68
70
|
|
69
|
-
def write(words: []
|
71
|
+
def write(words: [])
|
70
72
|
raise "An output_pin must be specified to write" if !@output_pin
|
71
73
|
|
74
|
+
#you can't make reverse ranges so this logic is gross
|
75
|
+
#the key point is that 0 is the MSB so we only want it first if
|
76
|
+
#@lsb_first is set
|
72
77
|
bits = Array (0..(@word_size - 1))
|
73
|
-
|
74
|
-
if reverse_output
|
75
|
-
words = words.reverse()
|
76
|
-
bits = bits.reverse()
|
77
|
-
end
|
78
|
+
bits = bits.reverse() if !@lsb_first
|
78
79
|
|
79
80
|
words.each do |w|
|
80
81
|
w = 0 if w < 0
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chip-gpio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A ruby gem to control the IO hardware the CHIP computer
|
14
14
|
email: james@jameswilliams.me
|