rbuspirate 0.2.3 → 0.2.4

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
  SHA256:
3
- metadata.gz: ea1e9f18b739184a2722b3dd7d8cc4c8d64830291fe9caa93099360ade5ab41e
4
- data.tar.gz: e7ad361bd69818d82d73b1fb0942c184808428d835b66c894b70f1843fee4fa3
3
+ metadata.gz: 980cffb01298ceb60a0a7227b26162b2c1c9a81056f3f1d7533adc5dd1b3cb3a
4
+ data.tar.gz: 1ee643f76efbce4dd6bbda7a4b8882732ace3f52d49a93db3ca4e09f57ab4b0d
5
5
  SHA512:
6
- metadata.gz: 67bb082b478a92a839d8d8f5c8d0806ada5944d82cb8edf7de25626890519b6ed3afeae18fb0280c40ba4b503ef1f615a40307d1fad888d58294587160079fc7
7
- data.tar.gz: 8f066117c4100121d93ac477d1eea45f815a8e016651ad246e11e5fd81044553de5ada39080aa363323d399249b01d1caaaaaf39006b715bfa051826ff23a3ad
6
+ metadata.gz: 9c072cc7ee73949c9f790cf42a3e9baeca2cff6a120dce9dcabe559f27d2fda57508299727dcb29c3eb6f30c13ba54d04fab19f1b5a6bfddece3b152883beee7
7
+ data.tar.gz: e8ca8811d409638776363424d3fac01c7484a3ceadb2d1e42db6a2459e16ef90f5310699f5f5917e8867b5d31a4261707c7664f44a027e99f9c55c4e82028c1d
data/Gemfile CHANGED
@@ -3,4 +3,4 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in rbuspirate.gemspec
4
4
  gemspec
5
5
 
6
- gem "pry", "~> 0.12.2"
6
+ gem "pry", "~> 0.13.0"
data/Gemfile.lock CHANGED
@@ -1,18 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbuspirate (0.2.3)
4
+ rbuspirate (0.2.4)
5
5
  serialport (~> 1.3)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  coderay (1.1.2)
11
- method_source (0.9.2)
12
- pry (0.12.2)
13
- coderay (~> 1.1.0)
14
- method_source (~> 0.9.0)
15
- rake (10.5.0)
11
+ method_source (1.0.0)
12
+ pry (0.13.1)
13
+ coderay (~> 1.1)
14
+ method_source (~> 1.0)
15
+ rake (13.0.1)
16
16
  serialport (1.3.1)
17
17
 
18
18
  PLATFORMS
@@ -20,8 +20,8 @@ PLATFORMS
20
20
 
21
21
  DEPENDENCIES
22
22
  bundler (~> 2.0)
23
- pry (~> 0.12.2)
24
- rake (~> 10.0)
23
+ pry (~> 0.13.0)
24
+ rake (~> 13.0)
25
25
  rbuspirate!
26
26
 
27
27
  BUNDLED WITH
data/lib/rbuspirate.rb CHANGED
@@ -62,6 +62,30 @@ module Rbuspirate
62
62
 
63
63
  raise 'Enter to bitbang failied'
64
64
  end
65
+
66
+ def pin_on_off(power: false, pullup: false, aux: false, mosi: false, clk: false, miso: false, cs: false)
67
+ argarray = [power, pullup, aux, mosi, clk, miso, cs].freeze
68
+ argarray.each do |arg|
69
+ raise ArgumentError, 'Shitty arg' unless [true, false].include?(arg)
70
+ end
71
+
72
+ final_comm = argarray
73
+ .each.with_index
74
+ .inject(Commands::Config::PINONOFF) do |comm, (arg, idx)|
75
+ arg ? (comm | 1 << idx) : (comm)
76
+ end
77
+ @le_port.putc(final_comm)
78
+ # I don't fucking understand:
79
+ # "The Bus pirate responds to each update
80
+ # with a byte in the same format
81
+ # that shows the current state of the pins"
82
+ # So, why response is always a null byte ?
83
+ resp = @le_port.expect(
84
+ Responses::PINS_SET, Timeouts::PINONOFF
85
+ )
86
+ raise 'Setting pins state failied' unless resp
87
+ end
88
+
65
89
  [
66
90
  [
67
91
  :i2c, Commands::I2C::ENTER,
@@ -7,6 +7,8 @@ module Rbuspirate
7
7
  CONF_PER = 0b01000000
8
8
 
9
9
  module Config
10
+ PINONOFF = 0b10000000
11
+
10
12
  module Peripherals
11
13
  POWER = 0b00001000
12
14
  PULLUP = 0b00000100
@@ -51,6 +53,8 @@ module Rbuspirate
51
53
  module UART
52
54
  ENTER = 0b00000011
53
55
  START_BRIDGE = 0b00001111
56
+ ECHO_RX = 0b00000010
57
+ BULK_WRITE = 0b00010000
54
58
 
55
59
  module Config
56
60
  CONF_UART = 0b10000000
@@ -8,7 +8,7 @@ module Rbuspirate
8
8
  class UART < Abstract
9
9
  attr_reader :bridge, :speed, :power, :pullup, :aux, :cs,
10
10
  :pin_out_33, :parity_data, :stop_bits, :rx_idle,
11
- :port
11
+ :port, :speed, :echo_rx
12
12
 
13
13
  def initialize(serial, bup)
14
14
  raise 'Bus pirate must be in uart mode' unless bup.mode == :uart
@@ -16,6 +16,7 @@ module Rbuspirate
16
16
  @bridge = false
17
17
  @bup = bup
18
18
  @le_port = serial
19
+ @echo_rx = false
19
20
  end
20
21
 
21
22
  def configure_peripherals(...)
@@ -56,6 +57,16 @@ module Rbuspirate
56
57
  @speed = bit_speed
57
58
  end
58
59
 
60
+ # Not working ?
61
+ def echo_rx=(echo_state)
62
+ raise ArgumentError, 'Echo state arg should be false or true' unless [true, false].include?(echo_state)
63
+ return if echo_state == @echo_rx
64
+
65
+ echo_comm = (Commands::UART::ECHO_RX | (echo_state ? 0 : 1))
66
+ simplex_command(echo_comm, Timeouts::SUCCESS, "Unable to set echo rx state to #{echo_state}")
67
+ @echo_rx = echo_state
68
+ end
69
+
59
70
  def config_uart(
60
71
  pin_out_33: false, parity_data: :n8, stop_bits: 1, rx_idle: true
61
72
  )
@@ -90,20 +101,36 @@ module Rbuspirate
90
101
  def enter_bridge
91
102
  return @bridge if @bridge
92
103
 
93
- @le_port.write(Commands::UART::START_BRIDGE.chr)
104
+ simplex_command(Commands::UART::START_BRIDGE, Timeouts::SUCCESS, 'Unable to enter bridge')
94
105
  @bridge = true
95
106
  @bup.instance_variable_set(:@needs_reset, true)
96
107
  @port = @le_port
97
108
  end
98
109
 
99
110
  def read(bytes = 0)
100
- raise 'Enter to bridge mode first' unless @bridge
111
+ raise 'Enable echo_rx or enter to bridge mode' unless @bridge || @echo_rx
112
+ # Not working in echo rx mode - firmware bug or expect discards data buffer
101
113
  bytes.positive? ? @le_port.read(bytes) : @le_port.read
102
114
  end
103
115
 
104
116
  def write(data)
105
- raise 'Enter to bridge mode first' unless @bridge
106
- @le_port.write(data.to_s.b)
117
+ data = data.to_s.b
118
+ @bridge ? @le_port.write(data) : bulk_write(data)
119
+ end
120
+
121
+ protected
122
+
123
+ def bulk_write(data)
124
+ dbt = data.bytesize
125
+ unpackstr = 'a16' * (dbt / 16)
126
+ !(dbt % 16).zero? && unpackstr += "a#{dbt % 16}"
127
+ data = data.unpack(unpackstr)
128
+ data.each do |slice|
129
+ comm = Commands::UART::BULK_WRITE | (slice.bytesize - 1)
130
+ simplex_command(comm, Timeouts::SUCCESS, 'Unable to write data slice prepare')
131
+ simplex_command(slice, Timeouts::SUCCESS, 'Unable to write data slice')
132
+ end
133
+ dbt
107
134
  end
108
135
  end
109
136
  end
@@ -5,6 +5,7 @@ module Rbuspirate
5
5
  module Responses
6
6
  BITBANG_MODE = 'BBIO1'
7
7
  SUCCESS = 0x01.chr
8
+ PINS_SET = 0x00.chr
8
9
 
9
10
  module LE1WIRE
10
11
  ENTER = '1W01'
@@ -5,6 +5,7 @@ module Rbuspirate
5
5
  module Timeouts
6
6
  BINARY_RESET = 0.05
7
7
  SUCCESS = 0.1
8
+ PINONOFF = 0.1
8
9
 
9
10
  module LE1WIRE
10
11
  ENTER = 0.2
@@ -26,6 +27,7 @@ module Rbuspirate
26
27
 
27
28
  module UART
28
29
  ENTER = 0.2
30
+ BULK_WRITE = 5
29
31
  end
30
32
  end
31
33
  end
@@ -1,3 +1,3 @@
1
1
  module Rbuspirate
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
data/rbuspirate.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.require_paths = ['lib'] + Dir.glob('lib/**').select(&File.method(:directory?))
25
25
 
26
26
  spec.add_development_dependency "bundler", "~> 2.0"
27
- spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rake", "~> 13.0"
28
28
  spec.add_development_dependency "pry", "~> 0.12"
29
29
  spec.add_dependency "serialport", "~> 1.3"
30
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbuspirate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - sh7d
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-14 00:00:00.000000000 Z
11
+ date: 2020-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pry
43
43
  requirement: !ruby/object:Gem::Requirement