Skip to content

Commit a6fffea

Browse files
committed
fix(tests): fix testdisplay, add hwdisplay example
1 parent 12955be commit a6fffea

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

tests/hwdisplay.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import lvgl as lv
2+
import pyb
3+
4+
5+
class HwDisplayDriver:
6+
def __init__(self, width=240, height=320, color_format=lv.COLOR_FORMAT.RGB565):
7+
self.width = width
8+
self.height = height
9+
self.color_depth = lv.color_format_get_bpp(color_format)
10+
self.color_size = lv.color_format_get_size(color_format)
11+
self._debug = False
12+
13+
@property
14+
def debug(self):
15+
return self._debug
16+
17+
@debug.setter
18+
def debug(self, x):
19+
self._debug = x
20+
21+
def blit(self, x1, y1, w, h, buff):
22+
pyb.LED((y1 % 4) + 1).toggle()
23+
...
24+
25+
26+
display = HwDisplayDriver()

tests/testdisplay.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,15 @@ def blit(self, x1, y1, w, h, buff):
213213
tdisp = DummyDisplay(color_format=lv.COLOR_FORMAT.RGB888)
214214

215215

216-
alloc_buffer = lambda buffersize: memoryview(bytearray(buffer_size))
216+
# alloc_buffer = lambda buffersize: memoryview(bytearray(buffer_size))
217217

218-
factor = 10 ### Must be 1 if using an RGBBus
219-
double_buf = True ### Must be False if using an RGBBus
218+
# factor = 10 ### Must be 1 if using an RGBBus
219+
# double_buf = True ### Must be False if using an RGBBus
220220

221-
buffer_size = tdisp.width * tdisp.height * (tdisp.color_depth // 8) // factor
221+
# buffer_size = tdisp.width * tdisp.height * (tdisp.color_depth // 8) // factor
222222

223-
fbuf1 = alloc_buffer(buffer_size)
224-
fbuf2 = alloc_buffer(buffer_size) if double_buf else None
223+
# fbuf1 = alloc_buffer(buffer_size)
224+
# fbuf2 = alloc_buffer(buffer_size) if double_buf else None
225225

226226

227227
def get_display(
@@ -241,7 +241,22 @@ def get_display(
241241
except Exception as e:
242242
if sys.platform not in ["darwin", "linux"]:
243243
sys.print_exception(e)
244-
if hasattr(disp, "width") and hasattr(disp, "height"):
245-
disp.width = width
246-
disp.height = height
244+
assert hasattr(disp, "width") is True, "expected width attribute in display driver"
245+
assert (
246+
hasattr(disp, "height") is True
247+
), "expected height attribute in display driver"
248+
249+
assert (
250+
hasattr(disp, "color_depth") is True
251+
), "expected color_depth attribute in display driver"
252+
253+
alloc_buffer = lambda buffersize: memoryview(bytearray(buffer_size))
254+
255+
factor = 10 ### Must be 1 if using an RGBBus
256+
double_buf = True ### Must be False if using an RGBBus
257+
258+
buffer_size = disp.width * disp.height * (disp.color_depth // 8) // factor
259+
260+
fbuf1 = alloc_buffer(buffer_size)
261+
fbuf2 = alloc_buffer(buffer_size) if double_buf else None
247262
return TestDisplayDriver(disp, fbuf1, fbuf2, color_format, mode, pointer)

0 commit comments

Comments
 (0)