Minor changes to st7735r driver and setup.

ili9341
Peter Hinch 2020-11-26 18:26:18 +00:00
rodzic f4d5cef529
commit 4208d8f54b
2 zmienionych plików z 21 dodań i 18 usunięć

Wyświetl plik

@ -13,13 +13,16 @@
# WIRING (Adafruit pin nos and names).
# Pyb SSD
# 3v3 Vin (10)
# Gnd Gnd (11)
# Y1 DC (3 DC)
# Y2 CS (5 OC OLEDCS)
# Y3 Rst (4 R RESET)
# Y6 CLK (2 CL SCK)
# Y8 DATA (1 SI MOSI)
# Gnd Gnd (1)
# Vin VCC (2) 5V
# Y3 RESET (3)
# Y1 D/C (4)
# CARD_CS (5) No connection (for SD card)
# Y2 TFT_CS (6)
# Y8 MOSI (7)
# Y6 SCK (8)
# Y7 MISO (9) Optional - (for SD card)
# Vin LITE (10) Backlight
import machine
import gc
@ -34,4 +37,4 @@ pcs = machine.Pin('Y2', machine.Pin.OUT_PP, value=1)
prst = machine.Pin('Y3', machine.Pin.OUT_PP, value=1)
spi = machine.SPI(2, baudrate=12_000_000)
gc.collect() # Precaution before instantiating framebuf
ssd = SSD(spi, pcs, pdc, prst) # Create a display instance
ssd = SSD(spi, pcs, pdc, prst, height, width) # Create a display instance

Wyświetl plik

@ -48,20 +48,20 @@ class ST7735R(framebuf.FrameBuffer):
return (r & 0xe0) | ((g >> 3) & 0x1c) | (b >> 6)
# rst and cs are active low, SPI is mode 0
def __init__(self, spi, cs, dc, rst):
def __init__(self, spi, cs, dc, rst, height, width):
self._spi = spi
self._rst = rst # Pins
self._dc = dc
self._cs = cs
self.height = 128 # Required by Writer class
self.width = 160
self.height = height # Required by Writer class
self.width = width
# Save color mode for use by writer_gui (blit)
self.mode = framebuf.GS8 # Use 8bit greyscale for 8 bit color.
gc.collect()
self.buffer = bytearray(128 * 160)
self.buffer = bytearray(height * width)
self._mvb = memoryview(self.buffer)
super().__init__(self.buffer, 160, 128, self.mode)
self._linebuf = bytearray(int(160 * 3 // 2)) # 12 bit color out
super().__init__(self.buffer, width, height, self.mode)
self._linebuf = bytearray(int(width * 3 // 2)) # 12 bit color out
self._init()
self.show()
@ -121,8 +121,8 @@ class ST7735R(framebuf.FrameBuffer):
wcd(b'\xe0', b'\x02\x1c\x07\x12\x37\x32\x29\x2d\x29\x25\x2B\x39\x00\x01\x03\x10') # GMCTRP1 Gamma
wcd(b'\xe1', b'\x03\x1d\x07\x06\x2E\x2C\x29\x2D\x2E\x2E\x37\x3F\x00\x00\x02\x10') # GMCTRN1
wcd(b'\x2a', int.to_bytes(160, 4, 'big')) # CASET column address 0 start, 160 end
wcd(b'\x2b', int.to_bytes(128, 4, 'big')) # RASET
wcd(b'\x2a', int.to_bytes(self.width, 4, 'big')) # CASET column address 0 start, 160 end
wcd(b'\x2b', int.to_bytes(self.height, 4, 'big')) # RASET
cmd(b'\x13') # NORON
sleep_ms(10)
@ -130,8 +130,8 @@ class ST7735R(framebuf.FrameBuffer):
sleep_ms(100)
def show(self): # Blocks 36ms on Pyboard D at stock frequency (160*128)
wd = 160
ht = 128
wd = self.width
ht = self.height
lb = self._linebuf
buf = self._mvb
self._dc(0)