rmt_hal.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // Copyright 2019 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "soc/rmt_struct.h"
  19. #include "soc/rmt_caps.h"
  20. /**
  21. * @brief HAL context type of RMT driver
  22. *
  23. */
  24. typedef struct {
  25. rmt_dev_t *regs; /*!< RMT Register base address */
  26. rmt_mem_t *mem; /*!< RMT Memory base address */
  27. } rmt_hal_context_t;
  28. #define RMT_MEM_OWNER_SW (0) /*!< RMT Memory ownership belongs to software side */
  29. #define RMT_MEM_OWNER_HW (1) /*!< RMT Memory ownership belongs to hardware side */
  30. /**
  31. * @brief Initialize the RMT HAL driver
  32. *
  33. * @param hal: RMT HAL context
  34. */
  35. void rmt_hal_init(rmt_hal_context_t *hal);
  36. /**
  37. * @brief Reset RMT HAL driver
  38. *
  39. * @param hal: RMT HAL context
  40. */
  41. void rmt_hal_reset(rmt_hal_context_t *hal);
  42. /**
  43. * @brief Reset RMT Channel specific HAL driver
  44. *
  45. * @param hal: RMT HAL context
  46. * @param channel: RMT channel number
  47. */
  48. void rmt_hal_channel_reset(rmt_hal_context_t *hal, uint32_t channel);
  49. /**
  50. * @brief Set counter clock for RMT channel
  51. *
  52. * @param hal: RMT HAL context
  53. * @param channel: RMT channel number
  54. * @param base_clk_hz: base clock for RMT internal channel (counter clock will divide from it)
  55. * @param counter_clk_hz: target counter clock
  56. */
  57. void rmt_hal_set_counter_clock(rmt_hal_context_t *hal, uint32_t channel, uint32_t base_clk_hz, uint32_t counter_clk_hz);
  58. /**
  59. * @brief Get counter clock for RMT channel
  60. *
  61. * @param hal: RMT HAL context
  62. * @param channel: RMT channel number
  63. * @param base_clk_hz: base clock for RMT internal channel (counter clock will divide from it)
  64. * @return counter clock in Hz
  65. */
  66. uint32_t rmt_hal_get_counter_clock(rmt_hal_context_t *hal, uint32_t channel, uint32_t base_clk_hz);
  67. /**
  68. * @brief Set carrier clock for RMT channel
  69. *
  70. * @param hal: RMT HAL context
  71. * @param channel: RMT channel number
  72. * @param base_clk_hz: base clock for RMT carrier generation (carrier clock will divide from it)
  73. * @param carrier_clk_hz: target carrier clock
  74. * @param carrier_clk_duty: duty ratio of carrier clock
  75. */
  76. void rmt_hal_set_carrier_clock(rmt_hal_context_t *hal, uint32_t channel, uint32_t base_clk_hz, uint32_t carrier_clk_hz, float carrier_clk_duty);
  77. /**
  78. * @brief Get carrier clock for RMT channel
  79. *
  80. * @param hal: RMT HAL context
  81. * @param channel: RMT channel number
  82. * @param base_clk_hz: base clock for RMT carrier generation
  83. * @param carrier_clk_hz: target carrier clock
  84. * @param carrier_clk_duty: duty ratio of carrier clock
  85. */
  86. void rmt_hal_get_carrier_clock(rmt_hal_context_t *hal, uint32_t channel, uint32_t base_clk_hz, uint32_t *carrier_clk_hz, float *carrier_clk_duty);
  87. /**
  88. * @brief Set filter threshold for RMT Receive channel
  89. *
  90. * @param hal: RMT HAL context
  91. * @param channel: RMT channel number
  92. * @param base_clk_hz: base clock for RMT receive filter
  93. * @param thres_us: threshold of RMT receive filter, in us
  94. */
  95. void rmt_hal_set_rx_filter_thres(rmt_hal_context_t *hal, uint32_t channel, uint32_t base_clk_hz, uint32_t thres_us);
  96. /**
  97. * @brief Set idle threshold for RMT Receive channel
  98. *
  99. * @param hal: RMT HAL context
  100. * @param channel: RMT channel number
  101. * @param base_clk_hz: base clock for RMT receive channel
  102. * @param thres_us: IDLE threshold for RMT receive channel
  103. */
  104. void rmt_hal_set_rx_idle_thres(rmt_hal_context_t *hal, uint32_t channel, uint32_t base_clk_hz, uint32_t thres_us);
  105. /**
  106. * @brief Receive a frame from RMT channel
  107. *
  108. * @param hal: RMT HAL context
  109. * @param channel: RMT channel number
  110. * @param buf: buffer to store received RMT frame
  111. * @return number of items that get received
  112. */
  113. uint32_t rmt_hal_receive(rmt_hal_context_t *hal, uint32_t channel, rmt_item32_t *buf);
  114. /**
  115. * @brief Transmit a from by RMT
  116. *
  117. * @param hal: RMT HAL context
  118. * @param channel: RMT channel number
  119. * @param src: RMT items to transmit
  120. * @param length: length of RMT items to transmit
  121. * @param offset: offset of RMT internal memory to store the items
  122. * @note The caller should ensure that (length + offset) <= (memory block * RMT_CHANNEL_MEM_WORDS).
  123. */
  124. void rmt_hal_transmit(rmt_hal_context_t *hal, uint32_t channel, const rmt_item32_t *src, uint32_t length, uint32_t offset);
  125. #ifdef __cplusplus
  126. }
  127. #endif