chip-gpio 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2bd88f0fd76071fd6292675337841d22465f029
4
- data.tar.gz: ce6a49044b5748da33d16d5af5a2dfb7369668c2
3
+ metadata.gz: 2f70b8ed01708787a7cf556b02960218fb06e669
4
+ data.tar.gz: a3b78c5c8e4969b5e9da2249c94fd8d8d18a19c3
5
5
  SHA512:
6
- metadata.gz: ff287ee4e02d61680d5b1c927b56eb3ee64420d81bab7c8b5e8b8846da44d25774fe96839455f25e12d19f251514856dd8ce28b11001e07052e93a873b06fc5e
7
- data.tar.gz: 2819b7e2d8f00def73258b74b66a821bedcdaca2afaa58eaf4b81a016d304ea431a90ec895af434e3e32ac01dffd6b84e1e1b489028bc0aaeded86e0a4d472f7
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 GPIO pins on a $9 CHIP computer.
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 for CHIP computers running v4.3 or v4.4 images.
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.3
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: 2016-09-10 00:00:00.000000000 Z
11
+ date: 2017-01-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: A ruby gem to control the GPIO pens on the CHIP computer
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.1
43
+ rubygems_version: 2.5.2
43
44
  signing_key:
44
45
  specification_version: 4
45
- summary: A ruby gem to control the GPIO pens on the CHIP computer
46
+ summary: A ruby gem to control the IO hardware on the CHIP computer
46
47
  test_files: []