P4-Nano: controller port with the C6 as ESP-NOW radio, and the simulator
The controller now builds for the Waveshare ESP32-P4-Nano only (plus the linux sim and the desktop); the S3 stays for the USB/network bridge in bridge/. - radio-c6/: C6 firmware, esp-hosted plus ESP-NOW over peer data. The P4 loads it from the slave_fw partition when the C6 runs another version (c6_update.c) - bridge_hosted.c: the C6 as the always-on "c6" bridge, and the P4 as a network bridge on UDP 8766 for the desktop - Ethernet on the P4's EMAC, ES8311 mic; default address 192.168.50.20. The W5500, INMP441 and direct ESP-NOW code is gone - The simulated rig at /sim/ is built into the board image, with an always-on "browser" bridge. Its frames go through a queue so a slow page cannot hold up the radio, and frames for simulated bars are not sent over the C6. Receiver buffers are on the heap; a bar's flash file is only written when it changes - HTTP server: more handlers, sockets and stack for the rig - docs/P4_NANO.md, README and Makefile updated; graphify output Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ba8e160aee
commit
4ab0c7c6d7
101 files changed
+3284
-971
No files matched your search
+33
-69
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* v2 controller: W5500 Ethernet, INMP441 beat detection, ESP-NOW master.
|
||||
* v2 controller on the Waveshare ESP32-P4-Nano: Ethernet on the internal EMAC (IP101), beat detection from the
|
||||
* ES8311 microphone, and Wi-Fi and ESP-NOW on the C6 next to it (bridge_hosted.c). See docs/P4_NANO.md.
|
||||
*/
|
||||
#include "auth.h"
|
||||
#include <stdio.h>
|
||||
@@ -12,12 +13,10 @@
|
||||
#include <stdlib.h>
|
||||
#include "esp_netif.h"
|
||||
#include "esp_eth.h"
|
||||
#include "esp_eth_mac_w5500.h"
|
||||
#include "esp_eth_phy_w5500.h"
|
||||
#include "bridge_hosted.h"
|
||||
#include "esp_mac.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/spi_master.h"
|
||||
#include "esp_http_server.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_heap_caps.h"
|
||||
@@ -38,6 +37,7 @@
|
||||
#include "api.h"
|
||||
#include "engine.h"
|
||||
#include "seqplay.h"
|
||||
#include "sim_rig.h"
|
||||
#include "audio_api.h"
|
||||
#include "rel.h"
|
||||
#include "web.h"
|
||||
@@ -84,7 +84,7 @@ static esp_err_t status_get_handler(httpd_req_t *req)
|
||||
mic_get_level(&level);
|
||||
espnow_tx_stats(&es);
|
||||
rel_stats(&rs);
|
||||
if (s_eth_netif) { // NULL when the W5500 did not start
|
||||
if (s_eth_netif) { // NULL when Ethernet did not start
|
||||
esp_netif_get_ip_info(s_eth_netif, &ip_info);
|
||||
esp_netif_get_mac(s_eth_netif, mac);
|
||||
}
|
||||
@@ -119,9 +119,9 @@ static esp_err_t status_get_handler(httpd_req_t *req)
|
||||
#define DEFAULT_HOSTNAME "led-controller"
|
||||
|
||||
// Address when no DHCP server answers, as on a cable straight to a PC. The PC needs a static IP on this subnet.
|
||||
#define DEFAULT_IP ESP_IP4TOADDR(192, 168, 4, 1)
|
||||
#define DEFAULT_IP ESP_IP4TOADDR(CONFIG_P4_DEFAULT_IP_A, CONFIG_P4_DEFAULT_IP_B, CONFIG_P4_DEFAULT_IP_C, CONFIG_P4_DEFAULT_IP_D)
|
||||
#define DHCP_WAIT_S 5 // the Nano usually sits on a cable to the PC, with no DHCP server
|
||||
#define DEFAULT_NETMASK ESP_IP4TOADDR(255, 255, 255, 0)
|
||||
#define DHCP_WAIT_S 15
|
||||
|
||||
// Boolean setting; def when missing or not a boolean
|
||||
static bool settings_bool(const char *key, bool def)
|
||||
@@ -299,10 +299,10 @@ static void start_webserver(void)
|
||||
}
|
||||
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
|
||||
config.uri_match_fn = httpd_uri_match_wildcard;
|
||||
config.max_uri_handlers = 80;
|
||||
config.stack_size = 8192;
|
||||
config.max_uri_handlers = 112;
|
||||
config.stack_size = 12288; // the rig's room and flash files (sim_rig.c) need more than 8 KB
|
||||
config.lru_purge_enable = true;
|
||||
config.max_open_sockets = 12; // browsers open 6 connections at once
|
||||
config.max_open_sockets = 24; // browsers open 6 connections at once, and the rig page its own
|
||||
config.backlog_conn = 10; // the default 5 drops the 6th SYN, a 1 s retry
|
||||
if (httpd_start(&s_server, &config) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "HTTP server start failed");
|
||||
@@ -310,6 +310,7 @@ static void start_webserver(void)
|
||||
}
|
||||
const httpd_uri_t status_uri = { .uri = "/status", .method = HTTP_GET, .handler = status_get_handler };
|
||||
auth_register_uri(s_server, &status_uri);
|
||||
sim_rig_register(s_server); // before the pages: /sim/* is not theirs
|
||||
web_register(s_server);
|
||||
audio_register(s_server);
|
||||
audio_api_register(s_server);
|
||||
@@ -373,71 +374,28 @@ static void got_ip_event_handler(void *arg, esp_event_base_t event_base,
|
||||
}
|
||||
}
|
||||
|
||||
static esp_err_t w5500_init(esp_eth_handle_t *eth_handle_out)
|
||||
// The P4's own EMAC over RMII to the IP101 PHY: MDC 31, MDIO 52, 50 MHz reference in on GPIO 50 (IDF's P4
|
||||
// defaults, which match the Waveshare ESP32-P4-Nano), PHY reset on CONFIG_P4_ETH_PHY_RST_GPIO
|
||||
static esp_err_t eth_init(esp_eth_handle_t *eth_handle_out)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
esp_eth_mac_t *mac = NULL;
|
||||
esp_eth_phy_t *phy = NULL;
|
||||
esp_eth_handle_t eth_handle = NULL;
|
||||
|
||||
// INT pin uses a GPIO ISR
|
||||
ESP_RETURN_ON_ERROR(gpio_install_isr_service(0), TAG, "GPIO ISR service install failed");
|
||||
|
||||
spi_bus_config_t buscfg = {
|
||||
.miso_io_num = CONFIG_W5500_MISO_GPIO,
|
||||
.mosi_io_num = CONFIG_W5500_MOSI_GPIO,
|
||||
.sclk_io_num = CONFIG_W5500_SCLK_GPIO,
|
||||
.quadwp_io_num = -1,
|
||||
.quadhd_io_num = -1,
|
||||
};
|
||||
ESP_RETURN_ON_ERROR(spi_bus_initialize(CONFIG_W5500_SPI_HOST, &buscfg, SPI_DMA_CH_AUTO),
|
||||
TAG, "SPI bus init failed");
|
||||
|
||||
spi_device_interface_config_t spi_devcfg = {
|
||||
.mode = 0,
|
||||
.clock_speed_hz = CONFIG_W5500_SPI_CLOCK_MHZ * 1000 * 1000,
|
||||
.queue_size = 20,
|
||||
.spics_io_num = CONFIG_W5500_CS_GPIO,
|
||||
};
|
||||
|
||||
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(CONFIG_W5500_SPI_HOST, &spi_devcfg);
|
||||
w5500_config.base.int_gpio_num = CONFIG_W5500_INT_GPIO;
|
||||
if (CONFIG_W5500_INT_GPIO < 0) {
|
||||
w5500_config.base.poll_period_ms = CONFIG_W5500_POLL_PERIOD_MS;
|
||||
}
|
||||
|
||||
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
|
||||
eth_esp32_emac_config_t emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG();
|
||||
emac_config.smi_gpio.mdc_num = CONFIG_P4_ETH_MDC_GPIO;
|
||||
emac_config.smi_gpio.mdio_num = CONFIG_P4_ETH_MDIO_GPIO;
|
||||
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
|
||||
phy_config.reset_gpio_num = CONFIG_W5500_RST_GPIO;
|
||||
|
||||
mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
|
||||
phy = esp_eth_phy_new_w5500(&phy_config);
|
||||
ESP_GOTO_ON_FALSE(mac && phy, ESP_FAIL, err, TAG, "W5500 MAC/PHY create failed");
|
||||
|
||||
phy_config.phy_addr = ESP_ETH_PHY_ADDR_AUTO;
|
||||
phy_config.reset_gpio_num = CONFIG_P4_ETH_PHY_RST_GPIO;
|
||||
esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&emac_config, &mac_config);
|
||||
esp_eth_phy_t *phy = esp_eth_phy_new_generic(&phy_config); // the IP101 is a plain 802.3 PHY
|
||||
ESP_RETURN_ON_FALSE(mac && phy, ESP_FAIL, TAG, "EMAC/PHY create failed");
|
||||
esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy);
|
||||
ESP_GOTO_ON_ERROR(esp_eth_driver_install(ð_config, ð_handle), err, TAG,
|
||||
"Driver install failed (check W5500 wiring/power)");
|
||||
|
||||
// The W5500 has no factory MAC; use the ESP32's Ethernet MAC from eFuse
|
||||
uint8_t eth_mac[6];
|
||||
ESP_GOTO_ON_ERROR(esp_read_mac(eth_mac, ESP_MAC_ETH), err, TAG, "Read MAC failed");
|
||||
ESP_GOTO_ON_ERROR(esp_eth_ioctl(eth_handle, ETH_CMD_S_MAC_ADDR, eth_mac), err, TAG, "Set MAC failed");
|
||||
|
||||
*eth_handle_out = eth_handle;
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
if (eth_handle) {
|
||||
esp_eth_driver_uninstall(eth_handle);
|
||||
}
|
||||
if (mac) {
|
||||
esp_err_t err = esp_eth_driver_install(ð_config, eth_handle_out);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Ethernet driver install failed: %s", esp_err_to_name(err));
|
||||
mac->del(mac);
|
||||
}
|
||||
if (phy) {
|
||||
phy->del(phy);
|
||||
}
|
||||
spi_bus_free(CONFIG_W5500_SPI_HOST);
|
||||
return ret;
|
||||
return err;
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
@@ -461,11 +419,17 @@ void app_main(void)
|
||||
ESP_LOGI(TAG, "AP %s%s", s_ap_on ? "on" : "off", held ? " (button held)" : "");
|
||||
char bridges[BRIDGE_MAX_LINKS][BRIDGE_ADDR_MAX]; // led-simulator or a network/USB bridge stands in for the radio
|
||||
espnow_tx_set_bridges(bridges, store_bridges(bridges, BRIDGE_MAX_LINKS));
|
||||
// The C6 is the radio: without it there is no Wi-Fi and no ESP-NOW, but the web UI still runs on Ethernet
|
||||
if (bridge_hosted_start() != ESP_OK) {
|
||||
ESP_LOGE(TAG, "C6 radio down: no Wi-Fi access point and no ESP-NOW");
|
||||
s_ap_on = false;
|
||||
}
|
||||
ESP_ERROR_CHECK(espnow_tx_init(s_ap_on ? (host ? host : DEFAULT_HOSTNAME) : NULL, settings_str("ap_password")));
|
||||
bridge_hosted_udp_start();
|
||||
|
||||
// Ethernet is optional: without it the web UI is still served over the AP
|
||||
esp_eth_handle_t eth_handle = NULL;
|
||||
if (w5500_init(ð_handle) == ESP_OK) {
|
||||
if (eth_init(ð_handle) == ESP_OK) {
|
||||
esp_netif_config_t netif_cfg = ESP_NETIF_DEFAULT_ETH();
|
||||
s_eth_netif = esp_netif_new(&netif_cfg);
|
||||
ESP_ERROR_CHECK(esp_netif_attach(s_eth_netif, esp_eth_new_netif_glue(eth_handle)));
|
||||
|
||||
Reference in new issue
Block a user