radiolib: RADIO_DIAG reads the SX1262 status byte by hand

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-10-31 20:44:42 +01:00
1 parent 65ff32a10a
commit d32c8caa37
1 file changed
+17 -1
+17 -1
View File
@@ -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
};