doc/syscalls/00004_gpio.md
The GPIO driver allows userspace to synchronously control the output and receive callbacks on changes in the input for a set of GPIO pins.
This is a low-level GPIO driver designed to export "hardware-like" control of GPIO pins to userspace. Not all platforms will expose all or even any pins using this interface to userspace.
Unstable: As this is a low-level interface, the mapping of GPIO pins is currently unstable and unspecified. Users of this driver must consult their board for a mapping from pin identifiers used in this driver to actual hardware pins. This mapping is currently subject to change.
0Description: Does the driver exist?
Argument 1: unused
Argument 2: unused
Returns: Success if it exists, otherwise NODEVICE
1Description: Enable output on a GPIO pin. After enabling output,
output-related operations on the pin (set, clear, toggle) are
available. Using input operations on a pin in this state is undefined.
Argument 1: The identifier of the GPIO pin to enable output for.
Argument 2: unused
Returns: Ok(()) if the command was successful, and INVAL if the
argument refers to a non-existent pin.
2Description: Set the output of a GPIO pin (high). Using this command without first enabling output is undefined.
Argument 1: The identifier of the GPIO pin to set.
Argument 2: unused
Returns: Ok(()) if the pin identifier is valid, INVAL otherwise.
3Description: Clear the output of a GPIO pin (low). Using this command without first enabling output is undefined.
Argument 1: The identifier of the GPIO pin to clear.
Argument 2: unused
Returns: Ok(()) if the pin identifier is valid, INVAL otherwise.
4Description: Toggle the output of a GPIO pin. If the pin was previously high, this operation clears it. If it was previously low, sets it. Using this command without first enabling output is undefined.
Argument 1: The identifier of the GPIO pin to toggle.
Argument 2: unused
Returns: Ok(()) if the pin identifier is valid, INVAL otherwise.
5Description: Enable and configure input on a GPIO pin. After enabling
input, input-related operations on the pin (e.g. read) are available.
Using output operations on a pin in this state is undefined.
Argument 1: The identifier of the GPIO pin to toggle.
Argument 2: requested resistor to attach to the pin: 0 for pull-none,
1 for pull-up, or 2 for pull-down. Other values are undefined.
Returns: Ok(()) if the pin identifier is valid, INVAL if it is
invalid, and ENOSUPPORT if the resistor configuration is not supported by
the hardware. If any error is returned, no state will be changed.
6Description: Read the current value of a GPIO pin.
Argument 1: The identifier of the GPIO pin to read.
Argument 2: unused
Returns: INVAL if the identifier of the pin is invalid, 1 if the
value of the pin is high or 0 if it is low.
7Description: Configure interrupts on a GPIO pin. After enabling interrupts, the callback set in subscribe will be called when the pin level changes. Using this command without first enabling input is undefined.
Argument 1: The identifier of the GPIO pin to read.
Argument 2: Indicates which events trigger callbacks: 0 for either
edge, 1 for rising edge, or 2 for falling edge. Other values are
undefined.
Returns: Ok(()) if the pin identifier is valid, INVAL if it is
invalid, and ENOSUPPORT if an invalid interrupt mode is passed in the
configuration field of the argument. If any error is returned, no state
will be changed.
10Description: Whether GPIO pins are exported by this board.
Argument 1: unused
Argument 2: unused
Returns: Unstable: Most boards return the number of GPIO pins available, however users should consult their board for details of this return value.
0Description: Subscribe a callback that will fire when any GPIO pin whose interrupts have been enabled changes level. Registering the callback does not have an effect on whether any GPIO pin interrupts are enabled.
Callback signature: The callback receives two arguments. The first is
the identifier of the GPIO pin whose level has changed, and the second is
the value of the pin when the interrupt occurred. The second argument has
the same semantics as the return value for the read command: 0 for low,
1 for high.
Returns: Ok(()) if the subscribe was successful, NOMEM if the driver
cannot support another app, and INVAL if the app is somehow invalid.
Unused for the GPIO driver. Will always return ENOSUPPORT.