Class: LittleWire::SPI
- Inherits:
-
Object
- Object
- LittleWire::SPI
- Defined in:
- lib/littlewire/spi.rb
Instance Method Summary collapse
-
#debug ⇒ Object
get debug status.
-
#delay=(number) ⇒ Object
change spi delay setting.
-
#initialize(wire) ⇒ SPI
constructor
A new instance of SPI.
-
#send(send, auto_chipselect = false) ⇒ Object
send and receive a message of up to four bytes.
Constructor Details
#initialize(wire) ⇒ SPI
Returns a new instance of SPI.
2 3 4 5 6 |
# File 'lib/littlewire/spi.rb', line 2 def initialize wire @wire = wire @wire.control_transfer(function: :setup_spi) raise "SPI requires LittleWire firmware 1.1. Yours = #{@wire.version}" unless @wire.version_hex >= 0.11 end |
Instance Method Details
#debug ⇒ Object
get debug status
26 27 28 29 |
# File 'lib/littlewire/spi.rb', line 26 def debug @wire.control_transfer(function: :debug_spi, dataIn: 8) @wire.control_transfer(function: :read_buffer, dataIn: 8).unpack('c').first end |
#delay=(number) ⇒ Object
change spi delay setting
21 22 23 |
# File 'lib/littlewire/spi.rb', line 21 def delay= number @wire.control_transfer(function: :spi_update_delay, wValue: number) end |
#send(send, auto_chipselect = false) ⇒ Object
send and receive a message of up to four bytes
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/littlewire/spi.rb', line 9 def send send, auto_chipselect = false mode = auto_chipselect ? 1 : 0 bytes = send.bytes.to_a @wire.control_transfer( bRequest: 0xF0 + send.length + (mode << 3), wValue: bytes[1].to_i << 8 | bytes[0].to_i, wIndex: bytes[3].to_i << 8 | bytes[2].to_i, dataIn: bytes.length ) end |