MKMxxZxxACxx5 Bare Metal Software Drivers  R4.1.6
Reference Manual
GPIO Pin Control

This example shows typical use of the General-Purpose Input/Output (GPIO) module for pin control and interrupt generation. The example installs the callback function port_callback which services any falling edge interrupts that occurs on the PTD0 pin. When an interrupt occurs, the states of PTJ3 and PTJ4 pins, configured in an output mode, toggle. On TWR-KM34Z75M board the PTD0 pin is connected to SW2 push button and PTJ3 and PTJ4 are connected LED1 and LED2, respectively.

Source code:
/******************************************************************************
* (c) Copyright 2010-2015, Freescale Semiconductor Inc.
* ALL RIGHTS RESERVED.
******************************************************************************
* gpio_test.c
******************************************************************************/
#include "drivers.h"
/* LEDs definition */
#define LED1 PIN5 /* PTE5 */
#define LED2 PIN1 /* PTD1 */
#define BTN1 PIN0 /* PTD0 */
/* Callback function declaration */
static void port_callback(PORT_CALLBACK_SRC src, uint8 pin);
void main (void)
{
GPIO_Init (GPIOD, GPIO_INP_MODE, BTN1);
PORT_InstallCallback (PRI_LVL3,port_callback);
while(1);
}
/* Callback function definition */
static void port_callback(PORT_CALLBACK_SRC src, uint8 pin)
{
if (src == PORTD_CALLBACK)
{
if (pin == BTN1)
{
GPIO_Tgl (GPIOE, LED1); /* standard access via peripheral bridge */
GPIO_Tgl (FGPIOD, LED2); /* single cycle direct access via IOPORT */
}
}
}
Toolchain support:
IAR EWARM 7.40.7CodeWarrior 10.6KEIL uVision 5.15CrossWorks 3.6ATOLLIC TrueStudio 5.3.0Kinetis Design Studio 3.0.0