Add internet radio streaming with runtime API, modernize web UI, remove auto-tune/beep at boot

Streaming (main feature this session):
- New WebRadioConfig/WebRadioJson core types, ISecureStore-backed persistence
- New webradio::WebRadioService (thread-safe live config) + GET/POST /api/streaming
- web_radio_stream task now runtime-toggleable (no reboot), no hardcoded URL
- Content-Type diagnostic: warns clearly when a URL is a webpage, not an audio stream

Boot cleanup:
- Removed boot-time auto FM/DAB tune, auto-beep, and the (now-concluded) Si4684
  crystal IBIAS/CTUN empirical sweep from main.cpp — tuning/beep are on-demand
  via the existing REST API only

Web UI:
- Modernized styling (cards, gradients, toggle switches, light/dark theme)
- New Stream tab wired to /api/streaming

Fixes found via real idf.py build (not just clangd):
- Restored wrongly-removed si4684/Si4684Tuner.hpp include in main.cpp
- Fixed MP3Decode() argument types in web_radio_stream.cpp (unsigned char**/int*)

Quality-gate fixes:
- Host-test stub headers (esp_log.h, freertos/*) so TunerService.cpp's
  scanForStation logging/pacing compiles for station_service_test /
  integration_service_test instead of running stale binaries
- Added WifiScanner and WebRadioService manual sections; filled in missing
  Doxygen docs on BluetoothService, i2s_sdata_probe, test_firmware, Bt1035At
- Ignore clangd's .cache/ index directory

Also includes prior uncommitted work carried in the tree: Wi-Fi/Bluetooth
device scan REST API and UI (WifiScanner, BT scan), SigmaStudio TCP bridge,
and the current ADAU1701 SigmaStudio DSP program export.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-08 21:15:22 +02:00
co-authored by Claude Sonnet 5
parent 8a8523515d
commit 6f7b6dd12c
131 changed files with 20309 additions and 1702 deletions
+122 -6
View File
@@ -11,7 +11,9 @@
* @date 2026-07-06
*/
#include "board_pins.hpp"
#include "hardware_bootstrap.hpp"
#include "audio/AudioService.hpp"
#include "bluetooth/BluetoothService.hpp"
#include "integration/IntegrationService.hpp"
#include "net/NetBootstrap.hpp"
@@ -21,20 +23,104 @@
#include "si4684/Si4684Tuner.hpp"
#include "station/StationService.hpp"
#include "tuner/TunerService.hpp"
#include "web_radio_stream.hpp"
#include "webradio/WebRadioService.hpp"
#include "driver/pulse_cnt.h"
#include "esp_log.h"
#include "esp_timer.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <cstdint>
#if CONFIG_TEST_FIRMWARE
#include "test_firmware.hpp"
#endif
#if CONFIG_I2S_SDATA_PROBE
#include "i2s_sdata_probe.hpp"
#endif
namespace {
constexpr char kTag[] = "digiradio";
constexpr TickType_t kHeartbeatPeriod = pdMS_TO_TICKS(5000);
/**
* @brief logGpioClockFrequency — one-shot edge-count frequency probe.
*
* Uses the ESP32-S3 PCNT peripheral to count rising edges on an input GPIO
* over a fixed window and log the resulting frequency, so BCLK/LRCLK on the
* ADAU1701 -> ESP32 I2S bus (board::pins::I2sBclk/I2sLrclk, shared clock
* domain with the ADAU -> BT1035 link, see docs/manual/ch-bt1035.tex) can be
* verified without an oscilloscope. Read-only: the PCNT channel only listens
* on the pad, so it does not conflict with the I2S peripheral also reading
* the same GPIO later (ESP32 GPIO matrix fans one input pad out to multiple
* peripherals). windowMs must stay short enough that expected edge count
* does not exceed the PCNT hardware limit (signed 16-bit, so < 32767).
*/
void logGpioClockFrequency(const char* label, int gpio, int windowMs)
{
pcnt_unit_config_t unitConfig{};
unitConfig.low_limit = -1;
unitConfig.high_limit = 30000;
pcnt_unit_handle_t unit = nullptr;
if (pcnt_new_unit(&unitConfig, &unit) != ESP_OK) {
ESP_LOGW(kTag, "%s clock probe: pcnt_new_unit failed", label);
return;
}
pcnt_chan_config_t chanConfig{};
chanConfig.edge_gpio_num = gpio;
chanConfig.level_gpio_num = -1;
pcnt_channel_handle_t chan = nullptr;
if (pcnt_new_channel(unit, &chanConfig, &chan) != ESP_OK) {
ESP_LOGW(kTag, "%s clock probe: pcnt_new_channel failed (GPIO%d)",
label, gpio);
pcnt_del_unit(unit);
return;
}
pcnt_channel_set_edge_action(chan, PCNT_CHANNEL_EDGE_ACTION_INCREASE,
PCNT_CHANNEL_EDGE_ACTION_HOLD);
pcnt_unit_enable(unit);
pcnt_unit_clear_count(unit);
pcnt_unit_start(unit);
// Busy-wait on esp_timer instead of vTaskDelay: at the default 100 Hz
// FreeRTOS tick rate, a short requested window (e.g. 5-10 ms for BCLK)
// rounds to the nearest 10 ms tick, which is a huge relative error at
// MHz-range signals. Measuring the *actual* elapsed time afterwards
// makes the frequency calculation correct regardless of overshoot.
const std::int64_t startUs = esp_timer_get_time();
const std::int64_t targetUs = static_cast<std::int64_t>(windowMs) * 1000;
while (esp_timer_get_time() - startUs < targetUs) {
// intentionally tight: window is a few ms to a few hundred ms,
// far under any watchdog timeout.
}
pcnt_unit_stop(unit);
const std::int64_t elapsedUs = esp_timer_get_time() - startUs;
int count = 0;
pcnt_unit_get_count(unit, &count);
pcnt_del_channel(chan);
pcnt_unit_disable(unit);
pcnt_del_unit(unit);
const long freqHz = elapsedUs > 0
? static_cast<long>((static_cast<std::int64_t>(count) * 1000000LL)
/ elapsedUs)
: 0;
const bool nearSaturation = count >= (unitConfig.high_limit * 9) / 10;
ESP_LOGI(kTag, "%s clock probe: GPIO%d = %ld edges / %lld us -> ~%ld Hz%s",
label, gpio, static_cast<long>(count),
static_cast<long long>(elapsedUs), freqHz,
nearSaturation ? " (near PCNT limit — window too long for this "
"clock, re-run with a shorter windowMs)"
: "");
}
void heartbeatTask(void* arg)
{
(void)arg;
@@ -65,6 +151,18 @@ extern "C" void app_main()
return;
}
ESP_LOGI(kTag, "==== ADAU1701 I2S clock probe (no scope needed) ====");
// 500 ms: at 44.1-48 kHz this stays under the 16-bit PCNT limit
// (~24000 counts) while keeping tick/overhead error under ~1%.
logGpioClockFrequency("LRCLK", board::pins::I2sLrclk, 500);
// 10 ms: BCLK is in the MHz range (Nx LRCLK), so the window must be
// short enough that expected edges stay under the PCNT limit.
logGpioClockFrequency("BCLK", board::pins::I2sBclk, 10);
#if CONFIG_I2S_SDATA_PROBE
i2s_sdata_probe::captureAndLog(500);
#endif
#if CONFIG_TEST_FIRMWARE
test_firmware::runTestFirmware();
return;
@@ -93,10 +191,12 @@ extern "C" void app_main()
}
static bluetooth::BluetoothService bluetoothService(
hardware::HardwareBootstrap::bt1035Driver());
hardware::HardwareBootstrap::bt1035Driver(), store);
static ota::OtaService otaService;
static webradio::WebRadioService webRadioService(store);
auto netResult = net::NetBootstrap::start(
store,
tunerService,
@@ -105,6 +205,7 @@ extern "C" void app_main()
stationService,
integration,
otaService,
webRadioService,
hardware::HardwareBootstrap::companionChipStatus(),
hardware::HardwareBootstrap::deviceIdentity());
if (!netResult) {
@@ -118,17 +219,32 @@ extern "C" void app_main()
ESP_LOGW(kTag, "OTA rollback confirm failed");
}
if (xTaskCreate(heartbeatTask, "heartbeat", 2048, nullptr, 5, nullptr)
if (xTaskCreate(heartbeatTask, "heartbeat", 4096, nullptr, 5, nullptr)
!= pdPASS) {
ESP_LOGE(kTag, "heartbeat task create failed");
return;
}
bluetoothService.startupReconnect();
if (xTaskCreate(web_radio_stream::run, "web_radio", 16384,
&webRadioService, 4, nullptr) != pdPASS) {
ESP_LOGW(kTag, "web radio stream task create failed");
}
if (net.state() == net::NetState::StaConnected) {
ESP_LOGI(kTag, "running in STA mode — open http://<device-ip>/");
} else {
const auto& identity = hardware::HardwareBootstrap::deviceIdentity();
ESP_LOGI(kTag,
"running in setup mode — join DigiRadio-setup, "
"open http://192.168.4.1/");
"running in STA mode — open http://%.*s.local/ "
"(or check serial for IP)",
static_cast<int>(identity.hostname().size()),
identity.hostname().data());
} else {
const auto& identity = hardware::HardwareBootstrap::deviceIdentity();
ESP_LOGI(kTag,
"running in setup mode — join %.*s, "
"open http://192.168.4.1/",
static_cast<int>(identity.softApSsid().size()),
identity.softApSsid().data());
}
}