Initial commit
This commit is contained in:
parent
c55149afc2
commit
2a9abffffb
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
build/
|
||||||
|
sdkconfig
|
||||||
|
sdkconfig.old
|
||||||
|
|
||||||
|
.vscode/
|
||||||
8
CMakeLists.txt
Normal file
8
CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# For more information about build system see
|
||||||
|
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
|
||||||
|
# The following five lines of boilerplate have to be in your project's
|
||||||
|
# CMakeLists in this exact order for cmake to work correctly
|
||||||
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
project(espnow-testies)
|
||||||
3
main/CMakeLists.txt
Normal file
3
main/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
idf_component_register(SRCS "esp_tunnel.cpp"
|
||||||
|
"app_networking.cpp"
|
||||||
|
INCLUDE_DIRS ".")
|
||||||
36
main/app_networking.cpp
Normal file
36
main/app_networking.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include "app_networking.hpp"
|
||||||
|
|
||||||
|
#include "esp_event.h"
|
||||||
|
#include "esp_netif.h"
|
||||||
|
#include "esp_wifi.h"
|
||||||
|
#include "esp_now.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace App
|
||||||
|
{
|
||||||
|
|
||||||
|
void setupWifi()
|
||||||
|
{
|
||||||
|
ESP_ERROR_CHECK(esp_netif_init());
|
||||||
|
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||||
|
|
||||||
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_init(&cfg) );
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_start());
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_set_channel(1, WIFI_SECOND_CHAN_NONE));
|
||||||
|
}
|
||||||
|
|
||||||
|
void setupEspNow()
|
||||||
|
{
|
||||||
|
ESP_ERROR_CHECK(esp_now_init());
|
||||||
|
// ESP_ERROR_CHECK(esp_now_set_pmk(nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
9
main/app_networking.hpp
Normal file
9
main/app_networking.hpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace App
|
||||||
|
{
|
||||||
|
|
||||||
|
void setupWifi();
|
||||||
|
void setupEspNow();
|
||||||
|
|
||||||
|
}
|
||||||
80
main/esp_tunnel.cpp
Normal file
80
main/esp_tunnel.cpp
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
1845
sdkconfig.esp32c6.example
Normal file
1845
sdkconfig.esp32c6.example
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user