mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-30 19:19:21 +00:00
refactor(gpio): make gpio driver as component, and fix astyle
This commit is contained in:
184
components/esp_driver_gpio/include/driver/dedic_gpio.h
Normal file
184
components/esp_driver_gpio/include/driver/dedic_gpio.h
Normal file
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_attr.h"
|
||||
#include "soc/soc_caps.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Type of Dedicated GPIO bundle
|
||||
*/
|
||||
typedef struct dedic_gpio_bundle_t *dedic_gpio_bundle_handle_t;
|
||||
|
||||
/**
|
||||
* @brief Type of Dedicated GPIO bundle configuration
|
||||
*/
|
||||
typedef struct {
|
||||
const int *gpio_array; /*!< Array of GPIO numbers, gpio_array[0] ~ gpio_array[size-1] <=> low_dedic_channel_num ~ high_dedic_channel_num */
|
||||
size_t array_size; /*!< Number of GPIOs in gpio_array */
|
||||
struct {
|
||||
unsigned int in_en: 1; /*!< Enable input */
|
||||
unsigned int in_invert: 1; /*!< Invert input signal */
|
||||
unsigned int out_en: 1; /*!< Enable output */
|
||||
unsigned int out_invert: 1; /*!< Invert output signal */
|
||||
} flags; /*!< Flags to control specific behaviour of GPIO bundle */
|
||||
} dedic_gpio_bundle_config_t;
|
||||
|
||||
/**
|
||||
* @brief Create GPIO bundle and return the handle
|
||||
*
|
||||
* @param[in] config Configuration of GPIO bundle
|
||||
* @param[out] ret_bundle Returned handle of the new created GPIO bundle
|
||||
* @return
|
||||
* - ESP_OK: Create GPIO bundle successfully
|
||||
* - ESP_ERR_INVALID_ARG: Create GPIO bundle failed because of invalid argument
|
||||
* - ESP_ERR_NO_MEM: Create GPIO bundle failed because of no capable memory
|
||||
* - ESP_ERR_NOT_FOUND: Create GPIO bundle failed because of no enough continuous dedicated channels
|
||||
* - ESP_FAIL: Create GPIO bundle failed because of other error
|
||||
*
|
||||
* @note One has to enable at least input or output mode in "config" parameter.
|
||||
*/
|
||||
esp_err_t dedic_gpio_new_bundle(const dedic_gpio_bundle_config_t *config, dedic_gpio_bundle_handle_t *ret_bundle);
|
||||
|
||||
/**
|
||||
* @brief Destroy GPIO bundle
|
||||
*
|
||||
* @param[in] bundle Handle of GPIO bundle that returned from "dedic_gpio_new_bundle"
|
||||
* @return
|
||||
* - ESP_OK: Destroy GPIO bundle successfully
|
||||
* - ESP_ERR_INVALID_ARG: Destroy GPIO bundle failed because of invalid argument
|
||||
* - ESP_FAIL: Destroy GPIO bundle failed because of other error
|
||||
*/
|
||||
esp_err_t dedic_gpio_del_bundle(dedic_gpio_bundle_handle_t bundle);
|
||||
|
||||
/**@{*/
|
||||
/**
|
||||
* @brief Get allocated channel mask
|
||||
*
|
||||
* @param[in] bundle Handle of GPIO bundle that returned from "dedic_gpio_new_bundle"
|
||||
* @param[out] mask Returned mask value for on specific direction (in or out)
|
||||
* @return
|
||||
* - ESP_OK: Get channel mask successfully
|
||||
* - ESP_ERR_INVALID_ARG: Get channel mask failed because of invalid argument
|
||||
* - ESP_FAIL: Get channel mask failed because of other error
|
||||
*
|
||||
* @note Each bundle should have at least one mask (in or/and out), based on bundle configuration.
|
||||
* @note With the returned mask, user can directly invoke LL function like "dedic_gpio_cpu_ll_write_mask"
|
||||
* or write assembly code with dedicated GPIO instructions, to get better performance on GPIO manipulation.
|
||||
*/
|
||||
esp_err_t dedic_gpio_get_out_mask(dedic_gpio_bundle_handle_t bundle, uint32_t *mask);
|
||||
esp_err_t dedic_gpio_get_in_mask(dedic_gpio_bundle_handle_t bundle, uint32_t *mask);
|
||||
/**@}*/
|
||||
|
||||
/**@{*/
|
||||
/**
|
||||
* @brief Get the channel offset of the GPIO bundle
|
||||
*
|
||||
* A GPIO bundle maps the GPIOS of a particular direction to a consecutive set of channels within
|
||||
* a particular GPIO bank of a particular CPU. This function returns the offset to
|
||||
* the bundle's first channel of a particular direction within the bank.
|
||||
*
|
||||
* @param[in] bundle Handle of GPIO bundle that returned from "dedic_gpio_new_bundle"
|
||||
* @param[out] offset Offset value to the first channel of a specific direction (in or out)
|
||||
* @return
|
||||
* - ESP_OK: Get channel offset successfully
|
||||
* - ESP_ERR_INVALID_ARG: Get channel offset failed because of invalid argument
|
||||
* - ESP_FAIL: Get channel offset failed because of other error
|
||||
*/
|
||||
esp_err_t dedic_gpio_get_out_offset(dedic_gpio_bundle_handle_t bundle, uint32_t *offset);
|
||||
esp_err_t dedic_gpio_get_in_offset(dedic_gpio_bundle_handle_t bundle, uint32_t *offset);
|
||||
/**@}*/
|
||||
|
||||
/**
|
||||
* @brief Write value to GPIO bundle
|
||||
*
|
||||
* @param[in] bundle Handle of GPIO bundle that returned from "dedic_gpio_new_bundle"
|
||||
* @param[in] mask Mask of the GPIOs to be written in the given bundle
|
||||
* @param[in] value Value to write to given GPIO bundle, low bit represents low member in the bundle
|
||||
*
|
||||
* @note The mask is seen from the view of GPIO bundle.
|
||||
* For example, bundleA contains [GPIO10, GPIO12, GPIO17], to set GPIO17 individually, the mask should be 0x04.
|
||||
* @note For performance reasons, this function doesn't check the validity of any parameters, and is placed in IRAM.
|
||||
*/
|
||||
void dedic_gpio_bundle_write(dedic_gpio_bundle_handle_t bundle, uint32_t mask, uint32_t value) IRAM_ATTR;
|
||||
|
||||
/**
|
||||
* @brief Read the value that output from the given GPIO bundle
|
||||
*
|
||||
* @param[in] bundle Handle of GPIO bundle that returned from "dedic_gpio_new_bundle"
|
||||
* @return Value that output from the GPIO bundle, low bit represents low member in the bundle
|
||||
*
|
||||
* @note For performance reasons, this function doesn't check the validity of any parameters, and is placed in IRAM.
|
||||
*/
|
||||
uint32_t dedic_gpio_bundle_read_out(dedic_gpio_bundle_handle_t bundle) IRAM_ATTR;
|
||||
|
||||
/**
|
||||
* @brief Read the value that input to the given GPIO bundle
|
||||
*
|
||||
* @param[in] bundle Handle of GPIO bundle that returned from "dedic_gpio_new_bundle"
|
||||
* @return Value that input to the GPIO bundle, low bit represents low member in the bundle
|
||||
*
|
||||
* @note For performance reasons, this function doesn't check the validity of any parameters, and is placed in IRAM.
|
||||
*/
|
||||
uint32_t dedic_gpio_bundle_read_in(dedic_gpio_bundle_handle_t bundle) IRAM_ATTR;
|
||||
|
||||
#if SOC_DEDIC_GPIO_HAS_INTERRUPT
|
||||
|
||||
/**
|
||||
* @brief Supported type of dedicated GPIO interrupt
|
||||
*/
|
||||
typedef enum {
|
||||
DEDIC_GPIO_INTR_NONE, /*!< No interrupt */
|
||||
DEDIC_GPIO_INTR_LOW_LEVEL = 2, /*!< Interrupt on low level */
|
||||
DEDIC_GPIO_INTR_HIGH_LEVEL, /*!< Interrupt on high level */
|
||||
DEDIC_GPIO_INTR_NEG_EDGE, /*!< Interrupt on negedge */
|
||||
DEDIC_GPIO_INTR_POS_EDGE, /*!< Interrupt on posedge */
|
||||
DEDIC_GPIO_INTR_BOTH_EDGE /*!< Interrupt on both negedge and posedge */
|
||||
} dedic_gpio_intr_type_t;
|
||||
|
||||
/**
|
||||
* @brief Type of dedicated GPIO ISR callback function
|
||||
*
|
||||
* @param bundle Handle of GPIO bundle that returned from "dedic_gpio_new_bundle"
|
||||
* @param index Index of the GPIO in its corresponding bundle (count from 0)
|
||||
* @param args User defined arguments for the callback function. It's passed through `dedic_gpio_bundle_set_interrupt_and_callback`
|
||||
* @return If a high priority task is woken up by the callback function
|
||||
*/
|
||||
typedef bool (*dedic_gpio_isr_callback_t)(dedic_gpio_bundle_handle_t bundle, uint32_t index, void *args);
|
||||
|
||||
/**
|
||||
* @brief Set interrupt and callback function for GPIO bundle
|
||||
*
|
||||
* @param[in] bundle Handle of GPIO bundle that returned from "dedic_gpio_new_bundle"
|
||||
* @param[in] mask Mask of the GPIOs in the given bundle
|
||||
* @param[in] intr_type Interrupt type, set to DEDIC_GPIO_INTR_NONE can disable interrupt
|
||||
* @param[in] cb_isr Callback function, which got invoked in ISR context. A NULL pointer here will bypass the callback
|
||||
* @param[in] cb_args User defined argument to be passed to the callback function
|
||||
*
|
||||
* @note This function is only valid for bundle with input mode enabled. See "dedic_gpio_bundle_config_t"
|
||||
* @note The mask is seen from the view of GPIO Bundle.
|
||||
* For example, bundleA contains [GPIO10, GPIO12, GPIO17], to set GPIO17 individually, the mask should be 0x04.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Set GPIO interrupt and callback function successfully
|
||||
* - ESP_ERR_INVALID_ARG: Set GPIO interrupt and callback function failed because of invalid argument
|
||||
* - ESP_FAIL: Set GPIO interrupt and callback function failed because of other error
|
||||
*/
|
||||
esp_err_t dedic_gpio_bundle_set_interrupt_and_callback(dedic_gpio_bundle_handle_t bundle, uint32_t mask, dedic_gpio_intr_type_t intr_type, dedic_gpio_isr_callback_t cb_isr, void *cb_args);
|
||||
|
||||
#endif // SOC_DEDIC_GPIO_HAS_INTERRUPT
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
563
components/esp_driver_gpio/include/driver/gpio.h
Normal file
563
components/esp_driver_gpio/include/driver/gpio.h
Normal file
@@ -0,0 +1,563 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_intr_alloc.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "hal/gpio_types.h"
|
||||
#include "esp_rom_gpio.h"
|
||||
#include "driver/gpio_etm.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define GPIO_PIN_COUNT (SOC_GPIO_PIN_COUNT)
|
||||
/// Check whether it is a valid GPIO number
|
||||
#define GPIO_IS_VALID_GPIO(gpio_num) ((gpio_num >= 0) && \
|
||||
(((1ULL << (gpio_num)) & SOC_GPIO_VALID_GPIO_MASK) != 0))
|
||||
/// Check whether it can be a valid GPIO number of output mode
|
||||
#define GPIO_IS_VALID_OUTPUT_GPIO(gpio_num) ((gpio_num >= 0) && \
|
||||
(((1ULL << (gpio_num)) & SOC_GPIO_VALID_OUTPUT_GPIO_MASK) != 0))
|
||||
/// 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))
|
||||
|
||||
typedef intr_handle_t gpio_isr_handle_t;
|
||||
|
||||
/**
|
||||
* @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 */
|
||||
#if SOC_GPIO_SUPPORT_PIN_HYS_FILTER
|
||||
gpio_hys_ctrl_mode_t hys_ctrl_mode; /*!< GPIO hysteresis: hysteresis filter on slope input */
|
||||
#endif
|
||||
} gpio_config_t;
|
||||
|
||||
/**
|
||||
* @brief GPIO common configuration
|
||||
*
|
||||
* Configure GPIO's Mode,pull-up,PullDown,IntrType
|
||||
*
|
||||
* @param pGPIOConfig Pointer to GPIO configure struct
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*
|
||||
*/
|
||||
esp_err_t gpio_config(const gpio_config_t *pGPIOConfig);
|
||||
|
||||
/**
|
||||
* @brief Reset an gpio to default state (select gpio function, enable pullup and disable input and output).
|
||||
*
|
||||
* @param gpio_num GPIO number.
|
||||
*
|
||||
* @note This function also configures the IOMUX for this pin to the GPIO
|
||||
* function, and disconnects any other peripheral output configured via GPIO
|
||||
* Matrix.
|
||||
*
|
||||
* @return Always return ESP_OK.
|
||||
*/
|
||||
esp_err_t gpio_reset_pin(gpio_num_t gpio_num);
|
||||
|
||||
/**
|
||||
* @brief GPIO set interrupt trigger type
|
||||
*
|
||||
* @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);
|
||||
* @param intr_type Interrupt type, select from gpio_int_type_t
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*
|
||||
*/
|
||||
esp_err_t gpio_set_intr_type(gpio_num_t gpio_num, gpio_int_type_t intr_type);
|
||||
|
||||
/**
|
||||
* @brief Enable GPIO module interrupt signal
|
||||
*
|
||||
* @note ESP32: Please do not use the interrupt of GPIO36 and GPIO39 when using ADC or Wi-Fi and Bluetooth with sleep mode enabled.
|
||||
* Please refer to the comments of `adc1_get_raw`.
|
||||
* 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.
|
||||
|
||||
*
|
||||
* @param gpio_num GPIO number. If you want to enable an interrupt on e.g. GPIO16, gpio_num should be GPIO_NUM_16 (16);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*
|
||||
*/
|
||||
esp_err_t gpio_intr_enable(gpio_num_t gpio_num);
|
||||
|
||||
/**
|
||||
* @brief Disable GPIO module interrupt signal
|
||||
*
|
||||
* @note This function is allowed to be executed when Cache is disabled within ISR context, by enabling `CONFIG_GPIO_CTRL_FUNC_IN_IRAM`
|
||||
*
|
||||
* @param gpio_num GPIO number. If you want to disable the interrupt of e.g. GPIO16, gpio_num should be GPIO_NUM_16 (16);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*
|
||||
*/
|
||||
esp_err_t gpio_intr_disable(gpio_num_t gpio_num);
|
||||
|
||||
/**
|
||||
* @brief GPIO set output level
|
||||
*
|
||||
* @note This function is allowed to be executed when Cache is disabled within ISR context, by enabling `CONFIG_GPIO_CTRL_FUNC_IN_IRAM`
|
||||
*
|
||||
* @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);
|
||||
* @param level Output level. 0: low ; 1: high
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG GPIO number error
|
||||
*
|
||||
*/
|
||||
esp_err_t gpio_set_level(gpio_num_t gpio_num, uint32_t level);
|
||||
|
||||
/**
|
||||
* @brief GPIO get input level
|
||||
*
|
||||
* @warning If the pad is not configured for input (or input and output) the returned value is always 0.
|
||||
*
|
||||
* @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);
|
||||
*
|
||||
* @return
|
||||
* - 0 the GPIO input level is 0
|
||||
* - 1 the GPIO input level is 1
|
||||
*
|
||||
*/
|
||||
int gpio_get_level(gpio_num_t gpio_num);
|
||||
|
||||
/**
|
||||
* @brief GPIO set direction
|
||||
*
|
||||
* 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_set_direction(gpio_num_t gpio_num, gpio_mode_t mode);
|
||||
|
||||
/**
|
||||
* @brief Configure GPIO pull-up/pull-down resistors
|
||||
*
|
||||
* @note ESP32: Only pins that support both input & output have integrated pull-up and pull-down resistors. Input-only GPIOs 34-39 do not.
|
||||
*
|
||||
* @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_set_pull_mode(gpio_num_t gpio_num, gpio_pull_mode_t pull);
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
esp_err_t gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type);
|
||||
|
||||
/**
|
||||
* @brief Disable GPIO wake-up function.
|
||||
*
|
||||
* @param gpio_num GPIO number
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t gpio_wakeup_disable(gpio_num_t gpio_num);
|
||||
|
||||
/**
|
||||
* @brief Register GPIO interrupt handler, the handler is an ISR.
|
||||
* The handler will be attached to the same CPU core that this function is running on.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @param fn Interrupt handler function.
|
||||
* @param arg Parameter for handler function
|
||||
* @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.
|
||||
* @param handle Pointer to return handle. If non-NULL, a handle for the interrupt will be returned here.
|
||||
*
|
||||
* \verbatim embed:rst:leading-asterisk
|
||||
* To disable or remove the ISR, pass the returned handle to the :doc:`interrupt allocation functions </api-reference/system/intr_alloc>`.
|
||||
* \endverbatim
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success ;
|
||||
* - ESP_ERR_INVALID_ARG GPIO error
|
||||
* - ESP_ERR_NOT_FOUND No free interrupt found with the specified flags
|
||||
*/
|
||||
esp_err_t gpio_isr_register(void (*fn)(void *), void *arg, int intr_alloc_flags, gpio_isr_handle_t *handle);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @brief Install the GPIO driver's ETS_GPIO_INTR_SOURCE ISR handler service, which allows per-pin GPIO interrupt handlers.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @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
|
||||
* - 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
|
||||
*/
|
||||
esp_err_t gpio_install_isr_service(int intr_alloc_flags);
|
||||
|
||||
/**
|
||||
* @brief Uninstall the driver's GPIO ISR service, freeing related resources.
|
||||
*/
|
||||
void gpio_uninstall_isr_service(void);
|
||||
|
||||
/**
|
||||
* @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().
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
esp_err_t gpio_isr_handler_add(gpio_num_t gpio_num, gpio_isr_t isr_handler, void *args);
|
||||
|
||||
/**
|
||||
* @brief Remove ISR handler for the corresponding GPIO pin.
|
||||
*
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
esp_err_t gpio_get_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t *strength);
|
||||
|
||||
/**
|
||||
* @brief Enable gpio pad hold function.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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`.
|
||||
*
|
||||
* Power down or call `gpio_hold_dis` will disable this function.
|
||||
*
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @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
|
||||
* the default level if this function is called. If you don't want the level changes, the gpio should be configured to
|
||||
* a known state before this function is called.
|
||||
* e.g.
|
||||
* If you hold gpio18 high during Deep-sleep, after the chip is woken up and `gpio_hold_dis` is called,
|
||||
* 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`.
|
||||
*
|
||||
* @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_dis(gpio_num_t gpio_num);
|
||||
|
||||
#if !SOC_GPIO_SUPPORT_HOLD_SINGLE_IO_IN_DSLP
|
||||
/**
|
||||
* @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!).
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
void gpio_deep_sleep_hold_en(void);
|
||||
|
||||
/**
|
||||
* @brief Disable all digital gpio pads hold function during Deep-sleep.
|
||||
*/
|
||||
void gpio_deep_sleep_hold_dis(void);
|
||||
#endif //!SOC_GPIO_SUPPORT_HOLD_SINGLE_IO_IN_DSLP
|
||||
|
||||
/**
|
||||
* @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``.
|
||||
* @param oen_inv True if the output enable needs to be inverted, otherwise False.
|
||||
*/
|
||||
void gpio_iomux_out(uint8_t gpio_num, int func, bool oen_inv);
|
||||
|
||||
#if SOC_GPIO_SUPPORT_FORCE_HOLD
|
||||
/**
|
||||
* @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.
|
||||
* */
|
||||
esp_err_t gpio_force_hold_all(void);
|
||||
|
||||
/**
|
||||
* @brief Force unhold all digital and rtc gpio pads.
|
||||
* */
|
||||
esp_err_t gpio_force_unhold_all(void);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @brief GPIO set direction at sleep
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* @note ESP32: Only pins that support both input & output have integrated pull-up and pull-down resistors. Input-only GPIOs 34-39 do not.
|
||||
*
|
||||
* @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);
|
||||
|
||||
#if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
|
||||
|
||||
#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))
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
#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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
132
components/esp_driver_gpio/include/driver/gpio_etm.h
Normal file
132
components/esp_driver_gpio/include/driver/gpio_etm.h
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_etm.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief GPIO edges that can be used as ETM event
|
||||
*/
|
||||
typedef enum {
|
||||
GPIO_ETM_EVENT_EDGE_POS, /*!< A rising edge on the GPIO will generate an ETM event signal */
|
||||
GPIO_ETM_EVENT_EDGE_NEG, /*!< A falling edge on the GPIO will generate an ETM event signal */
|
||||
GPIO_ETM_EVENT_EDGE_ANY, /*!< Any edge on the GPIO can generate an ETM event signal */
|
||||
} gpio_etm_event_edge_t;
|
||||
|
||||
/**
|
||||
* @brief GPIO ETM event configuration
|
||||
*/
|
||||
typedef struct {
|
||||
gpio_etm_event_edge_t edge; /*!< Which kind of edge can trigger the ETM event module */
|
||||
} gpio_etm_event_config_t;
|
||||
|
||||
/**
|
||||
* @brief Create an ETM event object for the GPIO peripheral
|
||||
*
|
||||
* @note The created ETM event object can be deleted later by calling `esp_etm_del_event`
|
||||
* @note The newly created ETM event object is not bind to any GPIO, you need to call `gpio_etm_event_bind_gpio` to bind the wanted GPIO
|
||||
*
|
||||
* @param[in] config GPIO ETM event configuration
|
||||
* @param[out] ret_event Returned ETM event handle
|
||||
* @return
|
||||
* - ESP_OK: Create ETM event successfully
|
||||
* - ESP_ERR_INVALID_ARG: Create ETM event failed because of invalid argument
|
||||
* - ESP_ERR_NO_MEM: Create ETM event failed because of out of memory
|
||||
* - ESP_ERR_NOT_FOUND: Create ETM event failed because all events are used up and no more free one
|
||||
* - ESP_FAIL: Create ETM event failed because of other reasons
|
||||
*/
|
||||
esp_err_t gpio_new_etm_event(const gpio_etm_event_config_t *config, esp_etm_event_handle_t *ret_event);
|
||||
|
||||
/**
|
||||
* @brief Bind the GPIO with the ETM event
|
||||
*
|
||||
* @note Calling this function multiple times with different GPIO number can override the previous setting immediately.
|
||||
* @note Only GPIO ETM object can call this function
|
||||
*
|
||||
* @param[in] event ETM event handle that created by `gpio_new_etm_event`
|
||||
* @param[in] gpio_num GPIO number that can trigger the ETM event
|
||||
* @return
|
||||
* - ESP_OK: Set the GPIO for ETM event successfully
|
||||
* - ESP_ERR_INVALID_ARG: Set the GPIO for ETM event failed because of invalid argument, e.g. GPIO is not input capable, ETM event is not of GPIO type
|
||||
* - ESP_FAIL: Set the GPIO for ETM event failed because of other reasons
|
||||
*/
|
||||
esp_err_t gpio_etm_event_bind_gpio(esp_etm_event_handle_t event, int gpio_num);
|
||||
|
||||
/**
|
||||
* @brief GPIO actions that can be taken by the ETM task
|
||||
*/
|
||||
typedef enum {
|
||||
GPIO_ETM_TASK_ACTION_SET, /*!< Set the GPIO level to high */
|
||||
GPIO_ETM_TASK_ACTION_CLR, /*!< Clear the GPIO level to low */
|
||||
GPIO_ETM_TASK_ACTION_TOG, /*!< Toggle the GPIO level */
|
||||
} gpio_etm_task_action_t;
|
||||
|
||||
/**
|
||||
* @brief GPIO ETM task configuration
|
||||
*/
|
||||
typedef struct {
|
||||
gpio_etm_task_action_t action; /*!< Which action to take by the ETM task module */
|
||||
} gpio_etm_task_config_t;
|
||||
|
||||
/**
|
||||
* @brief Create an ETM task object for the GPIO peripheral
|
||||
*
|
||||
* @note The created ETM task object can be deleted later by calling `esp_etm_del_task`
|
||||
* @note The GPIO ETM task works like a container, a newly created ETM task object doesn't have GPIO members to be managed.
|
||||
* You need to call `gpio_etm_task_add_gpio` to put one or more GPIOs to the container.
|
||||
*
|
||||
* @param[in] config GPIO ETM task configuration
|
||||
* @param[out] ret_task Returned ETM task handle
|
||||
* @return
|
||||
* - ESP_OK: Create ETM task successfully
|
||||
* - ESP_ERR_INVALID_ARG: Create ETM task failed because of invalid argument
|
||||
* - ESP_ERR_NO_MEM: Create ETM task failed because of out of memory
|
||||
* - ESP_ERR_NOT_FOUND: Create ETM task failed because all tasks are used up and no more free one
|
||||
* - ESP_FAIL: Create ETM task failed because of other reasons
|
||||
*/
|
||||
esp_err_t gpio_new_etm_task(const gpio_etm_task_config_t *config, esp_etm_task_handle_t *ret_task);
|
||||
|
||||
/**
|
||||
* @brief Add GPIO to the ETM task.
|
||||
*
|
||||
* @note You can call this function multiple times to add more GPIOs
|
||||
* @note Only GPIO ETM object can call this function
|
||||
*
|
||||
* @param[in] task ETM task handle that created by `gpio_new_etm_task`
|
||||
* @param[in] gpio_num GPIO number that can be controlled by the ETM task
|
||||
* @return
|
||||
* - ESP_OK: Add GPIO to the ETM task successfully
|
||||
* - ESP_ERR_INVALID_ARG: Add GPIO to the ETM task failed because of invalid argument, e.g. GPIO is not output capable, ETM task is not of GPIO type
|
||||
* - ESP_ERR_INVALID_STATE: Add GPIO to the ETM task failed because the GPIO is used by other ETM task already
|
||||
* - ESP_FAIL: Add GPIO to the ETM task failed because of other reasons
|
||||
*/
|
||||
esp_err_t gpio_etm_task_add_gpio(esp_etm_task_handle_t task, int gpio_num);
|
||||
|
||||
/**
|
||||
* @brief Remove the GPIO from the ETM task
|
||||
*
|
||||
* @note Before deleting the ETM task, you need to remove all the GPIOs from the ETM task by this function
|
||||
* @note Only GPIO ETM object can call this function
|
||||
*
|
||||
* @param[in] task ETM task handle that created by `gpio_new_etm_task`
|
||||
* @param[in] gpio_num GPIO number that to be remove from the ETM task
|
||||
* @return
|
||||
* - ESP_OK: Remove the GPIO from the ETM task successfully
|
||||
* - ESP_ERR_INVALID_ARG: Remove the GPIO from the ETM task failed because of invalid argument
|
||||
* - ESP_ERR_INVALID_STATE: Remove the GPIO from the ETM task failed because the GPIO is not controlled by this ETM task
|
||||
* - ESP_FAIL: Remove the GPIO from the ETM task failed because of other reasons
|
||||
*/
|
||||
esp_err_t gpio_etm_task_rm_gpio(esp_etm_task_handle_t task, int gpio_num);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
115
components/esp_driver_gpio/include/driver/gpio_filter.h
Normal file
115
components/esp_driver_gpio/include/driver/gpio_filter.h
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "esp_err.h"
|
||||
#include "hal/glitch_filter_types.h"
|
||||
#include "driver/gpio.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Typedef of GPIO glitch filter handle
|
||||
*/
|
||||
typedef struct gpio_glitch_filter_t *gpio_glitch_filter_handle_t;
|
||||
|
||||
/**
|
||||
* @brief Configuration of GPIO pin glitch filter
|
||||
*/
|
||||
typedef struct {
|
||||
glitch_filter_clock_source_t clk_src; /*!< Clock source for the glitch filter */
|
||||
gpio_num_t gpio_num; /*!< GPIO number */
|
||||
} gpio_pin_glitch_filter_config_t;
|
||||
|
||||
/**
|
||||
* @brief Create a pin glitch filter
|
||||
*
|
||||
* @note Pin glitch filter parameters are fixed, pulses shorter than two sample clocks (IO-MUX's source clock) will be filtered out.
|
||||
* It's independent with "flex" glitch filter. See also `gpio_new_flex_glitch_filter`.
|
||||
* @note The created filter handle can later be deleted by `gpio_del_glitch_filter`.
|
||||
*
|
||||
* @param[in] config Glitch filter configuration
|
||||
* @param[out] ret_filter Returned glitch filter handle
|
||||
* @return
|
||||
* - ESP_OK: Create a pin glitch filter successfully
|
||||
* - ESP_ERR_INVALID_ARG: Create a pin glitch filter failed because of invalid arguments (e.g. wrong GPIO number)
|
||||
* - ESP_ERR_NO_MEM: Create a pin glitch filter failed because of out of memory
|
||||
* - ESP_FAIL: Create a pin glitch filter failed because of other error
|
||||
*/
|
||||
esp_err_t gpio_new_pin_glitch_filter(const gpio_pin_glitch_filter_config_t *config, gpio_glitch_filter_handle_t *ret_filter);
|
||||
|
||||
/**
|
||||
* @brief Configuration of GPIO flex glitch filter
|
||||
*/
|
||||
typedef struct {
|
||||
glitch_filter_clock_source_t clk_src; /*!< Clock source for the glitch filter */
|
||||
gpio_num_t gpio_num; /*!< GPIO number */
|
||||
uint32_t window_width_ns; /*!< Sample window width (in ns) */
|
||||
uint32_t window_thres_ns; /*!< Sample window threshold (in ns), during the `window_width_ns` sample window, any pulse whose width < window_thres_ns will be discarded. */
|
||||
} gpio_flex_glitch_filter_config_t;
|
||||
|
||||
/**
|
||||
* @brief Allocate a flex glitch filter
|
||||
*
|
||||
* @note "flex" means the filter parameters (window, threshold) are adjustable. It's independent with pin glitch filter.
|
||||
* See also `gpio_new_pin_glitch_filter`.
|
||||
* @note The created filter handle can later be deleted by `gpio_del_glitch_filter`.
|
||||
*
|
||||
* @param[in] config Glitch filter configuration
|
||||
* @param[out] ret_filter Returned glitch filter handle
|
||||
* @return
|
||||
* - ESP_OK: Allocate a flex glitch filter successfully
|
||||
* - ESP_ERR_INVALID_ARG: Allocate a flex glitch filter failed because of invalid arguments (e.g. wrong GPIO number, filter parameters out of range)
|
||||
* - ESP_ERR_NO_MEM: Allocate a flex glitch filter failed because of out of memory
|
||||
* - ESP_ERR_NOT_FOUND: Allocate a flex glitch filter failed because the underlying hardware resources are used up
|
||||
* - ESP_FAIL: Allocate a flex glitch filter failed because of other error
|
||||
*/
|
||||
esp_err_t gpio_new_flex_glitch_filter(const gpio_flex_glitch_filter_config_t *config, gpio_glitch_filter_handle_t *ret_filter);
|
||||
|
||||
/**
|
||||
* @brief Delete a glitch filter
|
||||
*
|
||||
* @param[in] filter Glitch filter handle returned from `gpio_new_flex_glitch_filter` or `gpio_new_pin_glitch_filter`
|
||||
* @return
|
||||
* - ESP_OK: Delete glitch filter successfully
|
||||
* - ESP_ERR_INVALID_ARG: Delete glitch filter failed because of invalid arguments
|
||||
* - ESP_ERR_INVALID_STATE: Delete glitch filter failed because the glitch filter is still in working
|
||||
* - ESP_FAIL: Delete glitch filter failed because of other error
|
||||
*/
|
||||
esp_err_t gpio_del_glitch_filter(gpio_glitch_filter_handle_t filter);
|
||||
|
||||
/**
|
||||
* @brief Enable a glitch filter
|
||||
*
|
||||
* @param[in] filter Glitch filter handle returned from `gpio_new_flex_glitch_filter` or `gpio_new_pin_glitch_filter`
|
||||
* @return
|
||||
* - ESP_OK: Enable glitch filter successfully
|
||||
* - ESP_ERR_INVALID_ARG: Enable glitch filter failed because of invalid arguments
|
||||
* - ESP_ERR_INVALID_STATE: Enable glitch filter failed because the glitch filter is already enabled
|
||||
* - ESP_FAIL: Enable glitch filter failed because of other error
|
||||
*/
|
||||
esp_err_t gpio_glitch_filter_enable(gpio_glitch_filter_handle_t filter);
|
||||
|
||||
/**
|
||||
* @brief Disable a glitch filter
|
||||
*
|
||||
* @param[in] filter Glitch filter handle returned from `gpio_new_flex_glitch_filter` or `gpio_new_pin_glitch_filter`
|
||||
* @return
|
||||
* - ESP_OK: Disable glitch filter successfully
|
||||
* - ESP_ERR_INVALID_ARG: Disable glitch filter failed because of invalid arguments
|
||||
* - ESP_ERR_INVALID_STATE: Disable glitch filter failed because the glitch filter is not enabled yet
|
||||
* - ESP_FAIL: Disable glitch filter failed because of other error
|
||||
*/
|
||||
esp_err_t gpio_glitch_filter_disable(gpio_glitch_filter_handle_t filter);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
51
components/esp_driver_gpio/include/driver/lp_io.h
Normal file
51
components/esp_driver_gpio/include/driver/lp_io.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
#include "esp_err.h"
|
||||
#include "driver/gpio.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if SOC_LP_GPIO_MATRIX_SUPPORTED
|
||||
/**
|
||||
* @brief Connect a RTC(LP) GPIO input with a peripheral signal, which tagged as input attribute
|
||||
*
|
||||
* @note There's no limitation on the number of signals that a RTC(LP) GPIO can connect with
|
||||
*
|
||||
* @param gpio_num GPIO number, especially, `LP_GPIO_MATRIX_CONST_ZERO_INPUT` means connect logic 0 to signal
|
||||
* `LP_GPIO_MATRIX_CONST_ONE_INPUT` means connect logic 1 to signal
|
||||
* @param signal_idx LP peripheral signal index (tagged as input attribute)
|
||||
* @param inv Whether the RTC(LP) GPIO input to be inverted or not
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t lp_gpio_connect_in_signal(gpio_num_t gpio_num, uint32_t signal_idx, bool inv);
|
||||
|
||||
/**
|
||||
* @brief Connect a peripheral signal which tagged as output attribute with a RTC(LP) GPIO
|
||||
*
|
||||
* @note There's no limitation on the number of RTC(LP) GPIOs that a signal can connect with
|
||||
*
|
||||
* @param gpio_num GPIO number
|
||||
* @param signal_idx LP peripheral signal index (tagged as input attribute), especially, `SIG_LP_GPIO_OUT_IDX` means disconnect RTC(LP) GPIO and other peripherals. Only the RTC GPIO driver can control the output level
|
||||
* @param out_inv Whether to signal to be inverted or not
|
||||
* @param oen_inv Whether the output enable control is inverted or not
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t lp_gpio_connect_out_signal(gpio_num_t gpio_num, uint32_t signal_idx, bool out_inv, bool oen_inv);
|
||||
#endif // SOC_LP_GPIO_MATRIX_SUPPORTED
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
313
components/esp_driver_gpio/include/driver/rtc_io.h
Normal file
313
components/esp_driver_gpio/include/driver/rtc_io.h
Normal file
@@ -0,0 +1,313 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_err.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "hal/rtc_io_types.h"
|
||||
#include "driver/gpio.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Determine if the specified GPIO is a valid RTC GPIO.
|
||||
*
|
||||
* @param gpio_num GPIO number
|
||||
* @return true if GPIO is valid for RTC GPIO use. false otherwise.
|
||||
*/
|
||||
bool rtc_gpio_is_valid_gpio(gpio_num_t gpio_num);
|
||||
|
||||
#define RTC_GPIO_IS_VALID_GPIO(gpio_num) rtc_gpio_is_valid_gpio(gpio_num)
|
||||
|
||||
#if SOC_RTCIO_PIN_COUNT > 0
|
||||
/**
|
||||
* @brief Get RTC IO index number by gpio number.
|
||||
*
|
||||
* @param gpio_num GPIO number
|
||||
* @return
|
||||
* >=0: Index of rtcio.
|
||||
* -1 : The gpio is not rtcio.
|
||||
*/
|
||||
int rtc_io_number_get(gpio_num_t gpio_num);
|
||||
|
||||
/**
|
||||
* @brief Init a GPIO as RTC GPIO
|
||||
*
|
||||
* This function must be called when initializing a pad for an analog function.
|
||||
*
|
||||
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
||||
*/
|
||||
esp_err_t rtc_gpio_init(gpio_num_t gpio_num);
|
||||
|
||||
/**
|
||||
* @brief Init a GPIO as digital GPIO
|
||||
*
|
||||
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
||||
*/
|
||||
esp_err_t rtc_gpio_deinit(gpio_num_t gpio_num);
|
||||
|
||||
#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
|
||||
/**
|
||||
* @brief Get the RTC IO input level
|
||||
*
|
||||
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
||||
*
|
||||
* @return
|
||||
* - 1 High level
|
||||
* - 0 Low level
|
||||
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
||||
*/
|
||||
uint32_t rtc_gpio_get_level(gpio_num_t gpio_num);
|
||||
|
||||
/**
|
||||
* @brief Set the RTC IO output level
|
||||
*
|
||||
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
||||
* @param level output level
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
||||
*/
|
||||
esp_err_t rtc_gpio_set_level(gpio_num_t gpio_num, uint32_t level);
|
||||
|
||||
/**
|
||||
* @brief RTC GPIO set direction
|
||||
*
|
||||
* Configure RTC GPIO direction, such as output only, input only,
|
||||
* output and input.
|
||||
*
|
||||
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
||||
* @param mode GPIO direction
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
||||
*/
|
||||
esp_err_t rtc_gpio_set_direction(gpio_num_t gpio_num, rtc_gpio_mode_t mode);
|
||||
|
||||
/**
|
||||
* @brief RTC GPIO set direction in deep sleep mode or disable sleep status (default).
|
||||
* In some application scenarios, IO needs to have another states during deep sleep.
|
||||
*
|
||||
* NOTE: ESP32 supports INPUT_ONLY mode.
|
||||
* The rest targets support INPUT_ONLY, OUTPUT_ONLY, INPUT_OUTPUT mode.
|
||||
*
|
||||
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
||||
* @param mode GPIO direction
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
||||
*/
|
||||
esp_err_t rtc_gpio_set_direction_in_sleep(gpio_num_t gpio_num, rtc_gpio_mode_t mode);
|
||||
|
||||
/**
|
||||
* @brief RTC GPIO pullup enable
|
||||
*
|
||||
* This function only works for RTC IOs. In general, call gpio_pullup_en,
|
||||
* which will work both for normal GPIOs and RTC IOs.
|
||||
*
|
||||
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
||||
*/
|
||||
esp_err_t rtc_gpio_pullup_en(gpio_num_t gpio_num);
|
||||
|
||||
/**
|
||||
* @brief RTC GPIO pulldown enable
|
||||
*
|
||||
* This function only works for RTC IOs. In general, call gpio_pulldown_en,
|
||||
* which will work both for normal GPIOs and RTC IOs.
|
||||
*
|
||||
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
||||
*/
|
||||
esp_err_t rtc_gpio_pulldown_en(gpio_num_t gpio_num);
|
||||
|
||||
/**
|
||||
* @brief RTC GPIO pullup disable
|
||||
*
|
||||
* This function only works for RTC IOs. In general, call gpio_pullup_dis,
|
||||
* which will work both for normal GPIOs and RTC IOs.
|
||||
*
|
||||
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
||||
*/
|
||||
esp_err_t rtc_gpio_pullup_dis(gpio_num_t gpio_num);
|
||||
|
||||
/**
|
||||
* @brief RTC GPIO pulldown disable
|
||||
*
|
||||
* This function only works for RTC IOs. In general, call gpio_pulldown_dis,
|
||||
* which will work both for normal GPIOs and RTC IOs.
|
||||
*
|
||||
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
||||
*/
|
||||
esp_err_t rtc_gpio_pulldown_dis(gpio_num_t gpio_num);
|
||||
|
||||
/**
|
||||
* @brief Set RTC 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 rtc_gpio_set_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t strength);
|
||||
|
||||
/**
|
||||
* @brief Get RTC 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
|
||||
*/
|
||||
esp_err_t rtc_gpio_get_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t* strength);
|
||||
|
||||
/**
|
||||
* @brief Select a RTC IOMUX function for the RTC IO
|
||||
*
|
||||
* @param gpio_num GPIO number
|
||||
* @param func Function to assign to the pin
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t rtc_gpio_iomux_func_sel(gpio_num_t gpio_num, int func);
|
||||
|
||||
#endif // SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
|
||||
|
||||
#if SOC_RTCIO_HOLD_SUPPORTED
|
||||
|
||||
/**
|
||||
* @brief Enable hold function on an RTC IO pad
|
||||
*
|
||||
* Enabling HOLD function will cause the pad to latch current values of
|
||||
* input enable, output enable, output value, function, drive strength values.
|
||||
* This function is useful when going into light or deep sleep mode to prevent
|
||||
* the pin configuration from changing.
|
||||
*
|
||||
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
||||
*/
|
||||
esp_err_t rtc_gpio_hold_en(gpio_num_t gpio_num);
|
||||
|
||||
/**
|
||||
* @brief Disable hold function on an RTC IO pad
|
||||
*
|
||||
* Disabling hold function will allow the pad receive the values of
|
||||
* input enable, output enable, output value, function, drive strength from
|
||||
* RTC_IO peripheral.
|
||||
*
|
||||
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
||||
*/
|
||||
esp_err_t rtc_gpio_hold_dis(gpio_num_t gpio_num);
|
||||
|
||||
/**
|
||||
* @brief Enable force hold signal for all RTC IOs
|
||||
*
|
||||
* Each RTC pad has a "force hold" input signal from the RTC controller.
|
||||
* If this signal is set, pad latches current values of input enable,
|
||||
* function, output enable, and other signals which come from the RTC mux.
|
||||
* Force hold signal is enabled before going into deep sleep for pins which
|
||||
* are used for EXT1 wakeup.
|
||||
*/
|
||||
esp_err_t rtc_gpio_force_hold_en_all(void);
|
||||
|
||||
/**
|
||||
* @brief Disable force hold signal for all RTC IOs
|
||||
*/
|
||||
esp_err_t rtc_gpio_force_hold_dis_all(void);
|
||||
|
||||
#endif // SOC_RTCIO_HOLD_SUPPORTED
|
||||
|
||||
#if SOC_RTCIO_HOLD_SUPPORTED && SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
|
||||
/**
|
||||
* @brief Helper function to disconnect internal circuits from an RTC IO
|
||||
* This function disables input, output, pullup, pulldown, and enables
|
||||
* hold feature for an RTC IO.
|
||||
* Use this function if an RTC IO needs to be disconnected from internal
|
||||
* circuits in deep sleep, to minimize leakage current.
|
||||
*
|
||||
* In particular, for ESP32-WROVER module, call
|
||||
* rtc_gpio_isolate(GPIO_NUM_12) before entering deep sleep, to reduce
|
||||
* deep sleep current.
|
||||
*
|
||||
* @param gpio_num GPIO number (e.g. GPIO_NUM_12).
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG if GPIO is not an RTC IO
|
||||
*/
|
||||
esp_err_t rtc_gpio_isolate(gpio_num_t gpio_num);
|
||||
#endif // SOC_RTCIO_HOLD_SUPPORTED && SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
|
||||
|
||||
#if SOC_RTCIO_WAKE_SUPPORTED
|
||||
|
||||
/**
|
||||
* @brief Enable wakeup from sleep mode using specific GPIO
|
||||
* @param gpio_num GPIO number
|
||||
* @param intr_type Wakeup on high level (GPIO_INTR_HIGH_LEVEL) or low level
|
||||
* (GPIO_INTR_LOW_LEVEL)
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG if gpio_num is not an RTC IO, or intr_type is not
|
||||
* one of GPIO_INTR_HIGH_LEVEL, GPIO_INTR_LOW_LEVEL.
|
||||
*/
|
||||
esp_err_t rtc_gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type);
|
||||
|
||||
/**
|
||||
* @brief Disable wakeup from sleep mode using specific GPIO
|
||||
* @param gpio_num GPIO number
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG if gpio_num is not an RTC IO
|
||||
*/
|
||||
esp_err_t rtc_gpio_wakeup_disable(gpio_num_t gpio_num);
|
||||
|
||||
#endif // SOC_RTCIO_WAKE_SUPPORTED
|
||||
|
||||
#endif // SOC_RTCIO_PIN_COUNT > 0
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user