Skip to content

Commit

Permalink
Update LVGL and fix pixel size detection
Browse files Browse the repository at this point in the history
  • Loading branch information
PGNetHun committed Nov 29, 2023
1 parent 7e0adef commit 1d038ad
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 52 deletions.
64 changes: 32 additions & 32 deletions README.md

Large diffs are not rendered by default.

28 changes: 16 additions & 12 deletions driver/esp32/ili9XXX.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
##############################################################################
# Pure/Hybrid micropython lvgl display driver for ili9341 and ili9488 on ESP32
# Pure/Hybrid micropython lvgl display driver for
# ili9341, ili9488, ili9488g, gc9a01, st7789 on ESP32
#
# For ili9341 display:
#
Expand Down Expand Up @@ -64,6 +65,8 @@
import micropython
import gc

from micropython import const

micropython.alloc_emergency_exception_buf(256)
# gc.threshold(0x10000) # leave enough room for SPI master TX DMA buffers

Expand Down Expand Up @@ -94,9 +97,10 @@
DISPLAY_TYPE_ST7789 = const(4)
DISPLAY_TYPE_ST7735 = const(5)

_TRANS_BUFFER_LEN = const(16)

class ili9XXX:

TRANS_BUFFER_LEN = const(16)
display_name = 'ili9XXX'
init_cmds = [ ]

Expand Down Expand Up @@ -238,7 +242,7 @@ def disp_spi_init(self):
ret = esp.spi_bus_initialize(self.spihost, buscfg, 1)
if ret != 0: raise RuntimeError("Failed initializing SPI bus")

self.trans_buffer = esp.heap_caps_malloc(TRANS_BUFFER_LEN, esp.MALLOC_CAP.DMA)
self.trans_buffer = esp.heap_caps_malloc(_TRANS_BUFFER_LEN, esp.MALLOC_CAP.DMA)
self.cmd_trans_data = self.trans_buffer.__dereference__(1)
self.word_trans_data = self.trans_buffer.__dereference__(4)

Expand Down Expand Up @@ -353,7 +357,7 @@ def send_cmd(self, cmd):

def send_data(self, data):
esp.gpio_set_level(self.dc, 1) # Data mode
if len(data) > TRANS_BUFFER_LEN: raise RuntimeError('Data too long, please use DMA!')
if len(data) > _TRANS_BUFFER_LEN: raise RuntimeError('Data too long, please use DMA!')
trans_data = self.trans_buffer.__dereference__(len(data))
trans_data[:] = data[:]
self.spi_send(trans_data)
Expand Down Expand Up @@ -482,7 +486,7 @@ def flush(self, disp_drv, area, color_p):
self.send_cmd(0x2C)

size = (x2 - x1 + 1) * (y2 - y1 + 1)
data_view = color_p.__dereference__(size * lv.color_t.__SIZE__)
data_view = color_p.__dereference__(size * lv.COLOR_DEPTH // 8)

esp.get_ccount(self.end_time_ptr)
if self.end_time_ptr.int_val > self.start_time_ptr.int_val:
Expand Down Expand Up @@ -547,7 +551,7 @@ def __init__(self,

# Make sure Micropython was built such that color won't require processing before DMA

if lv.color_t.__SIZE__ != 2:
if lv.COLOR_DEPTH != 16:
raise RuntimeError('ili9341 micropython driver requires defining LV_COLOR_DEPTH=16')

self.display_name = 'ILI9341'
Expand Down Expand Up @@ -597,7 +601,7 @@ def __init__(self,
color_format=None, display_type=DISPLAY_TYPE_ILI9488, p16=False
):

if (lv.color_t.__SIZE__ != 4) and not p16:
if (lv.COLOR_DEPTH != 32) and not p16:
raise RuntimeError('ili9488 micropython driver requires defining LV_COLOR_DEPTH=32')
if not hybrid:
raise RuntimeError('ili9488 micropython driver do not support non-hybrid driver')
Expand Down Expand Up @@ -648,13 +652,13 @@ def __init__(self,
rot=PORTRAIT, invert=False, double_buffer=True, half_duplex=True, asynchronous=False, initialize=True
):

if lv.color_t.__SIZE__ == 4:
if lv.COLOR_DEPTH == 32:
colormode=COLOR_MODE_RGB
color_format=None
display_type=DISPLAY_TYPE_ILI9488 # 24-bit pixel handling
p16=False

if lv.color_t.__SIZE__ == 2:
if lv.COLOR_DEPTH == 16:
colormode=COLOR_MODE_BGR
color_format=lv.COLOR_FORMAT.NATIVE_REVERSE
display_type=DISPLAY_TYPE_ILI9341 # Force use of 16-bit pixel handling
Expand All @@ -677,7 +681,7 @@ def __init__(self,
color_format=None
):

if lv.color_t.__SIZE__ != 2:
if lv.COLOR_DEPTH != 16:
raise RuntimeError('gc9a01 micropython driver requires defining LV_COLOR_DEPTH=16')

# This is included as the color mode appears to be reversed from the
Expand Down Expand Up @@ -766,7 +770,7 @@ def __init__(self,

# Make sure Micropython was built such that color won't require processing before DMA

if lv.color_t.__SIZE__ != 2:
if lv.COLOR_DEPTH != 16:
raise RuntimeError('st7789 micropython driver requires defining LV_COLOR_DEPTH=16')

self.display_name = 'ST7789'
Expand Down Expand Up @@ -818,7 +822,7 @@ def __init__(self,

# Make sure Micropython was built such that color won't require processing before DMA

if lv.color_t.__SIZE__ != 2:
if lv.COLOR_DEPTH != 16:
raise RuntimeError('st7735 micropython driver requires defining LV_COLOR_DEPTH=16')

self.display_name = 'ST7735'
Expand Down
2 changes: 1 addition & 1 deletion driver/generic/st77xx.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def __init__(self,doublebuffer=True,factor=4):

if lv.COLOR_DEPTH!=16: raise RuntimeError(f'LVGL *must* be compiled with LV_COLOR_DEPTH=16 (currently LV_COLOR_DEPTH={lv.COLOR_DEPTH}.')

bufSize=(self.width*self.height*lv.color_t.__SIZE__)//factor
bufSize=(self.width * self.height * lv.COLOR_DEPTH // 8) // factor

if not lv.is_initialized(): lv.init()
# create event loop if not yet present
Expand Down
4 changes: 2 additions & 2 deletions examples/advanced_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ def init_gui_stm32(self):
lcd.init(w=hres, h=vres)
self.disp_drv = lv.display_create(hres, vres)
self.disp_drv.set_flush_cb(lcd.flush)
buf1_1 = bytearray(hres * 50 * lv.color_t.__SIZE__)
buf1_2 = bytearray(hres * 50 * lv.color_t.__SIZE__)
buf1_1 = bytearray(hres * 50 * lv.COLOR_DEPTH // 8)
buf1_2 = bytearray(hres * 50 * lv.COLOR_DEPTH // 8)
self.disp_drv.set_draw_buffers(buf1_1, buf1_2, len(buf1_1), lv.DISPLAY_RENDER_MODE.PARTIAL)

# Register touch sensor
Expand Down
2 changes: 1 addition & 1 deletion examples/example1.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class driver:
def init_gui_SDL(self):
self.event_loop = lv_utils.event_loop()
self.disp_drv = lv.sdl_window_create(480, 320)
self.indev_drv = lv.sdl_mouse_create();
self.indev_drv = lv.sdl_mouse_create()

def init_gui_esp32(self):

Expand Down
4 changes: 2 additions & 2 deletions examples/example3.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
lcd.init(w=hres, h=vres)
disp_drv = lv.disp_create(hres, vres)
disp_drv.set_flush_cb(lcd.flush)
buf1_1 = bytearray(hres * 10 * lv.color_t.__SIZE__)
buf1_2 = bytearray(hres * 10 * lv.color_t.__SIZE__)
buf1_1 = bytearray(hres * 10 * lv.COLOR_DEPTH // 8)
buf1_2 = bytearray(hres * 10 * lv.COLOR_DEPTH // 8)
disp_drv.set_draw_buffers(buf1_1, buf1_2, len(buf1_1), lv.DISP_RENDER_MODE.PARTIAL)

# disp_drv.gpu_blend_cb = lcd.gpu_blend
Expand Down
2 changes: 1 addition & 1 deletion gen/gen_mpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2104,7 +2104,7 @@ def get_arg_name(arg):
if isinstance(arg, c_ast.PtrDecl) or isinstance(arg, c_ast.FuncDecl):
return get_arg_name(arg.type)
if hasattr(arg, 'declname'): return arg.declname
if hasattr(arg, 'name'): return name
if hasattr(arg, 'name'): return arg.name
return 'unnamed_arg'

# print("// Typedefs: " + ", ".join(get_arg_name(t) for t in typedefs))
Expand Down
2 changes: 1 addition & 1 deletion lv_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

/*Color depth: 8 (A8), 16 (RGB565), 24 (RGB888), 32 (XRGB8888)*/
#ifndef LV_COLOR_DEPTH
#define LV_COLOR_DEPTH 32
#define LV_COLOR_DEPTH 16
#endif

/*=========================
Expand Down

0 comments on commit 1d038ad

Please sign in to comment.