Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic ILI9341 240x320 display #25

Open
SvenMb opened this issue Feb 12, 2024 · 0 comments
Open

Generic ILI9341 240x320 display #25

SvenMb opened this issue Feb 12, 2024 · 0 comments

Comments

@SvenMb
Copy link

SvenMb commented Feb 12, 2024

Nicely your driver works with ILI9341 too, but there was no example config for a generic ILI9341 and the custom_init for the m5stack m5cores3 didn't work.

So I created a tft_config.py, based on the init sequence from the adafruit ili9341 lib, which should work for nearly all these cheap ILI9341 displays with SPI.

1707750845516

Maybe you like to add this config to your examples.

tft_config.py

"""esp32s3 with ili9342c 320x240 display"""

# mosi: GPIO13
# sck:  GPIO12
# dc:   GPIO11
# cs:   GPIO10
# rst:  GPIO01
# backlight: GPIO14


from machine import Pin,freq
import s3lcd

BL = Pin(14, Pin.OUT)

TFA = 0
BFA = 0
# WIDE = 3
# TALL = 2
WIDE = 1
TALL = 0

# Set clock to 240MHz
freq(240000000)

def config(rotation=0, options=0):
    """Configure the display and return an ESPLCD instance."""
    
    BL.value(1)
    
    custom_init = [
# original adafruit init sequence - translated to mpy
#  0xEF, 3, 0x03, 0x80, 0x02,
        (b"\xEF\x03\x80\x02",),
#  0xCF, 3, 0x00, 0xC1, 0x30,
        (b"\xCF\x00\xC1\x30",),
#  0xED, 4, 0x64, 0x03, 0x12, 0x81,
        (b"\xED\x64\x03\x12\x81",),
#  0xE8, 3, 0x85, 0x00, 0x78,
        (b"\xE8\x85\x00\x78",),
#  0xCB, 5, 0x39, 0x2C, 0x00, 0x34, 0x02,
        (b"\xCB\x39\x2C\x00\x34\x02",),
#  0xF7, 1, 0x20,
        (b"\xF7\x20",),
#  0xEA, 2, 0x00, 0x00,
        (b"\xEA\x00\x00",),
#  ILI9341_PWCTR1 - 0xC0 , 1, 0x23,             // Power control VRH[5:0]
        (b"\xC0\x23",),
#  ILI9341_PWCTR2 - 0xC1 , 1, 0x10,             // Power control SAP[2:0];BT[3:0]
        (b"\xC1\x10",),
#  ILI9341_VMCTR1 - 0xC5 , 2, 0x3e, 0x28,       // VCM control
        (b"\xC5\x3E\x28",),
#  ILI9341_VMCTR2 - 0xC6 , 1, 0x86,             // VCM control2
        (b"\xC6\x86",),
#  ILI9341_MADCTL - 0x36 , 1, 0x48,             // Memory Access Control
        (b"\x36\x08",),
# ILI9341_VSCRSADD - 0x33, 1, 0x00,             // Vertical scroll zero
        (b"\x33\x00",),
#  ILI9341_PIXFMT - 0x3A , 1, 0x55,
        (b"\x3A\x55",),
#  ILI9341_FRMCTR1 - 0xB1 , 2, 0x00, 0x18,
        (b"\xB1\x00\x18",),
#  ILI9341_DFUNCTR - 0xB6, 3, 0x08, 0x82, 0x27, // Display Function Control
        (b"\xB6\x08\x82\x27",),
#  0xF2, 1, 0x00,                         // 3Gamma Function Disable
        (b"\xF2\x00",),
#  ILI9341_GAMMASET - 0x26 , 1, 0x01,             // Gamma curve selected
        (b"\x26\x01",),
#  ILI9341_GMCTRP1 - 0xE0 , 15, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, // Set Gamma
#    0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00,
        (b"\xE0\x0F\x31\x2B\x0C\x0E\x08\x4E\xF1\x37\x07\x10\x03\x0E\x09\x00",),
#  ILI9341_GMCTRN1 - 0xE1 , 15, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, // Set Gamma
#    0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F,
        (b"\xE1\x00\x0E\x14\x03\x11\x07\x31\xC1\x48\x08\x0F\x0C\x31\x36\x0F",),
#  ILI9341_SLPOUT - 0x11 , 0x80,                // Exit Sleep
        (b"\x11", 128),
#  ILI9341_DISPON - 0x29 , 0x80,                // Display on
        (b"\x29", 128),
#  0x00                                   // End of list
    ]
    
    custom_rotations = (
        (240, 320, 0, 0, False, True, False),
        (320, 240, 0, 0, True, False, False),
        (240, 320, 0, 0, False, False, True),
        (320, 240, 0, 0, True, True, True),
    )

    # To use baudrates above 26.6MHz you must use my firmware or modify the micropython
    # source code to increase the SPI baudrate limit by adding SPI_DEVICE_NO_DUMMY to
    # the .flag member of the spi_device_interface_config_t struct in the
    # machine_hw_spi_init_internal.c file.  Not doing so will cause the ESP32 to crash
    # if you use a baudrate that is too high.

    bus = s3lcd.SPI_BUS(
        2, mosi=13, sck=12, dc=11, cs=10, pclk=60000000, swap_color_bytes=True
    )
    
    return s3lcd.ESPLCD(
        bus,
        240,
        320,
        inversion_mode=False,
        color_space=s3lcd.BGR,
        reset=1,
        rotations=custom_rotations,
        rotation=rotation,
        dma_rows=32,
        custom_init=custom_init,
        options=options,
    )


def deinit(tft, display_off=False):
    """Take an ESPLCD instance and Deinitialize the display."""
    tft.deinit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant