|
| 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) |
0 commit comments