From b557f55e90f087ec310592b833441cd326206f61 Mon Sep 17 00:00:00 2001 From: Michael Polyntsov Date: Fri, 19 Jul 2024 13:12:12 +0400 Subject: led: Implement software led blinking If hardware (or driver) doesn't support leds blinking, it's now possible to use software implementation of blinking instead. This relies on cyclic functions. Signed-off-by: Michael Polyntsov Signed-off-by: Mikhail Kshevetskiy Reviewed-by: Simon Glass --- include/led.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'include') diff --git a/include/led.h b/include/led.h index 9b24a4ce188..8270d6cef93 100644 --- a/include/led.h +++ b/include/led.h @@ -18,6 +18,20 @@ enum led_state_t { LEDST_COUNT, }; +enum led_sw_blink_state_t { + LED_SW_BLINK_ST_DISABLED, + LED_SW_BLINK_ST_NOT_READY, + LED_SW_BLINK_ST_OFF, + LED_SW_BLINK_ST_ON, +}; + +struct led_sw_blink { + enum led_sw_blink_state_t state; + struct udevice *dev; + struct cyclic_info cyclic; + const char cyclic_name[0]; +}; + /** * struct led_uc_plat - Platform data the uclass stores about each device * @@ -27,6 +41,9 @@ enum led_state_t { struct led_uc_plat { const char *label; enum led_state_t default_state; +#ifdef CONFIG_LED_SW_BLINK + struct led_sw_blink *sw_blink; +#endif }; /** @@ -116,4 +133,9 @@ int led_set_period(struct udevice *dev, int period_ms); */ int led_bind_generic(struct udevice *parent, const char *driver_name); +/* Internal functions for software blinking. Do not use them in your code */ +int led_sw_set_period(struct udevice *dev, int period_ms); +bool led_sw_is_blinking(struct udevice *dev); +bool led_sw_on_state_change(struct udevice *dev, enum led_state_t state); + #endif -- cgit v1.3.1