From c076cb1bef6e41ea5c877c00c2864150fb5bec28 Mon Sep 17 00:00:00 2001 From: Takumi Ando Date: Mon, 13 Nov 2023 15:04:14 +0900 Subject: [PATCH] rp2040: pwm: Fix errors at CONFIG_PWM_NCHANNELS=1 Perhaps it has never been tested with CONFIG_PWM_NCHANNELS=1. Signed-off-by: Takumi Ando --- arch/arm/src/rp2040/Kconfig | 1 + arch/arm/src/rp2040/rp2040_pwm.c | 4 ++-- boards/arm/rp2040/common/src/rp2040_pwmdev.c | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/arm/src/rp2040/Kconfig b/arch/arm/src/rp2040/Kconfig index 4c9777cc71..d302f789e5 100644 --- a/arch/arm/src/rp2040/Kconfig +++ b/arch/arm/src/rp2040/Kconfig @@ -276,6 +276,7 @@ if PWM_MULTICHAN config PWM_NCHANNELS int "Number of channels" default 2 + range 1 2 ---help--- If the number of channels is set to 1, the generated code will only support the A channel of the PWM slices. This is functionally diff --git a/arch/arm/src/rp2040/rp2040_pwm.c b/arch/arm/src/rp2040/rp2040_pwm.c index a28dc8ad2e..e9d79e51c5 100644 --- a/arch/arm/src/rp2040/rp2040_pwm.c +++ b/arch/arm/src/rp2040/rp2040_pwm.c @@ -288,8 +288,8 @@ int pwm_shutdown (struct pwm_lowerhalf_s * dev) if (priv->pin >= 0) { - rp2040_gpio_setdir(priv->pin[0], true); - rp2040_gpio_put(priv->pin[0], + rp2040_gpio_setdir(priv->pin, true); + rp2040_gpio_put(priv->pin, ((priv->flags & RP2040_PWM_CSR_A_INV) != 0)); rp2040_gpio_set_function(priv->pin, RP2040_GPIO_FUNC_SIO); } diff --git a/boards/arm/rp2040/common/src/rp2040_pwmdev.c b/boards/arm/rp2040/common/src/rp2040_pwmdev.c index 21dfce7d74..297f96d9fb 100644 --- a/boards/arm/rp2040/common/src/rp2040_pwmdev.c +++ b/boards/arm/rp2040/common/src/rp2040_pwmdev.c @@ -58,11 +58,18 @@ int rp2040_pwmdev_initialize(int slice, int ret; struct rp2040_pwm_lowerhalf_s *pwm_lowerhalf; +#if defined(CONFIG_PWM_NCHANNELS) && CONFIG_PWM_NCHANNELS == 2 pwminfo("Initializing /dev/pwm%d a %d b %d f 0x%08lX..\n", slice, pin_a, pin_b, flags); +#else + pwminfo("Initializing /dev/pwm%d %d 0x%08lX..\n", + slice, + pin, + flags); +#endif /* Initialize spi device */