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