Page 1 of 1

Runnable component template

Posted: Tue Oct 24, 2023 11:35 am
by InterBilly
For an assignment I will need to create a lot of custom components that I will use in different IDF projects, so I wanted to create a template for this. The thing is, I also want to be able to open these components as a project and be runnable with a main.c to test/develop functionalities.

Via the documentation I figured out how to create and add new components to a project, but I cant manage to create a component that can be run by a main.c in the same component folder.

Making component:
idf.py -C x:/.../custom_components create-component cus_twai

I get:

components/ // idf components
custom_components/ // custom components
____cus_twai/ // custom implementation of twai
________include/
____________cus_twai.h
________cus_twai.c
I would also like:
________main.c // includes cus_twai

I tried adding a main to make it runnable but this didn't work and I couldn't figure out why (inexperienced with CMake etc).
Should I maybe try to make a working project into a component? Or am I maybe approaching this all wrong?
Any advice is greatly appreciated, thank you!

Re: Runnable component template

Posted: Wed Oct 25, 2023 2:44 am
by ESP_jakob
For testing and example applications, you could simply add a project inside your component. This is done for many IDF components which have a "test_apps" directory containing test apps. Similarly, you can add examples like this. You need to make sure to correctly use the enclosing component then, e.g. by something like

Code: Select all

list(APPEND EXTRA_COMPONENT_DIRS "../")
in your test app's CMakeLists.txt.

Would that work for you?

Re: Runnable component template

Posted: Wed Oct 25, 2023 7:02 am
by InterBilly
Thank you! That helped a lot, stupid of me that I never noticed the test_apps folders :roll: