GPIO(3lua)

πŸ“¦ version 11.0, in nixpkgs unstable

✨ 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. 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 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 with offset, mask, and optional flags at 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