nrf5/modules: Updating seeedstudio tft lcd driver to render using already existing framebuffer implementation.

This commit is contained in:
Glenn Ruben Bakke 2016-12-29 08:52:32 +01:00
parent 5f4cf7b908
commit cfbe91a709

View file

@ -1,9 +1,28 @@
# MicroPython Seeedstudio TFT Shield V2 driver, SPI interfaces, Analog GPIO """
# Contains SD-card reader, LCD and Touch sensor MicroPython Seeedstudio TFT Shield V2 driver, SPI interfaces, Analog GPIO
Contains SD-card reader, LCD and Touch sensor
import time Example usage of LCD:
from machine import SPI, Pin
from seeedstudio_tft_shield_v2 import ILI9341
lcd = ILI9341(240, 320)
lcd.text("Hello World!, 32, 32)
lcd.show()
Example usage of SD card reader:
import os
from seeedstudio_tft_shield_v2 import mount_tf
tf = mount_tf()
os.listdir()
"""
import os import os
import time
import framebuf
from machine import SPI, Pin
from sdcard import SDCard from sdcard import SDCard
def mount_tf(self, mount_point="/"): def mount_tf(self, mount_point="/"):
@ -14,6 +33,10 @@ class ILI9341:
def __init__(self, width, height): def __init__(self, width, height):
self.width = width self.width = width
self.height = height self.height = height
self.pages = self.height // 8
self.buffer = bytearray(self.pages * self.width)
self.framebuf = framebuf.FrameBuffer1(self.buffer, self.width, self.height)
self.spi = SPI(0) self.spi = SPI(0)
# chip select # chip select
self.cs = Pin("A16", mode=Pin.OUT, pull=Pin.PULL_UP) self.cs = Pin("A16", mode=Pin.OUT, pull=Pin.PULL_UP)
@ -24,7 +47,7 @@ class ILI9341:
self.cs.high() self.cs.high()
self.dc.high() self.dc.high()
self.spi.init(baudrate=1000000, phase=0, polarity=0) self.spi.init(baudrate=8000000, phase=0, polarity=0)
self.init_display() self.init_display()
@ -111,36 +134,41 @@ class ILI9341:
time.sleep_ms(500) time.sleep_ms(500)
self.fill(0) self.fill(0)
def fill(self, col): def show(self):
# set col # set col
self.write_cmd(0x2A) self.write_cmd(0x2A)
self.write_data(bytearray([0x00, 0x00])); self.write_data(bytearray([0x00, 0x00]))
self.write_data(bytearray([0x00, 0xef])); self.write_data(bytearray([0x00, 0xef]))
# set page # set page
self.write_cmd(0x2B) self.write_cmd(0x2B)
self.write_data(bytearray([0x00, 0x00])); 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);
self.dc.high() num_of_pixels = self.height * self.width
self.cs.low()
for i in range(0, self.width): for row in range(0, self.pages):
for j in range(0, self.height): for pixel_pos in range(0, 8):
a = bytearray([col, col]) for col in range(0, self.width):
self.spi.write(a) compressed_pixel = self.buffer[row * 240 + col]
self.cs.high() if ((compressed_pixel >> pixel_pos) & 0x1) == 0:
self.write_data(bytearray([0x00, 0x00]))
else:
self.write_data(bytearray([0xFF, 0xFF]))
def fill(self, col):
self.framebuf.fill(col)
def pixel(self, x, y, col): def pixel(self, x, y, col):
pass self.framebuf.pixel(x, y, col)
def scroll(self, dx, dy): def scroll(self, dx, dy):
pass self.framebuf.scroll(dx, dy)
def text(self, string, x, y, col=1): def text(self, string, x, y, col=1):
pass self.framebuf.text(string, x, y, col)
def write_cmd(self, cmd): def write_cmd(self, cmd):
self.dc.low() self.dc.low()