venice1200 / SSD1322_for_Adafruit_GFX

SSD1322 OLED Library for use with the Adafruit GFX/GrayOLED Library
BSD 3-Clause "New" or "Revised" License
5 stars 3 forks source link

Slow SPI writes #2

Open bringert opened 1 year ago

bringert commented 1 year ago

The current code uses Adafruit_SPIDevice::write() which on everything except EPS32 ends up writing one byte at a time to the SPI bus. This makes it very slow, I benchmarked it at 200 ms on an Arduino Nano 33 BLE.

I've forked the library to make it work with 128x64 displays, and in the process switched to Adafruit_SPIDevice::write_and_read(), which only takes 16 ms on the same device. The code is here: https://github.com/bringert/Fast_SSD1322_for_Adafruit_GFX but it can't be pulled in directly, since my code probably only works with 128x64 displays. They use a weird protocol where each 4-bit nibble is duplicated, and sent as one byte per pixel.

venice1200 commented 1 year ago

Do you think just replacing the SPI command can work?

bringert commented 1 year ago

No, not quite. Adafruit_SPIDevice::write_and_read() overwrites the buffer that it's given, so you first need to copy the data into a new buffer. Doing that is still a lot faster than using SPI byte-by-byte, so it's worth doing.

There's another benefit to using a second buffer, even for 256x64 displays that don't need the nibble-duplicating logic: you can copy only the data from the dirty window into the write buffer, set the start/end rows and columns, and write everything in one go, instead of having to write row-by-row.

I can try to rewrite my code to work for 256x64 displays as well.

venice1200 commented 1 year ago

Understand.

Using the library with an 8266 and my tty2oled project don't left much space within the MCU. Another full buffer can be problematic.

The ESP32 should work.

venice1200 commented 1 year ago

I wonder about your "nibble-duplicating logic", as we use the same controller.

I am happy to test a "fast" 256x64 Pixel library version with my application if you like.

bringert commented 1 year ago

For some reason the display manufacturer has decided to connect two memory positions to each pixel in the 128x64 display, which requires nibble duplication. I'm guessing that in the 256x64 display, there is only one memory position per pixel, so no such logic is needed.

I'll try to modify my code to work for 256x64 as well.