Skip to content

Commit 41635e3

Browse files
committed
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.
1 parent 4ca0493 commit 41635e3

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Adafruit_SPIDevice.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,26 @@ void Adafruit_SPIDevice::endTransaction(void) {
282282
}
283283
}
284284

285+
/*!
286+
* @brief Write a buffer or two to the SPI device, with transaction
287+
* management.
288+
* @brief Manually begin a transaction (calls beginTransaction if hardware
289+
* SPI) with asserting the CS pin
290+
*/
291+
void Adafruit_SPIDevice::beginTransactionWithAssertingCS() {
292+
beginTransaction();
293+
setChipSelect(LOW);
294+
}
295+
296+
/*!
297+
* @brief Manually end a transaction (calls endTransaction if hardware SPI)
298+
* with deasserting the CS pin
299+
*/
300+
void Adafruit_SPIDevice::endTransactionWithDeassertingCS() {
301+
setChipSelect(HIGH);
302+
endTransaction();
303+
}
304+
285305
/*!
286306
* @brief Write a buffer or two to the SPI device, with transaction
287307
* management.

Adafruit_SPIDevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class Adafruit_SPIDevice {
8888
void transfer(uint8_t *buffer, size_t len);
8989
void beginTransaction(void);
9090
void endTransaction(void);
91+
void beginTransactionWithAssertingCS();
92+
void endTransactionWithDeassertingCS();
9193

9294
private:
9395
SPIClass *_spi;

0 commit comments

Comments
 (0)