1try:
2    import framebuf, usys
3except ImportError:
4    print("SKIP")
5    raise SystemExit
6
7# This test and its .exp file is based on a little-endian architecture.
8if usys.byteorder != "little":
9    print("SKIP")
10    raise SystemExit
11
12
13def printbuf():
14    print("--8<--")
15    for y in range(h):
16        print(buf[y * w * 2 : (y + 1) * w * 2])
17    print("-->8--")
18
19
20w = 4
21h = 5
22buf = bytearray(w * h * 2)
23fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.RGB565)
24
25# fill
26fbuf.fill(0xFFFF)
27printbuf()
28fbuf.fill(0x0000)
29printbuf()
30
31# put pixel
32fbuf.pixel(0, 0, 0xEEEE)
33fbuf.pixel(3, 0, 0xEE00)
34fbuf.pixel(0, 4, 0x00EE)
35fbuf.pixel(3, 4, 0x0EE0)
36printbuf()
37
38# get pixel
39print(fbuf.pixel(0, 4), fbuf.pixel(1, 1))
40
41# scroll
42fbuf.fill(0x0000)
43fbuf.pixel(2, 2, 0xFFFF)
44printbuf()
45fbuf.scroll(0, 1)
46printbuf()
47fbuf.scroll(1, 0)
48printbuf()
49fbuf.scroll(-1, -2)
50printbuf()
51
52w2 = 2
53h2 = 3
54buf2 = bytearray(w2 * h2 * 2)
55fbuf2 = framebuf.FrameBuffer(buf2, w2, h2, framebuf.RGB565)
56
57fbuf2.fill(0x0000)
58fbuf2.pixel(0, 0, 0x0EE0)
59fbuf2.pixel(0, 2, 0xEE00)
60fbuf2.pixel(1, 0, 0x00EE)
61fbuf2.pixel(1, 2, 0xE00E)
62fbuf.fill(0xFFFF)
63fbuf.blit(fbuf2, 3, 3, 0x0000)
64fbuf.blit(fbuf2, -1, -1, 0x0000)
65fbuf.blit(fbuf2, 16, 16, 0x0000)
66printbuf()
67