1.8-inch Color Touch Display
Module Source
Purchase link: https://item.taobao.com/item.htm?spm=a1z10.3-c-s.w4002-23991449512.20.62ae703buie1Ei&id=568584833602 Materials download link: https://pan.baidu.com/s/1n_vp38V7ij88PUGpbJPd7Q Materials extraction code: 8888
Specifications
File 7.2-1 Screen Specification Operating voltage: 3.3V Operating current: 30 mA Module size: 35(H) x 56(V) mm Pixel size: 128(H) x 160(V) RGB Driver chip: ST7735S Communication protocol: SPI Number of pins: 12 Pin (2.54mm pitch header) Resistive touch chip: XPT2046
Principle Analysis
Similar to I2C, SPI also has both software SPI and hardware SPI.
The ESP32-S3 chip integrates four SPI controllers: • SPI0 • SPI1 • General-purpose SPI2, i.e., GP-SPI2 • General-purpose SPI3, i.e., GP-SPI3
The SPI0 and SPI1 controllers are mainly used internally to access external flash and PSRAM. We can only use SPI2 and SPI3. Hardware SPI supports the following features:
Porting Process
Our goal is to port the example to the ESP32-S3 dev board. Complete driver code has been provided for you. Follow the steps below to complete the porting.
Software SPI Porting
This screen requires 12 interfaces. For specific interface descriptions, see Table 7.4.1-1 Pin Descriptions.
The pins selected here are shown in Table 7.4.1-2 Software SPI Wiring.
Copy the prepared [OLED] and [TOUCH] folders into the main folder of your project. Software SPI driver code:
File Download
📌 Materials Download Center (Click to Jump)
📌 In the Materials Download Center -> Module Porting Materials Download, inside the compressed package of this chapter.
Copy the LCD folder and TOUCH folder under the main folder:
Open your project and import the files we just copied into the .c and .h file paths.
- In VSCode, open the CMakeLists.txt file in the main folder.
- Add these paths.
The porting is now complete. Please proceed to section 7.5 for porting verification.
Porting Verification
Enter the following code in main.c:
#include <stdio.h>
#include <inttypes.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
#include "esp_timer.h"
#include "lcd_init.h"
#include "lcd.h"
#include "pic.h"
#include "touch.h"
void app_main(void)
{
float t=0;
u16 lastpos[2];// Last recorded position
LCD_Init();// Initialize the LCD
LCD_Fill(0,0,LCD_W,LCD_H,WHITE);
lastpos[0]=0XFFFF;
// LCD_ShowChinese(0,0,(uint8_t *)"中景园电子",RED,WHITE,24,0);
// LCD_ShowString(24,30,(uint8_t *)"LCD_W:",RED,WHITE,16,0);
// LCD_ShowIntNum(72,30,LCD_W,3,RED,WHITE,16);
// LCD_ShowString(24,50,(uint8_t *)"LCD_H:",RED,WHITE,16,0);
// LCD_ShowIntNum(72,50,LCD_H,3,RED,WHITE,16);
// LCD_ShowFloatNum1(20,80,t,4,RED,WHITE,16);
// t+=0.11;
// LCD_ShowPicture(65,80,40,40,gImage_1);
// delay_ms(1000);
// LCD_Fill(0,0,LCD_W,LCD_H,WHITE);
TP_Init();
LCD_ShowString(10,LCD_H-40,(uint8_t *)"X:",RED,WHITE,16,0);
LCD_ShowIntNum(26,LCD_H-40,0,3,RED,WHITE,16);
LCD_ShowString(10,LCD_H-20,(uint8_t *)"Y:",RED,WHITE,16,0);
LCD_ShowIntNum(26,LCD_H-20,0,3,RED,WHITE,16);
while(1)
{
tp_dev.scan(0);// Scan
if(tp_dev.sta&TP_PRES_DOWN)// A touch is detected
{
delay_ms(1);// Necessary delay, otherwise it always thinks a key is pressed.
if((tp_dev.x[0]<(LCD_W-1)&&tp_dev.x[0]>=1)&&(tp_dev.y[0]<(LCD_H-1)&&tp_dev.y[0]>=1))
{
if(lastpos[0]==0XFFFF)
{
lastpos[0]=tp_dev.x[0];
lastpos[1]=tp_dev.y[0];
}
LCD_DrawRoughLine(lastpos[0],lastpos[1],tp_dev.x[0],tp_dev.y[0],BLUE);// Draw a line
lastpos[0]=tp_dev.x[0];
lastpos[1]=tp_dev.y[0];
LCD_ShowString(10,LCD_H-40,(uint8_t *)"X:",RED,WHITE,16,0);
LCD_ShowIntNum(26,LCD_H-40,tp_dev.x[0],3,RED,WHITE,16);
LCD_ShowString(10,LCD_H-20,(uint8_t *)"Y:",RED,WHITE,16,0);
LCD_ShowIntNum(26,LCD_H-20,tp_dev.y[0],3,RED,WHITE,16);
}
}
delay_ms(100);
}
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Power-on effect: