From 08989ff6fa615672938df2de9233af87d074da85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Fri, 10 Jun 2022 12:28:32 +0200 Subject: [PATCH 1/2] Allow SPItransfer to be overridden by subclasses This allows API clients to provide 'smarter' versions of Module that can do things like add thread safety so that multiple devices (and service threads) can share the same SPI bus. i.e. a subclass would lock some sort of mutex. This is used in the Radiolib Fork for Meshtastic to share an SPI bus with SD Card and TFT Display but we want to move back to upstream and not maintain our own fork. --- src/Module.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module.h b/src/Module.h index 3a7b098d4..2492c1a4b 100644 --- a/src/Module.h +++ b/src/Module.h @@ -190,7 +190,7 @@ class Module { \param numBytes Number of bytes to transfer. */ - void SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes); + virtual void SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes); // pin number access methods From 1ebf420a868190911bde2bc59483c4a126e1bc4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sun, 12 Jun 2022 21:20:48 +0200 Subject: [PATCH 2/2] change locking mechanism in patch to transactions --- src/Module.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Module.h b/src/Module.h index 2492c1a4b..aa38f6d4e 100644 --- a/src/Module.h +++ b/src/Module.h @@ -190,7 +190,7 @@ class Module { \param numBytes Number of bytes to transfer. */ - virtual void SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes); + void SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes); // pin number access methods @@ -361,9 +361,9 @@ class Module { // helper functions to set up SPI overrides on Arduino #if defined(RADIOLIB_BUILD_ARDUINO) void SPIbegin(); - void SPIbeginTransaction(); + virtual void SPIbeginTransaction(); uint8_t SPItransfer(uint8_t b); - void SPIendTransaction(); + virtual void SPIendTransaction(); void SPIend(); #endif