Class: Rbuspirate::Interfaces::UART
- Defined in:
- lib/rbuspirate/interfaces/uart.rb
Instance Attribute Summary collapse
-
#aux ⇒ Object
readonly
Returns the value of attribute aux.
-
#bridge ⇒ Object
readonly
Returns the value of attribute bridge.
-
#cs ⇒ Object
readonly
Returns the value of attribute cs.
-
#echo_rx ⇒ Object
Returns the value of attribute echo_rx.
-
#parity_data ⇒ Object
readonly
Returns the value of attribute parity_data.
-
#pin_out_33 ⇒ Object
readonly
Returns the value of attribute pin_out_33.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#power ⇒ Object
readonly
Returns the value of attribute power.
-
#pullup ⇒ Object
readonly
Returns the value of attribute pullup.
-
#rx_idle ⇒ Object
readonly
Returns the value of attribute rx_idle.
-
#speed ⇒ Object
Returns the value of attribute speed.
-
#stop_bits ⇒ Object
readonly
Returns the value of attribute stop_bits.
Instance Method Summary collapse
- #config_uart(pin_out_33: false, parity_data: :n8, stop_bits: 1, rx_idle: true) ⇒ Object
- #configure_peripherals ⇒ Object
- #enter_bridge ⇒ Object
-
#initialize(serial, bup) ⇒ UART
constructor
A new instance of UART.
- #read(bytes = 0) ⇒ Object
- #write(data) ⇒ Object
Constructor Details
#initialize(serial, bup) ⇒ UART
Returns a new instance of UART.
13 14 15 16 17 18 19 20 |
# File 'lib/rbuspirate/interfaces/uart.rb', line 13 def initialize(serial, bup) raise 'Bus pirate must be in uart mode' unless bup.mode == :uart @bridge = false @bup = bup @le_port = serial @echo_rx = false end |
Instance Attribute Details
#aux ⇒ Object (readonly)
Returns the value of attribute aux.
9 10 11 |
# File 'lib/rbuspirate/interfaces/uart.rb', line 9 def aux @aux end |
#bridge ⇒ Object (readonly)
Returns the value of attribute bridge.
9 10 11 |
# File 'lib/rbuspirate/interfaces/uart.rb', line 9 def bridge @bridge end |
#cs ⇒ Object (readonly)
Returns the value of attribute cs.
9 10 11 |
# File 'lib/rbuspirate/interfaces/uart.rb', line 9 def cs @cs end |
#echo_rx ⇒ Object
Returns the value of attribute echo_rx.
9 10 11 |
# File 'lib/rbuspirate/interfaces/uart.rb', line 9 def echo_rx @echo_rx end |
#parity_data ⇒ Object (readonly)
Returns the value of attribute parity_data.
9 10 11 |
# File 'lib/rbuspirate/interfaces/uart.rb', line 9 def parity_data @parity_data end |
#pin_out_33 ⇒ Object (readonly)
Returns the value of attribute pin_out_33.
9 10 11 |
# File 'lib/rbuspirate/interfaces/uart.rb', line 9 def pin_out_33 @pin_out_33 end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
9 10 11 |
# File 'lib/rbuspirate/interfaces/uart.rb', line 9 def port @port end |
#power ⇒ Object (readonly)
Returns the value of attribute power.
9 10 11 |
# File 'lib/rbuspirate/interfaces/uart.rb', line 9 def power @power end |
#pullup ⇒ Object (readonly)
Returns the value of attribute pullup.
9 10 11 |
# File 'lib/rbuspirate/interfaces/uart.rb', line 9 def pullup @pullup end |
#rx_idle ⇒ Object (readonly)
Returns the value of attribute rx_idle.
9 10 11 |
# File 'lib/rbuspirate/interfaces/uart.rb', line 9 def rx_idle @rx_idle end |
#speed ⇒ Object
Returns the value of attribute speed.
9 10 11 |
# File 'lib/rbuspirate/interfaces/uart.rb', line 9 def speed @speed end |
#stop_bits ⇒ Object (readonly)
Returns the value of attribute stop_bits.
9 10 11 |
# File 'lib/rbuspirate/interfaces/uart.rb', line 9 def stop_bits @stop_bits end |
Instance Method Details
#config_uart(pin_out_33: false, parity_data: :n8, stop_bits: 1, rx_idle: true) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rbuspirate/interfaces/uart.rb', line 70 def config_uart( pin_out_33: false, parity_data: :n8, stop_bits: 1, rx_idle: true ) raise 'Device needs reset in order to reconfigure it' if @bridge raise ArgumentError, 'Pin out should be false or true' unless [true, false].include?(pin_out_33) raise ArgumentError, 'Unknown praity and databits mode' unless [:n8, :e8, :o8, :n9].include?(parity_data) raise ArgumentError, 'Unknown stop bits mode' unless [1, 2].include?(stop_bits) raise ArgumentError, 'Rx idle should be false or true' unless [true, false].include?(rx_idle) bit_conf_uart = Commands::UART::Config::CONF_UART bit_conf_uart |= Commands::UART::Config::UartConf::PIN_OUT_33 if pin_out_33 bit_conf_uart |= case parity_data when :e8 Commands::UART::Config::UartConf::DAT_PARITY_8E when :o8 Commands::UART::Config::UartConf::DAT_PARITY_8O when :n9 Commands::UART::Config::UartConf::DAT_PARITY_9N else 0 end bit_conf_uart |= Commands::UART::Config::UartConf::STOP_BIT_2 if stop_bits == 2 bit_conf_uart |= Commands::UART::Config::UartConf::DISABLE_RX_IDLE unless rx_idle simplex_command(bit_conf_uart, Timeouts::SUCCESS, 'Unable to config uart') @pin_out_33, @parity_data, @stop_bits, @rx_idle = pin_out_33, parity_data, stop_bits, rx_idle end |
#configure_peripherals ⇒ Object
22 23 24 25 26 |
# File 'lib/rbuspirate/interfaces/uart.rb', line 22 def configure_peripherals(...) raise 'Device needs reset in order to reconfigure it' if @bridge super end |
#enter_bridge ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/rbuspirate/interfaces/uart.rb', line 101 def enter_bridge return @bridge if @bridge simplex_command(Commands::UART::START_BRIDGE, Timeouts::SUCCESS, 'Unable to enter bridge') @bridge = true @bup.instance_variable_set(:@needs_reset, true) @port = @le_port end |
#read(bytes = 0) ⇒ Object
110 111 112 113 114 |
# File 'lib/rbuspirate/interfaces/uart.rb', line 110 def read(bytes = 0) raise 'Enable echo_rx or enter to bridge mode' unless @bridge || @echo_rx # Not working in echo rx mode - firmware bug or expect discards data buffer bytes.positive? ? @le_port.read(bytes) : @le_port.read end |
#write(data) ⇒ Object
116 117 118 119 |
# File 'lib/rbuspirate/interfaces/uart.rb', line 116 def write(data) data = data.to_s.b @bridge ? @le_port.write(data) : bulk_write(data) end |