#include #include "app_networking.hpp" #include "freertos/FreeRTOS.h" #include "freertos/queue.h" #include "nvs_flash.h" #include "esp_now.h" namespace { TaskHandle_t s_main_task = nullptr; QueueSetHandle_t s_queue_set = nullptr; QueueHandle_t s_esp_now_queue = nullptr; QueueHandle_t s_uart_queue = nullptr; void s_cbEspNowSendComplete(const std::uint8_t* peer_mac, esp_now_send_status_t status) { } void s_cbEspNowReceiveComplete(const esp_now_recv_info_t* recv_info, const std::uint8_t* data, int len) { } void s_mainTask(void*) { bool radio_tx_busy = false; bool uart_tx_busy = false; while (true) { const std::uint32_t notification = ulTaskNotifyTake(pdTRUE, portMAX_DELAY); if (notification & (1 << 0)) { // Radio RX complete. // Send to uart. uart_tx_busy = true; } if (notification & (1 << 1)) { // UART RX ISR fired. Send to radio. // UART RX FIFO is 128 bytes for C3. UART_RXFIFO_FULL_INT, set by UART_RXFIFO_THRHD. radio_tx_busy = true; } if (notification & (1 << 2)) { radio_tx_busy = false; // radio TX complete. } if (notification & (1 << 3)) { uart_tx_busy = false; // uart TX complete. UART_TX_DONE_INT } } } } extern "C" void app_main(void) { ESP_ERROR_CHECK(nvs_flash_init()); App::setupWifi(); App::setupEspNow(); ESP_ERROR_CHECK(esp_now_register_send_cb(s_cbMessageSendComplete)); ESP_ERROR_CHECK(esp_now_register_recv_cb(s_cbMessageReceiveComplete)); xTaskCreate(s_mainTask, "main_task", 2048, nullptr, 4, &s_main_task); }