Re: [PATCH v2 1/4] led: add blinking/flashing and led_blink_pattern interface

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Mar 12, 2017 at 09:19:21AM +0100, Oleksij Rempel wrote:
> From: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
> 
> So far blinking/flashing LEDs is only supported on led-trigger level.
> Even without triggers it useful to be able to blink/flash LEDs, so
> add this functionality to the LED core.
> 
> A led_blink_pattern consists of a number of on and off-periods which
> are described in an array. Using such an array you can encode nearly
> every blink pattern you need.
> 
> Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
> Signed-off-by: Markus Pargmann <mpa@xxxxxxxxxxxxxx>
> Signed-off-by: Oleksij Rempel <o.rempel@xxxxxxxxxxxxxx>
> ---
>  drivers/led/core.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  include/led.h      |  11 ++++++
>  2 files changed, 112 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/led/core.c b/drivers/led/core.c
> index 30b016bb3..ab293b562 100644
> --- a/drivers/led/core.c
> +++ b/drivers/led/core.c
> @@ -23,6 +23,7 @@
>  #include <linux/list.h>
>  #include <errno.h>
>  #include <led.h>
> +#include <init.h>
>  #include <poller.h>
>  #include <clock.h>
>  #include <linux/ctype.h>
> @@ -101,7 +102,7 @@ struct led *led_by_name_or_number(const char *str)
>   * @param led	the led
>   * @param value	the value of the LED (0 is disabled)
>   */
> -int led_set(struct led *led, unsigned int value)
> +static int __led_set(struct led *led, unsigned int value)
>  {
>  	if (value > led->max_value)
>  		value = led->max_value;
> @@ -114,6 +115,105 @@ int led_set(struct led *led, unsigned int value)
>  	return 0;
>  }
>  
> +int led_set(struct led *led, unsigned int value)
> +{
> +	led->blink = 0;
> +	led->flash = 0;
> +	return __led_set(led, value);
> +}
> +
> +static void led_blink_func(struct poller_struct *poller)
> +{
> +	struct led *led;
> +
> +	list_for_each_entry(led, &leds, list) {
> +		bool on;
> +
> +		if (!led->blink && !led->flash)
> +			continue;
> +
> +		if (led->blink_next_event > get_time_ns()) {
> +			continue;
> +		}
> +
> +		on = !(led->blink_next_state % 2);
> +
> +		led->blink_next_event = get_time_ns() +
> +			(led->blink_states[led->blink_next_state] * MSECOND);
> +		led->blink_next_state = (led->blink_next_state + 1) %
> +					led->blink_nr_states;
> +
> +		if (led->flash && !on)
> +			led->flash = 0;
> +
> +		__led_set(led, on);
> +	}
> +}
> +
> +/**
> + * led_blink_pattern - Blink a led with flexible timings.
> + * @led LED used
> + * @pattern Array of millisecond intervals describing the on and off periods of
> + * the pattern. At the end of the array/pattern it is repeated. The array
> + * starts with an on-period. In general every array item with even index
> + * describes an on-period, every item with odd index an off-period.
> + * @pattern_len Length of the pattern array.
> + *
> + * Returns 0 on success.
> + *
> + * Example:
> + * 	pattern = {500, 1000};
> + * 	This will enable the LED for 500ms and disable it for 1000ms after
> + * 	that. This is repeated forever.
> + */
> +int led_blink_pattern(struct led *led, const unsigned int *pattern,
> +		      unsigned int pattern_len)
> +{
> +	if (led->blink_states)
> +		free(led->blink_states);

The test is unnecessary.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux