CAT2 Peripheral Driver Library

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...
 
__STATIC_INLINE 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...
 
__STATIC_INLINE 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 (const 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 (const GPIO_PRT_Type *base, uint32_t pinNum)
 Returns the current HSIOM multiplexer connection to the pin. More...
 
__STATIC_INLINE GPIO_PRT_TypeCy_GPIO_PortToAddr (uint32_t portNum)
 Retrieves the port address based on the given port number. 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
basePointer to the pin's port register base address
pinNumPosition of the pin bit-field within the port register
configPointer 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.
Function Usage
/*.outVal */ 1UL, /* Output = High */
/*.driveMode */ CY_GPIO_DM_PULLUP, /* Resistive pull-up, input buffer on */
/*.hsiom */ P0_0_GPIO, /* Software controlled pin */
/*.intEdge */ CY_GPIO_INTR_RISING, /* Rising edge interrupt */
/*.vtrip */ CY_GPIO_VTRIP_CMOS, /* CMOS voltage trip */
/*.slewRate */ CY_GPIO_SLEW_FAST, /* Fast slew rate */
/*.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 */
};
/* Initialize pin P0.3 */
if(CY_GPIO_SUCCESS != Cy_GPIO_Pin_Init(P0_0_PORT, P0_0_NUM, &pinConfig))
{
/* Insert error handling */
}

◆ 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
basePointer to the pin's port register base address
configPointer to the pin config structure base address
Returns
Initialization status
Function Usage
cy_stc_gpio_prt_config_t portConfig = {
/*.dr =*/ 0x00000008u, /* PX.3 output = 1 */
/*.intrCfg =*/ 0x00000080u, /* PX.3 rising edge interrupt */
/*.pc =*/ 0x00000400u, /* PX.3 resistive pull-up */
/*.pc2 =*/ 0x00000000u, /* PX.3 input buffer on */
/*.sio =*/ 0x00000000u, /* PX[7:0] ignored */
/*.selActive =*/ 0x00000000u, /* PX[7:0] software controlled */
};
/* Initialize GPIO port 0 */
if(CY_GPIO_SUCCESS != Cy_GPIO_Port_Init(GPIO_PRT0, &portConfig))
{
/* Insert error handling */
}

◆ Cy_GPIO_Pin_FastInit()

__STATIC_INLINE 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, in the specified order, initial output value, drive mode, and HSIOM connection. This order might not be suitable for some analog configurations, use standalone GPIO functions if the order of the pin configuration is important.

Parameters
basePointer to the pin's port register base address
pinNumPosition of the pin bit-field within the port register
driveModePin drive mode. Options are detailed in Pin drive mode macros
outValLogic state of the output buffer driven to the pin (1 or 0)
hsiomHSIOM 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.
Function Usage
/* Quickly initialize pin P0.3 (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_Port_Deinit()

__STATIC_INLINE void Cy_GPIO_Port_Deinit ( GPIO_PRT_Type base)

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

Parameters
basePointer 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_SetHSIOM()

__STATIC_INLINE void Cy_GPIO_SetHSIOM ( const 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
basePointer to the pin's port register base address
pinNumPosition of the pin bit-field within the port register
valueHSIOM 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
#define GPIO_PORT P0_3_PORT
#define GPIO_NUM P0_3_NUM
#define GPIO_HSIOM P0_3_AMUXA
#define HSIOM_STATE_GPIO P0_3_GPIO
/* Retrieve the HSIOM connection to P0.3 */
if(HSIOM_STATE_GPIO == Cy_GPIO_GetHSIOM(GPIO_PORT, GPIO_NUM))
{
/* Connect P0.3 to AMUXA */
Cy_GPIO_SetHSIOM(GPIO_PORT, GPIO_NUM, GPIO_HSIOM);
}

◆ Cy_GPIO_GetHSIOM()

__STATIC_INLINE en_hsiom_sel_t Cy_GPIO_GetHSIOM ( const GPIO_PRT_Type base,
uint32_t  pinNum 
)

Returns the current HSIOM multiplexer connection to the pin.

Parameters
basePointer to the pin's port register base address
pinNumPosition of the pin bit-field within the port register
Returns
HSIOM input selection
Function Usage
#define GPIO_PORT P0_3_PORT
#define GPIO_NUM P0_3_NUM
#define GPIO_HSIOM P0_3_AMUXA
#define HSIOM_STATE_GPIO P0_3_GPIO
/* Retrieve the HSIOM connection to P0.3 */
if(HSIOM_STATE_GPIO == Cy_GPIO_GetHSIOM(GPIO_PORT, GPIO_NUM))
{
/* Connect P0.3 to AMUXA */
Cy_GPIO_SetHSIOM(GPIO_PORT, GPIO_NUM, GPIO_HSIOM);
}

◆ 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
portNumPort number
Returns
Base address of the port register structure
Function Usage
uint32_t portCnt = 0UL;
uint32_t pinCnt = 0UL;
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);