GPIO¶
Overview¶
API Reference¶
-
group
gpio_interface
GPIO Driver APIs.
Typedefs
-
typedef
gpio_callback_handler_t
¶ Define the application callback handler function signature.
Note: cb pointer can be used to retrieve private data through
CONTAINER_OF() if original struct gpio_callback is stored in another private structure.- Parameters
struct device *port
: Device struct for the GPIO device.struct gpio_callback *cb
: Original struct gpio_callback owning this handleru32_t pins
: Mask of pins that triggers the callback handler
Functions
-
static int
gpio_pin_configure
(struct device *port, u32_t pin, int flags)¶ Configure a single pin.
- Return
0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to device structure for the driver instance.pin
: Pin number to configure.flags
: Flags for pin configuration. IN/OUT, interrupt …
-
static int
gpio_pin_write
(struct device *port, u32_t pin, u32_t value)¶ Write the data value to a single pin.
- Return
0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to the device structure for the driver instance.pin
: Pin number where the data is written.value
: Value set on the pin.
-
static int
gpio_pin_read
(struct device *port, u32_t pin, u32_t *value)¶ Read the data value of a single pin.
Read the input state of a pin, returning the value 0 or 1.
- Return
0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to the device structure for the driver instance.pin
: Pin number where data is read.value
: Integer pointer to receive the data values from the pin.
-
static void
gpio_init_callback
(struct gpio_callback *callback, gpio_callback_handler_t handler, u32_t pin_mask)¶ Helper to initialize a struct gpio_callback properly.
- Parameters
callback
: A valid Application’s callback structure pointer.handler
: A valid handler function pointer.pin_mask
: A bit mask of relevant pins for the handler
-
static int
gpio_add_callback
(struct device *port, struct gpio_callback *callback)¶ Add an application callback.
Note: enables to add as many callback as needed on the same port.
- Return
0 if successful, negative errno code on failure.
- Note
Callbacks may be added to the device from within a callback handler invocation, but whether they are invoked for the current GPIO event is not specified.
- Parameters
port
: Pointer to the device structure for the driver instance.callback
: A valid Application’s callback structure pointer.
-
static int
gpio_remove_callback
(struct device *port, struct gpio_callback *callback)¶ Remove an application callback.
Note: enables to remove as many callbacks as added through
gpio_add_callback().- Return
0 if successful, negative errno code on failure.
- Warning
It is explicitly permitted, within a callback handler, to remove the registration for the callback that is running, i.e.
callback
. Attempts to remove other registrations on the same device may result in undefined behavior, including failure to invoke callbacks that remain registered and unintended invocation of removed callbacks.- Parameters
port
: Pointer to the device structure for the driver instance.callback
: A valid application’s callback structure pointer.
-
static int
gpio_pin_enable_callback
(struct device *port, u32_t pin)¶ Enable callback(s) for a single pin.
Note: Depending on the driver implementation, this function will enable the pin to trigger an interruption. So as a semantic detail, if no callback is registered, of course none will be called.
- Return
0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to the device structure for the driver instance.pin
: Pin number where the callback function is enabled.
-
static int
gpio_pin_disable_callback
(struct device *port, u32_t pin)¶ Disable callback(s) for a single pin.
- Return
0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to the device structure for the driver instance.pin
: Pin number where the callback function is disabled.
-
int
gpio_get_pending_int
(struct device *dev)¶ Function to get pending interrupts.
The purpose of this function is to return the interrupt status register for the device. This is especially useful when waking up from low power states to check the wake up source.
- Parameters
dev
: Pointer to the device structure for the driver instance.
- Return Value
status
: != 0 if at least one gpio interrupt is pending.0
: if no gpio interrupt is pending.
-
struct
gpio_callback
¶ - #include <gpio.h>
GPIO callback structure.
Used to register a callback in the driver instance callback list. As many callbacks as needed can be added as long as each of them are unique pointers of struct gpio_callback. Beware such structure should not be allocated on stack.
Note: To help setting it, see gpio_init_callback() below
-
typedef