4.2. hardware_gpio Library Functions#
All the GPIOs in the μC are set to Input Pull-Down configuration during power up by default. To use this library, add following to the C/C++ file,
#include <hardware/gpio.h>
and following to the CMakeLists.txt file.
target_link_libraries(projectName pico_stdlib hardware_gpio)
Following are some of the most commonly used functions for configuring the GPIOs.
4.2.1. gpio_init(uint8_t pinNo)#
This function initializes a GPIO to the peripheral function SIO (Single-Cycle IO). This function is similar to controlling a GPIO directly. However, this peripheral allows the processor to switch GPIO states in a single clock cycle.
Function input
pinNocan be any GPIO number, i.e. 0 through 29.
4.2.2. gpio_set_dir(uint8_t pinNo, bool dir)#
This function configures a GPIO to Input or Output.
Function input
pinNocan be any GPIO number, i.e. 0 through 29.Function input
dirmust be a boolean value, i.e.0orfalsefor Input and1ortruefor Output.
4.2.3. gpio_put(uint8_t pinNo, bool outVal)#
This function drives a GPIO to High or Low if it is configured as an Output.
Function input
pinNocan be any GPIO number, i.e. 0 through 29.Function input
outValmust be a boolean value, i.e.0to drive GPIO Low and1to drive GPIO High.
4.2.4. bool gpio_get(uint8_t pinNo)#
This function reads the state of a GPIO.
Function input
pinNocan be any GPIO number, i.e. 0 through 29.Function returns
0if the GPIO is inLOWstate, else1if the GPIO is inHIGHstate.
4.2.5. gpio_set_pulls(uint8_t pinNo, bool pUp, bool pDown)#
This function enables or disables pull-down or pull-up resistors if the GPIO is configured as an Input.
Function input
pinNocan be any GPIO number, i.e. 0 through 29.Function input
pUpmust be a boolean value, i.e.0to disable and1to enable the pull-up resistor.Function input
pDownmust be a boolean value, i.e.0to disable and1to enable the pull-down resistor.
4.2.6. gpio_set_function(uint8_t pinNo, uint8_t func)#
This function sets up the state of the GPIO to be controlled by a specific peripheral as discussed in the table.
Function input
pinNocan be any GPIO number, i.e. 0 through 29.Function input
funcmust be an unsigned integer value from the table. Necessary constants representing different functions are already defined in the SDK as follows,GPIO_FUNC_SPI = 1,GPIO_FUNC_UART = 2,GPIO_FUNC_I2C = 3,GPIO_FUNC_PWM = 4,GPIO_FUNC_SIO = 5.