diff options
Diffstat (limited to 'ports/nrf/examples/seeed_tft.py')
-rw-r--r-- | ports/nrf/examples/seeed_tft.py | 106 |
1 files changed, 74 insertions, 32 deletions
diff --git a/ports/nrf/examples/seeed_tft.py b/ports/nrf/examples/seeed_tft.py index c5cd4cc0a..bf246bed4 100644 --- a/ports/nrf/examples/seeed_tft.py +++ b/ports/nrf/examples/seeed_tft.py @@ -51,24 +51,28 @@ import framebuf from machine import SPI, Pin from sdcard import SDCard + def mount_tf(self, mount_point="/"): sd = SDCard(SPI(0), Pin("P15", mode=Pin.OUT)) os.mount(sd, mount_point) + class ILI9341: def __init__(self, width, height): self.width = width self.height = height self.pages = self.height // 8 self.buffer = bytearray(self.pages * self.width) - self.framebuf = framebuf.FrameBuffer(self.buffer, self.width, self.height, framebuf.MONO_VLSB) + self.framebuf = framebuf.FrameBuffer( + self.buffer, self.width, self.height, framebuf.MONO_VLSB + ) self.spi = SPI(0) # chip select self.cs = Pin("P16", mode=Pin.OUT, pull=Pin.PULL_UP) # command self.dc = Pin("P17", mode=Pin.OUT, pull=Pin.PULL_UP) - + # initialize all pins high self.cs.high() self.dc.high() @@ -76,27 +80,26 @@ class ILI9341: self.spi.init(baudrate=8000000, phase=0, polarity=0) self.init_display() - def init_display(self): time.sleep_ms(500) - + self.write_cmd(0x01) - + time.sleep_ms(200) - + self.write_cmd(0xCF) self.write_data(bytearray([0x00, 0x8B, 0x30])) - + self.write_cmd(0xED) self.write_data(bytearray([0x67, 0x03, 0x12, 0x81])) self.write_cmd(0xE8) self.write_data(bytearray([0x85, 0x10, 0x7A])) - + self.write_cmd(0xCB) self.write_data(bytearray([0x39, 0x2C, 0x00, 0x34, 0x02])) - + self.write_cmd(0xF7) self.write_data(bytearray([0x20])) @@ -107,54 +110,94 @@ class ILI9341: self.write_cmd(0xC0) # VRH[5:0] self.write_data(bytearray([0x1B])) - + # Power control self.write_cmd(0xC1) # SAP[2:0];BT[3:0] self.write_data(bytearray([0x10])) - + # VCM control self.write_cmd(0xC5) self.write_data(bytearray([0x3F, 0x3C])) - + # VCM control2 self.write_cmd(0xC7) self.write_data(bytearray([0xB7])) - + # Memory Access Control self.write_cmd(0x36) self.write_data(bytearray([0x08])) - + self.write_cmd(0x3A) self.write_data(bytearray([0x55])) - + self.write_cmd(0xB1) self.write_data(bytearray([0x00, 0x1B])) - + # Display Function Control self.write_cmd(0xB6) self.write_data(bytearray([0x0A, 0xA2])) - + # 3Gamma Function Disable self.write_cmd(0xF2) self.write_data(bytearray([0x00])) - + # Gamma curve selected self.write_cmd(0x26) self.write_data(bytearray([0x01])) - + # Set Gamma self.write_cmd(0xE0) - self.write_data(bytearray([0x0F, 0x2A, 0x28, 0x08, 0x0E, 0x08, 0x54, 0XA9, 0x43, 0x0A, 0x0F, 0x00, 0x00, 0x00, 0x00])) - + self.write_data( + bytearray( + [ + 0x0F, + 0x2A, + 0x28, + 0x08, + 0x0E, + 0x08, + 0x54, + 0xA9, + 0x43, + 0x0A, + 0x0F, + 0x00, + 0x00, + 0x00, + 0x00, + ] + ) + ) + # Set Gamma - self.write_cmd(0XE1) - self.write_data(bytearray([0x00, 0x15, 0x17, 0x07, 0x11, 0x06, 0x2B, 0x56, 0x3C, 0x05, 0x10, 0x0F, 0x3F, 0x3F, 0x0F])) - + self.write_cmd(0xE1) + self.write_data( + bytearray( + [ + 0x00, + 0x15, + 0x17, + 0x07, + 0x11, + 0x06, + 0x2B, + 0x56, + 0x3C, + 0x05, + 0x10, + 0x0F, + 0x3F, + 0x3F, + 0x0F, + ] + ) + ) + # Exit Sleep self.write_cmd(0x11) time.sleep_ms(120) - + # Display on self.write_cmd(0x29) time.sleep_ms(500) @@ -164,14 +207,14 @@ class ILI9341: # set col self.write_cmd(0x2A) self.write_data(bytearray([0x00, 0x00])) - self.write_data(bytearray([0x00, 0xef])) - - # set page + self.write_data(bytearray([0x00, 0xEF])) + + # set page self.write_cmd(0x2B) self.write_data(bytearray([0x00, 0x00])) - self.write_data(bytearray([0x01, 0x3f])) + self.write_data(bytearray([0x01, 0x3F])) - self.write_cmd(0x2c); + self.write_cmd(0x2C) num_of_pixels = self.height * self.width @@ -201,10 +244,9 @@ class ILI9341: self.cs.low() self.spi.write(bytearray([cmd])) self.cs.high() - + def write_data(self, buf): self.dc.high() self.cs.low() self.spi.write(buf) self.cs.high() - |