feat(v2): ESP32-S3 controller with Ethernet, I2S mic beat detection and ESP-NOW

New ESP-IDF project in v2/ that replaces the Pi and the UART bridge:

- W5500 Ethernet, INMP441 beat/tempo detector (from esp32-eth), ESP-NOW master
- LittleFS data store and a JSON API over the Pi's db/*.json collections,
  with /db import and export; web UI minified and gzipped at build time
- Zone play/stop as 0x4C GROUP_CMD, preset push/send as CMD (binary v2
  envelope, byte-identical to src/util/binary_envelope.py), sequencer and
  scenes, driver registration from the boot hello
- Reliable bulk link: acks with retransmit, fragments, state-version digest
  and resync; beat frames sent twice with a lead so drivers fire together
- Bench tooling: lossy-link mode, synthetic beats with echo measurement,
  USB and logic-analyzer latency scripts, and docs/BENCH_TEST.md

Needs the matching led-driver changes (p2p branch) to receive the link and
beat frames.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Sonnet 5.5 committed 2026-10-27 17:15:28 +13:00
1 parent 7336c7fb22
commit a94d6a7de5
37 files changed
+5109

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "esp_err.h"
// Reliable bulk link on top of espnow_tx. Wire format is documented in
// led-driver/src/espnow_rx.py:
// All frames are 0x4C wire packets with extra message types (see led-driver/src/espnow_rx.py):
// data [4C][20][flags][seq u16][ver u16][idx][cnt] + fragment of an inner packet (<= 9 + 238)
// ack [4C][21][0][seq u16][cnt][mask u32] (driver -> us)
// digest [4C][22][ver u16] (broadcast)
// resync [4C][23][ver u16] (driver -> us)
// echo [4C][24][beat_idx u16] (driver -> us, bench)
#define REL_FRAG_MAX 238 // inner packet bytes per frame; 4C 03/04 wrappers plus an envelope fit in one
#define REL_MAX_FRAGS 32
typedef struct {
uint32_t acked;
uint32_t ack_timeouts;
uint32_t retransmits;
uint32_t resyncs;
uint32_t digests;
} rel_stats_t;
typedef void (*rel_resync_cb_t)(const uint8_t mac[6]);
esp_err_t rel_init(void);
// Send a message of any size up to REL_MAX_FRAGS * REL_FRAG_MAX.
// mac == NULL broadcasts it `repeat` times with one sequence number (no acks);
// otherwise it is unicast, acknowledged by the driver and retransmitted until
// acked or given up on. commit makes the driver adopt the current state version.
esp_err_t rel_send(const uint8_t *mac, const void *data, size_t len, bool commit, int repeat);
// A broadcast state change happened: advance the version drivers compare in digests
void rel_bump_ver(void);
uint16_t rel_ver(void);
void rel_set_resync_cb(rel_resync_cb_t cb);
// A driver announced itself at boot: a 0x4C ANNOUNCE packet or its JSON hello (called from the rel task)
typedef void (*rel_announce_cb_t)(const uint8_t mac[6], const uint8_t *pkt, int len);
void rel_set_announce_cb(rel_announce_cb_t cb);
void rel_stats(rel_stats_t *out);
// Milliseconds since the driver last acked; -1 if never. fails = consecutive unacked messages
int rel_peer_status(const uint8_t mac[6], int *fails);