-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathEcranLCD.h
More file actions
178 lines (162 loc) · 4.85 KB
/
EcranLCD.h
File metadata and controls
178 lines (162 loc) · 4.85 KB
1
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#define LGFX_USE_V1
#include <LovyanGFX.hpp>
//******************************************
// Equivalence ESP32_Type et ScreenType
//******************************************
enum ScreenType {
S028_SCREEN_ILI9341_BL21 = 4,
S028_SCREEN_ST7789_BL21 = 5,
S024_SCREEN_ILI9341_BL27 = 6,
S024_SCREEN_ST7789_BL27 = 7,
S024C_SCREEN_ILI9341_BL27 = 8,
S028C_JC2432W328_ST7789_BL27 = 9,
ESP32_2432S032C_ST7789_BL27 = 101
};
#define LCD_MOSI 13
#define LCD_MISO 12
#define LCD_SCK 14
#define LCD_CS 15
#define LCD_RST -1
#define LCD_DC 2
#define LCD_BL_27 27
#define LCD_BL_21 21
//Resistive Touch
#define TOUCH_CS 33
#define TOUCH_IRQ 36
//pour 024
#define S024_TOUCH_MOSI 13
#define S024_TOUCH_MISO 12
#define S024_TOUCH_SCK 14
//pour 028
#define S028_TOUCH_MOSI 32
#define S028_TOUCH_MISO 39
#define S028_TOUCH_SCK 25
//Capacitive touch
#define I2C_SDA 33 // Touch screen SDA pin
#define I2C_SCL 32 // Touch screen SCL pin
#define TP_RST 25 // Touch screen reset pin
#define TP_INT 21 // Touch screen interrupt pin
#define TOUCH_ADDR 0x5D //GT911_I2C_ADDR_5D
#define I2C_FREQ 400000
class LGFX : public lgfx::LGFX_Device {
private:
lgfx::Bus_SPI _bus;
lgfx::Panel_Device* _panel = nullptr;
lgfx::Light_PWM _light;
lgfx::Touch_XPT2046 _touch; //Touch résistif
public:
LGFX(byte ESP32type) {
ScreenType type = (ScreenType)ESP32type;
initBus();
initPanel(type);
initBacklight(type);
initTouch(type);
}
private:
void initBus() {
auto cfg = _bus.config();
cfg.spi_host = HSPI_HOST;
cfg.spi_mode = 3; // 3 pour ST7789, 0 pour ILI9341(? à tester)
cfg.freq_write = 40000000;
cfg.freq_read = 16000000;
cfg.spi_3wire = true;
cfg.use_lock = true;
cfg.dma_channel = 1;
cfg.pin_sclk = LCD_SCK;
cfg.pin_mosi = LCD_MOSI;
cfg.pin_miso = LCD_MISO;
cfg.pin_dc = LCD_DC;
_bus.config(cfg);
}
void initPanel(ScreenType type) {
if (type == S028_SCREEN_ST7789_BL21 || type == S024_SCREEN_ST7789_BL27 || type == S028C_JC2432W328_ST7789_BL27 || type == ESP32_2432S032C_ST7789_BL27) {
auto* p = new lgfx::Panel_ST7789();
auto cfg = p->config();
cfg.pin_cs = LCD_CS;
cfg.pin_rst = LCD_RST;
cfg.pin_busy = -1;
cfg.memory_width = 240;
cfg.memory_height = 320;
cfg.panel_width = 240;
cfg.panel_height = 320;
cfg.offset_x = 0;
cfg.offset_y = 0;
cfg.offset_rotation = 0;
cfg.dummy_read_pixel = 8;
cfg.dummy_read_bits = 1;
cfg.readable = true;
cfg.invert = false;
if (type == ESP32_2432S032C_ST7789_BL27) cfg.invert = true;
cfg.rgb_order = false;
cfg.dlen_16bit = false;
cfg.bus_shared = true;
p->config(cfg);
p->setBus(&_bus);
_panel = p;
} else if (type == S028_SCREEN_ILI9341_BL21 || type == S024_SCREEN_ILI9341_BL27 || type == S024C_SCREEN_ILI9341_BL27) {
auto* p = new lgfx::Panel_ILI9341();
auto cfg = p->config();
cfg.pin_cs = LCD_CS;
cfg.pin_rst = LCD_RST;
cfg.pin_busy = -1;
cfg.memory_width = 240;
cfg.memory_height = 320;
cfg.panel_width = 240;
cfg.panel_height = 320;
cfg.offset_x = 0;
cfg.offset_y = 0;
cfg.offset_rotation = 0;
cfg.dummy_read_pixel = 8;
cfg.dummy_read_bits = 1;
cfg.readable = true;
cfg.invert = false;
cfg.rgb_order = false;
cfg.dlen_16bit = false;
cfg.bus_shared = true;
p->config(cfg);
p->setBus(&_bus);
_panel = p;
}
setPanel(_panel);
}
void initBacklight(ScreenType type) {
auto cfg = _light.config();
if (type == S024_SCREEN_ILI9341_BL27 || type == S024_SCREEN_ST7789_BL27 || type == S024C_SCREEN_ILI9341_BL27 || type== S028C_JC2432W328_ST7789_BL27 || type == ESP32_2432S032C_ST7789_BL27) {
cfg.pin_bl = LCD_BL_27;
} else {
cfg.pin_bl = LCD_BL_21;
}
cfg.invert = false;
cfg.freq = 44100;
cfg.pwm_channel = 7;
_light.config(cfg);
_panel->setLight(&_light);
}
void initTouch(ScreenType type) {
if (type != S024C_SCREEN_ILI9341_BL27 && type !=S028C_JC2432W328_ST7789_BL27 && type != ESP32_2432S032C_ST7789_BL27) { //Touch resistifs seulement
auto cfg = _touch.config();
cfg.x_min = 0;
cfg.x_max = 239;
cfg.y_min = 0;
cfg.y_max = 319;
cfg.pin_int = TOUCH_IRQ;
cfg.bus_shared = true;
cfg.offset_rotation = 0;
cfg.freq = 1000000;
if (type == S028_SCREEN_ILI9341_BL21 || type == S028_SCREEN_ST7789_BL21) {
cfg.spi_host = VSPI_HOST;
cfg.pin_sclk = S028_TOUCH_SCK;
cfg.pin_mosi = S028_TOUCH_MOSI;
cfg.pin_miso = S028_TOUCH_MISO;
} else {
cfg.spi_host = HSPI_HOST;
cfg.pin_sclk = S024_TOUCH_SCK;
cfg.pin_mosi = S024_TOUCH_MOSI;
cfg.pin_miso = S024_TOUCH_MISO;
}
cfg.pin_cs = TOUCH_CS;
_touch.config(cfg);
_panel->setTouch(&_touch);
}
}
};