Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented ST7789 LCD driver #5020

Merged
merged 33 commits into from
Jan 12, 2024
Merged

Implemented ST7789 LCD driver #5020

merged 33 commits into from
Jan 12, 2024

Conversation

zjanosy
Copy link
Contributor

@zjanosy zjanosy commented Dec 15, 2023

Implemented driver model for LCD controllers connected via SPI/parallel port. Implemented support for ST7789.

Copy link
Member

@kisvegabor kisvegabor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Zoltan. It looks good in general, just a few minor issue caught by the CI should be fixed.

Please run code-format.py in the scripts folder to format the code.

@@ -0,0 +1,54 @@
/*
Copy link
Member

@kisvegabor kisvegabor Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As these are specific to st7789, please move these commands in lv_st7789.c.

List only the really used commands should be enough. If someone needs to use a custom command they need to look into the datasheet anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These commands are common for various controllers, not ST7789 specific.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But not all, so we can't put it into a generic LCD file.
It seems roughly 10 commands are really used in st7789.c. I think it's okay to define them locally to avoid any conflicts later.

src/dev/display/st7789/lv_st7789.c Outdated Show resolved Hide resolved
src/dev/display/st7789/lv_st7789.c Outdated Show resolved Hide resolved
src/dev/display/st7789/lv_st7789.c Outdated Show resolved Hide resolved
src/dev/display/st7789/lv_st7789.c Outdated Show resolved Hide resolved
@lvgl-bot
Copy link

We need some feedback on this pull request.

Now we mark this as "stale" because there was no activity here for 14 days.

Remove the "stale" label or comment else this will be closed in 7 days.

@lvgl-bot lvgl-bot added the stale label Dec 30, 2023
@kisvegabor
Copy link
Member

Not stale, will be finished in January.

@lvgl-bot lvgl-bot removed the stale label Dec 31, 2023
Zoltan Janosy and others added 4 commits January 5, 2024 17:37
…trollers that use the same command set. Added drivers for ST7789, ST7796, ILI9341. Initialization command lists are based on LovyanGFX drivers. These improved the color reproduction quite much. Changed API to be able to supply additional flags for panel-dependent mirroring X and/or Y coordinates, and setting RGB order at create time.
Copy link
Member

@kisvegabor kisvegabor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the update.

Please also run scripts/code-format.py.

* INCLUDES
*********************/
#include "lv_ili9341.h"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add LV_USE_ILI9341 guard here and and also in lv_conf_template.h (scripts/lv_conf_internal_gen.py needs to run as well)

* STATIC CONSTANTS
**********************/

// init commands based on LovyanGFX
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use /**/ comemnts

* @param param parameter buffer
* @param param_size number of bytes of the parameters
*/
typedef void (*lv_ili9341_send_cmd_cb_t)(lv_display_t *disp, uint8_t *cmd, size_t cmd_size, uint8_t *param, size_t param_size);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
typedef void (*lv_ili9341_send_cmd_cb_t)(lv_display_t *disp, uint8_t *cmd, size_t cmd_size, uint8_t *param, size_t param_size);
typedef lv_ili9341_send_cmd_cb_t lv_lcd_send_cmd_cb_t;

**********************/

static const uint8_t init_cmd_list[] = {
#if 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#if 0s should be removed and only the final code should remain.
If the other options might be used by the users as well, and API functions or other direct way to adjust shall be provided.

#define LV_LCD_FLAG_RGB666 0x00000010UL

/* command list */
#define LV_LCD_CMD_SPECIAL 0xff
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it's used only as a delay:

Suggested change
#define LV_LCD_CMD_SPECIAL 0xff
#define LV_LCD_CMD_DELAY_MS 0xfe

…ror and BGR settings. Improved init commands for the available LCD drivers. Formatted code. Added LV_USE_ flags and compiler guards.
@PGNetHun
Copy link
Collaborator

PGNetHun commented Jan 9, 2024

Hello!
Thx for the drivers!
Could you please provide example / doc how to use it, how to initialize?
I see that callbacks must be given (example: send_color_cb ), but don’t know what it should be exactly, how to implement, for example on ESP32 where SPI data can be sent with DMA.
My other question is about RGB565 byte swap: ST7789 display needs that in ESP32 platform, and I don’t see where it is done.
Thx again for the display drivers, I think when this PR is merged, and MicroPython is aligned to use it, then it will further improve FPS (or less CPU usage) in MicroPython binding, and replacing the actual hybrid drivers (if it’s possible).

Copy link
Member

@kisvegabor kisvegabor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometime the code formatter needs to be tun multiple times to remove all double empty lines.

As these controllers don't contain any HW dependent parts we can enable them for the CI, so that they will be built and we will see if there are any compile time warnings,
So please enable the controllers here.

Please add docs for each controller. In an example section some dummy callbacks shall be added well.

*********************/
#include "lv_st7796.h"

#if LV_USE_ST7796
Copy link
Member

@kisvegabor kisvegabor Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add these guards to the header files as well.

@kisvegabor
Copy link
Member

@PGNetHun According to our plans after these drivers this PR will be finalized. Does it help with MicroPython somehow?

@zjanosy
Copy link
Contributor Author

zjanosy commented Jan 9, 2024

@PGNetHun

Could you please provide example / doc how to use it, how to initialize?

I will add the documentation soon.

I see that callbacks must be given (example: send_color_cb ), but don’t know what it should be exactly, how to implement, for example on ESP32 where SPI data can be sent with DMA.

I will include a sample implementation. Currently the drivers have been implemented only on STM32, but ESP32 will be added soon.

My other question is about RGB565 byte swap: ST7789 display needs that in ESP32 platform, and I don’t see where it is done.

On the STM32 platform the SPI controller can swap the bytes. I need to check how the ESP32 SPI controller handles this. We may need to do it in software.

@kisvegabor
Copy link
Member

My other question is about RGB565 byte swap: ST7789 display needs that in ESP32 platform, and I don’t see where it is done.

On the STM32 platform the SPI controller can swap the bytes. I need to check how the ESP32 SPI controller handles this. We may need to do it in software.

As it depends on the periphery if it can swap the bytes, lv_draw_sw_rgb565_swap can be called from the send_color_cb if needed.

@PGNetHun
Copy link
Collaborator

PGNetHun commented Jan 9, 2024

@PGNetHun According to our plans after these drivers this PR will be finalized. Does it help with MicroPython somehow?

Well, I'm a bit lost.
There is an another thread about (MicroPython) display drivers: https://forum.lvgl.io/t/micropython-display-drivers-part-2/14131

... so at the moment I see 3 different approaches:

  1. the current MicroPython specific drivers (including the ESP32 hybrid display driver ili9xxx.py): https://github.com/lvgl/lv_binding_micropython/tree/master/driver
  2. this PR and related ESP driver
  3. the above mentioned forum thread: https://forum.lvgl.io/t/micropython-display-drivers-part-2/14131

I prefer having C display drivers due to high performance requirement (and less C <-> MicroPython context switch during display flushes)

@zjanosy
Copy link
Contributor Author

zjanosy commented Jan 9, 2024

@PGNetHun

Well, I'm a bit lost.
There is an another thread about (MicroPython) display drivers: https://forum.lvgl.io/t/micropython-display-drivers-part-2/14131

... so at the moment I see 3 different approaches:

the current MicroPython specific drivers (including the ESP32 hybrid display driver ili9xxx.py): https://github.com/lvgl/lv_binding_micropython/tree/master/driver
this PR and related #4507
the above mentioned forum thread: https://forum.lvgl.io/t/micropython-display-drivers-part-2/14131

The ESP-LCD driver was an initial attempt to implement a unified LCD driver architecture for LVGL. However, we decided to develop the idea further, and the current PR is the result of this. The ESP-LCD driver is now obsolete, and will be replaced by an example implementation of the current driver model.
I don't know much about the MicroPython drivers, but hopefully we can move towards a common solution for all platforms. The goal is to make LVGL work out of the box with the most common LCD controllers, without the need for using 3rd party drivers.

Overview
-------------

The `ST7789 <>`__ SOC is a popular TFT LCD controller chip made by Sitronix. It supports TFT LCD panels with a maximum resolution of 240x320 pixels, and 262k (18 bit) colors.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link to the datasheet?

docs/integration/driver/display/st7789.rst Outdated Show resolved Hide resolved
docs/integration/driver/display/st7789.rst Show resolved Hide resolved
docs/integration/driver/display/st7789.rst Outdated Show resolved Hide resolved
Copy link
Member

@kisvegabor kisvegabor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updated docs looks good!

/*********************
* INCLUDES
*********************/
#include "lv_st7735.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs is still missing for this one.

@kisvegabor
Copy link
Member

Please enable these controllers for tests, so they can be built by the CI.

Copy link
Member

@kisvegabor kisvegabor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you.
If anything comes up probably we can extend these without API braking the API.

@kisvegabor kisvegabor merged commit a61e51f into lvgl:master Jan 12, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants