CMSIS-Driver  
Peripheral Interface for Middleware and Application Code
 
Loading...
Searching...
No Matches
GPIO Interface

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.
 

Description

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.

#include "Driver_GPIO.h"
/* GPIO driver instance */
extern ARM_DRIVER_GPIO Driver_GPIO0;
static ARM_DRIVER_GPIO *GPIOdrv = &Driver_GPIO0;
/* Pin mapping */
#define GPIO_PIN0 0U
#define GPIO_PIN1 1U
#define GPIO_PIN2 2U
#define GPIO_PIN3 3U
/* GPIO Signal Event callback */
static void GPIO_SignalEvent (ARM_GPIO_Pin_t pin, uint32_t event) {
switch (pin) {
case GPIO_PIN1:
/* Events on pin GPIO_PIN1 */
/* Rising-edge detected */
}
/* Falling-edge detected */
}
break;
}
}
/* Get GPIO Input 0 */
uint32_t GPIO_GetInput0 (void) {
return (GPIOdrv->GetInput(GPIO_PIN0));
}
/* Get GPIO Input 1 */
uint32_t GPIO_GetInput1 (void) {
return (GPIOdrv->GetInput(GPIO_PIN1));
}
/* Set GPIO Output Pin 2 */
void GPIO_SetOutput2 (uint32_t val) {
GPIOdrv->SetOutput(GPIO_PIN2, val);
}
/* Set GPIO Output Pin 3 */
void GPIO_SetOutput3 (uint32_t val) {
GPIOdrv->SetOutput(GPIO_PIN3, val);
}
/* Setup GPIO pins */
void GPIO_Setup (void) {
/* Pin GPIO_PIN0: Input */
GPIOdrv->Setup (GPIO_PIN0, NULL);
GPIOdrv->SetDirection (GPIO_PIN0, ARM_GPIO_INPUT);
/* Pin GPIO_PIN1: Input with trigger on rising and falling edge */
GPIOdrv->Setup (GPIO_PIN1, GPIO_SignalEvent);
GPIOdrv->SetDirection (GPIO_PIN1, ARM_GPIO_INPUT);
/* Pin GPIO_PIN2: Output push-pull (initial level 0) */
GPIOdrv->Setup (GPIO_PIN2, NULL);
GPIOdrv->SetOutput (GPIO_PIN2, 0U);
GPIOdrv->SetDirection (GPIO_PIN2, ARM_GPIO_OUTPUT);
/* Pin GPIO_PIN3: Output open-drain with pull-up resistor (initial level 1) */
GPIOdrv->Setup (GPIO_PIN3, NULL);
GPIOdrv->SetPullResistor(GPIO_PIN3, ARM_GPIO_PULL_UP);
GPIOdrv->SetOutputMode (GPIO_PIN3, ARM_GPIO_OPEN_DRAIN);
GPIOdrv->SetOutput (GPIO_PIN3, 1U);
GPIOdrv->SetDirection (GPIO_PIN3, ARM_GPIO_OUTPUT);
}
uint32_t ARM_GPIO_Pin_t
GPIO Pin.
Definition: Driver_GPIO.h:38
@ ARM_GPIO_TRIGGER_EITHER_EDGE
Either edge (rising and falling)
Definition: Driver_GPIO.h:72
@ ARM_GPIO_OPEN_DRAIN
Open-drain.
Definition: Driver_GPIO.h:53
@ ARM_GPIO_PULL_UP
Pull-up.
Definition: Driver_GPIO.h:61
@ ARM_GPIO_INPUT
Input (default)
Definition: Driver_GPIO.h:44
@ ARM_GPIO_OUTPUT
Output.
Definition: Driver_GPIO.h:45
#define ARM_GPIO_EVENT_RISING_EDGE
Rising-edge detected.
#define ARM_GPIO_EVENT_FALLING_EDGE
Falling-edge detected.
int32_t(* Setup)(ARM_GPIO_Pin_t pin, ARM_GPIO_SignalEvent_t cb_event)
Pointer to ARM_GPIO_Setup : Setup GPIO Interface.
Definition: Driver_GPIO.h:141
int32_t(* SetPullResistor)(ARM_GPIO_Pin_t pin, ARM_GPIO_PULL_RESISTOR resistor)
Pointer to ARM_GPIO_SetPullResistor : Set GPIO Pull Resistor.
Definition: Driver_GPIO.h:144
int32_t(* SetDirection)(ARM_GPIO_Pin_t pin, ARM_GPIO_DIRECTION direction)
Pointer to ARM_GPIO_SetDirection : Set GPIO Direction.
Definition: Driver_GPIO.h:142
int32_t(* SetEventTrigger)(ARM_GPIO_Pin_t pin, ARM_GPIO_EVENT_TRIGGER trigger)
Pointer to ARM_GPIO_SetEventTrigger : Set GPIO Event Trigger.
Definition: Driver_GPIO.h:145
uint32_t(* GetInput)(ARM_GPIO_Pin_t pin)
Pointer to ARM_GPIO_GetInput : Get GPIO Input Level.
Definition: Driver_GPIO.h:147
void(* SetOutput)(ARM_GPIO_Pin_t pin, uint32_t val)
Pointer to ARM_GPIO_SetOutput : Set GPIO Output Level.
Definition: Driver_GPIO.h:146
int32_t(* SetOutputMode)(ARM_GPIO_Pin_t pin, ARM_GPIO_OUTPUT_MODE mode)
Pointer to ARM_GPIO_SetOutputMode : Set GPIO Output Mode.
Definition: Driver_GPIO.h:143
Access structure of the GPIO Driver.
Definition: Driver_GPIO.h:140

Data Structure Documentation

◆ ARM_DRIVER_GPIO

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:

  • Driver_GPIO0 is the name of the access struct of the first instance (no. 0).
  • Driver_GPIO1 is the name of the access struct of the second instance (no. 1).

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.
 

Field Documentation

◆ Setup

int32_t(* Setup) (ARM_GPIO_Pin_t pin, ARM_GPIO_SignalEvent_t cb_event)

Pointer to ARM_GPIO_Setup : Setup GPIO Interface.

◆ SetDirection

int32_t(* SetDirection) (ARM_GPIO_Pin_t pin, ARM_GPIO_DIRECTION direction)

Pointer to ARM_GPIO_SetDirection : Set GPIO Direction.

◆ SetOutputMode

int32_t(* SetOutputMode) (ARM_GPIO_Pin_t pin, ARM_GPIO_OUTPUT_MODE mode)

Pointer to ARM_GPIO_SetOutputMode : Set GPIO Output Mode.

◆ SetPullResistor

int32_t(* SetPullResistor) (ARM_GPIO_Pin_t pin, ARM_GPIO_PULL_RESISTOR resistor)

Pointer to ARM_GPIO_SetPullResistor : Set GPIO Pull Resistor.

◆ SetEventTrigger

int32_t(* SetEventTrigger) (ARM_GPIO_Pin_t pin, ARM_GPIO_EVENT_TRIGGER trigger)

Pointer to ARM_GPIO_SetEventTrigger : Set GPIO Event Trigger.

◆ SetOutput

void(* SetOutput) (ARM_GPIO_Pin_t pin, uint32_t val)

Pointer to ARM_GPIO_SetOutput : Set GPIO Output Level.

◆ GetInput

uint32_t(* GetInput) (ARM_GPIO_Pin_t pin)

Pointer to ARM_GPIO_GetInput : Get GPIO Input Level.

Typedef Documentation

◆ ARM_GPIO_SignalEvent_t

ARM_GPIO_SignalEvent_t

Provides the typedef for the callback function ARM_GPIO_SignalEvent.

Parameter for:

Enumeration Type Documentation

◆ ARM_GPIO_DIRECTION

GPIO Direction.

Specifies values for setting the direction.

Parameter for:

Enumerator
ARM_GPIO_INPUT 

Input (default)

ARM_GPIO_OUTPUT 

Output.

◆ ARM_GPIO_OUTPUT_MODE

GPIO Output Mode.

Specifies values for setting the output mode.

Parameter for:

Enumerator
ARM_GPIO_PUSH_PULL 

Push-pull (default)

ARM_GPIO_OPEN_DRAIN 

Open-drain.

◆ ARM_GPIO_PULL_RESISTOR

GPIO Pull Resistor.

Specifies values for setting the pull resistor.

Parameter for:

Enumerator
ARM_GPIO_PULL_NONE 

None (default)

ARM_GPIO_PULL_UP 

Pull-up.

ARM_GPIO_PULL_DOWN 

Pull-down.

◆ ARM_GPIO_EVENT_TRIGGER

GPIO Event Trigger.

Specifies values for setting the event trigger.

Parameter for:

Enumerator
ARM_GPIO_TRIGGER_NONE 

None (default)

ARM_GPIO_TRIGGER_RISING_EDGE 

Rising-edge.

ARM_GPIO_TRIGGER_FALLING_EDGE 

Falling-edge.

ARM_GPIO_TRIGGER_EITHER_EDGE 

Either edge (rising and falling)

Function Documentation

◆ ARM_GPIO_Setup()

int32_t ARM_GPIO_Setup ( ARM_GPIO_Pin_t  pin,
ARM_GPIO_SignalEvent_t  cb_event 
)

Setup GPIO Interface.

Parameters
[in]pinGPIO Pin
[in]cb_eventPointer to ARM_GPIO_SignalEvent
Returns
Status Error Codes

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.

◆ ARM_GPIO_SetDirection()

int32_t ARM_GPIO_SetDirection ( ARM_GPIO_Pin_t  pin,
ARM_GPIO_DIRECTION  direction 
)

Set GPIO Direction.

Parameters
[in]pinGPIO Pin
[in]directionARM_GPIO_DIRECTION
Returns
Status Error Codes

The function ARM_GPIO_SetDirection configures the direction of the specified pin.

Direction is specified with parameter direction:

◆ ARM_GPIO_SetOutputMode()

int32_t ARM_GPIO_SetOutputMode ( ARM_GPIO_Pin_t  pin,
ARM_GPIO_OUTPUT_MODE  mode 
)

Set GPIO Output Mode.

Parameters
[in]pinGPIO Pin
[in]modeARM_GPIO_OUTPUT_MODE
Returns
Status Error Codes

The function ARM_GPIO_SetOutputMode configures the output mode of the specified pin.

Output mode is specified with parameter mode:

Note
Output mode is relevant only when the pin is configured as output.

◆ ARM_GPIO_SetPullResistor()

int32_t ARM_GPIO_SetPullResistor ( ARM_GPIO_Pin_t  pin,
ARM_GPIO_PULL_RESISTOR  resistor 
)

Set GPIO Pull Resistor.

Parameters
[in]pinGPIO Pin
[in]resistorARM_GPIO_PULL_RESISTOR
Returns
Status Error Codes

The function ARM_GPIO_SetPullResistor configures the pull resistor of the specified pin.

Pull resistor is specified with parameter resistor:

Note
Pull resistor applies to the pin regardless of pin direction.

◆ ARM_GPIO_SetEventTrigger()

int32_t ARM_GPIO_SetEventTrigger ( ARM_GPIO_Pin_t  pin,
ARM_GPIO_EVENT_TRIGGER  trigger 
)

Set GPIO Event Trigger.

Parameters
[in]pinGPIO Pin
[in]triggerARM_GPIO_EVENT_TRIGGER
Returns
Status Error Codes

The function ARM_GPIO_SetEventTrigger configures the event trigger of the specified pin.

Event trigger is specified with parameter trigger:

Note
To disable event trigger use trigger parameter ARM_GPIO_TRIGGER_NONE.

◆ ARM_GPIO_SetOutput()

void ARM_GPIO_SetOutput ( ARM_GPIO_Pin_t  pin,
uint32_t  val 
)

Set GPIO Output Level.

Parameters
[in]pinGPIO Pin
[in]valGPIO 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.

Note
When a pin is configured as input, the level is latched and will be driven once the pin is configured as output.

◆ ARM_GPIO_GetInput()

uint32_t ARM_GPIO_GetInput ( ARM_GPIO_Pin_t  pin)

Get GPIO Input Level.

Parameters
[in]pinGPIO Pin
Returns
GPIO Pin Level (0 or 1)

The function ARM_GPIO_GetInput reads the level of the specified pin.

◆ ARM_GPIO_SignalEvent()

void ARM_GPIO_SignalEvent ( ARM_GPIO_Pin_t  pin,
uint32_t  event 
)

Signal GPIO Events.

Parameters
[in]pinGPIO Pin on which event occurred
[in]eventGPIO 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.