Skip to content

Conversation

@MarekPieta
Copy link
Contributor

Change introduces LED GPIO driver.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

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?

Copy link
Contributor

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

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 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.

@MarekPieta MarekPieta requested a review from anangl April 22, 2021 09:57
@jfischer-no jfischer-no requested a review from KAGA164 April 22, 2021 10:01
@jfischer-no
Copy link
Contributor

There is similar PR, "Add generic gpio leds driver with sample" #21578

@jfischer-no
Copy link
Contributor

It does not build in CI, you need to add it to https://github.com/zephyrproject-rtos/zephyr/tree/master/tests/drivers/build_all

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, done

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 use the recently introduced GPIO_DT_SPEC_GET utilities? https://docs.zephyrproject.org/latest/reference/peripherals/gpio.html#c.GPIO_DT_SPEC_GET

Copy link
Contributor Author

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

Comment on lines 73 to 76
Copy link
Member

@gmarull gmarull Apr 22, 2021

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

Suggested change
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;
}

Copy link
Contributor

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.

Copy link
Contributor Author

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 ?

@KAGA164
Copy link

KAGA164 commented Apr 22, 2021

@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

Copy link

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, added

Copy link

Choose a reason for hiding this comment

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

Suggested change
depends on GPIO
depends on GPIO && $(dt_compat_enabled, gpio-leds)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, added

Copy link
Contributor Author

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

Copy link

@KAGA164 KAGA164 left a comment

Choose a reason for hiding this comment

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

Looks good

@MarekPieta MarekPieta force-pushed the gpio_led branch 2 times, most recently from 6b780e6 to d174f7b Compare April 23, 2021 14:24
@MarekPieta MarekPieta requested a review from nashif as a code owner April 23, 2021 15:16
@github-actions github-actions bot added area: Devicetree area: Tests Issues related to a particular existing or missing test labels Apr 23, 2021
@MarekPieta
Copy link
Contributor Author

@jfischer-no, I added requested test to build_all

Copy link
Member

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?

Copy link
Contributor Author

@MarekPieta MarekPieta Apr 23, 2021

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

Copy link
Contributor Author

@MarekPieta MarekPieta Apr 23, 2021

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

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

@Mani-Sadhasivam Mani-Sadhasivam left a 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>
@MarekPieta
Copy link
Contributor Author

@nashif, can we merge it ?

@ioannisg ioannisg merged commit 66b6f07 into zephyrproject-rtos:master Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Devicetree area: Drivers area: LED Label to identify LED subsystem area: Tests Issues related to a particular existing or missing test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants