Runnable component template

InterBilly
Posts: 13
Joined: Mon Jul 31, 2023 4:53 pm

Runnable component template

Postby InterBilly » Tue Oct 24, 2023 11:35 am

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!

ESP_jakob
Posts: 49
Joined: Mon Jun 01, 2020 6:28 am

Re: Runnable component template

Postby ESP_jakob » Wed Oct 25, 2023 2:44 am

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?

InterBilly
Posts: 13
Joined: Mon Jul 31, 2023 4:53 pm

Re: Runnable component template

Postby InterBilly » Wed Oct 25, 2023 7:02 am

Thank you! That helped a lot, stupid of me that I never noticed the test_apps folders :roll:

Who is online

Users browsing this forum: Bing [Bot], ShinyGlossy and 334 guests