Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4640

General • C/C++ drivers for WaveShare 3.5 inch LCD display for the Pico

$
0
0
I'm using the WaveShare Pico ResTouch 3.5 inch LCD with my Raspberry Pi Pico 2W. When I followed the MicroPython tutorials, I managed to get it to work, and got about a smooth framerate, however touchscreen working was on and off and sometimes I'd have to restart several times for touch to be recognised, which is annoying. Additionally, I just prefer C++, so I decided to look at the example code they had for C. You can download both the Python and C examples here.

The Waveshare Wiki page for the Pico ResTouch 3.5.

However, one thing I noticed when experimenting around was that the C implementation of the driver took much longer to draw. For the example included this isn't a problem, because it draws most of the GUI only once. However, when I was trying out my own things it took a while to draw. After some research and looking at the driver code, I think I've found the problem.

The MicroPython driver stores all the pixels and colours in a framebuffer. So when you tell the driver to "set pixel to red" or "draw rectangle" it's not actually drawing it directly on the screen right away, rather it's being put in the framebuffer in such a way that when the framebuffer is written to a screen, it would show whatever is requested. To get the framebuffer to show onto the screen, you have to call show_up or show_down. The MicroPython driver partitions the framebuffer into two, one containing the top half of the screen and the other the bottom half, because the Pico's memory isn't large enough to contain both in one. I can't remember the exact explanation and don't want to waste time rummaging around the internet for it.

This contrasts to the C driver. With the C driver, if you tell it to "colour a pixel" or "draw a rectangle" it goes straight to the screen, or in the latter's case, it will run colour a pixel for the width and height given for the rectangle. While with the MicroPython driver, the changes won't be shown on screen until manually specified, meaning everything since the last update will appear at once.

Is there any alternative driver for SPI displays such as my own? And if there's not, can you point me to any good guides on how to write display drivers for the Pico in C? I've tried "translating" the Python code but to be honest I find it all confusing.

Statistics: Posted by ChasTech — Fri Jan 10, 2025 3:18 pm — Replies 1 — Views 56



Viewing all articles
Browse latest Browse all 4640

Trending Articles