# Controller on the Waveshare ESP32-P4-Nano The v2 controller (`main/`) runs on the Waveshare ESP32-P4-Nano; it no longer builds for the ESP32-S3, which is now only a bridge board (`bridge/`). The P4 has no radio. The ESP32-C6 on the board supplies Wi-Fi through esp-hosted over SDIO, and ESP-NOW through `radio-c6/`, our firmware for the C6. ``` Ethernet (IP101, RMII) SDIO (esp-hosted 3.1) PC <-------------------------------> ESP32-P4 <-------------------------------> ESP32-C6 ~~ ESP-NOW ~~> drivers 192.168.50.10 web UI, API, controller Wi-Fi RPC + peer data radio-c6/ UDP bridge (main/) (bridge/main/radio_proto.h) ``` - **Wi-Fi** (the access point, Wi-Fi drivers): `esp_wifi_remote` runs the C6's Wi-Fi from the P4 as if it were local. - **ESP-NOW:** esp-hosted does not forward it. The controller treats the C6 as a bridge called `c6`, which is always present on this target, in `main/bridge_hosted.c`. Frames go to the C6 in batches over esp-hosted's peer-data channel. `radio-c6/main/radio_now.c` sends them one at a time and sends every frame it hears back to the P4. It does the same job as the USB bridge in `bridge/`, but over SDIO. - **Microphone:** the on-board mic goes through the ES8311 codec, set up over I2C with `esp_codec_dev`. The rest of the mic path (levels, beat detection, streaming) runs on the P4. - **Status:** `GET /settings/bridge` lists the `c6` bridge (kind `c6`) and the `browser` one ([Simulator](#simulator)). For `c6` it shows whether the C6 is linked, its MAC and channel, its counters, and which desktop is using the radio, if any. - **Cores:** both P4 cores are used. The controller's tasks are not pinned to one. ## Build and flash Use ESP-IDF v6.1 (`espressif/idf:v6.1`). The settings are `sdkconfig.defaults` and the partition table is `partitions.csv`. ```bash make sim-wasm # once, and after led-driver changes: the simulator's drivers make build # the web UI, the simulator, radio-c6/ (C6) and the controller (P4) make flash PORT=/dev/ttyACM0 # the controller, plus the C6 image into the slave_fw partition make log PORT=/dev/ttyACM0 # the console for 10 s (the board's USB-C port is a CH343 UART) make ota HOST=192.168.50.20 # later updates over Ethernet (not the C6 image: flash for that) ``` `radio-c6/` takes its version (`rc6-`) from its sources. At boot, the controller compares that version with what the C6 reports (`main/c6_update.c`). When they differ, it sends the image from `slave_fw` to the C6 over esp-hosted OTA and restarts the board. This takes about 10 seconds, and only happens on the first boot after a change. Never put the one-off updater in `scripts/c6-ota/host-v2` on the board again: it updates the C6 on every boot. ## Flash layout `partitions.csv`, 16 MB: | Partition | Size | What | | --- | --- | --- | | `ota_0`, `ota_1` | 3 MB each | the controller, web UI and simulator included | | `db` | 8.1 MB (0x820000) | LittleFS: the records, and the simulator's rooms and bars in `/db/sim` | | `slave_fw` | 1.75 MB | the C6 image | | `nvs`, `otadata`, `phy_init` | 36 KB | | ## Network The board sits on a cable straight to the PC (192.168.50.10), so there is no DHCP server. At boot it tries: 1. the settings `static_ips` 2. DHCP, for 5 seconds 3. **192.168.50.20/24**, with no gateway (menuconfig "ESP32-P4-Nano board") The web UI is at http://192.168.50.20/. ## Using it as a network bridge from the desktop The P4 also speaks the network bridge protocol, the same one as a bridge board with Ethernet (see `bridge/README.md`): - UDP 8766 carries frames. - UDP 8767 carries HELLO/INFO and the microphone. In the desktop led-controller, add the bridge `192.168.50.20:8766` (settings `"bridges": ["192.168.50.20:8766"]`). The desktop's drivers then go out over the C6, and the desktop can use the Nano's microphone as the bridge board's mic. While a desktop is sending, the P4's own controller frames are dropped, so the drivers only hear the desktop. The P4 logs the hand-over. When the desktop has been quiet for 2 seconds, the P4's controller takes the radio back. ## Pins (from the Waveshare wiki and BSP) | What | GPIO | | --- | --- | | Ethernet: MDC, MDIO, PHY reset, 50 MHz REF_CLK in | 31, 52, 51, 50 | | RMII: TXD0, TXD1, TX_EN, RXD0, RXD1, CRS_DV | 34, 35, 49, 30, 29, 28 (IDF's P4 defaults) | | ES8311: I2C SDA, SCL (address 0x18) | 7, 8 | | ES8311: I2S MCLK, BCLK, WS, ADC data in | 13, 12, 10, 11 | | C6 over SDIO: CLK, CMD, D0-D3, C6 reset | 18, 19, 14-17, 54 | The board has no user button or user LED, so the AP button and beat LED are off. ## Back to the factory demo The board's original 16 MB flash is saved in `~/esp-backups/p4-nano-factory-e8f60ae851f8.bin`: ```bash docker run --rm --device=/dev/ttyACM0 -v ~/esp-backups:/b espressif/idf:v6.1 esptool -p /dev/ttyACM0 -b 921600 write-flash 0 /b/p4-nano-factory-e8f60ae851f8.bin ``` The C6 keeps running `radio-c6`. Waveshare's demo uses an older esp-hosted, which may not work with it. ## Simulator The board serves the same simulated rig as the desktop at `/sim/` (Menu > Simulator; see `led-simulator/README.md`). The bars run in the browser and get the controller's frames from the `browser` bridge, which is always on next to `c6`. Frames addressed to simulated bars (MACs starting 02:51:4d) are not sent over the C6. A page that reads too slowly loses frames; the radio does not wait for it. Rooms and the bars' flash are in `/db/sim`. `make build` packs the page from `led-simulator/web`. The bars' WebAssembly comes from `make sim-wasm`; without it `/sim/` only says how to build it. `make build` reuses whatever WebAssembly is there, so run `make sim-wasm` again after led-driver changes. Art-Net and DDP sent to the board reach the rig's network fixtures. The board's own outputs reach them too, aimed at `127.0.0.1`. DMX bridges (`dmx:`) are in the host builds only.