Class: BeagleBoard::FreeBSD::Gpio

Inherits:
Base::Gpio show all
Extended by:
FFI::Library
Defined in:
lib/beagleboard/freebsd/gpio.rb

Constant Summary collapse

GPIO_PIN_LOW =
0x00
GPIO_PIN_HIGH =
0x01
GPIO_PIN_INPUT =
0x001
GPIO_PIN_OUTPUT =
0x002
GPIO_PIN_OPENDRAIN =
0x004
GPIO_PIN_PUSHPULL =
0x008
GPIO_PIN_TRISTATE =
0x010
GPIO_PIN_PULLUP =
0x020
GPIO_PIN_PULLDOWN =
0x040
GPIO_PIN_INVIN =
0x080
GPIO_PIN_INVOUT =
0x100
GPIO_VALUE_INVALID =
-1
GPIO_VALUE_LOW =
GPIO_PIN_LOW
GPIO_VALUE_HIGH =
GPIO_PIN_HIGH

Instance Method Summary collapse

Constructor Details

#initialize(bank, gpio) ⇒ Gpio

Returns a new instance of Gpio.



50
51
52
# File 'lib/beagleboard/freebsd/gpio.rb', line 50

def initialize(bank, gpio)
  super
end

Instance Method Details

#closeObject



58
59
60
# File 'lib/beagleboard/freebsd/gpio.rb', line 58

def close
  gpio_close(@bank_fd)
end

#directionObject



66
67
68
69
70
71
# File 'lib/beagleboard/freebsd/gpio.rb', line 66

def direction
  case gpio_pin_config(@bank_fd, @gpio)
  when GPIO_PIN_INPUT then :in
  when GPIO_PIN_OUTPUT then :out
  end
end

#direction=(direction) ⇒ Object



73
74
75
76
# File 'lib/beagleboard/freebsd/gpio.rb', line 73

def direction=(direction)
  send(direction_function(direction), @bank_fd, @gpio)
  self.value = direction_value(direction)
end

#openObject



54
55
56
# File 'lib/beagleboard/freebsd/gpio.rb', line 54

def open
  @bank_fd = gpio_open(@bank)
end

#toggleObject



62
63
64
# File 'lib/beagleboard/freebsd/gpio.rb', line 62

def toggle
  gpio_pin_toggle(@bank_fd, @gpio)
end

#valueObject



78
79
80
81
82
83
84
# File 'lib/beagleboard/freebsd/gpio.rb', line 78

def value
  res = Gpio.gpio_pin_get(@bank_fd, @gpio)

  raise 'Read error' if res < 0

  res
end

#value=(value) ⇒ Object

Raises:

  • (StandardError)


86
87
88
89
90
# File 'lib/beagleboard/freebsd/gpio.rb', line 86

def value=(value)
  return unless value
  res = send(value_function(value), @bank_fd, @gpio)
  raise StandardError, 'Write error' if res < 0
end