ESPHome 2025.11.0b4
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 <driver/rmt_tx.h>
10#endif
11
12namespace esphome {
13namespace remote_transmitter {
14
15#ifdef USE_ESP32
16#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 1)
17// IDF version 5.5.1 and above is required because of a bug in
18// the RMT encoder: https://github.com/espressif/esp-idf/issues/17244
19typedef union { // NOLINT(modernize-use-using)
20 struct {
21 uint16_t duration : 15;
22 uint16_t level : 1;
23 };
24 uint16_t val;
26
28 uint32_t times{0};
29 uint32_t index{0};
30};
31#endif
32#endif
33
35 public Component
36#ifdef USE_ESP32
37 ,
39#endif
40{
41 public:
43 void setup() override;
44
45 void dump_config() override;
46
47 // transmitter setup must run after receiver setup to allow the same GPIO to be used by both
48 float get_setup_priority() const override { return setup_priority::DATA - 1; }
49
50 void set_carrier_duty_percent(uint8_t carrier_duty_percent) { this->carrier_duty_percent_ = carrier_duty_percent; }
51
52 void digital_write(bool value);
53
54#if defined(USE_ESP32)
55 void set_with_dma(bool with_dma) { this->with_dma_ = with_dma; }
56 void set_eot_level(bool eot_level) { this->eot_level_ = eot_level; }
57 void set_non_blocking(bool non_blocking) { this->non_blocking_ = non_blocking; }
58#endif
59
62
63 protected:
64 void send_internal(uint32_t send_times, uint32_t send_wait) override;
65#if defined(USE_ESP8266) || defined(USE_LIBRETINY)
66 void calculate_on_off_time_(uint32_t carrier_frequency, uint32_t *on_time_period, uint32_t *off_time_period);
67
68 void mark_(uint32_t on_time, uint32_t off_time, uint32_t usec);
69
70 void space_(uint32_t usec);
71
72 void await_target_time_();
73 uint32_t target_time_;
74#endif
75
76#ifdef USE_ESP32
77 void configure_rmt_();
78 void wait_for_rmt_();
79
80#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 1)
82 std::vector<rmt_symbol_half_t> rmt_temp_;
83#else
84 std::vector<rmt_symbol_word_t> rmt_temp_;
85#endif
87 bool initialized_{false};
88 bool with_dma_{false};
89 bool eot_level_{false};
90 rmt_channel_handle_t channel_{NULL};
91 rmt_encoder_handle_t encoder_{NULL};
92 esp_err_t error_code_{ESP_OK};
93 std::string error_string_{""};
94 bool inverted_{false};
95 bool non_blocking_{false};
96#endif
98
101};
102
103} // namespace remote_transmitter
104} // namespace esphome
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:59
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7