Module: Denko::I2C::Peripheral

Instance Attribute Summary collapse

Attributes included from Behaviors::Callbacks

#callback_mutex

Attributes included from Behaviors::BusPeripheral

#address

Attributes included from Behaviors::Component

#board

Instance Method Summary collapse

Methods included from Behaviors::Reader

#_read, #read, #read_using, #wait_for_read

Methods included from Behaviors::Callbacks

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

Methods included from Behaviors::State

#initialize, #state

Methods included from Behaviors::BusPeripheral

#atomically

Methods included from Behaviors::Component

#initialize, #micro_delay

Instance Attribute Details

#i2c_frequencyObject

Returns the value of attribute i2c_frequency.



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

def i2c_frequency
  @i2c_frequency
end

#i2c_repeated_startObject

Returns the value of attribute i2c_repeated_start.



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

def i2c_repeated_start
  @i2c_repeated_start
end

Instance Method Details

#before_initialize(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/denko/i2c/peripheral.rb', line 7

def before_initialize(options={})
  # Allow peripherals to set @i2c_address.
  @address            ||= @i2c_address

  # I2C defaults if peripheral does not set.
  @i2c_frequency      ||= 100000
  @i2c_repeated_start ||= false

  # Override defaults if given in options.
  @i2c_frequency      = options[:i2c_frequency]      if options[:i2c_frequency]
  @i2c_repeated_start = options[:i2c_repeated_start] if options[:i2c_frequency]

  # Allow generic :address option to be given as :i2c_address before validation.
  # Superclass method will hande override.
  options[:address] ||= options[:i2c_address]

  super(options)
end

#i2c_read(register, num_bytes) ⇒ Object



33
34
35
# File 'lib/denko/i2c/peripheral.rb', line 33

def i2c_read(register, num_bytes)
  bus._read(address, register, num_bytes, i2c_frequency, i2c_repeated_start)
end

#i2c_write(bytes = []) ⇒ Object



29
30
31
# File 'lib/denko/i2c/peripheral.rb', line 29

def i2c_write(bytes=[])
  bus.write(address, bytes, i2c_frequency, i2c_repeated_start)
end