mcpwm_sync.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 <stdbool.h>
  9. #include "esp_err.h"
  10. #include "driver/mcpwm_types.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. /**
  15. * @brief MCPWM timer sync source configuration
  16. */
  17. typedef struct {
  18. mcpwm_timer_event_t timer_event; /*!< Timer event, upon which MCPWM timer will generate the sync signal */
  19. struct {
  20. uint32_t propagate_input_sync: 1; /*!< The input sync signal would be routed to its sync output */
  21. } flags; /*!< Extra configuration flags for timer sync source */
  22. } mcpwm_timer_sync_src_config_t;
  23. /**
  24. * @brief Create MCPWM timer sync source
  25. *
  26. * @param[in] timer MCPWM timer handle, allocated by `mcpwm_new_timer()`
  27. * @param[in] config MCPWM timer sync source configuration
  28. * @param[out] ret_sync Returned MCPWM sync handle
  29. * @return
  30. * - ESP_OK: Create MCPWM timer sync source successfully
  31. * - ESP_ERR_INVALID_ARG: Create MCPWM timer sync source failed because of invalid argument
  32. * - ESP_ERR_NO_MEM: Create MCPWM timer sync source failed because out of memory
  33. * - ESP_ERR_INVALID_STATE: Create MCPWM timer sync source failed because the timer has created a sync source before
  34. * - ESP_FAIL: Create MCPWM timer sync source failed because of other error
  35. */
  36. esp_err_t mcpwm_new_timer_sync_src(mcpwm_timer_handle_t timer, const mcpwm_timer_sync_src_config_t *config, mcpwm_sync_handle_t *ret_sync);
  37. /**
  38. * @brief MCPWM GPIO sync source configuration
  39. */
  40. typedef struct {
  41. int group_id; /*!< MCPWM group ID */
  42. int gpio_num; /*!< GPIO used by sync source */
  43. struct {
  44. uint32_t active_neg: 1; /*!< Whether the sync signal is active on negedge, by default, the sync signal's posedge is treated as active */
  45. uint32_t io_loop_back: 1; /*!< For debug/test, the signal output from the GPIO will be fed to the input path as well */
  46. uint32_t pull_up: 1; /*!< Whether to pull up internally */
  47. uint32_t pull_down: 1; /*!< Whether to pull down internally */
  48. } flags; /*!< Extra configuration flags for GPIO sync source */
  49. } mcpwm_gpio_sync_src_config_t;
  50. /**
  51. * @brief Create MCPWM GPIO sync source
  52. *
  53. * @param[in] config MCPWM GPIO sync source configuration
  54. * @param[out] ret_sync Returned MCPWM GPIO sync handle
  55. * @return
  56. * - ESP_OK: Create MCPWM GPIO sync source successfully
  57. * - ESP_ERR_INVALID_ARG: Create MCPWM GPIO sync source failed because of invalid argument
  58. * - ESP_ERR_NO_MEM: Create MCPWM GPIO sync source failed because out of memory
  59. * - ESP_ERR_NOT_FOUND: Create MCPWM GPIO sync source failed because can't find free resource
  60. * - ESP_FAIL: Create MCPWM GPIO sync source failed because of other error
  61. */
  62. esp_err_t mcpwm_new_gpio_sync_src(const mcpwm_gpio_sync_src_config_t *config, mcpwm_sync_handle_t *ret_sync);
  63. /**
  64. * @brief MCPWM software sync configuration structure
  65. */
  66. typedef struct {
  67. } mcpwm_soft_sync_config_t;
  68. /**
  69. * @brief Create MCPWM software sync source
  70. *
  71. * @param[in] config MCPWM software sync source configuration
  72. * @param[out] ret_sync Returned software sync handle
  73. * @return
  74. * - ESP_OK: Create MCPWM software sync successfully
  75. * - ESP_ERR_INVALID_ARG: Create MCPWM software sync failed because of invalid argument
  76. * - ESP_ERR_NO_MEM: Create MCPWM software sync failed because out of memory
  77. * - ESP_FAIL: Create MCPWM software sync failed because of other error
  78. */
  79. esp_err_t mcpwm_new_soft_sync_src(const mcpwm_soft_sync_config_t *config, mcpwm_sync_handle_t *ret_sync);
  80. /**
  81. * @brief Delete MCPWM sync source
  82. *
  83. * @param[in] sync MCPWM sync handle, allocated by `mcpwm_new_timer_sync_src()` or `mcpwm_new_gpio_sync_src()` or `mcpwm_new_soft_sync_src()`
  84. * @return
  85. * - ESP_OK: Delete MCPWM sync source successfully
  86. * - ESP_ERR_INVALID_ARG: Delete MCPWM sync source failed because of invalid argument
  87. * - ESP_FAIL: Delete MCPWM sync source failed because of other error
  88. */
  89. esp_err_t mcpwm_del_sync_src(mcpwm_sync_handle_t sync);
  90. /**
  91. * @brief Activate the software sync, trigger the sync event for once
  92. *
  93. * @param[in] sync MCPWM soft sync handle, allocated by `mcpwm_new_soft_sync_src()`
  94. * @return
  95. * - ESP_OK: Trigger MCPWM software sync event successfully
  96. * - ESP_ERR_INVALID_ARG: Trigger MCPWM software sync event failed because of invalid argument
  97. * - ESP_FAIL: Trigger MCPWM software sync event failed because of other error
  98. */
  99. esp_err_t mcpwm_soft_sync_activate(mcpwm_sync_handle_t sync);
  100. #ifdef __cplusplus
  101. }
  102. #endif