Files
led-controller/bridge
jimmyandClaude Opus 5.5 4ab0c7c6d7 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>
2026-11-24 21:45:25 +13:00
..

USB ESP-NOW bridge

An ESP32 board that gives a computer an ESP-NOW radio. Two builds: an ESP32-S3 (the one with an I2S microphone, below) and an ESP32-C3 (ESP-NOW only). led-controller running on the computer sends its ESP-NOW frames to the board over USB, and the board puts them on the air; frames from the drivers come back the same way.

led-controller (host) --SLIP over USB-Serial-JTAG--> bridge board --ESP-NOW--> LED drivers
                      <-------------------------------                <--------

Build and flash

Built with ESP-IDF v6.1 (espressif/idf:v6.1), one build directory per chip (bridge/build-s3, bridge/build-c3):

make bridge-build-s3                       # or bridge-build-c3, or bridge-build for both
make bridge-flash-s3 BRIDGE=/dev/ttyACM2   # overwrites the board's firmware
make bridge-flash-c3 BRIDGE=/dev/ttyACM1

Flash only the board you mean: the flash targets overwrite whatever is on the port.

Running the controller against it

make rig BRIDGE=/dev/ttyACM1               # the sim-controller build, web UI on http://localhost:8080/

Or set the bridge in settings ("bridge": "/dev/ttyACM1"), or LED_SIM_BRIDGE=/dev/ttyACM1 for the sim. The controller reconnects if the board is unplugged. Its status (GET /status, field bridge_links, one entry per bridge) shows whether the board is linked, its MAC and channel, and the counters.

Microphone (S3)

The S3 build reads an I2S microphone (an INMP441 wired as on the controller's XIAO ESP32-S3: SCK GPIO 5, WS GPIO 6, SD GPIO 43, configurable under "Bridge microphone (I2S)" in menuconfig). While the desktop records from it, the board sends 10 ms blocks of 16 kHz mono audio (AUDIO frames, below). The desktop lists it in the audio input list as "I2S microphone on the bridge board". The C3 build has no microphone and reports that in INFO.

Channel

ESP-NOW runs on one Wi-Fi channel, and the drivers and the bridge must share it. The bridge starts on channel 6. Set the channel the drivers use (the access point's, or the router's when a driver is joined to one), either by a SET_CHANNEL frame (bridge_serial_set_channel) or by changing it on the board's NVS.

Protocol

SLIP frames, each [type][body][crc16 LE] (CRC-16/CCITT-FALSE over type and body). The single source is main/bridge_proto.h, shared by the firmware and the host (main/bridge_serial.c).

type direction body
00 PKT host → board dst_mac(6) + packet → ESP-NOW
00 PKT board → host src_mac(6) + packet for every ESP-NOW frame received
10 HELLO host → board (empty); answered with INFO
11 INFO board → host version, MAC, channel, tx, tx_fail, rx, drop counters
12 SET_CHANNEL host → board channel (1-13); answered with INFO
13 SET_MIC host → board on (1) or off (0): send microphone audio
40 AUDIO board → host 160 16-bit little-endian mono samples at 16 kHz, while the mic is on
30 LOG board → host a log line

INFO's last byte is capabilities: bit 0 is set when the board has a microphone.

The board sends one PKT at a time and waits for each send's result, so a burst cannot overrun the radio.

Ethernet (W5500)

The S3 board also has a W5500 on SPI (XIAO pins by default: SCLK 7, MISO 8, MOSI 9, CS 2, INT 3, RST 1; change them in make menuconfig under "Bridge Ethernet (W5500)"). It takes DHCP and answers UDP on port 8766, with the same datagrams as the simulator's bridge: send dst_mac + packet and the board puts it on ESP-NOW; each frame it hears comes back to the last sender as src_mac + packet.

The board's address is in INFO (bytes 25-28, with the Ethernet-up bit in byte 24), so the desktop shows it under the board's status (ip). Add it as a network bridge with <ip>:8766. Don't use the USB and the UDP path for the same board at once: each frame would go out over the air twice.