gpio.rst 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. GPIO & RTC GPIO
  2. ===============
  3. :link_to_translation:`zh_CN:[中文]`
  4. GPIO Summary
  5. ------------
  6. .. include:: gpio/{IDF_TARGET_PATH_NAME}.inc
  7. :start-after: gpio-summary
  8. :end-before: ---
  9. GPIO driver offers a dump function :cpp:func:`gpio_dump_io_configuration` to show the configurations of the IOs at the moment, such as pull-up / pull-down, input / output enable, pin mapping etc. Below is an example dump:
  10. ::
  11. ================IO DUMP Start================
  12. IO[4] -
  13. Pullup: 1, Pulldown: 0, DriveCap: 2
  14. InputEn: 1, OutputEn: 0, OpenDrain: 0
  15. FuncSel: 1 (GPIO)
  16. GPIO Matrix SigIn ID: (simple GPIO input)
  17. SleepSelEn: 1
  18. IO[18] -
  19. Pullup: 0, Pulldown: 0, DriveCap: 2
  20. InputEn: 0, OutputEn: 1, OpenDrain: 0
  21. FuncSel: 1 (GPIO)
  22. GPIO Matrix SigOut ID: 256 (simple GPIO output)
  23. SleepSelEn: 1
  24. IO[26] **RESERVED** -
  25. Pullup: 1, Pulldown: 0, DriveCap: 2
  26. InputEn: 1, OutputEn: 0, OpenDrain: 0
  27. FuncSel: 0 (IOMUX)
  28. SleepSelEn: 1
  29. =================IO DUMP End==================
  30. If an IO pin is routed to a peripheral signal through the GPIO matrix, the signal ID printed in the dump information is defined in the ``soc/gpio_sig_map.h`` file. The word ``**RESERVED**`` indicates the IO is occupied by either FLASH or PSRAM. It is strongly not recommended to reconfigure them for other application purposes.
  31. .. only:: SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
  32. .. only:: not SOC_LP_PERIPHERALS_SUPPORTED
  33. There is also separate "RTC GPIO" support, which functions when GPIOs are routed to the "RTC" low-power and analog subsystem. These pin functions can be used when:
  34. .. only:: SOC_LP_PERIPHERALS_SUPPORTED
  35. There is also separate "RTC GPIO" support, which functions when GPIOs are routed to the "RTC" low-power, analog subsystem, and Low-Power(LP) peripherals. These pin functions can be used when:
  36. .. list::
  37. - In Deep-sleep mode
  38. :SOC_ULP_SUPPORTED and not esp32c6: - The :doc:`Ultra Low Power co-processor <../../api-reference/system/ulp>` is running
  39. - Analog functions such as ADC/DAC/etc are in use
  40. :SOC_LP_PERIPHERALS_SUPPORTED: - LP peripherals, such as LP_UART, LP_I2C, are in use
  41. .. only:: SOC_GPIO_SUPPORT_PIN_GLITCH_FILTER or SOC_GPIO_FLEX_GLITCH_FILTER_NUM
  42. GPIO Glitch Filter
  43. ------------------
  44. The {IDF_TARGET_NAME} chip features hardware filters to remove unwanted glitch pulses from the input GPIO, which can help reduce false triggering of the interrupt and prevent a noise being routed to the peripheral side.
  45. .. only:: SOC_GPIO_SUPPORT_PIN_GLITCH_FILTER
  46. Each GPIO can be configured with a glitch filter, which can be used to filter out pulses shorter than **two** sample clock cycles. The duration of the filter is not configurable. The sample clock is the clock source of the IO_MUX. In the driver, we call this kind of filter as ``pin glitch filter``. You can create the filter handle by calling :cpp:func:`gpio_new_pin_glitch_filter`. All the configurations for a pin glitch filter are listed in the :cpp:type:`gpio_pin_glitch_filter_config_t` structure.
  47. - :cpp:member:`gpio_pin_glitch_filter_config_t::gpio_num` sets the GPIO number to enable the glitch filter.
  48. .. only:: SOC_GPIO_FLEX_GLITCH_FILTER_NUM
  49. {IDF_TARGET_FLEX_GLITCH_FILTER_NUM:default="8"}
  50. {IDF_TARGET_NAME} provides {IDF_TARGET_FLEX_GLITCH_FILTER_NUM} flexible glitch filters, whose duration is configurable. We refer to this kind of filter as ``flex flitch filter``. Each of them can be applied to any input GPIO. However, applying multiple filters to the same GPIO does not make difference from one. You can create the filter handle by calling :cpp:func:`gpio_new_flex_glitch_filter`. All the configurations for a flexible glitch filter are listed in the :cpp:type:`gpio_flex_glitch_filter_config_t` structure.
  51. - :cpp:member:`gpio_flex_glitch_filter_config_t::gpio_num` sets the GPIO that will be applied to the flex glitch filter.
  52. - :cpp:member:`gpio_flex_glitch_filter_config_t::window_width_ns` and :cpp:member:`gpio_flex_glitch_filter_config_t::window_thres_ns` are the key parameters of the glitch filter. During :cpp:member:`gpio_flex_glitch_filter_config_t::window_width_ns`, any pulse whose width is shorter than :cpp:member:`gpio_flex_glitch_filter_config_t::window_thres_ns` will be discarded. Please note that, you can not set :cpp:member:`gpio_flex_glitch_filter_config_t::window_thres_ns` bigger than :cpp:member:`gpio_flex_glitch_filter_config_t::window_width_ns`.
  53. .. only:: SOC_GPIO_SUPPORT_PIN_GLITCH_FILTER and SOC_GPIO_FLEX_GLITCH_FILTER_NUM
  54. Please note, the ``pin glitch filter`` and ``flex glitch filter`` are independent. You can enable both of them for the same GPIO.
  55. The glitch filter is disabled by default, and can be enabled by calling :cpp:func:`gpio_glitch_filter_enable`. To recycle the filter, you can call :cpp:func:`gpio_del_glitch_filter`. Please note, before deleting the filter, you should disable it first by calling :cpp:func:`gpio_glitch_filter_disable`.
  56. .. only:: SOC_GPIO_SUPPORT_PIN_HYS_FILTER
  57. GPIO Hysteresis Filter
  58. ----------------------
  59. {IDF_TARGET_NAME} support the hardware hysteresis of the input pin, which can reduce the GPIO interrupt shoot by accident due to unstable sampling when the input voltage is near the criteria of logic 0 and 1, especially when the input logic level conversion is slow or the voltage setup time is too long.
  60. .. only:: SOC_GPIO_SUPPORT_PIN_HYS_CTRL_BY_EFUSE
  61. Each pin can enable hysteresis function independently. By default, it controlled by eFuse and been closed, but it can also be enabled or disabled by software manually. You can select the hysteresis control mode by configuring :cpp:member:`gpio_config_t::hys_ctrl_mode`. Hysteresis control mode is set along with all the other GPIO configurations in :cpp:func:`gpio_config`.
  62. .. note::
  63. When the hysteresis function is controlled by eFuse, this feature can still be controlled independently for each pin, you need to `burn the eFuse <https://docs.espressif.com/projects/esptool/en/latest/esp32/espefuse/index.html>`_ to enable the hysteresis function on specific GPIO additionally.
  64. .. only:: not SOC_GPIO_SUPPORT_PIN_HYS_CTRL_BY_EFUSE
  65. Each pin can enable hysteresis function independently. By default, the function is not enabled. You can select the hysteresis control mode by configuring :cpp:member:`gpio_config_t::hys_ctrl_mode`. Hysteresis control mode is set along with all the other GPIO configurations in :cpp:func:`gpio_config`.
  66. Application Example
  67. -------------------
  68. * GPIO output and input interrupt example: :example:`peripherals/gpio/generic_gpio`.
  69. API Reference - Normal GPIO
  70. ---------------------------
  71. .. include-build-file:: inc/gpio.inc
  72. .. include-build-file:: inc/gpio_types.inc
  73. .. only:: SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
  74. API Reference - RTC GPIO
  75. ------------------------
  76. .. include-build-file:: inc/rtc_io.inc
  77. .. include-build-file:: inc/lp_io.inc
  78. .. include-build-file:: inc/rtc_io_types.inc
  79. .. only:: SOC_GPIO_SUPPORT_PIN_GLITCH_FILTER or SOC_GPIO_FLEX_GLITCH_FILTER_NUM
  80. API Reference - GPIO Glitch Filter
  81. ----------------------------------
  82. .. include-build-file:: inc/gpio_filter.inc