Add FM ANTCAP antenna calibration: HTTP sweep control + EEPROM persistence
Confirmed live tonight that the Si4684's automatic front-end tuning (FE_VARM/VARB properties) is measurably suboptimal on this board: a 129-value ANTCAP sweep (0-128, AN851 Appendix A) at four different FM frequencies found antcap=102 beats auto-tune by +6 to +11 dB RSSI and +3 to +11 dB SNR everywhere tested, consistent with the front-end network component mismatch already logged in docs/si4684-rf-investigation-report.md — the board's actual matching network differs from the AN851 reference network those auto-tune constants were derived from, so a fixed empirical override compensates for a gap the chip's own algorithm can't see. Wiring, bottom to top: - Si4684Driver::tuneFm() already took an antCap byte; threaded it through core::ITuner::tuneFm() and si4684::Si4684Tuner::tuneFm() as a new parameter (default 0 = auto, unchanged behaviour for every existing caller). - TunerService::tuneFm() takes an optional override instead: omitted, it falls back to a new defaultFmAntCap_ member so every ordinary FM tune (seek, scan, station recall, live UI) benefits automatically once calibrated, not just calls that pass antcap explicitly. - POST /api/tuner/tune gained an optional "antcap" field for sweeping live without touching the saved calibration. - POST /api/tuner/calibrate-antenna commits a sweep result: writes it to the 24AA025E48 EEPROM's user-writable region (word address 0x00, separate from the factory-locked EUI-48 at 0xFA-0xFF) via a new Eeprom24aa::writeFmAntCap()/readFmAntCap() pair, and immediately updates the live TunerService default — no reboot needed to take effect, though HardwareBootstrap::boot() also loads it at every boot so it survives power cycles. Same net::AntennaCalibration function-pointer bridge pattern as PhoneStreamSink/BleProvisioning, so components/net stays free of eeprom24aa headers. Verified end to end on hardware: swept and found 102, saved it via the new endpoint, confirmed the live default changed immediately, then power-cycled and confirmed the boot log reports "FM ANTCAP calibration loaded: 102" and a subsequent default tune reflects it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0178rASQ6ZETPMUamvpoR2KR
This commit is contained in:
@@ -80,7 +80,21 @@ bt1035::Bt1035Driver gBt1035(
|
||||
});
|
||||
|
||||
core::DeviceIdentity gDeviceIdentity = core::DeviceIdentity::unknown();
|
||||
std::optional<std::uint8_t> gFmAntCapCalibration;
|
||||
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 +116,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 +127,19 @@ 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 audioResult = gAudioService.loadAndApply(); !audioResult) {
|
||||
ESP_LOGW(kTag, "ADAU1701 profile apply failed");
|
||||
}
|
||||
@@ -175,4 +198,22 @@ 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;
|
||||
}
|
||||
|
||||
} // namespace hardware
|
||||
|
||||
Reference in New Issue
Block a user