-
Notifications
You must be signed in to change notification settings - Fork 8.3k
drivers: led: Add LED GPIO driver #34417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
drivers/led/led_gpio.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please do it as
value<50 then off
value>=50 then on
this way any client using brightness will work without having to consider that this driver behaves differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
drivers/led/led_gpio.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know we don't need it but maybe we could add blink using workqueue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw - if function is not supported won't it be enough to not add it to ops
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to keep the driver as simple and small as possible (it could be used by memory-limited devices).
Work in driver would need to be added for LED every color channel. Application could use a single work for whole multicolor LED. Adding blinking to an application would be simple too.
|
There is similar PR, "Add generic gpio leds driver with sample" #21578 |
|
It does not build in CI, you need to add it to https://github.com/zephyrproject-rtos/zephyr/tree/master/tests/drivers/build_all |
drivers/led/led_gpio.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need for this macro, just use dev->config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, done
drivers/led/led_gpio.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the recently introduced GPIO_DT_SPEC_GET utilities? https://docs.zephyrproject.org/latest/reference/peripherals/gpio.html#c.GPIO_DT_SPEC_GET
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I will change it
drivers/led/led_gpio.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that single return point doesn't make code flow more readable, my opinion though (non-blocking).
| if (device_is_ready(led->dev)) { | |
| err = gpio_pin_configure(led->dev, led->pin, led->flags); | |
| if (err) { | |
| LOG_ERR("Cannot configure GPIO (err %d)", err); | |
| } | |
| } else { | |
| LOG_ERR("%s: GPIO device not ready", dev->name); | |
| err = -ENODEV; | |
| } | |
| if (!device_is_ready(led->dev)) { | |
| LOG_ERR("%s: GPIO device not ready", dev->name); | |
| return -ENODEV; | |
| } | |
| err = gpio_pin_configure(led->dev, led->pin, led->flags); | |
| if (err) { | |
| LOG_ERR("Cannot configure GPIO (err %d)", err); | |
| return err; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I don't mind to have direct return instead of multiplying if-else blocks, I am against of returning directly from for loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case I suggest to leave it as it is. Could we do it @gmarull ?
|
@jfischer-no Yes I created a similar PR #21578 sometimes ago with additional software blink feature but I didn't have time to finish it. We also decided there that software blink should be done as generic module which can be used by any driver LED driver which doesn't support hardware blinking. If we are ok with basing on LED order in the board dts as the LED ids which are used for identify LED in the API than I am ok with this PR and I will close my one. If we cannot base on LED order, we could consider basing this driver on the led-controller binding: https://github.com/zephyrproject-rtos/zephyr/blob/master/dts/bindings/led/led-controller.yaml |
drivers/led/led_gpio.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| err = gpio_pin_configure(led->dev, led->pin, led->flags); | |
| err = gpio_pin_configure(led->dev, led->pin, GPIO_OUTPUT_INACTIVE | led->flags); |
Maybe It is worth to add this to be sure that leds will be off after driver initialization
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, added
drivers/led/Kconfig.gpio
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| depends on GPIO | |
| depends on GPIO && $(dt_compat_enabled, gpio-leds) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw. $(dt_compat_enabled,gpio-leds) - space must be excluded
KAGA164
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
6b780e6 to
d174f7b
Compare
|
@jfischer-no, I added requested test to build_all |
drivers/led/led_gpio.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why DEVICE_DT_DEFINE is not used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DEVICE_DT_DEFINE uses node label as a driver name. The label property is not assigned for led-gpio binding (only child nodes have it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I handled it in the same way as it is done for led_pwm driver
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DEVICE_DT_INST_DEFINE does not depend on node label, it uses ordinal information. I have quickly tried:
DEVICE_DT_INST_DEFINE(id, &led_gpio_init, device_pm_control_nop,\
NULL, &led_gpio_config_##id, \
POST_KERNEL, CONFIG_LED_INIT_PRIORITY, \
&led_gpio_api);
and it seems to build correctly. I'd suggest to use n, i, index instead of id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, changed. I also used i instead of id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like I looked at old version of docs. In current implementation full node name is used in case the label is not defined.
drivers/led/led_gpio.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DEVICE_DT_INST_DEFINE does not depend on node label, it uses ordinal information. I have quickly tried:
DEVICE_DT_INST_DEFINE(id, &led_gpio_init, device_pm_control_nop,\
NULL, &led_gpio_config_##id, \
POST_KERNEL, CONFIG_LED_INIT_PRIORITY, \
&led_gpio_api);
and it seems to build correctly. I'd suggest to use n, i, index instead of id.
Mani-Sadhasivam
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a minor nit. Otherwise LGTM.
Change introduces LED GPIO driver. Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
Change adds LED GPIO driver to build_all test. Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
|
@nashif, can we merge it ? |
Change introduces LED GPIO driver.