Firmware SDK
twr_led.h
1 #ifndef _TWR_LED_H
2 #define _TWR_LED_H
3 
4 #include <twr_gpio.h>
5 #include <twr_scheduler.h>
6 
22 
24 
25 typedef enum
26 {
29 
32 
35 
38 
41 
44 
47 
49 
51 
52 typedef struct twr_led_t twr_led_t;
53 
55 
56 typedef struct
57 {
59  void (*init)(twr_led_t *self);
60 
62  void (*on)(twr_led_t *self);
63 
65  void (*off)(twr_led_t *self);
66 
68 
70 
71 typedef union
72 {
73  twr_gpio_channel_t gpio;
74  int virtual;
75 
76 } twr_led_channel_t;
77 
78 struct twr_led_t
79 {
80  twr_led_channel_t _channel;
81  const twr_led_driver_t *_driver;
82  bool _open_drain_output;
83  int _idle_state;
84  twr_tick_t _slot_interval;
85  uint32_t _pattern;
86  uint32_t _selector;
87  int _count;
88  bool _pulse_active;
89  twr_scheduler_task_id_t _task_id;
90 };
91 
93 
99 
100 void twr_led_init(twr_led_t *self, twr_gpio_channel_t gpio_channel, bool open_drain_output, int idle_state);
101 
107 
108 void twr_led_init_virtual(twr_led_t *self, int channel, const twr_led_driver_t *driver, int idle_state);
109 
113 
114 void twr_led_set_slot_interval(twr_led_t *self, twr_tick_t interval);
115 
119 
120 void twr_led_set_mode(twr_led_t *self, twr_led_mode_t mode);
121 
125 
126 void twr_led_set_pattern(twr_led_t *self, uint32_t pattern);
127 
131 
132 void twr_led_set_count(twr_led_t *self, int count);
133 
137 
138 void twr_led_blink(twr_led_t *self, int count);
139 
143 
144 void twr_led_pulse(twr_led_t *self, twr_tick_t duration);
145 
150 
151 bool twr_led_is_pulse(twr_led_t *self);
152 
154 
155 #endif // _TWR_LED_H
twr_gpio_channel_t
GPIO channels.
Definition: twr_gpio.h:13
bool twr_led_is_pulse(twr_led_t *self)
Check if there is ongoing LED pulse.
Definition: twr_led.c:251
void twr_led_set_slot_interval(twr_led_t *self, twr_tick_t interval)
Set slot interval for pattern processing.
Definition: twr_led.c:120
void twr_led_set_pattern(twr_led_t *self, uint32_t pattern)
Set custom blinking pattern.
Definition: twr_led.c:217
void twr_led_init_virtual(twr_led_t *self, int channel, const twr_led_driver_t *driver, int idle_state)
Initialize virtual LED.
Definition: twr_led.c:103
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_blink(twr_led_t *self, int count)
LED blink.
Definition: twr_led.c:230
twr_led_mode_t
LED modes.
Definition: twr_led.h:26
void twr_led_pulse(twr_led_t *self, twr_tick_t duration)
Turn on LED for the specified duration of time.
Definition: twr_led.c:239
void twr_led_set_count(twr_led_t *self, int count)
Set count for blinking pattern executed.
Definition: twr_led.c:225
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_TOGGLE
LED toggles between on/off state (this has no effect while processing alternating patterns)
Definition: twr_led.h:28
@ TWR_LED_MODE_BLINK
LED blinks.
Definition: twr_led.h:37
@ TWR_LED_MODE_BLINK_FAST
LED blinks quickly.
Definition: twr_led.h:43
@ TWR_LED_MODE_FLASH
LED flashes repeatedly.
Definition: twr_led.h:46
@ TWR_LED_MODE_BLINK_SLOW
LED blinks slowly.
Definition: twr_led.h:40
@ TWR_LED_MODE_ON
LED has steady on state.
Definition: twr_led.h:34
@ TWR_LED_MODE_OFF
LED has steady off state.
Definition: twr_led.h:31
size_t twr_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: twr_scheduler.h:22
uint64_t twr_tick_t
Timestamp data type.
Definition: twr_tick.h:16
LED driver interface.
Definition: twr_led.h:57