Espressif ESP32-S2 Programming Manual page 1290

Table of Contents

Advertisement

Chapter 4. API Guides
- autoProject/
- CMakeLists.txt
- components/ - car/ - CMakeLists.txt
Car component
The car.h header file is the public interface for the car component. This header includes
engine.h directly because it uses some declarations from this header:
/* car.h */
#include
"engine.h"
#ifdef ENGINE_IS_HYBRID
#define CAR_MODEL "Hybrid"
#endif
And car.c includes car.h as well:
/* car.c */
#include
"car.h"
This means the car/CMakeLists.txt file needs to declare that car requires engine:
idf_component_register(SRCS "car.c"
INCLUDE_DIRS "."
REQUIRES
• SRCS gives the list of source files in the car component.
• INCLUDE_DIRS gives the list of public include directories for this component. Because the public interface
is car.h, the directory containing car.h is listed here.
• REQUIRES gives the list of components required by the public interface of this component. Because car.h
is a public header and includes a header from engine, we include engine here. This makes sure that any
other component which includes car.h will be able to recursively include the required engine.h also.
Engine component
The engine component also has a public header file include/engine.h, but this header
is simpler:
/* engine.h */
#define ENGINE_IS_HYBRID
void
engine_start(void);
The implementation is in engine.c:
/* engine.c */
#include
"engine.h"
#include
"spark_plug.h"
...
In this component, engine depends on spark_plug but this is a private dependency. spark_plug.h is needed
to compile engine.c, but not needed to include engine.h.
This means that the engine/CMakeLists.txt file can use PRIV_REQUIRES:
Espressif Systems
- car.c
- car.h
- engine/ - CMakeLists.txt
- engine.c
- include/ - engine.h
- spark_plug/
- CMakeLists.txt
- plug.c
- plug.h
engine)
1279
Submit Document Feedback
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents

Save PDF