VSF Documented
gpio.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2026 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18/*
19 * Clean-room re-implementation of ESP-IDF public API "driver/gpio.h".
20 * Authored from ESP-IDF v5.1 public API only; no ESP-IDF source was
21 * copied. The VSF port bridges onto
22 *
23 * hal/driver/common/template/vsf_template_gpio.h
24 *
25 * via the global vsf_hw_io_mapper (hal/utilities/io_mapper).
26 *
27 * Pin numbering contract (shim-defined, deterministic across MCUs):
28 *
29 * gpio_num = (port_index << VSF_HW_IO_MAPPER_PORT_BITS_LOG2)
30 * | pin_index_within_port;
31 *
32 * With the default VSF_HW_IO_MAPPER_PORT_BITS_LOG2 = 8 this is the
33 * natural "port * 256 + pin" layout. Users that need the classic
34 * ESP-IDF-style symbolic names (GPIO_NUM_0 ... GPIO_NUM_48) may either
35 * rely on the numeric enum below or define their own port/pin macros in
36 * the board configuration.
37 */
38
39#ifndef __VSF_ESPIDF_DRIVER_GPIO_H__
40#define __VSF_ESPIDF_DRIVER_GPIO_H__
41
42#include <stdint.h>
43#include <stdbool.h>
44#include <stddef.h>
45
46#include "esp_err.h"
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52/*============================ TYPES =========================================*/
53
60
61#define GPIO_NUM_NC (-1)
62
66typedef enum {
74
78typedef enum {
82
83typedef enum {
87
88typedef enum {
94
98typedef enum {
106
110typedef enum {
114
123
127typedef struct {
134
142typedef void (*gpio_isr_t)(void *arg);
143
144/*============================ PROTOTYPES ====================================*/
145
155extern esp_err_t gpio_config(const gpio_config_t *config);
156
161extern esp_err_t gpio_reset_pin(gpio_num_t gpio_num);
162
167
172
176extern esp_err_t gpio_set_level(gpio_num_t gpio_num, uint32_t level);
177
181extern int gpio_get_level(gpio_num_t gpio_num);
182
186extern esp_err_t gpio_pullup_en(gpio_num_t gpio_num);
187extern esp_err_t gpio_pullup_dis(gpio_num_t gpio_num);
188extern esp_err_t gpio_pulldown_en(gpio_num_t gpio_num);
189extern esp_err_t gpio_pulldown_dis(gpio_num_t gpio_num);
190
196extern esp_err_t gpio_set_intr_type(gpio_num_t gpio_num, gpio_int_type_t intr_type);
197
201extern esp_err_t gpio_intr_enable(gpio_num_t gpio_num);
202extern esp_err_t gpio_intr_disable(gpio_num_t gpio_num);
203
220extern esp_err_t gpio_install_isr_service(int intr_alloc_flags);
221
228extern void gpio_uninstall_isr_service(void);
229
239 gpio_isr_t isr_handler,
240 void *args);
241
247
248/*---------------------------- not supported --------------------------------*/
249
258typedef void *gpio_isr_handle_t;
259
260extern esp_err_t gpio_isr_register(void (*fn)(void *),
261 void *arg,
262 int intr_alloc_flags,
263 gpio_isr_handle_t *handle);
264
271 gpio_int_type_t intr_type);
273
274#ifdef __cplusplus
275}
276#endif
277
278#endif // __VSF_ESPIDF_DRIVER_GPIO_H__
int esp_err_t
Definition esp_err.h:41
esp_err_t gpio_pullup_en(gpio_num_t gpio_num)
Shortcut pull-up/pull-down enable/disable APIs.
Definition driver_gpio_port.c:359
gpio_pullup_t
Pull-resistor configuration.
Definition gpio.h:78
@ GPIO_PULLUP_ENABLE
Definition gpio.h:80
@ GPIO_PULLUP_DISABLE
Definition gpio.h:79
esp_err_t gpio_isr_register(void(*fn)(void *), void *arg, int intr_alloc_flags, gpio_isr_handle_t *handle)
Definition driver_gpio_port.c:573
gpio_pull_mode_t
Definition gpio.h:88
@ GPIO_PULLDOWN_ONLY
Definition gpio.h:91
@ GPIO_FLOATING
Definition gpio.h:89
@ GPIO_PULLUP_ONLY
Definition gpio.h:90
@ GPIO_PULLUP_PULLDOWN
Definition gpio.h:92
esp_err_t gpio_install_isr_service(int intr_alloc_flags)
Install the shim's per-pin ISR dispatcher.
Definition driver_gpio_port.c:456
gpio_mode_t
Pin direction.
Definition gpio.h:66
@ GPIO_MODE_INPUT_OUTPUT_OD
Definition gpio.h:71
@ GPIO_MODE_INPUT
Definition gpio.h:68
@ GPIO_MODE_OUTPUT
Definition gpio.h:69
@ GPIO_MODE_OUTPUT_OD
Definition gpio.h:70
@ GPIO_MODE_DISABLE
Definition gpio.h:67
@ GPIO_MODE_INPUT_OUTPUT
Definition gpio.h:72
int gpio_get_level(gpio_num_t gpio_num)
Read the input level of a single pin (0 or 1).
Definition driver_gpio_port.c:349
esp_err_t gpio_pullup_dis(gpio_num_t gpio_num)
Definition driver_gpio_port.c:364
esp_err_t gpio_isr_handler_remove(gpio_num_t gpio_num)
Detach a per-pin callback previously registered with gpio_isr_handler_add().
Definition driver_gpio_port.c:558
esp_err_t gpio_isr_handler_add(gpio_num_t gpio_num, gpio_isr_t isr_handler, void *args)
Attach a per-pin callback under the ISR service.
Definition driver_gpio_port.c:540
uint64_t gpio_pin_bit_mask_t
Bit-mask of pin numbers used by gpio_config().
Definition gpio.h:122
esp_err_t gpio_reset_pin(gpio_num_t gpio_num)
Reset a single pin to a safe post-boot state (input, no pull, no interrupt).
Definition driver_gpio_port.c:291
esp_err_t gpio_set_pull_mode(gpio_num_t gpio_num, gpio_pull_mode_t pull)
Set the pull mode of a single pin.
Definition driver_gpio_port.c:320
esp_err_t gpio_pulldown_en(gpio_num_t gpio_num)
Definition driver_gpio_port.c:369
int32_t gpio_num_t
GPIO pin number (flat encoding, see file comment).
Definition gpio.h:59
esp_err_t gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type)
Accepted for source compatibility. Returns ESP_ERR_NOT_SUPPORTED unless the underlying board enables ...
Definition driver_gpio_port.c:585
esp_err_t gpio_intr_enable(gpio_num_t gpio_num)
Per-pin interrupt arm/disarm.
Definition driver_gpio_port.c:400
void * gpio_isr_handle_t
Not supported on the VSF shim. Returns ESP_ERR_NOT_SUPPORTED.
Definition gpio.h:258
void gpio_uninstall_isr_service(void)
Release the per-pin ISR dispatcher.
Definition driver_gpio_port.c:510
esp_err_t gpio_intr_disable(gpio_num_t gpio_num)
Definition driver_gpio_port.c:412
esp_err_t gpio_set_direction(gpio_num_t gpio_num, gpio_mode_t mode)
Set the direction of a single pin.
Definition driver_gpio_port.c:312
gpio_level_t
Signal level passed to gpio_set_level().
Definition gpio.h:110
@ GPIO_HIGH
Definition gpio.h:112
@ GPIO_LOW
Definition gpio.h:111
void(* gpio_isr_t)(void *arg)
Per-pin ISR callback handler.
Definition gpio.h:142
esp_err_t gpio_wakeup_disable(gpio_num_t gpio_num)
Definition driver_gpio_port.c:592
esp_err_t gpio_config(const gpio_config_t *config)
Apply a bulk configuration to every pin listed in config->pin_bit_mask.
Definition driver_gpio_port.c:233
esp_err_t gpio_set_intr_type(gpio_num_t gpio_num, gpio_int_type_t intr_type)
Configure the edge/level that generates an external interrupt on the pin. This does NOT enable the in...
Definition driver_gpio_port.c:379
gpio_int_type_t
External interrupt trigger type.
Definition gpio.h:98
@ GPIO_INTR_LOW_LEVEL
Definition gpio.h:103
@ GPIO_INTR_NEGEDGE
Definition gpio.h:101
@ GPIO_INTR_DISABLE
Definition gpio.h:99
@ GPIO_INTR_HIGH_LEVEL
Definition gpio.h:104
@ GPIO_INTR_POSEDGE
Definition gpio.h:100
@ GPIO_INTR_ANYEDGE
Definition gpio.h:102
gpio_pulldown_t
Definition gpio.h:83
@ GPIO_PULLDOWN_ENABLE
Definition gpio.h:85
@ GPIO_PULLDOWN_DISABLE
Definition gpio.h:84
esp_err_t gpio_pulldown_dis(gpio_num_t gpio_num)
Definition driver_gpio_port.c:374
esp_err_t gpio_set_level(gpio_num_t gpio_num, uint32_t level)
Set the output level of a single pin (0 = low, non-zero = high).
Definition driver_gpio_port.c:334
unsigned uint32_t
Definition stdint.h:9
int int32_t
Definition stdint.h:8
unsigned long long uint64_t
Definition stdint.h:11
Bulk configuration structure used by gpio_config().
Definition gpio.h:127
gpio_pullup_t pull_up_en
Definition gpio.h:130
gpio_pin_bit_mask_t pin_bit_mask
Definition gpio.h:128
gpio_pulldown_t pull_down_en
Definition gpio.h:131
gpio_mode_t mode
Definition gpio.h:129
gpio_int_type_t intr_type
Definition gpio.h:132
Generated from commit: vsfteam/vsf@015f4d1