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>
196 lines
5.9 KiB
C++
196 lines
5.9 KiB
C++
/**
|
|
* @file test_firmware.cpp
|
|
* @brief Minimal firmware sequence for board, ADAU1701, Si4684 and BT1035 tests.
|
|
*
|
|
* DigiRadio firmware — https://github.com/manvalan/DigiRadio
|
|
*
|
|
* Copyright 2026 Michele Bigi
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include "adau1701/Adau1701Dsp.hpp"
|
|
#include "adau1701/Adau1701Driver.hpp"
|
|
#include "adau1701/EmbeddedDspProgramSource.hpp"
|
|
#include "adau1701/FallbackDspProgramSource.hpp"
|
|
#include "adau1701/FlashDspProgramSource.hpp"
|
|
#include "board_pins.hpp"
|
|
#include "bt1035/Bt1035Driver.hpp"
|
|
#include "core/Bt1035At.hpp"
|
|
#include "core/FrequencyKHz.hpp"
|
|
#include "esp_log.h"
|
|
#include "esp_system.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "si4684/Si4684Band.hpp"
|
|
#include "si4684/Si4684Driver.hpp"
|
|
#include "si4684/Si4684EmbeddedImages.hpp"
|
|
|
|
#include "test_firmware.hpp"
|
|
|
|
namespace test_firmware {
|
|
|
|
namespace {
|
|
constexpr char kTag[] = "testfw";
|
|
|
|
void logChipInfo()
|
|
{
|
|
esp_chip_info_t info;
|
|
esp_chip_info(&info);
|
|
ESP_LOGI(kTag, "ESP32 chip: %d cores, rev %d, features=0x%x",
|
|
info.cores, info.revision, info.features);
|
|
}
|
|
|
|
void logError(const char* stage, int code)
|
|
{
|
|
ESP_LOGE(kTag, "%s failed (err=%d)", stage, code);
|
|
}
|
|
|
|
void logStage(const char* stage)
|
|
{
|
|
ESP_LOGI(kTag, "==== %s ====", stage);
|
|
}
|
|
|
|
const char* a2dpStateToken(core::Bt1035A2dpState state) noexcept
|
|
{
|
|
using core::Bt1035A2dpState;
|
|
switch (state) {
|
|
case Bt1035A2dpState::Unsupported:
|
|
return "unsupported";
|
|
case Bt1035A2dpState::Standby:
|
|
return "standby";
|
|
case Bt1035A2dpState::Connecting:
|
|
return "connecting";
|
|
case Bt1035A2dpState::Connected:
|
|
return "connected";
|
|
case Bt1035A2dpState::Streaming:
|
|
return "streaming";
|
|
case Bt1035A2dpState::Paused:
|
|
return "paused";
|
|
}
|
|
return "unknown";
|
|
}
|
|
|
|
} // namespace
|
|
|
|
void runTestFirmware()
|
|
{
|
|
logStage("Board check");
|
|
logChipInfo();
|
|
|
|
logStage("Boot ADAU1701");
|
|
adau1701::EmbeddedDspProgramSource embeddedDspProgram;
|
|
adau1701::FlashDspProgramSource flashDspProgram;
|
|
adau1701::FallbackDspProgramSource dspProgramSource(
|
|
flashDspProgram, embeddedDspProgram);
|
|
adau1701::Adau1701Driver adau(
|
|
adau1701::Adau1701Pins{
|
|
.i2cSda = board::pins::Adau1701Sda,
|
|
.i2cScl = board::pins::Adau1701Scl,
|
|
.resetGpio = board::pins::Adau1701Reset,
|
|
.i2cAddr7 = board::pins::Adau1701Addr,
|
|
},
|
|
dspProgramSource);
|
|
|
|
if (auto result = adau.boot(); !result) {
|
|
logError("ADAU1701 boot", static_cast<int>(result.error()));
|
|
return;
|
|
}
|
|
ESP_LOGI(kTag, "ADAU1701 boot succeeded");
|
|
|
|
logStage("Boot Si4684");
|
|
si4684::Si4684EmbeddedImages images;
|
|
si4684::Si4684Driver si4684(
|
|
si4684::Si4684Pins{
|
|
.spiHost = SPI2_HOST,
|
|
.csGpio = board::pins::Si4684Cs,
|
|
.misoGpio = board::pins::Si4684Miso,
|
|
.mosiGpio = board::pins::Si4684Mosi,
|
|
.sclkGpio = board::pins::Si4684Sclk,
|
|
.rstbGpio = board::pins::Si4684Rstb,
|
|
.intbGpio = board::pins::Si4684Intb,
|
|
},
|
|
images.romPatch(),
|
|
images.dabFirmware(),
|
|
images.fmFirmware());
|
|
|
|
if (auto result = si4684.boot(si4684::Si4684Band::Fm); !result) {
|
|
logError("Si4684 boot", static_cast<int>(result.error()));
|
|
return;
|
|
}
|
|
ESP_LOGI(kTag, "Si4684 FM boot succeeded");
|
|
|
|
logStage("BT1035 boot");
|
|
bt1035::Bt1035Driver bt(
|
|
bt1035::Bt1035Pins{
|
|
.uartTx = board::pins::Bt1035UartTx,
|
|
.uartRx = board::pins::Bt1035UartRx,
|
|
.resetGpio = board::pins::Bt1035Reset,
|
|
.sysCtlGpio = board::pins::Bt1035SysCtl,
|
|
});
|
|
|
|
if (auto result = bt.boot(); !result) {
|
|
logError("BT1035 boot", static_cast<int>(result.error()));
|
|
return;
|
|
}
|
|
ESP_LOGI(kTag, "BT1035 boot succeeded");
|
|
|
|
if (auto nameResult = bt.queryDeviceName(); nameResult) {
|
|
ESP_LOGI(kTag, "BT1035 name=%s", nameResult->c_str());
|
|
}
|
|
|
|
if (auto result = bt.setDeviceName("DigiRadio-Test"); !result) {
|
|
logError("BT1035 setDeviceName", static_cast<int>(result.error()));
|
|
}
|
|
|
|
if (auto result = bt.enterPairingMode(); !result) {
|
|
logError("BT1035 pairing mode", static_cast<int>(result.error()));
|
|
} else {
|
|
ESP_LOGI(kTag, "BT1035 pairing mode enabled");
|
|
}
|
|
|
|
if (auto states = bt.queryA2dpState(); states) {
|
|
ESP_LOGI(kTag, "BT1035 A2DP state=%s",
|
|
a2dpStateToken(states.value()));
|
|
}
|
|
|
|
if (auto listResult = bt.queryPairedList(); listResult) {
|
|
ESP_LOGI(kTag, "BT1035 paired devices=%zu", listResult->size());
|
|
}
|
|
|
|
logStage("Radio test: tune FM");
|
|
auto frequency = core::FrequencyKHz::tryFromKhz(100700U);
|
|
if (!frequency) {
|
|
ESP_LOGE(kTag, "Invalid FM frequency");
|
|
return;
|
|
}
|
|
|
|
if (auto result = si4684.tuneFm(*frequency); !result) {
|
|
logError("Si4684 tune FM", static_cast<int>(result.error()));
|
|
} else {
|
|
ESP_LOGI(kTag, "Si4684 tuned FM to %u kHz", frequency->value());
|
|
}
|
|
|
|
if (auto result = si4684.setVolume(16); !result) {
|
|
logError("Si4684 setVolume", static_cast<int>(result.error()));
|
|
}
|
|
|
|
if (auto rsqResult = si4684.readFmRsq(); rsqResult) {
|
|
ESP_LOGI(kTag,
|
|
"FM RSQ: freq=%u kHz rssi=%d dBuV snr=%d dB valid=%d stereo=%d",
|
|
rsqResult->frequency ? rsqResult->frequency->value() : 0U,
|
|
static_cast<int>(rsqResult->rssiDbuV),
|
|
static_cast<int>(rsqResult->snrDb),
|
|
static_cast<int>(rsqResult->valid),
|
|
static_cast<int>(rsqResult->stereo));
|
|
} else {
|
|
logError("Si4684 read FM RSQ", static_cast<int>(rsqResult.error()));
|
|
}
|
|
|
|
ESP_LOGI(kTag, "Test firmware finished. Keep running for manual pairing and audio verification.");
|
|
while (true) {
|
|
vTaskDelay(pdMS_TO_TICKS(10000));
|
|
}
|
|
}
|
|
|
|
} // namespace test_firmware
|