1 /**
2  * @file lv_st7789.c
3  *
4  */
5 
6 /*********************
7  *      INCLUDES
8  *********************/
9 #include "lv_st7789.h"
10 
11 #if LV_USE_ST7789
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 #define CMD_RAMCTRL     0xB0
35 #define CMD_PORCTRL     0xB2    /* Porch control */
36 #define CMD_GCTRL       0xB7    /* Gate control */
37 #define CMD_VCOMS       0xBB    /* VCOMS setting */
38 #define CMD_LCMCTRL     0xC0    /* LCM control */
39 #define CMD_VDVVRHEN    0xC2    /* VDV and VRH command enable */
40 #define CMD_VRHS        0xC3    /* VRH set */
41 #define CMD_VDVSET      0xC4    /* VDV setting */
42 #define CMD_FRCTR2      0xC6    /* FR Control 2 */
43 #define CMD_PWCTRL1     0xD0    /* Power control 1 */
44 #define CMD_PVGAMCTRL   0xE0    /* Positive Gamma Correction */
45 #define CMD_NVGAMCTRL   0xE1    /* Negative Gamma Correction */
46 
47 /**********************
48  *      TYPEDEFS
49  **********************/
50 
51 /**********************
52  *  STATIC PROTOTYPES
53  **********************/
54 
55 /**********************
56  *  STATIC CONSTANTS
57  **********************/
58 
59 /* init commands based on LovyanGFX ST7789 driver */
60 static const uint8_t init_cmd_list[] = {
61     CMD_GCTRL,      1,  0x44,       /* GCTRL -- panel dependent */
62     CMD_VCOMS,      1,  0x24,       /* VCOMS -- panel dependent */
63     CMD_VRHS,       1,  0x13,       /* VRHS - panel dependent */
64     CMD_PWCTRL1,    2,  0xa4, 0xa1,
65     CMD_RAMCTRL,    2,  0x00, 0xC0, /* controls mapping of RGB565 to RGB666 */
66     CMD_PVGAMCTRL,  14, 0xd0, 0x00, 0x02, 0x07, 0x0a, 0x28, 0x32, 0x44, 0x42, 0x06, 0x0e, 0x12, 0x14, 0x17,
67     CMD_NVGAMCTRL,  14, 0xd0, 0x00, 0x02, 0x07, 0x0a, 0x28, 0x31, 0x54, 0x47, 0x0e, 0x1c, 0x17, 0x1b, 0x1e,
68     LV_LCD_CMD_SET_GAMMA_CURVE, 1, 0x01,
69     LV_LCD_CMD_DELAY_MS, LV_LCD_CMD_EOF
70 };
71 
72 /**********************
73  *  STATIC VARIABLES
74  **********************/
75 
76 /**********************
77  *      MACROS
78  **********************/
79 
80 /**********************
81  *   GLOBAL FUNCTIONS
82  **********************/
83 
lv_st7789_create(uint32_t hor_res,uint32_t ver_res,lv_lcd_flag_t flags,lv_st7789_send_cmd_cb_t send_cmd_cb,lv_st7789_send_color_cb_t send_color_cb)84 lv_display_t * lv_st7789_create(uint32_t hor_res, uint32_t ver_res, lv_lcd_flag_t flags,
85                                 lv_st7789_send_cmd_cb_t send_cmd_cb, lv_st7789_send_color_cb_t send_color_cb)
86 {
87     lv_display_t * disp = lv_lcd_generic_mipi_create(hor_res, ver_res, flags, send_cmd_cb, send_color_cb);
88     lv_lcd_generic_mipi_send_cmd_list(disp, init_cmd_list);
89     return disp;
90 }
91 
lv_st7789_set_gap(lv_display_t * disp,uint16_t x,uint16_t y)92 void lv_st7789_set_gap(lv_display_t * disp, uint16_t x, uint16_t y)
93 {
94     lv_lcd_generic_mipi_set_gap(disp, x, y);
95 }
96 
lv_st7789_set_invert(lv_display_t * disp,bool invert)97 void lv_st7789_set_invert(lv_display_t * disp, bool invert)
98 {
99     lv_lcd_generic_mipi_set_invert(disp, invert);
100 }
101 
lv_st7789_set_gamma_curve(lv_display_t * disp,uint8_t gamma)102 void lv_st7789_set_gamma_curve(lv_display_t * disp, uint8_t gamma)
103 {
104     lv_lcd_generic_mipi_set_gamma_curve(disp, gamma);
105 }
106 
lv_st7789_send_cmd_list(lv_display_t * disp,const uint8_t * cmd_list)107 void lv_st7789_send_cmd_list(lv_display_t * disp, const uint8_t * cmd_list)
108 {
109     lv_lcd_generic_mipi_send_cmd_list(disp, cmd_list);
110 }
111 
112 /**********************
113  *   STATIC FUNCTIONS
114  **********************/
115 
116 #endif /*LV_USE_ST7789*/
117