Kinetis SDK v.2.0 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

Overview

The KSDK provides a peripheral driver for the General-Purpose Input/Output (GPIO) module of Kinetis devices.

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);

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 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...
 

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

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...
 

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, GPIOC, and so on.)
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, GPIOC, and so on.)
pinGPIO pin's 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, GPIOC, and so on.)
maskGPIO pins' numbers macro
static void GPIO_ClearPinsOutput ( GPIO_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
maskGPIO pins' numbers macro
static void GPIO_TogglePinsOutput ( GPIO_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
maskGPIO pins' numbers macro
static uint32_t GPIO_ReadPinInput ( GPIO_Type *  base,
uint32_t  pin 
)
inlinestatic
Parameters
baseGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
pinGPIO pin's number
Return values
GPIOport input value
  • 0: corresponding pin input low logic level.
  • 1: corresponding pin input high logic level.
uint32_t GPIO_GetPinsInterruptFlags ( GPIO_Type *  base)

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
baseGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
Return values
CurrentGPIO port interrupt status flag, for example, 0x00010001 means the pin 0 and 17 have the interrupt.
void GPIO_ClearPinsInterruptFlags ( GPIO_Type *  base,
uint32_t  mask 
)
Parameters
baseGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
maskGPIO pins' numbers macro