diff --git a/samples/basic/fade_led/boards/nrf54h20dk_nrf54h20_cpuapp.overlay b/samples/basic/fade_led/boards/nrf54h20dk_nrf54h20_cpuapp.overlay new file mode 100644 index 00000000000..ab13a016025 --- /dev/null +++ b/samples/basic/fade_led/boards/nrf54h20dk_nrf54h20_cpuapp.overlay @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + * + * Test requires wire connection between: + * - PWM120 OUT[0] at P7.0 + * - LED[0-4] input at P9.[0-4] + */ + +#include +#include +#include + +&pwm130 { + status = "disabled"; +}; + +&pwm_led2 { + // pwms = <&pwm130 0 PWM_MSEC(10) PWM_POLARITY_NORMAL>; + pwms = <&pwm120 0 PWM_MSEC(10) PWM_POLARITY_NORMAL>; +}; + +&pinctrl { + pwm120_default: pwm120_default { + group1 { + psels = ; + }; + }; + pwm120_sleep: pwm120_sleep { + group1 { + psels = ; + low-power-enable; + }; + }; +}; + +&pwm120 { + status = "okay"; + pinctrl-0 = <&pwm120_default>; + pinctrl-1 = <&pwm120_sleep>; + pinctrl-names = "default", "sleep"; + memory-regions = <&dma_fast_region>; +}; + +&dma_fast_region { + status = "okay"; +}; diff --git a/samples/basic/fade_led/src/main.c b/samples/basic/fade_led/src/main.c index c6a49a13a12..61cdeb3b7f2 100644 --- a/samples/basic/fade_led/src/main.c +++ b/samples/basic/fade_led/src/main.c @@ -16,15 +16,11 @@ static const struct pwm_dt_spec pwm_led0 = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0)); -#define NUM_STEPS 50U -#define SLEEP_MSEC 25U int main(void) { - uint32_t pulse_width = 0U; - uint32_t step = pwm_led0.period / NUM_STEPS; - uint8_t dir = 1U; int ret; + uint32_t pulse_width; printk("PWM-based LED fade\n"); @@ -35,6 +31,7 @@ int main(void) } while (1) { + pulse_width = 0; ret = pwm_set_pulse_dt(&pwm_led0, pulse_width); if (ret) { printk("Error %d: failed to set pulse width\n", ret); @@ -42,22 +39,27 @@ int main(void) } printk("Using pulse width %d%%\n", 100 * pulse_width / pwm_led0.period); - if (dir) { - pulse_width += step; - if (pulse_width >= pwm_led0.period) { - pulse_width = pwm_led0.period - step; - dir = 0U; - } - } else { - if (pulse_width >= step) { - pulse_width -= step; - } else { - pulse_width = step; - dir = 1U; - } + k_msleep(1000); + + pulse_width = pwm_led0.period / 2; + ret = pwm_set_pulse_dt(&pwm_led0, pulse_width); + if (ret) { + printk("Error %d: failed to set pulse width\n", ret); + return 0; + } + printk("Using pulse width %d%%\n", 100 * pulse_width / pwm_led0.period); + + k_msleep(1000); + + pulse_width = pwm_led0.period; + ret = pwm_set_pulse_dt(&pwm_led0, pulse_width); + if (ret) { + printk("Error %d: failed to set pulse width\n", ret); + return 0; } + printk("Using pulse width %d%%\n", 100 * pulse_width / pwm_led0.period); - k_sleep(K_MSEC(SLEEP_MSEC)); + k_msleep(1000); } return 0; }