mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
many speed optimizations in Adafruit_ILI9341 lib (3x times faster)
add new SPI function: void write(uint8_t data); void write16(uint16_t data); void write16(uint16_t data, bool msb); void writeBytes(uint8_t * data, uint32_t size); void writePattern(uint8_t * data, uint8_t size, uint32_t repeat); Adafruit_ILI9341: | Benchmark | Old (ms) | New (ms) | Speedup | | ------------------------- | -------- | -------- | ----------- | | Screen fill | 1248369 | 278707 | +347,91% | | Text | 86102 | 53785 | +60,09% | | Lines | 825400 | 536374 | +53,89% | | Horiz/Vert Lines | 101875 | 24653 | +313,24% | | Rectangles (outline) | 65720 | 17295 | +279,99% | | Rectangles (filled) | 2592250 | 579157 | +347,59% | | Circles (filled) | 411475 | 179454 | +129,29% | | Circles (outline) | 360002 | 233584 | +54,12% | | Triangles (outline) | 261772 | 170118 | +53,88% | | Triangles (filled) | 866951 | 246237 | +252,08% | | Rounded rects (outline) | 154131 | 81570 | +88,96% | | Rounded rects (filled) | 2828112 | 660983 | +327,86% | | | | | | | Total | 9802159 | 3061917 | +220,13% |
This commit is contained in:
@ -36,6 +36,7 @@ typedef union {
|
||||
SPIClass SPI;
|
||||
|
||||
SPIClass::SPIClass() {
|
||||
useHwCs = false;
|
||||
}
|
||||
|
||||
void SPIClass::begin() {
|
||||
@ -54,9 +55,26 @@ void SPIClass::end() {
|
||||
pinMode(SCK, INPUT);
|
||||
pinMode(MISO, INPUT);
|
||||
pinMode(MOSI, INPUT);
|
||||
if(useHwCs) {
|
||||
pinMode(SS, INPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void SPIClass::setHwCs(bool use) {
|
||||
if(use) {
|
||||
pinMode(SS, SPECIAL); ///< GPIO15
|
||||
SPI1U |= (SPIUCSSETUP | SPIUCSHOLD);
|
||||
} else {
|
||||
if(useHwCs) {
|
||||
pinMode(SS, INPUT);
|
||||
SPI1U &= ~(SPIUCSSETUP | SPIUCSHOLD);
|
||||
}
|
||||
}
|
||||
useHwCs = use;
|
||||
}
|
||||
|
||||
void SPIClass::beginTransaction(SPISettings settings) {
|
||||
while(SPI1CMD & SPIBUSY) {}
|
||||
setFrequency(settings._clock);
|
||||
setBitOrder(settings._bitOrder);
|
||||
setDataMode(settings._dataMode);
|
||||
@ -199,12 +217,10 @@ void SPIClass::setClockDivider(uint32_t clockDiv) {
|
||||
}
|
||||
|
||||
uint8_t SPIClass::transfer(uint8_t data) {
|
||||
while(SPI1CMD & SPIBUSY)
|
||||
;
|
||||
while(SPI1CMD & SPIBUSY) {}
|
||||
SPI1W0 = data;
|
||||
SPI1CMD |= SPIBUSY;
|
||||
while(SPI1CMD & SPIBUSY)
|
||||
;
|
||||
while(SPI1CMD & SPIBUSY) {}
|
||||
return (uint8_t) (SPI1W0 & 0xff);
|
||||
}
|
||||
|
||||
@ -230,3 +246,101 @@ uint16_t SPIClass::transfer16(uint16_t data) {
|
||||
return out.val;
|
||||
}
|
||||
|
||||
void SPIClass::write(uint8_t data) {
|
||||
while(SPI1CMD & SPIBUSY) {}
|
||||
SPI1W0 = data;
|
||||
SPI1CMD |= SPIBUSY;
|
||||
while(SPI1CMD & SPIBUSY) {}
|
||||
}
|
||||
|
||||
void SPIClass::write16(uint16_t data) {
|
||||
write16(data, (SPI1C & (SPICWBO | SPICRBO)));
|
||||
}
|
||||
|
||||
void SPIClass::write16(uint16_t data, bool msb) {
|
||||
while(SPI1CMD & SPIBUSY) {}
|
||||
// Set to 16Bits transfer
|
||||
SPI1U1 = (SPI1U1 & ~((SPIMMOSI << SPILMOSI))) | ((16 - 1) << SPILMOSI);
|
||||
if(msb) {
|
||||
// MSBFIRST Byte first
|
||||
SPI1W0 = (data >> 8) | (data << 8);
|
||||
SPI1CMD |= SPIBUSY;
|
||||
} else {
|
||||
// LSBFIRST Byte first
|
||||
SPI1W0 = data;
|
||||
SPI1CMD |= SPIBUSY;
|
||||
}
|
||||
while(SPI1CMD & SPIBUSY) {}
|
||||
// reset to 8Bit mode
|
||||
SPI1U1 = (SPI1U1 & ~((SPIMMOSI << SPILMOSI))) | ((8 - 1) << SPILMOSI);
|
||||
}
|
||||
|
||||
void SPIClass::writeBytes(uint8_t * data, uint32_t size) {
|
||||
while(size) {
|
||||
if(size > 64) {
|
||||
writeBytes_(data, 64);
|
||||
size -= 64;
|
||||
data += 64;
|
||||
} else {
|
||||
writeBytes_(data, size);
|
||||
size = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SPIClass::writeBytes_(uint8_t * data, uint8_t size) {
|
||||
while(SPI1CMD & SPIBUSY) {}
|
||||
// Set Bits to transfer
|
||||
SPI1U1 = (SPI1U1 & ~((SPIMMOSI << SPILMOSI))) | ((size * 8 - 1) << SPILMOSI);
|
||||
|
||||
volatile uint32_t * fifoPtr = &SPI1W0;
|
||||
uint32_t * dataPtr = (uint32_t*) data;
|
||||
uint8_t dataSize = ((size + 3) / 4);
|
||||
|
||||
while(dataSize--) {
|
||||
*fifoPtr = *dataPtr;
|
||||
dataPtr++;
|
||||
fifoPtr++;
|
||||
}
|
||||
|
||||
SPI1CMD |= SPIBUSY;
|
||||
while(SPI1CMD & SPIBUSY) {}
|
||||
// reset to 8Bit mode
|
||||
SPI1U1 = (SPI1U1 & ~((SPIMMOSI << SPILMOSI))) | ((8 - 1) << SPILMOSI);
|
||||
}
|
||||
|
||||
void SPIClass::writePattern(uint8_t * data, uint8_t size, uint32_t repeat) {
|
||||
if(size > 64) return; //max Hardware FIFO
|
||||
|
||||
uint32_t byte = (size * repeat);
|
||||
uint8_t r = (64 / size);
|
||||
|
||||
while(byte) {
|
||||
if(byte > 64) {
|
||||
writePattern_(data, size, r);
|
||||
byte -= 64;
|
||||
} else {
|
||||
writePattern_(data, size, (byte / size));
|
||||
byte = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SPIClass::writePattern_(uint8_t * data, uint8_t size, uint8_t repeat) {
|
||||
uint8_t bytes = (size * repeat);
|
||||
uint8_t buffer[64];
|
||||
uint8_t * bufferPtr = &buffer[0];
|
||||
uint8_t * dataPtr;
|
||||
uint8_t dataSize = bytes;
|
||||
for(uint8_t i = 0; i < repeat; i++) {
|
||||
dataSize = size;
|
||||
dataPtr = data;
|
||||
while(dataSize--) {
|
||||
*bufferPtr = *dataPtr;
|
||||
dataPtr++;
|
||||
bufferPtr++;
|
||||
}
|
||||
}
|
||||
|
||||
writeBytes(&buffer[0], bytes);
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ public:
|
||||
SPIClass();
|
||||
void begin();
|
||||
void end();
|
||||
void setHwCs(bool use);
|
||||
void setBitOrder(uint8_t bitOrder);
|
||||
void setDataMode(uint8_t dataMode);
|
||||
void setFrequency(uint32_t freq);
|
||||
@ -71,7 +72,16 @@ public:
|
||||
void beginTransaction(SPISettings settings);
|
||||
uint8_t transfer(uint8_t data);
|
||||
uint16_t transfer16(uint16_t data);
|
||||
void write(uint8_t data);
|
||||
void write16(uint16_t data);
|
||||
void write16(uint16_t data, bool msb);
|
||||
void writeBytes(uint8_t * data, uint32_t size);
|
||||
void writePattern(uint8_t * data, uint8_t size, uint32_t repeat);
|
||||
void endTransaction(void);
|
||||
private:
|
||||
bool useHwCs;
|
||||
void writeBytes_(uint8_t * data, uint8_t size);
|
||||
void writePattern_(uint8_t * data, uint8_t size, uint8_t repeat);
|
||||
};
|
||||
|
||||
extern SPIClass SPI;
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
|
||||
Modified 09 May 2015 by Markus Sattler - rewrite the code add ESP8266 support and many optimizations now 220% fastet (320% total)
|
||||
****************************************************/
|
||||
|
||||
#include "Adafruit_ILI9341.h"
|
||||
@ -40,8 +42,8 @@ Adafruit_ILI9341::Adafruit_ILI9341(int8_t cs, int8_t dc, int8_t mosi,
|
||||
|
||||
// Constructor when using hardware SPI. Faster, but must use SPI pins
|
||||
// specific to each board type (e.g. 11,13 for Uno, 51,52 for Mega, etc.)
|
||||
Adafruit_ILI9341::Adafruit_ILI9341(int8_t cs, int8_t dc, int8_t rst) : Adafruit_GFX(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT) {
|
||||
_cs = cs;
|
||||
#ifdef USE_HW_CS
|
||||
Adafruit_ILI9341::Adafruit_ILI9341(int8_t dc, int8_t rst) : Adafruit_GFX(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT) {
|
||||
_dc = dc;
|
||||
_rst = rst;
|
||||
hwSPI = true;
|
||||
@ -49,6 +51,24 @@ Adafruit_ILI9341::Adafruit_ILI9341(int8_t cs, int8_t dc, int8_t rst) : Adafruit_
|
||||
_mosi = _sclk = 0;
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
Adafruit_ILI9341::Adafruit_ILI9341(int8_t cs, int8_t dc, int8_t rst) : Adafruit_GFX(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT) {
|
||||
_cs = cs;
|
||||
_dc = dc;
|
||||
_rst = rst;
|
||||
hwSPI = true;
|
||||
#ifndef ESP8266
|
||||
_mosi = _sclk = 0;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef ESP8266
|
||||
void Adafruit_ILI9341::spiwrite16(uint16_t c) {
|
||||
SPI.write16(c, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
void Adafruit_ILI9341::spiwrite(uint8_t c) {
|
||||
|
||||
@ -63,7 +83,7 @@ void Adafruit_ILI9341::spiwrite(uint8_t c) {
|
||||
while(!(SPSR & _BV(SPIF)));
|
||||
SPCR = backupSPCR;
|
||||
#elif defined(TEENSYDUINO) || defined(ESP8266)
|
||||
SPI.transfer(c);
|
||||
SPI.write(c);
|
||||
#elif defined (__arm__)
|
||||
SPI.setClockDivider(11); // 8-ish MHz (full! speed!)
|
||||
SPI.setBitOrder(MSBFIRST);
|
||||
@ -90,62 +110,129 @@ void Adafruit_ILI9341::spiwrite(uint8_t c) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void Adafruit_ILI9341::spiwriteBytes(uint8_t * data, uint8_t size) {
|
||||
#ifdef ESP8266
|
||||
SPI.writeBytes(data, size);
|
||||
#else
|
||||
while(size--) {
|
||||
spiwrite(*data);
|
||||
data++;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Adafruit_ILI9341::writecommand(uint8_t c) {
|
||||
void Adafruit_ILI9341::spiwritePattern(uint8_t * data, uint8_t size, uint32_t repeat) {
|
||||
#ifdef ESP8266
|
||||
SPI.writePattern(data, size, repeat);
|
||||
#else
|
||||
uint8_t * ptr;
|
||||
uint8_t i;
|
||||
while(repeat--) {
|
||||
ptr = data;
|
||||
i = size;
|
||||
while(i--) {
|
||||
spiwrite(*ptr);
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
inline void Adafruit_ILI9341::spiCsLow(void) {
|
||||
#ifdef USE_DIGITAL_WRITE
|
||||
digitalWrite(_dc, LOW);
|
||||
digitalWrite(_cs, LOW);
|
||||
#else
|
||||
#ifdef ESP8266
|
||||
GPOC = digitalPinToBitMask(_dc);
|
||||
#ifndef USE_HW_CS
|
||||
GPOC = digitalPinToBitMask(_cs);
|
||||
#else
|
||||
*dcport &= ~dcpinmask;
|
||||
//*clkport &= ~clkpinmask; // clkport is a NULL pointer when hwSPI==true
|
||||
//digitalWrite(_sclk, LOW);
|
||||
*csport &= ~cspinmask;
|
||||
#endif
|
||||
#endif
|
||||
spiwrite(c);
|
||||
#ifdef USE_DIGITAL_WRITE
|
||||
digitalWrite(_cs, HIGH);
|
||||
#else
|
||||
#ifdef ESP8266
|
||||
GPOS = digitalPinToBitMask(_cs);
|
||||
#else
|
||||
*csport |= cspinmask;
|
||||
*csport &= ~cspinmask;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void Adafruit_ILI9341::writedata(uint8_t c) {
|
||||
#ifdef USE_DIGITAL_WRITE
|
||||
digitalWrite(_dc, HIGH);
|
||||
digitalWrite(_cs, LOW);
|
||||
#else
|
||||
#ifdef ESP8266
|
||||
GPOS = digitalPinToBitMask(_dc);
|
||||
GPOC = digitalPinToBitMask(_cs);
|
||||
#else
|
||||
*dcport |= dcpinmask;
|
||||
|
||||
//*clkport &= ~clkpinmask; // clkport is a NULL pointer when hwSPI==true
|
||||
//digitalWrite(_sclk, LOW);
|
||||
*csport &= ~cspinmask;
|
||||
#endif
|
||||
#endif
|
||||
spiwrite(c);
|
||||
inline void Adafruit_ILI9341::spiCsHigh(void) {
|
||||
#ifdef USE_DIGITAL_WRITE
|
||||
digitalWrite(_cs, HIGH);
|
||||
#else
|
||||
#ifdef ESP8266
|
||||
GPOS = digitalPinToBitMask(_cs);
|
||||
#ifndef USE_HW_CS
|
||||
GPOS = digitalPinToBitMask(_cs);
|
||||
#endif
|
||||
#else
|
||||
*csport |= cspinmask;
|
||||
*csport |= cspinmask;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void Adafruit_ILI9341::spiDcLow(void){
|
||||
#ifdef USE_DIGITAL_WRITE
|
||||
digitalWrite(_dc, LOW);
|
||||
#else
|
||||
#ifdef ESP8266
|
||||
#ifndef USE_HW_CS
|
||||
GPOC = digitalPinToBitMask(_dc);
|
||||
#endif
|
||||
#else
|
||||
*dcport &= ~dcpinmask;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void Adafruit_ILI9341::spiDcHigh(void) {
|
||||
#ifdef USE_DIGITAL_WRITE
|
||||
digitalWrite(_dc, HIGH);
|
||||
#else
|
||||
#ifdef ESP8266
|
||||
GPOS = digitalPinToBitMask(_dc);
|
||||
#else
|
||||
*dcport |= dcpinmask;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void Adafruit_ILI9341::writecommand(uint8_t c) {
|
||||
spiDcLow();
|
||||
spiCsLow();
|
||||
|
||||
spiwrite(c);
|
||||
|
||||
spiCsHigh();
|
||||
}
|
||||
|
||||
void Adafruit_ILI9341::writedata(uint8_t c) {
|
||||
spiDcHigh();
|
||||
spiCsLow();
|
||||
|
||||
spiwrite(c);
|
||||
|
||||
spiCsHigh();
|
||||
}
|
||||
|
||||
void Adafruit_ILI9341::writedata(uint8_t * data, uint8_t size) {
|
||||
spiDcHigh();
|
||||
spiCsLow();
|
||||
|
||||
spiwriteBytes(data, size);
|
||||
|
||||
spiCsHigh();
|
||||
}
|
||||
|
||||
void Adafruit_ILI9341::writeCmdData(uint8_t cmd, uint8_t * data, uint8_t size) {
|
||||
spiDcLow();
|
||||
spiCsLow();
|
||||
|
||||
spiwrite(cmd);
|
||||
|
||||
spiDcHigh();
|
||||
|
||||
spiwriteBytes(data, size);
|
||||
|
||||
spiCsHigh();
|
||||
}
|
||||
|
||||
// If the SPI library has transaction support, these functions
|
||||
// establish settings and protect from interference from other
|
||||
// libraries. Otherwise, they simply do nothing.
|
||||
@ -153,7 +240,7 @@ void Adafruit_ILI9341::writedata(uint8_t c) {
|
||||
static inline void spi_begin(void) __attribute__((always_inline));
|
||||
static inline void spi_begin(void) {
|
||||
#ifdef ESP8266
|
||||
SPI.beginTransaction(SPISettings(80000000, MSBFIRST, SPI_MODE0));
|
||||
SPI.beginTransaction(SPISettings(F_CPU, MSBFIRST, SPI_MODE0));
|
||||
#else
|
||||
SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
|
||||
#endif
|
||||
@ -208,7 +295,9 @@ void Adafruit_ILI9341::begin(void) {
|
||||
}
|
||||
|
||||
pinMode(_dc, OUTPUT);
|
||||
#ifndef USE_HW_CS
|
||||
pinMode(_cs, OUTPUT);
|
||||
#endif
|
||||
#ifndef ESP8266
|
||||
#ifndef USE_DIGITAL_WRITE
|
||||
csport = portOutputRegister(digitalPinToPort(_cs));
|
||||
@ -236,6 +325,9 @@ void Adafruit_ILI9341::begin(void) {
|
||||
SPI.setDataMode(SPI_MODE0);
|
||||
#elif defined (ESP8266)
|
||||
SPI.begin();
|
||||
#ifdef USE_HW_CS
|
||||
SPI.setHwCs(true);
|
||||
#endif
|
||||
#endif
|
||||
#ifndef ESP8266
|
||||
} else {
|
||||
@ -388,20 +480,13 @@ void Adafruit_ILI9341::begin(void) {
|
||||
}
|
||||
|
||||
|
||||
void Adafruit_ILI9341::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1,
|
||||
uint16_t y1) {
|
||||
void Adafruit_ILI9341::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
|
||||
|
||||
writecommand(ILI9341_CASET); // Column addr set
|
||||
writedata(x0 >> 8);
|
||||
writedata(x0 & 0xFF); // XSTART
|
||||
writedata(x1 >> 8);
|
||||
writedata(x1 & 0xFF); // XEND
|
||||
uint8_t buffC[] = {(uint8_t)(x0 >> 8), (uint8_t)x0, (uint8_t)(x1 >> 8), (uint8_t)x1};
|
||||
uint8_t buffP[] = {(uint8_t)(y0 >> 8), (uint8_t)y0, (uint8_t)(y1 >> 8), (uint8_t)y1};
|
||||
|
||||
writecommand(ILI9341_PASET); // Row addr set
|
||||
writedata(y0>>8);
|
||||
writedata(y0); // YSTART
|
||||
writedata(y1>>8);
|
||||
writedata(y1); // YEND
|
||||
writeCmdData(ILI9341_CASET, &buffC[0], sizeof(buffC)); // Column addr set
|
||||
writeCmdData(ILI9341_PASET, &buffP[0], sizeof(buffP)); // Column addr set
|
||||
|
||||
writecommand(ILI9341_RAMWR); // write to RAM
|
||||
}
|
||||
@ -409,29 +494,19 @@ void Adafruit_ILI9341::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1,
|
||||
|
||||
void Adafruit_ILI9341::pushColor(uint16_t color) {
|
||||
if (hwSPI) spi_begin();
|
||||
#ifdef USE_DIGITAL_WRITE
|
||||
digitalWrite(_dc, HIGH);
|
||||
digitalWrite(_cs, LOW);
|
||||
#else
|
||||
|
||||
spiDcHigh();
|
||||
spiCsLow();
|
||||
|
||||
#ifdef ESP8266
|
||||
GPOS = digitalPinToBitMask(_dc);
|
||||
GPOC = digitalPinToBitMask(_cs);
|
||||
spiwrite16(color);
|
||||
#else
|
||||
*dcport |= dcpinmask;
|
||||
*csport &= ~cspinmask;
|
||||
#endif
|
||||
#endif
|
||||
spiwrite(color >> 8);
|
||||
spiwrite(color);
|
||||
#ifdef USE_DIGITAL_WRITE
|
||||
digitalWrite(_cs, HIGH);
|
||||
#else
|
||||
#ifdef ESP8266
|
||||
GPOS = digitalPinToBitMask(_cs);
|
||||
#else
|
||||
*csport |= cspinmask;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
spiCsHigh();
|
||||
|
||||
if (hwSPI) spi_end();
|
||||
}
|
||||
|
||||
@ -441,30 +516,18 @@ void Adafruit_ILI9341::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
||||
|
||||
if (hwSPI) spi_begin();
|
||||
setAddrWindow(x,y,x+1,y+1);
|
||||
#ifdef USE_DIGITAL_WRITE
|
||||
digitalWrite(_dc, HIGH);
|
||||
digitalWrite(_cs, LOW);
|
||||
#else
|
||||
#ifdef ESP8266
|
||||
GPOS = digitalPinToBitMask(_dc);
|
||||
GPOC = digitalPinToBitMask(_cs);
|
||||
#else
|
||||
*dcport |= dcpinmask;
|
||||
*csport &= ~cspinmask;
|
||||
#endif
|
||||
#endif
|
||||
spiDcHigh();
|
||||
spiCsLow();
|
||||
|
||||
#ifdef ESP8266
|
||||
spiwrite16(color);
|
||||
#else
|
||||
spiwrite(color >> 8);
|
||||
spiwrite(color);
|
||||
#ifdef USE_DIGITAL_WRITE
|
||||
digitalWrite(_cs, HIGH);
|
||||
#else
|
||||
#ifdef ESP8266
|
||||
GPOS = digitalPinToBitMask(_cs);
|
||||
#else
|
||||
*csport |= cspinmask;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
spiCsHigh();
|
||||
|
||||
if (hwSPI) spi_end();
|
||||
}
|
||||
|
||||
@ -480,35 +543,18 @@ void Adafruit_ILI9341::drawFastVLine(int16_t x, int16_t y, int16_t h,
|
||||
|
||||
if (hwSPI) spi_begin();
|
||||
setAddrWindow(x, y, x, y+h-1);
|
||||
|
||||
#ifndef ESP8266
|
||||
uint8_t hi = color >> 8, lo = color;
|
||||
|
||||
#ifdef USE_DIGITAL_WRITE
|
||||
digitalWrite(_dc, HIGH);
|
||||
digitalWrite(_cs, LOW);
|
||||
#else
|
||||
#ifdef ESP8266
|
||||
GPOS = digitalPinToBitMask(_dc);
|
||||
GPOC = digitalPinToBitMask(_cs);
|
||||
#else
|
||||
*dcport |= dcpinmask;
|
||||
*csport &= ~cspinmask;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
while (h--) {
|
||||
spiwrite(hi);
|
||||
spiwrite(lo);
|
||||
}
|
||||
#ifdef USE_DIGITAL_WRITE
|
||||
digitalWrite(_cs, HIGH);
|
||||
#else
|
||||
#ifdef ESP8266
|
||||
GPOS = digitalPinToBitMask(_cs);
|
||||
#else
|
||||
*csport |= cspinmask;
|
||||
#endif
|
||||
#endif
|
||||
spiDcHigh();
|
||||
spiCsLow();
|
||||
|
||||
uint8_t colorBin[] = { (uint8_t) (color >> 8), (uint8_t) color };
|
||||
spiwritePattern(&colorBin[0], 2, h);
|
||||
|
||||
spiCsHigh();
|
||||
|
||||
if (hwSPI) spi_end();
|
||||
}
|
||||
|
||||
@ -522,32 +568,14 @@ void Adafruit_ILI9341::drawFastHLine(int16_t x, int16_t y, int16_t w,
|
||||
if (hwSPI) spi_begin();
|
||||
setAddrWindow(x, y, x+w-1, y);
|
||||
|
||||
uint8_t hi = color >> 8, lo = color;
|
||||
#ifdef USE_DIGITAL_WRITE
|
||||
digitalWrite(_dc, HIGH);
|
||||
digitalWrite(_cs, LOW);
|
||||
#else
|
||||
#ifdef ESP8266
|
||||
GPOS = digitalPinToBitMask(_dc);
|
||||
GPOC = digitalPinToBitMask(_cs);
|
||||
#else
|
||||
*dcport |= dcpinmask;
|
||||
*csport &= ~cspinmask;
|
||||
#endif
|
||||
#endif
|
||||
while (w--) {
|
||||
spiwrite(hi);
|
||||
spiwrite(lo);
|
||||
}
|
||||
#ifdef USE_DIGITAL_WRITE
|
||||
digitalWrite(_cs, HIGH);
|
||||
#else
|
||||
#ifdef ESP8266
|
||||
GPOS = digitalPinToBitMask(_cs);
|
||||
#else
|
||||
*csport |= cspinmask;
|
||||
#endif
|
||||
#endif
|
||||
spiDcHigh();
|
||||
spiCsLow();
|
||||
|
||||
uint8_t colorBin[] = { (uint8_t) (color >> 8), (uint8_t) color };
|
||||
spiwritePattern(&colorBin[0], 2, w);
|
||||
|
||||
spiCsHigh();
|
||||
|
||||
if (hwSPI) spi_end();
|
||||
}
|
||||
|
||||
@ -556,48 +584,33 @@ void Adafruit_ILI9341::fillScreen(uint16_t color) {
|
||||
}
|
||||
|
||||
// fill a rectangle
|
||||
void Adafruit_ILI9341::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
|
||||
uint16_t color) {
|
||||
void Adafruit_ILI9341::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) {
|
||||
|
||||
// rudimentary clipping (drawChar w/big text requires this)
|
||||
if((x >= _width) || (y >= _height)) return;
|
||||
if((x + w - 1) >= _width) w = _width - x;
|
||||
if((y + h - 1) >= _height) h = _height - y;
|
||||
// rudimentary clipping (drawChar w/big text requires this)
|
||||
if((x >= _width) || (y >= _height))
|
||||
return;
|
||||
if((x + w - 1) >= _width)
|
||||
w = _width - x;
|
||||
if((y + h - 1) >= _height)
|
||||
h = _height - y;
|
||||
|
||||
if (hwSPI) spi_begin();
|
||||
setAddrWindow(x, y, x+w-1, y+h-1);
|
||||
|
||||
uint8_t hi = color >> 8, lo = color;
|
||||
|
||||
#ifdef USE_DIGITAL_WRITE
|
||||
digitalWrite(_dc, HIGH);
|
||||
digitalWrite(_cs, LOW);
|
||||
#else
|
||||
#ifdef ESP8266
|
||||
GPOS = digitalPinToBitMask(_dc);
|
||||
GPOC = digitalPinToBitMask(_cs);
|
||||
#else
|
||||
*dcport |= dcpinmask;
|
||||
*csport &= ~cspinmask;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
for(y=h; y>0; y--) {
|
||||
for(x=w; x>0; x--) {
|
||||
spiwrite(hi);
|
||||
spiwrite(lo);
|
||||
if(hwSPI) {
|
||||
spi_begin();
|
||||
}
|
||||
|
||||
setAddrWindow(x, y, x + w - 1, y + h - 1);
|
||||
|
||||
spiDcHigh();
|
||||
spiCsLow();
|
||||
|
||||
uint8_t colorBin[] = { (uint8_t) (color >> 8), (uint8_t) color };
|
||||
spiwritePattern(&colorBin[0], 2, (w * h));
|
||||
|
||||
spiCsHigh();
|
||||
|
||||
if(hwSPI) {
|
||||
spi_end();
|
||||
}
|
||||
}
|
||||
#ifdef USE_DIGITAL_WRITE
|
||||
digitalWrite(_cs, HIGH);
|
||||
#else
|
||||
#ifdef ESP8266
|
||||
GPOS = digitalPinToBitMask(_cs);
|
||||
#else
|
||||
*csport |= cspinmask;
|
||||
#endif
|
||||
#endif
|
||||
if (hwSPI) spi_end();
|
||||
}
|
||||
|
||||
|
||||
@ -697,10 +710,13 @@ uint8_t Adafruit_ILI9341::spiread(void) {
|
||||
|
||||
uint8_t Adafruit_ILI9341::readdata(void) {
|
||||
digitalWrite(_dc, HIGH);
|
||||
#ifndef USE_HW_CS
|
||||
digitalWrite(_cs, LOW);
|
||||
#endif
|
||||
uint8_t r = spiread();
|
||||
#ifndef USE_HW_CS
|
||||
digitalWrite(_cs, HIGH);
|
||||
|
||||
#endif
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -708,22 +724,29 @@ uint8_t Adafruit_ILI9341::spiread(void) {
|
||||
uint8_t Adafruit_ILI9341::readcommand8(uint8_t c, uint8_t index) {
|
||||
if (hwSPI) spi_begin();
|
||||
digitalWrite(_dc, LOW); // command
|
||||
#ifndef USE_HW_CS
|
||||
digitalWrite(_cs, LOW);
|
||||
#endif
|
||||
spiwrite(0xD9); // woo sekret command?
|
||||
digitalWrite(_dc, HIGH); // data
|
||||
spiwrite(0x10 + index);
|
||||
#ifndef USE_HW_CS
|
||||
digitalWrite(_cs, HIGH);
|
||||
|
||||
#endif
|
||||
digitalWrite(_dc, LOW);
|
||||
#ifndef ESP8266
|
||||
digitalWrite(_sclk, LOW);
|
||||
#endif
|
||||
#ifndef USE_HW_CS
|
||||
digitalWrite(_cs, LOW);
|
||||
#endif
|
||||
spiwrite(c);
|
||||
|
||||
digitalWrite(_dc, HIGH);
|
||||
uint8_t r = spiread();
|
||||
#ifndef USE_HW_CS
|
||||
digitalWrite(_cs, HIGH);
|
||||
#endif
|
||||
if (hwSPI) spi_end();
|
||||
return r;
|
||||
}
|
||||
|
@ -111,6 +111,10 @@
|
||||
#define ILI9341_PINK 0xF81F
|
||||
|
||||
//#define USE_DIGITAL_WRITE
|
||||
#ifdef ESP8266
|
||||
//not working
|
||||
//#define USE_HW_CS
|
||||
#endif
|
||||
|
||||
class Adafruit_ILI9341 : public Adafruit_GFX {
|
||||
|
||||
@ -119,8 +123,11 @@ class Adafruit_ILI9341 : public Adafruit_GFX {
|
||||
Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK,
|
||||
int8_t _RST, int8_t _MISO);
|
||||
#endif
|
||||
#ifdef USE_HW_CS
|
||||
Adafruit_ILI9341(int8_t _DC, int8_t _RST = -1);
|
||||
#else
|
||||
Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _RST = -1);
|
||||
|
||||
#endif
|
||||
void begin(void),
|
||||
setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1),
|
||||
pushColor(uint16_t color),
|
||||
@ -134,22 +141,43 @@ class Adafruit_ILI9341 : public Adafruit_GFX {
|
||||
invertDisplay(boolean i);
|
||||
uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
|
||||
|
||||
/* These are not for current use, 8-bit protocol only! */
|
||||
uint8_t readdata(void),
|
||||
readcommand8(uint8_t reg, uint8_t index = 0);
|
||||
/*
|
||||
uint16_t readcommand16(uint8_t);
|
||||
uint32_t readcommand32(uint8_t);
|
||||
void dummyclock(void);
|
||||
*/
|
||||
void commandList(uint8_t *addr);
|
||||
|
||||
void spiwrite(uint8_t),
|
||||
writecommand(uint8_t c),
|
||||
writedata(uint8_t d),
|
||||
commandList(uint8_t *addr);
|
||||
uint8_t spiread(void);
|
||||
/* These are not for current use, 8-bit protocol only! */
|
||||
uint8_t readdata(void),
|
||||
readcommand8(uint8_t reg, uint8_t index = 0);
|
||||
/*
|
||||
uint16_t readcommand16(uint8_t);
|
||||
uint32_t readcommand32(uint8_t);
|
||||
void dummyclock(void);
|
||||
*/
|
||||
|
||||
void writecommand(uint8_t c);
|
||||
void writedata(uint8_t d);
|
||||
void writedata(uint8_t * data, uint8_t size);
|
||||
void writeCmdData(uint8_t cmd, uint8_t * data, uint8_t size);
|
||||
|
||||
private:
|
||||
|
||||
uint8_t spiread(void);
|
||||
|
||||
#ifdef ESP8266
|
||||
inline void spiwrite(uint8_t data);
|
||||
inline void spiwrite16(uint16_t data);
|
||||
inline void spiwriteBytes(uint8_t * data, uint8_t size);
|
||||
inline void spiwritePattern(uint8_t * data, uint8_t size, uint32_t repeat);
|
||||
#else
|
||||
void spiwrite(uint8_t);
|
||||
void spiwrite16(uint16_t data);
|
||||
void spiwriteBytes(uint8_t * data, uint8_t size);
|
||||
void spiwritePattern(uint8_t * data, uint8_t size, uint8_t repeat);
|
||||
#endif
|
||||
|
||||
inline void spiCsHigh(void);
|
||||
inline void spiCsLow(void);
|
||||
inline void spiDcHigh(void);
|
||||
inline void spiDcLow(void);
|
||||
|
||||
uint8_t tabcolor;
|
||||
|
||||
boolean hwSPI;
|
||||
@ -163,7 +191,10 @@ class Adafruit_ILI9341 : public Adafruit_GFX {
|
||||
uint32_t _cs, _dc, _rst, _mosi, _miso, _sclk;
|
||||
uint32_t mosipinmask, clkpinmask, cspinmask, dcpinmask;
|
||||
#elif defined (ESP8266)
|
||||
uint32_t _cs, _dc, _rst;
|
||||
#ifndef USE_HW_CS
|
||||
int8_t _cs;
|
||||
#endif
|
||||
int8_t _dc, _rst;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user