AM261x MCU+ SDK: APIs for GPIO

| AM261x MCU+ SDK 26.00.00 |

Files | Functions | Macros
APIs for GPIO
APIs for SOC Specific Device Drivers

## Introduction

This module contains APIs to program and use the GPIO module.

## Files
file | gpio/v0/gpio.h
| GPIO Driver API/interface file.

## Functions
void | GPIO_setDirMode (uint32_t baseAddr, uint32_t pinNum, uint32_t pinDir)
| This API configures the direction of a specified GPIO pin as being either input or output. More...
static void | GPIO_pinWriteHigh (uint32_t baseAddr, uint32_t pinNum)
| This API drives an output GPIO pin to a logic HIGH state. More...
static void | GPIO_pinWriteLow (uint32_t baseAddr, uint32_t pinNum)
| This API drives an output GPIO pin to a logic LOW state. More...
uint32_t | GPIO_pinRead (uint32_t baseAddr, uint32_t pinNum)
| This API reads the logic level(value) on a specified GPIO pin. More...
uint32_t | GPIO_pinOutValueRead (uint32_t baseAddr, uint32_t pinNum)
| This API determines the output logic level(value) on a specified GPIO pin. More...
void | GPIO_setTrigType (uint32_t baseAddr, uint32_t pinNum, uint32_t trigType)
| This API configures the trigger type for a specified input GPIO pin. More...
void | GPIO_bankIntrEnable (uint32_t baseAddr, uint32_t bankNum)
| This API enables the bank interrupt. This has to be called after setting all the GPIO pin triggers of a bank to get interrupt. More...
void | GPIO_bankIntrDisable (uint32_t baseAddr, uint32_t bankNum)
| This API disables the bank interrupt. More...
static uint32_t | GPIO_getIntrStatus (uint32_t baseAddr, uint32_t pinNum)
| This API determines the enabled interrupt status of a specified pin. More...
static void | GPIO_clearIntrStatus (uint32_t baseAddr, uint32_t pinNum)
| This API clears the enabled interrupt status of a specified GPIO pin. More...
static uint32_t | GPIO_getBankIntrStatus (uint32_t baseAddr, uint32_t bankNum)
| This API returns the interrupt status of the specified bank. More...
static void | GPIO_clearBankIntrStatus (uint32_t baseAddr, uint32_t bankNum, uint32_t intrStatus)
| This API clears the interrupt status of the specified bank. More...

## Macros
#define | GPIO_MAX_BANKS (9U)
| Maximum number of banks per instance/module. More...
#define | GPIO_MAX_PIN_PER_BANK (16U)
| Maximum number of pins per bank. More...
#define | GPIO_MAX_PIN_PER_INSTANCE (GPIO_MAX_BANKS * GPIO_MAX_PIN_PER_BANK)
| Maximum number of pins per instance/module. More...
#define | GPIO_BANKS_PER_REG (2U)
| Number of banks per register. More...
#define | GPIO_PINS_PER_REG (GPIO_BANKS_PER_REG * GPIO_MAX_PIN_PER_BANK)
| Number of pins per register - 32 pins. More...
#define | GPIO_PINS_PER_REG_SHIFT (5U)
| Number of pins per register - shift value - used instead of divide operator. More...
#define | GPIO_PINS_PER_BANK_SHIFT (4U)
| Number of pins per bank - shift value - used instead of divide operator. More...
#define | GPIO_GET_BANK_INDEX(pinNum) (((uint32_t) pinNum) >> GPIO_PINS_PER_BANK_SHIFT)
| Returns the bank index based on pin number. More...
#define | GPIO_GET_REG_INDEX(pinNum) (((uint32_t) pinNum) >> GPIO_PINS_PER_REG_SHIFT)
| Returns the register index based on pin number. More...
#define | GPIO_GET_BIT_POS(pinNum) (pinNum - ((GPIO_GET_REG_INDEX(pinNum)) << GPIO_PINS_PER_REG_SHIFT))
| Returns the bit position within a register based on pin number. More...
#define | GPIO_GET_BIT_MASK(pinNum) (((uint32_t) 1U) << GPIO_GET_BIT_POS(pinNum))
| Returns the bit mask within a register based on pin number. More...
#define | GPIO_GET_BANK_BIT_POS(pinNum) (pinNum - ((GPIO_GET_BANK_INDEX(pinNum)) << GPIO_PINS_PER_BANK_SHIFT))
| Returns the bit position within a bank based on pin number. More...
#define | GPIO_GET_BANK_BIT_MASK(pinNum) (((uint32_t) 1U) << GPIO_GET_BANK_BIT_POS(pinNum))
| Returns the bit mask within a bank based on pin number. More...

## GPIO Pin Value
#define | GPIO_PIN_LOW (0U)
| GPIO pin is at logic low. More...
#define | GPIO_PIN_HIGH (1U)
| GPIO pin is at logic high. More...

## GPIO Direction
#define | GPIO_DIRECTION_OUTPUT (0U)
#define | GPIO_DIRECTION_INPUT (1U)

## GPIO Trigger Type
#define | GPIO_TRIG_TYPE_NONE (0U)
| No interrupt request on either rising or falling edges on the pin. More...
#define | GPIO_TRIG_TYPE_RISE_EDGE (1U)
| Interrupt request on occurrence of a rising edge on the input pin. More...
#define | GPIO_TRIG_TYPE_FALL_EDGE (2U)
| Interrupt request on occurrence of a falling edge on the input pin. More...
#define | GPIO_TRIG_TYPE_BOTH_EDGE (3U)
| Interrupt request on occurrence of a rising/falling edge on the input pin. More...

## Macro Definition Documentation

## ◆ GPIO_PIN_LOW

#define GPIO_PIN_LOW (0U)

GPIO pin is at logic low.

## ◆ GPIO_PIN_HIGH

#define GPIO_PIN_HIGH (1U)

GPIO pin is at logic high.

## ◆ GPIO_DIRECTION_OUTPUT

#define GPIO_DIRECTION_OUTPUT (0U)

## ◆ GPIO_DIRECTION_INPUT

#define GPIO_DIRECTION_INPUT (1U)

## ◆ GPIO_TRIG_TYPE_NONE

#define GPIO_TRIG_TYPE_NONE (0U)

No interrupt request on either rising or falling edges on the pin.

## ◆ GPIO_TRIG_TYPE_RISE_EDGE

#define GPIO_TRIG_TYPE_RISE_EDGE (1U)

Interrupt request on occurrence of a rising edge on the input pin.

## ◆ GPIO_TRIG_TYPE_FALL_EDGE

#define GPIO_TRIG_TYPE_FALL_EDGE (2U)

Interrupt request on occurrence of a falling edge on the input pin.

## ◆ GPIO_TRIG_TYPE_BOTH_EDGE

#define GPIO_TRIG_TYPE_BOTH_EDGE (3U)

Interrupt request on occurrence of a rising/falling edge on the input pin.

## ◆ GPIO_MAX_BANKS

#define GPIO_MAX_BANKS (9U)

Maximum number of banks per instance/module.

## ◆ GPIO_MAX_PIN_PER_BANK

#define GPIO_MAX_PIN_PER_BANK (16U)

Maximum number of pins per bank.

## ◆ GPIO_MAX_PIN_PER_INSTANCE

#define GPIO_MAX_PIN_PER_INSTANCE (GPIO_MAX_BANKS * GPIO_MAX_PIN_PER_BANK)

Maximum number of pins per instance/module.

## ◆ GPIO_BANKS_PER_REG

#define GPIO_BANKS_PER_REG (2U)

Number of banks per register.

## ◆ GPIO_PINS_PER_REG

#define GPIO_PINS_PER_REG (GPIO_BANKS_PER_REG * GPIO_MAX_PIN_PER_BANK)

Number of pins per register - 32 pins.

## ◆ GPIO_PINS_PER_REG_SHIFT

#define GPIO_PINS_PER_REG_SHIFT (5U)

Number of pins per register - shift value - used instead of divide operator.

## ◆ GPIO_PINS_PER_BANK_SHIFT

#define GPIO_PINS_PER_BANK_SHIFT (4U)

Number of pins per bank - shift value - used instead of divide operator.

## ◆ GPIO_GET_BANK_INDEX

#define GPIO_GET_BANK_INDEX | ( |  | pinNum | ) | (((uint32_t) pinNum) >> GPIO_PINS_PER_BANK_SHIFT)

Returns the bank index based on pin number.

## ◆ GPIO_GET_REG_INDEX

#define GPIO_GET_REG_INDEX | ( |  | pinNum | ) | (((uint32_t) pinNum) >> GPIO_PINS_PER_REG_SHIFT)

Returns the register index based on pin number.

## ◆ GPIO_GET_BIT_POS

#define GPIO_GET_BIT_POS | ( |  | pinNum | ) | (pinNum - ((GPIO_GET_REG_INDEX(pinNum)) << GPIO_PINS_PER_REG_SHIFT))

Returns the bit position within a register based on pin number.

## ◆ GPIO_GET_BIT_MASK

#define GPIO_GET_BIT_MASK | ( |  | pinNum | ) | (((uint32_t) 1U) << GPIO_GET_BIT_POS(pinNum))

Returns the bit mask within a register based on pin number.

## ◆ GPIO_GET_BANK_BIT_POS

#define GPIO_GET_BANK_BIT_POS | ( |  | pinNum | ) | (pinNum - ((GPIO_GET_BANK_INDEX(pinNum)) << GPIO_PINS_PER_BANK_SHIFT))

Returns the bit position within a bank based on pin number.

## ◆ GPIO_GET_BANK_BIT_MASK

#define GPIO_GET_BANK_BIT_MASK | ( |  | pinNum | ) | (((uint32_t) 1U) << GPIO_GET_BANK_BIT_POS(pinNum))

Returns the bit mask within a bank based on pin number.

## Function Documentation

## ◆ GPIO_setDirMode()

void GPIO_setDirMode | ( | uint32_t | baseAddr,
|  | uint32_t | pinNum,
|  | uint32_t | pinDir
| ) |  |

This API configures the direction of a specified GPIO pin as being either input or output.

Parameters

  baseAddr | The memory address of the GPIO instance being used
  pinNum | The number of the pin in the GPIO instance 'pinNum' can take one of the following values: (0 <= pinNum <= GPIO_MAX_PIN_PER_INSTANCE - 1)
  pinDir | The required direction for the GPIO pin. This can take one of the value from the following enum: GPIO_Direction_t.

## ◆ GPIO_pinWriteHigh()

static void GPIO_pinWriteHigh | ( | uint32_t | baseAddr,
|  | uint32_t | pinNum
| ) |  |
| inlinestatic

This API drives an output GPIO pin to a logic HIGH state.

Parameters

  baseAddr | The memory address of the GPIO instance being used
  pinNum | The number of the pin in the GPIO instance 'pinNum' can take one of the following values: (0 <= pinNum <= GPIO_MAX_PIN_PER_INSTANCE - 1)

## ◆ GPIO_pinWriteLow()

static void GPIO_pinWriteLow | ( | uint32_t | baseAddr,
|  | uint32_t | pinNum
| ) |  |
| inlinestatic

This API drives an output GPIO pin to a logic LOW state.

Parameters

  baseAddr | The memory address of the GPIO instance being used
  pinNum | The number of the pin in the GPIO instance 'pinNum' can take one of the following values: (0 <= pinNum <= GPIO_MAX_PIN_PER_INSTANCE - 1)

## ◆ GPIO_pinRead()

uint32_t GPIO_pinRead | ( | uint32_t | baseAddr,
|  | uint32_t | pinNum
| ) |  |

This API reads the logic level(value) on a specified GPIO pin.

Parameters

  baseAddr | The memory address of the GPIO instance being used
  pinNum | The number of the pin in the GPIO instance 'pinNum' can take one of the following values: (0 <= pinNum <= GPIO_MAX_PIN_PER_INSTANCE - 1)

Returns
  GPIO_PinValue_t

## ◆ GPIO_pinOutValueRead()

uint32_t GPIO_pinOutValueRead | ( | uint32_t | baseAddr,
|  | uint32_t | pinNum
| ) |  |

This API determines the output logic level(value) on a specified GPIO pin.

Parameters

  baseAddr | The memory address of the GPIO instance being used
  pinNum | The number of the pin in the GPIO instance 'pinNum' can take one of the following values: (0 <= pinNum <= GPIO_MAX_PIN_PER_INSTANCE - 1)

Returns
  GPIO_PinValue_t

## ◆ GPIO_setTrigType()

void GPIO_setTrigType | ( | uint32_t | baseAddr,
|  | uint32_t | pinNum,
|  | uint32_t | trigType
| ) |  |

This API configures the trigger type for a specified input GPIO pin.

        Whenever the selected trigger occurs on that GPIO pin and if interrupt
        generation is enabled for that pin, the GPIO module will send an
        interrupt to CPU.
        To disable the per pin event/interrupt generation, set the
        trigger type to #GPIO_TRIG_TYPE_NONE

Parameters

  baseAddr | The memory address of the GPIO instance being used
  pinNum | The number of the pin in the GPIO instance 'pinNum' can take one of the following values: (0 <= pinNum <= 63).
  trigType | This specifies the trigger type on whose detection, the GPIO module will send an interrupt to CPU, provided interrupt generation for that pin is enabled. 'trigType' can take one of the following values following enum: GPIO_TrigType_t.

## ◆ GPIO_bankIntrEnable()

void GPIO_bankIntrEnable | ( | uint32_t | baseAddr,
|  | uint32_t | bankNum
| ) |  |

This API enables the bank interrupt. This has to be called after setting all the GPIO pin triggers of a bank to get interrupt.

Parameters

  baseAddr | The memory address of the GPIO instance being used
  bankNum | The bank index 'bankNum' can take one of the following values: (0 <= bankNum <= GPIO_MAX_BANKS - 1)

## ◆ GPIO_bankIntrDisable()

void GPIO_bankIntrDisable | ( | uint32_t | baseAddr,
|  | uint32_t | bankNum
| ) |  |

This API disables the bank interrupt.

Parameters

  baseAddr | The memory address of the GPIO instance being used
  bankNum | The bank index 'bankNum' can take one of the following values: (0 <= bankNum <= GPIO_MAX_BANKS - 1)

## ◆ GPIO_getIntrStatus()

static uint32_t GPIO_getIntrStatus | ( | uint32_t | baseAddr,
|  | uint32_t | pinNum
| ) |  |
| inlinestatic

This API determines the enabled interrupt status of a specified pin.

Parameters

  baseAddr | The memory address of the GPIO instance being used
  pinNum | The number of the pin in the GPIO instance 'pinNum' can take one of the following values: (0 <= pinNum <= GPIO_MAX_PIN_PER_INSTANCE - 1)

Returns
  intrStatus The enabled interrupt status of the pin on the specified interrupt line. 1 - interrupt occurred 0 - interrupt hasnt occurred since last cleared writing 1 clears the corresponding interrupt status

## ◆ GPIO_clearIntrStatus()

static void GPIO_clearIntrStatus | ( | uint32_t | baseAddr,
|  | uint32_t | pinNum
| ) |  |
| inlinestatic

This API clears the enabled interrupt status of a specified GPIO pin.

Parameters

  baseAddr | The memory address of the GPIO instance being used
  pinNum | The number of the pin in the GPIO instance 'pinNum' can take one of the following values: (0 <= pinNum <= GPIO_MAX_PIN_PER_INSTANCE - 1)

## ◆ GPIO_getBankIntrStatus()

static uint32_t GPIO_getBankIntrStatus | ( | uint32_t | baseAddr,
|  | uint32_t | bankNum
| ) |  |
| inlinestatic

This API returns the interrupt status of the specified bank.

Parameters

  baseAddr | The memory address of the GPIO instance being used
  bankNum | Bank index of the GPIO instance.

Returns
  Raw interrupt status for the provided register index

## ◆ GPIO_clearBankIntrStatus()

static void GPIO_clearBankIntrStatus | ( | uint32_t | baseAddr,
|  | uint32_t | bankNum,
|  | uint32_t | intrStatus
| ) |  |
| inlinestatic

This API clears the interrupt status of the specified bank.

Parameters

  baseAddr | The memory address of the GPIO instance being used
  bankNum | Bank index of the GPIO instance.
  intrStatus | Interrupt mask to clear the status