From e6f96ea0e38ad97310a91f9be313433614479593 Mon Sep 17 00:00:00 2001 From: crosstyan Date: Thu, 11 Jun 2026 18:25:22 +0800 Subject: [PATCH] fix(llcc68): cache detected chip type Store the detected chip type after the first successful version-register read so repeated radio operations do not keep querying the chip identity. This preserves Unknown as uncached so transient read failures or unsupported responses can still be retried on a later call. --- include/llcc68.hpp | 1 + src/llcc68.cpp | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/llcc68.hpp b/include/llcc68.hpp index f98d24e..25d7047 100644 --- a/include/llcc68.hpp +++ b/include/llcc68.hpp @@ -303,6 +303,7 @@ struct LLCC68 { /** properties */ const struct device *dev; + std::optional cached_chip_type{}; }; } // namespace app::driver::llcc68 diff --git a/src/llcc68.cpp b/src/llcc68.cpp index eeb41cd..5b25588 100644 --- a/src/llcc68.cpp +++ b/src/llcc68.cpp @@ -674,6 +674,10 @@ expected LLCC68::set_standby() { } expected LLCC68::hal_get_chip_type() { + if (cached_chip_type.has_value()) { + return *cached_chip_type; + } + constexpr auto SX1262_CHIP_TYPE = "SX1262"; constexpr auto LLCC68_CHIP_TYPE = "LLCC68"; constexpr auto SX1261_CHIP_TYPE = "SX1261"; @@ -684,16 +688,19 @@ expected LLCC68::hal_get_chip_type() { auto r = read_register(RADIOLIB_SX126X_REG_VERSION_STRING, version_buf); APP_RADIO_RETURN_ERR(r); LOG_HEXDUMP_DBG(version, sizeof(version), "version dump"); + + ChipType chip_type = ChipType::Unknown; if (strncmp(version, LLCC68_CHIP_TYPE, 6) == 0) { - return ChipType::LLCC68; + chip_type = ChipType::LLCC68; + } else if (strncmp(version, SX1261_CHIP_TYPE, 6) == 0) { + chip_type = ChipType::SX1261; + } else if (strncmp(version, SX1262_CHIP_TYPE, 6) == 0) { + chip_type = ChipType::SX1262; } - if (strncmp(version, SX1261_CHIP_TYPE, 6) == 0) { - return ChipType::SX1261; + if (chip_type != ChipType::Unknown) { + cached_chip_type = chip_type; } - if (strncmp(version, SX1262_CHIP_TYPE, 6) == 0) { - return ChipType::SX1262; - } - return ChipType::Unknown; + return chip_type; } expected LLCC68::set_dio_irq_params(irq_params_t params) {