Tue, 26 Sep 2023 14:57:18 +0200
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 | 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 | ||
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 | 40 | |
41 | #include "driver/rmt_tx.h" | |
42 | #include "driver/rmt_rx.h" | |
43 | ||
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 | 50 | /** |
51 | * @brief RMT driver information | |
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 | 55 | rmt_channel_handle_t tx_channel_handle; ///< RMT transmit channel, allocated by RMT driver |
56 | rmt_channel_handle_t rx_channel_handle; ///< RMT receive channel, allocated by RMT driver | |
57 | rmt_encoder_handle_t copy_encoder_handle; ///< RMT built-in data encoder that sends pre-defined symbols | |
58 | rmt_encoder_handle_t bytes_encoder_handle; ///< RMT built-in data encoder that converts bits into symbols | |
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) | |
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 | 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 | |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
74 | */ |
72 | 75 | OneWireBus* owb_rmt_initialize(owb_rmt_driver_info * info, gpio_num_t gpio_num, |
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 | ||
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 |