GPIO
====

Introduction
------------

GPIO module allows application to manage General Purpose I/O  instances
and pins via simple portable APIs. Because of its simplicity, APIs are
pin based and does not follow model of other drivers inside PDK which
requires handle abstraction.

.. rubric:: Modes of Operation
   :name: gpio-modes-of-operation

Following modes of operations are supported
**Input or Output**
Each gpio pin can be configured as either input: GPIO_CFG_INPUT or
output: GPIO_CFG_OUTPUT. If it is configured as an output then pin
level can be additionally configured

**Interrupt support**
Each gpio pin can be configured to generate interrupts based on event
type GPIO_CFG_IN_INT_XXX configuration. To generate interrupt, gpio
pin has to be configured as input pin.

.. rubric:: Driver Configuration
   :name: gpio-driver-configuration

.. rubric:: **Board Specific Configuration**
   :name: gpio-board-specific-configuration

All board specific configurations like enabling clock and pin-mux are
required before calling any driver APIs. By default Board_Init() API
available under board module supports all initialization sequence for TI
supported EVMs. In addition it initializes UART instance for
Console/STDIO. Refer `PDK Board Support <../board/board_support.html#board-support>`__ 
for additional details.

.. rubric:: **GPIO Configuration Structure**
   :name: gpio-configuration-structure

GPIO_soc.c binds driver with hardware attributes on the board.
Hardware attributes includes base address, interrupt number etc. GPIO
pin behavior can be configured statically, or alternatively
dynamically during runtime.

GPIO_init () API triggers all static configuration information available
through hardware attributes. Once initialization is complete additional
APIs can be used to configure and access pins.

User Interface
--------------

For details about individual fields of this library structure, see the
PDK doxygen documentation

APIs
^^^^

API reference for Application:

::

    #include <ti/drv/gpio/GPIO.h>

Below sequence indicates API calling sequence for a simple use case of
LED toggling

::

    ...
    Board_init(boardCfg);
    GPIO_init();
    While(1)
    {
    GPIO_write(Board_LED1, GPIO_PIN_VAL_HIGH);
    Delay();
    GPIO_write(Board_LED1, GPIO_PIN_VAL_LOW);
    Delay();
    }

Application
-----------

Examples
^^^^^^^^

Refer SDK Release Note for GPIO support across different EVMs.

+-------------------+-----------------------+-----------------------+---------------------+---------------------+
|       Name        |      Description      || Expected Results     | SoC Supported       | Build Type          |
+===================+=======================+=======================+=====================+=====================+
| GPIO_LedBlink     | Simple example        || Following LED        |    AM335x,          | CCS project         |
|                   | demonstrating LED     | blinks based on EVM   |    AM437x,          |                     |
|                   | Toggling              | being used.           |    AM571x,          |                     |
|                   |                       |                       |    AM572x,          |                     |
|                   |                       || **AM335x             |    AM574x,          |                     |
|                   |                       | ICEv2**:              |    k2g,             |                     |
|                   |                       | USER  LED 1           |    k2hk,            |                     |
|                   |                       |                       |    k2l,             |                     |
|                   |                       || **AM437x             |    k2e,             |                     |
|                   |                       | EVM**:                |    c6657,           |                     |
|                   |                       | USER  LED 1           |    c6678,           |                     |
|                   |                       |                       |    omapl137,        |                     |
|                   |                       || **AM572x IDK** :     |                     |                     |
|                   |                       | STATUS LED 1 Yellow   +---------------------+---------------------+
|                   |                       | **AM572x GP           |    am65xx           | makefile            |
|                   |                       | EVM** : USER LED1     |    j721e            |                     |
|                   |                       | **AM574x IDK** :      |    tpr12            |                     |
|                   |                       | STATUS LED 1 Yellow   |    j7200            |                     |
|                   |                       | **AM572x GP           |    am64x            |                     |
|                   |                       | EVM** : USER LED1     |                     |                     |
|                   |                       | **AM571x IDK** :      |                     |                     |
|                   |                       | Industrial LED 3      |                     |                     |
|                   |                       | Red                   |                     |                     |
|                   |                       |                       |                     |                     |
|                   |                       || **K2H EVM:**         |                     |                     |
|                   |                       | USER LED 2 Blue       |                     |                     |
|                   |                       |                       |                     |                     |
|                   |                       || **K2E EVM:**         |                     |                     |
|                   |                       | USER LED 1 Blue       |                     |                     |
|                   |                       |                       |                     |                     |
|                   |                       || **K2G EVM:**         |                     |                     |
|                   |                       | USER LED 1 Yellow     |                     |                     |
|                   |                       |                       |                     |                     |
|                   |                       || **AM65xx EVM:**      |                     |                     |
|                   |                       | USER LD16, LD17       |                     |                     |
|                   |                       |                       |                     |                     |
|                   |                       || **J721E EVM:**       |                     |                     |
|                   |                       | USER LED 1            |                     |                     |
|                   |                       |                       |                     |                     |
|                   |                       || **J7200 EVM:**       |                     |                     |
|                   |                       | USER LED 1            |                     |                     |
|                   |                       |                       |                     |                     |
|                   |                       || **AM64x EVM:**       |                     |                     |
|                   |                       | USER LED 1            |                     |                     |
|                   |                       |                       |                     |                     |
|                   |                       |                       |                     |                     |
+-------------------+-----------------------+-----------------------+---------------------+---------------------+

.. ifconfig:: CONFIG_family in ('k2l','c6678', 'c6657')

   .. note::

      There are no user mode LEDs directly connected to GPIO pins on K2L, C6678 and C6657 EVMs.

FAQ
---

.. ifconfig:: CONFIG_family in ('am57x')

   **Is there any example using GPIO as input**

   Please refer to `RTOS Customization: using an external input to trigger an interrupt
   on AM57x <index_how_to_guides.html#rtos-customization-using-an-external-input-to-trigger-an-interrupt-on-am57x>`_ for details.
