Sha256: 3921c58750154fd158f97f060c6a067dc6b7798d8ce87ad80ed2ac3a29fe6748

Contents?: true

Size: 1.09 KB

Versions: 7

Compression:

Stored size: 1.09 KB

Contents

module Denko
  module SPI
    class BaseRegister
      include Peripheral
      #
      # Registers act as a Board for components that need only digital pins in
      # in their I/O direction. Give the register as a 'board' when initializing a
      # new component, and pin numbers that map onto the registers parallel output pins.
      #
      include Behaviors::BoardProxy

      attr_reader :bytes

      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

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

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
denko-0.13.6 lib/denko/spi/base_register.rb
denko-0.13.5 lib/denko/spi/base_register.rb
denko-0.13.4 lib/denko/spi/base_register.rb
denko-0.13.3 lib/denko/spi/base_register.rb
denko-0.13.2 lib/denko/spi/base_register.rb
denko-0.13.1 lib/denko/spi/base_register.rb
denko-0.13.0 lib/denko/spi/base_register.rb