GPIO¶
Overview¶
API Reference¶
-
group
gpio_interface
GPIO Driver APIs.
Defines
-
GPIO_DECLARE_PIN_CONFIG_IDX
(_idx)¶
-
GPIO_DECLARE_PIN_CONFIG
¶
-
GPIO_PIN_IDX
(_idx, _controller, _pin)¶
-
GPIO_PIN
(_controller, _pin)¶
-
GPIO_GET_CONTROLLER_IDX
(_idx, _conf)¶
-
GPIO_GET_PIN_IDX
(_idx, _conf)¶
-
GPIO_GET_CONTROLLER
(_conf)¶
-
GPIO_GET_PIN
(_conf)¶
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.
-
static int
gpio_port_configure
(struct device *port, int flags)¶ Configure all the pins the same way in the port. List out all flags on the detailed description.
- Return
- 0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to the device structure for the driver instance.flags
: Flags for the port configuration. IN/OUT, interrupt …
-
static int
gpio_port_write
(struct device *port, u32_t value)¶ Write a data value to the port.
Write the output state of a port. The state of each pin is represented by one bit in the value. Pin 0 corresponds to the least significant bit, pin 31 corresponds to the most significant bit. For ports with less that 32 physical pins the most significant bits which do not correspond to a physical pin are ignored.
- Return
- 0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to the device structure for the driver instance.value
: Value to set on the port.
-
static int
gpio_port_read
(struct device *port, u32_t *value)¶ Read data value from the port.
Read the input state of a port. The state of each pin is represented by one bit in the returned value. Pin 0 corresponds to the least significant bit, pin 31 corresponds to the most significant bit. Unused bits for ports with less that 32 physical pins are returned as 0.
- Return
- 0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to the device structure for the driver instance.value
: Integer pointer to receive the data value from the port.
-
static int
gpio_port_enable_callback
(struct device *port)¶ Enable callback(s) for the port.
Note: Depending on the driver implementation, this function will enable the port to trigger an interruption on all pins, as long as these are configured properly. 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.
-
static int
gpio_port_disable_callback
(struct device *port)¶ Disable callback(s) for the port.
- Return
- 0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to the device structure for the driver instance.
-
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
-