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

HAL refactoring: better callbacks #1293

Open
martukas opened this issue Jul 31, 2022 · 0 comments · May be fixed by #1294
Open

HAL refactoring: better callbacks #1293

martukas opened this issue Jul 31, 2022 · 0 comments · May be fixed by #1294
Labels
Controller code hardware controller project Software Umbrella: GUI, Controller or CI

Comments

@martukas
Copy link
Member

Need to implement a better way of doing callbacks in the HAL. Currently we have some callbacks for interrupt handlers and for high priority trigger that either:

  • must use a global function, or
  • must pass the object the method thereof we want to call, as in the case of communications channels

What we want to do is to be able to pass a generic callback that may also encapsulate a reference to the object upon which it is called. * the caller should not have to be aware of the object's class

  • there shouldn't have to be global instances of objects

The goal here is to further decouple dependencies. The interrupt implementation should not have to be aware of or hard-code who it is calling on to handle the interrupts. The handlers should not have to refer to any global objects nor possibly even singletons. It should be possible to bind these dependencies in a flexible way at a pretty high level - main.cpp or main_loop.*.

How do you know it has to be done

This is still a stumbling block for decoupling generic libraries from the ICD/computing hardware definitions, because instantiation/initialization of the high priority trigger requires selection of specific channels and timers. We need this done so we can have interchangeable configurations for different hardware setups without having many ifdefs scattered throughout many source files, which makes the code hard to maintain and audit.

Starting points
Using <functional> is not an option, as it brings in stdlib and heap memory. Possible solutions:
https://codereview.stackexchange.com/questions/152031/simple-callback-wrapper-for-an-embedded-c-app
https://stackoverflow.com/questions/61304132/embedded-c11-member-function-callback

@martukas martukas added Controller code hardware controller project Software Umbrella: GUI, Controller or CI labels Jul 31, 2022
@martukas martukas linked a pull request Jul 31, 2022 that will close this issue
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Controller code hardware controller project Software Umbrella: GUI, Controller or CI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant