Skip to content

Commit 0ab86c4

Browse files
nordic-krchnashif
authored andcommitted
drivers: pwm: nrfx: Improve device generation macros
Use NRFX_FOREACH_PRESENT macro to iterate over all PWM instances and create device only for those enabled in the devicetree. This approach removes need of changing driver code when new instance id is added. Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent 85501c5 commit 0ab86c4

File tree

1 file changed

+3
-46
lines changed

1 file changed

+3
-46
lines changed

drivers/pwm/pwm_nrfx.c

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -390,50 +390,7 @@ static int pwm_nrfx_pm_action(const struct device *dev,
390390
POST_KERNEL, CONFIG_PWM_INIT_PRIORITY, \
391391
&pwm_nrfx_drv_api_funcs)
392392

393-
#ifdef CONFIG_HAS_HW_NRF_PWM0
394-
PWM_NRFX_DEVICE(0);
395-
#endif
396-
397-
#ifdef CONFIG_HAS_HW_NRF_PWM1
398-
PWM_NRFX_DEVICE(1);
399-
#endif
400-
401-
#ifdef CONFIG_HAS_HW_NRF_PWM2
402-
PWM_NRFX_DEVICE(2);
403-
#endif
404-
405-
#ifdef CONFIG_HAS_HW_NRF_PWM3
406-
PWM_NRFX_DEVICE(3);
407-
#endif
408-
409-
#ifdef CONFIG_HAS_HW_NRF_PWM20
410-
PWM_NRFX_DEVICE(20);
411-
#endif
412-
413-
#ifdef CONFIG_HAS_HW_NRF_PWM21
414-
PWM_NRFX_DEVICE(21);
415-
#endif
393+
#define COND_PWM_NRFX_DEVICE(unused, prefix, i, _) \
394+
IF_ENABLED(CONFIG_HAS_HW_NRF_PWM##prefix##i, (PWM_NRFX_DEVICE(prefix##i);))
416395

417-
#ifdef CONFIG_HAS_HW_NRF_PWM22
418-
PWM_NRFX_DEVICE(22);
419-
#endif
420-
421-
#ifdef CONFIG_HAS_HW_NRF_PWM120
422-
PWM_NRFX_DEVICE(120);
423-
#endif
424-
425-
#ifdef CONFIG_HAS_HW_NRF_PWM130
426-
PWM_NRFX_DEVICE(130);
427-
#endif
428-
429-
#ifdef CONFIG_HAS_HW_NRF_PWM131
430-
PWM_NRFX_DEVICE(131);
431-
#endif
432-
433-
#ifdef CONFIG_HAS_HW_NRF_PWM132
434-
PWM_NRFX_DEVICE(132);
435-
#endif
436-
437-
#ifdef CONFIG_HAS_HW_NRF_PWM133
438-
PWM_NRFX_DEVICE(133);
439-
#endif
396+
NRFX_FOREACH_PRESENT(PWM, COND_PWM_NRFX_DEVICE, (), (), _)

0 commit comments

Comments
 (0)