Preliminary TTGO T-Display support.

pull/9/head
Peter Hinch 2021-04-23 13:49:02 +01:00
rodzic 95fc0898be
commit d1373248ae
3 zmienionych plików z 98 dodań i 23 usunięć

Wyświetl plik

@ -32,6 +32,7 @@ access via the `Writer` and `CWriter` classes is documented
3.1 [Drivers for ST7735R](./DRIVERS.md#31-drivers-for-st7735r) Small TFTs
3.2 [Drivers for ILI9341](./DRIVERS.md#32-drivers-for-ili9341) Large TFTs
3.3 [Drivers for ST7789](./DRIVERS.md#33-drivers-for-st7789) Small high density TFTs
3.3.1 [TTGO T Display](./DRIVERS.md#331-ttgo-t-display) Low cost ESP32 with integrated display
4. [Drivers for sharp displays](./DRIVERS.md#4-drivers-for-sharp-displays) Large low power monochrome displays
4.1 [Display characteristics](./DRIVERS.md#41-display-characteristics)
     4.1.1 [The VCOM bit](./DRIVERS.md#411-the-vcom-bit)
@ -471,6 +472,15 @@ At a 60MHz baudrate this equates to
This suggests that about 80% of the latency results from the Python code. An
option may be to overclock.
### 3.3.1 TTGO T Display
This is an ESP32 based device with an integrated 1.14" 135x240 pixel display
based on ST7789.
It is supported by `color_setup_ttgo.py` in `drivers/st7789`. Copy to
`/pyboard/color_setup.py` on the device. It produces a landscape mode display
with the top left hand corner adjacent to pin 36.
###### [Contents](./DRIVERS.md#contents)
# 4. Drivers for sharp displays

Wyświetl plik

@ -0,0 +1,76 @@
# color_setup.py Customise for your hardware config
# Released under the MIT License (MIT). See LICENSE.
# Copyright (c) 2021 Peter Hinch, Ihor Nehrutsa
# Notes: Peter Hinch April 2021
# UNDER DEVELOPMENT. This file and the ST7789 driver may change.
# These settings produce a landscape mode display with top left
# adjactent to pin 36.
# Supports:
# TTGO T-Display 1.14" 135*240(Pixel) based on ST7789V
# http://www.lilygo.cn/claprod_view.aspx?TypeId=62&Id=1274
# http://www.lilygo.cn/prod_view.aspx?TypeId=50044&Id=1126
# https://github.com/Xinyuan-LilyGO/TTGO-T-Display
# https://github.com/Xinyuan-LilyGO/TTGO-T-Display/blob/master/image/pinmap.jpg
# https://github.com/Xinyuan-LilyGO/TTGO-T-Display/blob/master/schematic/ESP32-TFT(6-26).pdf
# Demo of initialisation procedure designed to minimise risk of memory fail
# when instantiating the frame buffer. The aim is to do this as early as
# possible before importing other modules.
# WIRING (TTGO T-Display pin nos and names).
# Pinout of TFT Driver
# ST7789 ESP32
# TFT_MISO N/A
TFT_MOSI = 19
TFT_SCLK = 18
TFT_CS = 5
TFT_DC = 16
TFT_RST = 23
TFT_BL = 4 # LEDK = BL Display backlight control pin
ADC_IN = 34
ADC_EN = 14 # PWR_EN = ADC_EN is the ADC detection enable port
BUTTON1 = 35 # right of the USB connector
BUTTON2 = 0 # left of the USB connector
#I2C_SDA = 19
#I2C_SCL = 18
#DAC1 25
#DAC2 26
from machine import Pin, SPI, ADC
import gc
from drivers.st7789.st7789_4bit import ST7789 as SSD, PORTRAIT, USD, REFLECT
pdc = Pin(TFT_DC, Pin.OUT, value=0) # Arbitrary pins
pcs = Pin(TFT_CS, Pin.OUT, value=1)
prst = Pin(TFT_RST, Pin.OUT, value=1)
pbl = Pin(TFT_BL, Pin.OUT, value=1)
gc.collect() # Precaution before instantiating framebuf
# Conservative low baudrate. Can go to 62.5MHz.
spi = SPI(1, 30_000_000, sck=Pin(TFT_SCLK), mosi=Pin(TFT_MOSI))
ssd = SSD(spi, height=135, width=240, dc=pdc, cs=pcs, rst=prst, disp_mode=PORTRAIT | REFLECT, offset=(40, 52))
# optional
# b1 = Pin(BUTTON1, Pin.IN)
# b2 = Pin(BUTTON2, Pin.IN)
# adc_en = Pin(ADC_EN, Pin.OUT, value=1)
# adc_in = ADC(Pin(ADC_IN))
# adc_en.value(0)
'''
Set PWR_EN to "1" and read voltage in BAT_ADC,
if this voltage more than 4.3 V device have powered from USB.
If less then 4.3 V - device have power from battery.
To save battery you can set PWR_EN to "0" and in this case the USB converter
will be power off and do not use your battery.
When you need to measure battery voltage first set PWR_EN to "1",
measure voltage and then set PWR_EN back to "0" for save battery.
'''

Wyświetl plik

@ -19,6 +19,7 @@ import gc
import micropython
import uasyncio as asyncio
LANDSCAPE = 0 # Default
PORTRAIT = 0x20
REFLECT = 0x40
USD = 0x80
@ -138,33 +139,21 @@ class ST7789(framebuf.FrameBuffer):
wht = self.height
wwd = self.width # Window dimensions
# Determine x and y start and end. Defaults for LANDSCAPE and PORTRAIT
ys = 0 # y start
ye = wht - 1 # y end
yoff = self._offset[1]
xs = 0
xe = wwd - 1
xoff = self._offset[0]
if mode & PORTRAIT:
if mode & REFLECT:
ys = rwd - wht
ye = rwd - 1
if mode & USD:
xs = rht - wwd
xe = rht - 1
else: # LANDSCAPE
if mode & REFLECT:
xs = rwd - wht
xe = rwd - 1
if mode & USD:
ys = rht - wwd
ye = rht - 1
xs = xoff
xe = wwd + xoff - 1
yoff = self._offset[1]
ys = yoff # y start
ye = wht + yoff - 1 # y end
if mode & REFLECT:
ys = rwd - wht - yoff
ye = rwd - yoff - 1
if mode & USD:
xs = rht - wwd - xoff
xe = rht - xoff - 1
# Col address set. Add in any offset.
xs += xoff
xe += xoff
self._wcd(b'\x2a', int.to_bytes(xs, 2, 'big') + int.to_bytes(xe, 2, 'big'))
# Row address set
ys += yoff
ye += yoff
self._wcd(b'\x2b', int.to_bytes(ys, 2, 'big') + int.to_bytes(ye, 2, 'big'))
#@micropython.native # Made virtually no difference to timing.