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,7 +1,7 @@
idf_component_register(
SRCS "src/Eeprom24aa.cpp"
INCLUDE_DIRS "include"
REQUIRES core driver esp_driver_i2c
REQUIRES core driver esp_driver_i2c freertos
)
target_compile_features(${COMPONENT_LIB} PUBLIC cxx_std_23)
@@ -13,27 +13,44 @@
#pragma once
#include "core/IDeviceIdentitySource.hpp"
#include "core/IdentityError.hpp"
#include "driver/i2c_master.h"
#include <cstdint>
#include <expected>
#include <optional>
namespace eeprom24aa {
/**
* @brief Eeprom24aa — reads the factory EUI-48 from Microchip 24AA025E48.
* @brief Eeprom24aa — reads the factory EUI-48 from Microchip 24AA025E48;
* also stores one board-specific calibration byte in the chip's
* user-writable region.
*
* @dname Eeprom24aa
* @return n/a (type)
* @pubstate Borrows an existing I2C master bus (shared with ADAU1701). The
* EUI-48 lives at word address 0xFA..0xFF per the 24AA025E48
* datasheet (DS20001191).
* EUI-48 lives at word address 0xFA..0xFF (read-only, factory
* programmed) per the 24AA025E48 datasheet (DS20001191); the FM
* ANTCAP calibration byte lives at word address 0x00, and the
* DAB ANTCAP calibration byte at word address 0x01, both in the
* remaining user-writable 250 bytes.
*
* @author Michele Bigi
* @date 2026-07-07
*/
class Eeprom24aa : public core::IDeviceIdentitySource {
public:
/** Valid ANTCAP calibration values (FM or DAB) are 0-128 (AN649/AN851);
* any stored byte above this, including the EEPROM's blank/erased
* 0xFF, reads back as "never calibrated" — no separate sentinel write
* needed for a fresh chip. */
static constexpr std::uint8_t kFmAntCapMax = 128U;
/** Same range as kFmAntCapMax; kept as a separate name for the DAB
* calibration byte's own doc comments below. */
static constexpr std::uint8_t kDabAntCapMax = 128U;
/**
* @brief Eeprom24aa — bind to a running I2C master bus and 7-bit addr.
*
@@ -60,6 +77,69 @@ public:
[[nodiscard]] std::expected<core::DeviceIdentity, core::IdentityError>
readDeviceIdentity() override;
/**
* @brief readFmAntCap — read the stored FM antenna calibration byte.
*
* @dname readFmAntCap
* @return Calibrated ANTCAP (0-kFmAntCapMax) if one was ever saved via
* writeFmAntCap(), nullopt if the byte is blank/out of range,
* or IdentityError on an I2C failure.
* @pubstate performs one I2C read of one byte at word address 0x00.
*
* @author Michele Bigi
* @date 2026-08-19
*/
[[nodiscard]] std::expected<std::optional<std::uint8_t>, core::IdentityError>
readFmAntCap();
/**
* @brief writeFmAntCap — persist an FM antenna calibration value.
*
* @dname writeFmAntCap
* @param value ANTCAP to store, 0-kFmAntCapMax (AN851 Appendix A
* calibration procedure; found via a sweep, not
* computed).
* @return Ok on success, or IdentityError::I2cFailed.
* @pubstate performs one I2C byte write at word address 0x00, then
* blocks for the chip's write-cycle time before returning.
*
* @author Michele Bigi
* @date 2026-08-19
*/
[[nodiscard]] std::expected<void, core::IdentityError>
writeFmAntCap(std::uint8_t value);
/**
* @brief readDabAntCap — read the stored DAB antenna calibration byte.
*
* @dname readDabAntCap
* @return Calibrated ANTCAP (0-kDabAntCapMax) if one was ever saved via
* writeDabAntCap(), nullopt if the byte is blank/out of range,
* or IdentityError on an I2C failure.
* @pubstate performs one I2C read of one byte at word address 0x01.
*
* @author Michele Bigi
* @date 2026-08-20
*/
[[nodiscard]] std::expected<std::optional<std::uint8_t>, core::IdentityError>
readDabAntCap();
/**
* @brief writeDabAntCap — persist a DAB antenna calibration value.
*
* @dname writeDabAntCap
* @param value ANTCAP to store, 0-kDabAntCapMax (AN649 Command
* 0xB0 ARG4; found via a sweep, not computed).
* @return Ok on success, or IdentityError::I2cFailed.
* @pubstate performs one I2C byte write at word address 0x01, then
* blocks for the chip's write-cycle time before returning.
*
* @author Michele Bigi
* @date 2026-08-20
*/
[[nodiscard]] std::expected<void, core::IdentityError>
writeDabAntCap(std::uint8_t value);
private:
i2c_master_bus_handle_t bus_;
std::uint8_t addr7_;
@@ -15,6 +15,8 @@
#include "driver/i2c_master.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <array>
@@ -25,7 +27,15 @@ namespace {
constexpr char kTag[] = "Eeprom24aa";
/** EUI-48 word address per Microchip 24AA025E48 datasheet (DS20001191). */
constexpr std::uint8_t kEui48WordAddress = 0xFAU;
/** FM ANTCAP calibration byte, in the chip's user-writable region (anywhere
* below the factory-locked 0xFA-0xFF EUI-48 block). */
constexpr std::uint8_t kFmAntCapWordAddress = 0x00U;
/** DAB ANTCAP calibration byte, next word address after the FM byte. */
constexpr std::uint8_t kDabAntCapWordAddress = 0x01U;
constexpr int kI2cTimeoutMs = 100;
/** DS20001191 §"Page Write"/"Byte Write": max write cycle time after STOP
* before the chip acknowledges further I2C traffic. */
constexpr int kI2cWriteCycleMs = 5;
} // namespace
@@ -69,4 +79,146 @@ Eeprom24aa::readDeviceIdentity()
return core::DeviceIdentity::fromEui48(core::Eui48::fromBytes(payload));
}
std::expected<std::optional<std::uint8_t>, core::IdentityError>
Eeprom24aa::readFmAntCap()
{
if (bus_ == nullptr) {
return std::unexpected(core::IdentityError::I2cFailed);
}
i2c_device_config_t devCfg = {};
devCfg.dev_addr_length = I2C_ADDR_BIT_LEN_7;
devCfg.device_address = addr7_;
devCfg.scl_speed_hz = 100000;
i2c_master_dev_handle_t dev = nullptr;
if (i2c_master_bus_add_device(bus_, &devCfg, &dev) != ESP_OK) {
ESP_LOGW(kTag, "i2c_master_bus_add_device failed");
return std::unexpected(core::IdentityError::I2cFailed);
}
const std::uint8_t wordAddress = kFmAntCapWordAddress;
std::uint8_t value = 0xFFU;
const esp_err_t err = i2c_master_transmit_receive(
dev, &wordAddress, 1U, &value, 1U, kI2cTimeoutMs);
i2c_master_bus_rm_device(dev);
if (err != ESP_OK) {
ESP_LOGW(kTag, "FM ANTCAP read failed (err=0x%x)",
static_cast<unsigned>(err));
return std::unexpected(core::IdentityError::ReadFailed);
}
if (value > kFmAntCapMax) {
return std::optional<std::uint8_t>{};
}
return std::optional<std::uint8_t>{value};
}
std::expected<void, core::IdentityError>
Eeprom24aa::writeFmAntCap(std::uint8_t value)
{
if (bus_ == nullptr) {
return std::unexpected(core::IdentityError::I2cFailed);
}
i2c_device_config_t devCfg = {};
devCfg.dev_addr_length = I2C_ADDR_BIT_LEN_7;
devCfg.device_address = addr7_;
devCfg.scl_speed_hz = 100000;
i2c_master_dev_handle_t dev = nullptr;
if (i2c_master_bus_add_device(bus_, &devCfg, &dev) != ESP_OK) {
ESP_LOGW(kTag, "i2c_master_bus_add_device failed");
return std::unexpected(core::IdentityError::I2cFailed);
}
const std::array<std::uint8_t, 2> payload = {kFmAntCapWordAddress, value};
const esp_err_t err =
i2c_master_transmit(dev, payload.data(), payload.size(), kI2cTimeoutMs);
i2c_master_bus_rm_device(dev);
if (err != ESP_OK) {
ESP_LOGW(kTag, "FM ANTCAP write failed (err=0x%x)",
static_cast<unsigned>(err));
return std::unexpected(core::IdentityError::I2cFailed);
}
vTaskDelay(pdMS_TO_TICKS(kI2cWriteCycleMs));
return {};
}
std::expected<std::optional<std::uint8_t>, core::IdentityError>
Eeprom24aa::readDabAntCap()
{
if (bus_ == nullptr) {
return std::unexpected(core::IdentityError::I2cFailed);
}
i2c_device_config_t devCfg = {};
devCfg.dev_addr_length = I2C_ADDR_BIT_LEN_7;
devCfg.device_address = addr7_;
devCfg.scl_speed_hz = 100000;
i2c_master_dev_handle_t dev = nullptr;
if (i2c_master_bus_add_device(bus_, &devCfg, &dev) != ESP_OK) {
ESP_LOGW(kTag, "i2c_master_bus_add_device failed");
return std::unexpected(core::IdentityError::I2cFailed);
}
const std::uint8_t wordAddress = kDabAntCapWordAddress;
std::uint8_t value = 0xFFU;
const esp_err_t err = i2c_master_transmit_receive(
dev, &wordAddress, 1U, &value, 1U, kI2cTimeoutMs);
i2c_master_bus_rm_device(dev);
if (err != ESP_OK) {
ESP_LOGW(kTag, "DAB ANTCAP read failed (err=0x%x)",
static_cast<unsigned>(err));
return std::unexpected(core::IdentityError::ReadFailed);
}
if (value > kDabAntCapMax) {
return std::optional<std::uint8_t>{};
}
return std::optional<std::uint8_t>{value};
}
std::expected<void, core::IdentityError>
Eeprom24aa::writeDabAntCap(std::uint8_t value)
{
if (bus_ == nullptr) {
return std::unexpected(core::IdentityError::I2cFailed);
}
i2c_device_config_t devCfg = {};
devCfg.dev_addr_length = I2C_ADDR_BIT_LEN_7;
devCfg.device_address = addr7_;
devCfg.scl_speed_hz = 100000;
i2c_master_dev_handle_t dev = nullptr;
if (i2c_master_bus_add_device(bus_, &devCfg, &dev) != ESP_OK) {
ESP_LOGW(kTag, "i2c_master_bus_add_device failed");
return std::unexpected(core::IdentityError::I2cFailed);
}
const std::array<std::uint8_t, 2> payload = {kDabAntCapWordAddress, value};
const esp_err_t err =
i2c_master_transmit(dev, payload.data(), payload.size(), kI2cTimeoutMs);
i2c_master_bus_rm_device(dev);
if (err != ESP_OK) {
ESP_LOGW(kTag, "DAB ANTCAP write failed (err=0x%x)",
static_cast<unsigned>(err));
return std::unexpected(core::IdentityError::I2cFailed);
}
vTaskDelay(pdMS_TO_TICKS(kI2cWriteCycleMs));
return {};
}
} // namespace eeprom24aa