From 0ab86c48dd7a448e82c69a8e274de9984ac40f82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Tue, 1 Oct 2024 08:54:56 +0200 Subject: [PATCH] drivers: pwm: nrfx: Improve device generation macros MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- drivers/pwm/pwm_nrfx.c | 49 +++--------------------------------------- 1 file changed, 3 insertions(+), 46 deletions(-) diff --git a/drivers/pwm/pwm_nrfx.c b/drivers/pwm/pwm_nrfx.c index f6312535c7e..a1ee27fc702 100644 --- a/drivers/pwm/pwm_nrfx.c +++ b/drivers/pwm/pwm_nrfx.c @@ -390,50 +390,7 @@ static int pwm_nrfx_pm_action(const struct device *dev, POST_KERNEL, CONFIG_PWM_INIT_PRIORITY, \ &pwm_nrfx_drv_api_funcs) -#ifdef CONFIG_HAS_HW_NRF_PWM0 -PWM_NRFX_DEVICE(0); -#endif +#define COND_PWM_NRFX_DEVICE(unused, prefix, i, _) \ + IF_ENABLED(CONFIG_HAS_HW_NRF_PWM##prefix##i, (PWM_NRFX_DEVICE(prefix##i);)) -#ifdef CONFIG_HAS_HW_NRF_PWM1 -PWM_NRFX_DEVICE(1); -#endif - -#ifdef CONFIG_HAS_HW_NRF_PWM2 -PWM_NRFX_DEVICE(2); -#endif - -#ifdef CONFIG_HAS_HW_NRF_PWM3 -PWM_NRFX_DEVICE(3); -#endif - -#ifdef CONFIG_HAS_HW_NRF_PWM20 -PWM_NRFX_DEVICE(20); -#endif - -#ifdef CONFIG_HAS_HW_NRF_PWM21 -PWM_NRFX_DEVICE(21); -#endif - -#ifdef CONFIG_HAS_HW_NRF_PWM22 -PWM_NRFX_DEVICE(22); -#endif - -#ifdef CONFIG_HAS_HW_NRF_PWM120 -PWM_NRFX_DEVICE(120); -#endif - -#ifdef CONFIG_HAS_HW_NRF_PWM130 -PWM_NRFX_DEVICE(130); -#endif - -#ifdef CONFIG_HAS_HW_NRF_PWM131 -PWM_NRFX_DEVICE(131); -#endif - -#ifdef CONFIG_HAS_HW_NRF_PWM132 -PWM_NRFX_DEVICE(132); -#endif - -#ifdef CONFIG_HAS_HW_NRF_PWM133 -PWM_NRFX_DEVICE(133); -#endif +NRFX_FOREACH_PRESENT(PWM, COND_PWM_NRFX_DEVICE, (), (), _)