GPIO
Introduction
GPIO (General-purpose input/output) refers to general-purpose input/output ports. These ports can be controlled via software to handle both input and output operations. For inputs, the default voltage can be configured using pull modes. For outputs, the pin can be set to either high or low voltage by writing to registers.
Function List
Initialization — Initialize the driver.
Configure Direction — Set the direction of the GPIO pin (input or output).
Set Pull Mode — Configure the GPIO pin’s pull-up, pull-down, or floating mode.
Data Read — Read data from the GPIO pin.
Data Write — Write data to the GPIO pin, where 1 sets it high and 0 sets it low.
Pin Multiplexing — Select the IOMUX pin multiplexing function.
Enable Interrupt — Enable GPIO interrupts.
Set Interrupt Mode — Configure the GPIO interrupt mode.
Function Overview
The W800 has 48 GPIO pins that can be configured for multiplexing through IO MUX. The specific relationships are shown in the figure below. FUNC1-FUNC4 represent digital multiplexing, FUNC5 represents GPIO, and FUNC6-FUNC7 represent analog multiplexing. Note: When in analog multiplexing mode, the pin should be configured as input float.
The table below provides the multiplexing information for each pin.
GPIO |
FUNC1 |
FUNC2 |
FUNC3 |
FUNC4 |
FUNC5 |
FUNC6 |
FUNC7 |
---|---|---|---|---|---|---|---|
GPIO0 |
WM_IO_MUX_GPIO0_FUNC_I2S_MCLK |
WM_IO_MUX_GPIO0_FUNC_LSPI_CS |
WM_IO_MUX_GPIO0_FUNC_PWM2 |
WM_IO_MUX_GPIO0_FUNC_I2S_DO |
WM_IO_MUX_GPIO0_FUNC_GPIO |
||
GPIO1 |
WM_IO_MUX_GPIO1_FUNC_JATG_CK |
WM_IO_MUX_GPIO1_FUNC_I2C_SCL |
WM_IO_MUX_GPIO1_FUNC_PWM3 |
WM_IO_MUX_GPIO1_FUNC_I2S_LRCK |
WM_IO_MUX_GPIO1_FUNC_GPIO |
WM_IO_MUX_GPIO1_FUNC_ADC_0 |
|
GPIO2 |
WM_IO_MUX_GPIO2_FUNC_UART1_RTS |
WM_IO_MUX_GPIO2_FUNC_UART2_TX |
WM_IO_MUX_GPIO2_FUNC_PWM0 |
WM_IO_MUX_GPIO2_FUNC_UART3_RTS |
WM_IO_MU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_LCD_SEG1 |
|||
GPIO43 |
WM_IO_MUX_GPIO43_FUNC_PSRAM_CS |
WM_IO_MUX_GPIO43_FUNC_UART0_TX |
WM_IO_MUX_GPIO43_FUNC_GPIO |
WM_IO_MUX_GPIO43_FUNC_LCD_COM3 |
|||
GPIO44 |
|||||||
GPIO45 |
|||||||
GPIO46 |
|||||||
GPIO47 |
Main Functions
Initialize GPIO
Before using GPIO, the
wm_drv_gpio_init
function must be called to initialize the GPIO device. Usingwm_device_t
, the example code is as follows:wm_device_t *gpio_device; gpio_device = wm_drv_gpio_init("gpio");The parameter specifies the device name, which must match the name defined in the device table.
Warning
After initializing GPIO, if
wm_drv_gpio_deinit
is not called, callingwm_drv_gpio_init
again will returnNULL
.
Configure Direction
GPIO direction configuration is used to set the pin to either input or output mode. Use the
wm_drv_gpio_set_dir
function to set the pin direction. Example code is as follows:wm_drv_gpio_set_dir(WM_GPIO_NUM_0, WM_GPIO_DIR_INPUT); wm_drv_gpio_set_dir(WM_GPIO_NUM_0, WM_GPIO_DIR_OUTPUT);The first parameter is the pin number, and the second parameter is the direction, which can be either
WM_GPIO_DIR_INPUT
orWM_GPIO_DIR_OUTPUT
.
Configure Pull Mode
GPIO pull mode configuration is used to set the pin to pull-up, pull-down, or floating mode. Use the
wm_drv_gpio_set_pullmode
function to configure the pin pull mode. Example code is as follows:wm_drv_gpio_set_pullmode(WM_GPIO_NUM_0, WM_GPIO_PULL_UP); wm_drv_gpio_set_pullmode(WM_GPIO_NUM_0, WM_GPIO_PULL_DOWN);The first parameter is the pin number, and the second parameter is the pull mode, which can be
WM_GPIO_PULL_UP
,WM_GPIO_PULL_DOWN
, orWM_GPIO_FLOAT
.
Read Data
Use the
wm_drv_gpio_data_get
function to read data from a GPIO pin. This function returns the current level of the pin. Example code is as follows:int value = wm_drv_gpio_data_get(WM_GPIO_NUM_0);The parameter is the pin number.
Write Data
Use the
wm_drv_gpio_data_set
function to write data to a GPIO pin. This function sets the pin to high level. Example code is as follows:wm_drv_gpio_data_set(WM_GPIO_NUM_0);Use the
wm_drv_gpio_data_reset
function to set the pin to low level. Example code is as follows:wm_drv_gpio_data_reset(WM_GPIO_NUM_0);The parameter is the pin number.
Select Pin Multiplexing
Use the
wm_drv_gpio_iomux_func_sel
function to select the multiplexing function of a GPIO pin. Example code is as follows:wm_gpio_num_t pin = WM_GPIO_NUM_21; wm_gpio_pin_mux_t func = WM_GPIO_IOMUX_FUN5; wm_drv_gpio_iomux_func_sel(pin, func);The first parameter is the pin number, and the second parameter is the function mode, which can be referenced in the table in the function overview or checked in
wm_io_mux.h
.
Enable Interrupt
Use the
wm_drv_gpio_enable_isr
function to enable interrupts for a GPIO pin. Example code is as follows:wm_drv_gpio_enable_isr(WM_GPIO_NUM_21);The parameter is the pin number.
Disable Interrupt
Use the
wm_drv_gpio_disable_isr
function to disable interrupts for a GPIO pin. Example code is as follows:wm_drv_gpio_disable_isr(WM_GPIO_NUM_21);The parameter is the pin number.
Set Interrupt Mode
Use the
wm_drv_gpio_set_intr_mode
function to configure the interrupt trigger mode of a GPIO pin, including falling edge trigger, rising edge trigger, double edge trigger, low level trigger, and high level trigger. Example code is as follows:wm_drv_gpio_set_intr_mode(WM_GPIO_NUM_21, WM_GPIO_IRQ_TRIG_HIGH_LEVEL);The first parameter is the pin number, and the second parameter is the interrupt mode, which can be
WM_GPIO_IRQ_TRIG_FALLING_EDGE
,WM_GPIO_IRQ_TRIG_RISING_EDGE
,WM_GPIO_IRQ_TRIG_DOUBLE_EDGE
,WM_GPIO_IRQ_TRIG_LOW_LEVEL
, orWM_GPIO_IRQ_TRIG_HIGH_LEVEL
.
Application Example
For a basic example of using GPIO, please refer to: examples/peripheral/gpio
API Reference
To find GPIO-related APIs, please refer to: