Skip to content

Conversation

@Mani-Sadhasivam
Copy link
Member

@Mani-Sadhasivam Mani-Sadhasivam commented Aug 17, 2018

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_on and led_off APIs 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-leds configuration 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]

@Mani-Sadhasivam Mani-Sadhasivam added the area: LED Label to identify LED subsystem label Aug 17, 2018
@codecov-io
Copy link

codecov-io commented Aug 17, 2018

Codecov Report

Merging #9511 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           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     4267

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b1e912b...f42fa54. Read the comment docs.

@Mani-Sadhasivam
Copy link
Member Author

@erwango This leds_gpio requires the boards to have leds node for proper working. Without this node, we will run into LED0_GPIO_CONTROLLER undefined error.

Currently we have the following in blinky sample which takes care of this scenario:

/* Change this if you have an LED connected to a custom port */
#ifndef LED0_GPIO_CONTROLLER
#define LED0_GPIO_CONTROLLER    LED0_GPIO_PORT
#endif

Any idea of how we can handle this in driver? Moving the above defines to driver itself?

Copy link
Member

@erwango erwango left a 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

Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

okay.

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

@Mani-Sadhasivam ,

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

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

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Member Author

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.

@Mani-Sadhasivam
Copy link
Member Author

@erwango I have updated the PR incorporating your suggestions. Still, we have to figure out how to solve issues with boards without leds node.

Copy link
Contributor

@dbkinder dbkinder left a comment

Choose a reason for hiding this comment

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

OK

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member Author

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.

Copy link
Member

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?

red_led: led@0 {
gpios = <&gpiob 22 GPIO_INT_ACTIVE_LOW>;

Copy link
Member Author

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!

@Mani-Sadhasivam Mani-Sadhasivam force-pushed the gpio_led branch 2 times, most recently from cb519b1 to 748b004 Compare August 26, 2018 18:13
@Mani-Sadhasivam
Copy link
Member Author

@MaureenHelm Updated the PR with polarity check.

Copy link
Member

@MaureenHelm MaureenHelm left a 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.

Copy link
Member

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);

Copy link
Member Author

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.

Copy link
Member

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);

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay

@Mani-Sadhasivam
Copy link
Member Author

Mani-Sadhasivam commented Aug 28, 2018

@MaureenHelm CI failure is due to the absence of leds node in board DTS. Currently, the blinky sample has the following defines for the boards without leds node.

/* Change this if you have an LED connected to a custom port */
#ifndef LED0_GPIO_CONTROLLER
#define LED0_GPIO_CONTROLLER    LED0_GPIO_PORT
#endif

We need to add a few more for FLAGS, LABEL etc... So I just asked before that whether we need to have these #ifdefs or any other better solution available?

@MaureenHelm
Copy link
Member

We need to add a few more for FLAGS, LABEL etc... So I just asked before that whether we need to have these #ifdefs or any other better solution available?

The better solution is to add led nodes to the board dts, otherwise we need the defines.

@Mani-Sadhasivam
Copy link
Member Author

@erwango @MaureenHelm PR updated as per the comments. With this PR, blinky sample won't build for boards which don't have leds node in DT. I think this limitation is fine since most of the boards support DT and using defines will turn out be a hack.

Copy link
Member

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.

@MaureenHelm
Copy link
Member

@erwango Please have another look

@Mani-Sadhasivam
Copy link
Member Author

@erwango Can you please take a look?

@Mani-Sadhasivam
Copy link
Member Author

Build failed due to lack of onboard LED support in em_starterkit boards. Do I need to add the onboard led support or is there any work going on?

@erwango
Copy link
Member

erwango commented Oct 30, 2018

@Mani-Sadhasivam

Build failed due to lack of onboard LED support in em_starterkit boards. Do I need to add the onboard led support or is there any work going on?

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]>
@Mani-Sadhasivam
Copy link
Member Author

@erwango Mind taking a look at the updated rev?

@erwango
Copy link
Member

erwango commented Dec 21, 2018

@Mani-Sadhasivam ,

@erwango Mind taking a look at the updated rev?

Can you sum up the changeson this update? This has been a while ... :-)

@Mani-Sadhasivam
Copy link
Member Author

@erwango Nothing much really... There was a build failure when you last reviewed but that got fixed when LED node was added to em_starterkit board.

Anyway, here is the changeset:

  • Rebased to master
  • Fixed the LP3943 Kconfig to enable the default options only when CONFIG_I2C is set. Otherwise,
    it will give errors as !HAS_DTS_I2C will become true.

@pabigot pabigot self-requested a review December 27, 2018 12:58
Copy link
Contributor

@pabigot pabigot left a 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.

Copy link
Contributor

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.

@erwango erwango dismissed their stale review February 1, 2019 12:38

Dismissing as @MaureenHelm and@pabigot are aligned with proposition (at least on the point I disagreed)

@Mani-Sadhasivam
Copy link
Member Author

Closing at it got superseded.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants