2021-05-23 19:50:04 -04:00
|
|
|
/*
|
2023-09-22 05:36:51 -04:00
|
|
|
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
2021-05-23 19:50:04 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2016-09-19 05:33:21 -04:00
|
|
|
|
2019-07-15 02:44:15 -04:00
|
|
|
#pragma once
|
2021-01-13 23:11:22 -05:00
|
|
|
|
2023-09-22 05:36:51 -04:00
|
|
|
#include <stdio.h>
|
2022-01-05 03:17:12 -05:00
|
|
|
#include <stdbool.h>
|
2019-11-28 08:11:49 -05:00
|
|
|
#include "sdkconfig.h"
|
2016-09-28 11:20:34 -04:00
|
|
|
#include "esp_err.h"
|
2021-01-13 23:11:22 -05:00
|
|
|
#include "esp_intr_alloc.h"
|
2020-09-09 22:37:58 -04:00
|
|
|
#include "soc/soc_caps.h"
|
2019-07-25 11:11:31 -04:00
|
|
|
#include "hal/gpio_types.h"
|
2022-01-05 03:17:12 -05:00
|
|
|
#include "esp_rom_gpio.h"
|
2022-08-22 10:03:30 -04:00
|
|
|
#include "driver/gpio_etm.h"
|
global: move the soc component out of the common list
This MR removes the common dependency from every IDF components to the SOC component.
Currently, in the ``idf_functions.cmake`` script, we include the header path of SOC component by default for all components.
But for better code organization (or maybe also benifits to the compiling speed), we may remove the dependency to SOC components for most components except the driver and kernel related components.
In CMAKE, we have two kinds of header visibilities (set by include path visibility):
(Assume component A --(depends on)--> B, B is the current component)
1. public (``COMPONENT_ADD_INCLUDEDIRS``): means this path is visible to other depending components (A) (visible to A and B)
2. private (``COMPONENT_PRIV_INCLUDEDIRS``): means this path is only visible to source files inside the component (visible to B only)
and we have two kinds of depending ways:
(Assume component A --(depends on)--> B --(depends on)--> C, B is the current component)
1. public (```COMPONENT_REQUIRES```): means B can access to public include path of C. All other components rely on you (A) will also be available for the public headers. (visible to A, B)
2. private (``COMPONENT_PRIV_REQUIRES``): means B can access to public include path of C, but don't propagate this relation to other components (A). (visible to B)
1. remove the common requirement in ``idf_functions.cmake``, this makes the SOC components invisible to all other components by default.
2. if a component (for example, DRIVER) really needs the dependency to SOC, add a private dependency to SOC for it.
3. some other components that don't really depends on the SOC may still meet some errors saying "can't find header soc/...", this is because it's depended component (DRIVER) incorrectly include the header of SOC in its public headers. Moving all this kind of #include into source files, or private headers
4. Fix the include requirements for some file which miss sufficient #include directives. (Previously they include some headers by the long long long header include link)
This is a breaking change. Previous code may depends on the long include chain.
You may need to include the following headers for some files after this commit:
- soc/soc.h
- soc/soc_memory_layout.h
- driver/gpio.h
- esp_sleep.h
The major broken include chain includes:
1. esp_system.h no longer includes esp_sleep.h. The latter includes driver/gpio.h and driver/touch_pad.h.
2. ets_sys.h no longer includes soc/soc.h
3. freertos/portmacro.h no longer includes soc/soc_memory_layout.h
some peripheral headers no longer includes their hw related headers, e.g. rom/gpio.h no longer includes soc/gpio_pins.h and soc/gpio_reg.h
BREAKING CHANGE
2019-04-03 01:17:38 -04:00
|
|
|
|
2016-09-19 05:33:21 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2016-11-04 00:52:34 -04:00
|
|
|
|
2020-09-09 22:37:58 -04:00
|
|
|
#define GPIO_PIN_COUNT (SOC_GPIO_PIN_COUNT)
|
|
|
|
/// Check whether it is a valid GPIO number
|
2022-03-21 09:25:21 -04:00
|
|
|
#define GPIO_IS_VALID_GPIO(gpio_num) ((gpio_num >= 0) && \
|
|
|
|
(((1ULL << (gpio_num)) & SOC_GPIO_VALID_GPIO_MASK) != 0))
|
2020-09-09 22:37:58 -04:00
|
|
|
/// Check whether it can be a valid GPIO number of output mode
|
2022-03-21 09:25:21 -04:00
|
|
|
#define GPIO_IS_VALID_OUTPUT_GPIO(gpio_num) ((gpio_num >= 0) && \
|
|
|
|
(((1ULL << (gpio_num)) & SOC_GPIO_VALID_OUTPUT_GPIO_MASK) != 0))
|
2022-09-16 08:25:44 -04:00
|
|
|
/// Check whether it can be a valid digital I/O pad
|
|
|
|
#define GPIO_IS_VALID_DIGITAL_IO_PAD(gpio_num) ((gpio_num >= 0) && \
|
|
|
|
(((1ULL << (gpio_num)) & SOC_GPIO_VALID_DIGITAL_IO_PAD_MASK) != 0))
|
2020-09-09 22:37:58 -04:00
|
|
|
|
2016-12-07 08:30:21 -05:00
|
|
|
typedef intr_handle_t gpio_isr_handle_t;
|
2016-09-19 05:33:21 -04:00
|
|
|
|
2022-08-24 05:06:20 -04:00
|
|
|
/**
|
|
|
|
* @brief GPIO interrupt handler
|
|
|
|
*
|
|
|
|
* @param arg User registered data
|
|
|
|
*/
|
|
|
|
typedef void (*gpio_isr_t)(void *arg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Configuration parameters of GPIO pad for gpio_config function
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
uint64_t pin_bit_mask; /*!< GPIO pin: set with bit mask, each bit maps to a GPIO */
|
|
|
|
gpio_mode_t mode; /*!< GPIO mode: set input/output mode */
|
|
|
|
gpio_pullup_t pull_up_en; /*!< GPIO pull-up */
|
|
|
|
gpio_pulldown_t pull_down_en; /*!< GPIO pull-down */
|
|
|
|
gpio_int_type_t intr_type; /*!< GPIO interrupt type */
|
2023-02-20 05:48:47 -05:00
|
|
|
#if SOC_GPIO_SUPPORT_PIN_HYS_FILTER
|
|
|
|
gpio_hys_ctrl_mode_t hys_ctrl_mode; /*!< GPIO hysteresis: hysteresis filter on slope input */
|
|
|
|
#endif
|
2022-08-24 05:06:20 -04:00
|
|
|
} gpio_config_t;
|
|
|
|
|
2016-09-19 05:33:21 -04:00
|
|
|
/**
|
2016-10-31 23:48:32 -04:00
|
|
|
* @brief GPIO common configuration
|
2016-09-19 05:33:21 -04:00
|
|
|
*
|
2016-10-31 23:48:32 -04:00
|
|
|
* Configure GPIO's Mode,pull-up,PullDown,IntrType
|
2016-09-19 05:33:21 -04:00
|
|
|
*
|
2016-10-31 23:48:32 -04:00
|
|
|
* @param pGPIOConfig Pointer to GPIO configure struct
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
2016-09-19 05:33:21 -04:00
|
|
|
*
|
|
|
|
*/
|
2017-04-13 13:33:33 -04:00
|
|
|
esp_err_t gpio_config(const gpio_config_t *pGPIOConfig);
|
2016-09-19 05:33:21 -04:00
|
|
|
|
2018-06-08 03:33:04 -04:00
|
|
|
/**
|
|
|
|
* @brief Reset an gpio to default state (select gpio function, enable pullup and disable input and output).
|
2018-06-03 22:34:23 -04:00
|
|
|
*
|
2018-06-08 03:33:04 -04:00
|
|
|
* @param gpio_num GPIO number.
|
2018-06-03 22:34:23 -04:00
|
|
|
*
|
2018-06-08 03:33:04 -04:00
|
|
|
* @note This function also configures the IOMUX for this pin to the GPIO
|
|
|
|
* function, and disconnects any other peripheral output configured via GPIO
|
|
|
|
* Matrix.
|
2018-06-03 22:34:23 -04:00
|
|
|
*
|
2018-06-08 03:33:04 -04:00
|
|
|
* @return Always return ESP_OK.
|
|
|
|
*/
|
|
|
|
esp_err_t gpio_reset_pin(gpio_num_t gpio_num);
|
2016-09-20 21:51:37 -04:00
|
|
|
|
|
|
|
/**
|
2016-10-31 23:48:32 -04:00
|
|
|
* @brief GPIO set interrupt trigger type
|
2016-09-20 21:51:37 -04:00
|
|
|
*
|
2016-11-14 21:29:52 -05:00
|
|
|
* @param gpio_num GPIO number. If you want to set the trigger type of e.g. of GPIO16, gpio_num should be GPIO_NUM_16 (16);
|
2016-10-31 23:48:32 -04:00
|
|
|
* @param intr_type Interrupt type, select from gpio_int_type_t
|
2016-09-20 21:51:37 -04:00
|
|
|
*
|
2016-10-31 23:48:32 -04:00
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
2016-09-20 21:51:37 -04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
esp_err_t gpio_set_intr_type(gpio_num_t gpio_num, gpio_int_type_t intr_type);
|
|
|
|
|
|
|
|
/**
|
2016-10-31 23:48:32 -04:00
|
|
|
* @brief Enable GPIO module interrupt signal
|
2016-09-20 21:51:37 -04:00
|
|
|
*
|
2022-06-22 02:45:15 -04:00
|
|
|
* @note ESP32: Please do not use the interrupt of GPIO36 and GPIO39 when using ADC or Wi-Fi and Bluetooth with sleep mode enabled.
|
2018-02-05 08:51:32 -05:00
|
|
|
* Please refer to the comments of `adc1_get_raw`.
|
2022-07-19 21:43:52 -04:00
|
|
|
* Please refer to Section 3.11 of <a href="https://espressif.com/sites/default/files/documentation/eco_and_workarounds_for_bugs_in_esp32_en.pdf">ESP32 ECO and Workarounds for Bugs</a> for the description of this issue.
|
2022-09-05 04:23:54 -04:00
|
|
|
|
2018-02-05 08:51:32 -05:00
|
|
|
*
|
2016-11-14 21:29:52 -05:00
|
|
|
* @param gpio_num GPIO number. If you want to enable an interrupt on e.g. GPIO16, gpio_num should be GPIO_NUM_16 (16);
|
2016-09-20 21:51:37 -04:00
|
|
|
*
|
2016-10-31 23:48:32 -04:00
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
2016-09-20 21:51:37 -04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
esp_err_t gpio_intr_enable(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
2016-10-31 23:48:32 -04:00
|
|
|
* @brief Disable GPIO module interrupt signal
|
2016-09-20 21:51:37 -04:00
|
|
|
*
|
2022-03-09 01:37:41 -05:00
|
|
|
* @note This function is allowed to be executed when Cache is disabled within ISR context, by enabling `CONFIG_GPIO_CTRL_FUNC_IN_IRAM`
|
|
|
|
*
|
2016-11-14 21:29:52 -05:00
|
|
|
* @param gpio_num GPIO number. If you want to disable the interrupt of e.g. GPIO16, gpio_num should be GPIO_NUM_16 (16);
|
2016-09-20 21:51:37 -04:00
|
|
|
*
|
2016-10-31 23:48:32 -04:00
|
|
|
* @return
|
|
|
|
* - ESP_OK success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
2016-09-20 21:51:37 -04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
esp_err_t gpio_intr_disable(gpio_num_t gpio_num);
|
|
|
|
|
2016-09-19 05:33:21 -04:00
|
|
|
/**
|
2016-10-31 23:48:32 -04:00
|
|
|
* @brief GPIO set output level
|
2016-09-19 05:33:21 -04:00
|
|
|
*
|
2022-03-09 01:37:41 -05:00
|
|
|
* @note This function is allowed to be executed when Cache is disabled within ISR context, by enabling `CONFIG_GPIO_CTRL_FUNC_IN_IRAM`
|
|
|
|
*
|
2016-11-14 21:29:52 -05:00
|
|
|
* @param gpio_num GPIO number. If you want to set the output level of e.g. GPIO16, gpio_num should be GPIO_NUM_16 (16);
|
2016-10-31 23:48:32 -04:00
|
|
|
* @param level Output level. 0: low ; 1: high
|
2016-09-19 05:33:21 -04:00
|
|
|
*
|
2016-10-31 23:48:32 -04:00
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
2016-12-21 21:05:19 -05:00
|
|
|
* - ESP_ERR_INVALID_ARG GPIO number error
|
2016-09-19 05:33:21 -04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
esp_err_t gpio_set_level(gpio_num_t gpio_num, uint32_t level);
|
|
|
|
|
|
|
|
/**
|
2016-10-31 23:48:32 -04:00
|
|
|
* @brief GPIO get input level
|
2016-09-19 05:33:21 -04:00
|
|
|
*
|
2018-03-18 11:37:54 -04:00
|
|
|
* @warning If the pad is not configured for input (or input and output) the returned value is always 0.
|
|
|
|
*
|
2016-11-14 21:29:52 -05:00
|
|
|
* @param gpio_num GPIO number. If you want to get the logic level of e.g. pin GPIO16, gpio_num should be GPIO_NUM_16 (16);
|
2016-09-19 05:33:21 -04:00
|
|
|
*
|
2016-10-31 23:48:32 -04:00
|
|
|
* @return
|
|
|
|
* - 0 the GPIO input level is 0
|
|
|
|
* - 1 the GPIO input level is 1
|
2016-09-19 05:33:21 -04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
int gpio_get_level(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
2022-08-22 10:03:30 -04:00
|
|
|
* @brief GPIO set direction
|
2016-09-19 05:33:21 -04:00
|
|
|
*
|
|
|
|
* Configure GPIO direction,such as output_only,input_only,output_and_input
|
|
|
|
*
|
2016-11-14 21:29:52 -05:00
|
|
|
* @param gpio_num Configure GPIO pins number, it should be GPIO number. If you want to set direction of e.g. GPIO16, gpio_num should be GPIO_NUM_16 (16);
|
2016-10-31 23:48:32 -04:00
|
|
|
* @param mode GPIO direction
|
2016-09-19 05:33:21 -04:00
|
|
|
*
|
2016-10-31 23:48:32 -04:00
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO error
|
2016-09-19 05:33:21 -04:00
|
|
|
*
|
|
|
|
*/
|
2016-09-20 21:51:37 -04:00
|
|
|
esp_err_t gpio_set_direction(gpio_num_t gpio_num, gpio_mode_t mode);
|
2016-09-19 05:33:21 -04:00
|
|
|
|
|
|
|
/**
|
2017-02-15 21:59:50 -05:00
|
|
|
* @brief Configure GPIO pull-up/pull-down resistors
|
2016-09-19 05:33:21 -04:00
|
|
|
*
|
2022-06-22 02:45:15 -04:00
|
|
|
* @note ESP32: Only pins that support both input & output have integrated pull-up and pull-down resistors. Input-only GPIOs 34-39 do not.
|
2016-09-19 05:33:21 -04:00
|
|
|
*
|
2016-11-14 21:29:52 -05:00
|
|
|
* @param gpio_num GPIO number. If you want to set pull up or down mode for e.g. GPIO16, gpio_num should be GPIO_NUM_16 (16);
|
2016-10-31 23:48:32 -04:00
|
|
|
* @param pull GPIO pull up/down mode.
|
2016-09-19 05:33:21 -04:00
|
|
|
*
|
2016-10-31 23:48:32 -04:00
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG : Parameter error
|
2016-09-19 05:33:21 -04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
esp_err_t gpio_set_pull_mode(gpio_num_t gpio_num, gpio_pull_mode_t pull);
|
|
|
|
|
|
|
|
/**
|
2018-08-13 18:57:32 -04:00
|
|
|
* @brief Enable GPIO wake-up function.
|
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number.
|
|
|
|
*
|
|
|
|
* @param intr_type GPIO wake-up type. Only GPIO_INTR_LOW_LEVEL or GPIO_INTR_HIGH_LEVEL can be used.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
|
|
|
*/
|
2016-09-21 00:08:42 -04:00
|
|
|
esp_err_t gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type);
|
2016-09-19 05:33:21 -04:00
|
|
|
|
|
|
|
/**
|
2018-08-13 18:57:32 -04:00
|
|
|
* @brief Disable GPIO wake-up function.
|
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
|
|
|
*/
|
2016-09-21 00:08:42 -04:00
|
|
|
esp_err_t gpio_wakeup_disable(gpio_num_t gpio_num);
|
2016-09-19 05:33:21 -04:00
|
|
|
|
|
|
|
/**
|
2017-02-15 21:59:50 -05:00
|
|
|
* @brief Register GPIO interrupt handler, the handler is an ISR.
|
2016-09-19 05:33:21 -04:00
|
|
|
* The handler will be attached to the same CPU core that this function is running on.
|
2016-10-31 23:48:32 -04:00
|
|
|
*
|
2017-02-15 21:59:50 -05:00
|
|
|
* This ISR function is called whenever any GPIO interrupt occurs. See
|
|
|
|
* the alternative gpio_install_isr_service() and
|
|
|
|
* gpio_isr_handler_add() API in order to have the driver support
|
|
|
|
* per-GPIO ISRs.
|
|
|
|
*
|
2016-10-31 23:48:32 -04:00
|
|
|
* @param fn Interrupt handler function.
|
2019-09-02 06:39:39 -04:00
|
|
|
* @param arg Parameter for handler function
|
2016-11-25 04:33:51 -05:00
|
|
|
* @param intr_alloc_flags Flags used to allocate the interrupt. One or multiple (ORred)
|
|
|
|
* ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info.
|
2017-02-15 21:59:50 -05:00
|
|
|
* @param handle Pointer to return handle. If non-NULL, a handle for the interrupt will be returned here.
|
|
|
|
*
|
|
|
|
* \verbatim embed:rst:leading-asterisk
|
2017-03-26 18:01:52 -04:00
|
|
|
* To disable or remove the ISR, pass the returned handle to the :doc:`interrupt allocation functions </api-reference/system/intr_alloc>`.
|
2017-02-15 21:59:50 -05:00
|
|
|
* \endverbatim
|
2016-10-31 23:48:32 -04:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success ;
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO error
|
2018-03-25 22:50:22 -04:00
|
|
|
* - ESP_ERR_NOT_FOUND No free interrupt found with the specified flags
|
2016-09-19 05:33:21 -04:00
|
|
|
*/
|
2019-07-15 02:44:15 -04:00
|
|
|
esp_err_t gpio_isr_register(void (*fn)(void *), void *arg, int intr_alloc_flags, gpio_isr_handle_t *handle);
|
2016-09-19 05:33:21 -04:00
|
|
|
|
2016-11-14 21:29:52 -05:00
|
|
|
/**
|
|
|
|
* @brief Enable pull-up on GPIO.
|
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t gpio_pullup_en(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Disable pull-up on GPIO.
|
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t gpio_pullup_dis(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Enable pull-down on GPIO.
|
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t gpio_pulldown_en(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Disable pull-down on GPIO.
|
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t gpio_pulldown_dis(gpio_num_t gpio_num);
|
|
|
|
|
2016-09-20 21:51:37 -04:00
|
|
|
/**
|
2022-08-24 05:06:20 -04:00
|
|
|
* @brief Install the GPIO driver's ETS_GPIO_INTR_SOURCE ISR handler service, which allows per-pin GPIO interrupt handlers.
|
2017-02-15 21:59:50 -05:00
|
|
|
*
|
2017-05-03 15:40:01 -04:00
|
|
|
* This function is incompatible with gpio_isr_register() - if that function is used, a single global ISR is registered for all GPIO interrupts. If this function is used, the ISR service provides a global GPIO ISR and individual pin handlers are registered via the gpio_isr_handler_add() function.
|
2016-12-24 07:45:57 -05:00
|
|
|
*
|
|
|
|
* @param intr_alloc_flags Flags used to allocate the interrupt. One or multiple (ORred)
|
|
|
|
* ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_NO_MEM No memory to install this service
|
2018-03-25 22:50:22 -04:00
|
|
|
* - ESP_ERR_INVALID_STATE ISR service already installed.
|
|
|
|
* - ESP_ERR_NOT_FOUND No free interrupt found with the specified flags
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO error
|
2016-12-24 07:45:57 -05:00
|
|
|
*/
|
|
|
|
esp_err_t gpio_install_isr_service(int intr_alloc_flags);
|
2016-09-20 21:51:37 -04:00
|
|
|
|
2016-10-31 23:48:32 -04:00
|
|
|
/**
|
2017-02-15 21:59:50 -05:00
|
|
|
* @brief Uninstall the driver's GPIO ISR service, freeing related resources.
|
2016-12-24 07:45:57 -05:00
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
void gpio_uninstall_isr_service(void);
|
2016-10-31 23:48:32 -04:00
|
|
|
|
|
|
|
/**
|
2017-02-15 21:59:50 -05:00
|
|
|
* @brief Add ISR handler for the corresponding GPIO pin.
|
|
|
|
*
|
|
|
|
* Call this function after using gpio_install_isr_service() to
|
|
|
|
* install the driver's GPIO ISR handler service.
|
|
|
|
*
|
|
|
|
* The pin ISR handlers no longer need to be declared with IRAM_ATTR,
|
|
|
|
* unless you pass the ESP_INTR_FLAG_IRAM flag when allocating the
|
|
|
|
* ISR in gpio_install_isr_service().
|
2016-12-24 07:45:57 -05:00
|
|
|
*
|
2017-02-15 21:59:50 -05:00
|
|
|
* This ISR handler will be called from an ISR. So there is a stack
|
|
|
|
* size limit (configurable as "ISR stack size" in menuconfig). This
|
|
|
|
* limit is smaller compared to a global GPIO interrupt handler due
|
|
|
|
* to the additional level of indirection.
|
2016-12-24 07:45:57 -05:00
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number
|
|
|
|
* @param isr_handler ISR handler function for the corresponding GPIO number.
|
|
|
|
* @param args parameter for ISR handler.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_STATE Wrong state, the ISR service has not been initialized.
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
|
|
|
*/
|
2019-07-15 02:44:15 -04:00
|
|
|
esp_err_t gpio_isr_handler_add(gpio_num_t gpio_num, gpio_isr_t isr_handler, void *args);
|
2016-09-19 05:33:21 -04:00
|
|
|
|
|
|
|
/**
|
2017-02-15 21:59:50 -05:00
|
|
|
* @brief Remove ISR handler for the corresponding GPIO pin.
|
2016-12-24 07:45:57 -05:00
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_STATE Wrong state, the ISR service has not been initialized.
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t gpio_isr_handler_remove(gpio_num_t gpio_num);
|
|
|
|
|
2017-07-17 03:38:19 -04:00
|
|
|
/**
|
|
|
|
* @brief Set GPIO pad drive capability
|
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number, only support output GPIOs
|
|
|
|
* @param strength Drive capability of the pad
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t gpio_set_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t strength);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get GPIO pad drive capability
|
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number, only support output GPIOs
|
|
|
|
* @param strength Pointer to accept drive capability of the pad
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
|
|
|
*/
|
2019-07-15 02:44:15 -04:00
|
|
|
esp_err_t gpio_get_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t *strength);
|
2016-09-19 05:33:21 -04:00
|
|
|
|
2018-04-03 10:09:30 -04:00
|
|
|
/**
|
2018-12-07 08:44:43 -05:00
|
|
|
* @brief Enable gpio pad hold function.
|
2018-04-03 10:09:30 -04:00
|
|
|
*
|
2022-12-29 00:14:22 -05:00
|
|
|
* When a GPIO is set to hold, its state is latched at that moment and will not change when the internal
|
|
|
|
* signal or the IO MUX/GPIO configuration is modified (including input enable, output enable, output value,
|
|
|
|
* function, and drive strength values). This function can be used to retain the state of GPIOs when the chip
|
|
|
|
* or system is reset, for example, when watchdog time-out or Deep-sleep events are triggered.
|
2022-10-27 03:09:34 -04:00
|
|
|
*
|
2022-12-29 00:14:22 -05:00
|
|
|
* This function works in both input and output modes, and only applicable to output-capable GPIOs.
|
|
|
|
* If this function is enabled:
|
|
|
|
* in output mode: the output level of the GPIO will be locked and can not be changed.
|
|
|
|
* in input mode: the input read value can still reflect the changes of the input signal.
|
2018-04-03 10:09:30 -04:00
|
|
|
*
|
2023-02-26 10:09:02 -05:00
|
|
|
* However, on ESP32/S2/C3/S3/C2, this function cannot be used to hold the state of a digital GPIO during Deep-sleep.
|
|
|
|
* Even if this function is enabled, the digital GPIO will be reset to its default state when the chip wakes up from
|
|
|
|
* Deep-sleep. If you want to hold the state of a digital GPIO during Deep-sleep, please call `gpio_deep_sleep_hold_en`.
|
2018-12-07 08:44:43 -05:00
|
|
|
*
|
2022-10-27 03:09:34 -04:00
|
|
|
* Power down or call `gpio_hold_dis` will disable this function.
|
2018-04-03 10:09:30 -04:00
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number, only support output-capable GPIOs
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_NOT_SUPPORTED Not support pad hold function
|
|
|
|
*/
|
|
|
|
esp_err_t gpio_hold_en(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
2018-12-07 08:44:43 -05:00
|
|
|
* @brief Disable gpio pad hold function.
|
|
|
|
*
|
|
|
|
* When the chip is woken up from Deep-sleep, the gpio will be set to the default mode, so, the gpio will output
|
2019-07-15 02:44:15 -04:00
|
|
|
* the default level if this function is called. If you don't want the level changes, the gpio should be configured to
|
2018-12-07 08:44:43 -05:00
|
|
|
* a known state before this function is called.
|
|
|
|
* e.g.
|
global: move the soc component out of the common list
This MR removes the common dependency from every IDF components to the SOC component.
Currently, in the ``idf_functions.cmake`` script, we include the header path of SOC component by default for all components.
But for better code organization (or maybe also benifits to the compiling speed), we may remove the dependency to SOC components for most components except the driver and kernel related components.
In CMAKE, we have two kinds of header visibilities (set by include path visibility):
(Assume component A --(depends on)--> B, B is the current component)
1. public (``COMPONENT_ADD_INCLUDEDIRS``): means this path is visible to other depending components (A) (visible to A and B)
2. private (``COMPONENT_PRIV_INCLUDEDIRS``): means this path is only visible to source files inside the component (visible to B only)
and we have two kinds of depending ways:
(Assume component A --(depends on)--> B --(depends on)--> C, B is the current component)
1. public (```COMPONENT_REQUIRES```): means B can access to public include path of C. All other components rely on you (A) will also be available for the public headers. (visible to A, B)
2. private (``COMPONENT_PRIV_REQUIRES``): means B can access to public include path of C, but don't propagate this relation to other components (A). (visible to B)
1. remove the common requirement in ``idf_functions.cmake``, this makes the SOC components invisible to all other components by default.
2. if a component (for example, DRIVER) really needs the dependency to SOC, add a private dependency to SOC for it.
3. some other components that don't really depends on the SOC may still meet some errors saying "can't find header soc/...", this is because it's depended component (DRIVER) incorrectly include the header of SOC in its public headers. Moving all this kind of #include into source files, or private headers
4. Fix the include requirements for some file which miss sufficient #include directives. (Previously they include some headers by the long long long header include link)
This is a breaking change. Previous code may depends on the long include chain.
You may need to include the following headers for some files after this commit:
- soc/soc.h
- soc/soc_memory_layout.h
- driver/gpio.h
- esp_sleep.h
The major broken include chain includes:
1. esp_system.h no longer includes esp_sleep.h. The latter includes driver/gpio.h and driver/touch_pad.h.
2. ets_sys.h no longer includes soc/soc.h
3. freertos/portmacro.h no longer includes soc/soc_memory_layout.h
some peripheral headers no longer includes their hw related headers, e.g. rom/gpio.h no longer includes soc/gpio_pins.h and soc/gpio_reg.h
BREAKING CHANGE
2019-04-03 01:17:38 -04:00
|
|
|
* If you hold gpio18 high during Deep-sleep, after the chip is woken up and `gpio_hold_dis` is called,
|
2018-12-07 08:44:43 -05:00
|
|
|
* gpio18 will output low level(because gpio18 is input mode by default). If you don't want this behavior,
|
|
|
|
* you should configure gpio18 as output mode and set it to hight level before calling `gpio_hold_dis`.
|
2018-04-03 10:09:30 -04:00
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number, only support output-capable GPIOs
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_NOT_SUPPORTED Not support pad hold function
|
|
|
|
*/
|
2018-12-07 08:44:43 -05:00
|
|
|
esp_err_t gpio_hold_dis(gpio_num_t gpio_num);
|
|
|
|
|
2023-02-26 10:09:02 -05:00
|
|
|
#if !SOC_GPIO_SUPPORT_HOLD_SINGLE_IO_IN_DSLP
|
2018-12-07 08:44:43 -05:00
|
|
|
/**
|
2022-10-27 03:09:34 -04:00
|
|
|
* @brief Enable all digital gpio pads hold function during Deep-sleep.
|
|
|
|
*
|
|
|
|
* Enabling this feature makes all digital gpio pads be at the holding state during Deep-sleep. The state of each pad
|
|
|
|
* holds is its active configuration (not pad's sleep configuration!).
|
2018-12-07 08:44:43 -05:00
|
|
|
*
|
2022-10-27 03:09:34 -04:00
|
|
|
* Note that this pad hold feature only works when the chip is in Deep-sleep mode. When the chip is in active mode,
|
|
|
|
* the digital gpio state can be changed freely even you have called this function.
|
2018-12-07 08:44:43 -05:00
|
|
|
*
|
2022-10-27 03:09:34 -04:00
|
|
|
* After this API is being called, the digital gpio Deep-sleep hold feature will work during every sleep process. You
|
|
|
|
* should call `gpio_deep_sleep_hold_dis` to disable this feature.
|
2018-12-07 08:44:43 -05:00
|
|
|
*/
|
|
|
|
void gpio_deep_sleep_hold_en(void);
|
|
|
|
|
|
|
|
/**
|
2022-10-27 03:09:34 -04:00
|
|
|
* @brief Disable all digital gpio pads hold function during Deep-sleep.
|
2018-12-07 08:44:43 -05:00
|
|
|
*/
|
|
|
|
void gpio_deep_sleep_hold_dis(void);
|
2023-02-26 10:09:02 -05:00
|
|
|
#endif //!SOC_GPIO_SUPPORT_HOLD_SINGLE_IO_IN_DSLP
|
2018-04-03 10:09:30 -04:00
|
|
|
|
2018-04-23 13:23:12 -04:00
|
|
|
/**
|
|
|
|
* @brief Set pad input to a peripheral signal through the IOMUX.
|
|
|
|
* @param gpio_num GPIO number of the pad.
|
|
|
|
* @param signal_idx Peripheral signal id to input. One of the ``*_IN_IDX`` signals in ``soc/gpio_sig_map.h``.
|
|
|
|
*/
|
|
|
|
void gpio_iomux_in(uint32_t gpio_num, uint32_t signal_idx);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set peripheral output to an GPIO pad through the IOMUX.
|
|
|
|
* @param gpio_num gpio_num GPIO number of the pad.
|
|
|
|
* @param func The function number of the peripheral pin to output pin.
|
|
|
|
* One of the ``FUNC_X_*`` of specified pin (X) in ``soc/io_mux_reg.h``.
|
2019-07-15 02:44:15 -04:00
|
|
|
* @param oen_inv True if the output enable needs to be inverted, otherwise False.
|
2018-04-23 13:23:12 -04:00
|
|
|
*/
|
|
|
|
void gpio_iomux_out(uint8_t gpio_num, int func, bool oen_inv);
|
|
|
|
|
2020-09-09 22:37:58 -04:00
|
|
|
#if SOC_GPIO_SUPPORT_FORCE_HOLD
|
2019-06-13 03:37:58 -04:00
|
|
|
/**
|
2022-10-27 03:09:34 -04:00
|
|
|
* @brief Force hold all digital and rtc gpio pads.
|
|
|
|
*
|
|
|
|
* GPIO force hold, no matter the chip in active mode or sleep modes.
|
|
|
|
*
|
|
|
|
* This function will immediately cause all pads to latch the current values of input enable, output enable,
|
|
|
|
* output value, function, and drive strength values.
|
|
|
|
*
|
|
|
|
* @warning This function will hold flash and UART pins as well. Therefore, this function, and all code run afterwards
|
|
|
|
* (till calling `gpio_force_unhold_all` to disable this feature), MUST be placed in internal RAM as holding the flash
|
|
|
|
* pins will halt SPI flash operation, and holding the UART pins will halt any UART logging.
|
2019-06-13 03:37:58 -04:00
|
|
|
* */
|
|
|
|
esp_err_t gpio_force_hold_all(void);
|
|
|
|
|
|
|
|
/**
|
2022-10-27 03:09:34 -04:00
|
|
|
* @brief Force unhold all digital and rtc gpio pads.
|
2019-06-13 03:37:58 -04:00
|
|
|
* */
|
|
|
|
esp_err_t gpio_force_unhold_all(void);
|
|
|
|
#endif
|
|
|
|
|
2020-11-12 07:39:55 -05:00
|
|
|
/**
|
|
|
|
* @brief Enable SLP_SEL to change GPIO status automantically in lightsleep.
|
|
|
|
* @param gpio_num GPIO number of the pad.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
esp_err_t gpio_sleep_sel_en(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Disable SLP_SEL to change GPIO status automantically in lightsleep.
|
|
|
|
* @param gpio_num GPIO number of the pad.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
*/
|
|
|
|
esp_err_t gpio_sleep_sel_dis(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
2022-08-22 10:03:30 -04:00
|
|
|
* @brief GPIO set direction at sleep
|
2020-11-12 07:39:55 -05:00
|
|
|
*
|
|
|
|
* Configure GPIO direction,such as output_only,input_only,output_and_input
|
|
|
|
*
|
|
|
|
* @param gpio_num Configure GPIO pins number, it should be GPIO number. If you want to set direction of e.g. GPIO16, gpio_num should be GPIO_NUM_16 (16);
|
|
|
|
* @param mode GPIO direction
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO error
|
|
|
|
*/
|
|
|
|
esp_err_t gpio_sleep_set_direction(gpio_num_t gpio_num, gpio_mode_t mode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Configure GPIO pull-up/pull-down resistors at sleep
|
|
|
|
*
|
2022-06-22 02:45:15 -04:00
|
|
|
* @note ESP32: Only pins that support both input & output have integrated pull-up and pull-down resistors. Input-only GPIOs 34-39 do not.
|
2020-11-12 07:39:55 -05:00
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number. If you want to set pull up or down mode for e.g. GPIO16, gpio_num should be GPIO_NUM_16 (16);
|
|
|
|
* @param pull GPIO pull up/down mode.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG : Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t gpio_sleep_set_pull_mode(gpio_num_t gpio_num, gpio_pull_mode_t pull);
|
|
|
|
|
2021-02-05 04:10:44 -05:00
|
|
|
#if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
|
|
|
|
|
2022-04-11 01:58:00 -04:00
|
|
|
#define GPIO_IS_DEEP_SLEEP_WAKEUP_VALID_GPIO(gpio_num) ((gpio_num >= 0) && \
|
|
|
|
(((1ULL << (gpio_num)) & SOC_GPIO_DEEP_SLEEP_WAKE_VALID_GPIO_MASK) != 0))
|
2021-02-05 04:10:44 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Enable GPIO deep-sleep wake-up function.
|
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number.
|
|
|
|
*
|
|
|
|
* @param intr_type GPIO wake-up type. Only GPIO_INTR_LOW_LEVEL or GPIO_INTR_HIGH_LEVEL can be used.
|
|
|
|
*
|
|
|
|
* @note Called by the SDK. User shouldn't call this directly in the APP.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t gpio_deep_sleep_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Disable GPIO deep-sleep wake-up function.
|
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t gpio_deep_sleep_wakeup_disable(gpio_num_t gpio_num);
|
|
|
|
|
2023-09-22 05:36:51 -04:00
|
|
|
#endif //SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Dump IO configuration information to console
|
|
|
|
*
|
|
|
|
* @param out_stream IO stream (e.g. stdout)
|
|
|
|
* @param io_bit_mask IO pin bit mask, each bit maps to an IO
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t gpio_dump_io_configuration(FILE *out_stream, uint64_t io_bit_mask);
|
2021-02-05 04:10:44 -05:00
|
|
|
|
2016-09-19 05:33:21 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|