Skip to content

Does lvgl_micropython support ESP32P4? #591

Description

@lifedebug

I used the following command to build the ESP32P4 firmware:
'python3 make.py esp32 clean --flash-size=16 BOARD=ESP32_GENERIC_P4'

Then, through Thonny, the "st7796" folder was created, and the files "init.py", "_st7796_init.py", and "st7796.py" were uploaded to this folder.
init.py

import sys
from . import st7796
from . import _st7796_init

sys.modules['_st7796_init'] = _st7796_init


__all__ = [
    'ST7796',
    'STATE_HIGH',
    'STATE_LOW',
    'STATE_PWM',
    'BYTE_ORDER_RGB',
    'BYTE_ORDER_BGR',
]


ST7796 = st7796.ST7796
STATE_HIGH = st7796.STATE_HIGH
STATE_LOW = st7796.STATE_LOW
STATE_PWM = st7796.STATE_PWM
BYTE_ORDER_RGB = st7796.BYTE_ORDER_RGB
BYTE_ORDER_BGR = st7796.BYTE_ORDER_BGR

_st7796_init.py

# Copyright (c) 2024 - 2025 Kevin G. Schlosser

import time
from micropython import const  # NOQA

import lvgl as lv  # NOQA

_SWRESET = const(0x01)
_SLPOUT = const(0x11)
_CSCON = const(0xF0)
_MADCTL = const(0x36)
_COLMOD = const(0x3A)
_DIC = const(0xB4)
_DFC = const(0xB6)
_DOCA = const(0xE8)
_PWR2 = const(0xC1)
_PWR3 = const(0xC2)
_VCMPCTL = const(0xC5)
_PGC = const(0xE0)
_NGC = const(0xE1)
_DISPON = const(0x29)

_EM = const(0xB7)


def init(self):
    param_buf = bytearray(14)
    param_mv = memoryview(param_buf)

    self.set_params(_SWRESET)

    time.sleep_ms(120)  # NOQA

    self.set_params(_SLPOUT)

    time.sleep_ms(120)  # NOQA

    param_buf[0] = 0xC3
    self.set_params(_CSCON, param_mv[:1])

    param_buf[0] = 0x96
    self.set_params(_CSCON, param_mv[:1])

    param_buf[0] = (
        self._madctl(
            self._color_byte_order,
            self._ORIENTATION_TABLE  # NOQA
        )
    )
    self.set_params(_MADCTL, param_mv[:1])

    color_size = lv.color_format_get_size(self._color_space)
    if color_size == 2:  # NOQA
        pixel_format = 0x05
    elif color_size == 3:
        pixel_format = 0x07
    else:
        raise RuntimeError(
            'ST7796 IC only supports '
            'lv.COLOR_FORMAT.RGB565 or lv.COLOR_FORMAT.RGB888'
        )

    param_buf[0] = pixel_format
    self.set_params(_COLMOD, param_mv[:1])

    param_buf[0] = 0xC6
    self.set_params(_EM, param_mv[:1])

    param_buf[0] = 0x01
    self.set_params(_DIC, param_mv[:1])

    param_buf[0] = 0x80
    param_buf[1] = 0x02
    param_buf[2] = 0x3B
    self.set_params(_DFC, param_mv[:3])

    param_buf[:8] = bytearray(
        [
            0x40, 0x8A, 0x00, 0x00, 0x29, 0x19, 0xA5, 0x33
        ]
    )
    self._data_bus.tx_param(_DOCA, param_mv[:8])

    param_buf[0] = 0x06
    self.set_params(_PWR2, param_mv[:1])

    param_buf[0] = 0xA7
    self.set_params(_PWR3, param_mv[:1])

    param_buf[0] = 0x18
    self.set_params(_VCMPCTL, param_mv[:1])

    time.sleep_ms(120)  # NOQA

    param_buf[:14] = bytearray(
        [
            0xF0, 0x09, 0x0b, 0x06, 0x04, 0x15, 0x2F,
            0x54, 0x42, 0x3C, 0x17, 0x14, 0x18, 0x1B
        ]
    )
    self.set_params(_PGC, param_mv[:14])

    param_buf[:14] = bytearray(
        [
            0xF0, 0x09, 0x0B, 0x06, 0x04, 0x03, 0x2D,
            0x43, 0x42, 0x3B, 0x16, 0x14, 0x17, 0x1B
        ]
    )
    self.set_params(_NGC, param_mv[:14])

    time.sleep_ms(120)  # NOQA

    param_buf[0] = 0x3C
    self.set_params(_CSCON, param_mv[:1])

    param_buf[0] = 0x69
    self.set_params(_CSCON, param_mv[:1])

    time.sleep_ms(120)  # NOQA

    self.set_params(_DISPON)

    time.sleep_ms(120)  # NOQA

st7796.py

# Copyright (c) 2024 - 2025 Kevin G. Schlosser

from micropython import const  # NOQA
import display_driver_framework


STATE_HIGH = display_driver_framework.STATE_HIGH
STATE_LOW = display_driver_framework.STATE_LOW
STATE_PWM = display_driver_framework.STATE_PWM

BYTE_ORDER_RGB = display_driver_framework.BYTE_ORDER_RGB
BYTE_ORDER_BGR = display_driver_framework.BYTE_ORDER_BGR

_MADCTL_MV = const(0x20)
_MADCTL_MX = const(0x40)
_MADCTL_MY = const(0x80)


class ST7796(display_driver_framework.DisplayDriver):

    _ORIENTATION_TABLE = (
        _MADCTL_MX,
        _MADCTL_MV | _MADCTL_MY | _MADCTL_MX,
        _MADCTL_MY,
        _MADCTL_MV
    )

Then the main.py file was created and the program was written into it:

import  st7796
import lcd_bus
import lvgl as lv
import time
from micropython import const
import machine
from machine import Pin
#import pointer_framework
import i2c
# Display settings
_WIDTH = const(320)
_HEIGHT = const(480)

# Common SPI bus settings
_SPI_HOST = const(2)
_MOSI_PIN = const(30)
_MISO_PIN = const(31)
_SCLK_PIN = const(32)

# Display SPI bus settings
_LCD_SPI_FREQ = const(20_000_000)
_LCD_CS_PIN = const(28)
# display additional pins
_LCD_RST_PIN = const(12)
_LCD_DC_PIN = const(13)
_LCD_BKL_PIN = const(20)

spi_bus = machine.SPI.Bus(
    host=_SPI_HOST,
    miso=_MISO_PIN,
    mosi=_MOSI_PIN,
    sck=_SCLK_PIN,
)

display_bus = lcd_bus.SPIBus(
    spi_bus=spi_bus,
    freq=_LCD_SPI_FREQ,
    dc=_LCD_DC_PIN,
    cs=_LCD_CS_PIN
)

_BUFFER_SIZE = const(_WIDTH * _HEIGHT * 2 // 4 )
#fb1 = display_bus.allocate_framebuffer(_BUFFER_SIZE, lcd_bus.MEMORY_SPIRAM | lcd_bus.MEMORY_DMA)
#fb2 = display_bus.allocate_framebuffer(_BUFFER_SIZE, lcd_bus.MEMORY_SPIRAM | lcd_bus.MEMORY_DMA)

#fb1 = display_bus.allocate_framebuffer(_BUFFER_SIZE, lcd_bus.MEMORY_INTERNAL | lcd_bus.MEMORY_DMA)
#fb2 = display_bus.allocate_framebuffer(_BUFFER_SIZE, lcd_bus.MEMORY_INTERNAL | lcd_bus.MEMORY_DMA)


display = st7796.ST7796(
    data_bus=display_bus,
    #frame_buffer1=fb1,
    #frame_buffer2=fb2,
    display_width=_WIDTH,
    display_height=_HEIGHT,
    color_space=lv.COLOR_FORMAT.RGB888,
    color_byte_order=st7796.BYTE_ORDER_BGR,
    rgb565_byte_swap=True,

    backlight_pin=_LCD_BKL_PIN,
    backlight_on_state=st7796.STATE_PWM,

    reset_pin=_LCD_RST_PIN,
    reset_state=st7796.STATE_LOW,

)

However, the following error was encountered during runtime:
'Traceback (most recent call last):
File "main.py", line 64, in
File "display_driver_framework.py", line 231, in init
File "display_driver_framework.py", line 243, in _init_bus'
ValueError: SPI(2) invalid configuration

Could you please help me identify where my mistake is, or is it that the lvgl_micropython currently doesn't have sufficient support for the ESP32P4?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions