1 /**
2  * @file lv_ili9341.c
3  *
4  */
5 
6 /*********************
7  *      INCLUDES
8  *********************/
9 #include "lv_ili9341.h"
10 
11 #if LV_USE_ILI9341
12 
13 /*********************
14  *      DEFINES
15  *********************/
16 
17 #define CMD_FRMCTR1     0xB1    /* Frame Rate Control (In Normal Mode/Full Colors) */
18 #define CMD_FRMCTR2     0xB2    /* Frame Rate Control (In Idle Mode/8 colors) */
19 #define CMD_FRMCTR3     0xB3    /* Frame Rate control (In Partial Mode/Full Colors) */
20 #define CMD_INVCTR      0xB4    /* Display Inversion Control */
21 #define CMD_DFUNCTR     0xB6    /* Display Function Control */
22 #define CMD_PWCTR1      0xC0    /* Power Control 1 */
23 #define CMD_PWCTR2      0xC1    /* Power Control 2 */
24 #define CMD_VMCTR1      0xC5    /* VCOM Control 1 */
25 #define CMD_VMCTR2      0xC7    /* VCOM Control 2 */
26 #define CMD_PWCTRA      0xCB    /* Power Control A */
27 #define CMD_PWCTRB      0xCF    /* Power Control B */
28 #define CMD_GMCTRP1     0xE0    /* Positive Gamma Correction */
29 #define CMD_GMCTRN1     0xE1    /* Negative Gamma Correction */
30 #define CMD_DTCTRA      0xE8    /* Driver timing control A */
31 #define CMD_DTCTRB      0xEA    /* Driver timing control B */
32 #define CMD_PONSEQ      0xED    /* Power On Sequence */
33 #define CMD_RDINDEX     0xD9    /* ili9341 */
34 #define CMD_IDXRD       0xDD    /* ILI9341 only, indexed control register read */
35 #define CMD_ENA3G       0xF2    /* Enable 3 Gamma control */
36 #define CMD_IFCTR       0xF6    /* Interface Control */
37 #define CMD_PRCTR       0xF7    /* Pump ratio control */
38 
39 /**********************
40  *      TYPEDEFS
41  **********************/
42 
43 /**********************
44  *  STATIC PROTOTYPES
45  **********************/
46 
47 /**********************
48  *  STATIC CONSTANTS
49  **********************/
50 
51 /* init commands based on LovyanGFX ILI9341 driver */
52 static const uint8_t init_cmd_list[] = {
53     CMD_PWCTRB,     3,  0x00, 0xC1, 0x30,
54     CMD_PONSEQ,     4,  0x64, 0x03, 0x12, 0x81,
55     CMD_DTCTRA,     3,  0x85, 0x00, 0x78,
56     CMD_PWCTRA,     5,  0x39, 0x2C, 0x00, 0x34, 0x02,
57     CMD_PRCTR,      1,  0x20,
58     CMD_DTCTRB,     2,  0x00, 0x00,
59     CMD_PWCTR1,     1,  0x23,
60     CMD_PWCTR2,     1,  0x10,
61     CMD_VMCTR1,     2,  0x3e, 0x28,
62     CMD_VMCTR2,     1,  0x86,
63     CMD_FRMCTR1,    2,  0x00, 0x13,
64     CMD_DFUNCTR,    2,  0x0A, 0xA2,
65     CMD_IFCTR,      3,  0x09, 0x30, 0x00,
66     CMD_ENA3G,      1,  0x00,
67     LV_LCD_CMD_SET_GAMMA_CURVE, 1, 0x01,
68     CMD_GMCTRP1,    15, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00,
69     CMD_GMCTRN1,    15, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F,
70     LV_LCD_CMD_DELAY_MS, LV_LCD_CMD_EOF
71 };
72 
73 /**********************
74  *  STATIC VARIABLES
75  **********************/
76 
77 /**********************
78  *      MACROS
79  **********************/
80 
81 /**********************
82  *   GLOBAL FUNCTIONS
83  **********************/
84 
lv_ili9341_create(uint32_t hor_res,uint32_t ver_res,lv_lcd_flag_t flags,lv_ili9341_send_cmd_cb_t send_cmd_cb,lv_ili9341_send_color_cb_t send_color_cb)85 lv_display_t * lv_ili9341_create(uint32_t hor_res, uint32_t ver_res, lv_lcd_flag_t flags,
86                                  lv_ili9341_send_cmd_cb_t send_cmd_cb, lv_ili9341_send_color_cb_t send_color_cb)
87 {
88     lv_display_t * disp = lv_lcd_generic_mipi_create(hor_res, ver_res, flags, send_cmd_cb, send_color_cb);
89     lv_lcd_generic_mipi_send_cmd_list(disp, init_cmd_list);
90     return disp;
91 }
92 
lv_ili9341_set_gap(lv_display_t * disp,uint16_t x,uint16_t y)93 void lv_ili9341_set_gap(lv_display_t * disp, uint16_t x, uint16_t y)
94 {
95     lv_lcd_generic_mipi_set_gap(disp, x, y);
96 }
97 
lv_ili9341_set_invert(lv_display_t * disp,bool invert)98 void lv_ili9341_set_invert(lv_display_t * disp, bool invert)
99 {
100     lv_lcd_generic_mipi_set_invert(disp, invert);
101 }
102 
lv_ili9341_set_gamma_curve(lv_display_t * disp,uint8_t gamma)103 void lv_ili9341_set_gamma_curve(lv_display_t * disp, uint8_t gamma)
104 {
105     lv_lcd_generic_mipi_set_gamma_curve(disp, gamma);
106 }
107 
lv_ili9341_send_cmd_list(lv_display_t * disp,const uint8_t * cmd_list)108 void lv_ili9341_send_cmd_list(lv_display_t * disp, const uint8_t * cmd_list)
109 {
110     lv_lcd_generic_mipi_send_cmd_list(disp, cmd_list);
111 }
112 
113 /**********************
114  *   STATIC FUNCTIONS
115  **********************/
116 
117 #endif /*LV_USE_ILI9341*/
118