-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbmp7735a.py
44 lines (43 loc) · 1.65 KB
/
bmp7735a.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from ST7735 import TFT,TFTColor
from machine import SPI,Pin
#spi = SPI(2, baudrate=20000000, polarity=0, phase=0, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
#hardware SPI, HSPI
spi = SPI(1, baudrate=8000000, polarity=0, phase=0)
# dc, rst, cs
# tft=TFT(spi,2,16,0)
tft=TFT(spi,16)
tft.init_7735(tft.GREENTAB80x160)
tft.rotation(1)
tft.fill(TFT.BLACK)
f=open('girl128x160.bmp', 'rb')
if f.read(2) == b'BM': #header
dummy = f.read(8) #file size(4), creator bytes(4)
offset = int.from_bytes(f.read(4), 'little')
hdrsize = int.from_bytes(f.read(4), 'little')
width = int.from_bytes(f.read(4), 'little')
height = int.from_bytes(f.read(4), 'little')
if int.from_bytes(f.read(2), 'little') == 1: #planes must be 1
depth = int.from_bytes(f.read(2), 'little')
if depth == 24 and int.from_bytes(f.read(4), 'little') == 0:#compress method == uncompressed
print("Image size:", width, "x", height)
rowsize = (width * 3 + 3) & ~3
if height < 0:
height = -height
flip = False
else:
flip = True
w, h = width, height
if w > 128: w = 128
if h > 160: h = 160
tft._setwindowloc((0,0),(w - 1,h - 1))
for row in range(h):
if flip:
pos = offset + (height - 1 - row) * rowsize
else:
pos = offset + row * rowsize
if f.tell() != pos:
dummy = f.seek(pos)
for col in range(w):
bgr = f.read(3)
tft._pushcolor(TFTColor(bgr[2],bgr[1],bgr[0]))
spi.deinit()