PSoC 4 Peripheral Driver Library - Alpha
GPIO (General Purpose Input Output)

General Description

The GPIO driver provides an API to configure and access the device Input/Output pins.

The Peripheral Driver Library(PDL) GPIO functions and other declarations used in this driver are located in cy_gpio.h. You can optionally include cy_pdl.h (ModusToolbox only) to get access to all the functions and declarations in the PDL.

IO pins include all general purpose types such as GPIO, SIO, HSIO, AUXIO, and their variants.

Initialization can be performed either at the port level or by configuring individual pins. Use the port configuration to efficiently use the code space. For the list of supported ports and pins, refer to the product device header files

Once the pin/port initialization is complete, each pin can be accessed by specifying the port (GPIO_PRT_Type) and the pin (0-7) in the provided API functions.

Configuration Considerations

  1. Pin multiplexing is controlled through the High-Speed IO Matrix (HSIOM) selection. This allows the pin to connect to signal sources/sinks throughout the device, as defined by the pin HSIOM selection options (en_hsiom_sel_t). Refer to a device-specific gpio hearder file, e.g. <PDL_DIR>/devices/include/gpio_psoc4100sp_48_tqfp.h and the device datasheet for the supported HSIOM options.
  2. All the pins are initialized to High-Z drive mode with HSIOM connected to CPU (SW control digital pin only) at Power-On-Reset(POR).
  3. Some API functions perform read-modify-write operations on shared port registers. These functions are not thread safe, so the application must call them with precaution.
  4. Each pin provides a digital input buffer that provides a high-impedance buffer for external digital inputs. The input buffer is connected to the HSIOM for routing to the CPU port registers and selected peripherals. Enabling the input buffer provides the possibility to read the pin state via the CPU. If a pin is connected to an analog signal, the input buffer should be disabled to avoid crowbar currents. For detail, refer to the device TRM and device datasheet.

If multiple pins on a port are updated at the same time, using direct port register writes with an appropriate port mask is more efficient than using the PDL single-pin functions. An example is shown below. Highlighted - different ways of configuring Port 1 pins using:

GPIO_PRT_Type* portAddr;
uint8_t value;
/* Set the port address */
portAddr = GPIO_PRT1;
/* Set the drive mode to STRONG for pins P1[0], P1[2] and P1[3] (other pins in this port are HIGHZ) */
CY_SET_REG32(&portAddr->PC, CY_GPIO_DM_STRONG << GPIO_PRT_PC_DM0_Pos |
CY_GPIO_DM_STRONG << GPIO_PRT_PC_DM2_Pos |
CY_GPIO_DM_STRONG << GPIO_PRT_PC_DM3_Pos );
/* Set the pins P1[0], P1[2] and P1[3] to high and other pins in this port to low */
CY_SET_REG32(&portAddr->DR, GPIO_PRT_DR_DATA0_Msk |
GPIO_PRT_DR_DATA2_Msk |
GPIO_PRT_DR_DATA3_Msk);
/* Set the pins P1[2] and P1[3] to low (other pins in this port are unchanged) */
CY_SET_REG32(&portAddr->DR_CLR, GPIO_PRT_DR_DATA2_Msk |
GPIO_PRT_DR_DATA3_Msk);
/* Set the pin P1[3] to high again (other pins in this port are unchanged) */
CY_SET_REG32(&portAddr->DR_SET, GPIO_PRT_DR_DATA3_Msk);
/* Read the port data (value should be 0b00001001) */
value = CY_GET_REG32(&portAddr->DR);
(void)value;
/* Set pin P1[3] to low (other pins are not impacted) */
CY_SET_REG32(&portAddr->DR, _CLR_SET_FLD32U(portAddr->DR, GPIO_PRT_DR_DATA3, 0u));
/* Set pin P1[2] to high (other pins are not impacted) */
CY_SET_REG32(&portAddr->DR, _CLR_SET_FLD32U(portAddr->DR, GPIO_PRT_DR_DATA2, 1u));

More Information

Refer to the technical reference manual (TRM) and the device datasheet.

MISRA-C Compliance

The GPIO driver has the following specific deviations:

MISRA Rule Rule Class (Required/Advisory) Rule Description Description of Deviation(s)
10.5 A The value of an expression should not be cast to an inappropriate essential type. This code is safe because value is checked before conversion to the enumeration.

Changelog

VersionChangesReason for Change
1.0 Initial version

API Reference

 Macros
 
 Functions
 
 Data Structures
 
 Enumerated Types