17static bool IRAM_ATTR HOT rmt_callback(rmt_channel_handle_t channel,
const rmt_rx_done_event_data_t *event,
void *arg) {
33 rmt_receive(channel, (uint8_t *) store->buffer + next_write + event_size, store->receive_size, &store->config);
41 rmt_rx_channel_config_t channel;
42 memset(&channel, 0,
sizeof(channel));
43 channel.clk_src = RMT_CLK_SRC_DEFAULT;
46 channel.gpio_num = gpio_num_t(this->
pin_->
get_pin());
47 channel.intr_priority = 0;
48 channel.flags.invert_in = 0;
50 channel.flags.io_loop_back = 0;
51 esp_err_t error = rmt_new_rx_channel(&channel, &this->
channel_);
52 if (error != ESP_OK) {
54 if (error == ESP_ERR_NOT_FOUND) {
68 if (error != ESP_OK) {
75 rmt_rx_event_callbacks_t callbacks;
76 memset(&callbacks, 0,
sizeof(callbacks));
77 callbacks.on_recv_done = rmt_callback;
78 error = rmt_rx_register_event_callbacks(this->
channel_, &callbacks, &this->
store_);
79 if (error != ESP_OK) {
86 uint32_t event_size =
sizeof(rmt_rx_done_event_data_t);
87 uint32_t max_filter_ns = 255u * 1000 / (RMT_CLK_FREQ / 1000000);
88 memset(&this->
store_.
config, 0,
sizeof(this->store_.config));
95 error = rmt_receive(this->
channel_, (uint8_t *) this->
store_.
buffer + event_size, this->store_.receive_size,
96 &this->store_.config);
97 if (error != ESP_OK) {
127 ESP_LOGE(TAG,
"Receive error");
133 ESP_LOGW(TAG,
"Buffer overflow");
138 rmt_rx_done_event_data_t *
event = (rmt_rx_done_event_data_t *) (this->
store_.
buffer + this->store_.buffer_read);
139 uint32_t event_size =
sizeof(rmt_rx_done_event_data_t);
140 uint32_t next_read = this->
store_.
buffer_read + event_size +
event->num_symbols *
sizeof(rmt_symbol_word_t);
144 this->
decode_rmt_(event->received_symbols, event->num_symbols);
147 if (!this->
temp_.empty()) {
154 bool prev_level =
false;
155 bool idle_level =
false;
156 uint32_t prev_length = 0;
161 ESP_LOGVV(TAG,
"START:");
162 for (
size_t i = 0; i < item_count; i++) {
163 if (item[i].level0) {
164 ESP_LOGVV(TAG,
"%zu A: ON %" PRIu32
"us (%u ticks)", i, this->
to_microseconds_(item[i].duration0),
167 ESP_LOGVV(TAG,
"%zu A: OFF %" PRIu32
"us (%u ticks)", i, this->
to_microseconds_(item[i].duration0),
170 if (item[i].level1) {
171 ESP_LOGVV(TAG,
"%zu B: ON %" PRIu32
"us (%u ticks)", i, this->
to_microseconds_(item[i].duration1),
174 ESP_LOGVV(TAG,
"%zu B: OFF %" PRIu32
"us (%u ticks)", i, this->
to_microseconds_(item[i].duration1),
178 ESP_LOGVV(TAG,
"\n");
180 this->
temp_.reserve(item_count * 2);
181 for (
size_t i = 0; i < item_count; i++) {
182 if (item[i].duration0 == 0u) {
185 }
else if ((
bool(item[i].level0) == prev_level) || (item[i].duration0 < filter_ticks)) {
186 prev_length += item[i].duration0;
188 if (prev_length >= filter_ticks) {
195 prev_level = bool(item[i].level0);
196 prev_length = item[i].duration0;
198 idle_level = !bool(item[i].level0);
200 if (item[i].duration1 == 0u) {
203 }
else if ((
bool(item[i].level1) == prev_level) || (item[i].duration1 < filter_ticks)) {
204 prev_length += item[i].duration1;
206 if (prev_length >= filter_ticks) {
213 prev_level = bool(item[i].level1);
214 prev_length = item[i].duration1;
216 idle_level = !bool(item[i].level1);
218 if (prev_length >= filter_ticks && prev_level != idle_level) {
225 if (!this->
temp_.empty()) {
229 this->
temp_.push_back(-int32_t(this->
idle_us_) * multiplier);