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