Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MCPWM_GEN_COMPARE_EVENT_ACTION_END() doesnt exist? #337

Closed
Violabitch5 opened this issue Sep 8, 2024 · 3 comments
Closed

MCPWM_GEN_COMPARE_EVENT_ACTION_END() doesnt exist? #337

Violabitch5 opened this issue Sep 8, 2024 · 3 comments

Comments

@Violabitch5
Copy link

Hi there,

Ive looked through the open and closed issues, but it doesnt look like this has been discussed so far.

After creating a MCPWM generator, it can be fed with a list of actions via

esp_idf_sys::mcpwm_generator_set_actions_on_compare_event

This list needs to be terminated with this macro:

MCPWM_GEN_COMPARE_EVENT_ACTION_END()

which I cannot find anywhere in the crate. Also, the existing actions are just constants from 0 to 3. So just feeding a 0 at the end wont work either.

Workaround is obviously to use the function which only feeds one action at a time:

esp_idf_sys::mcpwm_generator_set_action_on_compare_event

I guess its not that of a big deal, but it just leads to more boilerplate code when a longer list is used.

https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/peripherals/mcpwm.html#mcpwm-generator-actions-on-events
image

@Vollbrecht
Copy link
Collaborator

Vollbrecht commented Sep 8, 2024

We dont directly translate preprocessor C macros into rust code. That is true for every C macro.

Though you don't need to loose hope ;D Just have a look at the definition of the macro and you see, all it does it creates a additional instance of mcpwm_gen_compare_event_action_t in the last spot, and set the comparator field to Null. In other words you need to make sure that for the last element mcpwm_gen_compare_event_action_t the comparator field is set NULL.

@ivmarkov
Copy link
Collaborator

ivmarkov commented Sep 8, 2024

bindgen is limited in that it cannot expose to Rust any C macro but the most simple ones which define constants.
Other than re-implementing the equivalent of MCPWM_GEN_COMPARE_EVENT_ACTION_END (by looking at the ESP IDF source code) I don't have other "easy" ideas.

This is also what we do when we have to reach to ESP IDF function macros...

A more complex idea would be for esp-idf-sys to somehow have a whole new machinery - in the form of abilities to compile .c files which are separate from ESP IDF itself, and then wrap a bunch of hard-coded pre-defined macros from ESP IDF as C functions (which you can then call from Rust). Certainly possible, but a lot of work.

@Violabitch5
Copy link
Author

Ok, good to know!

Thanks a lot for the quick response guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

3 participants