Skip to content

Commit b59cdc5

Browse files
committed
[P095] Add ILI9342 display variants
1 parent 5d5e58e commit b59cdc5

File tree

5 files changed

+119
-2
lines changed

5 files changed

+119
-2
lines changed

lib/Adafruit_ILI9341/Adafruit_ILI9341.cpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,83 @@ static const uint8_t PROGMEM initcmd_9342[] = { // ILI9342
238238

239239
// clang-format on
240240

241+
#ifdef ESP32
242+
// clang-format off
243+
static const uint8_t PROGMEM initcmd_9342_2[] = { // ILI9342_2 (CYD/Adafruit)
244+
0xEF, 3, 0x03, 0x80, 0x02,
245+
0xCF, 3, 0x00, 0xC1, 0x30,
246+
0xED, 4, 0x64, 0x03, 0x12, 0x81,
247+
0xE8, 3, 0x85, 0x00, 0x78,
248+
0xCB, 5, 0x39, 0x2C, 0x00, 0x34, 0x02,
249+
0xF7, 1, 0x20,
250+
0xEA, 2, 0x00, 0x00,
251+
ILI9341_PWCTR1, 1, 0x23, // Power control VRH[5:0]
252+
ILI9341_PWCTR2, 1, 0x10, // Power control SAP[2:0];BT[3:0]
253+
ILI9341_VMCTR1, 2, 0x2B, 0x2B, // VCM control
254+
ILI9341_VMCTR2, 1, 0xC0, // VCM control2
255+
ILI9341_MADCTL, 1, (MADCTL_MX | MADCTL_BGR), // Memory Access Control
256+
ILI9341_VSCRSADD, 1, 0x00, // Vertical scroll zero
257+
ILI9341_PIXFMT, 1, 0x55,
258+
ILI9341_FRMCTR1, 2, 0x00, 0x1B,
259+
ILI9341_DFUNCTR, 3, 0x08, 0x82, 0x27, // Display Function Control
260+
0xF2, 1, 0x00, // 3Gamma Function Disable
261+
ILI9341_GAMMASET, 1, 0x01, // Gamma curve selected
262+
ILI9341_GMCTRP1, 15, 0x0F, 0x31, 0x2B, 0x0C, 0x0E,
263+
0x08,
264+
0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E,
265+
0x09, 0x00, //
266+
// Set
267+
// Gamma
268+
ILI9341_GMCTRN1, 15, 0x00, 0x0E, 0x14, 0x03, 0x11,
269+
0x07,
270+
0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31,
271+
0x36, 0x0F, // Set Gamma
272+
ILI9341_SLPOUT, 0x80, // Exit Sleep
273+
ILI9341_DISPON, 0x80, // Display on
274+
0x00 // End of list
275+
};
276+
277+
// clang-format on
278+
// clang-format off
279+
static const uint8_t PROGMEM initcmd_9342_3[] = { // ILI9342_3 (CYD/Bodmer)
280+
0xEF, 3, 0x03, 0x80, 0x02,
281+
0xCF, 3, 0x00, 0xC1, 0x30,
282+
0xED, 4, 0x64, 0x03, 0x12, 0x81,
283+
0xE8, 3, 0x85, 0x00, 0x78,
284+
0xCB, 5, 0x39, 0x2C, 0x00, 0x34, 0x02,
285+
0xF7, 1, 0x20,
286+
0xEA, 2, 0x00, 0x00,
287+
ILI9341_PWCTR1, 1, 0x10, // Power control VRH[5:0]
288+
ILI9341_PWCTR2, 1, 0x00, // Power control SAP[2:0];BT[3:0]
289+
ILI9341_VMCTR1, 2, 0x30, 0x30, // VCM control
290+
ILI9341_VMCTR2, 1, 0xB7, // VCM control2
291+
ILI9341_MADCTL, 1, (MADCTL_BGR), // Memory Access Control
292+
// ILI9341_VSCRSADD, 1, 0x00, // Vertical scroll zero
293+
ILI9341_PIXFMT, 1, 0x55,
294+
ILI9341_FRMCTR1, 2, 0x00, 0x1A,
295+
ILI9341_DFUNCTR, 3, 0x08, 0x82, 0x27, // Display Function Control
296+
0xF2, 1, 0x00, // 3Gamma Function Disable
297+
ILI9341_GAMMASET, 1, 0x01, // Gamma curve selected
298+
ILI9341_GMCTRP1, 15, 0x0F, 0x2A, 0x28, 0x08, 0x0E,
299+
0x08,
300+
0x54, 0xA9, 0x43, 0x0A, 0x0F, 0x00, 0x00,
301+
0x00, 0x00, //
302+
// Set
303+
// Gamma
304+
ILI9341_GMCTRN1, 15, 0x00, 0x15, 0x17, 0x07, 0x11,
305+
0x06,
306+
0x2B, 0x56, 0x3C, 0x05, 0x10, 0x0F, 0x3F,
307+
0x3F, 0x0F, // Set Gamma
308+
ILI9341_PASET, 4, 0x00, 0x00, 0x01, 0x3F,
309+
ILI9341_CASET, 4, 0x00, 0x00, 0x00, 0xEF,
310+
ILI9341_SLPOUT, 0x80, // Exit Sleep
311+
ILI9341_DISPON, 0x80, // Display on
312+
0x00 // End of list
313+
};
314+
315+
// clang-format on
316+
#endif // ifdef ESP32
317+
241318
// clang-format off
242319
static const uint8_t PROGMEM initcmd_9481[] = { // ILI9481
243320
ILI9341_SLPOUT, 0x80, // Exit Sleep
@@ -478,6 +555,14 @@ void Adafruit_ILI9341::begin(uint32_t freq) {
478555
case ILI_TYPE_9342: // ILI9342 M5STACK
479556
addr = initcmd_9342;
480557
break;
558+
#ifdef ESP32
559+
case ILI_TYPE_9342_2: // ILI9342 CYD/Adafruit
560+
addr = initcmd_9342_2;
561+
break;
562+
case ILI_TYPE_9342_3: // ILI9342 CYD/Bodmer
563+
addr = initcmd_9342_3;
564+
break;
565+
#endif // ifdef ESP32
481566
case ILI_TYPE_9481: // ILI9481
482567
addr = initcmd_9481;
483568
break;
@@ -540,6 +625,9 @@ void Adafruit_ILI9341::setRotation(uint8_t m) {
540625
case ILI_TYPE_9342: // ILI9342 M5STACK
541626
m = (MADCTL_MY | MADCTL_MV | MADCTL_BGR);
542627
break;
628+
case ILI_TYPE_9342_2: // ILI9342 CYD/Adafruit
629+
m = (MADCTL_BGR);
630+
break;
543631
case ILI_TYPE_9481: // ILI9481
544632
case ILI_TYPE_9481_CPT29: // ILI9481 CPT29
545633
case ILI_TYPE_9481_PVI35: // ILI9481 PVI35
@@ -551,6 +639,7 @@ void Adafruit_ILI9341::setRotation(uint8_t m) {
551639
m = (MADCTL_SS | MADCTL_BGR);
552640
break;
553641
case ILI_TYPE_9341: // ILI9341
642+
case ILI_TYPE_9342_3: // ILI9342 CYD/Bodmer
554643
// m = (MADCTL_MX | MADCTL_BGR);
555644
// break;
556645
default:
@@ -577,6 +666,8 @@ void Adafruit_ILI9341::setRotation(uint8_t m) {
577666
// m = (MADCTL_MV | MADCTL_BGR);
578667
// break;
579668
case ILI_TYPE_9341: // ILI9341
669+
case ILI_TYPE_9342_2: // ILI9342 CYD/Adafruit
670+
case ILI_TYPE_9342_3: // ILI9342 CYD/Bodmer
580671
// m = (MADCTL_MV | MADCTL_BGR);
581672
// break;
582673
default:
@@ -603,6 +694,8 @@ void Adafruit_ILI9341::setRotation(uint8_t m) {
603694
m = (MADCTL_GS | MADCTL_BGR);
604695
break;
605696
case ILI_TYPE_9341: // ILI9341
697+
case ILI_TYPE_9342_2: // ILI9342 CYD/Adafruit
698+
case ILI_TYPE_9342_3: // ILI9342 CYD/Bodmer
606699
// m = (MADCTL_MY | MADCTL_BGR);
607700
// break;
608701
default:
@@ -629,6 +722,8 @@ void Adafruit_ILI9341::setRotation(uint8_t m) {
629722
m = (MADCTL_SS | MADCTL_GS | MADCTL_MV | MADCTL_BGR);
630723
break;
631724
case ILI_TYPE_9341: // ILI9341
725+
case ILI_TYPE_9342_2: // ILI9342 CYD/Adafruit
726+
case ILI_TYPE_9342_3: // ILI9342 CYD/Bodmer
632727
// m = (MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR);
633728
// break;
634729
default:

lib/Adafruit_ILI9341/Adafruit_ILI9341.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@
128128

129129
#define ILI_TYPE_9341 0 // MUST match with enum class ILI9xxx_type_e in P095_data_struct.h !
130130
#define ILI_TYPE_9342 1
131+
#define ILI_TYPE_9342_2 12 // !! ONLY enabled on ESP32 for size reasons !!
132+
#define ILI_TYPE_9342_3 13 // !! ONLY enabled on ESP32 for size reasons !!
131133
#define ILI_TYPE_9481 2
132134
#define ILI_TYPE_9481_CPT29 3
133135
#define ILI_TYPE_9481_PVI35 4

src/_P095_ILI9341.ino

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ boolean Plugin_095(uint8_t function, struct EventStruct *event, String& string)
229229
const __FlashStringHelper *hardwareTypes[] = {
230230
ILI9xxx_type_toString(ILI9xxx_type_e::ILI9341_240x320),
231231
ILI9xxx_type_toString(ILI9xxx_type_e::ILI9342_240x320),
232+
# if P095_ENABLE_ILI9342_2
233+
ILI9xxx_type_toString(ILI9xxx_type_e::ILI9342_CYD_AF_240x320),
234+
ILI9xxx_type_toString(ILI9xxx_type_e::ILI9342_CYD_BD_240x320),
235+
# endif // if P095_ENABLE_ILI9342_2
232236
ILI9xxx_type_toString(ILI9xxx_type_e::ILI9481_320x480),
233237
ILI9xxx_type_toString(ILI9xxx_type_e::ILI9481_CPT29_320x480),
234238
ILI9xxx_type_toString(ILI9xxx_type_e::ILI9481_PVI35_320x480),
@@ -246,6 +250,10 @@ boolean Plugin_095(uint8_t function, struct EventStruct *event, String& string)
246250
constexpr int hardwareOptions[] = {
247251
static_cast<int>(ILI9xxx_type_e::ILI9341_240x320),
248252
static_cast<int>(ILI9xxx_type_e::ILI9342_240x320),
253+
# if P095_ENABLE_ILI9342_2
254+
static_cast<int>(ILI9xxx_type_e::ILI9342_CYD_AF_240x320),
255+
static_cast<int>(ILI9xxx_type_e::ILI9342_CYD_BD_240x320),
256+
# endif // if P095_ENABLE_ILI9342_2
249257
static_cast<int>(ILI9xxx_type_e::ILI9481_320x480),
250258
static_cast<int>(ILI9xxx_type_e::ILI9481_CPT29_320x480),
251259
static_cast<int>(ILI9xxx_type_e::ILI9481_PVI35_320x480),
@@ -262,8 +270,8 @@ boolean Plugin_095(uint8_t function, struct EventStruct *event, String& string)
262270
};
263271
constexpr size_t optionCount = NR_ELEMENTS(hardwareOptions);
264272
const FormSelectorOptions selector(optionCount,
265-
hardwareTypes,
266-
hardwareOptions);
273+
hardwareTypes,
274+
hardwareOptions);
267275
selector.addFormSelector(
268276
F("TFT display model"),
269277
F("dsptype"),

src/src/PluginStructs/P095_data_struct.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ const __FlashStringHelper* ILI9xxx_type_toString(const ILI9xxx_type_e& device) {
99
switch (device) {
1010
case ILI9xxx_type_e::ILI9341_240x320: return F("ILI9341 240 x 320px");
1111
case ILI9xxx_type_e::ILI9342_240x320: return F("ILI9342 240 x 320px (M5Stack)");
12+
# if P095_ENABLE_ILI9342_2
13+
case ILI9xxx_type_e::ILI9342_CYD_AF_240x320: return F("ILI9342 240 x 320px (CYD-1)");
14+
case ILI9xxx_type_e::ILI9342_CYD_BD_240x320: return F("ILI9342 240 x 320px (CYD-2)");
15+
# endif // if P095_ENABLE_ILI9342_2
1216
case ILI9xxx_type_e::ILI9481_320x480: return F("ILI9481 320 x 480px");
1317
case ILI9xxx_type_e::ILI9481_CPT29_320x480: return F("ILI9481 320 x 480px (CPT29)");
1418
case ILI9xxx_type_e::ILI9481_PVI35_320x480: return F("ILI9481 320 x 480px (PVI35)");

src/src/PluginStructs/P095_data_struct.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
# define P095_ENABLE_ILI948X 0 // Not enabled for limited buildsizes
2323
# endif // if defined(LIMIT_BUILD_SIZE) && P095_ENABLE_ILI948X && !defined(PLUGIN_BUILD_CUSTOM)
2424

25+
# if !defined(P095_ENABLE_ILI9342_2) && defined(ESP32)
26+
# define P095_ENABLE_ILI9342_2 1
27+
# endif // if !defined(P095_ENABLE_ILI9342_2) && defined(ESP32)
28+
2529
# if P095_ENABLE_ILI948X
2630
# include <ILI9488.h> // Specific behavior: ILI9488 needs 24 bit colors in SPI mode
2731
# endif // if P095_ENABLE_ILI948X
@@ -97,6 +101,10 @@ enum class ILI9xxx_type_e : uint8_t {
97101
// ILI9486_320x480 = 10u,
98102
ILI9488_320x480 = 11u, // Uses a separate library for having a 16 bit data interface
99103
# endif // if P095_ENABLE_ILI948X
104+
# if P095_ENABLE_ILI9342_2
105+
ILI9342_CYD_AF_240x320 = 12u,
106+
ILI9342_CYD_BD_240x320 = 13u,
107+
# endif // if P095_ENABLE_ILI9342_2
100108
};
101109

102110
enum class P095_CommandTrigger : uint8_t {

0 commit comments

Comments
 (0)