chip-gpio 0.0.3 → 0.0.5
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 +5 -2
- data/lib/chip-gpio/Pin.rb +0 -0
- data/lib/chip-gpio/SoftSpi.rb +99 -0
- data/lib/chip-gpio.rb +0 -0
- metadata +6 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2f70b8ed01708787a7cf556b02960218fb06e669
|
|
4
|
+
data.tar.gz: a3b78c5c8e4969b5e9da2249c94fd8d8d18a19c3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b287f8c9de23ba1fc5ea28f3368832608fce72978e8240310036cadc655e8a88d8a83fe99b7a00efd3739413b18ed50d5193d60f25e0a7398e3020cf9dcd6e7a
|
|
7
|
+
data.tar.gz: 60dd01362b593661f35ab6bd6e9d021e5a87e8dfe44f0398fafeb47ff3ca71e297d285b9f48221e240ef85a5491183e4c4a62922152a3711c9dc675fdf061d3b
|
data/README.md
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
# chip-gpio
|
|
2
2
|
|
|
3
|
-
A ruby gem for controlling the
|
|
3
|
+
A ruby gem for controlling the IO hardware on a $9 CHIP computer.
|
|
4
4
|
|
|
5
|
-
Can currently set output values and read input values
|
|
5
|
+
Can currently set output values and read input values from GPIO pins on CHIP computers running v4.3 or v4.4 images.
|
|
6
|
+
|
|
7
|
+
Supports a software SPI mode using the GPIO pins. This support is incomplete. See the TODO
|
|
8
|
+
in `SoftSpi.rb`.
|
|
6
9
|
|
|
7
10
|
## Installation
|
|
8
11
|
|
data/lib/chip-gpio/Pin.rb
CHANGED
|
File without changes
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Ported from https://github.com/adafruit/circuitpython/blob/master/shared-module/bitbangio/SPI.c
|
|
2
|
+
#
|
|
3
|
+
# The MIT License (MIT)
|
|
4
|
+
#
|
|
5
|
+
# Copyright (c) 2013, 2014 Damien P. George
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
# furnished to do so, subject to the following conditions:
|
|
13
|
+
#
|
|
14
|
+
# The above copyright notice and this permission notice shall be included in
|
|
15
|
+
|
|
16
|
+
# *** TODO
|
|
17
|
+
# *** Reads
|
|
18
|
+
# *** Baudrate
|
|
19
|
+
# *** Phase
|
|
20
|
+
|
|
21
|
+
module ChipGPIO
|
|
22
|
+
class SoftSPI
|
|
23
|
+
attr_reader :clock_pin
|
|
24
|
+
attr_reader :input_pin
|
|
25
|
+
attr_reader :output_pin
|
|
26
|
+
|
|
27
|
+
attr_reader :polarity
|
|
28
|
+
attr_reader :phase
|
|
29
|
+
attr_reader :word_size
|
|
30
|
+
|
|
31
|
+
def initialize(clock_pin: nil, input_pin: nil, output_pin: nil, polarity: 1, phase: 0, word_size: 8)
|
|
32
|
+
raise ArgumentError, "clock_pin is required" if clock_pin == nil
|
|
33
|
+
raise ArgumentError, "At least input_pin or output_pin must be specified" if ((input_pin == nil) && (output_pin == nil))
|
|
34
|
+
|
|
35
|
+
raise ArgumentError, "polarity must be either 0 or 1" if ((polarity != 0) && (polarity != 1))
|
|
36
|
+
raise ArgumentError, "phase must be either 0 or 1" if ((phase != 0) && (phase != 1))
|
|
37
|
+
|
|
38
|
+
pins = ChipGPIO.get_pins()
|
|
39
|
+
|
|
40
|
+
@clock_pin = nil
|
|
41
|
+
@input_pin = nil
|
|
42
|
+
@output_pin = nil
|
|
43
|
+
|
|
44
|
+
@clock_pin = pins[clock_pin]
|
|
45
|
+
@input_pin = pins[input_pin] if (input_pin)
|
|
46
|
+
@output_pin = pins[output_pin] if (output_pin)
|
|
47
|
+
|
|
48
|
+
@clock_pin.export if not @clock_pin.available?
|
|
49
|
+
@input_pin.export if input_pin && (not @input_pin.available?)
|
|
50
|
+
@output_pin.export if output_pin && (not @output_pin.available?)
|
|
51
|
+
|
|
52
|
+
@clock_pin.direction = :output
|
|
53
|
+
@input_pin.direction = :output if (input_pin)
|
|
54
|
+
@output_pin.direction = :output if (output_pin)
|
|
55
|
+
|
|
56
|
+
@clock_pin.value = 0
|
|
57
|
+
@input_pin.value = 0 if (input_pin)
|
|
58
|
+
@output_pin.value = 0 if (output_pin)
|
|
59
|
+
|
|
60
|
+
@polarity = polarity
|
|
61
|
+
@phase = phase
|
|
62
|
+
@word_size = word_size
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def max_word
|
|
66
|
+
((2**@word_size) - 1)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def write(words: [], reverse_output: true)
|
|
70
|
+
raise "An output_pin must be specified to write" if !@output_pin
|
|
71
|
+
|
|
72
|
+
bits = Array (0..(@word_size - 1))
|
|
73
|
+
|
|
74
|
+
if reverse_output
|
|
75
|
+
words = words.reverse()
|
|
76
|
+
bits = bits.reverse()
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
words.each do |w|
|
|
80
|
+
w = 0 if w < 0
|
|
81
|
+
w = max_word if w > max_word
|
|
82
|
+
|
|
83
|
+
bits.each do |b|
|
|
84
|
+
@clock_pin.value = (1 - @polarity)
|
|
85
|
+
|
|
86
|
+
if (w & (1 << b)) > 0
|
|
87
|
+
@output_pin.value = 1
|
|
88
|
+
else
|
|
89
|
+
@output_pin.value = 0
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
@clock_pin.value = @polarity
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
@clock_pin.value = (1 - @polarity)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
data/lib/chip-gpio.rb
CHANGED
|
File without changes
|
metadata
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
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.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- James Williams
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2017-01-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
|
-
description: A ruby gem to control the
|
|
13
|
+
description: A ruby gem to control the IO hardware the CHIP computer
|
|
14
14
|
email: james@jameswilliams.me
|
|
15
15
|
executables: []
|
|
16
16
|
extensions: []
|
|
@@ -19,6 +19,7 @@ files:
|
|
|
19
19
|
- README.md
|
|
20
20
|
- lib/chip-gpio.rb
|
|
21
21
|
- lib/chip-gpio/Pin.rb
|
|
22
|
+
- lib/chip-gpio/SoftSpi.rb
|
|
22
23
|
homepage: http://github.com/willia4/chip-gpio
|
|
23
24
|
licenses:
|
|
24
25
|
- MIT
|
|
@@ -39,8 +40,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
39
40
|
version: '0'
|
|
40
41
|
requirements: []
|
|
41
42
|
rubyforge_project:
|
|
42
|
-
rubygems_version: 2.5.
|
|
43
|
+
rubygems_version: 2.5.2
|
|
43
44
|
signing_key:
|
|
44
45
|
specification_version: 4
|
|
45
|
-
summary: A ruby gem to control the
|
|
46
|
+
summary: A ruby gem to control the IO hardware on the CHIP computer
|
|
46
47
|
test_files: []
|