If you are just here because you used the example of waveshare and want to speed up the display module, do the following:
I have recently gotten my hands on a LCD Module from Waveshare. Naturally i tried to ran their example code provided here to see on my Arduino Nano ESP32 if everything is working correctly.
I did work as advertised and I have moved on with my project. However once I have added some functionality i soon realised that the 2 seconds it took for the screen to update wasn’t really feasable and wondered if it is maybe normal that SPI is just that slow.
As i have joined lemmy i tried my luck there and asked on /c/askelectronics for help. I got help fairly quickly (2 hours) which kinda surpised me as the community wasn’t too active at the time of writing with around a post every week and 3.7k subscribers who have to be online as posts get burried fairly quickly. The quality was also note worthy, not a single answer was duplicated and every single one helped me with the goal. For me that was the moment i realised that the internet is not dead yet
Here are the things i have learned:
Arduino provides you with a helper function to “talk” to the GPIO. Namely digitalWrite digitalRead these however do much more then just writing/reading to GPIO e.g. checking if that PIN is actually there, everytime so to bypass we can just talk to register directly which is what those function do anyways.
digitalWrite
digitalRead
For that just change this:
digitalWrite(10, LOW); digitalWrite(7, HIGH);
to this:
GPIO.out_w1tc = 1UL << 21; GPIO.out_w1ts = 1UL << 10;
If the pin is higher than 32 you have to set a different variable (those start at 0 again so you have to subtract 32):
GPIO.out1_w1tc.val = 1UL << (48 - 32)
Do this where it calls often like in loops etc.
This is changeset coming out of this: https://codeberg.org/bvoigtlaender/open-phone/commit/66bcae5aa343f7f76126223b3b36ff0de033af73
The ST7735S TFT Driver the module is based of as two different modes: Command Mode/Data Mode the example code changes the mode for every pixel it writes to move the cursor to the next position. You don’t have to do this if the pixel is next to last one anyways. It is in fact so slow that is rarly worth it to move the cursor other than moving it back to the start. Which means it is better to build a buffer on cpu and send the whole thing in one go. You can consider splitting the buffer in bigger chunks which rarly update like a task bar though.
This is the changeset coming out of this: https://codeberg.org/bvoigtlaender/open-phone/commit/60f8fe356043c251e2307ea433dc99644061118b
It is kinda fun and a great way to learn about computers to run into the same problems people had back in the day. I never would have gotten a better explainer on buffers than having to solve this problem myself.
Honestly im not sure where it is written but somebody on lemmy said that the display supports up to 15Mhz.
The functions used in the waveshare example are also deprecated. You can now use SPISettings and set the clock speed directly.
Here is the changeset coming out of this: https://codeberg.org/bvoigtlaender/open-phone/commit/5a1dd9e5e8b9035459f4047efa72b817a2a62f67