components/esp32-owb/include/owb_rmt.h

Tue, 26 Sep 2023 14:57:18 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 26 Sep 2023 14:57:18 +0200
changeset 72
acc1904cd70d
parent 0
88d965579617
permissions
-rw-r--r--

Migrated to isp-idf v5.1

0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /*
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * MIT License
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * Copyright (c) 2017 David Antliff
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * Copyright (c) 2017 Chris Morgan <chmorgan@gmail.com>
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 *
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * of this software and associated documentation files (the "Software"), to deal
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * in the Software without restriction, including without limitation the rights
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * copies of the Software, and to permit persons to whom the Software is
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * furnished to do so, subject to the following conditions:
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 *
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * The above copyright notice and this permission notice shall be included in all
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * copies or substantial portions of the Software.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 *
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 * SOFTWARE.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
72
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
26 /**
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
27 * @file
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
28 * @brief Interface definitions for ESP32 RMT driver used to communicate with devices
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
29 * on the One Wire Bus.
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
30 *
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
31 * This is the recommended driver.
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
32 */
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
33
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 #pragma once
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 #ifndef OWB_RMT_H
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 #define OWB_RMT_H
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 #include "freertos/FreeRTOS.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 #include "freertos/queue.h"
72
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
40
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
41 #include "driver/rmt_tx.h"
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
42 #include "driver/rmt_rx.h"
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
43
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
44 #include "owb.h" // for tyoe OneWireBus
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 #ifdef __cplusplus
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 extern "C" {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 #endif
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49
72
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
50 /**
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
51 * @brief RMT driver information
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
52 */
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 typedef struct
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 {
72
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
55 rmt_channel_handle_t tx_channel_handle; ///< RMT transmit channel, allocated by RMT driver
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
56 rmt_channel_handle_t rx_channel_handle; ///< RMT receive channel, allocated by RMT driver
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
57 rmt_encoder_handle_t copy_encoder_handle; ///< RMT built-in data encoder that sends pre-defined symbols
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
58 rmt_encoder_handle_t bytes_encoder_handle; ///< RMT built-in data encoder that converts bits into symbols
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
59 rmt_symbol_word_t *rx_buffer; ///< RMT receive channel symbol buffer
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
60 size_t rx_buffer_size_in_bytes; ///< Size of the RMT received buffer, in bytes
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
61 QueueHandle_t rx_queue; ///< xQueue to receive RMT symbols from the `on_recv_done` callback
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
62 int gpio; ///< OneWireBus GPIO
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
63 OneWireBus bus; ///< OneWireBus instance (see owb.h)
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 } owb_rmt_driver_info;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 /**
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 * @brief Initialise the RMT driver.
72
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
68 * @param[in] info Pointer to an uninitialized owb_rmt_driver_info structure.
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
69 * Note: the structure must remain in scope for the lifetime of this component.
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
70 * @param[in] gpio_num The GPIO number to use as the One Wire bus data line.
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
71 * @param tx_channel NOW IGNORED: the new RMT driver allocates channels dynamically.
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
72 * @param rx_channel NOW IGNORED: the new RMT driver allocates channels dynamically.
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
73 * @return OneWireBus *, pass this into the other OneWireBus public API functions
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 */
72
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
75 OneWireBus* owb_rmt_initialize(owb_rmt_driver_info * info, gpio_num_t gpio_num,
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
76 /*rmt_channel_t*/ int tx_channel, /* rmt_channel_t*/ int rx_channel);
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
77
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
78
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
79 /**
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
80 * @brief Legacy RMT channel IDs.
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
81 *
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
82 * These are no longer used for anything. They are defined here purely so
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
83 * that code written for the old rmt driver can still compile.
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
84 */
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
85 typedef enum {
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
86 RMT_CHANNEL_0, /*!< RMT channel number 0 */
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
87 RMT_CHANNEL_1, /*!< RMT channel number 1 */
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
88 RMT_CHANNEL_2, /*!< RMT channel number 2 */
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
89 RMT_CHANNEL_3, /*!< RMT channel number 3 */
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
90 #if SOC_RMT_CHANNELS_PER_GROUP > 4
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
91 RMT_CHANNEL_4, /*!< RMT channel number 4 */
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
92 RMT_CHANNEL_5, /*!< RMT channel number 5 */
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
93 RMT_CHANNEL_6, /*!< RMT channel number 6 */
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
94 RMT_CHANNEL_7, /*!< RMT channel number 7 */
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
95 #endif
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
96 RMT_CHANNEL_MAX /*!< Number of RMT channels */
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
97 } rmt_channel_t;
acc1904cd70d Migrated to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
98
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 #ifdef __cplusplus
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 #endif
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104 #endif // OWB_RMT_H

mercurial