driver number: 0x00004
GPIO
Overview
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.
Command
-
Command number:
0Description: 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.
ENODEVICEif this driver is not present on the board. -
Command number:
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: SUCCESS if the command was successful, and
EINVALif the argument refers to a non-existent pin. -
Command number:
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:
SUCCESSif the pin identifier is valid,EINVALotherwise. -
Command number:
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:
SUCCESSif the pin identifier is valid,EINVALotherwise. -
Command number:
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:
SUCCESSif the pin identifier is valid,EINVALotherwise. -
Command number:
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:
0for pull-none,1for pull-up, or2for pull-down. Other values are undefined.Returns:
SUCCESSif the pin identifier is valid,EINVALif it is invalid, andENOSUPPORTif the resistor configuration is not supported by the hardware. If any error is returned, no state will be changed. -
Command number:
6Description: Read the current value of a GPIO pin.
Argument 1: The identifier of the GPIO pin to read.
Argument 2: unused
Returns:
EINVALif the identifier of the pin is invalid,1if the value of the pin is high or0if it is low. -
Command number:
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:
0for either edge,1for rising edge, or2for falling edge. Other values are undefined.Returns:
SUCCESSif the pin identifier is valid,EINVALif it is invalid, andENOSUPPORTif an invalid interrupt mode is passed in the configuration field of the argument. If any error is returned, no state will be changed.
Subscribe
-
Subscribe number:
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
readcommand:0for low,1for high.Returns: SUCCESS if the subscribe was successful, ENOMEM if the driver cannot support another app, and
EINVALif the app is somehow invalid.
Allow
Unused for the GPIO driver. Will always return ENOSUPPORT.