MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_led_set_state

Function rt_led_set_state

components/drivers/led/led.c:221–270  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219}
220
221rt_err_t rt_led_set_state(struct rt_led_device *led, enum rt_led_state state)
222{
223 rt_err_t err;
224 struct blink_timer *btimer;
225
226 if (!led)
227 {
228 return -RT_EINVAL;
229 }
230
231 if (!led->ops->set_state)
232 {
233 return -RT_ENOSYS;
234 }
235
236 rt_spin_lock(&led->spinlock);
237
238 btimer = led->sysdata;
239
240 if (btimer && btimer->enabled)
241 {
242 rt_timer_stop(&btimer->timer);
243 }
244
245 err = led->ops->set_state(led, state);
246
247 if (state == RT_LED_S_BLINK)
248 {
249 if (err == -RT_ENOSYS && btimer && !btimer->enabled)
250 {
251 btimer->enabled = RT_TRUE;
252 rt_timer_start(&btimer->timer);
253 }
254 }
255 else if (btimer && btimer->enabled)
256 {
257 if (err)
258 {
259 rt_timer_start(&btimer->timer);
260 }
261 else
262 {
263 btimer->enabled = RT_FALSE;
264 }
265 }
266
267 rt_spin_unlock(&led->spinlock);
268
269 return err;
270}
271
272rt_err_t rt_led_get_state(struct rt_led_device *led, enum rt_led_state *out_state)
273{

Callers 3

ofw_append_gpio_ledFunction · 0.85
_led_writeFunction · 0.85
rt_led_unregisterFunction · 0.85

Calls 4

rt_timer_stopFunction · 0.85
rt_timer_startFunction · 0.85
rt_spin_lockFunction · 0.50
rt_spin_unlockFunction · 0.50

Tested by

no test coverage detected