1 /**
2  * @file lv_st7796.c
3  *
4  */
5 
6 /*********************
7  *      INCLUDES
8  *********************/
9 #include "lv_st7796.h"
10 
11 #if LV_USE_ST7796
12 
13 /*********************
14  *      DEFINES
15  *********************/
16 
17 #define CMD_FRMCTR1     0xB1
18 #define CMD_FRMCTR2     0xB2
19 #define CMD_FRMCTR3     0xB3
20 #define CMD_INVCTR      0xB4
21 #define CMD_DFUNCTR     0xB6
22 #define CMD_ETMOD       0xB7
23 #define CMD_PWCTR1      0xC0
24 #define CMD_PWCTR2      0xC1
25 #define CMD_PWCTR3      0xC2
26 #define CMD_PWCTR4      0xC3
27 #define CMD_PWCTR5      0xC4
28 #define CMD_VMCTR       0xC5
29 #define CMD_GMCTRP1     0xE0
30 #define CMD_GMCTRN1     0xE1
31 #define CMD_DOCA        0xE8
32 #define CMD_CSCON       0xF0
33 
34 /**********************
35  *      TYPEDEFS
36  **********************/
37 
38 /**********************
39  *  STATIC PROTOTYPES
40  **********************/
41 
42 /**********************
43  *  STATIC CONSTANTS
44  **********************/
45 
46 /* init commands based on LovyanGFX */
47 static const uint8_t init_cmd_list[] = {
48     CMD_CSCON,      1,  0xC3,                           /* Enable extension command 2 partI */
49     CMD_CSCON,      1,  0x96,                           /* Enable extension command 2 partII */
50     CMD_INVCTR,     1,  0x01,                           /* 1-dot inversion */
51     CMD_DFUNCTR,    3,  0x80,                           /* Display Function Control: Bypass */
52     0x22,                           /* Source Output Scan from S1 to S960, Gate Output scan from G1 to G480, scan cycle = 2 */
53     0x3B,                           /* LCD Drive Line = 8 * (59 + 1) */
54     CMD_DOCA,       8,  0x40, 0x8A, 0x00, 0x00,
55     0x29,                           /* Source equalizing period time = 22.5 us */
56     0x19,                           /* Timing for "Gate start" = 25 (Tclk) */
57     0xA5,                           /* Timing for "Gate End" = 37 (Tclk), Gate driver EQ function ON */
58     0x33,
59     CMD_PWCTR2,     1,  0x06,                           /* Power control2: VAP(GVDD) = 3.85 + (vcom + vcom offset), VAN(GVCL) = -3.85 + (vcom + vcom offset) */
60     CMD_PWCTR3,     1,  0xA7,                           /* Power control 3: Source driving current level = low, Gamma driving current level = High */
61     CMD_VMCTR,      1,  0x18,                           /* VCOM Control: VCOM = 0.9 */
62     LV_LCD_CMD_DELAY_MS,    12,                         /* delay 120 ms */
63     CMD_GMCTRP1,    14,                                 /* Gamma */
64     0xF0, 0x09, 0x0B, 0x06, 0x04, 0x15, 0x2F,
65     0x54, 0x42, 0x3C, 0x17, 0x14, 0x18, 0x1B,
66     CMD_GMCTRN1,    14,
67     0xE0, 0x09, 0x0B, 0x06, 0x04, 0x03, 0x2B,
68     0x43, 0x42, 0x3B, 0x16, 0x14, 0x17, 0x1B,
69     LV_LCD_CMD_DELAY_MS, 12,                            /* delay 120 ms */
70     CMD_CSCON,      1,  0x3C,                           /* Disable extension command 2 partI */
71     CMD_CSCON,      1,  0x69,                           /* Disable extension command 2 partII */
72     LV_LCD_CMD_DELAY_MS, LV_LCD_CMD_EOF
73 };
74 
75 /**********************
76  *  STATIC VARIABLES
77  **********************/
78 
79 /**********************
80  *      MACROS
81  **********************/
82 
83 /**********************
84  *   GLOBAL FUNCTIONS
85  **********************/
86 
lv_st7796_create(uint32_t hor_res,uint32_t ver_res,lv_lcd_flag_t flags,lv_st7796_send_cmd_cb_t send_cmd_cb,lv_st7796_send_color_cb_t send_color_cb)87 lv_display_t * lv_st7796_create(uint32_t hor_res, uint32_t ver_res, lv_lcd_flag_t flags,
88                                 lv_st7796_send_cmd_cb_t send_cmd_cb, lv_st7796_send_color_cb_t send_color_cb)
89 {
90     lv_display_t * disp = lv_lcd_generic_mipi_create(hor_res, ver_res, flags, send_cmd_cb, send_color_cb);
91     lv_lcd_generic_mipi_send_cmd_list(disp, init_cmd_list);
92     return disp;
93 }
94 
lv_st7796_set_gap(lv_display_t * disp,uint16_t x,uint16_t y)95 void lv_st7796_set_gap(lv_display_t * disp, uint16_t x, uint16_t y)
96 {
97     lv_lcd_generic_mipi_set_gap(disp, x, y);
98 }
99 
lv_st7796_set_invert(lv_display_t * disp,bool invert)100 void lv_st7796_set_invert(lv_display_t * disp, bool invert)
101 {
102     lv_lcd_generic_mipi_set_invert(disp, invert);
103 }
104 
lv_st7796_set_gamma_curve(lv_display_t * disp,uint8_t gamma)105 void lv_st7796_set_gamma_curve(lv_display_t * disp, uint8_t gamma)
106 {
107     /* NOTE: the generic method is not supported on ST7796, TODO: implement gamma tables */
108     LV_UNUSED(disp);
109     LV_UNUSED(gamma);
110 }
111 
lv_st7796_send_cmd_list(lv_display_t * disp,const uint8_t * cmd_list)112 void lv_st7796_send_cmd_list(lv_display_t * disp, const uint8_t * cmd_list)
113 {
114     lv_lcd_generic_mipi_send_cmd_list(disp, cmd_list);
115 }
116 
117 /**********************
118  *   STATIC FUNCTIONS
119  **********************/
120 
121 #endif /*LV_USE_ST7796*/
122