From 170ce9752bf7ccf78713d60fb1a0b93f9ba3e3d2 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 4 Oct 2022 18:19:54 +0200 Subject: [PATCH] [SX126x] Skip SPI verification during block calibration (#583) --- src/modules/SX126x/SX126x.cpp | 30 +++++++++++++++++++++--------- src/modules/SX126x/SX126x.h | 8 ++++---- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index ad8668be..4662bc3d 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -1617,7 +1617,7 @@ int16_t SX126x::config(uint8_t modem) { // calibrate all blocks data[0] = RADIOLIB_SX126X_CALIBRATE_ALL; - state = SPIwriteCommand(RADIOLIB_SX126X_CMD_CALIBRATE, data, 1); + state = SPIwriteCommand(RADIOLIB_SX126X_CMD_CALIBRATE, data, 1, true, false); RADIOLIB_ASSERT(state); // wait for calibration completion @@ -1662,43 +1662,55 @@ int16_t SX126x::checkCommandResult() { return(state); } -int16_t SX126x::SPIwriteCommand(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes, bool waitForBusy) { +int16_t SX126x::SPIwriteCommand(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes, bool waitForBusy, bool verify) { // send the command int16_t state = SX126x::SPItransfer(cmd, cmdLen, true, data, NULL, numBytes, waitForBusy); RADIOLIB_ASSERT(state); // check the status - state = checkCommandResult(); + if(verify) { + state = checkCommandResult(); + } + return(state); } -int16_t SX126x::SPIwriteCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy) { +int16_t SX126x::SPIwriteCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy, bool verify) { // send the command int16_t state = SX126x::SPItransfer(&cmd, 1, true, data, NULL, numBytes, waitForBusy); RADIOLIB_ASSERT(state); // check the status - state = checkCommandResult(); + if(verify) { + state = checkCommandResult(); + } + return(state); } -int16_t SX126x::SPIreadCommand(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes, bool waitForBusy) { +int16_t SX126x::SPIreadCommand(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes, bool waitForBusy, bool verify) { // send the command int16_t state = SX126x::SPItransfer(cmd, cmdLen, false, NULL, data, numBytes, waitForBusy); RADIOLIB_ASSERT(state); // check the status - state = checkCommandResult(); + if(verify) { + state = checkCommandResult(); + } + return(state); } -int16_t SX126x::SPIreadCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy) { +int16_t SX126x::SPIreadCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy, bool verify) { // send the command int16_t state = SX126x::SPItransfer(&cmd, 1, false, NULL, data, numBytes, waitForBusy); RADIOLIB_ASSERT(state); // check the status - state = checkCommandResult(); + if(verify) { + state = checkCommandResult(); + } + return(state); } diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index 2132a3fa..b1c783ab 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -1005,10 +1005,10 @@ class SX126x: public PhysicalLayer { Module* _mod; // common low-level SPI interface - int16_t SPIwriteCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy = true); - int16_t SPIwriteCommand(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes, bool waitForBusy = true); - int16_t SPIreadCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy = true); - int16_t SPIreadCommand(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes, bool waitForBusy = true); + int16_t SPIwriteCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy = true, bool verify = true); + int16_t SPIwriteCommand(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes, bool waitForBusy = true, bool verify = true); + int16_t SPIreadCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy = true, bool verify = true); + int16_t SPIreadCommand(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes, bool waitForBusy = true, bool verify = true); int16_t SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes, bool waitForBusy, uint32_t timeout = 5000); #if !defined(RADIOLIB_GODMODE)