Add DAB ANTCAP calibration and fix BT1035 boot banner timing

Extend the FM-only ANTCAP antenna-varactor override to DAB, mirroring the
existing mechanism end to end (driver, tuner, service, EEPROM storage,
HTTP API). Live sweep on real hardware found no ANTCAP value beating
auto-tune on the ensembles tested, so DAB stays on auto-tune by default.

Also fix BT1035 boot: the module's real boot banner doesn't appear until
~18-24s after RESET# releases, not the 3.5s previously waited; add a
2-attempt retry and a baud-rate probe fallback for diagnostics.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-21 08:12:08 +02:00
co-authored by Claude Sonnet 5
parent 9ad2e42fe2
commit 3a58d33aad
38 changed files with 1444 additions and 115 deletions
+1
View File
@@ -5,6 +5,7 @@ idf_component_register(
"web_radio_stream.cpp"
"esp32_i2s_sink.cpp"
"phone_stream.cpp"
"antenna_calibration.cpp"
"$<$<BOOL:${CONFIG_TEST_FIRMWARE}>:test_firmware.cpp>"
"$<$<BOOL:${CONFIG_I2S_SDATA_PROBE}>:i2s_sdata_probe.cpp>"
INCLUDE_DIRS "."
+26
View File
@@ -0,0 +1,26 @@
/**
* @file antenna_calibration.cpp
* @brief net::AntennaCalibration implementation over HardwareBootstrap.
*
* DigiRadio firmware — https://github.com/manvalan/DigiRadio
*
* Copyright 2026 Michele Bigi
* SPDX-License-Identifier: Apache-2.0
*/
#include "antenna_calibration.hpp"
#include "hardware_bootstrap.hpp"
namespace antenna_calibration {
net::AntennaCalibration& bridge() noexcept
{
static net::AntennaCalibration instance{
.save = &hardware::HardwareBootstrap::saveFmAntCapCalibration,
.saveDab = &hardware::HardwareBootstrap::saveDabAntCapCalibration,
};
return instance;
}
} // namespace antenna_calibration
+28
View File
@@ -0,0 +1,28 @@
/**
* @file antenna_calibration.hpp
* @brief net::AntennaCalibration implementation over HardwareBootstrap.
*
* DigiRadio firmware — https://github.com/manvalan/DigiRadio
*
* Copyright 2026 Michele Bigi
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "net/SetupWebServer.hpp"
namespace antenna_calibration {
/**
* @brief bridge — the process-lifetime AntennaCalibration instance.
*
* @dname bridge
* @return Function-pointer table bound to
* HardwareBootstrap::saveFmAntCapCalibration, for
* net::HttpRouteContext::antennaCalibration /
* POST /api/tuner/calibrate-antenna.
* @pubstate none
*/
[[nodiscard]] net::AntennaCalibration& bridge() noexcept;
} // namespace antenna_calibration
+78 -5
View File
@@ -80,7 +80,22 @@ bt1035::Bt1035Driver gBt1035(
});
core::DeviceIdentity gDeviceIdentity = core::DeviceIdentity::unknown();
std::optional<std::uint8_t> gFmAntCapCalibration;
std::optional<std::uint8_t> gDabAntCapCalibration;
bool gReady = false;
/**
* @brief makeEeprom — construct a transient EEPROM handle onto the
* shared I2C bus, matching the one built inline in boot().
*/
[[nodiscard]] eeprom24aa::Eeprom24aa makeEeprom()
{
auto* busHandle =
static_cast<i2c_master_bus_handle_t>(gAdau1701.i2cBusHandle());
return eeprom24aa::Eeprom24aa(
busHandle,
static_cast<std::uint8_t>(board::pins::Eeprom24aaAddr));
}
} // namespace
std::expected<void, HardwareBootError> HardwareBootstrap::boot()
@@ -102,11 +117,7 @@ std::expected<void, HardwareBootError> HardwareBootstrap::boot()
}
}
auto* busHandle =
static_cast<i2c_master_bus_handle_t>(gAdau1701.i2cBusHandle());
eeprom24aa::Eeprom24aa eeprom(busHandle,
static_cast<std::uint8_t>(
board::pins::Eeprom24aaAddr));
eeprom24aa::Eeprom24aa eeprom = makeEeprom();
if (auto identity = eeprom.readDeviceIdentity(); identity) {
gDeviceIdentity = std::move(*identity);
ESP_LOGI(kTag, "unit serial %.*s",
@@ -117,6 +128,32 @@ std::expected<void, HardwareBootError> HardwareBootstrap::boot()
ESP_LOGW(kTag, "EUI-48 read failed — using fallback identity");
}
if (auto antCap = eeprom.readFmAntCap(); antCap) {
gFmAntCapCalibration = *antCap;
if (gFmAntCapCalibration) {
ESP_LOGI(kTag, "FM ANTCAP calibration loaded: %u",
static_cast<unsigned>(*gFmAntCapCalibration));
} else {
ESP_LOGI(kTag, "FM ANTCAP not calibrated — using chip auto-tune");
}
} else {
ESP_LOGW(kTag, "FM ANTCAP calibration read failed — using chip "
"auto-tune");
}
if (auto antCap = eeprom.readDabAntCap(); antCap) {
gDabAntCapCalibration = *antCap;
if (gDabAntCapCalibration) {
ESP_LOGI(kTag, "DAB ANTCAP calibration loaded: %u",
static_cast<unsigned>(*gDabAntCapCalibration));
} else {
ESP_LOGI(kTag, "DAB ANTCAP not calibrated — using chip auto-tune");
}
} else {
ESP_LOGW(kTag, "DAB ANTCAP calibration read failed — using chip "
"auto-tune");
}
if (auto audioResult = gAudioService.loadAndApply(); !audioResult) {
ESP_LOGW(kTag, "ADAU1701 profile apply failed");
}
@@ -175,4 +212,40 @@ const core::DeviceIdentity& HardwareBootstrap::deviceIdentity() noexcept
return gDeviceIdentity;
}
std::optional<std::uint8_t> HardwareBootstrap::fmAntCapCalibration() noexcept
{
return gFmAntCapCalibration;
}
bool HardwareBootstrap::saveFmAntCapCalibration(std::uint8_t antCap)
{
eeprom24aa::Eeprom24aa eeprom = makeEeprom();
if (auto written = eeprom.writeFmAntCap(antCap); !written) {
ESP_LOGW(kTag, "FM ANTCAP calibration write failed");
return false;
}
gFmAntCapCalibration = antCap;
ESP_LOGI(kTag, "FM ANTCAP calibration saved: %u",
static_cast<unsigned>(antCap));
return true;
}
std::optional<std::uint8_t> HardwareBootstrap::dabAntCapCalibration() noexcept
{
return gDabAntCapCalibration;
}
bool HardwareBootstrap::saveDabAntCapCalibration(std::uint8_t antCap)
{
eeprom24aa::Eeprom24aa eeprom = makeEeprom();
if (auto written = eeprom.writeDabAntCap(antCap); !written) {
ESP_LOGW(kTag, "DAB ANTCAP calibration write failed");
return false;
}
gDabAntCapCalibration = antCap;
ESP_LOGI(kTag, "DAB ANTCAP calibration saved: %u",
static_cast<unsigned>(antCap));
return true;
}
} // namespace hardware
+60
View File
@@ -17,7 +17,9 @@
#include "bt1035/Bt1035Driver.hpp"
#include <cstdint>
#include <expected>
#include <optional>
namespace audio {
class AudioService;
@@ -137,6 +139,64 @@ public:
* @date 2026-07-07
*/
[[nodiscard]] static const core::DeviceIdentity& deviceIdentity() noexcept;
/**
* @brief fmAntCapCalibration — saved FM antenna calibration, if any.
*
* @dname fmAntCapCalibration
* @return Calibrated ANTCAP (0-128) read from the 24AA025E48 during
* boot(), or nullopt if never calibrated / the read failed.
* @pubstate reads gFmAntCapCalibration; set once during boot().
*
* @author Michele Bigi
* @date 2026-08-19
*/
[[nodiscard]] static std::optional<std::uint8_t>
fmAntCapCalibration() noexcept;
/**
* @brief saveFmAntCapCalibration — persist a new FM ANTCAP to EEPROM.
*
* @dname saveFmAntCapCalibration
* @param antCap Value found via a calibration sweep (0-128).
* @return true on success, false on an I2C failure.
* @pubstate writes the 24AA025E48 user region and gFmAntCapCalibration.
* Does not itself change any live tuner state — callers must
* also call TunerService::setDefaultFmAntCap() to apply it.
*
* @author Michele Bigi
* @date 2026-08-19
*/
[[nodiscard]] static bool saveFmAntCapCalibration(std::uint8_t antCap);
/**
* @brief dabAntCapCalibration — saved DAB antenna calibration, if any.
*
* @dname dabAntCapCalibration
* @return Calibrated ANTCAP (0-128) read from the 24AA025E48 during
* boot(), or nullopt if never calibrated / the read failed.
* @pubstate reads gDabAntCapCalibration; set once during boot().
*
* @author Michele Bigi
* @date 2026-08-20
*/
[[nodiscard]] static std::optional<std::uint8_t>
dabAntCapCalibration() noexcept;
/**
* @brief saveDabAntCapCalibration — persist a new DAB ANTCAP to EEPROM.
*
* @dname saveDabAntCapCalibration
* @param antCap Value found via a calibration sweep (0-128).
* @return true on success, false on an I2C failure.
* @pubstate writes the 24AA025E48 user region and gDabAntCapCalibration.
* Does not itself change any live tuner state — callers must
* also call TunerService::setDefaultDabAntCap() to apply it.
*
* @author Michele Bigi
* @date 2026-08-20
*/
[[nodiscard]] static bool saveDabAntCapCalibration(std::uint8_t antCap);
};
} // namespace hardware
+10
View File
@@ -23,6 +23,7 @@
#include "si4684/Si4684Tuner.hpp"
#include "station/StationService.hpp"
#include "tuner/TunerService.hpp"
#include "antenna_calibration.hpp"
#include "esp32_i2s_sink.hpp"
#include "phone_stream.hpp"
#include "web_radio_stream.hpp"
@@ -179,6 +180,14 @@ extern "C" void app_main()
static tuner::TunerService tunerService(
hardware::HardwareBootstrap::si4684Tuner());
if (auto antCap = hardware::HardwareBootstrap::fmAntCapCalibration();
antCap) {
tunerService.setDefaultFmAntCap(*antCap);
}
if (auto antCap = hardware::HardwareBootstrap::dabAntCapCalibration();
antCap) {
tunerService.setDefaultDabAntCap(*antCap);
}
static station::StationService stationService(store, tunerService);
@@ -214,6 +223,7 @@ extern "C" void app_main()
otaService,
webRadioService,
phone_stream::sink(),
antenna_calibration::bridge(),
hardware::HardwareBootstrap::companionChipStatus(),
hardware::HardwareBootstrap::deviceIdentity());
if (!netResult) {