Files
DigiRadio/Software/main/antenna_calibration.cpp
T
micheleandClaude Sonnet 5 a7a5311c2c Persist Si4684 crystal calibration (ibias/ctun/xtalFreqHz) to EEPROM
Extends the existing FM/DAB ANTCAP EEPROM persistence pattern
(Eeprom24aa::writeFmAntCap/writeDabAntCap) to the crystal trim found by
POST /api/tuner/xtal-calibrate, which previously only applied live and
was lost on every reboot.

- Eeprom24aa gains readXtalCalibration()/writeXtalCalibration() at word
  addresses 0x02 (ibias), 0x03 (ctun), 0x04-0x07 (xtalFreqHz,
  big-endian), right after the existing FM/DAB ANTCAP bytes.
- HardwareBootstrap::boot() now boots ADAU1701 before Si4684 (needed so
  the EEPROM read, which borrows ADAU1701's I2C bus, can happen before
  Si4684's boot() call, which takes the crystal trim as an argument),
  loads the saved trim if present, and falls back to the compiled-in
  defaults (ibias=72, ctun=0, xtalFreqHz=19199750) otherwise.
- POST /api/tuner/xtal-calibrate now persists every successful live
  recalibration automatically ("persisted":true/false in the response)
  via a new saveXtalCalibration()/net::AntennaCalibration::saveXtal
  bridge, mirroring the ANTCAP save pattern.

Verified live: boot log confirms "Xtal not calibrated" before the first
save, "Xtal calibration loaded: ibias=72 ctun=0 xtal_freq_hz=19199750"
after, surviving a reboot; DAB/FM tuning unaffected (DAB CNR 17-19dB,
locked).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-25 15:22:03 +02:00

49 lines
1.4 KiB
C++

/**
* @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"
#include "si4684/Si4684Tuner.hpp"
namespace antenna_calibration {
namespace {
/** Diagnostic-only, 2026-08-23: see net::AntennaCalibration::recalibrateXtal. */
bool recalibrateXtal(std::uint8_t ibias, std::uint8_t ctun,
std::uint32_t xtalFreqHz)
{
return static_cast<bool>(hardware::HardwareBootstrap::si4684Tuner()
.recalibrateXtal(ibias, ctun, xtalFreqHz));
}
/** Persist to EEPROM, 2026-08-24: see net::AntennaCalibration::saveXtal. */
bool saveXtal(std::uint8_t ibias, std::uint8_t ctun, std::uint32_t xtalFreqHz)
{
return hardware::HardwareBootstrap::saveXtalCalibration(ibias, ctun,
xtalFreqHz);
}
} // namespace
net::AntennaCalibration& bridge() noexcept
{
static net::AntennaCalibration instance{
.save = &hardware::HardwareBootstrap::saveFmAntCapCalibration,
.saveDab = &hardware::HardwareBootstrap::saveDabAntCapCalibration,
.recalibrateXtal = &recalibrateXtal,
.saveXtal = &saveXtal,
};
return instance;
}
} // namespace antenna_calibration