• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 Beken Corporation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <driver/gpio.h>
16 #include <driver/media_types.h>
17 #include <driver/lcd_types.h>
18 #include "lcd_disp_hal.h"
19 
20 #include "lcd_devices.h"
21 
22 #define SLEEP_OUT          0x11
23 #define COMMAND_1          0xf0
24 #define COMMAND_2          0xf0
25 #define PLOAR_CONVERT      0xb4
26 #define DISP_OUT_CTRL      0xe8
27 #define POWER_CTRL1        0xc1
28 #define POWER_CTRL2        0xc2
29 #define VCOM_CTRL          0xc5
30 #define CATHODE_CTRL       0xe0
31 #define ANODE_CTRL         0xe1
32 #define COLOR_MODE         0x3a
33 #define DISPLAY_ON         0x29
34 #define ROW_SET            0x2b
35 #define COLUMN_SET         0x2a
36 #define RAM_WRITE          0x2c
37 #define CONTINUE_WRITE     0x3c
38 #define MEM_ACCESS_CTRL    0x36
39 
40 #define TAG "st7796s"
41 #define LOGI(...) BK_LOGI(TAG, ##__VA_ARGS__)
42 
43 
44 const static uint32_t param_sleep_out[1]  = {0x00};
45 const static uint32_t param_command1[1]   = {0xc3};
46 const static uint32_t param_command2[1]   = {0x96};
47 const static uint32_t param_memacess[1]   = {0x48};
48 const static uint32_t param_color_md[1]   = {0x05};
49 const static uint32_t param_polar_cv[1]   = {0x01};
50 const static uint32_t param_disp_out[8]   = {0x40, 0x8a, 0x00, 0x00, 0x29, 0x19, 0xa5, 0x33};
51 const static uint32_t param_power_1[1]    = {0x06};
52 const static uint32_t param_power_2[1]    = {0xa7};
53 const static uint32_t param_vcom_ctl[1]   = {0x18};
54 const static uint32_t param_cath_ctl1[14] = {0xf0, 0x09, 0x0b, 0x06, 0x04, 0x15, 0x2f, 0x54, 0x42, 0x3c, 0x17, 0x14, 0x18, 0x1b};
55 const static uint32_t param_cath_ctl2[14] = {0xf0, 0x09, 0x0b, 0x06, 0x04, 0x03, 0x2d, 0x43, 0x42, 0x3b, 0x16, 0x14, 0x17, 0x1b};
56 const static uint32_t param_command12[1]  = {0x3c};
57 const static uint32_t param_command22[1]  = {0x69};
58 const static uint32_t param_display_on[1] = {0x00 };
59 
lcd_st7796s_init(void)60 void lcd_st7796s_init(void)
61 {
62 	LOGI("%s\n", __func__);
63 
64 	rtos_delay_milliseconds(131);
65 	rtos_delay_milliseconds(131);
66 
67 	lcd_hal_8080_cmd_send(0, SLEEP_OUT, (uint32_t *)param_sleep_out);
68 	rtos_delay_milliseconds(120);
69 
70 	lcd_hal_8080_cmd_send(1, COMMAND_1, (uint32_t *)param_command1);
71 	lcd_hal_8080_cmd_send(1, COMMAND_2, (uint32_t *)param_command2);
72 	lcd_hal_8080_cmd_send(1, MEM_ACCESS_CTRL, (uint32_t *)param_memacess);
73 	lcd_hal_8080_cmd_send(1, COLOR_MODE, (uint32_t *)param_color_md);
74 	lcd_hal_8080_cmd_send(1, PLOAR_CONVERT, (uint32_t *)param_polar_cv);
75 	lcd_hal_8080_cmd_send(8, DISP_OUT_CTRL, (uint32_t *)param_disp_out);
76 	lcd_hal_8080_cmd_send(1, POWER_CTRL1, (uint32_t *)param_power_1);
77 	lcd_hal_8080_cmd_send(1, POWER_CTRL2, (uint32_t *)param_power_2);
78 	lcd_hal_8080_cmd_send(1, VCOM_CTRL, (uint32_t *)param_vcom_ctl);
79 	lcd_hal_8080_cmd_send(14, CATHODE_CTRL, (uint32_t *)param_cath_ctl1);
80 	lcd_hal_8080_cmd_send(14, ANODE_CTRL, (uint32_t *)param_cath_ctl2);
81 	lcd_hal_8080_cmd_send(1, COMMAND_1, (uint32_t *)param_command12);
82 	lcd_hal_8080_cmd_send(1, COMMAND_2, (uint32_t *)param_command22);
83 
84 	rtos_delay_milliseconds(120);
85 	lcd_hal_8080_cmd_send(0, DISPLAY_ON, (uint32_t *)param_display_on);
86 }
87 
lcd_st7796s_set_display_mem_area(uint16 xs,uint16 xe,uint16 ys,uint16 ye)88 void lcd_st7796s_set_display_mem_area(uint16 xs, uint16 xe, uint16 ys, uint16 ye)
89 {
90 	uint16 xs_l, xs_h, xe_l, xe_h;
91 	uint16 ys_l, ys_h, ye_l, ye_h;
92 
93 	xs_h = xs >> 8;
94 	xs_l = xs & 0xff;
95 
96 	xe_h = xe >> 8;
97 	xe_l = xe & 0xff;
98 
99 	ys_h = ys >> 8;
100 	ys_l = ys & 0xff;
101 
102 	ye_h = ye >> 8;
103 	ye_l = ye & 0xff;
104 
105 	uint32_t param_clumn[4] = {xs_h, xs_l, xe_h, xe_l};
106 	uint32_t param_row[4] = {ys_h, ys_l, ye_h, ye_l};
107 
108 	lcd_hal_8080_cmd_send(4, 0x2a, param_clumn);
109 	lcd_hal_8080_cmd_send(4, 0x2b, param_row);
110 }
111 
112 static const lcd_mcu_t lcd_mcu =
113 {
114 	.clk = LCD_60M,
115 
116 	.set_display_area = lcd_st7796s_set_display_mem_area,
117 };
118 
119 const lcd_device_t lcd_device_st7796s =
120 {
121 	.id = LCD_DEVICE_ST7796S,
122 	.name = "st7796s",
123 	.type = LCD_TYPE_MCU8080,
124 	.ppi = PPI_320X480,
125 	.mcu = &lcd_mcu,
126 	.init = lcd_st7796s_init,
127 };
128 
129