2024-05-21 11:52:50 +03:00
|
|
|
#include "stdio.h"
|
|
|
|
#include "driver/rmt_rx.h"
|
|
|
|
#include "driver/gpio.h"
|
|
|
|
// #include "freertos/queue.h"
|
|
|
|
// #include "freertos/task.h"
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
|
|
|
|
// static bool example_rmt_rx_done_callback(rmt_channel_handle_t channel, const rmt_rx_done_event_data_t *edata, void *user_data)
|
|
|
|
// {
|
|
|
|
// // BaseType_t high_task_wakeup = pdFALSE;
|
|
|
|
// // QueueHandle_t receive_queue = (QueueHandle_t)user_data;
|
|
|
|
// // // send the received RMT symbols to the parser task
|
|
|
|
// // xQueueSendFromISR(receive_queue, edata, &high_task_wakeup);
|
|
|
|
// // // return whether any task is woken up
|
|
|
|
// // return high_task_wakeup == pdTRUE;
|
|
|
|
// }
|
|
|
|
|
|
|
|
void app_main(void)
|
|
|
|
{
|
|
|
|
gpio_config_t config;
|
|
|
|
config.intr_type = GPIO_INTR_DISABLE;
|
|
|
|
config.mode = GPIO_MODE_INPUT;
|
|
|
|
config.pin_bit_mask = (1ULL << 5);
|
|
|
|
config.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
|
|
|
config.pull_up_en = GPIO_PULLUP_ENABLE;
|
|
|
|
gpio_config(&config);
|
|
|
|
gpio_set_direction(5, GPIO_MODE_OUTPUT);
|
|
|
|
gpio_set_level(5, 0);
|
|
|
|
vTaskDelay(10 / portTICK_PERIOD_MS);
|
|
|
|
// gpio_set_level(5, 1);
|
|
|
|
gpio_set_direction(5, GPIO_MODE_INPUT);
|
|
|
|
|
|
|
|
rmt_channel_handle_t rx_channel = NULL;
|
|
|
|
rmt_rx_channel_config_t rx_chan_config = {
|
|
|
|
.gpio_num = 5, // GPIO number
|
|
|
|
.clk_src = RMT_CLK_SRC_DEFAULT, // select source clock
|
|
|
|
.resolution_hz = 1 * 1000 * 1000, // 1MHz tick resolution, i.e. 1 tick = 1us
|
|
|
|
.mem_block_symbols = 64, // memory block size, 64 * 4 = 256Bytes
|
|
|
|
.flags.invert_in = false, // don't invert input signal
|
|
|
|
.flags.with_dma = false, // don't need DMA backend
|
|
|
|
// .flags.io_loop_back=false,
|
|
|
|
// .intr_priority=0,
|
|
|
|
};
|
|
|
|
ESP_ERROR_CHECK(rmt_new_rx_channel(&rx_chan_config, &rx_channel));
|
|
|
|
|
|
|
|
// QueueHandle_t receive_queue = xQueueCreate(1, sizeof(rmt_rx_done_event_data_t));
|
|
|
|
// rmt_rx_event_callbacks_t cbs = {
|
|
|
|
// .on_recv_done = example_rmt_rx_done_callback,
|
|
|
|
// };
|
|
|
|
// ESP_ERROR_CHECK(rmt_rx_register_event_callbacks(rx_channel, &cbs, NULL));
|
|
|
|
|
|
|
|
// the following timing requirement is based on NEC protocol
|
|
|
|
rmt_receive_config_t receive_config = {
|
|
|
|
.signal_range_min_ns = 20000, // the shortest duration for NEC signal is 560us, 1250ns < 560us, valid signal won't be treated as noise
|
|
|
|
.signal_range_max_ns = 90000, // the longest duration for NEC signal is 9000us, 12000000ns > 9000us, the receive won't stop early
|
|
|
|
};
|
|
|
|
|
|
|
|
rmt_symbol_word_t raw_symbols[64]; // 64 symbols should be sufficient for a standard NEC frame
|
|
|
|
// ready to receive
|
|
|
|
ESP_ERROR_CHECK(rmt_receive(rx_channel, raw_symbols, sizeof(raw_symbols), &receive_config));
|
|
|
|
// wait for RX done signal
|
|
|
|
for (uint8_t i = 0; i < 64; ++i)
|
|
|
|
{
|
2024-05-21 11:55:23 +03:00
|
|
|
printf("%d - %d, %d, %d, %d\n", raw_symbols[i].duration0, raw_symbols[i].level0, raw_symbols[i].duration1, raw_symbols[i].level1);
|
2024-05-21 11:52:50 +03:00
|
|
|
}
|
|
|
|
}
|