• 中文论坛
  • bl602使用bl_iot_sdk,如何添加自己的.c文件.h文件

不想把所有的代码都放到main.c里面,请问如何添加自己的文件和文件夹呢?

    通过读makefile知道了,components路径如下所示。

    # Component directories. These directories are searched for components (either the directory is a component,
    # or the directory contains subdirectories which are components.)
    # The project Makefile can override these component dirs, or add extras via EXTRA_COMPONENT_DIRS
    ifndef COMPONENT_DIRS
    EXTRA_COMPONENT_DIRS ?=
    COMPONENT_DIRS := $(PROJECT_PATH)/components $(EXTRA_COMPONENT_DIRS) $(BL60X_SDK_PATH)/components $(BL60X_SDK_PATH)/customer_components $(PROJECT_PATH)/$(PROJECT_NAME) $(PROJECT_COMPONENT)
    endif
    export COMPONENT_DIRS
    1. 工程目录下和SDK目录下的components文件夹
    2. SDK目录下的customer_components文件夹
    3. PROJECT_COMPONENTEXTRA_COMPONENT_DIRS定义的目录
    4. PROJECT_PATH/PROJECT_NAME目录

    下面这部分代码没看很明白,不过大概意思知道了。这部分代码就是添加对应的components的makefile的规则。

    # The project Makefile can define a list of components, but if it does not do this we just take all available components
    # in the component dirs. A component is COMPONENT_DIRS directory, or immediate subdirectory,
    # which contains a bouffalo.mk file.
    #
    # Use the "make list-components" target to debug this step.
    #ifndef COMPONENTS
    # Find all component names. The component names are the same as the
    # directories they're in, so /bla/components/mycomponent/bouffalo.mk -> mycomponent.
    # using by https://stackoverflow.com/questions/3774568/makefile-issue-smart-way-to-scan-directory-tree-for-c-files
    ifeq ("$(wildcard ${BL60X_SDK_PATH}/components.mk)","")
    rwildcard = $(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
    COMPONENTS_RAL_PATH :=  $(dir $(foreach cd,$(COMPONENT_DIRS),                       \
    						$(call rwildcard,$(cd)/,bouffalo.mk) 						\
    				))
    COMPONENTS := $(sort $(foreach comp,$(COMPONENTS_RAL_PATH),$(lastword $(subst /, ,$(comp)))))
    COMPONENTS_REAL_PATH := $(patsubst %/,%,$(COMPONENTS_RAL_PATH))
    else
    COMPONENTS := $(notdir $(PROJECT_PATH))
    COMPONENTS_REAL_PATH := $(PROJECT_PATH)/$(notdir $(PROJECT_PATH))
    include $(BL60X_SDK_PATH)/components.mk
    $(info use existing components.mk file)
    endif
      Write a Reply...
      @ 2025 Bouffalo Lab (Nanjing) Co., Ltd. All rights reserved.