From: Jacek Anaszewski <jacek.anaszewski@gmail.com>
To: Sven Schuchmann <schuchmann@schleissheimer.de>,
Sven Schwermer <sven@svenschwermer.de>,
"linux-leds@vger.kernel.org" <linux-leds@vger.kernel.org>
Cc: "pavel@ucw.cz" <pavel@ucw.cz>
Subject: Re: AW: Setting multi-color intensities stops software blink
Date: Tue, 17 May 2022 23:43:28 +0200 [thread overview]
Message-ID: <4f672091-07da-8815-a00f-659f5a478b0e@gmail.com> (raw)
In-Reply-To: <GVXP190MB19172D8DD26648FC9F2EB4D6D9CE9@GVXP190MB1917.EURP190.PROD.OUTLOOK.COM>
On 5/17/22 12:29, Sven Schuchmann wrote:
> Hi Sven,
>
>> -----Ursprüngliche Nachricht-----
>> Von: Sven Schwermer <sven@svenschwermer.de>
>> Gesendet: Dienstag, 3. Mai 2022 14:17
>> An: linux-leds@vger.kernel.org
>> Cc: pavel@ucw.cz
>> Betreff: Setting multi-color intensities stops software blink
>>
>> Hi,
>>
>> I'm experiencing an issue with multi-color LEDs when setting the
>> intensities while software blinking is active (e.g. trigger=timer). This
>> manifests itself by delay_on and delay_off being set to 0 when writing
>> multi_intensities while the LED is off. If doing this while the LED is
>> on, everything works as expected.
>
> At least I can see the same thing. Setup a led like this:
> echo 255 0 0 | sudo tee /sys/class/leds/rgb\:fbx-led-1/multi_intensity
> echo 100 | sudo tee /sys/class/leds/rgb\:fbx-led-1/brightness
> echo "timer" | sudo tee /sys/class/leds/rgb\:fbx-led-1/trigger
> echo 5000 | sudo tee /sys/class/leds/rgb\:fbx-led-1/delay_on
> echo 5000 | sudo tee /sys/class/leds/rgb\:fbx-led-1/delay_off
>
> Change the color afterwards while the LED is in the "on" cycle
> echo 0 255 0 | sudo tee /sys/class/leds/rgb\:fbx-led-1/multi_intensity
> no problem, on the next "on" cycle the led has the new intensity
>
> Change the color afterwards while the LED is in the "off" cycle
> echo 0 255 0 | sudo tee /sys/class/leds/rgb\:fbx-led-1/multi_intensity
> the led stays off because delay_on and delay_off is 0.
>
> This also looks like incorrect behavior to me.
>
>> I suspect that this happens because multi_intensity_store() calls
>> led_set_brightness(led_cdev, led_cdev->brightness) at the end. It seems
>> like the software blinking modifies led_cdev->brightness directly, so if
>> the LED is in its off-phase, we're effectively switching the LED off
>> because we're setting its brightness to 0 which clears delay_on and
>> delay_off to 0:
>>
>> led_set_brightness(brightness=0): sets LED_BLINK_DISABLE
>> -> set_brightness_delayed()
>> -> led_stop_software_blink(): clears blink delays
>>
>> How would one fix this properly? Should multi_intensity_store() call
>> led_set_brightness() with brightness=led_cdev->blink_brightness if
>> blinking is active? That feels like an unclean solution.
>>
>> I'm hoping for some input. Thanks :)
>
> To me this looks wrong:
>
> void led_set_brightness(struct led_classdev *led_cdev, unsigned int brightness)
> {
> /*
> * If software blink is active, delay brightness setting
> * until the next timer tick.
> */
> if (test_bit(LED_BLINK_SW, &led_cdev->work_flags)) {
> /*
> * If we need to disable soft blinking delegate this to the
> * work queue task to avoid problems in case we are called
> * from hard irq context.
> */
> if (!brightness) {
> set_bit(LED_BLINK_DISABLE, &led_cdev->work_flags);
>
> I think it is wrong to ask for the brightness over here when we know
> that the led is blinking and could be currently in it's off cycle.
>
> schedule_work(&led_cdev->set_brightness_work);
> } else {
> set_bit(LED_BLINK_BRIGHTNESS_CHANGE,
> &led_cdev->work_flags);
> led_cdev->new_blink_brightness = brightness;
>
> I think the else path could always be done regardless of the brightness?
This construct was introduced to let the new brightness be applied only
upon the next blink, so as to avoid an interference of the blink
sequence.
To fix the issue it could suffice to let led_set_brightness()
be called in multi_intensity_store() only if SW blinking is disabled.
When enabled the new color will be applied upon the next blink anyway,
and the behavior will match that of monochrome LEDs.
--
Best regards,
Jacek Anaszewski
next prev parent reply other threads:[~2022-05-17 21:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-03 12:16 Setting multi-color intensities stops software blink Sven Schwermer
2022-05-17 10:29 ` AW: " Sven Schuchmann
2022-05-17 21:43 ` Jacek Anaszewski [this message]
2022-05-18 6:26 ` Sven Schwermer
2022-05-18 8:22 ` [PATCH] led: multicolor: Don't set brightness when blinking Sven Schwermer
2022-05-18 14:06 ` AW: " Sven Schuchmann
2022-05-18 19:29 ` Jacek Anaszewski
2022-05-18 19:36 ` Jacek Anaszewski
2022-05-18 19:54 ` [PATCH v2] led: multicolor: Fix intensity setting while SW blinking Sven Schwermer
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=4f672091-07da-8815-a00f-659f5a478b0e@gmail.com \
--to=jacek.anaszewski@gmail.com \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=schuchmann@schleissheimer.de \
--cc=sven@svenschwermer.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).