Bedtime. /LEDs

LEDs

The four RGB LEDs - driven directly, or through the OS pattern engine

The device has 4 RGB LEDs, indexed 0-3. The OS runs its own animations on them, so stop whatever is playing before driving them directly:

os_led_stop_current();               // once, in init()
hal_led_set_rgb(0, 100, 70, 20);     // then from tick()

Patterns versus direct writes

Writing from tick() is the simple route and costs nothing but the call. For anything that animates on its own clock, hand the OS a led_pattern_t instead: the LED task steps it on its own timer, so the animation keeps running at a steady rate even when the app's tick() is busy, and it survives a skipped frame. See examples/leds/ for a pattern usage example.

Note — When the app exits the firmware blanks the LEDs and re-pushes the pattern that was running before it - there is nothing to restore in deinit().

void hal_led_set_rgb(const uint8_t led_num, const uint8_t red, const uint8_t green, const uint8_t blue)

Set one LED's colour

const uint8_tled_numLED index, 0-3
const uint8_tred0-255
const uint8_tgreen0-255
const uint8_tblue0-255

Note — The driver latches: an LED keeps its last written colour until it is changed (or the app exits - the firmware blanks and restores then).

void os_led_stop_current(void)

Stop the OS LED pattern currently playing

uint8_t os_led_get_step(const os_led_t* led)

Read the step counter from inside a pattern callback

const os_led_t*led
void os_led_set_pattern(led_pattern_t* pattern, const void* ctx)

Start a pattern, replacing whatever is currently playing

led_pattern_t*pattern
const void*ctxbecomes the pattern's ctx for this run (NULL clears it) - the callback reads it

Note — The pattern outlives the call - give it static storage, not a local.