Class: Denko::SPI::BaseRegister

Inherits:
Object
  • Object
show all
Includes:
Behaviors::BoardProxy, Peripheral
Defined in:
lib/denko/spi/base_register.rb

Direct Known Subclasses

InputRegister, OutputRegister

Instance Attribute Summary collapse

Attributes included from Peripheral

#spi_bit_order, #spi_frequency, #spi_mode

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::BoardProxy

#convert_pin, #high, #low, #set_pin_mode, #start_read

Methods included from Behaviors::Subcomponents

#add_component, #components, #remove_component, #single_pin_components

Methods included from Peripheral

#spi_listen, #spi_read, #spi_stop, #spi_transfer, #spi_write

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

#bytesObject (readonly)

Returns the value of attribute bytes.



12
13
14
# File 'lib/denko/spi/base_register.rb', line 12

def bytes
  @bytes
end

Instance Method Details

#after_initialize(options = {}) ⇒ Object



29
30
31
32
33
34
# File 'lib/denko/spi/base_register.rb', line 29

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

  # Drive select pin high by default.
  self.high
end

#before_initialize(options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/denko/spi/base_register.rb', line 14

def before_initialize(options={})
  super(options)
  #
  # To use the register as a board proxy, we need to know how many
  # bytes there are and map each bit to a virtual pin.
  # Defaults to 1 byte. Ignore if writing to the register directly.
  #
  @bytes = options[:bytes] || 1
  #
  # When used as a board proxy, store the state of each register
  # pin as a 0 or 1 in an array that is (@bytes * 8) long. Zero out to start.
  #
  @state = Array.new(@bytes*8) { 0 }
end