Driver API for GPIO Interface (Driver_GPIO.h) More...
Content | |
GPIO Status Error Codes | |
Negative values indicate errors (GPIO has specific codes in addition to common Status Error Codes). | |
GPIO Events | |
The GPIO driver generates call back events that are notified via the function ARM_GPIO_SignalEvent. | |
Data Structures | |
struct | ARM_DRIVER_GPIO |
Access structure of the GPIO Driver. More... | |
Typedefs | |
typedef void(* | ARM_GPIO_SignalEvent_t) (ARM_GPIO_Pin_t pin, uint32_t event) |
Enumerations | |
enum | ARM_GPIO_DIRECTION { ARM_GPIO_INPUT , ARM_GPIO_OUTPUT } |
GPIO Direction. More... | |
enum | ARM_GPIO_OUTPUT_MODE { ARM_GPIO_PUSH_PULL , ARM_GPIO_OPEN_DRAIN } |
GPIO Output Mode. More... | |
enum | ARM_GPIO_PULL_RESISTOR { ARM_GPIO_PULL_NONE , ARM_GPIO_PULL_UP , ARM_GPIO_PULL_DOWN } |
GPIO Pull Resistor. More... | |
enum | ARM_GPIO_EVENT_TRIGGER { ARM_GPIO_TRIGGER_NONE , ARM_GPIO_TRIGGER_RISING_EDGE , ARM_GPIO_TRIGGER_FALLING_EDGE , ARM_GPIO_TRIGGER_EITHER_EDGE } |
GPIO Event Trigger. More... | |
Functions | |
int32_t | ARM_GPIO_Setup (ARM_GPIO_Pin_t pin, ARM_GPIO_SignalEvent_t cb_event) |
Setup GPIO Interface. | |
int32_t | ARM_GPIO_SetDirection (ARM_GPIO_Pin_t pin, ARM_GPIO_DIRECTION direction) |
Set GPIO Direction. | |
int32_t | ARM_GPIO_SetOutputMode (ARM_GPIO_Pin_t pin, ARM_GPIO_OUTPUT_MODE mode) |
Set GPIO Output Mode. | |
int32_t | ARM_GPIO_SetPullResistor (ARM_GPIO_Pin_t pin, ARM_GPIO_PULL_RESISTOR resistor) |
Set GPIO Pull Resistor. | |
int32_t | ARM_GPIO_SetEventTrigger (ARM_GPIO_Pin_t pin, ARM_GPIO_EVENT_TRIGGER trigger) |
Set GPIO Event Trigger. | |
void | ARM_GPIO_SetOutput (ARM_GPIO_Pin_t pin, uint32_t val) |
Set GPIO Output Level. | |
uint32_t | ARM_GPIO_GetInput (ARM_GPIO_Pin_t pin) |
Get GPIO Input Level. | |
void | ARM_GPIO_SignalEvent (ARM_GPIO_Pin_t pin, uint32_t event) |
Signal GPIO Events. | |
Driver API for GPIO Interface (Driver_GPIO.h)
The General-purpose Input/Output Interface (GPIO) features Input/Output operations on pin level (does not support simultaneous operations on multiple pins belonging to the same port).
Features:
Each function operates on a pin level and uses a pin identification as the first parameter. Pin identification is a virtual number which is mapped to an actual pin.
GPIO API
The following header files define the Application Programming Interface (API) for the GPIO interface:
The driver implementation is a typical part of the Device Family Pack (DFP) that supports the peripherals of the microcontroller family.
Driver Functions
The driver functions are published in the access struct as explained in Common Driver Functions
Example Code
The following example code shows the usage of the GPIO interface.
struct ARM_DRIVER_GPIO |
Access structure of the GPIO Driver.
The functions of the GPIO driver are accessed by function pointers exposed by this structure. Refer to Common Driver Functions for overview information.
Each instance of a GPIO interface provides such an access structure. The instance is identified by a postfix number in the symbol name of the access structure, for example:
A middleware configuration setting allows connecting the middleware to a specific driver instance Driver_GPIOn. The default is 0, which connects a middleware to the first instance of a driver.
Data Fields | |
int32_t(* | Setup )(ARM_GPIO_Pin_t pin, ARM_GPIO_SignalEvent_t cb_event) |
Pointer to ARM_GPIO_Setup : Setup GPIO Interface. | |
int32_t(* | SetDirection )(ARM_GPIO_Pin_t pin, ARM_GPIO_DIRECTION direction) |
Pointer to ARM_GPIO_SetDirection : Set GPIO Direction. | |
int32_t(* | SetOutputMode )(ARM_GPIO_Pin_t pin, ARM_GPIO_OUTPUT_MODE mode) |
Pointer to ARM_GPIO_SetOutputMode : Set GPIO Output Mode. | |
int32_t(* | SetPullResistor )(ARM_GPIO_Pin_t pin, ARM_GPIO_PULL_RESISTOR resistor) |
Pointer to ARM_GPIO_SetPullResistor : Set GPIO Pull Resistor. | |
int32_t(* | SetEventTrigger )(ARM_GPIO_Pin_t pin, ARM_GPIO_EVENT_TRIGGER trigger) |
Pointer to ARM_GPIO_SetEventTrigger : Set GPIO Event Trigger. | |
void(* | SetOutput )(ARM_GPIO_Pin_t pin, uint32_t val) |
Pointer to ARM_GPIO_SetOutput : Set GPIO Output Level. | |
uint32_t(* | GetInput )(ARM_GPIO_Pin_t pin) |
Pointer to ARM_GPIO_GetInput : Get GPIO Input Level. | |
int32_t(* Setup) (ARM_GPIO_Pin_t pin, ARM_GPIO_SignalEvent_t cb_event) |
Pointer to ARM_GPIO_Setup : Setup GPIO Interface.
int32_t(* SetDirection) (ARM_GPIO_Pin_t pin, ARM_GPIO_DIRECTION direction) |
Pointer to ARM_GPIO_SetDirection : Set GPIO Direction.
int32_t(* SetOutputMode) (ARM_GPIO_Pin_t pin, ARM_GPIO_OUTPUT_MODE mode) |
Pointer to ARM_GPIO_SetOutputMode : Set GPIO Output Mode.
int32_t(* SetPullResistor) (ARM_GPIO_Pin_t pin, ARM_GPIO_PULL_RESISTOR resistor) |
Pointer to ARM_GPIO_SetPullResistor : Set GPIO Pull Resistor.
int32_t(* SetEventTrigger) (ARM_GPIO_Pin_t pin, ARM_GPIO_EVENT_TRIGGER trigger) |
Pointer to ARM_GPIO_SetEventTrigger : Set GPIO Event Trigger.
void(* SetOutput) (ARM_GPIO_Pin_t pin, uint32_t val) |
Pointer to ARM_GPIO_SetOutput : Set GPIO Output Level.
uint32_t(* GetInput) (ARM_GPIO_Pin_t pin) |
Pointer to ARM_GPIO_GetInput : Get GPIO Input Level.
ARM_GPIO_SignalEvent_t |
enum ARM_GPIO_DIRECTION |
enum ARM_GPIO_OUTPUT_MODE |
int32_t ARM_GPIO_Setup | ( | ARM_GPIO_Pin_t | pin, |
ARM_GPIO_SignalEvent_t | cb_event | ||
) |
Setup GPIO Interface.
[in] | pin | GPIO Pin |
[in] | cb_event | Pointer to ARM_GPIO_SignalEvent |
The function ARM_GPIO_Setup sets-up the specified pin as GPIO with default configuration. Pin is configured as input without pull-resistor and without event trigger.
The parameter cb_event specifies a pointer to the ARM_GPIO_SignalEvent callback function to register. Use a NULL pointer when no callback events are required or to deregister a callback function.
int32_t ARM_GPIO_SetDirection | ( | ARM_GPIO_Pin_t | pin, |
ARM_GPIO_DIRECTION | direction | ||
) |
Set GPIO Direction.
[in] | pin | GPIO Pin |
[in] | direction | ARM_GPIO_DIRECTION |
The function ARM_GPIO_SetDirection configures the direction of the specified pin.
Direction is specified with parameter direction:
int32_t ARM_GPIO_SetOutputMode | ( | ARM_GPIO_Pin_t | pin, |
ARM_GPIO_OUTPUT_MODE | mode | ||
) |
Set GPIO Output Mode.
[in] | pin | GPIO Pin |
[in] | mode | ARM_GPIO_OUTPUT_MODE |
The function ARM_GPIO_SetOutputMode configures the output mode of the specified pin.
Output mode is specified with parameter mode:
int32_t ARM_GPIO_SetPullResistor | ( | ARM_GPIO_Pin_t | pin, |
ARM_GPIO_PULL_RESISTOR | resistor | ||
) |
Set GPIO Pull Resistor.
[in] | pin | GPIO Pin |
[in] | resistor | ARM_GPIO_PULL_RESISTOR |
The function ARM_GPIO_SetPullResistor configures the pull resistor of the specified pin.
Pull resistor is specified with parameter resistor:
int32_t ARM_GPIO_SetEventTrigger | ( | ARM_GPIO_Pin_t | pin, |
ARM_GPIO_EVENT_TRIGGER | trigger | ||
) |
Set GPIO Event Trigger.
[in] | pin | GPIO Pin |
[in] | trigger | ARM_GPIO_EVENT_TRIGGER |
The function ARM_GPIO_SetEventTrigger configures the event trigger of the specified pin.
Event trigger is specified with parameter trigger:
void ARM_GPIO_SetOutput | ( | ARM_GPIO_Pin_t | pin, |
uint32_t | val | ||
) |
Set GPIO Output Level.
[in] | pin | GPIO Pin |
[in] | val | GPIO Pin Level (0 or 1) |
The function ARM_GPIO_SetOutput sets the level of the specified pin defined as output to the value specified by val.
uint32_t ARM_GPIO_GetInput | ( | ARM_GPIO_Pin_t | pin | ) |
Get GPIO Input Level.
[in] | pin | GPIO Pin |
The function ARM_GPIO_GetInput reads the level of the specified pin.
void ARM_GPIO_SignalEvent | ( | ARM_GPIO_Pin_t | pin, |
uint32_t | event | ||
) |
Signal GPIO Events.
[in] | pin | GPIO Pin on which event occurred |
[in] | event | GPIO Events notification mask |
The function ARM_GPIO_SignalEvent is a callback functions registered by the function ARM_GPIO_Setup. It is called by the GPIO driver to notify the application about GPIO Events occurred during operation.
The parameter pin indicates on which pin the event occurred and parameter event indicates one or more events that occurred.
The following events can be generated:
Parameter event | Bit | Description |
---|---|---|
ARM_GPIO_EVENT_RISING_EDGE | 0 | Occurs when rising-edge is detected on the indicated pin. |
ARM_GPIO_EVENT_FALLING_EDGE | 1 | Occurs when falling-edge is detected on the indicated pin. |
ARM_GPIO_EVENT_EITHER_EDGE | 2 | Occurs when either edge is detected on the indicated pin when trigger is configured as ARM_GPIO_TRIGGER_EITHER_EDGE and hardware is not able to distinguish between rising and falling edge. |