Firmware SDK
twr_led

Driver for generic LED. More...

Data Structures

struct  twr_led_driver_t
 LED driver interface. More...
 

Typedefs

typedef struct twr_led_t twr_led_t
 LED instance.
 

Enumerations

enum  twr_led_mode_t {
  TWR_LED_MODE_TOGGLE = 0 ,
  TWR_LED_MODE_OFF = 1 ,
  TWR_LED_MODE_ON = 2 ,
  TWR_LED_MODE_BLINK = 3 ,
  TWR_LED_MODE_BLINK_SLOW = 4 ,
  TWR_LED_MODE_BLINK_FAST = 5 ,
  TWR_LED_MODE_FLASH = 6
}
 LED modes. More...
 

Functions

void twr_led_init (twr_led_t *self, twr_gpio_channel_t gpio_channel, bool open_drain_output, int idle_state)
 Initialize LED. More...
 
void twr_led_init_virtual (twr_led_t *self, int channel, const twr_led_driver_t *driver, int idle_state)
 Initialize virtual LED. More...
 
void twr_led_set_slot_interval (twr_led_t *self, twr_tick_t interval)
 Set slot interval for pattern processing. More...
 
void twr_led_set_mode (twr_led_t *self, twr_led_mode_t mode)
 Set LED mode. More...
 
void twr_led_set_pattern (twr_led_t *self, uint32_t pattern)
 Set custom blinking pattern. More...
 
void twr_led_set_count (twr_led_t *self, int count)
 Set count for blinking pattern executed. More...
 
void twr_led_blink (twr_led_t *self, int count)
 LED blink. More...
 
void twr_led_pulse (twr_led_t *self, twr_tick_t duration)
 Turn on LED for the specified duration of time. More...
 
bool twr_led_is_pulse (twr_led_t *self)
 Check if there is ongoing LED pulse. More...
 

Detailed Description

Driver for generic LED.

Example: Blink with on-board LED

#include <twr_led.h>
void application_init(void)
{
twr_led_init(&led, TWR_GPIO_LED, false, false);
}
@ TWR_GPIO_LED
GPIO channel LED.
Definition: twr_gpio.h:69
struct twr_led_t twr_led_t
LED instance.
Definition: twr_led.h:52
void twr_led_init(twr_led_t *self, twr_gpio_channel_t gpio_channel, bool open_drain_output, int idle_state)
Initialize LED.
Definition: twr_led.c:75
void twr_led_set_mode(twr_led_t *self, twr_led_mode_t mode)
Set LED mode.
Definition: twr_led.c:125
@ TWR_LED_MODE_BLINK
LED blinks.
Definition: twr_led.h:37

Enumeration Type Documentation

◆ twr_led_mode_t

LED modes.

Enumerator
TWR_LED_MODE_TOGGLE 

LED toggles between on/off state (this has no effect while processing alternating patterns)

TWR_LED_MODE_OFF 

LED has steady off state.

TWR_LED_MODE_ON 

LED has steady on state.

TWR_LED_MODE_BLINK 

LED blinks.

TWR_LED_MODE_BLINK_SLOW 

LED blinks slowly.

TWR_LED_MODE_BLINK_FAST 

LED blinks quickly.

TWR_LED_MODE_FLASH 

LED flashes repeatedly.

Definition at line 25 of file twr_led.h.

Function Documentation

◆ twr_led_blink()

void twr_led_blink ( twr_led_t self,
int  count 
)

LED blink.

Parameters
[in]selfInstance
[in]countCount of blink

Definition at line 230 of file twr_led.c.

Here is the call graph for this function:

◆ twr_led_init()

void twr_led_init ( twr_led_t self,
twr_gpio_channel_t  gpio_channel,
bool  open_drain_output,
int  idle_state 
)

Initialize LED.

Parameters
[in]selfInstance
[in]gpio_channelGPIO channel LED is connected to
[in]open_drain_outputDetermines if LED is driven by open-drain output
[in]idle_stateGPIO pin idle state (when LED is supposed to be off)

Definition at line 75 of file twr_led.c.

Here is the call graph for this function:

◆ twr_led_init_virtual()

void twr_led_init_virtual ( twr_led_t self,
int  channel,
const twr_led_driver_t driver,
int  idle_state 
)

Initialize virtual LED.

Parameters
[in]selfInstance
[in]channelVirtual channel LED is connected to
[in]driverVirtual channel LED driver
[in]idle_stateVirtual pin idle state (when LED is supposed to be off)

Definition at line 103 of file twr_led.c.

Here is the call graph for this function:

◆ twr_led_is_pulse()

bool twr_led_is_pulse ( twr_led_t self)

Check if there is ongoing LED pulse.

Parameters
[in]selfInstance
Returns
true If pulse is now active
false If pulse is now inactive

Definition at line 251 of file twr_led.c.

◆ twr_led_pulse()

void twr_led_pulse ( twr_led_t self,
twr_tick_t  duration 
)

Turn on LED for the specified duration of time.

Parameters
[in]selfInstance
[in]durationDuration for which LED will be turned on

Definition at line 239 of file twr_led.c.

Here is the call graph for this function:

◆ twr_led_set_count()

void twr_led_set_count ( twr_led_t self,
int  count 
)

Set count for blinking pattern executed.

Parameters
[in]selfInstance
[in]countCount for blinking pattern executed, negative value means infinity

Definition at line 225 of file twr_led.c.

◆ twr_led_set_mode()

void twr_led_set_mode ( twr_led_t self,
twr_led_mode_t  mode 
)

Set LED mode.

Parameters
[in]selfInstance
[in]modeDesired LED mode

Definition at line 125 of file twr_led.c.

Here is the call graph for this function:

◆ twr_led_set_pattern()

void twr_led_set_pattern ( twr_led_t self,
uint32_t  pattern 
)

Set custom blinking pattern.

Parameters
[in]selfInstance
[in]patternBlinking pattern (bits with log. 1 represent active slot)

Definition at line 217 of file twr_led.c.

Here is the call graph for this function:

◆ twr_led_set_slot_interval()

void twr_led_set_slot_interval ( twr_led_t self,
twr_tick_t  interval 
)

Set slot interval for pattern processing.

Parameters
[in]selfInstance
[in]intervalDesired slot interval in ticks

Definition at line 120 of file twr_led.c.