1"""LilyGo T-Dongle-S3 80x160 (ST7735)
2"""
3
4from machine import Pin, SPI
5import st7789py as st7789
6
7
8TFA = 1
9BFA = 1
10WIDE = 1
11TALL = 0
12SCROLL = 0 # orientation for scroll.py
13FEATHERS = 1 # orientation for feathers.py
14
15def config(rotation=0):
16 """
17 Configures and returns an instance of the ST7789 display driver.
18
19 Args:
20 rotation (int): The rotation of the display (default: 0).
21
22 Returns:
23 ST7789: An instance of the ST7789 display driver.
24 """
25
26 init_cmds = (
27 (b'\xCF', b'\x00\x83\x30', 0),
28 (b'\xED', b'\x64\x03\x12\x81', 0),
29 (b'\xE8', b'\x85\x01\x79', 0),
30 (b'\xCB', b'\x39\x2C\x00\x34\x02', 0),
31 (b'\xF7', b'\x20', 0),
32 (b'\xEA', b'\x00\x00', 0),
33 (b'\xC0', b'\x26', 0),
34 (b'\xC1', b'\x11', 0),
35 (b'\xC5', b'\x35\x3E', 0),
36 (b'\xC7', b'\xBE', 0),
37 (b'\x3A', b'\x55', 0),
38 (b'\xB1', b'\x00\x1B', 0),
39 (b'\xF2', b'\x08', 0),
40 (b'\x26', b'\x01', 0),
41 (b'\xE0', b'\x1F\x1A\x18\x0A\x0F\x06\x45\x87\x32\x0A\x07\x02\x07\x05\x00', 0),
42 (b'\xE1', b'\x00\x25\x27\x05\x10\x09\x3A\x78\x4D\x05\x18\x0D\x38\x3A\x1F', 0),
43 (b'\x2A', b'\x00\x00\x00\xEF', 0),
44 (b'\x2B', b'\x00\x00\x01\x3f', 0),
45 (b'\x2C', None, 0),
46 (b'\xB7', b'\x07', 0),
47 (b'\xB6', b'\x0A\x82\x27\x00', 0),
48 (b'\x21', None, 0),
49 (b'\x11', None, 100),
50 (b'\x29', None, 100)
51 )
52
53 custom_rotations = (
54 (0x00, 80, 160, 26, 1, False),
55 (0x60, 160, 80, 1, 26, False),
56 (0xc0, 80, 160, 26, 1, False),
57 (0xa0, 160, 80, 1, 26, False),
58 )
59
60 return st7789.ST7789(
61 SPI(1, baudrate=20000000, sck=Pin(5), mosi=Pin(3), miso=None),
62 80,
63 160,
64 reset=Pin(1, Pin.OUT),
65 cs=Pin(4, Pin.OUT),
66 dc=Pin(2, Pin.OUT),
67 backlight=Pin(37, Pin.OUT),
68 rotation=rotation,
69 color_order=st7789.BGR,
70 custom_init=init_cmds,
71 custom_rotations=custom_rotations,
72 )