ST7796S driver lv_micropython

I would like to implement the ST7796S display driver, this display.
A Raspi Python Port already exists.
In this forum I have already learned that the ST7796S may be like the ili9488.
TFT_eSPI also supports the screen. I don’t own the module myself, I want to make sure that I can use it with lv_micropython first.
So I would like to know what I would have to rewrite in the source code to get the screen to work.
With best regards!

1 Like

Hi @Christian_Draxl!

That’s great!
I’ll be happy to help you with this, hoping that you could eventually contribute the driver back to LVGL.

You didn’t explicitly say which platform you are targeting.
A driver is usually implemented for a specific architecture. ESP32 driver would be different from Raspi driver, for example.
In the links you sent there are references to Raspi, ESP32, STM32… Which one are you going to use?

While Python and Micropython implement the same Python3 syntax, they are different languages.
This means that a Python driver cannot directly be used on Micropython, but you can probably port much of the code.

One of the main differences is library support. The Raspi Python Port for example imports numpy, spidev, RPi.GPIO libraries which are not available on Micropython.

Sometimes a driver is implemented in C and has a Python API. Writing Python API for a C library is very different between the “original” Python and Micropython, but if you have a C driver for your target architecture then there is a technique to automatically convert the C API into Micropython API.

There are of course other differences between Python and Micropython, a major one is memory management (Python manages reference counting while Micropython uses Garbage Collection), but the end-user experience in both cases is “writing Python3 code”.

This is good!
We already have a pure-Micropython driver for ILI9341 and ILI9488 for ESP32.
Are you targeting ESP32? If so, it should be pretty easy adding ST7796S over there.

If you are targeting Raspi then you can consider using the frame-buffer Micropython driver.
The Linux kernel supports many displays with the Frame Buffer API so this could be a good “generic” solution for many displays.

Yes, I would like to use the display primarily for the ESP32 (in my case WROVER with 8MB PSRAM).

I suppose we can basically expand the (ili9XXX.py based on the comparison between the ili9488 and the ST7796?

Yes.

On this family of displays the interface (SPI) and commands are very similar, and most of the differences are the initialization sequence and the color mode.
Here is the ILI9488 specific initialization.

So all you need to do is derive a new subclass from ili9XXX, set self.init_cmds, self.display_name and self.display_type and call the parent constructor.

If you use the 16-bit/pixel color mode (RGB=(565) 65K colors) then you can probably set display_type to DISPLAY_TYPE_ILI9341 since ILI9341 also uses the same 16 bit color mode. (ILI9488 currently uses 24-bit color mode (RGB=(888) 16.7M colors) )

Were there any development efforts on this? Just got a lv_micropython build going and was wondering if any progress has been made before I take a deeper look into it.

Hi @MrTimcakes!

Not that I’m aware of.

For ESP32 the starting point is ili9XXX.py.
For generic driver (slower, but should work on other platforms) see st77xx.py.

In the future we hope that Micropython code would also be able to use native LVGL drivers from lv_drivers, but this is a long-term goal that might take some time.

Feel free to open a PR on lv_binding_micropython!

Cheers, yeah I’d looked at the ST77XX generic driver and made some sym links to include them for an ESP32 build. But I didn’t get anywhere that evening as the generic driver supports the ST7789 (240x320), but I’ve not looked at the datasheets to see how similar the initialisation procedure is to the ST7796 (320x480).

If I make any progress on it of course I’d submit a PR

st77xx author here. In my experience the easiest was to look at a few existing drivers which have the initialization sorted out already (e.g. here which is exceptionally cleanly written — don’t know about functionality, did not test), then write it using (new) symbolic constants where it makes sense (e.g. here, checking against the datasheet along the way. Later, you might add things like hardware display orientation (that particular driver has it here). You can use the test st77xx-test.py script (as described here). The last (easy, with st77xx), is to use the driver with LVGL. Good luck.