rmt_hal.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 <stdint.h>
  19. #include "soc/soc_caps.h"
  20. #include "soc/rmt_struct.h"
  21. /**
  22. * @brief HAL context type of RMT driver
  23. *
  24. */
  25. typedef struct {
  26. rmt_dev_t *regs; /*!< RMT Register base address */
  27. rmt_mem_t *mem; /*!< RMT Memory base address */
  28. } rmt_hal_context_t;
  29. #define RMT_MEM_OWNER_SW (0) /*!< RMT Memory ownership belongs to software side */
  30. #define RMT_MEM_OWNER_HW (1) /*!< RMT Memory ownership belongs to hardware side */
  31. /**
  32. * @brief Initialize the RMT HAL driver
  33. *
  34. * @param hal: RMT HAL context
  35. */
  36. void rmt_hal_init(rmt_hal_context_t *hal);
  37. /**
  38. * @brief Reset RMT TX Channel
  39. *
  40. * @param hal: RMT HAL context
  41. * @param channel: RMT channel number
  42. */
  43. void rmt_hal_tx_channel_reset(rmt_hal_context_t *hal, uint32_t channel);
  44. /**
  45. * @brief Reset RMT TX Channel
  46. *
  47. * @param hal: RMT HAL context
  48. * @param channel: RMT channel number
  49. */
  50. void rmt_hal_rx_channel_reset(rmt_hal_context_t *hal, uint32_t channel);
  51. /**
  52. * @brief Set counter clock for RMT channel
  53. *
  54. * @param hal: RMT HAL context
  55. * @param channel: RMT channel number
  56. * @param base_clk_hz: base clock for RMT internal channel (counter clock will divide from it)
  57. * @param counter_clk_hz: target counter clock
  58. */
  59. void rmt_hal_tx_set_channel_clock(rmt_hal_context_t *hal, uint32_t channel, uint32_t base_clk_hz, uint32_t counter_clk_hz);
  60. /**
  61. * @brief Set carrier clock for RMT channel
  62. *
  63. * @param hal: RMT HAL context
  64. * @param channel: RMT channel number
  65. * @param base_clk_hz: base clock for RMT carrier generation (carrier clock will divide from it)
  66. * @param carrier_clk_hz: target carrier clock
  67. * @param carrier_clk_duty: duty ratio of carrier clock
  68. */
  69. 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);
  70. /**
  71. * @brief Set filter threshold for RMT Receive channel
  72. *
  73. * @param hal: RMT HAL context
  74. * @param channel: RMT channel number
  75. * @param base_clk_hz: base clock for RMT receive filter
  76. * @param thres_us: threshold of RMT receive filter, in us
  77. */
  78. void rmt_hal_set_rx_filter_thres(rmt_hal_context_t *hal, uint32_t channel, uint32_t base_clk_hz, uint32_t thres_us);
  79. /**
  80. * @brief Set idle threshold for RMT Receive channel
  81. *
  82. * @param hal: RMT HAL context
  83. * @param channel: RMT channel number
  84. * @param base_clk_hz: base clock for RMT receive channel
  85. * @param thres_us: IDLE threshold for RMT receive channel
  86. */
  87. void rmt_hal_set_rx_idle_thres(rmt_hal_context_t *hal, uint32_t channel, uint32_t base_clk_hz, uint32_t thres_us);
  88. /**
  89. * @brief Receive a frame from RMT channel
  90. *
  91. * @param hal: RMT HAL context
  92. * @param channel: RMT channel number
  93. * @param buf: buffer to store received RMT frame
  94. * @return number of items that get received
  95. */
  96. uint32_t rmt_hal_receive(rmt_hal_context_t *hal, uint32_t channel, rmt_item32_t *buf);
  97. #ifdef __cplusplus
  98. }
  99. #endif