Skip to content

Instantly share code, notes, and snippets.

@notro
Created January 27, 2022 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notro/3ca61c48e7dcc4a0ef34dbadbc30bfa5 to your computer and use it in GitHub Desktop.
Save notro/3ca61c48e7dcc4a0ef34dbadbc30bfa5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# SPDX-License-Identifier: CC0-1.0
import ctypes
class panel_mipi_dbi_config(ctypes.BigEndianStructure):
_fields_ = [
('magic', ctypes.c_char * 15),
('file_format_version', ctypes.c_uint8),
('width', ctypes.c_uint16),
('height', ctypes.c_uint16),
('width_mm', ctypes.c_uint16),
('height_mm', ctypes.c_uint16),
('x_offset', ctypes.c_uint16),
('y_offset', ctypes.c_uint16),
('pad', ctypes.c_char * 4),
#('commands', ctypes.c_uint8 * 0),
]
def command(buf, cmd, *parameters):
buf.append(cmd)
buf.append(len(parameters))
for parameter in parameters:
buf.append(parameter)
def sleep(buf, ms):
buf.append(0x00)
buf.append(1)
buf.append(ms)
def main():
config = panel_mipi_dbi_config()
config.magic = b'MIPI DBI'
config.file_format_version = 1
config.width = 160
config.height = 128
config.width_mm = 35
config.height_mm = 28
buf = bytearray()
command(buf, 0x11)
sleep(buf, 120)
command(buf, 0xB1, 0x01, 0x2C, 0x2D)
command(buf, 0xB4, 0x07)
command(buf, 0xC0, 0xA2, 0x02, 0x84)
command(buf, 0xC1, 0xC5)
command(buf, 0xC2, 0x0A, 0x00)
command(buf, 0xC5, 0x0E)
command(buf, 0x60)
command(buf, 0x3A, 0x05)
command(buf, 0x36, 0xA0)
command(buf, 0xE0, 0x0F, 0x1A, 0x0F, 0x18, 0x2F, 0x28, 0x20, 0x22, 0x1F, 0x1B, 0x23, 0x37, 0x00, 0x07, 0x02, 0x10)
command(buf, 0xE1, 0x0F, 0x1B, 0x0F, 0x17, 0x33, 0x2C, 0x29, 0x2E, 0x30, 0x30, 0x39, 0x3F, 0x00, 0x07, 0x03, 0x10)
command(buf, 0x29)
sleep(buf, 100)
cfg_str = " ".join("{:02x}".format(x) for x in bytearray(config))
buf_str = " ".join("{:02x}".format(x) for x in buf)
print('Config:', cfg_str)
print('Commands:', buf_str)
print()
config_bytes = bytearray(config) + buf
#r = panel_mipi_dbi_config.from_buffer_copy(config_bytes)
#print(r.magic, r.file_format_version)
with open('sainsmart18.bin', 'wb') as f:
f.write(config_bytes)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment