ESPHome  2025.2.0
remote_receiver.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 #include <cinttypes>
7 
8 #if defined(USE_ESP32) && ESP_IDF_VERSION_MAJOR >= 5
9 #include <driver/rmt_rx.h>
10 #endif
11 
12 namespace esphome {
13 namespace remote_receiver {
14 
15 #if defined(USE_ESP8266) || defined(USE_LIBRETINY)
17  static void gpio_intr(RemoteReceiverComponentStore *arg);
18 
22  volatile uint32_t *buffer{nullptr};
24  volatile uint32_t buffer_write_at;
26  uint32_t buffer_read_at{0};
27  bool overflow{false};
28  uint32_t buffer_size{1000};
29  uint32_t filter_us{10};
31 };
32 #elif defined(USE_ESP32) && ESP_IDF_VERSION_MAJOR >= 5
35  volatile uint8_t *buffer{nullptr};
37  volatile uint32_t buffer_write{0};
39  volatile uint32_t buffer_read{0};
40  bool overflow{false};
41  uint32_t buffer_size{1000};
42  uint32_t receive_size{0};
43  uint32_t filter_symbols{0};
44  esp_err_t error{ESP_OK};
45  rmt_receive_config_t config;
46 };
47 #endif
48 
50  public Component
51 #ifdef USE_ESP32
52  ,
54 #endif
55 
56 {
57  public:
58 #if defined(USE_ESP32) && ESP_IDF_VERSION_MAJOR < 5
59  RemoteReceiverComponent(InternalGPIOPin *pin, uint8_t mem_block_num = 1)
60  : RemoteReceiverBase(pin), remote_base::RemoteRMTChannel(mem_block_num) {}
61 
62  RemoteReceiverComponent(InternalGPIOPin *pin, rmt_channel_t channel, uint8_t mem_block_num = 1)
63  : RemoteReceiverBase(pin), remote_base::RemoteRMTChannel(channel, mem_block_num) {}
64 #else
65  RemoteReceiverComponent(InternalGPIOPin *pin) : RemoteReceiverBase(pin) {}
66 #endif
67  void setup() override;
68  void dump_config() override;
69  void loop() override;
70  float get_setup_priority() const override { return setup_priority::DATA; }
71 
72 #if defined(USE_ESP32) && ESP_IDF_VERSION_MAJOR >= 5
73  void set_filter_symbols(uint32_t filter_symbols) { this->filter_symbols_ = filter_symbols; }
74  void set_receive_symbols(uint32_t receive_symbols) { this->receive_symbols_ = receive_symbols; }
75  void set_with_dma(bool with_dma) { this->with_dma_ = with_dma; }
76 #endif
77  void set_buffer_size(uint32_t buffer_size) { this->buffer_size_ = buffer_size; }
78  void set_filter_us(uint32_t filter_us) { this->filter_us_ = filter_us; }
79  void set_idle_us(uint32_t idle_us) { this->idle_us_ = idle_us; }
80 
81  protected:
82 #ifdef USE_ESP32
83 #if ESP_IDF_VERSION_MAJOR >= 5
84  void decode_rmt_(rmt_symbol_word_t *item, size_t item_count);
85  rmt_channel_handle_t channel_{NULL};
86  uint32_t filter_symbols_{0};
87  uint32_t receive_symbols_{0};
88  bool with_dma_{false};
89 #else
90  void decode_rmt_(rmt_item32_t *item, size_t item_count);
91  RingbufHandle_t ringbuf_;
92 #endif
93  esp_err_t error_code_{ESP_OK};
94  std::string error_string_{""};
95 #endif
96 
97 #if defined(USE_ESP8266) || defined(USE_LIBRETINY) || (defined(USE_ESP32) && ESP_IDF_VERSION_MAJOR >= 5)
100 #endif
101 
102  uint32_t buffer_size_{};
103  uint32_t filter_us_{10};
104  uint32_t idle_us_{10000};
105 };
106 
107 } // namespace remote_receiver
108 } // namespace esphome
void setup()
void loop()
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
volatile uint32_t buffer_read
The position last read from.
Copy of GPIOPin that is safe to use from ISRs (with no virtual functions)
Definition: gpio.h:73
Helper class to request loop() to be called as fast as possible.
Definition: helpers.h:630
volatile uint32_t buffer_write_at
The position last written to.
void set_filter_symbols(uint32_t filter_symbols)
RemoteReceiverComponent(InternalGPIOPin *pin, rmt_channel_t channel, uint8_t mem_block_num=1)
static void gpio_intr(RemoteReceiverComponentStore *arg)
uint32_t buffer_read_at
The position last read from.
volatile uint32_t * buffer
Stores the time (in micros) that the leading/falling edge happened at.
volatile uint32_t buffer_write
The position last written to.
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void set_receive_symbols(uint32_t receive_symbols)
RemoteReceiverComponent(InternalGPIOPin *pin, uint8_t mem_block_num=1)