Skip to content

File syn_led.h

FileList > output > syn_led.h

Go to the source code of this file

Non-blocking LED controller — blink, flash, patterns. More...

  • #include "../common/syn_defs.h"
  • #include "../drivers/syn_gpio.h"
  • #include "../port/syn_port_system.h"
  • #include <stdbool.h>

Classes

Type Name
struct SYN_LED
LED instance — pin, mode, blink/flash/pattern state.

Public Types

Type Name
enum SYN_LEDMode
LED operating mode.
enum SYN_LEDPolarity
LED output polarity.

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
bool syn_led_is_on (const SYN_LED * led)
Check if the LED is currently lit.

Detailed Description

Drives LEDs through GPIO with non-blocking blink/flash/pattern sequencing. No timers or tasks required — just call syn_led_update() from your main loop.

** **

static SYN_LED led;
syn_led_init(&led, LED_PIN, SYN_LED_ACTIVE_HIGH);
syn_led_blink(&led, 500, 500);     // 500ms on, 500ms off
while (1) { syn_led_update(&led); }

Public Types Documentation

enum SYN_LEDMode

LED operating mode.

enum SYN_LEDMode {
    SYN_LED_MODE_OFF = 0,
    SYN_LED_MODE_ON = 1,
    SYN_LED_MODE_BLINK = 2,
    SYN_LED_MODE_FLASH = 3,
    SYN_LED_MODE_PATTERN = 4
};


enum SYN_LEDPolarity

LED output polarity.

enum SYN_LEDPolarity {
    SYN_LED_ACTIVE_HIGH = 0,
    SYN_LED_ACTIVE_LOW = 1
};


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 syn_led_is_on

Check if the LED is currently lit.

static inline bool syn_led_is_on (
    const SYN_LED * led
) 

Parameters:

  • led LED instance.

Returns:

true if lit.



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