feat:display l1 create driver file

Signed-off-by: chenpan0560 <chenpan55@huawei.com>
This commit is contained in:
chenpan0560
2022-06-13 15:59:39 +08:00
parent cf17c70f82
commit 584a24f227
7 changed files with 325 additions and 14 deletions
@@ -135,7 +135,7 @@ class HdfAddDriver(object):
else:
makefile_file_operation(
makefile_path, driver_file_path[0], driver_head_path[0],
self.module, self.driver)
self.module, self.driver, self.root)
file_path['Makefile'] = makefile_path
elif file_name == "Kconfig":
@@ -257,6 +257,7 @@ class HdfAddDriver(object):
source_file_name = os.path.join(source_file, create_source_name)
if os.path.exists(source_file_name):
source_statu_exist = True
source_file_list.append(source_file_name)
else:
self._template_fill(source_file_temp, source_file_name, data_model)
source_file_list.append(source_file_name)
@@ -279,11 +280,12 @@ class HdfAddDriver(object):
head_file_name = os.path.join(head_path, create_head_name)
if os.path.exists(head_file_name):
head_statu_exist = True
head_path_list.append(head_file_name)
else:
self._template_fill(head_file_temp, head_file_name, data_model)
head_path_list.append(head_file_name)
if head_statu_exist and source_statu_exist:
return True, source_file, head_path
return True, source_file_list, head_path_list
child_dir_list, operation_object = hdf_utils.ini_file_read_operation(
section_name=module, node_name='file_dir')
if device not in child_dir_list:
@@ -36,6 +36,11 @@ def kconfig_file_operation(path, module, driver, template_path):
"driver_name_lower": driver.lower()
}
new_line = temp_handle.substitute(temp_replace)
if module == "display":
replace_str = "depends on DRIVERS_HDF_%s"
old_str = replace_str % module.upper()
new_str = replace_str % "disp".upper()
new_line = new_line.replace(old_str, new_str)
date_lines = date_lines + [new_line]
hdf_utils.write_file_lines(kconfig_gn_path, date_lines)
@@ -119,5 +119,13 @@ def linux_makefile_operation(path, driver_file_path, head_path, module, driver):
'head_file_path': '/'.join(head_path.split("model")[-1].strip(os.path.sep).split(os.path.sep)[:-1])
}
new_line = temp_handle.substitute(temp_replace).replace("temp_flag", "$(")
date_lines = date_lines + [new_line]
endif_status = False
for index, v in enumerate(date_lines[::-1]):
if v.strip().startswith("endif"):
endif_status = True
end_line_index = len(date_lines) - index - 1
date_lines = date_lines[:end_line_index] + [new_line] + [date_lines[end_line_index]]
break
if not endif_status:
date_lines = date_lines + [new_line]
hdf_utils.write_file_lines(makefile_gn_path, date_lines)
@@ -84,7 +84,7 @@ def audio_makefile_file_operation(path, args_tuple):
hdf_utils.write_file_lines(makefile_gn_path, date_lines)
def makefile_file_operation(path, driver_file_path, head_path, module, driver):
def makefile_file_operation(path, driver_file_path, head_path, module, driver, root_path):
makefile_gn_path = path
date_lines = hdf_utils.read_file_lines(makefile_gn_path)
judge_result = judge_driver_config_exists(date_lines, driver_name=driver)
@@ -99,23 +99,47 @@ def makefile_file_operation(path, driver_file_path, head_path, module, driver):
input_second_line = "LOCAL_SRCS += $(${model_name_upper}_ROOT_DIR)/${source_file_path}\n"
sensor_include_line = "LOCAL_INCLUDE += $(FRAMEWORKS_${model_name_upper}_ROOT)/${head_file_path}\n"
sensor_second_line = "LOCAL_SRCS += $(FRAMEWORKS_${model_name_upper}_ROOT)/${source_file_path}\n"
display_include_line = "LOCAL_INCLUDE += $(LITEOSTOPDIR)/../../${head_file_path}\n"
display_second_line = "LOCAL_SRCS += $(LITEOSTOPDIR)/../../${source_file_path}\n"
third_line = "endif\n"
if module == "sensor":
makefile_add_template = first_line + sensor_include_line + sensor_second_line + third_line
elif module == "display":
makefile_add_template = first_line + display_include_line + display_second_line + third_line
else:
makefile_add_template = first_line + input_include_line + input_second_line + third_line
include_model_info = model_dir_value.split("model")[-1].strip('"') + "/"
makefile_path_config = source_file_path.split(include_model_info)
temp_handle = Template(makefile_add_template.replace("$(", "temp_flag"))
temp_replace = {
'model_name_upper': module.upper(),
'driver_name_upper': driver.upper(),
'source_file_path': makefile_path_config[-1],
'head_file_path': '/'.join(
list(filter(lambda x: x, head_path.split("model")[-1].strip(
os.path.sep).split(os.path.sep)[2:-1])))
}
if module == "display":
temp_replace = {
'model_name_upper': module.upper(),
'driver_name_upper': driver.upper(),
'source_file_path': '/'.join(
list(filter(lambda x: x, driver_file_path.split(root_path)[-1].
strip(os.path.sep).split(os.path.sep)))),
'head_file_path': '/'.join(
list(filter(lambda x: x, head_path.split(root_path)[-1].
strip(os.path.sep).split(os.path.sep)))[:-1])
}
else:
temp_replace = {
'model_name_upper': module.upper(),
'driver_name_upper': driver.upper(),
'source_file_path': makefile_path_config[-1],
'head_file_path': '/'.join(
list(filter(lambda x: x, head_path.split("model")[-1].strip(
os.path.sep).split(os.path.sep)[2:-1])))
}
new_line = temp_handle.substitute(temp_replace).replace("temp_flag", "$(")
date_lines = date_lines[:end_index-1] + [new_line] + date_lines[end_index-1:]
endif_status = False
for index, v in enumerate(date_lines[::-1]):
if v.strip().startswith("endif"):
endif_status = True
end_line_index = len(date_lines) - index - 1
date_lines = date_lines[:end_line_index] + [new_line] + date_lines[end_line_index:]
break
if not endif_status:
date_lines = date_lines + [new_line]
hdf_utils.write_file_lines(makefile_gn_path, date_lines)
+5 -1
View File
@@ -10,9 +10,13 @@ file_dir = ["accel", "als", "barometer", "gyro", "hall", "magnetic", "pedometer"
driver_path = "device/board/hisilicon/hispark_taurus/audio_drivers"
file_dir = ["codec", "dsp", "soc"]
[display]
driver_path = ""
file_dir = ["adapter_soc", "backlight", "lcdkit", "panel"]
[peripheral]
devices_list = ["audio"]
[framework]
devices_list = ["input", "sensor"]
devices_list = ["input", "sensor", "display"]
@@ -0,0 +1,37 @@
#ifndef ${device_upper_case}_${driver_upper_case}_DRIVER_H
#define ${device_upper_case}_${driver_upper_case}_DRIVER_H
#include "gpio_if.h"
#include "hdf_bl.h"
#include "hdf_disp.h"
#include "hdf_log.h"
#include "mipi_dsi_if.h"
#include "osal.h"
#include "pwm_if.h"
#define RESET_GPIO 0
#define MIPI_DSI0 0
#define BLK_PWM1 0
#define PWM_MAX_PERIOD 0
/* backlight setting */
#define MIN_LEVEL 0
#define MAX_LEVEL 255
#define DEFAULT_LEVEL 100
#define WIDTH 0
#define HEIGHT 0
#define HORIZONTAL_BACK_PORCH 0
#define HORIZONTAL_FRONT_PORCH 0
#define HORIZONTAL_SYNC_WIDTH 0
#define VERTICAL_BACK_PORCH 0
#define VERTICAL_FRONT_PORCH 0
#define VERTICAL_SYNC_WIDTH 0
#define FRAME_RATE 0
struct ${driver_upper_camel_case}Dev {
struct PanelData panel;
DevHandle mipiHandle;
uint16_t reset_gpio;
uint16_t reset_delay;
};
#endif /* ${device_upper_case}_${driver_upper_case}_DRIVER_H */
@@ -0,0 +1,231 @@
#include "gpio_if.h"
#include "hdf_bl.h"
#include "hdf_disp.h"
#include "osal.h"
#include "${include_file}"
static struct DsiCmdDesc g_OnCmd[] = {};
/* panel off command payload */
static uint8_t g_offPayLoad0[] = { 0x28 };
static uint8_t g_offPayLoad1[] = { 0x10 };
static struct DsiCmdDesc g_offCmd[] = {
{ 0x05, 20, sizeof(g_offPayLoad0), g_offPayLoad0 },
{ 0x05, 120, sizeof(g_offPayLoad1), g_offPayLoad1 },
};
static int32_t LcdResetOn(struct ${driver_upper_camel_case}Dev *${driver_lower_case})
{
int32_t ret;
ret = GpioSetDir(${driver_lower_case}->reset_gpio, GPIO_DIR_OUT);
if (ret != HDF_SUCCESS) {
HDF_LOGE("GpioSetDir failed, ret:%d", ret);
return HDF_FAILURE;
}
ret = GpioWrite(${driver_lower_case}->reset_gpio, GPIO_VAL_HIGH);
if (ret != HDF_SUCCESS) {
HDF_LOGE("GpioWrite failed, ret:%d", ret);
return HDF_FAILURE;
}
/* delay 20ms */
OsalMSleep(${driver_lower_case}->reset_delay);
return HDF_SUCCESS;
}
static int32_t LcdResetOff(struct ${driver_upper_camel_case}Dev *${driver_lower_case})
{
int32_t ret;
ret = GpioSetDir(${driver_lower_case}->reset_gpio, GPIO_DIR_OUT);
if (ret != HDF_SUCCESS) {
HDF_LOGE("GpioSetDir failed, ret:%d", ret);
return HDF_FAILURE;
}
ret = GpioWrite(${driver_lower_case}->reset_gpio, GPIO_VAL_LOW);
if (ret != HDF_SUCCESS) {
HDF_LOGE("GpioWrite failed, ret:%d", ret);
return HDF_FAILURE;
}
/* delay 20ms */
OsalMSleep(${driver_lower_case}->reset_delay);
return HDF_SUCCESS;
}
static struct ${driver_upper_camel_case}Dev *PanelTo${driver_upper_camel_case}Dev(const struct PanelData *panel)
{
struct ${driver_upper_camel_case}Dev *${driver_lower_case} = NULL;
if (panel == NULL) {
HDF_LOGE("%s: panel is null", __func__);
return NULL;
}
if (panel->object == NULL) {
HDF_LOGE("%s: object is null", __func__);
return NULL;
}
${driver_lower_case} = (struct ${driver_upper_camel_case}Dev *)panel->object->priv;
return ${driver_lower_case};
}
static int32_t ${driver_upper_camel_case}Init(struct PanelData *panel)
{
struct ${driver_upper_camel_case}Dev *${driver_lower_case} = NULL;
${driver_lower_case} = PanelTo${driver_upper_camel_case}Dev(panel);
if (${driver_lower_case} == NULL) {
HDF_LOGE("%s: ${driver_lower_case} is null", __func__);
return HDF_FAILURE;
}
${driver_lower_case}->mipiHandle = MipiDsiOpen(MIPI_DSI0);
if (${driver_lower_case}->mipiHandle == NULL) {
HDF_LOGE("%s: MipiDsiOpen failed", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t ${driver_upper_camel_case}On(struct PanelData *panel)
{
int32_t ret;
struct ${driver_upper_camel_case}Dev *${driver_lower_case} = NULL;
${driver_lower_case} = PanelTo${driver_upper_camel_case}Dev(panel);
if (${driver_lower_case} == NULL) {
HDF_LOGE("%s: ${driver_lower_case} is null", __func__);
return HDF_FAILURE;
}
/* lcd reset power on */
ret = LcdResetOn(${driver_lower_case});
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: LcdResetOn failed", __func__);
return HDF_FAILURE;
}
if (${driver_lower_case}->mipiHandle == NULL) {
HDF_LOGE("%s: mipiHandle is null", __func__);
return HDF_FAILURE;
}
/* send mipi init code */
int32_t count = sizeof(g_OnCmd) / sizeof(g_OnCmd[0]);
int32_t i;
/* set mipi to lp mode */
MipiDsiSetLpMode(${driver_lower_case}->mipiHandle);
for (i = 0; i < count; i++) {
ret = MipiDsiTx(${driver_lower_case}->mipiHandle, &(g_OnCmd[i]));
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: MipiDsiTx failed", __func__);
return HDF_FAILURE;
}
}
/* set mipi to hs mode */
MipiDsiSetHsMode(${driver_lower_case}->mipiHandle);
return HDF_SUCCESS;
}
static int32_t ${driver_upper_camel_case}Off(struct PanelData *panel)
{
int32_t ret;
struct ${driver_upper_camel_case}Dev *${driver_lower_case} = NULL;
${driver_lower_case} = PanelTo${driver_upper_camel_case}Dev(panel);
if (${driver_lower_case} == NULL) {
HDF_LOGE("%s: ${driver_lower_case} is null", __func__);
return HDF_FAILURE;
}
if (${driver_lower_case}->mipiHandle == NULL) {
HDF_LOGE("%s: mipiHandle is null", __func__);
return HDF_FAILURE;
}
/* send mipi init code */
int32_t count = sizeof(g_offCmd) / sizeof(g_offCmd[0]);
int32_t i;
/* set mipi to lp mode */
MipiDsiSetLpMode(${driver_lower_case}->mipiHandle);
for (i = 0; i < count; i++) {
ret = MipiDsiTx(${driver_lower_case}->mipiHandle, &(g_offCmd[i]));
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: MipiDsiTx failed", __func__);
return HDF_FAILURE;
}
}
/* lcd reset power off */
ret = LcdResetOff(${driver_lower_case});
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: LcdResetOff failed", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t ${driver_upper_camel_case}EsdCheckFunc(struct PanelData *panel)
{
struct ${driver_upper_camel_case}Dev *${driver_lower_case} = NULL;
${driver_lower_case} = PanelTo${driver_upper_camel_case}Dev(panel);
if (${driver_lower_case} == NULL) {
HDF_LOGE("%s: ${driver_lower_case} is null", __func__);
return HDF_FAILURE;
}
HDF_LOGE("%s: enter", __func__);
return HDF_SUCCESS;
}
#define OUTPUT_USER 0 /* output timing type */
static struct PanelInfo g_panelInfo = {};
static struct PanelEsd g_panelEsd = {
.support = false,
.checkFunc = ${driver_upper_camel_case}EsdCheckFunc,
};
static void ${driver_upper_camel_case}PanelInit(struct PanelData *panel)
{
panel->info = &g_panelInfo;
panel->esd = &g_panelEsd;
panel->init = ${driver_upper_camel_case}Init;
panel->on = ${driver_upper_camel_case}On;
panel->off = ${driver_upper_camel_case}Off;
}
int32_t ${driver_upper_camel_case}EntryInit(struct HdfDeviceObject *object)
{
struct ${driver_upper_camel_case}Dev *${driver_lower_case} = NULL;
if (object == NULL) {
HDF_LOGE("%s: object is null", __func__);
return HDF_FAILURE;
}
${driver_lower_case} = (struct ${driver_upper_camel_case}Dev *)OsalMemCalloc(sizeof(struct ${driver_upper_camel_case}Dev));
if (${driver_lower_case} == NULL) {
HDF_LOGE("%s ${driver_lower_case} malloc fail", __func__);
return HDF_FAILURE;
}
${driver_upper_camel_case}PanelInit(&${driver_lower_case}->panel);
${driver_lower_case}->panel.object = object;
${driver_lower_case}->reset_gpio = RESET_GPIO;
${driver_lower_case}->reset_delay = 20; // delay 20ms
object->priv = (void *)${driver_lower_case};
${driver_lower_case}->panel.blDev = GetBacklightDev("hdf_pwm");
if (${driver_lower_case}->panel.blDev == NULL) {
HDF_LOGE("%s GetBacklightDev fail", __func__);
return HDF_FAILURE;
}
if (RegisterPanel(&${driver_lower_case}->panel) != HDF_SUCCESS) {
HDF_LOGE("%s: RegisterPanel failed", __func__);
return HDF_FAILURE;
}
HDF_LOGI("%s: exit succ", __func__);
return HDF_SUCCESS;
}
struct HdfDriverEntry g_${driver_upper_case}DevEntry = {
.moduleVersion = 1,
.moduleName = "${device_upper_case}_${driver_upper_case}",
.Init = ${driver_upper_camel_case}EntryInit,
};
HDF_INIT(g_${driver_upper_case}DevEntry);