MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
GPIO: General Purpose I/O

Overview

The MCUXpresso SDK provides a peripheral driver for the General Purpose I/O (GPIO) module of MCUXpresso SDK devices.

Function groups

Initialization and deinitialization

The function GPIO_PinInit() initializes the GPIO with specified configuration.

Pin manipulation

The function GPIO_WritePinOutput() set output state of the selected GPIO pin. The function GPIO_ReadPinInput() read input value of the selected GPIO pin.

Port manipulation

The function GPIO_SetPinsOutput() sets the output level of selected GPIO pins to the logic 1. The function GPIO_ClearPinsOutput() sets the output level of selected GPIO pins to the logic 1. The function GPIO_TogglePinsOutput() reverse the output level of selected GPIO pins.

Typical use case

Example use of GPIO API.

int main(void)
{
/* Board pin, clock, debug console init */
BOARD_InitHardware();
/* Enable GPIO clock */
CLOCK_EnableClock(kCLOCK_Gpio);
/* Init output LED GPIO. */
GPIO_PinInit(BOARD_LED_GPIO, BOARD_LED_RED_GPIO_PIN, &(gpio_pin_config_t){kGPIO_DigitalOutput, 1U});
GPIO_PinInit(BOARD_LED_GPIO, BOARD_LED_GREEN_GPIO_PIN, &(gpio_pin_config_t){kGPIO_DigitalOutput, 1U});
GPIO_PinInit(BOARD_LED_GPIO, BOARD_LED_BLUE_GPIO_PIN, &(gpio_pin_config_t){kGPIO_DigitalOutput, 1U});
while (1)
{
GPIO_TogglePinsOutput(BOARD_LED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN);
delay(500000);
GPIO_TogglePinsOutput(BOARD_LED_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN);
delay(500000);
GPIO_TogglePinsOutput(BOARD_LED_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN);
delay(500000);
}
}

Files

file  fsl_gpio.h
 

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
}
 QN GPIO direction definition. More...
 

Driver version

#define FSL_GPIO_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))
 QN GPIO driver version 2.0.0. More...
 

GPIO Configuration

void GPIO_PinInit (GPIO_Type *base, uint32_t pin, const gpio_pin_config_t *config)
 Initializes a GPIO pin used by the board. More...
 

GPIO Output Operations

static void GPIO_WritePinOutput (GPIO_Type *base, uint32_t pin, uint8_t output)
 Sets the output level of a GPIO pin 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...
 

GPIO Input Operations

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

GPIO Interrupt

static uint32_t GPIO_GetPinsInterruptFlags (GPIO_Type *base)
 Reads whole GPIO port interrupt status flag. More...
 
static void GPIO_ClearPinsInterruptFlags (GPIO_Type *base, uint32_t mask)
 Clears multiple GPIO pin interrupt status flag. More...
 
static void GPIO_SetHighLevelInterrupt (GPIO_Type *base, uint32_t mask)
 Changes the interrupt type for the specified pin to a high level interrupt. More...
 
static void GPIO_SetRisingEdgeInterrupt (GPIO_Type *base, uint32_t mask)
 Changes the interrupt type for the specified pin to a rising edge interrupt. More...
 
static void GPIO_SetLowLevelInterrupt (GPIO_Type *base, uint32_t mask)
 Changes the interrupt type for the specified pin to a low level interrupt. More...
 
static void GPIO_SetFallingEdgeInterrupt (GPIO_Type *base, uint32_t mask)
 Changes the interrupt type for the specified pin to a falling edge interrupt. More...
 
static void GPIO_EnableInterrupt (GPIO_Type *base, uint32_t mask)
 Enable GPIO pin interrupt. More...
 
static void GPIO_DisableInterrupt (GPIO_Type *base, uint32_t mask)
 Disable GPIO pin interrupt. More...
 

Data Structure Documentation

struct gpio_pin_config_t

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 outputLogic unused

Data Fields

gpio_pin_direction_t pinDirection
 GPIO direction, input or output.
 
uint8_t outputLogic
 Set default output logic, no use in input.
 

Macro Definition Documentation

#define FSL_GPIO_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))

Enumeration Type Documentation

Enumerator
kGPIO_DigitalInput 

Set current pin as digital input.

kGPIO_DigitalOutput 

Set current pin as digital output.

Function Documentation

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

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,
* {
* 0,
* }
* //Define a digital output pin configuration,
* {
* 0,
* }
*
Parameters
baseGPIO peripheral base pointer(GPIOA, GPIOB.)
pinGPIO port pin number
configGPIO pin configuration pointer
static void GPIO_WritePinOutput ( GPIO_Type *  base,
uint32_t  pin,
uint8_t  output 
)
inlinestatic
Parameters
baseGPIO peripheral base pointer(GPIOA, GPIOB.)
pinGPIO pin number
outputGPIO pin output logic level.
  • 0: corresponding pin output low-logic level.
  • 1: corresponding pin output high-logic level.
static void GPIO_SetPinsOutput ( GPIO_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseGPIO peripheral base pointer(GPIOA, GPIOB.)
maskGPIO pin number macro
static void GPIO_ClearPinsOutput ( GPIO_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseGPIO peripheral base pointer(GPIOA, GPIOB.)
maskGPIO pin number macro
static void GPIO_TogglePinsOutput ( GPIO_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseGPIO peripheral base pointer(GPIOA, GPIOB.)
maskGPIO pin number macro
static uint32_t GPIO_ReadPinInput ( GPIO_Type *  base,
uint32_t  pin 
)
inlinestatic
Parameters
baseGPIO peripheral base pointer(GPIOA, GPIOB.)
pinGPIO pin number
Return values
GPIOport input value
  • 0: corresponding pin input low-logic level.
  • 1: corresponding pin input high-logic level.
static uint32_t GPIO_GetPinsInterruptFlags ( GPIO_Type *  base)
inlinestatic

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
baseGPIO peripheral base pointer(GPIOA, GPIOB.)
Return values
CurrentGPIO port interrupt status flag, for example, 0x00010001 means the pin 0 and 17 have the interrupt.
static void GPIO_ClearPinsInterruptFlags ( GPIO_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseGPIO peripheral base pointer(GPIOA, GPIOB.)
maskGPIO pin number macro
static void GPIO_SetHighLevelInterrupt ( GPIO_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseGPIO peripheral base pointer(GPIOA, GPIOB.)
maskGPIO pin number macro
static void GPIO_SetRisingEdgeInterrupt ( GPIO_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseGPIO peripheral base pointer(GPIOA, GPIOB.)
maskGPIO pin number macro
static void GPIO_SetLowLevelInterrupt ( GPIO_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseGPIO peripheral base pointer(GPIOA, GPIOB.)
maskGPIO pin number macro
static void GPIO_SetFallingEdgeInterrupt ( GPIO_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseGPIO peripheral base pointer(GPIOA, GPIOB.)
maskGPIO pin number macro
static void GPIO_EnableInterrupt ( GPIO_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseGPIO peripheral base pointer(GPIOA, GPIOB.)
maskGPIO pin number macro
static void GPIO_DisableInterrupt ( GPIO_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseGPIO peripheral base pointer(GPIOA, GPIOB.)
maskGPIO pin number macro