10000 add ili9341 test program; hard-code the only supported resolution · shankezh/lv_binding_micropython@591e390 · GitHub
[go: up one dir, main page]

Skip to content

Commit 591e390

Browse files
committed
add ili9341 test program; hard-code the only supported resolution
1 parent 2713076 commit 591e390

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

driver/generic/ili9xxx-test.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from machine import SPI, Pin
2+
3+
from ili9xxx import Ili9341_hw
4+
5+
6+
def build_rect_buf(w, h, inner=[0x00, 0x00]):
7+
top = b"\xFF\xFF" * w
8+
body = (b"\xFF\xFF\xFF" + bytes(inner) * (w - 3) + b"\xFF\xFF\xFF") * (h - 3)
9+
bot = b"\xFF\xFF" * w
10+
return top + body + bot
11+
12+
13+
spi = SPI(
14+
0,
15+
baudrate=24_000_000,
16+
sck=Pin(18),
17+
mosi=Pin(19),
18+
miso=Pin(16),
19+
)
20+
lcd = Ili9341_hw(spi=spi, cs=17, dc=15, rst=14)
21+
22+
lcd.set_backlight(30)
23+
for rot in (0, 1, 2, 3):
24+
lcd.apply_rotation(rot)
25+
26+
lcd.clear(0x0000)
27+
# 1/4 screen pixels square with white border red backgorund
28+
w, h = lcd.width // 4, lcd.height // 8
29+
bmp = build_rect_buf(w, h, [0x03, 0x03])
30+
t0 = time.ticks_us()
31+
lcd.blit(w, h, w, h, bmp)
32+
t1 = time.ticks_us()
33+
bmp = build_rect_buf(lcd.width, lcd.height // 20, [0x09, 0x09])
34+
lcd.blit(0, 0, lcd.width, lcd.height // 20, bmp)
35+
36+
print("Maximum FPS @24MHz:", 24e6 / (320 * 240 * 16)) # FPS = F/(W*H*BPP)
37+
print(
38+
"Achieved FPS:", 1 / (16 * (t1 - t0) * 1e-6)
39+
) # Note: Test only draws 1/16 of the sreen area
40+
41+
print("Draw TSC calibration pattern")
42+
w, h, wu, hu = lcd.width // 10, lcd.height // 10, lcd.width // 5, lcd.height // 5
43+
bmp = build_rect_buf(w, h, [0xA0, 0xF0])
44+
lcd.blit(wu, hu, w, h, bmp)
45+
lcd.blit(4 * wu, hu, w, h, bmp)
46+
lcd.blit(4 * wu, 4 * hu, w, h, bmp)
47+
lcd.blit(wu, 4 * hu, w, h, bmp)
48+
time.sleep(0.5)

driver/generic/ili9xxx.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Usage information.
1010
"""
1111
from micropython import const
12+
1213
from st77xx import St77xx_hw, St77xx_lvgl
1314

1415
# Command constants from ILI9341 datasheet
@@ -93,13 +94,13 @@
9394

9495

9596
class Ili9341_hw(St77xx_hw):
96-
def __init__(self, res, **kw):
97+
def __init__(self, **kw):
9798
"""ILI9341 TFT Display Driver.
9899
99100
Requires ``LV_COLOR_DEPTH=16`` when building lv_micropython to function.
100101
"""
101102
super().__init__(
102-
res=res,
103+
res=(240, 320),
103104
suppRes=[
104105
(240, 320),
105106
],
@@ -156,11 +157,11 @@ def apply_rotation(self, rot):
156157

157158

158159
class Ili9341(Ili9341_hw, St77xx_lvgl):
159-
def __init__(self, res, doublebuffer=True, factor=4, **kw):
160+
def __init__(self, doublebuffer=True, factor=4, **kw):
160161
"""See :obj:`Ili9341_hw` for the meaning of the parameters."""
161162
import lvgl as lv
162163

163-
Ili9341_hw.__init__(self, res=res, **kw)
164+
Ili9341_hw.__init__(self, **kw)
164165
St77xx_lvgl.__init__(self, doublebuffer, factor)
165166
self.disp_drv.color_format = lv.COLOR_FORMAT.NATIVE_REVERSE
166167
self.disp_drv.register()

0 commit comments

Comments
 (0)
0