PSOC E8XXGP Device Support Library

| PSOC E8XXGP Device Support Library

Functions
Initialization Functions
PDL API Reference » GPIO (General Purpose Input Output) » Functions

## General Description

## Functions
cy_en_gpio_status_t | Cy_GPIO_Pin_Init (GPIO_PRT_Type *base, uint32_t pinNum, const cy_stc_gpio_pin_config_t *config)
| Initializes all pin configuration settings for the specified pin. More...
cy_en_gpio_status_t | Cy_GPIO_Port_Init (GPIO_PRT_Type *base, const cy_stc_gpio_prt_config_t *config)
| Initialize a complete port of pins from a single init structure. More...
void | Cy_GPIO_Pin_FastInit (GPIO_PRT_Type *base, uint32_t pinNum, uint32_t driveMode, uint32_t outVal, en_hsiom_sel_t hsiom)
| Initialize the most common configuration settings for all pin types. More...
void | Cy_GPIO_Port_Deinit (GPIO_PRT_Type *base)
| Reset a complete port of pins back to power on reset defaults. More...
__STATIC_INLINE void | Cy_GPIO_SetHSIOM (GPIO_PRT_Type *base, uint32_t pinNum, en_hsiom_sel_t value)
| Configures the HSIOM connection to the pin. More...
__STATIC_INLINE en_hsiom_sel_t | Cy_GPIO_GetHSIOM (GPIO_PRT_Type *base, uint32_t pinNum)
| Returns the current HSIOM multiplexer connection to the pin. More...
__STATIC_INLINE GPIO_PRT_Type * | Cy_GPIO_PortToAddr (uint32_t portNum)
| Retrieves the port address based on the given port number. More...
void | Cy_GPIO_Pin_SecFastInit (GPIO_PRT_Type *base, uint32_t pinNum, uint32_t driveMode, uint32_t outVal, en_hsiom_sel_t hsiom)
| Initialize the most common configuration settings for all pin types. More...
__STATIC_INLINE void | Cy_GPIO_SetHSIOM_SecPin (GPIO_PRT_Type *base, uint32_t pinNum, uint32_t value)
| Configures the pin as secure or non-secure. More...
__STATIC_INLINE uint32_t | Cy_GPIO_GetHSIOM_SecPin (GPIO_PRT_Type *base, uint32_t pinNum)
| Returns the current status of secure Pin. More...

## Function Documentation

## ◆ Cy_GPIO_Pin_Init()

cy_en_gpio_status_t Cy_GPIO_Pin_Init | ( | GPIO_PRT_Type * | base,
|  | uint32_t | pinNum,
|  | const cy_stc_gpio_pin_config_t * | config
| ) |  |

Initializes all pin configuration settings for the specified pin.

Parameters

  base | Pointer to the pin's port register base address
  pinNum | Position of the pin bit-field within the port register
  config | Pointer to the pin config structure base address

Returns
  Initialization status

Note
  This function modifies port registers in read-modify-write operations. It is not thread safe as the resource is shared among multiple pins on a port.
  When EXT_CLK is source to HF0 and this API is called from application then make sure that the drivemode argument is CY_GPIO_DM_HIGHZ.

Function Usage
  cy_stc_gpio_pin_config_t pinConfig = {
  /*.outVal =*/ 1UL, /* Output = High */
  /*.driveMode =*/ CY_GPIO_DM_STRONG, /* Resistive pull-up, input buffer on */
  /*.hsiom =*/ P0_0_GPIO, /* Software controlled pin */
  /*.intEdge =*/ CY_GPIO_INTR_RISING, /* Rising edge interrupt */
  /*.intMask =*/ 1UL, /* Enable port interrupt for this pin */
  /*.vtrip =*/ CY_GPIO_VTRIP_CMOS, /* CMOS voltage trip */
  /*.slewRate =*/ CY_GPIO_SLEW_FAST, /* Fast slew rate */
  /*.driveSel =*/ CY_GPIO_DRIVE_FULL, /* Full drive strength */
  /*.vregEn =*/ 0UL, /* SIO-specific setting - ignored */
  /*.ibufMode =*/ 0UL, /* SIO-specific setting - ignored */
  /*.vtripSel =*/ 0UL, /* SIO-specific setting - ignored */
  /*.vrefSel =*/ 0UL, /* SIO-specific setting - ignored */
  /*.vohSel =*/ 0UL, /* SIO-specific setting - ignored */
  /*.nonSec =*/ 0UL, /* Secure attribute */
  /*.pullUpRes =*/ 0UL /* Pull-up resistor configuration */
  };
  /* Initialize pin P0.0 */
  if(CY_GPIO_SUCCESS != Cy_GPIO_Pin_Init(P0_0_PORT, P0_0_NUM, &pinConfig))
  {
  /* Insert error handling */
  }
  cy_stc_gpio_pin_config_t
  This structure is used to initialize a single GPIO pin.
  Definition: cy_gpio.h:230
  CY_GPIO_DM_STRONG
  #define CY_GPIO_DM_STRONG
  Strong Drive.
  Definition: cy_gpio.h:522
  CY_GPIO_DRIVE_FULL
  #define CY_GPIO_DRIVE_FULL
  Full drive strength: Max drive current.
  Definition: cy_gpio.h:563
  CY_GPIO_SUCCESS
  @ CY_GPIO_SUCCESS
  Returned successful.
  Definition: cy_gpio.h:157
  Cy_GPIO_Pin_Init
  cy_en_gpio_status_t Cy_GPIO_Pin_Init(GPIO_PRT_Type *base, uint32_t pinNum, const cy_stc_gpio_pin_config_t *config)
  Initializes all pin configuration settings for the specified pin.
  Definition: cy_gpio.c:79
  CY_GPIO_INTR_RISING
  #define CY_GPIO_INTR_RISING
  Rising-Edge interrupt.
  Definition: cy_gpio.h:577
  CY_GPIO_SLEW_FAST
  #define CY_GPIO_SLEW_FAST
  Fast slew rate.
  Definition: cy_gpio.h:544
  CY_GPIO_VTRIP_CMOS
  #define CY_GPIO_VTRIP_CMOS
  Input buffer compatible with CMOS and I2C interfaces.
  Definition: cy_gpio.h:534

## ◆ Cy_GPIO_Port_Init()

cy_en_gpio_status_t Cy_GPIO_Port_Init | ( | GPIO_PRT_Type * | base,
|  | const cy_stc_gpio_prt_config_t * | config
| ) |  |

Initialize a complete port of pins from a single init structure.

The configuration structure used in this function has a 1:1 mapping to the GPIO and HSIOM registers. Refer to the device Technical Reference Manual (TRM) for the register details on how to populate them.

Parameters

  base | Pointer to the pin's port register base address
  config | Pointer to the pin config structure base address

Returns
  Initialization status

Note
  If using the PSoC Creator IDE, there is no need to initialize the pins when using the GPIO component on the schematic. Ports are configured in Cy_SystemInit() before main() entry.

Function Usage
  /* Scenario: Initialize GPIO port 0:
  * - 3 pin as input with resistive pull-up and rising edge interrupt;
  * - 5 pin as output in a strong drive mode with initial state high. */
  #define PIN_INPUT_NUM 3u
  #define PIN_OUTPUT_NUM 5u
  #define PIN_HIGH 1u
  #define INTR_ENABLE 1u
  #define INTR_CFG_LEN 2u
  #define PIN_DM_CFG_LEN 4u
  cy_stc_gpio_prt_config_t port0_Config = {
  /*.out =*/ (PIN_HIGH << PIN_OUTPUT_NUM), /* PX.5 output value = 1 */
  /*.intrMask =*/ (INTR_ENABLE << PIN_INPUT_NUM), /* PX.3 interrupt enabled */
  /*.intrCfg =*/ (CY_GPIO_INTR_RISING << (PIN_INPUT_NUM * INTR_CFG_LEN)), /* PX.3 rising edge interrupt */
  /*.cfg =*/ ((CY_GPIO_DM_PULLUP << (PIN_INPUT_NUM * PIN_DM_CFG_LEN)) | /* PX.3 resistive pull-up */
  (CY_GPIO_DM_STRONG << (PIN_OUTPUT_NUM * PIN_DM_CFG_LEN))), /* PX.5 strong drive */
  /*.cfgIn =*/ 0x00000000u, /* PX[7:0] CMOS trip (default value)*/
  /*.cfgOut =*/ 0x00000000u, /* PX[7:0] Fast slew rate, full drive strength (default value) */
  /*.cfgSIO =*/ 0x00000000u, /* PX[7:0] ignored (default value) */
  /*.sel0Active =*/ 0x00000000u, /* PX[3:0] Use GPIO HSIOM (default value) */
  /*.sel1Active =*/ 0x00000000u, /* PX[7:4] Use GPIO HSIOM (default value) */
  /*.cfgSlew =*/ 0x00000000u, /* PX[3:0] Slew rate control (default value) */
  /*.cfgDriveSel0 =*/ 0x00000000u, /* PX[3:0] Drive strength selection (default value) */
  /*.cfgDriveSel1 =*/ 0x00000000u, /* PX[7:4] Drive strength selection (default value) */
  /*.nonSecMask =*/ 0x00000000u, /* PX[7:0] Non-secure mask (default value) */
  /*.cfgRes =*/ 0x00000000u, /* PX[7:0] Pull-up resistor configuration for port pins (default value) */
  /*.cfgOut3 =*/ 0x00000000u, /* PX[7:0] Pin extra drive mode (default value) */
  };
  /* Initialize GPIO port 0 */
  if(CY_GPIO_SUCCESS != Cy_GPIO_Port_Init(GPIO_PRT0, &port0_Config))
  {
  /* Insert error handling */
  }
  cy_stc_gpio_prt_config_t
  This structure is used to initialize a port of GPIO pins.
  Definition: cy_gpio.h:206
  CY_GPIO_DM_PULLUP
  #define CY_GPIO_DM_PULLUP
  Resistive Pull-Up.
  Definition: cy_gpio.h:518
  Cy_GPIO_Port_Init
  cy_en_gpio_status_t Cy_GPIO_Port_Init(GPIO_PRT_Type *base, const cy_stc_gpio_prt_config_t *config)
  Initialize a complete port of pins from a single init structure.
  Definition: cy_gpio.c:254

## ◆ Cy_GPIO_Pin_FastInit()

void Cy_GPIO_Pin_FastInit | ( | GPIO_PRT_Type * | base,
|  | uint32_t | pinNum,
|  | uint32_t | driveMode,
|  | uint32_t | outVal,
|  | en_hsiom_sel_t | hsiom
| ) |  |

Initialize the most common configuration settings for all pin types.

These include, drive mode, initial output value, and HSIOM connection.

Parameters

  base | Pointer to the pin's port register base address
  pinNum | Position of the pin bit-field within the port register
  driveMode | Pin drive mode. Options are detailed in Pin drive mode macros
  outVal | Logic state of the output buffer driven to the pin (1 or 0)
  hsiom | HSIOM input selection

Note
  This function modifies port registers in read-modify-write operations. It is not thread safe as the resource is shared among multiple pins on a port. You can use the Cy_SysLib_EnterCriticalSection() and Cy_SysLib_ExitCriticalSection() functions to ensure that Cy_GPIO_Pin_FastInit() function execution is not interrupted.
  When EXT_CLK is source to HF0 and this API is called from application then make sure that the drivemode argument is CY_GPIO_DM_HIGHZ.
  This doesn't set pull-up resistance value. By default. the pull-up resistance is disabled. To select it, use Cy_GPIO_SetPullupResistance.

Function Usage
  /* Quickly initialize pin P0.0 (e.g. quickly set up a test LED) */
  Cy_GPIO_Pin_FastInit(P0_0_PORT, P0_0_NUM, CY_GPIO_DM_PULLUP, 1UL, P0_0_GPIO);
  Cy_GPIO_Pin_FastInit
  void Cy_GPIO_Pin_FastInit(GPIO_PRT_Type *base, uint32_t pinNum, uint32_t driveMode, uint32_t outVal, en_hsiom_sel_t hsiom)
  Initialize the most common configuration settings for all pin types.
  Definition: cy_gpio.c:419

## ◆ Cy_GPIO_Port_Deinit()

void Cy_GPIO_Port_Deinit | ( | GPIO_PRT_Type * | base | ) |

Reset a complete port of pins back to power on reset defaults.

Parameters

  base | Pointer to the pin's port register base address

Function Usage
  /* Initialize GPIO port 0 */
  (void)Cy_GPIO_Port_Init(GPIO_PRT0, &portConfig);
  /* Scenario: The port is no longer used or needs to be disabled */
  /* Reset the GPIO port 0 to Power-On-Reset values */
  Cy_GPIO_Port_Deinit(GPIO_PRT0);
  Cy_GPIO_Port_Deinit
  void Cy_GPIO_Port_Deinit(GPIO_PRT_Type *base)
  Reset a complete port of pins back to power on reset defaults.
  Definition: cy_gpio.c:606

## ◆ Cy_GPIO_SetHSIOM()

__STATIC_INLINE void Cy_GPIO_SetHSIOM | ( | GPIO_PRT_Type * | base,
|  | uint32_t | pinNum,
|  | en_hsiom_sel_t | value
| ) |  |

Configures the HSIOM connection to the pin.

Connects the specified High-Speed Input Output Multiplexer (HSIOM) selection to the pin.

Parameters

  base | Pointer to the pin's port register base address
  pinNum | Position of the pin bit-field within the port register
  value | HSIOM input selection

Note
  This function modifies a port register in a read-modify-write operation. It is not thread safe as the resource is shared among multiple pins on a port.

Function Usage
  /* Retrieve the HSIOM connection to P0.0 */
  if(P0_0_GPIO == Cy_GPIO_GetHSIOM(P0_0_PORT, P0_0_NUM))
  {
  /* Connect P0.3 to AMUXA */
  Cy_GPIO_SetHSIOM(P0_0_PORT, P0_0_NUM, P0_0_SCB3_SPI_SELECT0);
  }
  Cy_GPIO_GetHSIOM
  __STATIC_INLINE en_hsiom_sel_t Cy_GPIO_GetHSIOM(GPIO_PRT_Type *base, uint32_t pinNum)
  Returns the current HSIOM multiplexer connection to the pin.
  Definition: cy_gpio.h:979
  Cy_GPIO_SetHSIOM
  __STATIC_INLINE void Cy_GPIO_SetHSIOM(GPIO_PRT_Type *base, uint32_t pinNum, en_hsiom_sel_t value)
  Configures the HSIOM connection to the pin.
  Definition: cy_gpio.h:925

## ◆ Cy_GPIO_GetHSIOM()

__STATIC_INLINE en_hsiom_sel_t Cy_GPIO_GetHSIOM | ( | GPIO_PRT_Type * | base,
|  | uint32_t | pinNum
| ) |  |

Returns the current HSIOM multiplexer connection to the pin.

Parameters

  base | Pointer to the pin's port register base address
  pinNum | Position of the pin bit-field within the port register

Returns
  HSIOM input selection

Function Usage
  /* Retrieve the HSIOM connection to P0.0 */
  if(P0_0_GPIO == Cy_GPIO_GetHSIOM(P0_0_PORT, P0_0_NUM))
  {
  /* Connect P0.3 to AMUXA */
  Cy_GPIO_SetHSIOM(P0_0_PORT, P0_0_NUM, P0_0_SCB3_SPI_SELECT0);
  }

## ◆ Cy_GPIO_PortToAddr()

__STATIC_INLINE GPIO_PRT_Type * Cy_GPIO_PortToAddr | ( | uint32_t | portNum | ) |

Retrieves the port address based on the given port number.

This is a helper function to calculate the port base address when given a port number. It is to be used when pin access needs to be calculated at runtime.

Parameters

  portNum | Port number

Returns
  Base address of the port register structure

Function Usage
  uint32_t portCnt = 0UL;
  uint32_t pinCnt = 3UL;
  uint32_t pinState = 1UL;
  /* Scenario: Calculate the location and state of a pin to control */
  /* Control which pin to set/clear using parameters */
  Cy_GPIO_Write(Cy_GPIO_PortToAddr(portCnt), pinCnt, pinState);
  Cy_GPIO_Write
  __STATIC_INLINE void Cy_GPIO_Write(GPIO_PRT_Type *base, uint32_t pinNum, uint32_t value)
  Write a logic 0 or logic 1 state to the output driver.
  Definition: cy_gpio.h:1106
  Cy_GPIO_PortToAddr
  __STATIC_INLINE GPIO_PRT_Type * Cy_GPIO_PortToAddr(uint32_t portNum)
  Retrieves the port address based on the given port number.
  Definition: cy_gpio.h:1031

## ◆ Cy_GPIO_Pin_SecFastInit()

void Cy_GPIO_Pin_SecFastInit | ( | GPIO_PRT_Type * | base,
|  | uint32_t | pinNum,
|  | uint32_t | driveMode,
|  | uint32_t | outVal,
|  | en_hsiom_sel_t | hsiom
| ) |  |

Initialize the most common configuration settings for all pin types.

These include, drive mode, initial output value, and HSIOM connection. This function should be called from appropriate protection context where secure HSIOM port (HSIOM_SECURE_PRT_Type) is accessible.

Parameters

  base | Pointer to the pin's port register base address
  pinNum | Position of the pin bit-field within the port register
  driveMode | Pin drive mode. Options are detailed in Pin drive mode macros
  outVal | Logic state of the output buffer driven to the pin (1 or 0)
  hsiom | HSIOM input selection

Note
  This function modifies port registers in read-modify-write operations. It is not thread safe as the resource is shared among multiple pins on a port. You can use the Cy_SysLib_EnterCriticalSection() and Cy_SysLib_ExitCriticalSection() functions to ensure that Cy_GPIO_Pin_SecFastInit() function execution is not interrupted.
  This API should be accessed from secure domain only.

## ◆ Cy_GPIO_SetHSIOM_SecPin()

__STATIC_INLINE void Cy_GPIO_SetHSIOM_SecPin | ( | GPIO_PRT_Type * | base,
|  | uint32_t | pinNum,
|  | uint32_t | value
| ) |  |

Configures the pin as secure or non-secure.

Parameters

  base | Pointer to the pin's port register base address
  pinNum | Position of the pin bit-field within the port register
  value | Secure HSIOM non-secure mask

Note
  This function modifies a port register in a read-modify-write operation. It is not thread safe as the resource is shared among multiple pins on a port. This function should be called from the right protection context to access HSIOM secure port (HSIOM_SECURE_PRT_Type).
  This API is available for devices that support TrustZone. It should be accessed from secure domain only.

Function Usage

## ◆ Cy_GPIO_GetHSIOM_SecPin()

__STATIC_INLINE uint32_t Cy_GPIO_GetHSIOM_SecPin | ( | GPIO_PRT_Type * | base,
|  | uint32_t | pinNum
| ) |  |

Returns the current status of secure Pin.

Parameters

  base | Pointer to the pin's port register base address
  pinNum | Position of the pin bit-field within the port register

Returns
  HSIOM input selection. In case of accessing this API from secure domain, it will return 0 ( secure ) or 1 ( non-secure ). Whereas, in case of accessing this API from non-secure domain, it will return CY_GPIO_BAD_PARAM.

Note
  This API is available for devices that support TrustZone. It should be accessed from secure domain only.

Function Usage