• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd.
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 
16 #include "hdf_log.h"
17 #include "hdf_device_desc.h"
18 #include "device_resource_if.h"
19 #include "osal_time.h"
20 #include "lcd_abs_if.h"
21 #include "tli_ipa_config.h"
22 #include "lcd_hardware_init.h"
23 
24 #define HDF_LOG_TAG gd_lcd
25 
26 #define WIDTH (320)
27 #define HEIGHT (480)
28 #define PICTURE_DEFAULT_POSITION_X 0
29 #define PICTURE_DEFAULT_POSITION_Y 0
30 #define PICTURE_WIDTH 162
31 #define PICTURE_HEIGHT 320
32 #define DELAY_500_MS 500
33 #define DELAY_50_MS 50
34 #define DISWIDTH 137
35 #define DISHEIGHT 160
36 #define DISHEIGHT_STANDARD 310
37 #define DISHEIGHT_STEP 10
38 static int32_t PanelReadId(uint32_t *p_dev_id);
39 struct PanelDevice {
40     struct PanelData panelData;
41     struct PanelInfo panelInfo;
42 };
43 
44 static struct PanelDevice priv = {
45     .panelInfo =
46         {
47             .width = WIDTH,
48             .height = HEIGHT,
49             .frameRate = 60,
50             .intfSync = OUTPUT_USER,
51         },
52 };
53 #define US_TO_MS_CONV (1000)
54 
LcdMDelay(uint32_t timeOut)55 static void LcdMDelay(uint32_t timeOut)
56 {
57     OsalTimespec startTick = {0, 0};
58     OsalTimespec endTick = {0, 0};
59     OsalTimespec diffTick = {0, 0};
60 
61     OsalGetTime(&startTick);
62     do {
63         OsalMSleep(1);
64 
65         /* time out break */
66         OsalGetTime(&endTick);
67         OsalDiffTime(&startTick, &endTick, &diffTick);
68         if ((uint32_t)(diffTick.sec * US_TO_MS_CONV + diffTick.usec / US_TO_MS_CONV) >= timeOut) {
69             break;
70         }
71     } while (true);
72 }
73 #define RGB565_DATA_BUFF_SIZE 307200 // 320*480*2=307200 137*320*2=87680
74 static uint8_t *g_blended_address_buffer = NULL;
75 
PanelInit(struct PanelData * panel)76 static int32_t PanelInit(struct PanelData *panel)
77 {
78     HDF_LOGI("enter in %s\n", __FUNCTION__);
79     static const unsigned char gImageLogo[32] = {0};
80     if (panel == NULL) {
81         HDF_LOGE("in %s: panel == NULL", __FUNCTION__);
82         return HDF_ERR_INVALID_PARAM;
83     }
84     if (g_blended_address_buffer == NULL) {
85         g_blended_address_buffer = (uint8_t *)OsalMemCalloc(RGB565_DATA_BUFF_SIZE);
86         if (g_blended_address_buffer == NULL) {
87             HDF_LOGE("in %s:%s %d: mallc g_blended_address_buffer failed\n", __FILE__, __FUNCTION__, __LINE__);
88             return;
89         }
90 
91         memset_s(&g_blended_address_buffer[0], RGB565_DATA_BUFF_SIZE, 0, RGB565_DATA_BUFF_SIZE);
92     }
93 
94     LcdMDelay(DELAY_500_MS);
95 
96     InitLcdGpio();
97 
98     InitLcdRegister(); // init lcd register
99 
100     ConfigTli();
101     SetLcdBackgroundLayer();
102     SetLcdFrontLayer(0, PICTURE_DEFAULT_POSITION_X, PICTURE_DEFAULT_POSITION_Y, 1, 1,
103                      (uint32_t)gImageLogo); // set layer0
104     tli_layer_enable(LAYER0);
105     tli_layer_enable(LAYER1);
106     tli_reload_config(TLI_FRAME_BLANK_RELOAD_EN);
107     tli_enable();
108 
109     SetLcdFrontLayer(1, PICTURE_DEFAULT_POSITION_X, PICTURE_DEFAULT_POSITION_Y, WIDTH, HEIGHT,
110                      (uint32_t)&g_blended_address_buffer[0]); // set layer1
111 
112     tli_reload_config(TLI_REQUEST_RELOAD_EN);
113 
114     return HDF_SUCCESS;
115 }
116 
PanelReadId(uint32_t * p_dev_id)117 static int32_t PanelReadId(uint32_t *p_dev_id)
118 {
119     return HDF_SUCCESS;
120 }
121 
PanelOn(struct PanelData * panel)122 static int32_t PanelOn(struct PanelData *panel)
123 {
124     return HDF_SUCCESS;
125 }
126 
PanelOff(struct PanelData * panel)127 static int32_t PanelOff(struct PanelData *panel)
128 {
129     return HDF_SUCCESS;
130 }
131 
PanelSetBacklight(struct PanelData * panel,uint32_t level)132 static int32_t PanelSetBacklight(struct PanelData *panel, uint32_t level)
133 {
134     return HDF_SUCCESS;
135 }
136 
PanelFlush(uint16_t disWidth,uint16_t disHeight,uint16_t * dataBuffer)137 static int32_t PanelFlush(uint16_t disWidth, uint16_t disHeight, uint16_t *dataBuffer)
138 {
139     if ((disWidth <= 0) || (disHeight <= 0) || (dataBuffer == NULL)) {
140         HDF_LOGE("input para is wrong: disWidth(%d) disHeight(%d) dataBuffer(%p)", disWidth, disHeight, dataBuffer);
141         return HDF_ERR_INVALID_PARAM;
142     }
143 
144     SetLcdFrontLayer(1, PICTURE_DEFAULT_POSITION_X, PICTURE_DEFAULT_POSITION_X, disWidth, disHeight,
145                      (uint32_t)&g_blended_address_buffer[0]);
146     tli_reload_config(TLI_REQUEST_RELOAD_EN); // make layer_settings in work
147 
148 #ifdef USE_IPA
149     ipaConfig(disWidth, disHeight, (uint32_t)dataBuffer, (uint32_t)&g_blended_address_buffer[0]);
150     ipa_transfer_enable();
151     while (RESET == ipa_interrupt_flag_get(IPA_INT_FLAG_FTF)) { }
152 #else
153     uint16_t area_multip = 2;
154     memcpy_s(&g_blended_address_buffer[0], (disWidth * disHeight * area_multip), dataBuffer,
155              (disWidth * disHeight * area_multip));
156 #endif
157 
158     return HDF_SUCCESS;
159 }
160 
PanelDriverInit(struct HdfDeviceObject * object)161 static int32_t PanelDriverInit(struct HdfDeviceObject *object)
162 {
163     HDF_LOGI("enter in %s\n", __FUNCTION__);
164 
165     if (object == NULL) {
166         return HDF_ERR_INVALID_PARAM;
167     }
168 
169     priv.panelData.info = &priv.panelInfo;
170     priv.panelData.init = PanelInit;
171     priv.panelData.on = PanelOn;
172     priv.panelData.off = PanelOff;
173     priv.panelData.setBacklight = PanelSetBacklight;
174     priv.panelData.dispFlush = PanelFlush;
175     priv.panelData.object = object;
176     if (RegisterPanel(&priv.panelData) != HDF_SUCCESS) {
177         HDF_LOGE("%s: RegisterPanel failed", __func__);
178         return HDF_FAILURE;
179     }
180 
181     return HDF_SUCCESS;
182 }
183 
PanelDriverBind(struct HdfDeviceObject * device)184 static int32_t PanelDriverBind(struct HdfDeviceObject *device)
185 {
186     (void)device;
187     return HDF_SUCCESS;
188 }
189 
PanelDriverRelease(struct HdfDeviceObject * device)190 static void PanelDriverRelease(struct HdfDeviceObject *device)
191 {
192     (void)device;
193 }
194 
195 static struct HdfDriverEntry g_lcdDriverEntry = {
196     .moduleVersion = 1,
197     .moduleName = "GD_LCD_MODULE_HDF",
198     .Bind = PanelDriverBind,
199     .Init = PanelDriverInit,
200     .Release = PanelDriverRelease,
201 };
202 
203 HDF_INIT(g_lcdDriverEntry);