Skip to content

Commit 3505566

Browse files
makermelissaladyada
authored andcommitted
added the sendCommand function (#209)
* Added sendCommand for SPI abstraction
1 parent 253e30d commit 3505566

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

Adafruit_SPITFT.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,51 @@ uint16_t Adafruit_SPITFT::color565(uint8_t red, uint8_t green, uint8_t blue) {
16321632
return ((red & 0xF8) << 8) | ((green & 0xFC) << 3) | (blue >> 3);
16331633
}
16341634

1635+
/*!
1636+
@brief Adafruit_SPITFT Send Command handles complete sending of commands and data
1637+
@param commandByte The Command Byte
1638+
@param dataBytes A pointer to the Data bytes to send
1639+
@param numDataBytes The number of bytes we should send
1640+
*/
1641+
void Adafruit_SPITFT::sendCommand(uint8_t commandByte, uint8_t *dataBytes, uint8_t numDataBytes) {
1642+
SPI_BEGIN_TRANSACTION();
1643+
if(_cs >= 0) SPI_CS_LOW();
1644+
1645+
SPI_DC_LOW(); // Command mode
1646+
spiWrite(commandByte); // Send the command byte
1647+
1648+
SPI_DC_HIGH();
1649+
for (int i=0; i<numDataBytes; i++) {
1650+
spiWrite(*dataBytes); // Send the data bytes
1651+
dataBytes++;
1652+
}
1653+
1654+
if(_cs >= 0) SPI_CS_HIGH();
1655+
SPI_END_TRANSACTION();
1656+
}
1657+
1658+
/*!
1659+
@brief Adafruit_SPITFT Send Command handles complete sending of commands and const data
1660+
@param commandByte The Command Byte
1661+
@param dataBytes A pointer to the Data bytes to send
1662+
@param numDataBytes The number of bytes we should send
1663+
*/
1664+
void Adafruit_SPITFT::sendCommand(uint8_t commandByte, const uint8_t *dataBytes, uint8_t numDataBytes) {
1665+
SPI_BEGIN_TRANSACTION();
1666+
if(_cs >= 0) SPI_CS_LOW();
1667+
1668+
SPI_DC_LOW(); // Command mode
1669+
spiWrite(commandByte); // Send the command byte
1670+
1671+
SPI_DC_HIGH();
1672+
for (int i=0; i<numDataBytes; i++) {
1673+
spiWrite(pgm_read_byte(dataBytes++)); // Send the data bytes
1674+
}
1675+
1676+
if(_cs >= 0) SPI_CS_HIGH();
1677+
SPI_END_TRANSACTION();
1678+
}
1679+
16351680

16361681
// -------------------------------------------------------------------------
16371682
// Lowest-level hardware-interfacing functions. Many of these are inline and

Adafruit_SPITFT.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ class Adafruit_SPITFT : public Adafruit_GFX {
187187
void startWrite(void);
188188
// Chip deselect and/or hardware SPI transaction end as needed:
189189
void endWrite(void);
190+
void sendCommand(uint8_t commandByte, uint8_t *dataBytes = NULL, uint8_t numDataBytes = 0);
191+
void sendCommand(uint8_t commandByte, const uint8_t *dataBytes, uint8_t numDataBytes);
190192

191193
// These functions require a chip-select and/or SPI transaction
192194
// around them. Higher-level graphics primitives might start a

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Adafruit GFX Library
2-
version=1.4.8
2+
version=1.4.9
33
author=Adafruit
44
maintainer=Adafruit <[email protected]>
55
sentence=Adafruit GFX graphics core library, this is the 'core' class that all our other graphics libraries derive from.

0 commit comments

Comments
 (0)