From 41635e3c68386cbaaf6006d073e3767a4971c962 Mon Sep 17 00:00:00 2001 From: Christian Riggenbach Date: Mon, 2 May 2022 22:35:38 +0200 Subject: [PATCH] beginTransactionWithAssertingCS() and endTransactionWithDeassertingCS() These two methods are similar to beginTransaction() and endTransaction(), but, as the name implies, with CS management. They are both public, as beginTransaction() and endTransaction() are too. --- Adafruit_SPIDevice.cpp | 20 ++++++++++++++++++++ Adafruit_SPIDevice.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/Adafruit_SPIDevice.cpp b/Adafruit_SPIDevice.cpp index 3cca367..45a2e65 100644 --- a/Adafruit_SPIDevice.cpp +++ b/Adafruit_SPIDevice.cpp @@ -282,6 +282,26 @@ void Adafruit_SPIDevice::endTransaction(void) { } } +/*! + * @brief Write a buffer or two to the SPI device, with transaction + * management. + * @brief Manually begin a transaction (calls beginTransaction if hardware + * SPI) with asserting the CS pin + */ +void Adafruit_SPIDevice::beginTransactionWithAssertingCS() { + beginTransaction(); + setChipSelect(LOW); +} + +/*! + * @brief Manually end a transaction (calls endTransaction if hardware SPI) + * with deasserting the CS pin + */ +void Adafruit_SPIDevice::endTransactionWithDeassertingCS() { + setChipSelect(HIGH); + endTransaction(); +} + /*! * @brief Write a buffer or two to the SPI device, with transaction * management. diff --git a/Adafruit_SPIDevice.h b/Adafruit_SPIDevice.h index 4c8d7bf..7639a9b 100644 --- a/Adafruit_SPIDevice.h +++ b/Adafruit_SPIDevice.h @@ -88,6 +88,8 @@ public: void transfer(uint8_t *buffer, size_t len); void beginTransaction(void); void endTransaction(void); + void beginTransactionWithAssertingCS(); + void endTransactionWithDeassertingCS(); private: SPIClass *_spi;