Module: Denko::SPI::Peripheral

Includes:
Behaviors::BusPeripheral, Behaviors::Callbacks, Behaviors::OutputPin
Included in:
AnalogIO::ADS1118, LED::APA102, BaseRegister
Defined in:
lib/denko/spi/peripheral.rb

Instance Attribute Summary collapse

Attributes included from Behaviors::BusPeripheral

#address

Attributes included from Behaviors::Component

#board

Attributes included from Behaviors::Callbacks

#callback_mutex

Attributes included from Behaviors::SinglePin

#mode, #pin

Instance Method Summary collapse

Methods included from Behaviors::BusPeripheral

#atomically

Methods included from Behaviors::Component

#initialize, #micro_delay

Methods included from Behaviors::State

#initialize, #state

Methods included from Behaviors::Callbacks

#add_callback, #callbacks, #initialize, #pre_callback_filter, #remove_callback, #update

Instance Attribute Details

#spi_bit_orderObject (readonly)

Returns the value of attribute spi_bit_order.



8
9
10
# File 'lib/denko/spi/peripheral.rb', line 8

def spi_bit_order
  @spi_bit_order
end

#spi_frequencyObject (readonly)

Returns the value of attribute spi_frequency.



8
9
10
# File 'lib/denko/spi/peripheral.rb', line 8

def spi_frequency
  @spi_frequency
end

#spi_modeObject (readonly)

Returns the value of attribute spi_mode.



8
9
10
# File 'lib/denko/spi/peripheral.rb', line 8

def spi_mode
  @spi_mode
end

Instance Method Details

#before_initialize(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/denko/spi/peripheral.rb', line 10

def before_initialize(options={})
  super(options)

  # Save SPI settings.
  @spi_frequency  = options[:spi_frequency]
  @spi_mode       = options[:spi_mode]
  @spi_bit_order  = options[:spi_bit_order]
end

#spi_listen(num_bytes) ⇒ Object



34
35
36
# File 'lib/denko/spi/peripheral.rb', line 34

def spi_listen(num_bytes)
  bus.listen(pin, read: num_bytes, frequency: spi_frequency, mode: spi_mode, bit_order: spi_bit_order)
end

#spi_read(num_bytes) ⇒ Object



30
31
32
# File 'lib/denko/spi/peripheral.rb', line 30

def spi_read(num_bytes)
  bus.transfer(pin, read: num_bytes, frequency: spi_frequency, mode: spi_mode, bit_order: spi_bit_order)
end

#spi_stopObject



38
39
40
# File 'lib/denko/spi/peripheral.rb', line 38

def spi_stop
  bus.stop(pin)
end

#spi_transfer(write: [], read: 0) ⇒ Object

Delegate methods to the bus.



22
23
24
# File 'lib/denko/spi/peripheral.rb', line 22

def spi_transfer(write: [], read: 0)
  bus.transfer(pin, write: write, read: read, frequency: spi_frequency, mode: spi_mode, bit_order: spi_bit_order)
end

#spi_write(byte_array) ⇒ Object



26
27
28
# File 'lib/denko/spi/peripheral.rb', line 26

def spi_write(byte_array)
  bus.transfer(pin, write: byte_array, frequency: spi_frequency, mode: spi_mode, bit_order: spi_bit_order)
end