1"""M5STACK CORE2 320x240 (ILI9342)
2"""
3
4from machine import Pin, SPI
5import st7789py as st7789
6import axp202c
7
8TFA = 0
9BFA = 0
10WIDE = 0
11TALL = 1
12SCROLL = 0 # orientation for scroll.py
13FEATHERS = 1 # orientation for feathers.py
14
15def config(rotation=0):
16 """Configure the M5Stack CORE2 display using a custom_init and
17 custom_rotations since the display is ili9342c. The custom_init is a
18 list of commands to send to the display during the init() metehod. The
19 list contains tuples with a bytes object, optionally followed by a
20 delay specified in ms. The first byte of the bytes object contains the
21 command to send optionally followed by data bytes.
22 """
23 custom_init = [
24 (b'\x01', None, 150), # soft reset
25 (b'\x11', None, 255), # exit sleep
26 (b'\xCB', b'\x39\x2C\x00\x34\x02', 0), # power control A
27 (b'\xCF', b'\x00\xC1\x30', 0), # power control B
28 (b'\xE8', b'\x85\x00\x78', 0), # driver timing control A
29 (b'\xEA', b'\x00\x00', 0), # driver timing control B
30 (b'\xED', b'\x64\x03\x12\x81', 0), # power on sequence control
31 (b'\xF7', b'\x20', 0), # pump ratio control
32 (b'\xC0', b'\x23', 0), # power control,VRH[5:0]
33 (b'\xC1', b'\x10', 0), # Power control,SAP[2:0];BT[3:0]
34 (b'\xC5', b'\x3E\x28', 0), # vcm control
35 (b'\xC7', b'\x86', 0), # vcm control 2
36 (b'\x3A', b'\x55', 0), # pixel format
37 (b'\x36', b'\x00', 0), # madctl
38 (b'\x21', None, 0), # inversion on
39 (b'\xB1', b'\x00\x18', 0), # frameration control,normal mode full colours
40 (b'\xB6', b'\x08\x82\x27', 0), # display function control
41 (b'\xF2', b'\x00', 0), # 3gamma function disable
42 (b'\x26', b'\x01', 0), # gamma curve selected
43 # set positive gamma correction
44 (b'\xE0', b'\x0F\x31\x2B\x0C\x0E\x08\x4E\xF1\x37\x07\x10\x03\x0E\x09\x00', 0),
45 # set negative gamma correction
46 (b'\xE1', b'\x00\x0E\x14\x03\x11\x07\x31\xC1\x48\x08\x0F\x0C\x31\x36\x0F', 0),
47 (b'\x29', None, 100), # display on
48 ]
49
50 custom_rotations = [
51 (0x08, 320, 240, 0, 0, False),
52 (0x68, 240, 320, 0, 0, False),
53 (0xc8, 320, 240, 0, 0, False),
54 (0xa8, 240, 320, 0, 0, False),
55 ]
56
57 axp = axp202c.PMU(address=0x34)
58 axp.enablePower(axp202c.AXP192_LDO2)
59 # Set backlight voltage
60 axp.setDC3Voltage(3000)
61
62 return st7789.ST7789(
63 SPI(2, baudrate=40000000, sck=Pin(18), mosi=Pin(23)),
64 320,
65 240,
66 cs=Pin(5, Pin.OUT),
67 dc=Pin(15, Pin.OUT),
68 custom_init=custom_init,
69 custom_rotations=custom_rotations,
70 rotation=rotation,
71 color_order=st7789.BGR)