Skip to content

Instantly share code, notes, and snippets.

@craigjb
Last active July 3, 2023 21:07
Show Gist options
  • Save craigjb/da1bc4200f0378a886a6b4987837551c to your computer and use it in GitHub Desktop.
Save craigjb/da1bc4200f0378a886a6b4987837551c to your computer and use it in GitHub Desktop.
Initialization for 128x128 0.85" LCD with GC9107
# Example init and basic routines for 0.85" 128x128 pixel LCD
# Sold under Wisevision N085-1212TBWIG41-H12
#
# Unnecessary init commands have been stripped out versus other
# routines I found online
def write_cmd(cmd):
set_dc_pin_low()
spi_transmit(cmd)
def write_cmd_data(cmd, data):
write_cmd(cmd)
set_dc_pin_high()
spi_transmit(data)
def init_lcd():
# reset required on power up
set_reset_low()
sleep(120)
set_reset_high()
set_cs_low()
# Pixel format set
# 0x1 = 12 bits / pixel
# 0x5 = 16 bits / pixel
# 0x6 = 18 bits / pixel
write_cmd_data(0x3A, 0x05)
# Display inversion on
write_cmd(0x21)
# Sleep out
write_cmd(0x11)
set_cs_high()
# Wait 120 ms
sleep(120)
set_cs_low()
# Display on
write_cmd(0x29)
set_cs_high()
# Wait 20 ms
sleep(20)
COL_OFFSET = 2
ROW_OFFSET = 1
def write_data(data_bytes):
set_dc_pin_high()
for b in data_bytes:
spi_transmit(b)
def hi_byte(d):
return (d & 0xFF00) >> 8
def lo_byte(d):
return (d & 0xFF)
def set_window(x, y, width, height):
col = x + COL_OFFSET
col_data = [
hi_byte(col), low_byte(col),
hi_byte(col + width - 1), low_byte(col + width - 1)
]
row = y + ROW_OFFSET
row_data = [
hi_byte(row), low_byte(row),
hi_byte(row + height - 1), low_byte(row + height - 1)
]
set_cs_pin_low()
write_cmd(0x2A)
write_data(col_data)
write_cmd(0x2B)
write_data(row_data)
set_cs_pin_high()
def write_window(x, y, width, height, pixel_data):
set_window(x, y, width, height)
set_cs_pin_low()
write_cmd(0x2C)
write_data(pixel_data)
set_cs_pin_high()
def clear_to_color(color_r5g6b5):
hi = hi_byte(color_r5g6b5)
lo = lo_byte(color_r5g6b5)
write_window(0, 0, 128, 128, [hi, lo] * 128 * 128)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment