Skip to content
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

LED PWM driver #29401

Merged
merged 2 commits into from
Oct 28, 2020
Merged

LED PWM driver #29401

merged 2 commits into from
Oct 28, 2020

Conversation

simonguinot
Copy link
Collaborator

This pull request adds a driver (and its test sample) for the PWM driven LEDs.

The devices are created from the DT nodes with a compatible property matching "pwm-leds". For each child node a LED is created and its "pwms" phandle's node is used to retrieve the PWM configuration: channel, period and flags. If some of this properties are missing (it is the case for some PWM controllers), then reasonable default values are used.

This driver implements the following LED API methods:

  • led_on
  • led_off
  • led_blink
  • led_set_brightness

@simonguinot
Copy link
Collaborator Author

Two commits I used to test this driver on a STM32F070-based board have been accidentally pushed in the initial PR. I removed them.

Copy link
Member

@gmarull gmarull left a comment

Choose a reason for hiding this comment

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

Added some comments. LGTM, simple and nice driver!

drivers/led/led_pwm.c Outdated Show resolved Hide resolved
drivers/led/led_pwm.c Outdated Show resolved Hide resolved
samples/drivers/led_pwm/src/main.c Outdated Show resolved Hide resolved
samples/drivers/led_pwm/src/main.c Outdated Show resolved Hide resolved
drivers/led/led_pwm.c Show resolved Hide resolved
drivers/led/led_pwm.c Show resolved Hide resolved
@simonguinot simonguinot force-pushed the led-pwm branch 3 times, most recently from 67abdbf to be2c568 Compare October 21, 2020 17:10
Copy link
Contributor

@mbolivar-nordic mbolivar-nordic left a comment

Choose a reason for hiding this comment

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

Thanks!

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.

LGTM, thanks!

This driver supports the PWM driven LEDs. The devices are created from
the DT nodes with a compatible property matching "pwm-leds". For each
child node a LED is created and its "pwms" phandle's node is used to
retrieve the PWM configuration: channel, period and flags. If some of
this properties are missing (it is the case for some PWM controllers),
then reasonable default values are used.

This driver implements the following LED API methods:

- led_on
- led_off
- led_blink
- led_set_brightness

Signed-off-by: Simon Guinot <[email protected]>
This sample allows to test the led-pwm driver. The first "pwm-leds"
compatible device instance found in DT is used. For each LEDs attached
to this device (child nodes) the same test pattern (described below) is
executed. The LED API functions are used to control the LEDs.

Test pattern:

For each PWM LEDs (one after the other):

- turn on
- turn off
- increase the brightness gradually up to the maximum level
- blink (0.1 sec on, 0.1 sec off)
- blink (1 sec on, 1 sec off)
- turn off

Signed-off-by: Simon Guinot <[email protected]>
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.

This is cool, thanks!

@MaureenHelm MaureenHelm merged commit 6499ecb into zephyrproject-rtos:master Oct 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants