From: Jacek Anaszewski <j.anaszewski@samsung.com>
To: Heiner Kallweit <hkallweit1@gmail.com>
Cc: linux-leds@vger.kernel.org
Subject: Re: [PATCH v3 4/4] leds: core: add support for RGB LED's
Date: Fri, 19 Feb 2016 14:59:23 +0100 [thread overview]
Message-ID: <56C71FBB.7080901@samsung.com> (raw)
In-Reply-To: <56C6381A.7060209@gmail.com>
Hi Heiner,
On 02/18/2016 10:31 PM, Heiner Kallweit wrote:
> Add support for RGB LED's. Flag LED_DEV_CAP_HSV is used to instruct
> the core to convert HSV to RGB on output.
>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
> v2:
> - move hsv -> rgb conversion to separate file
> - remove flag LED_DEV_CAP_RGB
> v3:
> - call led_hsv_to_rgb only if LED_DEV_CAP_HSV is set
> This is needed in cases when we have monochrome and color LEDs
> as well in a system.
> ---
> drivers/leds/led-color-core.c | 35 +++++++++++++++++++++++++++++++++++
> drivers/leds/led-core.c | 17 ++++++++++++++++-
> drivers/leds/leds.h | 1 +
> 3 files changed, 52 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/leds/led-color-core.c b/drivers/leds/led-color-core.c
> index b101f73..467beeb 100644
> --- a/drivers/leds/led-color-core.c
> +++ b/drivers/leds/led-color-core.c
> @@ -31,3 +31,38 @@ enum led_brightness led_confine_brightness(struct led_classdev *led_cdev,
> return brightness |
> min(value & LED_BRIGHTNESS_MASK, led_cdev->max_brightness);
> }
> +
> +enum led_brightness led_hsv_to_rgb(enum led_brightness hsv)
> +{
> + int h = min_t(int, (hsv >> 16) & 0xff, 251);
> + int s = (hsv >> 8) & 0xff;
> + int v = hsv & 0xff;
> + int f, p, q, t, r, g, b;
> +
> + if (!v)
> + return 0;
> + if (!s)
> + return (v << 16) + (v << 8) + v;
> +
> + f = DIV_ROUND_CLOSEST((h % 42) * 255, 42);
> + p = v - DIV_ROUND_CLOSEST(s * v, 255);
> + q = v - DIV_ROUND_CLOSEST(f * s * v, 255 * 255);
> + t = v - DIV_ROUND_CLOSEST((255 - f) * s * v, 255 * 255);
> +
> + switch (h / 42) {
> + case 0:
> + r = v; g = t; b = p; break;
> + case 1:
> + r = q; g = v; b = p; break;
> + case 2:
> + r = p; g = v; b = t; break;
> + case 3:
> + r = p; g = q; b = v; break;
> + case 4:
> + r = t; g = p; b = v; break;
> + case 5:
> + r = v; g = p; b = q; break;
> + }
> +
> + return (r << 16) + (g << 8) + b;
> +}
Do you plan to add a driver using Color LEDs Support?
If so, it would be good to add it to this patch set,
which would make testing this code easier.
> diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
> index 525d566..255bdd7 100644
> --- a/drivers/leds/led-core.c
> +++ b/drivers/leds/led-core.c
> @@ -31,6 +31,11 @@ static int __led_set_brightness(struct led_classdev *led_cdev,
> if (!led_cdev->brightness_set)
> return -ENOTSUPP;
>
> +#if IS_ENABLED(CONFIG_LEDS_COLOR)
> + if (led_cdev->flags & LED_DEV_CAP_HSV)
> + value = led_hsv_to_rgb(value);
> +#endif
> +
Please drop this changes. led_hsv_to_rgb() can be used internally
by RGB LED class drivers.
> led_cdev->brightness_set(led_cdev, value);
>
> return 0;
> @@ -42,6 +47,11 @@ static int __led_set_brightness_blocking(struct led_classdev *led_cdev,
> if (!led_cdev->brightness_set_blocking)
> return -ENOTSUPP;
>
> +#if IS_ENABLED(CONFIG_LEDS_COLOR)
> + if (led_cdev->flags & LED_DEV_CAP_HSV)
> + value = led_hsv_to_rgb(value);
> +#endif
> +
Ditto.
> return led_cdev->brightness_set_blocking(led_cdev, value);
> }
>
> @@ -294,7 +304,12 @@ int led_update_brightness(struct led_classdev *led_cdev)
> {
> int ret = 0;
>
> - if (led_cdev->brightness_get) {
> + /*
> + * for now reading back the color is not supported as multiple
> + * HSV -> RGB -> HSV conversions may distort the color due to
> + * rounding issues in the conversion algorithm
> + */
> + if (led_cdev->brightness_get && !(led_cdev->flags & LED_DEV_CAP_HSV)) {
> ret = led_cdev->brightness_get(led_cdev);
> if (ret >= 0) {
> led_cdev->brightness = ret;
> diff --git a/drivers/leds/leds.h b/drivers/leds/leds.h
> index 094707f..763f19a 100644
> --- a/drivers/leds/leds.h
> +++ b/drivers/leds/leds.h
> @@ -37,6 +37,7 @@ void led_set_brightness_nosleep(struct led_classdev *led_cdev,
> #if IS_ENABLED(CONFIG_LEDS_COLOR)
> enum led_brightness led_confine_brightness(struct led_classdev *led_cdev,
> enum led_brightness value);
> +enum led_brightness led_hsv_to_rgb(enum led_brightness hsv);
> #else
> static inline enum led_brightness led_confine_brightness(
> struct led_classdev *led_cdev, enum led_brightness value)
>
--
Best regards,
Jacek Anaszewski
next prev parent reply other threads:[~2016-02-19 13:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-18 21:31 [PATCH v3 4/4] leds: core: add support for RGB LED's Heiner Kallweit
2016-02-19 13:59 ` Jacek Anaszewski [this message]
2016-02-23 20:27 ` Heiner Kallweit
2016-02-25 12:40 ` Jacek Anaszewski
2016-02-26 22:36 ` Heiner Kallweit
2016-02-29 9:57 ` Jacek Anaszewski
[not found] ` <56D415FF.7010106-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2016-02-29 19:19 ` Heiner Kallweit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56C71FBB.7080901@samsung.com \
--to=j.anaszewski@samsung.com \
--cc=hkallweit1@gmail.com \
--cc=linux-leds@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.