rmt_hal.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 Channel specific HAL driver
  38. *
  39. * @param hal: RMT HAL context
  40. * @param channel: RMT channel number
  41. */
  42. void rmt_hal_channel_reset(rmt_hal_context_t *hal, uint32_t channel);
  43. /**
  44. * @brief Set counter clock for RMT channel
  45. *
  46. * @param hal: RMT HAL context
  47. * @param channel: RMT channel number
  48. * @param base_clk_hz: base clock for RMT internal channel (counter clock will divide from it)
  49. * @param counter_clk_hz: target counter clock
  50. */
  51. void rmt_hal_set_counter_clock(rmt_hal_context_t *hal, uint32_t channel, uint32_t base_clk_hz, uint32_t counter_clk_hz);
  52. /**
  53. * @brief Get counter clock for RMT channel
  54. *
  55. * @param hal: RMT HAL context
  56. * @param channel: RMT channel number
  57. * @param base_clk_hz: base clock for RMT internal channel (counter clock will divide from it)
  58. * @return counter clock in Hz
  59. */
  60. uint32_t rmt_hal_get_counter_clock(rmt_hal_context_t *hal, uint32_t channel, uint32_t base_clk_hz);
  61. /**
  62. * @brief Set carrier clock for RMT channel
  63. *
  64. * @param hal: RMT HAL context
  65. * @param channel: RMT channel number
  66. * @param base_clk_hz: base clock for RMT carrier generation (carrier clock will divide from it)
  67. * @param carrier_clk_hz: target carrier clock
  68. * @param carrier_clk_duty: duty ratio of carrier clock
  69. */
  70. 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);
  71. /**
  72. * @brief Get carrier clock for RMT channel
  73. *
  74. * @param hal: RMT HAL context
  75. * @param channel: RMT channel number
  76. * @param base_clk_hz: base clock for RMT carrier generation
  77. * @param carrier_clk_hz: target carrier clock
  78. * @param carrier_clk_duty: duty ratio of carrier clock
  79. */
  80. 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);
  81. /**
  82. * @brief Set filter threshold for RMT Receive channel
  83. *
  84. * @param hal: RMT HAL context
  85. * @param channel: RMT channel number
  86. * @param base_clk_hz: base clock for RMT receive filter
  87. * @param thres_us: threshold of RMT receive filter, in us
  88. */
  89. void rmt_hal_set_rx_filter_thres(rmt_hal_context_t *hal, uint32_t channel, uint32_t base_clk_hz, uint32_t thres_us);
  90. /**
  91. * @brief Set idle threshold for RMT Receive channel
  92. *
  93. * @param hal: RMT HAL context
  94. * @param channel: RMT channel number
  95. * @param base_clk_hz: base clock for RMT receive channel
  96. * @param thres_us: IDLE threshold for RMT receive channel
  97. */
  98. void rmt_hal_set_rx_idle_thres(rmt_hal_context_t *hal, uint32_t channel, uint32_t base_clk_hz, uint32_t thres_us);
  99. /**
  100. * @brief Receive a frame from RMT channel
  101. *
  102. * @param hal: RMT HAL context
  103. * @param channel: RMT channel number
  104. * @param buf: buffer to store received RMT frame
  105. * @return number of items that get received
  106. */
  107. uint32_t rmt_hal_receive(rmt_hal_context_t *hal, uint32_t channel, rmt_item32_t *buf);
  108. /**
  109. * @brief Transmit a from by RMT
  110. *
  111. * @param hal: RMT HAL context
  112. * @param channel: RMT channel number
  113. * @param src: RMT items to transmit
  114. * @param length: length of RMT items to transmit
  115. * @param offset: offset of RMT internal memory to store the items.
  116. * Note: the caller should ensure that (length + offset) <= (memory block * SOC_RMT_CHANNEL_MEM_WORDS).
  117. */
  118. void rmt_hal_transmit(rmt_hal_context_t *hal, uint32_t channel, const rmt_item32_t *src, uint32_t length, uint32_t offset);
  119. #ifdef __cplusplus
  120. }
  121. #endif