GPIO(3lua)
β¨ NAME β¨
okay so this is the GPIO(3lua) page β a LOCAL manual, bestie β and it's literally the Lua binding for gpio: gpio β access gpio(4) pins from Lua. It's giving "tiny door into the hardware" energy and I'm obsessed. π
π SYNOPSIS π
Here's the whole vibe, no cap:
local gpio = require 'gpio'
gpiodev = gpio.open(path)
pins = gpio.info(gpiodev)
gpio.close(gpiodev)
gpio.set(gpiodev, pin, flags)
gpio.unset(gpiodev, pin)
state = gpio.read(gpiodev, pin)
oldstate = gpio.write(gpiodev, pin, state)
gpio.toggle(gpiodev, pin)
gpio.attach(gpiodev, driver, offset, mask [, flags])
πΈ DESCRIPTION πΈ
The gpio Lua binding provides access to a gpio(4) device using the ioctl(2) interface. Slay, that's the whole point. β¨
gpiodev = gpio.open(path)β open the gpio device and return an object to access its pins.pins = gpio.info(gpiodev)β returns the number of pins. As with all remaining functions, this can also be called using the:notation, i.e. asgpiodev: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 likegpioctl(8)which also number pins starting 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. (yes, literally, that's the word π«Ά)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 = gpio.read(gpiodev, 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 withoffset,mask, and optionalflagsat a pin.
π¦ EXAMPLES π¦
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
π SEE ALSO π
lua(1), luac(1), intro(3lua), gpio(4) β go read those too, bestie, iykyk. π
π HISTORY π
A gpio manual appeared in NetBSD 7.0. Periodt. π
π AUTHORS π
The gpio Lua binding was written by Marc Balmer <mbalmer@NetBSD.org>. Iconic behavior, honestly. π
xoxo bestie π β this page is brought to you by Debian, dated January 7, 2014. Mwah! πβ¨
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 2013, 2014 Marc Balmer <mbalmer@NetBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms