Skip to content

File syn_led.c

FileList > output > syn_led.c

Go to the source code of this file

LED controller implementation.

  • #include "../drivers/syn_gpio.h"
  • #include "../util/syn_assert.h"
  • #include "syn_led.h"
  • #include <string.h>

Public Functions

Type Name
void syn_led_blink (SYN_LED * led, uint16_t on_ms, uint16_t off_ms)
Start a continuous blink.
void syn_led_flash (SYN_LED * led, uint16_t on_ms, uint16_t off_ms, uint8_t count)
Flash the LED N times, then turn off.
void syn_led_init (SYN_LED * led, SYN_GPIO_Pin pin, SYN_LEDPolarity polarity)
Initialize an LED descriptor.
uint32_t syn_led_next_ms (const SYN_LED * led)
Milliseconds until the next state transition.
void syn_led_off (SYN_LED * led)
Turn the LED off.
void syn_led_on (SYN_LED * led)
Turn the LED on (steady).
void syn_led_pattern (SYN_LED * led, const char * pattern, uint16_t unit_ms)
Play a pattern string.
void syn_led_service (SYN_LED * leds, size_t count)
Service an array of LEDs.
void syn_led_toggle (SYN_LED * led)
Toggle the LED (only meaningful in ON/OFF modes).
void syn_led_update (SYN_LED * led)
Update the LED state machine.

Public Static Functions

Type Name
void led_set_output (SYN_LED * led, bool on)
Set the LED GPIO output based on polarity.

Public Functions Documentation

Start a continuous blink.

void syn_led_blink (
    SYN_LED * led,
    uint16_t on_ms,
    uint16_t off_ms
) 

Parameters:

  • led LED.
  • on_ms On time in milliseconds.
  • off_ms Off time in milliseconds.

function syn_led_flash

Flash the LED N times, then turn off.

void syn_led_flash (
    SYN_LED * led,
    uint16_t on_ms,
    uint16_t off_ms,
    uint8_t count
) 

Parameters:

  • led LED.
  • on_ms On time per flash (ms).
  • off_ms Off time between flashes (ms).
  • count Number of flashes.

function syn_led_init

Initialize an LED descriptor.

void syn_led_init (
    SYN_LED * led,
    SYN_GPIO_Pin pin,
    SYN_LEDPolarity polarity
) 

Parameters:

  • led LED to initialize.
  • pin GPIO pin number.
  • polarity Active-high or active-low.

function syn_led_next_ms

Milliseconds until the next state transition.

uint32_t syn_led_next_ms (
    const SYN_LED * led
) 

Returns 0 if a transition is overdue, UINT32_MAX if the LED is static (ON or OFF). Useful for sleeping in a protothread:

uint32_t wait = syn_led_next_ms(&led);
if (wait > 0 && wait < UINT32_MAX)
    PT_TASK_DELAY_MS(pt, task, wait);

Parameters:

  • led LED instance.

Returns:

Milliseconds until the next toggle.


function syn_led_off

Turn the LED off.

void syn_led_off (
    SYN_LED * led
) 

Parameters:

  • led LED instance.

function syn_led_on

Turn the LED on (steady).

void syn_led_on (
    SYN_LED * led
) 

Parameters:

  • led LED instance.

function syn_led_pattern

Play a pattern string.

void syn_led_pattern (
    SYN_LED * led,
    const char * pattern,
    uint16_t unit_ms
) 

Pattern characters: '.' = short on (1 unit) '-' = long on (3 units) ' ' = pause (1 unit) '|' = long pause (3 units)

The pattern repeats indefinitely. Set a null or empty string to stop.

Parameters:

  • led LED.
  • pattern Null-terminated pattern string.
  • unit_ms Base time unit in milliseconds (e.g., 100).

function syn_led_service

Service an array of LEDs.

void syn_led_service (
    SYN_LED * leds,
    size_t count
) 

Parameters:

  • leds LED array.
  • count Number of LEDs.

function syn_led_toggle

Toggle the LED (only meaningful in ON/OFF modes).

void syn_led_toggle (
    SYN_LED * led
) 

Parameters:

  • led LED instance.

function syn_led_update

Update the LED state machine.

void syn_led_update (
    SYN_LED * led
) 

Call from your main loop or a scheduler task.

Parameters:

  • led LED instance.

Public Static Functions Documentation

function led_set_output

Set the LED GPIO output based on polarity.

static void led_set_output (
    SYN_LED * led,
    bool on
) 

Parameters:

  • led LED instance.
  • on true to light the LED.


The documentation for this class was generated from the following file src/syntropic/output/syn_led.c