Skip to content

Instantly share code, notes, and snippets.

@elpekenin
Last active December 14, 2022 19:34
Show Gist options
  • Save elpekenin/acb334807dd82f7368233eed3e7477eb to your computer and use it in GitHub Desktop.
Save elpekenin/acb334807dd82f7368233eed3e7477eb to your computer and use it in GitHub Desktop.
from machine import Pin, SPI
import time
WIDTH = const(264)
HEIGHT = const(176)
cs = Pin(18, Pin.OUT)
dc = Pin(6, Pin.OUT)
rst = Pin(0, Pin.OUT)
spi = SPI(
0,
sck=Pin(2),
mosi=Pin(3),
miso=Pin(4),
)
def write_cmd(cmd):
cs.off()
dc.off()
spi.write(bytes([cmd]))
cs.on()
def write_data(*data):
cs.off()
dc.on()
spi.write(bytes(list(data)))
cs.on()
# HW reset
rst.on()
time.sleep_ms(10)
rst.off()
time.sleep_ms(10)
rst.on()
time.sleep_ms(10)
# Power on
write_cmd(4)
time.sleep_ms(255)
# Panel config
write_cmd(0)
write_data(0xAF)
# PLL
write_cmd(0x30)
write_data(0x3A)
# Power setting
write_cmd(1)
write_data(3, 0, 0x2B, 0x2B, 9)
# Booster soft start
write_cmd(6)
write_data(7, 7, 0x17)
# Mistery command
write_cmd(0xF8)
write_data(0x60, 0xA5)
write_cmd(0xF8)
write_data(0x89, 0xA5)
write_cmd(0xF8)
write_data(0x90, 0)
write_cmd(0xF8)
write_data(0x93, 0xA2)
write_cmd(0xF8)
write_data(0x73, 0x41)
# VCM DC
write_cmd(0x82)
write_data(0x12)
# CDI setting
write_cmd(0x50)
write_data(0x87)
# LUT1
write_cmd(0x20)
write_data(0, 0, 0, 26, 26, 0, 0, 1, 0, 10, 10, 0, 0, 8, 0, 14, 1, 14, 1, 16, 0, 10, 10, 0, 0, 8, 0, 4, 16, 0, 0, 5, 0, 3, 14, 0, 0, 10, 0, 35, 0, 0, 0, 1)
# LUTWW
write_cmd(0x21)
write_data(144, 26, 26, 0, 0, 1, 64, 10, 10, 0, 0, 8, 132, 14, 1, 14, 1, 16, 128, 10, 10, 0, 0, 8, 0, 4, 16, 0, 0, 5, 0, 3, 14, 0, 0, 10, 0, 35, 0, 0, 0, 1)
# LUTBW
write_cmd(0x22)
write_data(160, 26, 26, 0, 0, 1, 0, 10, 10, 0, 0, 8, 132, 14, 1, 14, 1, 16, 144, 10, 10, 0, 0, 8, 176, 4, 16, 0, 0, 5, 176, 3, 14, 0, 0, 10, 192, 35, 0, 0, 0, 1)
# LUTWB
write_cmd(0x23)
write_data(144, 26, 26, 0, 0, 1, 64, 10, 10, 0, 0, 8, 132, 14, 1, 14, 1, 16, 128, 10, 10, 0, 0, 8, 0, 4, 16, 0, 0, 5, 0, 3, 14, 0, 0, 10, 0, 35, 0, 0, 0, 1)
#LUTBB
write_cmd(0x24)
write_data(144, 26, 26, 0, 0, 1, 32, 10, 10, 0, 0, 8, 132, 14, 1, 14, 1, 16, 16, 10, 10, 0, 0, 8, 0, 4, 16, 0, 0, 5, 0, 3, 14, 0, 0, 10, 0, 35, 0, 0, 0, 1)
# Resolution
write_cmd(0x61)
write_data((WIDTH >> 8) & 0xFF, WIDTH & 0xFF, (HEIGHT >> 8) & 0xFF, HEIGHT & 0xFF)
print("Init done")
# PDRF
write_cmd(0x16)
write_data(0)
print("sending BW data")
write_cmd(0x10)
for _ in range(WIDTH * HEIGHT/8):
write_data(0)
print("Sending RED data")
write_cmd(0x13)
for _ in range(WIDTH * HEIGHT/8):
write_data(0xFF)
# Refresh
write_cmd(0x12)
# Power off
write_cmd(2)
write_data(0x17)
print("Program finished!!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment