1. First off, I've tried to find a Soft SPI library for Teensy 4.x, but found little. Does someone have one? You'll know why I ask in a bit.
So, I d/l'ed Teensyduino v1.53 to Arduino IDE v.1.8.12 a couple of days ago.
2. I tried using 2 instantiations of the ILI9341_t3 class to operate two standard Lcd modules from SPI0 (using different CS pins of course), but it wouldn't work for me. I think other people do it, but I didn't spend a lot of time debugging. (I need to try this further).
3. What I did do was try using Soft SPI with the ILI9341 displays and the T4.x, but that constructor no longer exists in the ILI9341_t3 library. So I grabbed the Adafruit_ILI9341 library circa 2016 from my old Teensyduino install on IDE v1.6.13, and at first it wouldn't compile, but I hacked on it a bit, and got it working.
4. So the results using ILI9341_t3 and the old Soft SPI code with the standard graphicstest program are shown below. Of interest, amazingly the Soft SPI test runs on average "only" 1.42X slower. I thought it might be "much much slower".
5. Now to the point: it occurs to me that Soft SPI is so fast on the T4.x that I can use multiple instantiations on different sets of pins, and not worry about issues with the Hard SPI ports. (I don't need blazing SPI speeds). Therefore, interested in a Soft SPI library, re item 1 above.
6. Now the question mark: on looking at the old code for Soft SPI ops, I notice there are no delays in there, so I am wondering how the darn thing was throttled back far enough on the T4.x (running at 1.008 GHz, BTW) that it ran fine on the Lcd, which I believe is limited to 30-MHz SPI rate. ????? Here is some of the old code, you'll notice it bit-bangs SPI, but there are no delays in there.
7. I've noticed on other threads people doing I/O bit-banging upwards to 150-MHz on the T4.x, so why isn't this code blasting the Lcd all to heck?
(04/26/21) T4.1 Hard SPI
------------------------
ILI9341 Test...
Benchmark Time (microseconds)
Screen fill 205264
Text 8385
Lines 64513
Horiz/Vert Lines 17419
Rectangles (outline) 11135
Rectangles (filled) 421431
Circles (filled) 64281
Circles (outline) 43112
Triangles (outline) 15276
Triangles (filled) 144514
Rounded rects (outline) 16782
Rounded rects (filled) 466422
Done!
////////////////////////////////////////////
(04/26/21) T4.1 Soft SPI
------------------------
ILI9341 Test...
Benchmark Time (microseconds)
Screen fill 264125 (1.28X slower)
Text 13874 (1.66X)
Lines 133240 (2.04X)
Horiz/Vert Lines 21778 (1.25X)
Rectangles (outline) 13841 (1.24X)
Rectangles (filled) 533664 (1.26X)
Circles (filled) 63560 (0.99X)
Circles (outline) 58224 (1.35X)
Triangles (outline) 30302 (1.99X)
Triangles (filled) 181690 (1.25X)
Rounded rects (outline) 27332 (1.63X)
Rounded rects (filled) 544964 (1.17X)
Done!
overall average (1.42X slower)
So, I d/l'ed Teensyduino v1.53 to Arduino IDE v.1.8.12 a couple of days ago.
2. I tried using 2 instantiations of the ILI9341_t3 class to operate two standard Lcd modules from SPI0 (using different CS pins of course), but it wouldn't work for me. I think other people do it, but I didn't spend a lot of time debugging. (I need to try this further).
3. What I did do was try using Soft SPI with the ILI9341 displays and the T4.x, but that constructor no longer exists in the ILI9341_t3 library. So I grabbed the Adafruit_ILI9341 library circa 2016 from my old Teensyduino install on IDE v1.6.13, and at first it wouldn't compile, but I hacked on it a bit, and got it working.
4. So the results using ILI9341_t3 and the old Soft SPI code with the standard graphicstest program are shown below. Of interest, amazingly the Soft SPI test runs on average "only" 1.42X slower. I thought it might be "much much slower".
5. Now to the point: it occurs to me that Soft SPI is so fast on the T4.x that I can use multiple instantiations on different sets of pins, and not worry about issues with the Hard SPI ports. (I don't need blazing SPI speeds). Therefore, interested in a Soft SPI library, re item 1 above.
6. Now the question mark: on looking at the old code for Soft SPI ops, I notice there are no delays in there, so I am wondering how the darn thing was throttled back far enough on the T4.x (running at 1.008 GHz, BTW) that it ran fine on the Lcd, which I believe is limited to 30-MHz SPI rate. ????? Here is some of the old code, you'll notice it bit-bangs SPI, but there are no delays in there.
7. I've noticed on other threads people doing I/O bit-banging upwards to 150-MHz on the T4.x, so why isn't this code blasting the Lcd all to heck?
Code:
void Adafruit_ILI9341::spiwrite(uint8_t c) {
//Serial.print("0x"); Serial.print(c, HEX); Serial.print(", ");
if (hwSPI) {
#if defined (__AVR__)
uint8_t backupSPCR = SPCR;
SPCR = mySPCR;
SPDR = c;
while(!(SPSR & _BV(SPIF)));
SPCR = backupSPCR;
#elif defined(TEENSYDUINO)
SPI.transfer(c);
#elif defined (__arm__)
SPI.setClockDivider(11); // 8-ish MHz (full! speed!)
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.transfer(c);
#endif
} else {
// Fast SPI bitbang swiped from LPD8806 library
for(uint8_t bit = 0x80; bit; bit >>= 1) {
if(c & bit) {
//digitalWrite(_mosi, HIGH);
*mosiport |= mosipinmask;
} else {
//digitalWrite(_mosi, LOW);
*mosiport &= ~mosipinmask;
}
//digitalWrite(_sclk, HIGH);
*clkport |= clkpinmask;
//digitalWrite(_sclk, LOW);
*clkport &= ~clkpinmask;
}
}
}
(04/26/21) T4.1 Hard SPI
------------------------
ILI9341 Test...
Benchmark Time (microseconds)
Screen fill 205264
Text 8385
Lines 64513
Horiz/Vert Lines 17419
Rectangles (outline) 11135
Rectangles (filled) 421431
Circles (filled) 64281
Circles (outline) 43112
Triangles (outline) 15276
Triangles (filled) 144514
Rounded rects (outline) 16782
Rounded rects (filled) 466422
Done!
////////////////////////////////////////////
(04/26/21) T4.1 Soft SPI
------------------------
ILI9341 Test...
Benchmark Time (microseconds)
Screen fill 264125 (1.28X slower)
Text 13874 (1.66X)
Lines 133240 (2.04X)
Horiz/Vert Lines 21778 (1.25X)
Rectangles (outline) 13841 (1.24X)
Rectangles (filled) 533664 (1.26X)
Circles (filled) 63560 (0.99X)
Circles (outline) 58224 (1.35X)
Triangles (outline) 30302 (1.99X)
Triangles (filled) 181690 (1.25X)
Rounded rects (outline) 27332 (1.63X)
Rounded rects (filled) 544964 (1.17X)
Done!
overall average (1.42X slower)
Last edited: