"So are you saying your library uses hardware SPI or digitalWrite?" Yes, hardware SPI. At 18 MHz:
myTFT.begin(SPI_18MHZ, MSBFIRST, 0);
I was not so lucky to keep adafruit's library intact, something goes wrong with initialization a class, I received a buch of error from compliler, that I cann't do:
Adafruit_ILI9340::Adafruit_ILI9340(uint8_t cs, uint8_t dc, uint8_t rst) : Adafruit_GFX(ILI9340_TFTWIDTH, ILI9340_TFTHEIGHT) {
_cs = cs;
_dc = dc;
_rst = rst;
hwSPI = true;
_mosi = _sclk = 0;
}
and I'm not so good in C++ to fix it, probably there is a big difference in construction of arduino IDE 1.5 and maple 0.0.12, but leaving this out of scope for a moment, I stack everything in single sketch which become huge ~600 lines -);
Two their's most important functions:
void Adafruit_ILI9340::writecommand(uint8_t c) {
CLEAR_BIT(dcport, dcpinmask);
//digitalWrite(_dc, LOW);
CLEAR_BIT(clkport, clkpinmask);
//digitalWrite(_sclk, LOW);
CLEAR_BIT(csport, cspinmask);
//digitalWrite(_cs, LOW);
spiwrite(c);
SET_BIT(csport, cspinmask);
//digitalWrite(_cs, HIGH);
}
void Adafruit_ILI9340::writedata(uint8_t c) {
SET_BIT(dcport, dcpinmask);
//digitalWrite(_dc, HIGH);
CLEAR_BIT(clkport, clkpinmask);
//digitalWrite(_sclk, LOW);
CLEAR_BIT(csport, cspinmask);
//digitalWrite(_cs, LOW);
spiwrite(c);
//digitalWrite(_cs, HIGH);
SET_BIT(csport, cspinmask);
}
become:
void LCDCommand(unsigned char data)
{
digitalWrite(DSS, LOW);
digitalWrite(CSS, LOW); //
myTFT.write(data);
digitalWrite(CSS, HIGH);
}
void LCDData(unsigned char data) // Send hex data through the serial port (MOSI 1 first)
{
digitalWrite(DSS, HIGH);
digitalWrite(CSS, LOW);
myTFT.write(data);
digitalWrite(CSS, HIGH);
}
and using this approach I get 30 millisec. Next step, after digging up a little this (helpful !) forum, it become:
void LCDCommand(unsigned char data)
{
GPIOB_BASE->BRR = 0x00000003;
myTFT.write(data);
GPIOB_BASE->BSRR = 0x00000003;
}
void LCDData(unsigned char data) // Send hex data through the serial port (MOSI 1 first)
{
GPIOB_BASE->BRR = 0x00000001;
myTFT.write(data);
GPIOB_BASE->BSRR = 0x00000001;
}
and I can see on my scope right now 18.1 milliseconds.
As you can see, I optimized away adafruit's 4 SET/CLEAR in just 2 access to ports in each function.
Probably, there is nothing can be improved. I did some test, trying to run SPI 16-bit ( a lot of data lengh 16 or even 32-bits), but unsuccessfully. Actually data sheet ILI9340 says it's oly support 8-bit's or 9-bit's.
Driving this two digital pins CS and D/C "manually" gives no chance to run SPI with DMA, I'm right?