Skip to content

drivers: led: led_gpio: Add support of blink#89734

Closed
anobli wants to merge 2 commits intozephyrproject-rtos:mainfrom
anobli:abailon/led-gpio-blink
Closed

drivers: led: led_gpio: Add support of blink#89734
anobli wants to merge 2 commits intozephyrproject-rtos:mainfrom
anobli:abailon/led-gpio-blink

Conversation

@anobli
Copy link
Contributor

@anobli anobli commented May 9, 2025

The led_api_blink is quite convenient to use.
This adds its support to the led_gpio driver.

@github-actions github-actions bot added the area: LED Label to identify LED subsystem label May 9, 2025
Copy link
Contributor

@simonguinot simonguinot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @anobli,

Please see #57791.

@henrikbrixandersen
Copy link
Member

Hi @anobli,

Please see #57791.

I agree that a general, optional fallback would be better.

@anobli
Copy link
Contributor Author

anobli commented May 11, 2025

OK, indeed, this makes sense. I will think about to another implementation more adapted to the fallback.

The led_api_blink is quite convenient to use.
This adds its support to the led_gpio driver.

Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
@anobli anobli force-pushed the abailon/led-gpio-blink branch 4 times, most recently from 1c7dfcf to 43f8722 Compare May 13, 2025 10:28
The LED blink API i squite useful but this is not supported by all
the LED controller.
This provides a software implementation of blink that relies on timer
to blink a LED.
This could be enabled using Kconfig, as well the maximum number of LED
that could blink at the same time using blink fallback.
This does not requires any changes to driver to be used.

Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
@anobli anobli force-pushed the abailon/led-gpio-blink branch from 43f8722 to f92a058 Compare May 13, 2025 10:41
@simonguinot
Copy link
Contributor

Hi @anobli,

Maybe you should close this PR, and take the time to write a proper driver for software blinking ? And once ready you could open a new PR, with the right title and a clean history ?

In addition, are you sure that timer is the right tool to implement software blinking ? There are various backends behind LEDs: GPIO, SPI, I2C, PWM, and many others. Some of them may even sleep during I/O. Is that allowed in timer context in Zephyr ? On all platforms ? In Linux for example, timers are indeed used for software blinking. But if the LED end-driver doesn't provide the brightness_set API method which is guaranteed to not sleep, then a work queue is used, to provide a user sleep-friendly context.

This software blinking driver will be quite an important one. So please take the time to make it great and optimized.

@simonguinot simonguinot requested a review from fabiobaltieri May 13, 2025 14:19

if (api->blink == NULL) {
return -ENOSYS;
return led_blink_fallback(dev, led, delay_on, delay_off);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to put this in an ifdef and implement it so that it keeps clean when it's disabled.

const struct led_driver_api *api =
(const struct led_driver_api *)dev->api;

led_blink_fallback(dev, led, 0, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

const struct led_driver_api *api =
(const struct led_driver_api *)dev->api;

led_blink_fallback(dev, led, 0, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

const struct gpio_dt_spec *led_gpio = &config->led[led];

data->blink_state ^= 1 << led;
gpio_pin_set_dt(led_gpio, data->blink_state & (1 << led));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be replaced with led_on to work with other LED devices?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left it by mistake. Actually, all the change made in led_gpio.c should be reverted.

@anobli
Copy link
Contributor Author

anobli commented May 19, 2025

Hi @anobli,

Maybe you should close this PR, and take the time to write a proper driver for software blinking ? And once ready you could open a new PR, with the right title and a clean history ?

In addition, are you sure that timer is the right tool to implement software blinking ? There are various backends behind LEDs: GPIO, SPI, I2C, PWM, and many others. Some of them may even sleep during I/O. Is that allowed in timer context in Zephyr ? On all platforms ? In Linux for example, timers are indeed used for software blinking. But if the LED end-driver doesn't provide the brightness_set API method which is guaranteed to not sleep, then a work queue is used, to provide a user sleep-friendly context.

This software blinking driver will be quite an important one. So please take the time to make it great and optimized.

I will close this PR, and open a new one soon.
Indeed, the timer is not the best choice.
I will use a delayable work that doesn't seem to have any big memory overhead compared to timer and deal correctly with sleep context.

@anobli
Copy link
Contributor Author

anobli commented May 19, 2025

Closing this PR since the scope has changed.
Thanks everyone for the review you made!

@anobli anobli closed this May 19, 2025
@anobli anobli deleted the abailon/led-gpio-blink branch May 19, 2025 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: LED Label to identify LED subsystem

5 participants