How to add a library and a display driver to lv_micropython

Hi everyone,


Currently, I am working with LittlevGL with Micropython. As I tried to did some research on the lv_micropython repo from Github, my display module is not supported. Therefore, I had to write my own display driver in C and ran it with STM32CubeIDE. After a long time of failing, our team could run lvgl objects like buttons on the screen. the driver we wrote mostly based on Discovery library.

What MCU/Processor/Board and compiler are you using?

STM32L4R9I Discovery

What do you want to achieve?

I want to add the display driver we wrote into lv_micropython. And also, because the driver based on Discovery library, I also need to add that library to lv_micropython too.

What have you tried so far?

I don’t know where to start.

The driver is here:

Tagging @amirgon on this conversation.

First step - try to build lv_micropython with your driver.

lv_micropython now supports stm32, see this PR:

Add the relevant files (your display.c file as well as the necessary BSP files) to the stm32 makefile and try to build and deploy it.

Another option, if you don’t want to change stm32 Makefile, is to add your code an en extenral module as explained here:

You should be able to get the micropython prompt (through UART).
Try to import lvstm32 and lvgl.

Next step, if everything builds and works fine, you need a way to call your driver functions from Micropython. This is done by creating a micropython module that wraps your display driver.

From your code it looks like your driver gets no parameters. How do you configure it? set its IO pins etc? In Micropython all these are usually set on runtime.
Once you decide how your module should look like (which parameters it should receive), please have a look at That’s a guide that explains how to add micropython user module and how to build it.

My suggestion is to have an init function which receives the parameters to configure your driver, and a deinit function to remove the driver.
You can call lv_disp_drv_register in your init function (like you do in your display.c), but another option is to call lv.disp_drv_register in micropython and let the driver provide a pointer to flush_cb, like is done on ili9341 driver on ESP32.

Hi @embeddedt,

Thank you for tagging @amirgon into this conversation.

Hi @amirgon,

Thank you for your detail response in this thread. I will carefully read it and initiate your instruction.
I am a bit concern about what i wrote (the display.c). As I read some already-supported display driver in lv_micropython/lib/lv_bindings/driver/esp32 (from lv_micropython Github repository: I saw quite a different style of C file than what i wrote. So Was what i did so far in correct path and if so, What you instructed me would allow me to change from display.c to what i read in the link above?

Thank you, Huy.