-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Add leds_gpio driver and modify blinky application #9511
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
Add leds_gpio driver and modify blinky application #9511
Conversation
Codecov Report
@@ Coverage Diff @@
## master #9511 +/- ##
=======================================
Coverage 48.25% 48.25%
=======================================
Files 293 293
Lines 44130 44130
Branches 10591 10591
=======================================
Hits 21296 21296
Misses 18567 18567
Partials 4267 4267Continue to review full report at Codecov.
|
|
@erwango This Currently we have the following in Any idea of how we can handle this in driver? Moving the above defines to driver itself? |
erwango
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.
Some comments on otherwise good stuf
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.
Can't we use the 'label' to get the instance name?
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.
okay.
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.
I'm finding 'LED0_GPIO' a bit confusing, as I read it 'GPIO of LED0'.
Would LED_GPIO_0 be a bit less confusing?
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.
Actually, the naming convention aligns with the DTS generated header (LEDx_GPIO). But anyway, LED_GPIO_x seems to be good.
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.
@Mani-Sadhasivam , sorry but I still find it a bit confusing actually. What about GPIO_LED ?
@MaureenHelm , any opinion on that?
drivers/led/leds_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.
Is 'led' argument actually required ?
We should be able to retrieve it from *dev.
And I think this is the interest of the API, so user doesn't care of the PIN
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.
led argument is there only for the purpose of LED API and yes, we can retrieve it from *dev. Anyway, passing the led argument gives us the possibility of checking the correct pin in led_on/led_off as below:
/* Make sure that the LED is valid */
if (led != cfg->gpio_pin)
return -EINVAL;Will include the above check.
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.
Anyway, passing the led argument gives us the possibility of checking the correct pin in led_on/led_off
In the other hand not having 'led' as arguments makes this kind of issue impossible.
I still prefer this is removed from the API.
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 the other hand not having 'led' as arguments makes this kind of issue impossible.
I still prefer this is removed from the API.
@erwango No. This only holds true for leds-gpio driver, for other drivers there is no GPIO information in cfg.
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 agree the argument should stay and the driver should check 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.
Can you check following PR to see if it wouldn't provide similar service and spare the argument?
#12056
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 don't see how #12056 relates. I also agree that since this is being done as an implementation for an API that is designed to support multiple LEDs the argument must stay. However, see review summary.
samples/basic/blinky/README.rst
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.
Change drive LED devices to configure LED devices. To me, the word drive has hardware implications (voltage, resistors, and such), whereas the previous word configure feels better here since it's a software configuration we're discussing, right?
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.
Actually, in this PR I have moved the configuration part inside the LED GPIO driver. So we don't configure pins in this sample anymore.
e673e79 to
3ebb598
Compare
|
@erwango I have updated the PR incorporating your suggestions. Still, we have to figure out how to solve issues with boards without |
dbkinder
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.
OK
drivers/led/leds_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.
Many NXP boards invert the polarity, meaning you have to write a zero to the gpio to turn on the LED.
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.
Okay. Then the best way to address is to have a invert-polarity property on the leds node. What is your opinion?
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.
@MaureenHelm Just a ping over my query.
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.
We've already got information about the polarity in dts, can you use that?
zephyr/boards/arm/frdm_k64f/frdm_k64f.dts
Lines 50 to 51 in c1f54cc
| red_led: led@0 { | |
| gpios = <&gpiob 22 GPIO_INT_ACTIVE_LOW>; |
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.
Hmm, makes sense. Thanks for the pointer!
cb519b1 to
748b004
Compare
|
@MaureenHelm Updated the PR with polarity check. |
MaureenHelm
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.
Please fix the CI failures.
The merge window is currently closed to new features, so we need to wait to merge this PR until after the 1.13 release is complete.
drivers/led/leds_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.
How about replacing the if/else with:
gpio_pin_write(data->gpio, led, (cfg->gpio_polarity & GPIO_INT_ACTIVE_HIGH) != 0);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.
yeah, but I just wanted to make it explicit for the user here. Anyway, I can modify this.
drivers/led/leds_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.
Similar to above, try this instead of the if/else:
gpio_pin_write(data->gpio, led, (cfg->gpio_polarity & GPIO_INT_ACTIVE_HIGH) == 0);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.
Okay
748b004 to
6960b8a
Compare
|
@MaureenHelm CI failure is due to the absence of We need to add a few more for |
The better solution is to add led nodes to the board dts, otherwise we need the defines. |
|
@erwango @MaureenHelm PR updated as per the comments. With this PR, blinky sample won't build for boards which don't have |
drivers/led/leds_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 agree the argument should stay and the driver should check it.
|
@erwango Please have another look |
|
@erwango Can you please take a look? |
399cfe4 to
1e3e05a
Compare
|
Build failed due to lack of onboard LED support in |
I think it is ok if you do. |
Add driver for controlling the LED devices attached to GPIO pins which are declared in devicetree under leds node. The driver takes care of configuring the pins to output state before using it. Signed-off-by: Manivannan Sadhasivam <[email protected]>
leds_gpio driver is used to control the LED devices attached to GPIO pins onboard. Hence, convert the blinky application to use this driver instead of toggling the GPIO pin manually. Signed-off-by: Manivannan Sadhasivam <[email protected]>
Since LP3943 is an I2C device, relevant Kconfig symbols should only be used when I2C is enabled. Signed-off-by: Manivannan Sadhasivam <[email protected]>
1e3e05a to
f42fa54
Compare
|
@erwango Mind taking a look at the updated rev? |
Can you sum up the changeson this update? This has been a while ... :-) |
|
@erwango Nothing much really... There was a build failure when you last reviewed but that got fixed when LED node was added to Anyway, here is the changeset:
|
pabigot
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.
I think a GPIO LED driver is very much needed; all existing uses of GPIO LEDs ignore the active level which is annoying when working on cross-platform applications.
However, I also really don't like having a distinct driver instance for each GPIO LED on the board: the boards I use most have 4 to 6 LEDs. IMO this should be reworked so that each led-gpio instance supports multiple LEDs, just like all the other implementations of the generic LED API. I think it would be fair to require that the LEDs be located on the same GPIO device and have the same active level so that information need not be replicated; only the pin selector for each LED would be needed.
This does get a little tricky to do generically until device-tree support is more robust, though if there's agreement this is worth pursuing I do have some ideas. But honestly I'd rather not have this driver available than have it merged with this design, which is why I'm currently nacking the PR. If I'm the only one who feels this way I'll remove the nack.
The only board I'm immediately aware of that has GPIO LEDs on different gpio devices are the Particle boards proposed in #12195; for there there would have to be two devices, but the LEDs on each gpio device have different roles so that's not a bad thing.
drivers/led/leds_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 don't see how #12056 relates. I also agree that since this is being done as an implementation for an API that is designed to support multiple LEDs the argument must stay. However, see review summary.
Dismissing as @MaureenHelm and@pabigot are aligned with proposition (at least on the point I disagreed)
|
Closing at it got superseded. |
This PR adds leds_gpio driver which is used to control the LED devices attached to the GPIO pins through LED API and also modifies the existing blinky application as a consumer.
The leds_gpio driver currently supports only
led_onandled_offAPIs and there are plans to extend this driver to use timers for software blinking implementation in future.The driver requires no change in the board configuration at all. It has been designed to reuse the
gpio-ledsconfiguration for compatibility and supports only two LED devices for now. Both driver and sample application are validated on 96Boards Carbon board.Signed-off-by: Manivannan Sadhasivam [email protected]