From 5b992cda512818dbba823d4a4cb5a60b88fcaaff Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 12 Apr 2019 22:48:39 -0700 Subject: [PATCH] Added sendCommand for SPI abstraction --- Adafruit_SPITFT.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++ Adafruit_SPITFT.h | 3 +++ 2 files changed, 59 insertions(+) diff --git a/Adafruit_SPITFT.cpp b/Adafruit_SPITFT.cpp index 50bc71d..7ba554c 100644 --- a/Adafruit_SPITFT.cpp +++ b/Adafruit_SPITFT.cpp @@ -1632,6 +1632,62 @@ uint16_t Adafruit_SPITFT::color565(uint8_t red, uint8_t green, uint8_t blue) { return ((red & 0xF8) << 8) | ((green & 0xFC) << 3) | (blue >> 3); } +/*! + @brief Adafruit_SPITFT Send Command handles complete sending of a command + @param commandByte The Command Byte + */ +void Adafruit_SPITFT::sendCommand(uint8_t commandByte) { + uint8_t dataBytes = NULL; + sendCommand(commandByte, &dataBytes, 0); +} + +/*! + @brief Adafruit_SPITFT Send Command handles complete sending of commands and data + @param commandByte The Command Byte + @param dataBytes A pointer to the Data bytes to send + @param numDataBytes The number of bytes we should send + */ +void Adafruit_SPITFT::sendCommand(uint8_t commandByte, uint8_t *dataBytes, uint8_t numDataBytes) { + SPI_BEGIN_TRANSACTION(); + if(_cs >= 0) SPI_CS_LOW(); + + SPI_DC_LOW(); // Command mode + spiWrite(commandByte); // Send the command byte + + SPI_DC_HIGH(); + for (int i=0; i= 0) SPI_CS_HIGH(); + SPI_END_TRANSACTION(); +} + +/*! + @brief Adafruit_SPITFT Send Command handles complete sending of commands and const data + @param commandByte The Command Byte + @param dataBytes A pointer to the Data bytes to send + @param numDataBytes The number of bytes we should send + */ +void Adafruit_SPITFT::sendCommand(uint8_t commandByte, const uint8_t *dataBytes, uint8_t numDataBytes) { + SPI_BEGIN_TRANSACTION(); + if(_cs >= 0) SPI_CS_LOW(); + + SPI_DC_LOW(); // Command mode + // Send the command byte + spiWrite(commandByte); + + SPI_DC_HIGH(); + for (int i=0; i= 0) SPI_CS_HIGH(); + SPI_END_TRANSACTION(); +} + // ------------------------------------------------------------------------- // Lowest-level hardware-interfacing functions. Many of these are inline and diff --git a/Adafruit_SPITFT.h b/Adafruit_SPITFT.h index 34f8102..39363b6 100644 --- a/Adafruit_SPITFT.h +++ b/Adafruit_SPITFT.h @@ -187,6 +187,9 @@ class Adafruit_SPITFT : public Adafruit_GFX { void startWrite(void); // Chip deselect and/or hardware SPI transaction end as needed: void endWrite(void); + void sendCommand(uint8_t commandByte); + void sendCommand(uint8_t commandByte, uint8_t *dataBytes, uint8_t numDataBytes); + void sendCommand(uint8_t commandByte, const uint8_t *dataBytes, uint8_t numDataBytes); // These functions require a chip-select and/or SPI transaction // around them. Higher-level graphics primitives might start a