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 sample #82383

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions samples/basic/blinky_pwm/boards/nucleo_l4r5zi.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
status = "okay";
};

&timers1 {
st,prescaler = <10000>;
};

&pwm1 {
status = "okay";
};
1 change: 1 addition & 0 deletions samples/drivers/led/pwm/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ For each PWM LEDs (one after the other):
- Turning on
- Turning off
- Increasing brightness gradually
- Decreasing brightness gradually
- Blinking on: 0.1 sec, off: 0.1 sec
- Blinking on: 1 sec, off: 1 sec
- Turning off
Expand Down
23 changes: 23 additions & 0 deletions samples/drivers/led/pwm/boards/nucleo_l4r5zi.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 STMicroelectronics
*/

/ {
leds {
status = "disabled";
};
};

&pwmleds {
status = "okay";
};

&timers1 {
st,prescaler = <10000>;
};

&pwm1 {
status = "okay";
};
11 changes: 11 additions & 0 deletions samples/drivers/led/pwm/boards/stm32f4_disco.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2023 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
leds {
status = "disabled";
};
};
1 change: 1 addition & 0 deletions samples/drivers/led/pwm/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ tests:
- "Turned on"
- "Turned off"
- "Increasing brightness gradually"
- "Decreasing brightness gradually"
- "Blinking on: ([0-9]+) msec, off: ([0-9]+) msec"
- "(Blinking on: ([0-9]+) msec, off: ([0-9]+) msec|Cycle period not supported)"
- "Turned off, loop end"
14 changes: 13 additions & 1 deletion samples/drivers/led/pwm/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const int num_leds = ARRAY_SIZE(led_label);
static void run_led_test(const struct device *led_pwm, uint8_t led)
{
int err;
uint16_t level;
int16_t level;

LOG_INF("Testing LED %d - %s", led, led_label[led] ? : "no label");

Expand Down Expand Up @@ -67,6 +67,18 @@ static void run_led_test(const struct device *led_pwm, uint8_t led)
}
k_sleep(K_MSEC(1000));

/* Decrease LED brightness gradually down to the minimum level. */
LOG_INF(" Decreasing brightness gradually");
for (level = MAX_BRIGHTNESS; level >= 0; level--) {
err = led_set_brightness(led_pwm, led, level);
if (err < 0) {
LOG_ERR("err=%d brightness=%d\n", err, level);
return;
}
k_sleep(K_MSEC(CONFIG_FADE_DELAY));
}
k_sleep(K_MSEC(1000));

#if CONFIG_BLINK_DELAY_SHORT > 0
/* Start LED blinking (short cycle) */
err = led_blink(led_pwm, led, CONFIG_BLINK_DELAY_SHORT, CONFIG_BLINK_DELAY_SHORT);
Expand Down