3 #define _TWR_LED_DEFAULT_SLOT_INTERVAL 100
5 static void _twr_led_gpio_init(
twr_led_t *
self)
10 static void _twr_led_gpio_on(
twr_led_t *
self)
15 static void _twr_led_gpio_off(
twr_led_t *
self)
22 .
init = _twr_led_gpio_init,
23 .on = _twr_led_gpio_on,
24 .off = _twr_led_gpio_off
27 static void _twr_led_task(
void *param)
31 if (self->_pulse_active)
33 self->_driver->off(
self);
35 self->_pulse_active =
false;
43 if (self->_pattern == 0 || self->_pattern == 0xffffffff)
48 if (self->_selector == 0)
50 self->_selector = 0x80000000;
53 if ((self->_pattern & self->_selector) != 0)
55 self->_driver->on(
self);
59 self->_driver->off(
self);
62 self->_selector >>= 1;
64 if (self->_count != 0)
66 if (--self->_count == 0)
77 memset(
self, 0,
sizeof(*
self));
79 self->_channel.gpio = gpio_channel;
81 self->_open_drain_output = open_drain_output;
83 self->_idle_state = idle_state;
85 self->_driver = &_twr_led_driver_gpio;
86 self->_driver->
init(
self);
87 self->_driver->off(
self);
89 if (self->_open_drain_output)
98 self->_slot_interval = _TWR_LED_DEFAULT_SLOT_INTERVAL;
105 memset(
self, 0,
sizeof(*
self));
107 self->_channel.virtual = channel;
109 self->_idle_state = idle_state;
111 self->_driver = driver;
112 self->_driver->
init(
self);
113 self->_driver->off(
self);
115 self->_slot_interval = _TWR_LED_DEFAULT_SLOT_INTERVAL;
122 self->_slot_interval = interval;
127 uint32_t pattern =
self->_pattern;
135 self->_pattern = 0xffffffff;
138 self->_driver->on(
self);
140 else if (pattern == 0xffffffff)
145 if (!self->_pulse_active)
147 self->_driver->off(
self);
155 self->_pattern = 0x00000000;
158 if (!self->_pulse_active)
160 self->_driver->off(
self);
167 self->_pattern = 0xffffffff;
170 if (!self->_pulse_active)
172 self->_driver->on(
self);
179 pattern = 0xf0f0f0f0;
185 pattern = 0xffff0000;
191 pattern = 0xaaaaaaaa;
197 pattern = 0x80000000;
207 if (self->_pattern != pattern)
209 self->_pattern = pattern;
219 self->_pattern = pattern;
227 self->_count = count;
232 self->_pattern = 0xf0f0f0f0;
234 self->_count = count * 8;
241 if (!self->_pulse_active)
243 self->_driver->on(
self);
245 self->_pulse_active =
true;
253 return self->_pulse_active;
void twr_gpio_set_output(twr_gpio_channel_t channel, int state)
Set output state for GPIO channel.
void twr_gpio_init(twr_gpio_channel_t channel)
Initialize GPIO channel.
twr_gpio_channel_t
GPIO channels.
void twr_gpio_set_mode(twr_gpio_channel_t channel, twr_gpio_mode_t mode)
Set mode of operation for GPIO channel.
@ TWR_GPIO_MODE_OUTPUT
GPIO channel operates as output.
@ TWR_GPIO_MODE_OUTPUT_OD
GPIO channel operates as open-drain output.
bool twr_led_is_pulse(twr_led_t *self)
Check if there is ongoing LED pulse.
void twr_led_set_slot_interval(twr_led_t *self, twr_tick_t interval)
Set slot interval for pattern processing.
void twr_led_set_pattern(twr_led_t *self, uint32_t pattern)
Set custom blinking pattern.
void twr_led_init_virtual(twr_led_t *self, int channel, const twr_led_driver_t *driver, int idle_state)
Initialize virtual LED.
struct twr_led_t twr_led_t
LED instance.
void twr_led_init(twr_led_t *self, twr_gpio_channel_t gpio_channel, bool open_drain_output, int idle_state)
Initialize LED.
void twr_led_blink(twr_led_t *self, int count)
LED blink.
void twr_led_pulse(twr_led_t *self, twr_tick_t duration)
Turn on LED for the specified duration of time.
void twr_led_set_count(twr_led_t *self, int count)
Set count for blinking pattern executed.
void twr_led_set_mode(twr_led_t *self, twr_led_mode_t mode)
Set LED mode.
@ TWR_LED_MODE_TOGGLE
LED toggles between on/off state (this has no effect while processing alternating patterns)
@ TWR_LED_MODE_BLINK
LED blinks.
@ TWR_LED_MODE_BLINK_FAST
LED blinks quickly.
@ TWR_LED_MODE_FLASH
LED flashes repeatedly.
@ TWR_LED_MODE_BLINK_SLOW
LED blinks slowly.
@ TWR_LED_MODE_ON
LED has steady on state.
@ TWR_LED_MODE_OFF
LED has steady off state.
void twr_scheduler_plan_current_relative(twr_tick_t tick)
Schedule current task to tick relative from current spin.
void twr_scheduler_plan_from_now(twr_scheduler_task_id_t task_id, twr_tick_t tick)
Schedule specified task to tick relative from now.
void twr_scheduler_plan_now(twr_scheduler_task_id_t task_id)
Schedule specified task for immediate execution.
twr_scheduler_task_id_t twr_scheduler_register(void(*task)(void *), void *param, twr_tick_t tick)
Register task in scheduler.
#define TWR_TICK_INFINITY
Maximum timestamp value.
uint64_t twr_tick_t
Timestamp data type.
void(* init)(twr_led_t *self)
Callback for initialization.
bool(* init)(void)
Callback for initialization.