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.
This commit is contained in:
2026-06-11 18:25:22 +08:00
parent b125dd33b9
commit e6f96ea0e3
2 changed files with 15 additions and 7 deletions
+1
View File
@@ -303,6 +303,7 @@ struct LLCC68 {
/** properties */ /** properties */
const struct device *dev; const struct device *dev;
std::optional<ChipType> cached_chip_type{};
}; };
} // namespace app::driver::llcc68 } // namespace app::driver::llcc68
+14 -7
View File
@@ -674,6 +674,10 @@ expected<unit, error_code> LLCC68::set_standby() {
} }
expected<ChipType, error_code> LLCC68::hal_get_chip_type() { expected<ChipType, error_code> LLCC68::hal_get_chip_type() {
if (cached_chip_type.has_value()) {
return *cached_chip_type;
}
constexpr auto SX1262_CHIP_TYPE = "SX1262"; constexpr auto SX1262_CHIP_TYPE = "SX1262";
constexpr auto LLCC68_CHIP_TYPE = "LLCC68"; constexpr auto LLCC68_CHIP_TYPE = "LLCC68";
constexpr auto SX1261_CHIP_TYPE = "SX1261"; constexpr auto SX1261_CHIP_TYPE = "SX1261";
@@ -684,16 +688,19 @@ expected<ChipType, error_code> LLCC68::hal_get_chip_type() {
auto r = read_register(RADIOLIB_SX126X_REG_VERSION_STRING, version_buf); auto r = read_register(RADIOLIB_SX126X_REG_VERSION_STRING, version_buf);
APP_RADIO_RETURN_ERR(r); APP_RADIO_RETURN_ERR(r);
LOG_HEXDUMP_DBG(version, sizeof(version), "version dump"); LOG_HEXDUMP_DBG(version, sizeof(version), "version dump");
ChipType chip_type = ChipType::Unknown;
if (strncmp(version, LLCC68_CHIP_TYPE, 6) == 0) { 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) { if (chip_type != ChipType::Unknown) {
return ChipType::SX1261; cached_chip_type = chip_type;
} }
if (strncmp(version, SX1262_CHIP_TYPE, 6) == 0) { return chip_type;
return ChipType::SX1262;
}
return ChipType::Unknown;
} }
expected<unit, error_code> LLCC68::set_dio_irq_params(irq_params_t params) { expected<unit, error_code> LLCC68::set_dio_irq_params(irq_params_t params) {