The GPIO driver provides an API to configure and access device Input/Output pins.
The functions and other declarations used in this driver are in cy_gpio.h. You can include cy_pdl.h to get access to all 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 the individual pins. For efficient use of code space, port configuration should be used in the field. Refer to the product device header files for the list of supported ports and pins.
A port is represented by GPIO_PRT_Type and a pin is represented by a number 0 to 7.
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
- 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).
- All pins are initialized to High-Z drive mode with HSIOM connected to CPU (SW control digital pin only) at Power-On-Reset(POR).
- Some API functions perform read-modify-write operations on shared port registers. These functions are not thread safe and care must be taken when called by the application.
- Digital input buffer provides a high-impedance buffer for the external digital input. The input buffer is connected to the HSIOM for routing to the CPU port registers and selected peripheral. Enabling the input buffer provides possibility to read the pin state via the CPU. If pin is connected to an analog signal, the input buffer should be disabled to avoid crowbar currents. For more information refer to device TRM and the device datasheet.
Multiple pins on a port can be updated using direct port register writes with an appropriate port mask. An example is shown below, highlighting the different ways of configuring Port 1 pins using:
- Initialize a Pin using cy_stc_gpio_pin_config_t structure
1UL,
P0_0_GPIO,
1UL,
0UL,
0UL,
0UL,
0UL,
0UL,
0UL,
0UL
};
{
}
This structure is used to initialize a single GPIO pin.
Definition: cy_gpio.h:227
#define CY_GPIO_DM_STRONG
Strong Drive.
Definition: cy_gpio.h:520
#define CY_GPIO_DRIVE_FULL
Full drive strength: Max drive current.
Definition: cy_gpio.h:561
@ CY_GPIO_SUCCESS
Returned successful.
Definition: cy_gpio.h:154
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:80
#define CY_GPIO_INTR_RISING
Rising-Edge interrupt.
Definition: cy_gpio.h:575
#define CY_GPIO_SLEW_FAST
Fast slew rate.
Definition: cy_gpio.h:542
#define CY_GPIO_VTRIP_CMOS
Input buffer compatible with CMOS and I2C interfaces.
Definition: cy_gpio.h:532
- Initialize entire port using cy_stc_gpio_prt_config_t structure
#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
(PIN_HIGH << PIN_OUTPUT_NUM),
(INTR_ENABLE << PIN_INPUT_NUM),
0x00000000u,
0x00000000u,
0x00000000u,
0x00000000u,
0x00000000u,
0x00000000u,
0x00000000u,
0x00000000u,
0x00000000u,
0x00000000u,
0x00000000u,
};
{
}
This structure is used to initialize a port of GPIO pins.
Definition: cy_gpio.h:203
#define CY_GPIO_DM_PULLUP
Resistive Pull-Up.
Definition: cy_gpio.h:516
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:255
- Port output data register
- Port output data set register
- Port output data clear register
uint8_t value;
portAddr = GPIO_PRT1;
CY_SET_REG32(&portAddr->
OUT, GPIO_PRT_OUT_OUT0_Msk |
GPIO_PRT_OUT_OUT2_Msk |
GPIO_PRT_OUT_OUT3_Msk);
CY_SET_REG32(&portAddr->
OUT_CLR, GPIO_PRT_OUT_CLR_OUT2_Msk |
GPIO_PRT_OUT_CLR_OUT3_Msk);
CY_SET_REG32(&portAddr->
OUT_SET, GPIO_PRT_OUT_SET_OUT3_Msk);
value = CY_GET_REG32(&portAddr->
OUT);
CY_SET_REG32(&portAddr->
OUT, _CLR_SET_FLD32U(portAddr->
OUT, GPIO_PRT_OUT_OUT3, 0u));
CY_SET_REG32(&portAddr->
OUT, _CLR_SET_FLD32U(portAddr->
OUT, GPIO_PRT_OUT_OUT2, 1u));
#define CY_GPIO_DM_STRONG_IN_OFF
Strong Drive.
Definition: cy_gpio.h:512
GPIO port registers (GPIO_PRT)
Definition: cyip_gpio.h:42
__IOM uint32_t OUT_SET
Definition: cyip_gpio.h:45
__IOM uint32_t OUT_CLR
Definition: cyip_gpio.h:44
__IOM uint32_t CFG
Definition: cyip_gpio.h:54
__IOM uint32_t OUT
Definition: cyip_gpio.h:43
More Information
Refer to the technical reference manual (TRM) and the device datasheet.