GPIO Peripheral driver
General-Purpose Input/Output (GPIO)
Collaboration diagram for GPIO Peripheral driver:

## Data Structures

struct | gpio_pin_config_t
| The GPIO pin configuration structure. More...

## Enumerations

enum | gpio_pin_direction_t { kGPIO_DigitalInput = 0U, kGPIO_DigitalOutput = 1U }
| GPIO direction definition. More...

## Configuration

Introduce the FGPIO feature. The FGPIO features are only support on some of kinetis chips. The FGPIO registers are aliased to the IOPORT interface. Accesses via the IOPORT interface occur in parallel with any instruction fetches and will therefore complete in a single cycle. This aliased Fast GPIO memory map is called FGPIO.
void | GPIO_PinInit (GPIO_Type *base, uint32_t pin, const gpio_pin_config_t *config)
| Initializes a GPIO pin used by the board. More...
void | FGPIO_PinInit (FGPIO_Type *base, uint32_t pin, const gpio_pin_config_t *config)
| Initializes a FGPIO pin used by the board. More...

## Output Operations

static void | GPIO_WritePinOutput (GPIO_Type *base, uint32_t pin, uint8_t output)
| Sets the output level of the multiple GPIO pins to the logic 1 or 0. More...
static void | GPIO_SetPinsOutput (GPIO_Type *base, uint32_t mask)
| Sets the output level of the multiple GPIO pins to the logic 1. More...
static void | GPIO_ClearPinsOutput (GPIO_Type *base, uint32_t mask)
| Sets the output level of the multiple GPIO pins to the logic 0. More...
static void | GPIO_TogglePinsOutput (GPIO_Type *base, uint32_t mask)
| Reverses current output logic of the multiple GPIO pins. More...
static void | FGPIO_WritePinOutput (FGPIO_Type *base, uint32_t pin, uint8_t output)
| Sets the output level of the multiple FGPIO pins to the logic 1 or 0. More...
static void | FGPIO_SetPinsOutput (FGPIO_Type *base, uint32_t mask)
| Sets the output level of the multiple FGPIO pins to the logic 1. More...
static void | FGPIO_ClearPinsOutput (FGPIO_Type *base, uint32_t mask)
| Sets the output level of the multiple FGPIO pins to the logic 0. More...
static void | FGPIO_TogglePinsOutput (FGPIO_Type *base, uint32_t mask)
| Reverses current output logic of the multiple FGPIO pins. More...

## Input Operations

static uint32_t | GPIO_ReadPinInput (GPIO_Type *base, uint32_t pin)
| Reads the current input value of the whole GPIO port. More...
static uint32_t | FGPIO_ReadPinInput (FGPIO_Type *base, uint32_t pin)
| Reads the current input value of the whole FGPIO port. More...

## Interrupt

uint32_t | GPIO_GetPinsInterruptFlags (GPIO_Type *base)
| Reads whole GPIO port interrupt status flag. More...
void | GPIO_ClearPinsInterruptFlags (GPIO_Type *base, uint32_t mask)
| Clears multiple GPIO pins' interrupt status flag. More...
uint32_t | FGPIO_GetPinsInterruptFlags (FGPIO_Type *base)
| Reads the whole FGPIO port interrupt status flag. More...
void | FGPIO_ClearPinsInterruptFlags (FGPIO_Type *base, uint32_t mask)
| Clears the multiple FGPIO pins' interrupt status flag. More...

## Usage Information

This section describes the programming interface of the GPIO Peripheral driver. The GPIO driver configures GPIO module and provides the functional interface to build the GPIO application.

# Function groups

## GPIO Configuration

This function group configures the the GPIO pin.

## GPIO Output Operations

This function group sets the GPIO pin output, such as write, set, clear, and toggle.

## GPIO Input Operations

This function reads the GPIO pin value.

## GPIO Interrupt

This function group checks or clears the GPIO pin interrupt.

# Typical use case

## Output Operation

/* Output pin configuration */
gpio_pin_config_t led_config =
{
kGpioDigitalOutput,
1,
};
/* Sets the configuration */
GPIO_PinInit(GPIO_LED, LED_PINNUM, &led_config);

## Input Operation

/* Input pin configuration */
PORT_SetPinInterruptConfig(BOARD_SW2_PORT, BOARD_SW2_GPIO_PIN, kPORT_InterruptFallingEdge);
NVIC_EnableIRQ(BOARD_SW2_IRQ);
gpio_pin_config_t sw1_config =
{
kGpioDigitalInput,
0,
};
/* Sets the input pin configuration */
GPIO_PinInit(GPIO_SW1, SW1_PINNUM, &sw1_config);

## Data Structure Documentation

struct gpio_pin_config_t

The GPIO pin configuration structure.

Every pin can only be configured as either output pin or input pin at a time. If configured as a input pin, then leave the outputConfig unused Note : In some cases, the corresponding port property should be configured in advance cwith the PORT_SetPinConfig()

Data Fields
uint8_t | outputLogic | Set default output logic, no use in input
gpio_pin_direction_t | pinDirection | gpio direction, input or output

## Enumeration Type Documentation

enum gpio_pin_direction_t

GPIO direction definition.

Enumerator
kGPIO_DigitalInput | Set current pin as digital input
kGPIO_DigitalOutput | Set current pin as digital output

## Function Documentation

void FGPIO_ClearPinsInterruptFlags | ( | FGPIO_Type * | base,
|  | uint32_t | mask
| ) |  |

Clears the multiple FGPIO pins' interrupt status flag.

Parameters

  base | FGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, etc.)
  mask | FGPIO pins' numbers macro

static void FGPIO_ClearPinsOutput | ( | FGPIO_Type * | base,
|  | uint32_t | mask
| ) |  |

inlinestatic

Sets the output level of the multiple FGPIO pins to the logic 0.

Parameters

  base | FGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, etc.)
  mask | FGPIO pins' numbers macro

uint32_t FGPIO_GetPinsInterruptFlags | ( | FGPIO_Type * | base | ) |

Reads the whole FGPIO port interrupt status flag.

If a pin is configured to generate the DMA request, the corresponding flag is cleared automatically at the completion of the requested DMA transfer. Otherwise, the flag remains set until a logic one is written to that flag. If configured for a level sensitive interrupt that remains asserted, the flag is set again immediately.

Parameters

  base | FGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, etc.)

Return values

  Current | FGPIO port interrupt status flags, for example, 0x00010001 means the pin 0 and 17 have the interrupt.

void FGPIO_PinInit | ( | FGPIO_Type * | base,
|  | uint32_t | pin,
|  | const gpio_pin_config_t * | config
| ) |  |

Initializes a FGPIO pin used by the board.

To initialize the FGPIO driver, define a pin configuration, either input or output, in the user file. Then, call the FGPIO_PinInit() function.

This is an example to define an input pin or output pin configuration:

// Define a digital input pin configuration,
gpio_pin_config_t config =
{
kGPIO_DigitalInput,
0,
}
//Define a digital output pin configuration,
gpio_pin_config_t config =
{
kGPIO_DigitalOutput,
0,
}

Parameters

  base | FGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, etc.)
  pin | FGPIO port pin number
  config | FGPIO pin configuration pointer

static uint32_t FGPIO_ReadPinInput | ( | FGPIO_Type * | base,
|  | uint32_t | pin
| ) |  |

inlinestatic

Reads the current input value of the whole FGPIO port.

Parameters

  base | FGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, etc.)
  pin | FGPIO pin's number

Return values

  FGPIO

  port input value
  - 0: corresponding pin input low logic level.
  - 1: corresponding pin input high logic level.

static void FGPIO_SetPinsOutput | ( | FGPIO_Type * | base,
|  | uint32_t | mask
| ) |  |

inlinestatic

Sets the output level of the multiple FGPIO pins to the logic 1.

Parameters

  base | FGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, etc.)
  mask | FGPIO pins' numbers macro

static void FGPIO_TogglePinsOutput | ( | FGPIO_Type * | base,
|  | uint32_t | mask
| ) |  |

inlinestatic

Reverses current output logic of the multiple FGPIO pins.

Parameters

  base | FGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, etc.)
  mask | FGPIO pins' numbers macro

static void FGPIO_WritePinOutput | ( | FGPIO_Type * | base,
|  | uint32_t | pin,
|  | uint8_t | output
| ) |  |

inlinestatic

Sets the output level of the multiple FGPIO pins to the logic 1 or 0.

Parameters

  base | FGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, etc.)
  pin | FGPIO pin's number

  output

  FGPIOpin output logic level.
  - 0: corresponding pin output low logic level.
  - 1: corresponding pin output high logic level.

void GPIO_ClearPinsInterruptFlags | ( | GPIO_Type * | base,
|  | uint32_t | mask
| ) |  |

Clears multiple GPIO pins' interrupt status flag.

Parameters

  base | GPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, etc.)
  mask | GPIO pins' numbers macro

static void GPIO_ClearPinsOutput | ( | GPIO_Type * | base,
|  | uint32_t | mask
| ) |  |

inlinestatic

Sets the output level of the multiple GPIO pins to the logic 0.

Parameters

  base | GPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, etc.)
  mask | GPIO pins' numbers macro

uint32_t GPIO_GetPinsInterruptFlags | ( | GPIO_Type * | base | ) |

Reads whole GPIO port interrupt status flag.

If a pin is configured to generate the DMA request, the corresponding flag is cleared automatically at the completion of the requested DMA transfer. Otherwise, the flag remains set until a logic one is written to that flag. If configured for a level sensitive interrupt that remains asserted, the flag is set again immediately.

Parameters

  base | GPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, etc.)

Return values

  Current | GPIO port interrupt status flag, for example, 0x00010001 means the pin 0 and 17 have the interrupt.

void GPIO_PinInit | ( | GPIO_Type * | base,
|  | uint32_t | pin,
|  | const gpio_pin_config_t * | config
| ) |  |

Initializes a GPIO pin used by the board.

To initialize the GPIO, define a pin configuration, either input or output, in the user file. Then, call the GPIO_PinInit() function.

This is an example to define an input pin or output pin configuration:

// Define a digital input pin configuration,
gpio_pin_config_t config =
{
kGPIO_DigitalInput,
0,
}
//Define a digital output pin configuration,
gpio_pin_config_t config =
{
kGPIO_DigitalOutput,
0,
}

Parameters

  base | GPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, etc.)
  pin | GPIO port pin number
  config | GPIO pin configuration pointer

static uint32_t GPIO_ReadPinInput | ( | GPIO_Type * | base,
|  | uint32_t | pin
| ) |  |

inlinestatic

Reads the current input value of the whole GPIO port.

Parameters

  base | GPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, etc.)
  pin | GPIO pin's number

Return values

  GPIO

  port input value
  - 0: corresponding pin input low logic level.
  - 1: corresponding pin input high logic level.

static void GPIO_SetPinsOutput | ( | GPIO_Type * | base,
|  | uint32_t | mask
| ) |  |

inlinestatic

Sets the output level of the multiple GPIO pins to the logic 1.

Parameters

  base | GPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, etc.)
  mask | GPIO pins' numbers macro

static void GPIO_TogglePinsOutput | ( | GPIO_Type * | base,
|  | uint32_t | mask
| ) |  |

inlinestatic

Reverses current output logic of the multiple GPIO pins.

Parameters

  base | GPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, etc.)
  mask | GPIO pins' numbers macro

static void GPIO_WritePinOutput | ( | GPIO_Type * | base,
|  | uint32_t | pin,
|  | uint8_t | output
| ) |  |

inlinestatic

Sets the output level of the multiple GPIO pins to the logic 1 or 0.

Parameters

  base | GPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, etc.)
  pin | GPIO pin's number

  output

  GPIO pin output logic level.
  - 0: corresponding pin output low logic level.
  - 1: corresponding pin output high logic level.