gpio_etm.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #include "esp_err.h"
  9. #include "esp_etm.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /**
  14. * @brief GPIO edges that can be used as ETM event
  15. */
  16. typedef enum {
  17. GPIO_ETM_EVENT_EDGE_POS, /*!< A rising edge on the GPIO will generate an ETM event signal */
  18. GPIO_ETM_EVENT_EDGE_NEG, /*!< A falling edge on the GPIO will generate an ETM event signal */
  19. GPIO_ETM_EVENT_EDGE_ANY, /*!< Any edge on the GPIO can generate an ETM event signal */
  20. } gpio_etm_event_edge_t;
  21. /**
  22. * @brief GPIO ETM event configuration
  23. */
  24. typedef struct {
  25. gpio_etm_event_edge_t edge; /*!< Which kind of edge can trigger the ETM event module */
  26. } gpio_etm_event_config_t;
  27. /**
  28. * @brief Create an ETM event object for the GPIO peripheral
  29. *
  30. * @note The created ETM event object can be deleted later by calling `esp_etm_del_event`
  31. * @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
  32. *
  33. * @param[in] config GPIO ETM event configuration
  34. * @param[out] ret_event Returned ETM event handle
  35. * @return
  36. * - ESP_OK: Create ETM event successfully
  37. * - ESP_ERR_INVALID_ARG: Create ETM event failed because of invalid argument
  38. * - ESP_ERR_NO_MEM: Create ETM event failed because of out of memory
  39. * - ESP_ERR_NOT_FOUND: Create ETM event failed because all events are used up and no more free one
  40. * - ESP_FAIL: Create ETM event failed because of other reasons
  41. */
  42. esp_err_t gpio_new_etm_event(const gpio_etm_event_config_t *config, esp_etm_event_handle_t *ret_event);
  43. /**
  44. * @brief Bind the GPIO with the ETM event
  45. *
  46. * @note Calling this function multiple times with different GPIO number can override the previous setting immediately.
  47. * @note Only GPIO ETM object can call this function
  48. *
  49. * @param[in] event ETM event handle that created by `gpio_new_etm_event`
  50. * @param[in] gpio_num GPIO number that can trigger the ETM event
  51. * @return
  52. * - ESP_OK: Set the GPIO for ETM event successfully
  53. * - 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
  54. * - ESP_FAIL: Set the GPIO for ETM event failed because of other reasons
  55. */
  56. esp_err_t gpio_etm_event_bind_gpio(esp_etm_event_handle_t event, int gpio_num);
  57. /**
  58. * @brief GPIO actions that can be taken by the ETM task
  59. */
  60. typedef enum {
  61. GPIO_ETM_TASK_ACTION_SET, /*!< Set the GPIO level to high */
  62. GPIO_ETM_TASK_ACTION_CLR, /*!< Clear the GPIO level to low */
  63. GPIO_ETM_TASK_ACTION_TOG, /*!< Toggle the GPIO level */
  64. } gpio_etm_task_action_t;
  65. /**
  66. * @brief GPIO ETM task configuration
  67. */
  68. typedef struct {
  69. gpio_etm_task_action_t action; /*!< Which action to take by the ETM task module */
  70. } gpio_etm_task_config_t;
  71. /**
  72. * @brief Create an ETM task object for the GPIO peripheral
  73. *
  74. * @note The created ETM task object can be deleted later by calling `esp_etm_del_task`
  75. * @note The GPIO ETM task works like a container, a newly created ETM task object doesn't have GPIO members to be managed.
  76. * You need to call `gpio_etm_task_add_gpio` to put one or more GPIOs to the container.
  77. *
  78. * @param[in] config GPIO ETM task configuration
  79. * @param[out] ret_task Returned ETM task handle
  80. * @return
  81. * - ESP_OK: Create ETM task successfully
  82. * - ESP_ERR_INVALID_ARG: Create ETM task failed because of invalid argument
  83. * - ESP_ERR_NO_MEM: Create ETM task failed because of out of memory
  84. * - ESP_ERR_NOT_FOUND: Create ETM task failed because all tasks are used up and no more free one
  85. * - ESP_FAIL: Create ETM task failed because of other reasons
  86. */
  87. esp_err_t gpio_new_etm_task(const gpio_etm_task_config_t *config, esp_etm_task_handle_t *ret_task);
  88. /**
  89. * @brief Add GPIO to the ETM task.
  90. *
  91. * @note You can call this function multiple times to add more GPIOs
  92. * @note Only GPIO ETM object can call this function
  93. *
  94. * @param[in] task ETM task handle that created by `gpio_new_etm_task`
  95. * @param[in] gpio_num GPIO number that can be controlled by the ETM task
  96. * @return
  97. * - ESP_OK: Add GPIO to the ETM task successfully
  98. * - 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
  99. * - ESP_ERR_INVALID_STATE: Add GPIO to the ETM task failed because the GPIO is used by other ETM task already
  100. * - ESP_FAIL: Add GPIO to the ETM task failed because of other reasons
  101. */
  102. esp_err_t gpio_etm_task_add_gpio(esp_etm_task_handle_t task, int gpio_num);
  103. /**
  104. * @brief Remove the GPIO from the ETM task
  105. *
  106. * @note Before deleting the ETM task, you need to remove all the GPIOs from the ETM task by this function
  107. * @note Only GPIO ETM object can call this function
  108. *
  109. * @param[in] task ETM task handle that created by `gpio_new_etm_task`
  110. * @param[in] gpio_num GPIO number that to be remove from the ETM task
  111. * @return
  112. * - ESP_OK: Remove the GPIO from the ETM task successfully
  113. * - ESP_ERR_INVALID_ARG: Remove the GPIO from the ETM task failed because of invalid argument
  114. * - ESP_ERR_INVALID_STATE: Remove the GPIO from the ETM task failed because the GPIO is not controlled by this ETM task
  115. * - ESP_FAIL: Remove the GPIO from the ETM task failed because of other reasons
  116. */
  117. esp_err_t gpio_etm_task_rm_gpio(esp_etm_task_handle_t task, int gpio_num);
  118. #ifdef __cplusplus
  119. }
  120. #endif