PSoC 6 Hardware Abstraction Layer (HAL)
GPIO (General Purpose Input Output)

General Description

High level interface for interacting with the Cypress GPIO.

This driver provides configuration of GPIO pins. It also allows values to be read from and written to a pin directly from firmware.

If a GPIO is to be used as an input to or an output from a fixed function peripheral on the device, this driver should not be used directly. The driver for the fixed function peripheral will perform the necessary function calls to configure its GPIO pins.

Macros

#define CYHAL_NC_PIN_VALUE   ((cyhal_gpio_t)0xFFFFFFFF)
 

Typedefs

typedef void(* cyhal_gpio_event_callback_t) (void *callback_arg, cyhal_gpio_event_t event)
 

Enumerations

enum  cyhal_gpio_event_t { CYHAL_GPIO_IRQ_NONE, CYHAL_GPIO_IRQ_RISE, CYHAL_GPIO_IRQ_FALL, CYHAL_GPIO_IRQ_BOTH }
 
enum  cyhal_gpio_direction_t { CYHAL_GPIO_DIR_INPUT, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DIR_BIDIRECTIONAL }
 
enum  cyhal_gpio_drive_mode_t {
  CYHAL_GPIO_DRIVE_NONE, CYHAL_GPIO_DRIVE_ANALOG, CYHAL_GPIO_DRIVE_PULLUP, CYHAL_GPIO_DRIVE_PULLDOWN,
  CYHAL_GPIO_DRIVE_OPENDRAINDRIVESLOW, CYHAL_GPIO_DRIVE_OPENDRAINDRIVESHIGH, CYHAL_GPIO_DRIVE_STRONG, CYHAL_GPIO_DRIVE_PULLUPDOWN
}
 

Functions

cy_rslt_t cyhal_gpio_init (cyhal_gpio_t pin, cyhal_gpio_direction_t direction, cyhal_gpio_drive_mode_t drvMode, bool initVal)
 
void cyhal_gpio_free (cyhal_gpio_t pin)
 
cy_rslt_t cyhal_gpio_configure (cyhal_gpio_t pin, cyhal_gpio_direction_t direction, cyhal_gpio_drive_mode_t drvMode)
 
void cyhal_gpio_write (cyhal_gpio_t pin, bool value)
 
bool cyhal_gpio_read (cyhal_gpio_t pin)
 
void cyhal_gpio_toggle (cyhal_gpio_t pin)
 
void cyhal_gpio_register_callback (cyhal_gpio_t pin, cyhal_gpio_event_callback_t callback, void *callback_arg)
 
void cyhal_gpio_enable_event (cyhal_gpio_t pin, cyhal_gpio_event_t event, uint8_t intrPriority, bool enable)
 

Macro Definition Documentation

◆ CYHAL_NC_PIN_VALUE

#define CYHAL_NC_PIN_VALUE   ((cyhal_gpio_t)0xFFFFFFFF)

Integer representation of no connect pin (required to exist in all BSPs)

Typedef Documentation

◆ cyhal_gpio_event_callback_t

typedef void(* cyhal_gpio_event_callback_t) (void *callback_arg, cyhal_gpio_event_t event)

GPIO callback function type

Enumeration Type Documentation

◆ cyhal_gpio_event_t

Pin events

Enumerator
CYHAL_GPIO_IRQ_NONE 

No interrupt

CYHAL_GPIO_IRQ_RISE 

Interrupt on rising edge

CYHAL_GPIO_IRQ_FALL 

Interrupt on falling edge

CYHAL_GPIO_IRQ_BOTH 

Interrupt on both rising and falling edges

◆ cyhal_gpio_direction_t

Pin direction

Enumerator
CYHAL_GPIO_DIR_INPUT 

Input pin

CYHAL_GPIO_DIR_OUTPUT 

Output pin

CYHAL_GPIO_DIR_BIDIRECTIONAL 

Input and output pin

◆ cyhal_gpio_drive_mode_t

Pin drive mode

Enumerator
CYHAL_GPIO_DRIVE_NONE 

No drive; Hi-Z

CYHAL_GPIO_DRIVE_ANALOG 

Analog Hi-Z

CYHAL_GPIO_DRIVE_PULLUP 

Pull-up resistor

CYHAL_GPIO_DRIVE_PULLDOWN 

Pull-down resistor

CYHAL_GPIO_DRIVE_OPENDRAINDRIVESLOW 

Open-drain, Drives Low

CYHAL_GPIO_DRIVE_OPENDRAINDRIVESHIGH 

Open-drain, Drives High

CYHAL_GPIO_DRIVE_STRONG 

Strong output

CYHAL_GPIO_DRIVE_PULLUPDOWN 

Pull-up and pull-down resistors

Function Documentation

◆ cyhal_gpio_init()

cy_rslt_t cyhal_gpio_init ( cyhal_gpio_t  pin,
cyhal_gpio_direction_t  direction,
cyhal_gpio_drive_mode_t  drvMode,
bool  initVal 
)

Initialize the GPIO pin

Parameters
[in]pinThe GPIO pin to initialize
[in]directionThe pin direction
[in]drvModeThe pin drive mode
[in]initValInitial value on the pin
Returns
The status of the init request

◆ cyhal_gpio_free()

void cyhal_gpio_free ( cyhal_gpio_t  pin)

Uninitialize the gpio peripheral and the cyhal_gpio_t object

Parameters
[in]pinPin number

◆ cyhal_gpio_configure()

cy_rslt_t cyhal_gpio_configure ( cyhal_gpio_t  pin,
cyhal_gpio_direction_t  direction,
cyhal_gpio_drive_mode_t  drvMode 
)

Configure the GPIO pin

Parameters
[in]pinThe GPIO pin
[in]directionThe pin direction
[in]drvModeThe pin drive mode
Returns
The status of the configure request

◆ cyhal_gpio_write()

void cyhal_gpio_write ( cyhal_gpio_t  pin,
bool  value 
)

Set the output value for the pin. This only works for output & in_out pins.

Parameters
[in]pinThe GPIO object
[in]valueThe value to be set (high = true, low = false)

◆ cyhal_gpio_read()

bool cyhal_gpio_read ( cyhal_gpio_t  pin)

Read the input value. This only works for input & in_out pins.

Parameters
[in]pinThe GPIO object
Returns
The value of the IO (true = high, false = low)

◆ cyhal_gpio_toggle()

void cyhal_gpio_toggle ( cyhal_gpio_t  pin)

Toggle the output value

Parameters
[in]pinThe GPIO object

◆ cyhal_gpio_register_callback()

void cyhal_gpio_register_callback ( cyhal_gpio_t  pin,
cyhal_gpio_event_callback_t  callback,
void *  callback_arg 
)

Register/clear a callback handler for pin events

Parameters
[in]pinThe pin number
[in]callbackThe function to call when the specified event happens. Pass NULL to unregister the handler.
[in]callback_argGeneric argument that will be provided to the callback when called, can be NULL

◆ cyhal_gpio_enable_event()

void cyhal_gpio_enable_event ( cyhal_gpio_t  pin,
cyhal_gpio_event_t  event,
uint8_t  intrPriority,
bool  enable 
)

Enable or Disable the specified GPIO event

Parameters
[in]pinThe GPIO object
[in]eventThe GPIO event
[in]intrPriorityThe priority for NVIC interrupt events
[in]enableTrue to turn on interrupts, False to turn off