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
- 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.
- 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).
- 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.
- 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:
- Port output data register
- Port output data set register
- Port output data clear register
uint8_t value;
portAddr = GPIO_PRT1;
CY_SET_REG32(&portAddr->DR, GPIO_PRT_DR_DATA0_Msk |
GPIO_PRT_DR_DATA2_Msk |
GPIO_PRT_DR_DATA3_Msk);
CY_SET_REG32(&portAddr->DR_CLR, GPIO_PRT_DR_DATA2_Msk |
GPIO_PRT_DR_DATA3_Msk);
CY_SET_REG32(&portAddr->DR_SET, GPIO_PRT_DR_DATA3_Msk);
value = CY_GET_REG32(&portAddr->DR);
(void)value;
CY_SET_REG32(&portAddr->DR, _CLR_SET_FLD32U(portAddr->DR, GPIO_PRT_DR_DATA3, 0u));
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
Version | Changes | Reason for Change |
1.0 | Initial version | |