From cf17c70f8289f5d97779f51b6c536d0e86f35a9f Mon Sep 17 00:00:00 2001 From: chenpan0560 Date: Wed, 8 Jun 2022 19:11:15 +0800 Subject: [PATCH] feat:audio l1 create driver file Signed-off-by: chenpan0560 --- .../command_line/driver_add/hdf_add_driver.py | 214 +++++++++++++----- .../linux/kconfig_file_add_config.py | 4 +- .../driver_add/linux/mk_file_add_config.py | 87 +++++-- .../driver_add/liteos/gn_file_add_config.py | 126 +++++++++-- .../driver_add/liteos/mk_file_add_config.py | 73 +++++- .../command_line/hdf_add_handler.py | 13 +- .../command_line/hdf_device_info_hcs.py | 19 +- tools/hdf_dev_eco_tool/hdf_tool_settings.py | 9 +- tools/hdf_dev_eco_tool/hdf_utils.py | 13 +- tools/hdf_dev_eco_tool/resources/config.ini | 12 + .../resources/create_driver.config | 2 +- .../hdf_dev_eco_tool/resources/settings.json | 3 +- .../hi35xx_audio_adapter_source.template | 103 +++++++++ .../hi35xx_audio_ops_head.template | 28 +++ .../hi35xx_audio_ops_source.template | 30 +++ .../lite/exists_model_hcs_info.template | 3 +- .../input_driver_source.template | 2 +- .../accel_sensor_driver_source.template | 2 +- 18 files changed, 620 insertions(+), 123 deletions(-) create mode 100644 tools/hdf_dev_eco_tool/resources/templates/lite/audio_template/hi35xx_audio_adapter_source.template create mode 100644 tools/hdf_dev_eco_tool/resources/templates/lite/audio_template/hi35xx_audio_ops_head.template create mode 100644 tools/hdf_dev_eco_tool/resources/templates/lite/audio_template/hi35xx_audio_ops_source.template diff --git a/tools/hdf_dev_eco_tool/command_line/driver_add/hdf_add_driver.py b/tools/hdf_dev_eco_tool/command_line/driver_add/hdf_add_driver.py index bc38b700..e61a25e5 100644 --- a/tools/hdf_dev_eco_tool/command_line/driver_add/hdf_add_driver.py +++ b/tools/hdf_dev_eco_tool/command_line/driver_add/hdf_add_driver.py @@ -10,15 +10,16 @@ import configparser import os +import re from string import Template import hdf_utils from hdf_tool_exception import HdfToolException from .linux.kconfig_file_add_config import kconfig_file_operation -from .linux.mk_file_add_config import linux_makefile_operation +from .linux.mk_file_add_config import audio_linux_makefile_operation, linux_makefile_operation -from .liteos.gn_file_add_config import build_file_operation -from .liteos.mk_file_add_config import makefile_file_operation +from .liteos.gn_file_add_config import audio_build_file_operation, build_file_operation +from .liteos.mk_file_add_config import audio_makefile_file_operation, makefile_file_operation from ..hdf_command_error_code import CommandErrorCode from ..hdf_defconfig_patch import HdfDefconfigAndPatch from ..hdf_device_info_hcs import HdfDeviceInfoHcsFile @@ -40,7 +41,7 @@ class HdfAddDriver(object): 'template file: %s not exist' % self.template_file_path, CommandErrorCode.TARGET_NOT_EXIST) - def add_linux(self, driver_file_path): + def add_linux(self, driver_file_path, driver_head_path): adapter_hdf = hdf_utils.get_vendor_hdf_dir_adapter( self.root, self.kernel) hdf_utils.judge_file_path_exists(adapter_hdf) @@ -52,10 +53,16 @@ class HdfAddDriver(object): file_path = {} for file_name in liteos_file_name: if file_name == "Makefile": - build_file_path = os.path.join(adapter_model_path, file_name) - linux_makefile_operation(build_file_path, driver_file_path, - self.module, self.driver) - file_path['Makefile'] = build_file_path + linux_makefile_file_path = os.path.join(adapter_model_path, file_name) + if self.module == "audio": + args_tuple = (driver_file_path, driver_head_path, self.module, + self.driver, self.root, self.device) + audio_linux_makefile_operation(linux_makefile_file_path, args_tuple) + else: + linux_makefile_operation( + linux_makefile_file_path, driver_file_path[0], driver_head_path[0], + self.module, self.driver) + file_path['Makefile'] = linux_makefile_file_path elif file_name == "Kconfig": kconfig_path = os.path.join(adapter_model_path, file_name) @@ -66,7 +73,7 @@ class HdfAddDriver(object): device_info = HdfDeviceInfoHcsFile(self.root, self.vendor, self.module, self.board, self.driver, path="") - hcs_file_path = device_info.add_hcs_config_to_exists_model() + hcs_file_path = device_info.add_hcs_config_to_exists_model(self.device) file_path["devices_info.hcs"] = hcs_file_path device_enable_config_line = self.__get_enable_config() template_string = "CONFIG_DRIVERS_HDF_${module_upper}_${driver_upper}=y\n" @@ -96,7 +103,7 @@ class HdfAddDriver(object): list(set(patch_list + defconfig_list)) return file_path - def add_liteos(self, driver_file_path): + def add_liteos(self, driver_file_path, driver_head_path): adapter_hdf = hdf_utils.get_vendor_hdf_dir_adapter( self.root, self.kernel) hdf_utils.judge_file_path_exists(adapter_hdf) @@ -109,14 +116,26 @@ class HdfAddDriver(object): for file_name in liteos_file_name: if file_name == "BUILD.gn": build_file_path = os.path.join(adapter_model_path, file_name) - build_file_operation(build_file_path, driver_file_path, - self.module, self.driver) + if self.module == "audio": + args_tuple = (driver_file_path, driver_head_path, self.module, + self.driver, self.root, self.device, self.kernel) + audio_build_file_operation(build_file_path, args_tuple) + else: + build_file_operation( + build_file_path, driver_file_path[0], driver_head_path[0], + self.module, self.driver) file_path['BUILD.gn'] = build_file_path elif file_name == "Makefile": makefile_path = os.path.join(adapter_model_path, file_name) - makefile_file_operation(makefile_path, driver_file_path, - self.module, self.driver) + if self.module == "audio": + args_tuple = (driver_file_path, driver_head_path, self.module, + self.driver, self.root, self.device, self.kernel) + audio_makefile_file_operation(makefile_path, args_tuple) + else: + makefile_file_operation( + makefile_path, driver_file_path[0], driver_head_path[0], + self.module, self.driver) file_path['Makefile'] = makefile_path elif file_name == "Kconfig": @@ -129,7 +148,7 @@ class HdfAddDriver(object): device_info = HdfDeviceInfoHcsFile( self.root, self.vendor, self.module, self.board, self.driver, path="") - hcs_file_path = device_info.add_hcs_config_to_exists_model() + hcs_file_path = device_info.add_hcs_config_to_exists_model(self.device) file_path["devices_info.hcs"] = hcs_file_path dot_file_list = hdf_utils.get_dot_configs_path( @@ -144,9 +163,11 @@ class HdfAddDriver(object): file_lines_old = hdf_utils.read_file_lines(dot_file) if device_enable: file_lines = list( - filter(lambda x: hdf_utils.judge_enable_line( - enable_line=x, device_base=device_enable.split("=")[0]), - file_lines_old)) + filter( + lambda x: hdf_utils.judge_enable_line( + enable_line=x, + device_base=device_enable.split("=")[0]), + file_lines_old)) if device_enable not in file_lines: file_lines.append(device_enable) else: @@ -198,46 +219,78 @@ class HdfAddDriver(object): def add_driver(self, *args_tuple): root, vendor, module, driver, board, kernel, device = args_tuple drv_converter = hdf_utils.WordsConverter(driver) - source_file, head_path, include_name = self.create_model_file_name( + dev_converter = hdf_utils.WordsConverter(device) + # create driver file path + source_file, head_path = self.create_model_file_name( root, vendor, module, driver, board, kernel, device) data_model = { 'driver_lower_case': drv_converter.lower_case(), 'driver_upper_camel_case': drv_converter.upper_camel_case(), 'driver_lower_camel_case': drv_converter.lower_camel_case(), - "include_file": include_name, - 'driver_upper_case': drv_converter.upper_case() + 'driver_upper_case': drv_converter.upper_case(), + 'device_lower_case': dev_converter.lower_case(), + 'device_upper_camel_case': dev_converter.upper_camel_case(), + 'device_lower_camel_case': dev_converter.lower_camel_case(), + 'device_upper_case': dev_converter.upper_case() } - if os.path.exists(source_file): - return True, source_file - templates_dir = hdf_utils.get_templates_lite_dir() - templates_model_dir = [] - for path, dir_name, _ in os.walk(templates_dir): - if dir_name: - templates_model_dir.extend(dir_name) - templates_model_dir = list(filter( - lambda model_dir: self.module in model_dir, - templates_model_dir)) - target_template_path = list(map( - lambda dir_name: os.path.join(templates_dir, dir_name), - templates_model_dir))[0] - templates_file_list = os.listdir(target_template_path) - source_file_template = os.path.join( - target_template_path, - list(filter(lambda file_name: "source" in file_name, - templates_file_list))[0]) - self._template_fill(source_file_template, source_file, data_model) - head_file_template = os.path.join( - target_template_path, - list(filter(lambda file_name: "head" in file_name, - templates_file_list))[0]) - self._template_fill(head_file_template, head_path, data_model) + source_statu_exist = False + head_statu_exist = False + templates_list, target_path = self.get_model_template_list(module, board) + # find model template .c + source_file_template_list = list(filter( + lambda file_name: "source" in file_name, templates_list)) + source_file_template = list(map( + lambda template_name: os.path.join(target_path, template_name), + source_file_template_list)) + path_list = list(os.path.split(source_file)) + temp_path = os.path.sep.join(path_list[:-1]) + if not os.path.exists(temp_path): + os.makedirs(temp_path) + + source_file_list = [] + for source_file_temp in source_file_template: + if not os.path.exists(source_file): + os.makedirs(source_file) + create_name = re.search(r'[a-z]+_source', source_file_temp).group() + create_source_name = "%s_%s_%s.c" % (device, driver, create_name.split("_")[0]) + data_model.update({'include_file': "%s_%s_%s.h" % (device, driver, create_name.split("_")[0])}) + source_file_name = os.path.join(source_file, create_source_name) + if os.path.exists(source_file_name): + source_statu_exist = True + else: + self._template_fill(source_file_temp, source_file_name, data_model) + source_file_list.append(source_file_name) + # find model template .h + head_file_template_list = list(filter( + lambda file_name: "head" in file_name, templates_list)) + head_file_template = list(map( + lambda template_name: os.path.join(target_path, template_name), + head_file_template_list)) + path_list = list(os.path.split(head_path)) + temp_path = os.path.sep.join(path_list[:-1]) + if not os.path.exists(temp_path): + os.makedirs(temp_path) + head_path_list = [] + for head_file_temp in head_file_template: + if not os.path.exists(head_path): + os.makedirs(head_path) + create_name = re.search(r'[a-z]+_head', head_file_temp).group() + create_head_name = "%s_%s_%s.h" % (device, driver, create_name.split("_")[0]) + head_file_name = os.path.join(head_path, create_head_name) + if os.path.exists(head_file_name): + head_statu_exist = True + 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 child_dir_list, operation_object = hdf_utils.ini_file_read_operation( - model=module, node_name='file_dir') + section_name=module, node_name='file_dir') if device not in child_dir_list: child_dir_list.append(device) hdf_utils.ini_file_write_operation( module, operation_object, child_dir_list) - return True, source_file + return True, source_file_list, head_path_list def _file_gen_lite(self, template, source_file_path, model): templates_dir = hdf_utils.get_templates_lite_dir() @@ -256,14 +309,21 @@ class HdfAddDriver(object): drv_src_dir = hdf_utils.get_drv_src_dir(root, module) if device.strip(): if module == "sensor": - new_mkdir_path = os.path.join(drv_src_dir, 'chipset', device) + relatively_path, _ = hdf_utils.ini_file_read_operation( + section_name=module, node_name='driver_path') + new_mkdir_path = os.path.join(drv_src_dir, relatively_path, device) + elif module == "audio": + relatively_path, _ = hdf_utils.ini_file_read_operation( + section_name=module, node_name='driver_path') + new_mkdir_path = os.path.join( + root, relatively_path, device) else: new_mkdir_path = os.path.join(drv_src_dir, device) + if not os.path.exists(new_mkdir_path): os.mkdir(new_mkdir_path) - result_path_source = os.path.join(new_mkdir_path, '%s_%s_driver.c' % (device, driver)) - result_path_head = os.path.join(new_mkdir_path, '%s_%s_driver.h' % (device, driver)) - include_name = '%s_%s_driver.h' % (device, driver) + result_path_source = os.path.join(new_mkdir_path, 'src') + result_path_head = os.path.join(new_mkdir_path, 'include') else: if module == "sensor": new_mkdir_path = os.path.join(drv_src_dir, 'chipset', driver) @@ -271,10 +331,11 @@ class HdfAddDriver(object): new_mkdir_path = os.path.join(drv_src_dir, driver) if not os.path.exists(new_mkdir_path): os.mkdir(new_mkdir_path) - result_path_source = os.path.join(new_mkdir_path, '%s_driver.c' % driver) - result_path_head = os.path.join(new_mkdir_path, '%s_driver.h' % driver) - include_name = '%s_driver.h' % driver - return result_path_source, result_path_head, include_name + result_path_source = os.path.join( + new_mkdir_path, '%s_driver.c' % driver) + result_path_head = os.path.join( + new_mkdir_path, '%s_driver.h' % driver) + return result_path_source, result_path_head def __get_enable_config(self): templates_dir = hdf_utils.get_templates_lite_dir() @@ -282,22 +343,51 @@ class HdfAddDriver(object): for path, dir_name, _ in os.walk(templates_dir): if dir_name: templates_model_dir.extend(dir_name) - templates_model_dir = list(filter(lambda model_dir: self.module in model_dir, templates_model_dir)) - config_file = [name for name in os.listdir(os.path.join(templates_dir, templates_model_dir[0])) if - name.endswith("ini")] + templates_model_dir = list( + filter( + lambda model_dir: self.module in model_dir, + templates_model_dir)) + config_file = [ + name for name in os.listdir( + os.path.join( + templates_dir, + templates_model_dir[0])) if name.endswith("ini")] if config_file: - config_path = os.path.join(templates_dir, templates_model_dir[0], config_file[0]) + config_path = os.path.join( + templates_dir, + templates_model_dir[0], + config_file[0]) config = configparser.ConfigParser() config.read(config_path) section_list = config.options(section=self.kernel) if self.device in section_list: device_enable_config, _ = hdf_utils.ini_file_read_operation( - model=self.kernel, node_name=self.device, path=config_path) + section_name=self.kernel, node_name=self.device, path=config_path) else: if self.kernel == "linux": - device_enable_config = ["CONFIG_DRIVERS_HDF_SENSOR_ACCEL=y\n"] + device_enable_config = [ + "CONFIG_DRIVERS_HDF_SENSOR_ACCEL=y\n"] else: - device_enable_config = ["LOSCFG_DRIVERS_HDF_SENSOR_ACCEL=y\n"] + device_enable_config = [ + "LOSCFG_DRIVERS_HDF_SENSOR_ACCEL=y\n"] else: device_enable_config = [""] return device_enable_config[0] + + def get_model_template_list(self, module, board): + templates_dir = hdf_utils.get_templates_lite_dir() + templates_model_dir = [] + for path, dir_name, _ in os.walk(templates_dir): + if dir_name: + templates_model_dir.extend(dir_name) + templates_model_dir = list(filter( + lambda model_dir: self.module in model_dir, + templates_model_dir)) + target_template_path = list(map( + lambda dir_name: os.path.join(templates_dir, dir_name), + templates_model_dir))[0] + templates_file_list = os.listdir(target_template_path) + if module == "audio" and board.startswith("hispark_taurus"): + templates_file_list = list(filter( + lambda x: x.startswith("hi35xx"), templates_file_list)) + return templates_file_list, target_template_path diff --git a/tools/hdf_dev_eco_tool/command_line/driver_add/linux/kconfig_file_add_config.py b/tools/hdf_dev_eco_tool/command_line/driver_add/linux/kconfig_file_add_config.py index 8f8e00d8..39848ebf 100644 --- a/tools/hdf_dev_eco_tool/command_line/driver_add/linux/kconfig_file_add_config.py +++ b/tools/hdf_dev_eco_tool/command_line/driver_add/linux/kconfig_file_add_config.py @@ -29,13 +29,13 @@ def kconfig_file_operation(path, module, driver, template_path): if judge_result: return temp_handle = Template(config_add_config) - data = { + temp_replace = { "model_name_upper": module.upper(), "model_name_lower": module.lower(), "driver_name_upper": driver.upper(), "driver_name_lower": driver.lower() } - new_line = temp_handle.substitute(data) + new_line = temp_handle.substitute(temp_replace) date_lines = date_lines + [new_line] hdf_utils.write_file_lines(kconfig_gn_path, date_lines) \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/command_line/driver_add/linux/mk_file_add_config.py b/tools/hdf_dev_eco_tool/command_line/driver_add/linux/mk_file_add_config.py index fafd1fe0..3faae35e 100644 --- a/tools/hdf_dev_eco_tool/command_line/driver_add/linux/mk_file_add_config.py +++ b/tools/hdf_dev_eco_tool/command_line/driver_add/linux/mk_file_add_config.py @@ -8,15 +8,16 @@ # See the LICENSE file in the root of this repository for complete details. +import os from string import Template import hdf_utils +from ..liteos.gn_file_add_config import analyze_parent_path def find_makefile_file_end_index(date_lines, model_name): file_end_flag = "ccflags-y" end_index = 0 - # INPUT_ROOT_DIR info model_dir_name = ("%s_ROOT_DIR" % model_name.upper()) model_dir_value = "" @@ -34,7 +35,67 @@ def find_makefile_file_end_index(date_lines, model_name): return result_tuple -def linux_makefile_operation(path, driver_file_path, module, driver): +def audio_linux_makefile_operation(path, args_tuple): + source_path, head_path, module, driver, root, devices = args_tuple + 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) + if judge_result: + return + if len(source_path) > 1: + sources_line = "" + obj_first_line = "\nobj-$(CONFIG_DRIVERS_HDF_${model_name_upper}_${driver_name_upper}) += \\"+"\n" + temp_line = "\t\t\t\t$(${file_parent_path})/${source_path}.o" + for source in source_path: + temp_handle = Template(temp_line.replace("$(", "temp_flag")) + temp_dict = analyze_parent_path( + date_lines, source, "", devices, root) + temp_dict['source_path'] = temp_dict['source_path'].strip(".c") + if source == source_path[-1]: + sources_line += temp_handle.substitute(temp_dict).replace("temp_flag", "$(") + "\n" + else: + sources_line += temp_handle.substitute(temp_dict).replace("temp_flag", "$(") + " \\" + "\n" + build_resource = obj_first_line + sources_line + else: + build_resource = "LOCAL_SRCS += $(${file_parent_path})/${source_path}\n" + for source in source_path: + temp_handle = Template(build_resource.replace("$(", "temp_flag")) + temp_dict = analyze_parent_path( + date_lines, source, "", devices, root) + build_resource = temp_handle.substitute(temp_dict).replace("temp_flag", "$(") + head_line = "" + ccflags_first_line = "\nccflags-$(CONFIG_DRIVERS_HDF_${model_name_upper}_${driver_name_upper}) += \\" + "\n" + temp_line = "\t\t\t\t-I$(srctree)/$(${file_parent_path})/${head_path}" + for head_file in head_path: + temp_handle = Template(temp_line.replace("$(", "temp_flag")) + temp_dict = analyze_parent_path( + date_lines, "", head_file, devices, root) + if head_file == head_path[-1]: + head_line += temp_handle.substitute(temp_dict).replace("temp_flag", "$(") + "\n" + else: + head_line += temp_handle.substitute(temp_dict).replace("temp_flag", "$(") + " \\" + "\n" + build_head = ccflags_first_line + head_line + makefile_add_template = build_resource + build_head + temp_handle = Template(makefile_add_template.replace("$(", "temp_flag")) + temp_replace = { + 'model_name_upper': module.upper(), + 'driver_name_upper': driver.upper(), + } + new_line = temp_handle.substitute(temp_replace).replace("temp_flag", "$(") + date_lines = date_lines + [new_line] + hdf_utils.write_file_lines(makefile_gn_path, date_lines) + + +def judge_driver_config_exists(date_lines, driver_name): + for _, line in enumerate(date_lines): + if line.startswith("#"): + continue + elif line.find(driver_name) != -1: + return True + return False + + +def linux_makefile_operation(path, driver_file_path, head_path, module, driver): makefile_gn_path = path date_lines = hdf_utils.read_file_lines(makefile_gn_path) source_file_path = driver_file_path.replace('\\', '/') @@ -46,25 +107,17 @@ def linux_makefile_operation(path, driver_file_path, module, driver): first_line = "\nobj-$(CONFIG_DRIVERS_HDF_${model_name_upper}_${driver_name_upper}) += \\\n" second_line = " $(${model_name_upper}_ROOT_DIR)/${source_file_path}\n" - makefile_add_template = first_line + second_line + third_line = "ccflags-y += -I$(srctree)/drivers/hdf/framework/model/${head_file_path}\n" + makefile_add_template = first_line + 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")) - d = { + temp_replace = { 'model_name_upper': module.upper(), 'driver_name_upper': driver.upper(), - 'source_file_path': makefile_path_config[-1].replace(".c", ".o") + 'source_file_path': makefile_path_config[-1].replace(".c", ".o"), + 'head_file_path': '/'.join(head_path.split("model")[-1].strip(os.path.sep).split(os.path.sep)[:-1]) } - new_line = temp_handle.substitute(d).replace("temp_flag", "$(") - - date_lines = date_lines[:end_index-1] + [new_line] + date_lines[end_index-1:] + new_line = temp_handle.substitute(temp_replace).replace("temp_flag", "$(") + date_lines = date_lines + [new_line] hdf_utils.write_file_lines(makefile_gn_path, date_lines) - - -def judge_driver_config_exists(date_lines, driver_name): - for _, line in enumerate(date_lines): - if line.startswith("#"): - continue - elif line.find(driver_name) != -1: - return True - return False \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/command_line/driver_add/liteos/gn_file_add_config.py b/tools/hdf_dev_eco_tool/command_line/driver_add/liteos/gn_file_add_config.py index 8fef9dbf..a8fd1cef 100644 --- a/tools/hdf_dev_eco_tool/command_line/driver_add/liteos/gn_file_add_config.py +++ b/tools/hdf_dev_eco_tool/command_line/driver_add/liteos/gn_file_add_config.py @@ -8,6 +8,8 @@ # See the LICENSE file in the root of this repository for complete details. +import re +import os from string import Template import hdf_utils @@ -35,31 +37,49 @@ def find_build_file_end_index(date_lines, model_name): return result_tuple -def build_file_operation(path, driver_file_path, module, driver): - +def audio_build_file_operation(path, args_tuple): + source_path, head_path, module, driver, root, devices, kernel = args_tuple build_gn_path = path date_lines = hdf_utils.read_file_lines(build_gn_path) - source_file_path = driver_file_path.replace('\\', '/') result_tuple = find_build_file_end_index(date_lines, model_name=module) judge_result = judge_driver_config_exists(date_lines, driver_name=driver) if judge_result: return end_index, frameworks_name, frameworks_value = result_tuple - + first_line = "\n if (defined(LOSCFG_DRIVERS_HDF_${model_name_upper}_${driver_name_upper})) {\n" - second_line = ' sources += [ "$FRAMEWORKS_${model_name_upper}_ROOT/${source_file_path}" ]\n' - third_line = " }\n" - build_add_template = first_line + second_line + third_line - include_model_info = frameworks_value.split("model")[-1].strip('"')+"/" - build_gn_path_config = source_file_path.split(include_model_info) - temp_handle = Template(build_add_template.replace("$FRAMEWORKS", "FRAMEWORKS")) - d = { + third_line = ' include_dirs += [ "$${file_parent_path}/${head_path}" ]\n' + four_line = " }\n" + if len(source_path) > 1: + sources_line = "" + multi_resource = " sources += [ \n" + multi_end = " ]\n" + temp_line = r' "$${file_parent_path}/${source_path}",' + for source in source_path: + temp_handle = Template(temp_line.replace("\"$", "temp_flag")) + temp_dict = analyze_parent_path( + date_lines, source, "", devices, root) + sources_line += temp_handle.substitute( + temp_dict).replace("temp_flag", "\"$") + "\n" + build_resource = multi_resource + sources_line + multi_end + else: + build_resource = ' sources += [ "$${file_parent_path}/${source_path}" ]\n' + for source in source_path: + temp_handle = Template(build_resource.replace("\"$", "temp_flag")) + temp_dict = analyze_parent_path( + date_lines, source, "", devices, root) + build_resource = temp_handle.substitute( + temp_dict).replace("temp_flag", "\"$") + build_add_template = first_line + build_resource + third_line + four_line + build_replace_dict = analyze_parent_path( + date_lines, "", head_path[0], devices, root, kernel_type=kernel) + temp_handle = Template(build_add_template.replace("\"$", "temp_flag")) + model_dict = { 'model_name_upper': module.upper(), 'driver_name_upper': driver.upper(), - 'source_file_path': build_gn_path_config[-1] } - new_line = temp_handle.substitute(d).replace("FRAMEWORKS", "$FRAMEWORKS") - + build_replace_dict.update(model_dict) + new_line = temp_handle.substitute(build_replace_dict).replace("temp_flag", "\"$") date_lines = date_lines[:end_index] + [new_line] + date_lines[end_index:] hdf_utils.write_file_lines(build_gn_path, date_lines) @@ -71,3 +91,81 @@ def judge_driver_config_exists(date_lines, driver_name): elif line.find(driver_name) != -1: return True return False + + +def analyze_parent_path(date, source_path, head_path, + devices, root, kernel_type="linux"): + str_re = "^[A-Z _ 0-9]+=" + macro_definition_dict = {} + for index, i in enumerate(date): + re_result = re.search(str_re, i) + if re_result: + str_split_list = i.strip().split(" = ") + if len(str_split_list) == 1 and str_split_list[0].endswith("="): + temp_name = str_split_list[0].split(" ")[0].strip("=") + macro_definition_dict[temp_name] = date[index + 1].strip() + else: + macro_definition_dict[str_split_list[0]] = str_split_list[-1] + date_replace = { + "file_parent_path": "", + "source_path": "", + "head_path": "", + } + if source_path: + parent_path = source_path.split(devices)[0].strip( + root).replace("\\", "/").strip("/") + else: + parent_path = head_path.split(devices)[0].strip( + root).replace("\\", "/").strip("/") + if kernel_type == "linux": + for k, v in macro_definition_dict.items(): + if v.find(parent_path) != -1: + if v.startswith("drivers/hdf/framework") and head_path.strip(): + date_replace['file_parent_path'] = k + elif source_path.strip() and not v.startswith("drivers/hdf/framework"): + date_replace['file_parent_path'] = k + else: + for k, v in macro_definition_dict.items(): + if v.find(parent_path) != -1: + date_replace['file_parent_path'] = k + if source_path: + file_source_path_full = source_path.replace("\\", "/") + date_replace['source_path'] = file_source_path_full.split( + parent_path)[-1].strip('/') + if head_path: + file_head_path_full = head_path.replace("\\", "/") + date_replace['head_path'] = '/'.join(file_head_path_full.split( + parent_path)[-1].split('/')[:-1]).strip('/') + return date_replace + + +def build_file_operation(path, driver_file_path, head_path, module, driver): + build_gn_path = path + date_lines = hdf_utils.read_file_lines(build_gn_path) + source_file_path = driver_file_path.replace('\\', '/') + result_tuple = find_build_file_end_index(date_lines, model_name=module) + judge_result = judge_driver_config_exists(date_lines, driver_name=driver) + if judge_result: + return + end_index, frameworks_name, frameworks_value = result_tuple + + first_line = "\n if (defined(LOSCFG_DRIVERS_HDF_${model_name_upper}_${driver_name_upper})) {\n" + include_line = ' include_dirs += [ "$FRAMEWORKS_${model_name_upper}_ROOT/${head_file_path}" ]\n' + second_line = ' sources += [ "$FRAMEWORKS_${model_name_upper}_ROOT/${source_file_path}" ]\n' + third_line = " }\n" + build_add_template = first_line + include_line + second_line + third_line + include_model_info = frameworks_value.split("model")[-1].strip('"') + "/" + build_gn_path_config = source_file_path.split(include_model_info) + temp_handle = Template(build_add_template.replace("$FRAMEWORKS", "FRAMEWORKS")) + temp_replace = { + 'model_name_upper': module.upper(), + 'driver_name_upper': driver.upper(), + 'source_file_path': build_gn_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("FRAMEWORKS", "$FRAMEWORKS") + + date_lines = date_lines[:end_index] + [new_line] + date_lines[end_index:] + hdf_utils.write_file_lines(build_gn_path, date_lines) diff --git a/tools/hdf_dev_eco_tool/command_line/driver_add/liteos/mk_file_add_config.py b/tools/hdf_dev_eco_tool/command_line/driver_add/liteos/mk_file_add_config.py index 651f9429..00b8aab5 100644 --- a/tools/hdf_dev_eco_tool/command_line/driver_add/liteos/mk_file_add_config.py +++ b/tools/hdf_dev_eco_tool/command_line/driver_add/liteos/mk_file_add_config.py @@ -8,11 +8,11 @@ # See the LICENSE file in the root of this repository for complete details. +import os from string import Template import hdf_utils - -from .gn_file_add_config import judge_driver_config_exists +from .gn_file_add_config import judge_driver_config_exists, analyze_parent_path def find_makefile_file_end_index(date_lines, model_name): @@ -37,7 +37,54 @@ def find_makefile_file_end_index(date_lines, model_name): return result_tuple -def makefile_file_operation(path, driver_file_path, module, driver): +def audio_makefile_file_operation(path, args_tuple): + source_path, head_path, module, driver, root, devices, kernel = args_tuple + 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) + if judge_result: + return + result_tuple = find_makefile_file_end_index(date_lines, model_name=module) + end_index, model_dir_name, model_dir_value = result_tuple + first_line = "\nifeq ($(LOSCFG_DRIVERS_HDF_${model_name_upper}_${driver_name_upper}), y)\n" + third_line = "LOCAL_INCLUDE += $(${file_parent_path})/${head_path}\n" + four_line = "endif\n" + + if len(source_path) > 1: + sources_line = "" + multi_resource = "LOCAL_SRCS += " + temp_line = r'$(${file_parent_path})/${source_path}' + for source in source_path: + temp_handle = Template(temp_line.replace("$(", "temp_flag")) + temp_dict = analyze_parent_path( + date_lines, source, "", devices, root) + if source == source_path[-1]: + sources_line += len(multi_resource)*" " + temp_handle.substitute(temp_dict).replace("temp_flag", "$(")+"\n" + else: + sources_line += temp_handle.substitute(temp_dict).replace("temp_flag", "$(")+" \\"+"\n" + build_resource = multi_resource + sources_line + else: + build_resource = "LOCAL_SRCS += $(${file_parent_path})/${source_path}\n" + for source in source_path: + temp_handle = Template(build_resource.replace("$(", "temp_flag")) + temp_dict = analyze_parent_path( + date_lines, source, "", devices, root) + build_resource = temp_handle.substitute(temp_dict).replace("temp_flag", "$(") + makefile_add_template = first_line + build_resource + third_line + four_line + makefile_replace_dict = analyze_parent_path( + date_lines, "", head_path[0], devices, root, kernel_type=kernel) + temp_handle = Template(makefile_add_template.replace("$(", "temp_flag")) + model_dict = { + 'model_name_upper': module.upper(), + 'driver_name_upper': driver.upper(), + } + makefile_replace_dict.update(model_dict) + new_line = temp_handle.substitute(makefile_replace_dict).replace("temp_flag", "$(") + date_lines = date_lines[:end_index-1] + [new_line] + date_lines[end_index-1:] + hdf_utils.write_file_lines(makefile_gn_path, date_lines) + + +def makefile_file_operation(path, driver_file_path, head_path, module, driver): 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) @@ -46,25 +93,29 @@ def makefile_file_operation(path, driver_file_path, module, driver): source_file_path = driver_file_path.replace('\\', '/') result_tuple = find_makefile_file_end_index(date_lines, model_name=module) end_index, model_dir_name, model_dir_value = result_tuple - + first_line = "\nifeq ($(LOSCFG_DRIVERS_HDF_${model_name_upper}_${driver_name_upper}), y)\n" + input_include_line = "LOCAL_INCLUDE += $(${model_name_upper}_ROOT_DIR)/${head_file_path}\n" 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" third_line = "endif\n" - if module == "sensor": - makefile_add_template = first_line + sensor_second_line + third_line + makefile_add_template = first_line + sensor_include_line + sensor_second_line + third_line else: - makefile_add_template = first_line + input_second_line + third_line - include_model_info = model_dir_value.split("model")[-1].strip('"')+"/" + 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")) - d = { + temp_replace = { 'model_name_upper': module.upper(), 'driver_name_upper': driver.upper(), - 'source_file_path': makefile_path_config[-1] + '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(d).replace("temp_flag", "$(") + new_line = temp_handle.substitute(temp_replace).replace("temp_flag", "$(") date_lines = date_lines[:end_index-1] + [new_line] + date_lines[end_index-1:] hdf_utils.write_file_lines(makefile_gn_path, date_lines) diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py b/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py index f7e78eb7..aad7cf77 100644 --- a/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py @@ -448,12 +448,12 @@ class HdfAddHandler(HdfCommandHandlerBase): hdf_utils.judge_file_path_exists(framework_drv_root_dir) add_driver = HdfAddDriver(args=self.args) - state, driver_file_path = add_driver.add_driver(*args_tuple) - + # create driver Source File (.c 、.h) + state, driver_file_list, driver_head_list = add_driver.add_driver(*args_tuple) if board == "hispark_taurus": - file_path = add_driver.add_liteos(driver_file_path) + file_path = add_driver.add_liteos(driver_file_list, driver_head_list) elif board.endswith("linux"): - file_path = add_driver.add_linux(driver_file_path) + file_path = add_driver.add_linux(driver_file_list, driver_head_list) else: file_path = [] @@ -461,7 +461,8 @@ class HdfAddHandler(HdfCommandHandlerBase): 'module_name': module, 'module_path': file_path, 'driver_name': "%s_driver.c" % driver, - 'driver_file_path': driver_file_path, + 'driver_file_path': driver_file_list, + 'head_file_path': driver_head_list, 'enabled': True } config_name = "create_driver.config" @@ -483,5 +484,3 @@ class HdfAddHandler(HdfCommandHandlerBase): drv_config = HdfDriverConfigFile(root, board, module, driver, kernel) drv_config.create_driver() return drv_config.get_drv_config_path() - - diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_device_info_hcs.py b/tools/hdf_dev_eco_tool/command_line/hdf_device_info_hcs.py index 9dd51028..a9e0cc04 100644 --- a/tools/hdf_dev_eco_tool/command_line/hdf_device_info_hcs.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_device_info_hcs.py @@ -32,6 +32,8 @@ class HdfDeviceInfoHcsFile(object): self.data = { "driver_name": self.driver, "model_name": self.module, + "module_upper_case": self.module.upper(), + "driver_upper_case": self.driver.upper(), "module_name": "_".join([self.module, self.driver]).upper() } else: @@ -152,7 +154,7 @@ class HdfDeviceInfoHcsFile(object): self._save() return self.hcspath - def add_hcs_config_to_exists_model(self): + def add_hcs_config_to_exists_model(self, device): template_path = os.path.join(self.file_path, 'exists_model_hcs_info.template') lines = list(map(lambda x: "\t\t\t" + x, @@ -160,11 +162,17 @@ class HdfDeviceInfoHcsFile(object): old_lines = list(filter(lambda x: x != "\n", hdf_utils.read_file_lines(self.hcspath))) + if self.judge_module_branch_exists(date_lines=old_lines): + return self.hcspath end_index, start_index = self._get_model_index(old_lines) model_hcs_lines = old_lines[start_index:end_index] hcs_judge = self.judge_driver_hcs_exists(date_lines=model_hcs_lines) if hcs_judge: return self.hcspath + temp_replace_dict = { + "device_upper_case": device.upper() + } + self.data.update(temp_replace_dict) for index, _ in enumerate(lines): lines[index] = Template(lines[index]).substitute(self.data) @@ -199,3 +207,12 @@ class HdfDeviceInfoHcsFile(object): elif line.find(self.driver) != -1: return True return False + + def judge_module_branch_exists(self, date_lines): + module_branch_start = "%s :: host" % self.module + for _, line in enumerate(date_lines): + if line.startswith("#"): + continue + elif line.strip().find(module_branch_start) != -1: + return False + return True diff --git a/tools/hdf_dev_eco_tool/hdf_tool_settings.py b/tools/hdf_dev_eco_tool/hdf_tool_settings.py index 1b7c2c5e..8b5b8d29 100644 --- a/tools/hdf_dev_eco_tool/hdf_tool_settings.py +++ b/tools/hdf_dev_eco_tool/hdf_tool_settings.py @@ -45,7 +45,8 @@ class HdfToolSettings(object): (self.file_path, str(exc)), CommandErrorCode.FILE_FORMAT_WRONG) self.supported_boards_key = 'supported_boards' - self.drivers_path_key = 'drivers_path_relative_to_vendor' + self.drivers_path_key_framework = 'drivers_path_relative_framework' + self.drivers_path_key_peripheral = 'drivers_path_relative_peripheral' self.drivers_adapter_path_key = 'drivers_path_relative_adapter' self.user_adapter_path_key = 'user_model_path_relative_adapter' self.dot_configs_key = 'dot_configs' @@ -69,7 +70,11 @@ class HdfToolSettings(object): return board_entry.get(key, '') def get_drivers_path_framework(self): - key = self.drivers_path_key + key = self.drivers_path_key_framework + return self.settings.get(key, 'hdf') + + def get_drivers_path_peripheral(self): + key = self.drivers_path_key_peripheral return self.settings.get(key, 'hdf') def get_drivers_path_adapter(self): diff --git a/tools/hdf_dev_eco_tool/hdf_utils.py b/tools/hdf_dev_eco_tool/hdf_utils.py index 729a8d6f..2425a0ca 100644 --- a/tools/hdf_dev_eco_tool/hdf_utils.py +++ b/tools/hdf_dev_eco_tool/hdf_utils.py @@ -202,6 +202,11 @@ def get_vendor_hdf_dir_framework(root): return os.path.join(root, relative_path) +def get_vendor_hdf_dir_peripheral(root): + relative_path = HdfToolSettings().get_drivers_path_peripheral() + return os.path.join(root, relative_path) + + def get_vendor_hdf_dir_adapter(root, kernel='liteos'): relative_path = HdfToolSettings().get_drivers_path_adapter() return os.path.join(root, relative_path, kernel) @@ -236,6 +241,10 @@ def get_drv_src_dir(root, module): return get_drv_root_dir(root, module) +def get_drv_src_dir_peripheral(root, module): + return get_vendor_hdf_dir_peripheral(root) + + def get_drv_include_dir(root, module, driver): return os.path.join(get_drv_dir(root, module, driver), 'include') @@ -382,14 +391,14 @@ def write_config(root_path, config_file_json, config_name): config_file_replace) -def ini_file_read_operation(model, node_name, path=""): +def ini_file_read_operation(section_name, node_name, path=""): if path: ini_config_path = path else: ini_config_path = os.path.join("resources", "config.ini") config = configparser.ConfigParser() config.read(ini_config_path) - model_child_dir_list = config.get(section=model, option=node_name) + model_child_dir_list = config.get(section=section_name, option=node_name) return literal_eval(model_child_dir_list), config diff --git a/tools/hdf_dev_eco_tool/resources/config.ini b/tools/hdf_dev_eco_tool/resources/config.ini index 01a22bff..34ed27a9 100644 --- a/tools/hdf_dev_eco_tool/resources/config.ini +++ b/tools/hdf_dev_eco_tool/resources/config.ini @@ -1,6 +1,18 @@ [input] +driver_path = "" file_dir = ["input_bus_ops", "touchscreen"] [sensor] +driver_path = "chipsets" file_dir = ["accel", "als", "barometer", "gyro", "hall", "magnetic", "pedometer", "proximity"] +[audio] +driver_path = "device/board/hisilicon/hispark_taurus/audio_drivers" +file_dir = ["codec", "dsp", "soc"] + +[peripheral] +devices_list = ["audio"] + +[framework] +devices_list = ["input", "sensor"] + diff --git a/tools/hdf_dev_eco_tool/resources/create_driver.config b/tools/hdf_dev_eco_tool/resources/create_driver.config index 2c63c085..7a73a41b 100644 --- a/tools/hdf_dev_eco_tool/resources/create_driver.config +++ b/tools/hdf_dev_eco_tool/resources/create_driver.config @@ -1,2 +1,2 @@ { -} +} \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/resources/settings.json b/tools/hdf_dev_eco_tool/resources/settings.json index aa3f6fda..48bdf305 100644 --- a/tools/hdf_dev_eco_tool/resources/settings.json +++ b/tools/hdf_dev_eco_tool/resources/settings.json @@ -33,7 +33,8 @@ "patch_and_config": [] } }, - "drivers_path_relative_to_vendor": "drivers/framework", + "drivers_path_relative_framework": "drivers/framework", + "drivers_path_relative_peripheral": "drivers/peripheral", "drivers_path_relative_adapter": "drivers/adapter/khdf", "user_model_path_relative_adapter": "drivers/adapter/uhdf2", "template_file_path": "tools/hdf_dev_eco_tool/resources/templates/lite" diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/audio_template/hi35xx_audio_adapter_source.template b/tools/hdf_dev_eco_tool/resources/templates/lite/audio_template/hi35xx_audio_adapter_source.template new file mode 100644 index 00000000..c55fce20 --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/audio_template/hi35xx_audio_adapter_source.template @@ -0,0 +1,103 @@ +#include "${device_lower_case}_${driver_lower_case}_ops.h" +#include "audio_codec_base.h" +#include "audio_codec_if.h" +#include "audio_driver_log.h" + +#define HDF_LOG_TAG HDF_AUDIO_DRIVER + +struct CodecData g_${driver_lower_case}Data = { + .Init = ${driver_upper_camel_case}DeviceInit, + .Read = CodecDeviceRegI2cRead, + .Write = CodecDeviceRegI2cWrite, +}; + +struct AudioDaiOps g_${driver_lower_case}DaiDeviceOps = { + .Startup = ${driver_upper_camel_case}DaiStartup, + .HwParams = ${driver_upper_camel_case}DaiHwParams, +}; + +struct DaiData g_${driver_lower_case}DaiData = { + .drvDaiName = "${driver_lower_case}_codec_dai", + .DaiInit = ${driver_upper_camel_case}DaiDeviceInit, + .ops = &g_${driver_lower_case}DaiDeviceOps, + .Read = CodecDaiRegI2cRead, + .Write = CodecDaiRegI2cWrite, +}; + +/* HdfDriverEntry implementations */ +static int32_t ${driver_upper_camel_case}DriverBind(struct HdfDeviceObject *device) +{ + (void)device; + AUDIO_DRIVER_LOG_INFO("success!"); + return HDF_SUCCESS; +} + +static int32_t ${driver_upper_camel_case}DriverInit(struct HdfDeviceObject *device) +{ + int32_t ret; + if (device == NULL) { + AUDIO_DRIVER_LOG_ERR("device is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + + ret = CodecGetConfigInfo(device, &g_${driver_lower_case}Data); + if (ret != HDF_SUCCESS) { + AUDIO_DRIVER_LOG_ERR("get config info failed."); + return ret; + } + + if (CodecSetConfigInfo(&g_${driver_lower_case}Data, &g_${driver_lower_case}DaiData) != HDF_SUCCESS) { + AUDIO_DRIVER_LOG_ERR("set config info failed."); + return HDF_FAILURE; + } + + if (CodecGetServiceName(device, &g_${driver_lower_case}Data.drvCodecName) != HDF_SUCCESS) { + AUDIO_DRIVER_LOG_ERR("get codec service name failed."); + return HDF_FAILURE; + } + + if (CodecGetDaiName(device, &g_${driver_lower_case}DaiData.drvDaiName) != HDF_SUCCESS) { + AUDIO_DRIVER_LOG_ERR("get codec dai service name failed."); + return HDF_FAILURE; + } + + OsalMutexInit(&g_${driver_lower_case}Data.mutex); + + ret = AudioRegisterCodec(device, &g_${driver_lower_case}Data, &g_${driver_lower_case}DaiData); + if (ret != HDF_SUCCESS) { + AUDIO_DRIVER_LOG_ERR("AudioRegisterCodec failed."); + return ret; + } + AUDIO_DRIVER_LOG_INFO("success!"); + return HDF_SUCCESS; +} + +static void ${driver_upper_camel_case}DriverRelease(struct HdfDeviceObject *device) +{ + if (device == NULL) { + AUDIO_DRIVER_LOG_ERR("device is NULL"); + return; + } + + OsalMutexDestroy(&g_${driver_lower_case}Data.mutex); + + if (device->priv != NULL) { + OsalMemFree(device->priv); + } + struct CodecHost *codecHost = (struct CodecHost *)device->service; + if (codecHost == NULL) { + HDF_LOGE("CodecDriverRelease: codecHost is NULL"); + return; + } + OsalMemFree(codecHost); +} + +/* HdfDriverEntry definitions */ +struct HdfDriverEntry g_${driver_lower_case}_${device_lower_case}DriverEntry = { + .moduleVersion = 1, + .moduleName = "${device_upper_case}_${driver_upper_case}", + .Bind = ${driver_upper_camel_case}DriverBind, + .Init = ${driver_upper_camel_case}DriverInit, + .Release = ${driver_upper_camel_case}DriverRelease, +}; +HDF_INIT(g_${driver_lower_case}_${device_lower_case}DriverEntry); diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/audio_template/hi35xx_audio_ops_head.template b/tools/hdf_dev_eco_tool/resources/templates/lite/audio_template/hi35xx_audio_ops_head.template new file mode 100644 index 00000000..edad3079 --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/audio_template/hi35xx_audio_ops_head.template @@ -0,0 +1,28 @@ +#ifndef ${device_upper_case}_${driver_upper_case}_OPS_H +#define ${device_upper_case}_${driver_upper_case}_OPS_H + +#include +#include "osal_io.h" +#include "osal_mem.h" +#include "osal_time.h" +#include "securec.h" +#include "audio_codec_if.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +int32_t ${driver_upper_camel_case}DeviceInit(struct AudioCard *audioCard, const struct CodecDevice *device); +int32_t ${driver_upper_camel_case}DaiDeviceInit(struct AudioCard *card, const struct DaiDevice *device); +int32_t ${driver_upper_camel_case}DaiStartup(const struct AudioCard *card, const struct DaiDevice *device); +int32_t ${driver_upper_camel_case}DaiHwParams(const struct AudioCard *card, const struct AudioPcmHwParams *param); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif + +#endif diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/audio_template/hi35xx_audio_ops_source.template b/tools/hdf_dev_eco_tool/resources/templates/lite/audio_template/hi35xx_audio_ops_source.template new file mode 100644 index 00000000..bfba4491 --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/audio_template/hi35xx_audio_ops_source.template @@ -0,0 +1,30 @@ +#include "${device_lower_case}_${driver_lower_case}_ops.h" +#include "audio_codec_base.h" +#include "audio_driver_log.h" +#include "gpio_if.h" + +#define HDF_LOG_TAG HDF_AUDIO_DRIVER + +int32_t ${driver_upper_camel_case}DeviceInit(struct AudioCard *audioCard, const struct CodecDevice *device) +{ + AUDIO_DEVICE_LOG_DEBUG("success."); + return HDF_SUCCESS; +} + +int32_t ${driver_upper_camel_case}DaiDeviceInit(struct AudioCard *card, const struct DaiDevice *device) +{ + AUDIO_DEVICE_LOG_DEBUG("success."); + return HDF_SUCCESS; +} + +int32_t ${driver_upper_camel_case}DaiStartup(const struct AudioCard *card, const struct DaiDevice *device) +{ + AUDIO_DEVICE_LOG_DEBUG("success."); + return HDF_SUCCESS; +} + +int32_t ${driver_upper_camel_case}DaiHwParams(const struct AudioCard *card, const struct AudioPcmHwParams *param) +{ + AUDIO_DEVICE_LOG_DEBUG("success."); + return HDF_SUCCESS; +} \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/exists_model_hcs_info.template b/tools/hdf_dev_eco_tool/resources/templates/lite/exists_model_hcs_info.template index c2b54928..42cdc9cc 100644 --- a/tools/hdf_dev_eco_tool/resources/templates/lite/exists_model_hcs_info.template +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/exists_model_hcs_info.template @@ -4,7 +4,8 @@ device_${model_name}_${driver_name} :: device { // Device node of sample priority= 100; // Driver startup priority (0-200). A larger value indicates a lower priority. The default value 100 is recommended. If the priorities are the same, the device loading sequence is random. preload = 0; // On-demand loading of the driver. For details, see "NOTE" at the end of this section. permission = 0664; // Permission for the driver to create device nodes. - moduleName = "${driver_name}_driver"; // Driver name. The value of this field must be the same as the value of moduleName in the driver entry structure. + moduleName = "${device_upper_case}_${driver_upper_case}"; + // Driver name. The value of this field must be the same as the value of moduleName in the driver entry structure. serviceName = "${driver_name}_service"; // Name of the service released by the driver. The name must be unique. deviceMatchAttr = ""; // Keyword matching the private data of the driver. The value must be the same as that of match_attr in the private data configuration table of the driver. } diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/input_template/input_driver_source.template b/tools/hdf_dev_eco_tool/resources/templates/lite/input_template/input_driver_source.template index 9c726c44..73b22c03 100644 --- a/tools/hdf_dev_eco_tool/resources/templates/lite/input_template/input_driver_source.template +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/input_template/input_driver_source.template @@ -344,7 +344,7 @@ static void HdfGoodixChipRelease(struct HdfDeviceObject *device) struct HdfDriverEntry g_touchchip_${driver_lower_case}Entry = { .moduleVersion = 1, - .moduleName = "INPUT_${driver_upper_case}", + .moduleName = "${device_upper_case}_${driver_upper_case}", .Bind = HdfGoodixChipBind, .Init = HdfGoodixChipInit, .Release = HdfGoodixChipRelease, diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/sensor_template/accel_sensor_driver_source.template b/tools/hdf_dev_eco_tool/resources/templates/lite/sensor_template/accel_sensor_driver_source.template index f1a95cd0..cdebffc3 100644 --- a/tools/hdf_dev_eco_tool/resources/templates/lite/sensor_template/accel_sensor_driver_source.template +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/sensor_template/accel_sensor_driver_source.template @@ -149,7 +149,7 @@ void ${driver_upper_camel_case}ReleaseDriver(struct HdfDeviceObject *device) struct HdfDriverEntry g_accel${driver_upper_camel_case}DevEntry = { .moduleVersion = 1, - .moduleName = "SENSOR_${driver_upper_case}", + .moduleName = "${device_upper_case}_${driver_upper_case}", .Bind = ${driver_upper_camel_case}BindDriver, .Init = ${driver_upper_camel_case}InitDriver, .Release = ${driver_upper_camel_case}ReleaseDriver,