gpio(3lua) - NetBSD Manual Pages

Command: Section: Arch: Collection:  
GPIO(3lua)                           LOCAL                          GPIO(3lua)

gpio -- access gpio(4) pins from Lua
local gpio = require 'gpio' gpiodev = pins = gpio.close(gpiodev) gpio.set(gpiodev, pin, flags) gpio.unset(gpiodev, pin) state =, pin) oldstate = gpio.write(gpiodev, pin, state) gpio.toggle(gpiodev, pin) gpio.attach(gpiodev, driver, offset, mask [, flags])
The gpio Lua binding provides access to a gpio(4) device using the ioctl(2) interface. gpiodev = Open the gpio device and return an object to access its pins. pins = Returns the number of pins. As with all remaining functions, this can also be called using the : notation, i.e. as gpiodev:info(). gpio.close(gpiodev) Close the gpio device. gpio.set(gpiodev, pin, flags) 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 start- ing at zero. The following flags are defined: gpio.PIN_INPUT Pin is an input. gpio.PIN_OUTPUT Pin is an output. gpio.PIN_INOUT Pin is birectional. gpio.PIN_OPENDRAIN Pin is an open-drain output. gpio.PIN_PUSHPULL Pin is a push-pull output. gpio.PIN_TRISTATE Pin is tri-state (output disabled). gpio.PIN_PULLUP Pin has an internal pull-up enabled. gpio.PIN_PULLDOWN Pin has an internal pull-down enabled. gpio.PIN_INVIN Invert input. gpio.PIN_INVOUT Invert output. gpio.PIN_USER Pin accessible by users. gpio.PIN_PULSATE Pulsate pin at a hardware set frequency. gpio.PIN_SET Pin is set. gpio.unset(gpiodev, pin) Unset gpio pin. stat =, pin) Read the current pin state. oldstate = gpio.write(gpiodev, pin, state) Write the pin state returning the old state. The following states are defined: gpio.PIN_LOW Pin is in the low state. gpio.PIN_HIGH Pin is in the high state. gpio.toggle(gpiodev, pin) Toggle pin state. gpio.attach(gpiodev, driver, offset, mask [, flags]) 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 ='/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 <>. NetBSD 9.3 January 7, 2014 NetBSD 9.3
Powered by man-cgi (2024-03-20). Maintained for NetBSD by Kimmo Suominen. Based on man-cgi by Panagiotis Christias.