ESPHome 2026.2.4
Loading...
Searching...
No Matches
remote_transmitter.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <vector>
7
8#if defined(USE_ESP32)
9#include <soc/soc_caps.h>
10#if SOC_RMT_SUPPORTED
11#include <driver/rmt_tx.h>
12#endif // SOC_RMT_SUPPORTED
13#endif // USE_ESP32
14
16
17#if defined(USE_ESP32) && SOC_RMT_SUPPORTED
18#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 1)
19// IDF version 5.5.1 and above is required because of a bug in
20// the RMT encoder: https://github.com/espressif/esp-idf/issues/17244
21typedef union { // NOLINT(modernize-use-using)
22 struct {
23 uint16_t duration : 15;
24 uint16_t level : 1;
25 };
26 uint16_t val;
28
30 uint32_t times{0};
31 uint32_t index{0};
32};
33#endif
34#endif
35
37 public Component
38#if defined(USE_ESP32) && SOC_RMT_SUPPORTED
39 ,
41#endif
42{
43 public:
45 void setup() override;
46
47 void dump_config() override;
48
49 // transmitter setup must run after receiver setup to allow the same GPIO to be used by both
50 float get_setup_priority() const override { return setup_priority::DATA - 1; }
51
52 void set_carrier_duty_percent(uint8_t carrier_duty_percent) { this->carrier_duty_percent_ = carrier_duty_percent; }
53
54 void digital_write(bool value);
55
56#if defined(USE_ESP32) && SOC_RMT_SUPPORTED
57 void set_with_dma(bool with_dma) { this->with_dma_ = with_dma; }
58 void set_eot_level(bool eot_level) { this->eot_level_ = eot_level; }
59 void set_non_blocking(bool non_blocking) { this->non_blocking_ = non_blocking; }
60#endif
61
64
65 protected:
66 void send_internal(uint32_t send_times, uint32_t send_wait) override;
67#if defined(USE_ESP8266) || defined(USE_LIBRETINY) || defined(USE_RP2040) || (defined(USE_ESP32) && !SOC_RMT_SUPPORTED)
68 void calculate_on_off_time_(uint32_t carrier_frequency, uint32_t *on_time_period, uint32_t *off_time_period);
69
70 void mark_(uint32_t on_time, uint32_t off_time, uint32_t usec);
71
72 void space_(uint32_t usec);
73
74 void await_target_time_();
75 uint32_t target_time_;
76#endif
77
78#if defined(USE_ESP32) && SOC_RMT_SUPPORTED
79 void configure_rmt_();
80 void wait_for_rmt_();
81
82#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 1)
84 std::vector<rmt_symbol_half_t> rmt_temp_;
85#else
86 std::vector<rmt_symbol_word_t> rmt_temp_;
87#endif
89 bool initialized_{false};
90 bool with_dma_{false};
91 bool eot_level_{false};
92 rmt_channel_handle_t channel_{NULL};
93 rmt_encoder_handle_t encoder_{NULL};
94 esp_err_t error_code_{ESP_OK};
95 std::string error_string_{""};
96 bool inverted_{false};
97 bool non_blocking_{false};
98#endif
100
103};
104
105} // namespace esphome::remote_transmitter
void send_internal(uint32_t send_times, uint32_t send_wait) override
void calculate_on_off_time_(uint32_t carrier_frequency, uint32_t *on_time_period, uint32_t *off_time_period)
void mark_(uint32_t on_time, uint32_t off_time, uint32_t usec)
void set_carrier_duty_percent(uint8_t carrier_duty_percent)
const float DATA
For components that import data from directly connected sensors like DHT.
Definition component.cpp:84