21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
23 * SOFTWARE. |
23 * SOFTWARE. |
24 */ |
24 */ |
25 |
25 |
|
26 /** |
|
27 * @file |
|
28 * @brief Interface definitions for ESP32 RMT driver used to communicate with devices |
|
29 * on the One Wire Bus. |
|
30 * |
|
31 * This is the recommended driver. |
|
32 */ |
|
33 |
26 #pragma once |
34 #pragma once |
27 #ifndef OWB_RMT_H |
35 #ifndef OWB_RMT_H |
28 #define OWB_RMT_H |
36 #define OWB_RMT_H |
29 |
37 |
30 #include "freertos/FreeRTOS.h" |
38 #include "freertos/FreeRTOS.h" |
31 #include "freertos/queue.h" |
39 #include "freertos/queue.h" |
32 #include "freertos/ringbuf.h" |
40 |
33 #include "driver/rmt.h" |
41 #include "driver/rmt_tx.h" |
|
42 #include "driver/rmt_rx.h" |
|
43 |
|
44 #include "owb.h" // for tyoe OneWireBus |
34 |
45 |
35 #ifdef __cplusplus |
46 #ifdef __cplusplus |
36 extern "C" { |
47 extern "C" { |
37 #endif |
48 #endif |
38 |
49 |
|
50 /** |
|
51 * @brief RMT driver information |
|
52 */ |
39 typedef struct |
53 typedef struct |
40 { |
54 { |
41 int tx_channel; ///< RMT channel to use for TX |
55 rmt_channel_handle_t tx_channel_handle; ///< RMT transmit channel, allocated by RMT driver |
42 int rx_channel; ///< RMT channel to use for RX |
56 rmt_channel_handle_t rx_channel_handle; ///< RMT receive channel, allocated by RMT driver |
43 RingbufHandle_t rb; ///< Ring buffer handle |
57 rmt_encoder_handle_t copy_encoder_handle; ///< RMT built-in data encoder that sends pre-defined symbols |
44 int gpio; ///< OneWireBus GPIO |
58 rmt_encoder_handle_t bytes_encoder_handle; ///< RMT built-in data encoder that converts bits into symbols |
45 OneWireBus bus; ///< OneWireBus instance |
59 rmt_symbol_word_t *rx_buffer; ///< RMT receive channel symbol buffer |
|
60 size_t rx_buffer_size_in_bytes; ///< Size of the RMT received buffer, in bytes |
|
61 QueueHandle_t rx_queue; ///< xQueue to receive RMT symbols from the `on_recv_done` callback |
|
62 int gpio; ///< OneWireBus GPIO |
|
63 OneWireBus bus; ///< OneWireBus instance (see owb.h) |
46 } owb_rmt_driver_info; |
64 } owb_rmt_driver_info; |
47 |
65 |
48 /** |
66 /** |
49 * @brief Initialise the RMT driver. |
67 * @brief Initialise the RMT driver. |
50 * @return OneWireBus*, pass this into the other OneWireBus public API functions |
68 * @param[in] info Pointer to an uninitialized owb_rmt_driver_info structure. |
|
69 * Note: the structure must remain in scope for the lifetime of this component. |
|
70 * @param[in] gpio_num The GPIO number to use as the One Wire bus data line. |
|
71 * @param tx_channel NOW IGNORED: the new RMT driver allocates channels dynamically. |
|
72 * @param rx_channel NOW IGNORED: the new RMT driver allocates channels dynamically. |
|
73 * @return OneWireBus *, pass this into the other OneWireBus public API functions |
51 */ |
74 */ |
52 OneWireBus* owb_rmt_initialize(owb_rmt_driver_info *info, uint8_t gpio_num, |
75 OneWireBus* owb_rmt_initialize(owb_rmt_driver_info * info, gpio_num_t gpio_num, |
53 rmt_channel_t tx_channel, rmt_channel_t rx_channel); |
76 /*rmt_channel_t*/ int tx_channel, /* rmt_channel_t*/ int rx_channel); |
|
77 |
|
78 |
|
79 /** |
|
80 * @brief Legacy RMT channel IDs. |
|
81 * |
|
82 * These are no longer used for anything. They are defined here purely so |
|
83 * that code written for the old rmt driver can still compile. |
|
84 */ |
|
85 typedef enum { |
|
86 RMT_CHANNEL_0, /*!< RMT channel number 0 */ |
|
87 RMT_CHANNEL_1, /*!< RMT channel number 1 */ |
|
88 RMT_CHANNEL_2, /*!< RMT channel number 2 */ |
|
89 RMT_CHANNEL_3, /*!< RMT channel number 3 */ |
|
90 #if SOC_RMT_CHANNELS_PER_GROUP > 4 |
|
91 RMT_CHANNEL_4, /*!< RMT channel number 4 */ |
|
92 RMT_CHANNEL_5, /*!< RMT channel number 5 */ |
|
93 RMT_CHANNEL_6, /*!< RMT channel number 6 */ |
|
94 RMT_CHANNEL_7, /*!< RMT channel number 7 */ |
|
95 #endif |
|
96 RMT_CHANNEL_MAX /*!< Number of RMT channels */ |
|
97 } rmt_channel_t; |
|
98 |
54 |
99 |
55 #ifdef __cplusplus |
100 #ifdef __cplusplus |
56 } |
101 } |
57 #endif |
102 #endif |
58 |
103 |