1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017,2019, 2022 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #include "fsl_ili9341.h"
10 
FT9341_Init(ili9341_send_byte_t _writeData,ili9341_send_byte_t _writeCommand)11 void FT9341_Init(ili9341_send_byte_t _writeData, ili9341_send_byte_t _writeCommand)
12 {
13     SDK_DelayAtLeastUs(ILI9341_RESET_CANCEL_MS * 1000U, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
14 
15     _writeCommand(ILI9341_CMD_PWRA);
16     _writeData(0x39);
17     _writeData(0x2C);
18     _writeData(0x00);
19     _writeData(0x34);
20     _writeData(0x02);
21     _writeCommand(ILI9341_CMD_PWRB);
22     _writeData(0x00);
23     _writeData(0xC1);
24     _writeData(0x30);
25     _writeCommand(ILI9341_CMD_DTCA);
26     _writeData(0x85);
27     _writeData(0x00);
28     _writeData(0x78);
29     _writeCommand(ILI9341_CMD_DTCB);
30     _writeData(0x00);
31     _writeData(0x00);
32     _writeCommand(ILI9341_CMD_PWRSEQ);
33     _writeData(0x64);
34     _writeData(0x03);
35     _writeData(0x12);
36     _writeData(0x81);
37     _writeCommand(ILI9341_CMD_PRC);
38     _writeData(0x20);
39     _writeCommand(ILI9341_CMD_PWR1);
40     _writeData(0x23);
41     _writeCommand(ILI9341_CMD_PWR2);
42     _writeData(0x10);
43     _writeCommand(ILI9341_CMD_VCOM1);
44     _writeData(0x3E);
45     _writeData(0x28);
46     _writeCommand(ILI9341_CMD_VCOM2);
47     _writeData(0x86);
48     _writeCommand(ILI9341_CMD_MAC);
49     _writeData(0x40);
50     _writeCommand(ILI9341_CMD_PIXELFORMAT);
51     _writeData(0x55);
52     _writeCommand(ILI9341_CMD_FRC);
53     _writeData(0x00);
54     _writeData(0x18);
55     _writeCommand(ILI9341_CMD_DFC);
56     _writeData(0x08);
57     _writeData(0x82);
58     _writeData(0x27);
59     _writeCommand(ILI9341_CMD_3GAMMAEN);
60     _writeData(0x00);
61     _writeCommand(ILI9341_CMD_COLADDR);
62     _writeData(0x00);
63     _writeData(0x00);
64     _writeData(0x00);
65     _writeData(0xEF);
66     _writeCommand(ILI9341_CMD_PAGEADDR);
67     _writeData(0x00);
68     _writeData(0x00);
69     _writeData(0x01);
70     _writeData(0x3F);
71     _writeCommand(ILI9341_CMD_GAMMA);
72     _writeData(0x01);
73     _writeCommand(ILI9341_CMD_PGAMMA);
74     _writeData(0x0F);
75     _writeData(0x31);
76     _writeData(0x2B);
77     _writeData(0x0C);
78     _writeData(0x0E);
79     _writeData(0x08);
80     _writeData(0x4E);
81     _writeData(0xF1);
82     _writeData(0x37);
83     _writeData(0x07);
84     _writeData(0x10);
85     _writeData(0x03);
86     _writeData(0x0E);
87     _writeData(0x09);
88     _writeData(0x00);
89     _writeCommand(ILI9341_CMD_NGAMMA);
90     _writeData(0x00);
91     _writeData(0x0E);
92     _writeData(0x14);
93     _writeData(0x03);
94     _writeData(0x11);
95     _writeData(0x07);
96     _writeData(0x31);
97     _writeData(0xC1);
98     _writeData(0x48);
99     _writeData(0x08);
100     _writeData(0x0F);
101     _writeData(0x0C);
102     _writeData(0x31);
103     _writeData(0x36);
104     _writeData(0x0F);
105     _writeCommand(ILI9341_CMD_SLEEPOUT);
106     _writeCommand(ILI9341_CMD_DISPLAYON);
107 }
108 
FT9341_Init1(ili9341_send_cmd_data_t sendCmdData)109 void FT9341_Init1(ili9341_send_cmd_data_t sendCmdData)
110 {
111     SDK_DelayAtLeastUs(ILI9341_RESET_CANCEL_MS * 1000U, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
112 
113     sendCmdData(ILI9341_CMD_PWRA, (const uint8_t[]){0x39U, 0x2CU, 0x00U, 0x34U, 0x02U}, 5u);
114     sendCmdData(ILI9341_CMD_PWRB, (const uint8_t[]){0x00U, 0xc1U, 0x30U}, 3u);
115     sendCmdData(ILI9341_CMD_DTCA, (const uint8_t[]){0x85U, 0x00U, 0x78U}, 3u);
116     sendCmdData(ILI9341_CMD_DTCB, (const uint8_t[]){0x00U, 0x00U}, 2u);
117     sendCmdData(ILI9341_CMD_PWRSEQ, (const uint8_t[]){0x64U, 0x03U, 0x12U, 0x81U}, 4u);
118     sendCmdData(ILI9341_CMD_PRC, (const uint8_t[]){0x20U}, 1u);
119     sendCmdData(ILI9341_CMD_PWR1, (const uint8_t[]){0x23U}, 1u);
120     sendCmdData(ILI9341_CMD_PWR2, (const uint8_t[]){0x10U}, 1u);
121     sendCmdData(ILI9341_CMD_VCOM1, (const uint8_t[]){0x3EU, 0x28U}, 2u);
122     sendCmdData(ILI9341_CMD_VCOM2, (const uint8_t[]){0x86U}, 1u);
123     sendCmdData(ILI9341_CMD_MAC, (const uint8_t[]){0x40U}, 1u);
124     sendCmdData(ILI9341_CMD_PIXELFORMAT, (const uint8_t[]){0x55U}, 1u);
125     sendCmdData(ILI9341_CMD_FRC, (const uint8_t[]){0x00U, 0x18U}, 2u);
126     sendCmdData(ILI9341_CMD_DFC, (const uint8_t[]){0x08U, 0x82U, 0x27U}, 3u);
127     sendCmdData(ILI9341_CMD_3GAMMAEN, (const uint8_t[]){0x00U}, 1u);
128     sendCmdData(ILI9341_CMD_COLADDR, (const uint8_t[]){0x00U, 0x00U, 0x00U, 0xEFU}, 4u);
129     sendCmdData(ILI9341_CMD_PAGEADDR, (const uint8_t[]){0x00U, 0x00U, 0x01U, 0x3FU}, 4u);
130     sendCmdData(ILI9341_CMD_GAMMA, (const uint8_t[]){0x01U}, 1u);
131     sendCmdData(ILI9341_CMD_PGAMMA,
132                 (const uint8_t[]){0x0FU, 0x31U, 0x2BU, 0x0CU, 0x0EU, 0x08U, 0x4EU, 0xF1U, 0x37U, 0x07U, 0x10U, 0x03U,
133                                   0x0EU, 0x09U, 0x00U},
134                 15u);
135     sendCmdData(ILI9341_CMD_NGAMMA,
136                 (const uint8_t[]){0x00U, 0x0EU, 0x14U, 0x03U, 0x11U, 0x07U, 0x31U, 0xC1U, 0x48U, 0x08U, 0x0FU, 0x0CU,
137                                   0x31U, 0x36U, 0x0FU},
138                 15u);
139 
140     sendCmdData(ILI9341_CMD_SLEEPOUT, NULL, 0U);
141     sendCmdData(ILI9341_CMD_DISPLAYON, NULL, 0U);
142 }
143