class studs::Gpio
sys::Obj studs::Gpio
Gpio provides high level access to GPIO pins through the Linux /sys/class/gpio
interface.
See Gpio chapter for details.
- close
-
Void close()
Close this port.
- listen
-
Void listen(Str mode, Duration? timeout, |Int| callback)
Register an interrupt handler to listen for GPIO output changes. The
mode
should be one of the strings "rising", "falling" or "both" to indicate which edge(s) the ISR is to be triggered on. Invoke the given callback function when a change occurs. This method will block listening untilclose
is called.If
timeout
is non-null, thencallback
will be invoked at every duration oftimeout
regardless of whether a state change occurred. Iftimeout
is null, this method blocks until a state change is detected.Note that after calling
listen
, you will receive an initial callback with the state of the pin. This prevents the race condition between getting the initial state of the pin and turning on interrupts. - open
-
const static Gpio open(Int pin, Str dir)
Open a GPIO port with given pin and direction, where
dir
is"in"
or"out"
. - read
-
Int read()
Read the current value of the pin.
- write
-
Write the given value to the GPIO. The GPIO should be configured as an output. Valid values are
0
for logic low, or1
for logic high. Other non-zero values will result in logic high being output. Returns this.