Commit 22e09516 authored by Russ's avatar Russ

TTGO T-Watch-202 support and demo

parent 327326fd
"""
watch_hello.py
Writes "Hello!" in random colors at random locations on a
LILYGO® TTGO T-Watch 2020.
https://youtu.be/Bwq39tuMoY4
"""
import time
import random
from machine import Pin, SPI
import axp202c
import st7789
# Choose a font
# import vga1_8x8 as font
# import vga2_8x8 as font
# import vga1_8x16 as font
# import vga2_8x16 as font
# import vga1_16x16 as font
# import vga1_bold_16x16 as font
# import vga2_16x16 as font
# import vga2_bold_16x16 as font
# import vga1_16x32 as font
# import vga1_bold_16x32 as font
# import vga2_16x32 as font
import vga2_bold_16x32 as font
def wheel(pos):
pos = 255 - (pos % 255)
if pos < 85:
return st7789.color565(255 - pos * 3, 0, pos * 3)
if pos < 170:
pos -= 85
return st7789.color565(0, pos * 3, 255 - pos * 3)
pos -= 170
return st7789.color565(pos * 3, 255 - pos * 3, 0)
def random_color():
return st7789.color565(
random.getrandbits(8),
random.getrandbits(8),
random.getrandbits(8))
def main():
try:
# Turn power on display power
axp = axp202c.PMU()
axp.enablePower(axp202c.AXP202_LDO2)
# initalize spi port
spi = SPI(
2,
baudrate=32000000,
polarity=1,
phase=0,
bits=8,
firstbit=0,
sck=Pin(18, Pin.OUT),
mosi=Pin(19, Pin.OUT))
# configure display
tft = st7789.ST7789(
spi,
240,
240,
cs=Pin(5, Pin.OUT),
dc=Pin(27, Pin.OUT),
backlight=Pin(12, Pin.OUT),
rotation=2)
# enable display
tft.init()
tft.fill(st7789.BLACK)
time.sleep(2)
while True:
# say Hello! and show off some colors
tft.fill(st7789.BLUE)
tft.text(font, "Hello!", 76, 96, st7789.WHITE, st7789.BLUE)
time.sleep(1)
tft.fill(0)
for _ in range(2):
for i in range(256):
j = i % 64
tft.rect(68-j, 96-j, j*2+104, j*2+32, wheel(i))
tft.text(font, "Hello!", 76, 96, wheel(i))
time.sleep(1)
# display some random letters
tft.fill(0)
col_max = tft.width() - font.WIDTH
row_max = tft.height() - font.HEIGHT
for i in range(5):
for c in range(0, 255):
tft.text(
font,
c,
random.randint(0, col_max),
random.randint(0, row_max),
random_color())
time.sleep(0.005)
time.sleep(1)
# write hello! randomly on display running through each rotation
for rotation in range(9):
tft.fill(0)
tft.rotation(rotation%4+2)
col_max = tft.width() - font.WIDTH*6
row_max = tft.height() - font.HEIGHT
for _ in range(250):
tft.text(
font,
"Hello!",
random.randint(0, col_max),
random.randint(0, row_max),
random_color(),
random_color())
finally:
# shutdown spi
spi.deinit()
# turn off display power
axp.disablePower(axp202c.AXP202_LDO2)
main()
......@@ -3,15 +3,16 @@ The esp32 directory contains a firmware.bin file with MicroPython
v1.12-464-gcae77daf0 compiled using ESP IDF v3 with the st7789 C driver and
the frozen python font files for generic ESP32 boards.
The esp32-spiram-16flash contains an untested firmware.bin file with
MicroPython v1.12-464-gcae77daf0 compiled using ESP IDF v3 with the st7789
C driver and the frozen python font files for generic ESP32 boards with
spiram and 16MB of flash. (ie TTGO T-Watch 2020) if this works let me know.
The pybv11 directory contains a firmware.dfu file with MicroPython
v1.12-464-gcae77daf0 compiled with the st7789 C driver and
the frozen python font files for the Pyboard v1.1.
The ttgo_watch directory contains a firmware.bin file with MicroPython
v1.12-464-gcae77daf0 compiled using ESP IDF v3 with the st7789
C driver, frozen axp202c driver from https://github.com/lewisxhe/AXP202X_Libraries
and the frozen python font files for the TTGO T-Watch 2020.
Frozen python bitmap font files included:
- vga1_8x8
......
This diff is collapsed.
......@@ -43,8 +43,8 @@
#define CS_HIGH() { if(self->cs) {mp_hal_pin_write(self->cs, 1);} }
#define DC_LOW() (mp_hal_pin_write(self->dc, 0))
#define DC_HIGH() (mp_hal_pin_write(self->dc, 1))
#define RESET_LOW() (mp_hal_pin_write(self->reset, 0))
#define RESET_HIGH() (mp_hal_pin_write(self->reset, 1))
#define RESET_LOW() { if (self->reset) mp_hal_pin_write(self->reset, 0); }
#define RESET_HIGH() { if (self->reset) mp_hal_pin_write(self->reset, 1); }
STATIC void write_spi(mp_obj_base_t *spi_obj, const uint8_t *buf, int len) {
......@@ -771,17 +771,20 @@ mp_obj_t st7789_ST7789_make_new(const mp_obj_type_t *type,
mp_raise_ValueError(MP_ERROR_TEXT("Unsupported display. Only 240x320, 240x240 and 135x240 are supported"));
}
if (args[ARG_reset].u_obj == MP_OBJ_NULL
|| args[ARG_dc].u_obj == MP_OBJ_NULL) {
mp_raise_ValueError(MP_ERROR_TEXT("must specify all of reset/dc pins"));
if (args[ARG_dc].u_obj == MP_OBJ_NULL) {
mp_raise_ValueError(MP_ERROR_TEXT("must specify dc pin"));
}
if (args[ARG_reset].u_obj != MP_OBJ_NULL) {
self->reset = mp_hal_get_pin_obj(args[ARG_reset].u_obj);
}
self->reset = mp_hal_get_pin_obj(args[ARG_reset].u_obj);
self->dc = mp_hal_get_pin_obj(args[ARG_dc].u_obj);
if (args[ARG_cs].u_obj != MP_OBJ_NULL) {
self->cs = mp_hal_get_pin_obj(args[ARG_cs].u_obj);
}
if (args[ARG_backlight].u_obj != MP_OBJ_NULL) {
self->backlight = mp_hal_get_pin_obj(args[ARG_backlight].u_obj);
}
......@@ -789,6 +792,7 @@ mp_obj_t st7789_ST7789_make_new(const mp_obj_type_t *type,
return MP_OBJ_FROM_PTR(self);
}
STATIC uint16_t color565(uint8_t r, uint8_t g, uint8_t b) {
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment