compile-time-init-build
compile-time-init-build copied to clipboard
How to port coroutine-style code & event loops to CIB ?
Hi I have just watched the seminar on the cib.hpp
library. I like how we can modularize hardware functions as services, and bind them with external commands, without runtime overhead.
Following #30 , how do I refactor a FreeRTOS-style code from the following LED blinker example to cib.hpp
? Here, there are two co-routines performing their own initializations, and then enters their own event loops iterating at 1000ms and 200ms correspondingly. I am assuming a single-thread application compiled by either avr-gcc
or stm32-aarch64-gcc
.
volatile bool is_led_on = false;
void loopLED() noexcept {
setupLED();
bool led_blink_state = true;
for(;;) {
if(is_led_on) {
digitalWrite(led_blink_state);
led_blink_state = ! led_blink_state;
} else {
digitalWrite(false);
}
using std::chrono_literal;
Rtos.resume_after(1000ms);
}
teardownLED();
}
void loopButton() noexcept {
setupButton();
for (;;) {
if (button1.is_pressed()) {
is_led_on = ! is_led_on;
}
using std::chrono_literal;
Rtos.resume_after(200ms);
}
teardownButton();
}
In particular, how do I refactor the above setup -> event loop -> teardown
code to utilize CIB's compile time init()
flow builder? How do I bind the button press event to the LED service? I hope to watch and learn how it is done in the CIB style.