ESP-IDF如何在已有项目中使用Component
esp32的component组件的编程方法很赞,把一些常用代码直接抽象成一个组件,可以在自己任意的项目中直接引用。
比如说我要使用esp32的light_drive的组件的话,我只需要一行命令就可以使用了。
在最顶层的cmakelists.txt中增加
set(EXTRA_COMPONENT_DIRS
$ENV{IDF_PATH}/examples/bluetooth/esp_ble_mesh/common_components/button
$ENV{IDF_PATH}/examples/bluetooth/esp_ble_mesh/common_components/light_driver
$ENV{IDF_PATH}/examples/bluetooth/esp_ble_mesh/common_components/example_init
$ENV{IDF_PATH}/examples/bluetooth/esp_ble_mesh/common_components/example_nvs)
在最顶层的Makefile中增加
PROJECT_NAME := aligenie_demo
EXTRA_COMPONENT_DIRS := $(IDF_PATH)/examples/bluetooth/esp_ble_mesh/common_components/button
EXTRA_COMPONENT_DIRS += $(IDF_PATH)/examples/bluetooth/esp_ble_mesh/common_components/light_driver
EXTRA_COMPONENT_DIRS += $(IDF_PATH)/examples/bluetooth/esp_ble_mesh/common_components/example_init
EXTRA_COMPONENT_DIRS += $(IDF_PATH)/examples/bluetooth/esp_ble_mesh/common_components/example_nvs
include $(IDF_PATH)/make/project.mk
路径的话自己选择了,一般在自己的工程下建一个components的文件夹里面放多个组件。也可以直接使用idf里面通用的库。