From d32c8caa37d7272133e035ae4122d038f37a8d1f Mon Sep 17 00:00:00 2001 From: TeTeHacko Date: Sat, 31 Oct 2026 20:44:42 +0100 Subject: [PATCH] radiolib: RADIO_DIAG reads the SX1262 status byte by hand Co-Authored-By: Claude Opus 5.5 --- src/helpers/radiolib/CustomSX1262.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/helpers/radiolib/CustomSX1262.h b/src/helpers/radiolib/CustomSX1262.h index e5c88aed..e49ee64d 100644 --- a/src/helpers/radiolib/CustomSX1262.h +++ b/src/helpers/radiolib/CustomSX1262.h @@ -166,7 +166,23 @@ class CustomSX1262 : public SX1262 { #ifdef RADIO_DIAG // CUSTOM (TeTeHacko): public views of SX126x commands RadioLib keeps // protected, for `radiostat` (RadioLibWrappers.cpp). Reads only. - uint8_t diagStatus() { return getStatus(); } + // SX126x::getStatus() reads ZERO data bytes and so always returns 0 (RadioLib + // 7.7.1); the status comes back on the NOP after the opcode, done by hand. + uint8_t diagStatus() { + #ifdef P_LORA_NSS + uint8_t out[2] = { RADIOLIB_SX126X_CMD_GET_STATUS, RADIOLIB_SX126X_CMD_NOP }, in[2] = { 0, 0 }; + uint32_t t0 = millis(); + while (mod->hal->digitalRead(mod->getGpio()) && millis() - t0 < 20) { } // BUSY + mod->hal->spiBeginTransaction(); + mod->hal->digitalWrite(P_LORA_NSS, mod->hal->GpioLevelLow); + mod->hal->spiTransfer(out, 2, in); + mod->hal->digitalWrite(P_LORA_NSS, mod->hal->GpioLevelHigh); + mod->hal->spiEndTransaction(); + return in[1]; + #else + return getStatus(); + #endif + } uint16_t diagDeviceErrors() { return getDeviceErrors(); } #endif }; \ No newline at end of file