Coder Social home page Coder Social logo

dermaister / esp-idf-parallel-tft Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nopnop2002/esp-idf-parallel-tft

0.0 0.0 0.0 536 KB

8bit parallel TFT & 4-line resistance touch screen Driver for esp-idf using i2s paralell mode

License: MIT License

C 99.38% Makefile 0.06% CMake 0.57%

esp-idf-parallel-tft's Introduction

esp-idf-parallel-tft

8 bit parallel TFT & 4-line resistance touch screen Driver for esp-idf.
You can use such a TFT-Shield with esp32.

TFT-Shield

Support driver

Generic Shield

  • ILI9225
  • ILI9226(Same as ILI9225)
  • ILI9320
  • ILI9325
  • ILI9341
  • ILI9342
  • ILI9481
  • ILI9486
  • ILI9488
  • SPFD5408(Same as ILI9320)
  • R61505U(Same as ILI9320)
  • R61509V
  • LGDP4532
  • ST7775(Same as ILI9225)
  • ST7781
  • ST7783(Same as ST7781)
  • ST7793(Same as R61509)
  • ST7796(Same as ILI9486)
  • HX8347A(*2)
  • HX8347D(Almost the same as HX8347A)(*2)
  • HX8347G(Same as HX8347D)(*2)
  • HX8347I(Same as HX8347D)(*2)

OPEN-SMART Products

  • OPEN-SMART ILI9225 TFT-Shield(176x220)(*5)
  • OPEN-SMART ILI9327 TFT-Shield(240x400)(*3)(*5)
  • OPEN-SMART ILI9340 TFT-Shield(240x320)(*5)
  • OPEN-SMART S6D1121 16Pin-Parallel(240x320)(*1)(*5)
  • OPEN-SMART ST7775 16Pin-Parallel(176x220 Same as ILI9225)(*1)(*5)
  • OPEN-SMART ST7783 16Pin-Parallel(240x320)(*1)(*5)
  • OPEN-SMART R61509V 16Pin-Parallel(240x400)(*1)(*5)
  • OPEN-SMART ILI9488 16Pin-Parallel(320x400 Color inversion)(*1)(*4)(*5)

(*1)
I2S parallel does not work.
I don't know why.
GPIO parallel or REGISTER I/O parallel works.
LED pins connect to GND instead of 3.3V.

(*2)
Very Slow.
Most drivers require three commands to display one Pixel.
This driver require 9 commands to display one Pixel.
For some reason, the color of 0xFFFF does not appear.

(*3)
It has a GRAM offset.
See below.

(*4)
Need RGB inverstion.

(*5)
4-line resistance touch screen available.
See below.

These are all 2.4 inch, 320x240 TFTs. TFT-SHIELD-2

3.95 inches is almost twice as large as 2.4 inches. TFT-SHIELD-3

These are OPEN-SMART 16Pin-Parallel Products. OPEN-SMART-16Pin

Software requirements

esp-idf v4.4/v5.0.

Note for ESP-IDF V5.0
ESP-IDF V5.0 gives this warning, but work.

#warning "legacy adc driver is deprecated, please migrate to use esp_adc/adc_oneshot.h and esp_adc/adc_continuous.h for oneshot mode and continuous mode drivers respectively"

Presumably, ESP-IDF V5.1 will completely obsolete the legacy ADC driver.

Installation

git clone https://github.com/nopnop2002/esp-idf-parallel-tft
cd esp-idf-parallel-tft/
idf.py set-target {esp32/esp32s2/esp32s3}
idf.py menuconfig
idf.py flash

Note for ESP32-S2
The tjpgd library is not present in ESP32-S2 ROM.
With ESP-IDF Ver5, the JPEG decode library is now provided from the IDF Component Registry, and the JPEG decode library is now available for ESP32-S2.
However, since the ROM is small, a large image cannot be displayed.
With ESP-IDF Ver4.4, you cannot be displayed JPEG files because the IDF Component Registry cannot be used.
PNG file cannot be displayed because the SRAM is small.

Configuration

You have to set this config value with menuconfig.

  • CONFIG_DRIVER

    The information provided by sellers on Ebay or AliExpress is largely incorrect.
    You waste time if you don't choose the right driver.
    There are many variations of the 2.4 inch shield.
    You can use this to find out your driver.
    This is for Arduino UNO.
    Do not use this on the ESP32 as the GPIO on the ESP32 is not 5V tolerant.
    Never believe the seller's information.
    I'll say it again.
    Never believe the seller's information.
  • CONFIG_INTERFACE
    Most drivers work using I2S parallel.
    However, some drivers only work using GPIO parallels or REGISTER I/O parallels.
    I2S parallel is the fastest when drawing to consecutive addresses.
    However, REGISTER I/O parallel is the fastest when drawing to non-contiguous addresses.
    When using REGISTER I/O parallel, GPIO from D0 to D7 is 1 to 31.(GPIO0 is boot mode pin)
    GPIO parallel is most slow.
  • CONFIG_WIDTH
  • CONFIG_HEIGHT
    Specifies the resolution of the TFT.
  • CONFIG_OFFSETX
  • CONFIG_OFFSETY
    You can specify the GRAM offset.
    You must specify Y offset = 32 for OPEN-SMART-ILI9327.
  • CONFIG_INVERSION
    For some TFTs, the BGR may be inverted.
    Specify if the colors are inverted.

config-menu

config-app1

config-app2

config-app4

Wireing

TFT ESP32 ESP32S2/S3
LDC_RST -- GPIO32 GPIO45 *1
LDC_CS -- GPIO33 GPIO42 *1
LDC_RS -- GPIO15 GPIO41 *1
LDC_WR -- GPIO4 GPIO40 *1
LDC_RD -- GPIO2 GPIO39 *1
LDC_D0 -- GPIO12 GPIO1 *1 *2
LDC_D1 -- GPIO13 GPIO2 *1 *2
LDC_D2 -- GPIO26 GPIO3 *1 *2
LDC_D3 -- GPIO25 GPIO4 *1 *2
LDC_D4 -- GPIO17 GPIO5 *1 *2
LDC_D5 -- GPIO16 GPIO6 *1 *2
LDC_D6 -- GPIO27 GPIO7 *1 *2
LDC_D7 -- GPIO14 GPIO8 *1 *2
5V -- 5V 5V *3
3.3V -- 3.3V 3.3V *3
GND -- GND GND

(*1)
You can change any GPIO using menuconfig.

config-app3

(*2)
When using REGISTER I/O parallel, GPIO from D0 to D7 is 1 to 31.(GPIO0 is boot mode pin)

(*3)
With a regulator (mostly AMS1117) is on the back, the supply voltage is 5V.
With a regulator is NOT on the back, the supply voltage is 3.3V.

Back

Note
My R61509V has a regulator on the back.
Normally, a TFT with a regulator works at 5V, but my R61509V doesn't work unless I supply both 5V and 3.3V.

Note
ESP32 development board cannot supply too much current.
It is more stable when supplied from an external power source.

All

Circuit

Graphic support

Graphic1 Graphic2 Graphic3 Graphic4 Graphic5 Graphic6 Graphic7 Graphic8

Fonts support

Font1 It's possible to text rotation and invert.
Font2 Font3 Font4 You can specify multiple fonts at the same time.
Font5

Image support

BMP file
Image1 JPEG file
Image2 PNG file
Image3

Using Wemos D1 ESP32

I bought this for $4.
WeMos-R32-11

I have changed some pin assignments.
Attached the TFT shield.
The TFT shield worked fine.
WeMos-R32-12

It's great because it doesn't require any wiring.
WeMos-R32-13

WeMos-R32-1

WeMos-R32-2

WeMos-R32-3

WeMos-R32-4

If you use OPEN-SMART TFT-Shield Products, you have to change Custom GPIO.

WeMos-R32-OpenSmart

JPEG Decoder

The ESP-IDF component includes Tiny JPEG Decompressor.
The document of Tiny JPEG Decompressor is here.
This can reduce the image to 1/2 1/4 1/8.

PNG Decoder

The ESP-IDF component includes part of the miniz library, such as mz_crc32.
But it doesn't support all of the miniz.
The document of miniz library is here.

And I ported the pngle library from here.
This can reduce the image to any size.

Font File

You can add your original font file.
The format of the font file is the FONTX format.
Your font file is put in font directory.
Your font file is uploaded to SPIFFS partition using meke flash.

Please refer this page about FONTX format.

FontxFile yourFont[2];
InitFontx(yourFont,"/spiffs/your_font_file_name","");
uint8_t ascii[10];
strcpy((char *)ascii, "MyFont");
lcdDrawString(dev, yourFont, x, y, ascii, color);

4-line resistance touch screen

Some TFT has 4-line resistance touch screen.
The 4-line resistor touch screen uses 4 pins.

  • X(+):Digital Output
  • X(-):Digital Output/Analog Input
  • Y(+):Digital Output/Analog Input
  • Y(-):Digital Output

When using GPIO Parallel Interface or REGISTER Parallel Interface, you can enable 4-line resistance touch screen using menuconfig.

ESP-IDF cannot simultaneous both digital output and analog input using a single gpio.
Two GPIOs are required for simultaneous digital output and analog input.
(X-) and ESP32 are connected with two wires.
(Y+) and ESP32 are connected with two wires.

(X-) ----+---- Gpio for Digital Output(Using GPIO number)
         +---- Gpio for Analog Input(Using ADC1 Channel number)

(Y+) ----+---- Gpio for Digital Output(Using GPIO number)
         +---- Gpio for Analog Input(Using ADC1 Channel number)

Configuration for touch screen

config-touch

  • ADC Channel
    When reading analog values, ESP-IDF can use ADC1 and ADC2.
    This project use ADC1 to read analog value.
    ESP32 has 8 channels: GPIO32 - GPIO39.
    ESP32S2/S3 has 10 channels: GPIO01 - GPIO10.
    Refer to the ESP32 data sheet for the relationship between ADC channels and GPIOs.
    When using ADC1_6(ADC1 Channel#6) and ADC1_7(ADC1 Channel#7), the following wiring is additionally required.
TFT ADC1 ESP32 ESP32S2/S3
LCD-WR(Y+) Channel#6 GPIO34 GPIO07
LCD-RS(X-) Channel#7 GPIO35 GPIO08
  • GPIO number
    It uses four GPIOs, but the GPIOs differ depending on the TFT model.

OPEN-SMART 16Pin-Parallel Products

X(+) X(-) Y(+) Y(-)
LCD_D6 LCD_RS LCD_WR LCD_D7

Touch0

OPEN-SMART TFT-Shield Products

There is no marking about 4-line resistance touch screen.
But 4-line resistance touch screen available.

X(+) X(-) Y(+) Y(-)
LCD_D6 LCD_RS LCD_WR LCD_D7

Touch-OpenSmart-Sheild-1

When using ADC1_6(ADC1 Channel#6) and ADC1_7(ADC1 Channel#7), the following wiring is additionally required.

TFT ESP32 ESP32S2
LCD_WR(Y+) ADC1_6(GPIO34) ADC1_6(GPIO07)
LCD_RS(X-) ADC1_7(GPIO35) ADC1_7(GPIO08)

4-line resistance touch screen cannot be used with the Wemos D1 ESP32.
Because the combination of GPIO and ADC does not match.

ELEGOO TFT-Shield Products

There is no marking about 4-line resistance touch screen.
But 4-line resistance touch screen available.

X(+) X(-) Y(+) Y(-)
LCD_D0 LCD_RS LCD_CS LCD_D1

Touch-Elegoo-1

When using ADC1_6(ADC1 Channel#6) and ADC1_7(ADC1 Channel#7), the following wiring is additionally required.

TFT ESP32 ESP32S2
LCD_CS(Y+) ADC1_6(GPIO34) ADC1_6(GPIO07)
LCD_RS(X-) ADC1_7(GPIO35) ADC1_7(GPIO08)

No additional wiring is required when using the Wemos D1 ESP32.
LCD_CS is assigned to ADC1_6 and LCD_RS is assigned to ADC1_7.

ILI9341 2.4inch TFT-Shield with Yellow Pin-header

There is no marking about 4-line resistance touch screen.
But 4-line resistance touch screen available.

X(+) X(-) Y(+) Y(-)
LCD_D0 LCD_RS LCD_CS LCD_D1

Touch-ILI9341-1

When using ADC1_6(ADC1 Channel#6) and ADC1_7(ADC1 Channel#7), the following wiring is additionally required.

TFT ESP32 ESP32S2
LCD_CS(Y+) ADC1_6(GPIO34) ADC1_6(GPIO07)
LCD_RS(X-) ADC1_7(GPIO35) ADC1_7(GPIO08)

No additional wiring is required when using the Wemos D1 ESP32.
LCD_CS is assigned to ADC1_6 and LCD_RS is assigned to ADC1_7.

ILI9486 3.5inch TFT-Shield

There is no marking about 4-line resistance touch screen.
But 4-line resistance touch screen available.

X(+) X(-) Y(+) Y(-)
LCD_D6 LCD_RS LCD_WR LCD_D7

Touch-ILI9486-1

When using ADC1_6(ADC1 Channel#6) and ADC1_7(ADC1 Channel#7), the following wiring is additionally required.

TFT ESP32 ESP32S2
LCD_WR(Y+) ADC1_6(GPIO34) ADC1_6(GPIO07)
LCD_RS(X-) ADC1_7(GPIO35) ADC1_7(GPIO08)

4-line resistance touch screen cannot be used with the Wemos D1 ESP32.
Because the combination of GPIO and ADC does not match.

Other TFT

I don't know which pin is X(+), X(-), Y(+), Y(-).
If you find, please tell me.

Calibrating the touch screen

Keep touching the corner point.
TouchCalib-1 TouchCalib-2

Draw with touch

If there is no touch for 20 seconds, it will end.
Touch-OpenSmat-16pin Touch-OpenSmart-Shield-2 Touch-Elegoo-2 Touch-ILI9341-2 Touch-ILI9486-2

Select with touch

If there is no touch for 20 seconds, it will end.
I borrowed the icon from here.
Touch-Icon-1 Touch-Icon-2

How dose it works

https://www.sparkfun.com/datasheets/LCD/HOW%20DOES%20IT%20WORK.pdf

Application layer

LibraryLayer

Performance comparison using ILI9488(320x480)

Test GPIO parallel REGISTER I/O parallel I2S parallel
AddressTest 1300 430 70
FillTest 5320 2810 1680
ColorBarTest 1290 460 110
ArrowTest 1360 460 210
LineTest 3190 1280 3650
CircleTest 3030 1230 3310
RoundRectTest 3060 1220 3400
RectAngleTest 4110 1890 11480
TriangleTest 4700 2110 13290
DirectionTest 1440 530 340
HorizontalTest 1750 640 740
VerticalTest 1750 640 730
FillRectTest 2340 890 280
ColorTest 2630 970 400
BMPTest 3350 2190 1370
JPEGTest 3870 2990 2630
PNGTest 4310 3450 3050

Performance comparison using ILI9341(240x320)

SPI used this.

Test SPI GPIO parallel REGISTER I/O parallel I2S parallel
FillTest 1620 2700 1920 1560
ColorBarTest 80 420 160 50
ArrowTest 250 460 170 140
LineTest 2690 1040 420 1530
CircleTest 2400 980 410 1370
RoundRectTest 2400 980 400 1390
RectAngleTest 5960 2010 940 6720
TriangleTest 6550 2120 990 7630
DirectionTest 420 520 200 240
HorizontalTest 990 720 300 580
VerticalTest 990 710 300 580
FillRectTest 160 730 300 120
ColorTest 240 850 330 190
BMPTest 1600 1930 1320 960
JPEGTest 2540 2940 2650 2530
PNGTest 2830 3210 2940 2810

Reference about I2S driver

https://github.com/espressif/esp-iot-solution/tree/master/components/bus

  • for esp32
    i2s_lcd_esp32_driver.c
  • for esp32s2
    i2s_lcd_esp32s2_driver.c
  • for esp32s3
    8080_lcd_esp32s3.c
  • Common header
    i2s_lcd_driver.h

esp-idf-parallel-tft's People

Contributors

nopnop2002 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.