How to integrate multiple demos of ESP32 into one project

During the development of ESP32, Espressif officially provided a lot of routines to help us learn to use each function, but each routine has only its specific function, so we need to combine the routines to achieve what we want. function.

It's easy for big guys. However, it is more difficult for novices to find (after all, it is too simple, and no one has recorded it. The editor has been in the pit for a long time, so I will share it with you. I have tried various macro definitions before and it cannot compile)

The following analysis takes wifi and Ethernet as examples

First, we open a single project to view the components of the project

At this point, we can see that there are a lot of config files, we must pay attention, what we modify is Kconfig.projbuild, all the macros in the settings (idf.py menuconfig) are added here, and the way to add is to copy and paste (The conflicting (same) can be removed), but remember not to copy the menu "Example Configuration" when copying  , because there is only one copy in a file, and similarly, redundant ones can also be deleted here.   

At this point, the default macro definition has been added, but it is impossible for us to modify it here every time, so we also need to learn to configure it in idf.py menuconfig (however, before configuring idf.py menuconfig, you must first configure it in Kconfig Add .projbuild first, otherwise this option will not appear in idf.py menuconfig)

Of course, if you are not used to using the command line, there is a way (the editor recommends practicing using the command line more, and the command line is also commonly used in other places). At this time, we can find the sdkconfig file in vs code, and enter the configuration in this file (modify The sdkconfig file has the same function as configuring idf.py menuconfig), but it should be noted that you can directly unblock and enable the function here

After the above modification, the configuration is basically completed, and the code can be modified.

At this time, we copy another project function (the main function cannot be copied, static  const  char  * TAG  =  "eth_wifi_example" ; cannot be copied), and then copy the header file (remove the duplicate header file), and then copy the demo main The macro definition in the c file is also transplanted

Later, some global variables are also transplanted

The principle of porting and splicing of other projects is the same, and the operation of project cutting is reversed. From then on, logic can be written. The next article will explain the streaming code architecture and write wifi Ethernet switching.

Guess you like

Origin blog.csdn.net/m0_45068979/article/details/131309763