rbuspirate 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rbuspirate.rb +2 -1
- data/lib/rbuspirate/commands.rb +11 -18
- data/lib/rbuspirate/interfaces/abstract.rb +36 -0
- data/lib/rbuspirate/interfaces/i2c.rb +21 -38
- data/lib/rbuspirate/interfaces/uart.rb +3 -21
- data/lib/rbuspirate/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4ff50218ea5120cf13b9bdb2023de3ab94c6130f4bf574d00cbb42509bfb133
|
4
|
+
data.tar.gz: 7f9de8009ee5136201f82eb6a07c7b68d2a68f039519f2b2776ca25a74a58184
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f66a9ea057a856b01ef13e8a91b982869f479308e488ea29df1f6a562987514aa5ef99e0740fa78a4a9610cab2b07164764baf8fdee263fd3c047cc8ccd18147
|
7
|
+
data.tar.gz: 34850f9a893ccc19b098bd2551425e36eb1d735636ecfd8617b374263c73da21385e856a256f86a07000b657f51f8b36349ff0d7e8fe560f944b77879e82bc0d
|
data/Gemfile.lock
CHANGED
data/lib/rbuspirate.rb
CHANGED
@@ -2,9 +2,9 @@ require 'expect'
|
|
2
2
|
require 'serialport'
|
3
3
|
|
4
4
|
require 'rbuspirate/commands'
|
5
|
-
require 'rbuspirate/helpers'
|
6
5
|
require 'rbuspirate/responses'
|
7
6
|
require 'rbuspirate/timeouts'
|
7
|
+
require 'rbuspirate/interfaces/abstract'
|
8
8
|
require 'rbuspirate/interfaces/i2c'
|
9
9
|
require 'rbuspirate/interfaces/uart'
|
10
10
|
|
@@ -20,6 +20,7 @@ module Rbuspirate
|
|
20
20
|
raise 'Device argument must be device' if File.stat(dvc).rdev.zero?
|
21
21
|
|
22
22
|
dvc = SerialPort.new(dvc, 115_200, 8, 1, SerialPort::NONE)
|
23
|
+
dvc.flow_control = SerialPort::NONE
|
23
24
|
end
|
24
25
|
@le_port = dvc
|
25
26
|
@le_port.sync = true if sync
|
data/lib/rbuspirate/commands.rb
CHANGED
@@ -4,6 +4,16 @@
|
|
4
4
|
module Rbuspirate
|
5
5
|
module Commands
|
6
6
|
RESET_BITBANG = 0b00000000
|
7
|
+
CONF_PER = 0b01000000
|
8
|
+
|
9
|
+
module Config
|
10
|
+
module Peripherals
|
11
|
+
POWER = 0b00001000
|
12
|
+
PULLUP = 0b00000100
|
13
|
+
AUX = 0b00000010
|
14
|
+
CS = 0b00000001
|
15
|
+
end
|
16
|
+
end
|
7
17
|
|
8
18
|
module I2C
|
9
19
|
ENTER = 0b00000010
|
@@ -12,18 +22,9 @@ module Rbuspirate
|
|
12
22
|
WRITE_THEN_READ = 0x8
|
13
23
|
|
14
24
|
module Config
|
15
|
-
CONF_PER = 0b01000000
|
16
|
-
|
17
|
-
module Peripherals
|
18
|
-
POWER = 0b00001000
|
19
|
-
PULLUP = 0b00000100
|
20
|
-
AUX = 0b00000010
|
21
|
-
CS = 0b00000001
|
22
|
-
end
|
23
|
-
|
24
25
|
module Speed
|
25
26
|
S5KHZ = 0b01100000
|
26
|
-
|
27
|
+
S50KHZ = 0b01100001
|
27
28
|
S100KHZ = 0b01100010
|
28
29
|
S400KHZ = 0b01100011
|
29
30
|
end
|
@@ -42,16 +43,8 @@ module Rbuspirate
|
|
42
43
|
START_BRIDGE = 0b00001111
|
43
44
|
|
44
45
|
module Config
|
45
|
-
CONF_PER = 0b01000000
|
46
46
|
CONF_UART = 0b10000000
|
47
47
|
|
48
|
-
module Peripherals
|
49
|
-
POWER = 0b00001000
|
50
|
-
PULLUP = 0b00000100
|
51
|
-
AUX = 0b00000010
|
52
|
-
CS = 0b00000001
|
53
|
-
end
|
54
|
-
|
55
48
|
module Speed
|
56
49
|
S300 = 0b01100000
|
57
50
|
S1200 = 0b01100001
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Rbuspirate
|
2
|
+
module Interfaces
|
3
|
+
class Abstract
|
4
|
+
def configure_peripherals(
|
5
|
+
power: false, pullup: false, aux: false, cs: false
|
6
|
+
)
|
7
|
+
[power, pullup, aux, cs].map(&:class).each do |cls|
|
8
|
+
raise ArgumentError, 'All args must be true or false' unless [FalseClass, TrueClass].include?(cls)
|
9
|
+
end
|
10
|
+
|
11
|
+
bit_config = Commands::CONF_PER
|
12
|
+
bit_config |= Commands::Config::Peripherals::POWER if power
|
13
|
+
bit_config |= Commands::Config::Peripherals::PULLUP if pullup
|
14
|
+
bit_config |= Commands::Config::Peripherals::AUX if aux
|
15
|
+
bit_config |= Commands::Config::Peripherals::CS if cs
|
16
|
+
|
17
|
+
simplex_command(
|
18
|
+
bit_config,
|
19
|
+
Timeouts::SUCCESS,
|
20
|
+
'Unable to confgure peripherals'
|
21
|
+
)
|
22
|
+
@power, @pullup, @aux, @cs = power, pullup, aux, cs
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def simplex_command(command, tout, ex_message)
|
28
|
+
@le_port.write(command.chr)
|
29
|
+
resp = @le_port.expect(Responses::SUCCESS, tout)
|
30
|
+
return true if resp
|
31
|
+
|
32
|
+
raise ex_message
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -5,52 +5,18 @@ require 'timeout'
|
|
5
5
|
|
6
6
|
module Rbuspirate
|
7
7
|
module Interfaces
|
8
|
-
class I2C
|
9
|
-
include Helpers
|
8
|
+
class I2C < Abstract
|
10
9
|
attr_reader :speed, :power, :pullup, :aux, :cs
|
11
10
|
|
12
11
|
def initialize(serial, bup)
|
13
12
|
raise 'Bus pirate must be in i2c mode' unless bup.mode == :i2c
|
14
13
|
|
15
14
|
@le_port = serial
|
16
|
-
|
17
|
-
|
18
|
-
def configure_peripherals(
|
19
|
-
power: false, pullup: false, aux: false, cs: false
|
20
|
-
)
|
21
|
-
[power, pullup, aux, cs].map(&:class).each do |cls|
|
22
|
-
raise ArgumentError, 'All args must be true or false' unless [FalseClass, TrueClass].include?(cls)
|
23
|
-
end
|
24
|
-
|
25
|
-
bit_config = Commands::I2C::Config::CONF_PER
|
26
|
-
bit_config |= Commands::I2C::Config::Peripherals::POWER if power
|
27
|
-
bit_config |= Commands::I2C::Config::Peripherals::PULLUP if pullup
|
28
|
-
bit_config |= Commands::I2C::Config::Peripherals::AUX if aux
|
29
|
-
bit_config |= Commands::I2C::Config::Peripherals::CS if cs
|
30
|
-
|
31
|
-
simplex_command(
|
32
|
-
bit_config,
|
33
|
-
Timeouts::SUCCESS,
|
34
|
-
'Unable to confgure peripherals'
|
35
|
-
)
|
36
|
-
@power, @pullup, @aux, @cs = power, pullup, aux, cs
|
15
|
+
set_speed(:'400khz')
|
37
16
|
end
|
38
17
|
|
39
18
|
def speed=(le_speed)
|
40
|
-
|
41
|
-
when :'5khz'
|
42
|
-
Commands::I2C::Config::Speed::S5KHZ
|
43
|
-
when :'50khz'
|
44
|
-
Commands::I2C::Config::Speed::S50KHZ
|
45
|
-
when :'100khz'
|
46
|
-
Commands::I2C::Config::Speed::S100KHZ
|
47
|
-
when :'400khz'
|
48
|
-
Commands::I2C::Config::Speed::S400KHZ
|
49
|
-
else
|
50
|
-
raise ArgumentError, 'Bad speed argument'
|
51
|
-
end
|
52
|
-
|
53
|
-
simplex_command(bit_speed, Timeouts::SUCCESS, 'Unable to set speed')
|
19
|
+
set_speed(le_speed)
|
54
20
|
end
|
55
21
|
|
56
22
|
def send_start
|
@@ -155,7 +121,6 @@ module Rbuspirate
|
|
155
121
|
end
|
156
122
|
return false if allow_zerobyte && result.ord.zero?
|
157
123
|
raise 'Write failed' if result.ord.zero?
|
158
|
-
|
159
124
|
if expected_bytes != 0
|
160
125
|
Timeout.timeout(Timeouts::I2C::WRITE_THEN_READ_D) do
|
161
126
|
result = @le_port.read(expected_bytes)
|
@@ -165,6 +130,24 @@ module Rbuspirate
|
|
165
130
|
true
|
166
131
|
end
|
167
132
|
end
|
133
|
+
private
|
134
|
+
def set_speed(le_speed)
|
135
|
+
bit_speed = case le_speed.to_sym
|
136
|
+
when :'5khz'
|
137
|
+
Commands::I2C::Config::Speed::S5KHZ
|
138
|
+
when :'50khz'
|
139
|
+
Commands::I2C::Config::Speed::S50KHZ
|
140
|
+
when :'100khz'
|
141
|
+
Commands::I2C::Config::Speed::S100KHZ
|
142
|
+
when :'400khz'
|
143
|
+
Commands::I2C::Config::Speed::S400KHZ
|
144
|
+
else
|
145
|
+
raise ArgumentError, 'Bad speed argument'
|
146
|
+
end
|
147
|
+
|
148
|
+
simplex_command(bit_speed, Timeouts::SUCCESS, 'Unable to set speed')
|
149
|
+
@speed = le_speed
|
150
|
+
end
|
168
151
|
end
|
169
152
|
end
|
170
153
|
end
|
@@ -5,8 +5,7 @@ require 'timeout'
|
|
5
5
|
|
6
6
|
module Rbuspirate
|
7
7
|
module Interfaces
|
8
|
-
class UART
|
9
|
-
include Helpers
|
8
|
+
class UART < Abstract
|
10
9
|
attr_reader :bridge, :speed, :power, :pullup, :aux, :cs,
|
11
10
|
:pin_out_33, :parity_data, :stop_bits, :rx_idle,
|
12
11
|
:port
|
@@ -19,27 +18,10 @@ module Rbuspirate
|
|
19
18
|
@le_port = serial
|
20
19
|
end
|
21
20
|
|
22
|
-
def configure_peripherals(
|
23
|
-
power: false, pullup: false, aux: false, cs: false
|
24
|
-
)
|
21
|
+
def configure_peripherals(...)
|
25
22
|
raise 'Device needs reset in order to reconfigure it' if @bridge
|
26
23
|
|
27
|
-
|
28
|
-
raise ArgumentError, 'All args must be true or false' unless [FalseClass, TrueClass].include?(cls)
|
29
|
-
end
|
30
|
-
|
31
|
-
bit_config = Commands::UART::Config::CONF_PER
|
32
|
-
bit_config |= Commands::UART::Config::Peripherals::POWER if power
|
33
|
-
bit_config |= Commands::UART::Config::Peripherals::PULLUP if pullup
|
34
|
-
bit_config |= Commands::UART::Config::Peripherals::AUX if aux
|
35
|
-
bit_config |= Commands::UART::Config::Peripherals::CS if cs
|
36
|
-
|
37
|
-
simplex_command(
|
38
|
-
bit_config,
|
39
|
-
Timeouts::SUCCESS,
|
40
|
-
'Unable to confgure peripherals'
|
41
|
-
)
|
42
|
-
@power, @pullup, @aux, @cs = power, pullup, aux, cs
|
24
|
+
super
|
43
25
|
end
|
44
26
|
|
45
27
|
def speed=(le_speed)
|
data/lib/rbuspirate/version.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sh7d
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/rbuspirate.rb
|
86
86
|
- lib/rbuspirate/commands.rb
|
87
87
|
- lib/rbuspirate/helpers.rb
|
88
|
+
- lib/rbuspirate/interfaces/abstract.rb
|
88
89
|
- lib/rbuspirate/interfaces/i2c.rb
|
89
90
|
- lib/rbuspirate/interfaces/uart.rb
|
90
91
|
- lib/rbuspirate/responses.rb
|