man.bsd.lv manual page server

Manual Page Search Parameters

GPIO(3lua) 3lua GPIO(3lua)

gpioaccess gpio(4) pins from Lua

local gpio = require 'gpio'

 
 
 
 
 
 
 
 
 

The gpio Lua binding provides access to a gpio(4) device using the ioctl(2) interface.

Open the gpio device and return an object to access its pins.

Returns the number of pins. As with all remaining functions, this can also be called using the : notation, i.e. as .

Close the gpio device.

Set gpio pin flags. Note that the pin number in this and all remaining functions is zero based and not one based, this to avoid confusion with tools like gpioctl(8) which also number pins starting at zero. The following flags are defined:

Pin is an input.

Pin is an output.

Pin is birectional.

Pin is an open-drain output.

Pin is a push-pull output.

Pin is tri-state (output disabled).

Pin has an internal pull-up enabled.

Pin has an internal pull-down enabled.

Invert input.

Invert output.

Pin accessible by users.

Pulsate pin at a hardware set frequency.

Pin is set.

Unset gpio pin.

Read the current pin state.

Write the pin state returning the old state. The following states are defined:

Pin is in the low state.

Pin is in the high state.

Toggle pin state.

Attach a device driver with offset, mask, and optional flags at a pin.

The following example code opens /dev/gpio0 and prints all pin values:

local gpio = require 'gpio'

gpiodev = gpio.open('/dev/gpio0')

local npins = gpiodev:info()

for n = 1, npins do
	print('pin ' .. n .. ': ' .. gpiodev:read(n - 1))
end

lua(1), luac(1), intro(3lua), gpio(4)

A gpio manual appeared in NetBSD 7.0.

The gpio Lua binding was written by Marc Balmer <mbalmer@NetBSD.org>.

January 7, 2014 NetBSD-9.2