From 78ff053845ff7439683327e7e80db13b943212d9 Mon Sep 17 00:00:00 2001 From: raiden00pl Date: Mon, 11 May 2026 11:15:18 +0200 Subject: [PATCH 1/2] examples/pwm: remove references to CONFIG_PWM_MULTICHAN remove references to CONFIG_PWM_MULTICHAN Signed-off-by: raiden00pl --- examples/pwm/Kconfig | 18 +---- examples/pwm/pwm.h | 10 ++- examples/pwm/pwm_main.c | 151 +++++++++++++++------------------------- 3 files changed, 63 insertions(+), 116 deletions(-) diff --git a/examples/pwm/Kconfig b/examples/pwm/Kconfig index 9378003f246..b6e0a3d8234 100644 --- a/examples/pwm/Kconfig +++ b/examples/pwm/Kconfig @@ -29,10 +29,7 @@ config EXAMPLES_PWM_DURATION default 5 ---help--- The default PWM pulse train duration in seconds. Used only if the current - pulse count is zero (pulse count is only supported if PWM_PULSECOUNT - is not defined). Default: 5 seconds - -if PWM_MULTICHAN + pulse count is zero. Default: 5 seconds config EXAMPLES_PWM_DUTYPCT1 int "First PWM duty percentage" @@ -138,17 +135,6 @@ config EXAMPLES_PWM_CHANNEL6 endif -endif - -if !PWM_MULTICHAN - -config EXAMPLES_PWM_DUTYPCT - int "Default PWM duty percentage" - default 50 - range 1 99 - ---help--- - The default PWM duty as a percentage. Default: 50% - config EXAMPLES_PWM_PULSECOUNT int "Default pulse count" default 0 @@ -159,5 +145,3 @@ config EXAMPLES_PWM_PULSECOUNT the count). endif - -endif diff --git a/examples/pwm/pwm.h b/examples/pwm/pwm.h index e0447b9b374..d5c15aed9d8 100644 --- a/examples/pwm/pwm.h +++ b/examples/pwm/pwm.h @@ -40,8 +40,10 @@ * Default: /dev/pwm0 * CONFIG_EXAMPLES_PWM_FREQUENCY - The initial PWM frequency. * Default: 100 Hz - * CONFIG_EXAMPLES_PWM_DUTYPCT - The initial PWM duty as a percentage. - * Default: 50% + * CONFIG_EXAMPLES_PWM_DUTYPCTn - The initial PWM duty as a percentage for + * channel n. Default: 50% + * CONFIG_EXAMPLES_PWM_CHANNELn - The PWM channel number for channel n. + * Default: n * CONFIG_EXAMPLES_PWM_DURATION - The initial PWM pulse train duration * in seconds. Used only if the current pulse count is zero * (pulse count is only supported if CONFIG_PWM_PULSECOUNT is defined). @@ -63,10 +65,6 @@ # define CONFIG_EXAMPLES_PWM_FREQUENCY 100 #endif -#ifndef CONFIG_EXAMPLES_PWM_DUTYPCT -# define CONFIG_EXAMPLES_PWM_DUTYPCT 50 -#endif - #ifndef CONFIG_EXAMPLES_PWM_DURATION # define CONFIG_EXAMPLES_PWM_DURATION 5 #endif diff --git a/examples/pwm/pwm_main.c b/examples/pwm/pwm_main.c index 683587f085c..085a36b9ee3 100644 --- a/examples/pwm/pwm_main.c +++ b/examples/pwm/pwm_main.c @@ -48,46 +48,44 @@ /* Configuration ************************************************************/ -#ifdef CONFIG_PWM_MULTICHAN -# if CONFIG_PWM_NCHANNELS > 1 -# if CONFIG_EXAMPLES_PWM_CHANNEL1 == CONFIG_EXAMPLES_PWM_CHANNEL2 -# error "Channel numbers must be unique" -# endif +#if CONFIG_PWM_NCHANNELS > 1 +# if CONFIG_EXAMPLES_PWM_CHANNEL1 == CONFIG_EXAMPLES_PWM_CHANNEL2 +# error "Channel numbers must be unique" # endif -# if CONFIG_PWM_NCHANNELS > 2 -# if CONFIG_EXAMPLES_PWM_CHANNEL1 == CONFIG_EXAMPLES_PWM_CHANNEL3 || \ +#endif +#if CONFIG_PWM_NCHANNELS > 2 +# if CONFIG_EXAMPLES_PWM_CHANNEL1 == CONFIG_EXAMPLES_PWM_CHANNEL3 || \ CONFIG_EXAMPLES_PWM_CHANNEL2 == CONFIG_EXAMPLES_PWM_CHANNEL3 -# error "Channel numbers must be unique" -# endif +# error "Channel numbers must be unique" # endif -# if CONFIG_PWM_NCHANNELS > 3 -# if CONFIG_EXAMPLES_PWM_CHANNEL1 == CONFIG_EXAMPLES_PWM_CHANNEL4 || \ +#endif +#if CONFIG_PWM_NCHANNELS > 3 +# if CONFIG_EXAMPLES_PWM_CHANNEL1 == CONFIG_EXAMPLES_PWM_CHANNEL4 || \ CONFIG_EXAMPLES_PWM_CHANNEL2 == CONFIG_EXAMPLES_PWM_CHANNEL4 || \ CONFIG_EXAMPLES_PWM_CHANNEL3 == CONFIG_EXAMPLES_PWM_CHANNEL4 -# error "Channel numbers must be unique" -# endif +# error "Channel numbers must be unique" # endif -# if CONFIG_PWM_NCHANNELS > 4 -# if CONFIG_EXAMPLES_PWM_CHANNEL1 == CONFIG_EXAMPLES_PWM_CHANNEL5 || \ +#endif +#if CONFIG_PWM_NCHANNELS > 4 +# if CONFIG_EXAMPLES_PWM_CHANNEL1 == CONFIG_EXAMPLES_PWM_CHANNEL5 || \ CONFIG_EXAMPLES_PWM_CHANNEL2 == CONFIG_EXAMPLES_PWM_CHANNEL5 || \ CONFIG_EXAMPLES_PWM_CHANNEL3 == CONFIG_EXAMPLES_PWM_CHANNEL5 || \ CONFIG_EXAMPLES_PWM_CHANNEL4 == CONFIG_EXAMPLES_PWM_CHANNEL5 -# error "Channel numbers must be unique" -# endif +# error "Channel numbers must be unique" # endif -# if CONFIG_PWM_NCHANNELS > 5 -# if CONFIG_EXAMPLES_PWM_CHANNEL1 == CONFIG_EXAMPLES_PWM_CHANNEL6 || \ +#endif +#if CONFIG_PWM_NCHANNELS > 5 +# if CONFIG_EXAMPLES_PWM_CHANNEL1 == CONFIG_EXAMPLES_PWM_CHANNEL6 || \ CONFIG_EXAMPLES_PWM_CHANNEL2 == CONFIG_EXAMPLES_PWM_CHANNEL6 || \ CONFIG_EXAMPLES_PWM_CHANNEL3 == CONFIG_EXAMPLES_PWM_CHANNEL6 || \ CONFIG_EXAMPLES_PWM_CHANNEL4 == CONFIG_EXAMPLES_PWM_CHANNEL6 || \ CONFIG_EXAMPLES_PWM_CHANNEL5 == CONFIG_EXAMPLES_PWM_CHANNEL6 -# error "Channel numbers must be unique" -# endif -# endif -# if CONFIG_PWM_NCHANNELS > 6 -# error "Too many PWM channels" +# error "Channel numbers must be unique" # endif #endif +#if CONFIG_PWM_NCHANNELS > 6 +# error "Too many PWM channels" +#endif /**************************************************************************** * Private Types @@ -97,12 +95,8 @@ struct pwm_state_s { bool initialized; FAR char *devpath; -#ifdef CONFIG_PWM_MULTICHAN - uint8_t channels[CONFIG_PWM_NCHANNELS]; + int8_t channels[CONFIG_PWM_NCHANNELS]; uint8_t duties[CONFIG_PWM_NCHANNELS]; -#else - uint8_t duty; -#endif uint32_t freq; #ifdef CONFIG_PWM_PULSECOUNT uint32_t count; @@ -152,49 +146,47 @@ static void pwm_devpath(FAR struct pwm_state_s *pwm, FAR const char *devpath) static void pwm_help(FAR struct pwm_state_s *pwm) { -#ifdef CONFIG_PWM_MULTICHAN - uint8_t channels[CONFIG_PWM_NCHANNELS] = - { - CONFIG_EXAMPLES_PWM_CHANNEL1, + int8_t channels[CONFIG_PWM_NCHANNELS] = + { + CONFIG_EXAMPLES_PWM_CHANNEL1, #if CONFIG_PWM_NCHANNELS > 1 - CONFIG_EXAMPLES_PWM_CHANNEL2, + CONFIG_EXAMPLES_PWM_CHANNEL2, #endif #if CONFIG_PWM_NCHANNELS > 2 - CONFIG_EXAMPLES_PWM_CHANNEL3, + CONFIG_EXAMPLES_PWM_CHANNEL3, #endif #if CONFIG_PWM_NCHANNELS > 3 - CONFIG_EXAMPLES_PWM_CHANNEL4, + CONFIG_EXAMPLES_PWM_CHANNEL4, #endif #if CONFIG_PWM_NCHANNELS > 4 - CONFIG_EXAMPLES_PWM_CHANNEL5, + CONFIG_EXAMPLES_PWM_CHANNEL5, #endif #if CONFIG_PWM_NCHANNELS > 5 - CONFIG_EXAMPLES_PWM_CHANNEL6, + CONFIG_EXAMPLES_PWM_CHANNEL6, #endif - }; + }; uint8_t duties[CONFIG_PWM_NCHANNELS] = - { - CONFIG_EXAMPLES_PWM_DUTYPCT1, + { + CONFIG_EXAMPLES_PWM_DUTYPCT1, #if CONFIG_PWM_NCHANNELS > 1 - CONFIG_EXAMPLES_PWM_DUTYPCT2, + CONFIG_EXAMPLES_PWM_DUTYPCT2, #endif #if CONFIG_PWM_NCHANNELS > 2 - CONFIG_EXAMPLES_PWM_DUTYPCT3, + CONFIG_EXAMPLES_PWM_DUTYPCT3, #endif #if CONFIG_PWM_NCHANNELS > 3 - CONFIG_EXAMPLES_PWM_DUTYPCT4, + CONFIG_EXAMPLES_PWM_DUTYPCT4, #endif #if CONFIG_PWM_NCHANNELS > 4 - CONFIG_EXAMPLES_PWM_DUTYPCT5, + CONFIG_EXAMPLES_PWM_DUTYPCT5, #endif #if CONFIG_PWM_NCHANNELS > 5 - CONFIG_EXAMPLES_PWM_DUTYPCT6, + CONFIG_EXAMPLES_PWM_DUTYPCT6, #endif - }; + }; int i; -#endif printf("Usage: pwm [OPTIONS]\n"); printf("\nArguments are \"sticky\". " @@ -207,7 +199,6 @@ static void pwm_help(FAR struct pwm_state_s *pwm) printf(" [-f frequency] selects the pulse frequency. " "Default: %d Hz Current: %" PRIu32 " Hz\n", CONFIG_EXAMPLES_PWM_FREQUENCY, pwm->freq); -#ifdef CONFIG_PWM_MULTICHAN printf(" [[-c channel1] [[-c channel2] ...]] " "selects the channel number for each channel. "); printf("Default:"); @@ -239,11 +230,6 @@ static void pwm_help(FAR struct pwm_state_s *pwm) } printf("\n"); -#else - printf(" [-d duty] selects the pulse duty as a percentage. " - "Default: %d %% Current: %d %%\n", - CONFIG_EXAMPLES_PWM_DUTYPCT, pwm->duty); -#endif #ifdef CONFIG_PWM_PULSECOUNT printf(" [-n count] selects the pulse count. " "Default: %d Current: %" PRIx32 "\n", @@ -301,10 +287,10 @@ static void parse_args(FAR struct pwm_state_s *pwm, int argc, long value; int index; int nargs; -#ifdef CONFIG_PWM_MULTICHAN +#if CONFIG_PWM_NCHANNELS > 1 int nchannels = 0; - int nduties = 0; #endif + int nduties = 0; for (index = 1; index < argc; ) { @@ -329,7 +315,7 @@ static void parse_args(FAR struct pwm_state_s *pwm, int argc, index += nargs; break; -#ifdef CONFIG_PWM_MULTICHAN +#if CONFIG_PWM_NCHANNELS > 1 case 'c': nargs = arg_decimal(&argv[index], &value); if (value < -1 || value > CONFIG_PWM_NCHANNELS) @@ -361,7 +347,6 @@ static void parse_args(FAR struct pwm_state_s *pwm, int argc, exit(1); } -#ifdef CONFIG_PWM_MULTICHAN if (nduties < CONFIG_PWM_NCHANNELS) { nduties++; @@ -373,9 +358,6 @@ static void parse_args(FAR struct pwm_state_s *pwm, int argc, } pwm->duties[nduties - 1] = (uint8_t)value; -#else - pwm->duty = (uint8_t)value; -#endif index += nargs; break; @@ -436,16 +418,13 @@ int main(int argc, FAR char *argv[]) struct pwm_info_s info; int fd; int ret; -#ifdef CONFIG_PWM_MULTICHAN int i; int j; -#endif /* Initialize the state data */ if (!g_pwmstate.initialized) { -#ifdef CONFIG_PWM_MULTICHAN g_pwmstate.channels[0] = CONFIG_EXAMPLES_PWM_CHANNEL1; g_pwmstate.duties[0] = CONFIG_EXAMPLES_PWM_DUTYPCT1; #if CONFIG_PWM_NCHANNELS > 1 @@ -467,9 +446,6 @@ int main(int argc, FAR char *argv[]) #if CONFIG_PWM_NCHANNELS > 5 g_pwmstate.channels[5] = CONFIG_EXAMPLES_PWM_CHANNEL6; g_pwmstate.duties[5] = CONFIG_EXAMPLES_PWM_DUTYPCT6; -#endif -#else - g_pwmstate.duty = CONFIG_EXAMPLES_PWM_DUTYPCT; #endif g_pwmstate.freq = CONFIG_EXAMPLES_PWM_FREQUENCY; g_pwmstate.duration = CONFIG_EXAMPLES_PWM_DURATION; @@ -483,19 +459,23 @@ int main(int argc, FAR char *argv[]) parse_args(&g_pwmstate, argc, argv); -#ifdef CONFIG_PWM_MULTICHAN - for (i = 0; i < CONFIG_PWM_MULTICHAN; i++) + for (i = 0; i < CONFIG_PWM_NCHANNELS; i++) { - for (j = i + 1; j < CONFIG_PWM_MULTICHAN; j++) + if (g_pwmstate.channels[i] < 1) + { + continue; + } + + for (j = i + 1; j < CONFIG_PWM_NCHANNELS; j++) { - if (g_pwmstate.channels[j] == g_pwmstate.channels[i]) + if (g_pwmstate.channels[j] > 0 && + g_pwmstate.channels[j] == g_pwmstate.channels[i]) { printf("pwm_main: channel numbers must be unique\n"); goto errout; } } } -#endif /* Has a device been assigned? */ @@ -517,8 +497,8 @@ int main(int argc, FAR char *argv[]) /* Configure the characteristics of the pulse train */ + memset(&info, 0, sizeof(info)); info.frequency = g_pwmstate.freq; -#ifdef CONFIG_PWM_MULTICHAN printf("pwm_main: starting output with frequency: %" PRIu32, info.frequency); @@ -531,26 +511,11 @@ int main(int argc, FAR char *argv[]) info.channels[i].channel, info.channels[i].duty); } - printf("\n"); - -#else - info.duty = g_pwmstate.duty ? \ - b16divi(uitoub16(g_pwmstate.duty) - 1, 100) : 0; -# ifdef CONFIG_PWM_PULSECOUNT - info.count = g_pwmstate.count; - - printf("pwm_main: starting output " - "with frequency: %" PRIu32 " duty: %08" PRIx32 - " count: %" PRIx32 "\n", - info.frequency, (uint32_t)info.duty, info.count); - -# else - printf("pwm_main: starting output " - "with frequency: %" PRIu32 " duty: %08" PRIx32 "\n", - info.frequency, (uint32_t)info.duty); - -# endif +#ifdef CONFIG_PWM_PULSECOUNT + info.channels[0].count = g_pwmstate.count; + printf(" count: %" PRIx32, info.channels[0].count); #endif + printf("\n"); ret = ioctl(fd, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&info)); @@ -577,7 +542,7 @@ int main(int argc, FAR char *argv[]) */ #ifdef CONFIG_PWM_PULSECOUNT - if (info.count == 0) + if (info.channels[0].count == 0) #endif { /* Wait for the specified duration */ From ed861229d686605793692cc7c33fd7316d3f05fc Mon Sep 17 00:00:00 2001 From: raiden00pl Date: Mon, 11 May 2026 11:15:41 +0200 Subject: [PATCH 2/2] testing/drivertest_pwm: remove references to CONFIG_PWM_MULTICHAN remove references to CONFIG_PWM_MULTICHAN Signed-off-by: raiden00pl --- testing/drivers/drivertest/drivertest_pwm.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/testing/drivers/drivertest/drivertest_pwm.c b/testing/drivers/drivertest/drivertest_pwm.c index 3dd3bae6443..7b08f9a24f7 100644 --- a/testing/drivers/drivertest/drivertest_pwm.c +++ b/testing/drivers/drivertest/drivertest_pwm.c @@ -164,11 +164,11 @@ static void parse_commandline(FAR struct pwm_state_s *pwm_state, int argc, OPTARG_TO_VALUE(converted, uint32_t, 10); if (converted < 0) { - printf("Count must be non-negative: %ld\n", converted); + printf("Count must be non-negative: %d\n", converted); pwm_help(argv[0], pwm_state, EXIT_FAILURE); } - pwm_state->count = (uint32_t)value; + pwm_state->count = (uint32_t)converted; break; #endif case 'f': @@ -223,9 +223,7 @@ static void drivertest_pwm(FAR void **state) { int fd; int ret; -#ifdef CONFIG_PWM_MULTICHAN int i; -#endif struct pwm_info_s info; FAR struct pwm_state_s *pwm_state; pwm_state = (FAR struct pwm_state_s *)*state; @@ -241,18 +239,14 @@ static void drivertest_pwm(FAR void **state) info.frequency = pwm_state->freq; -#ifdef CONFIG_PWM_MULTICHAN for (i = 0; i < CONFIG_PWM_NCHANNELS; i++) { info.channels[i].channel = i + 1; info.channels[i].duty = b16divi(uitoub16(pwm_state->duty), 100); } -#else - info.duty = b16divi(uitoub16(pwm_state->duty), 100); -#endif #ifdef CONFIG_PWM_PULSECOUNT - info.count = pwm_state.count; + info.channels[0].count = pwm_state->count; #endif ret = ioctl(fd, PWMIOC_SETCHARACTERISTICS, @@ -271,7 +265,7 @@ static void drivertest_pwm(FAR void **state) */ #ifdef CONFIG_PWM_PULSECOUNT - if (info.count == 0) + if (info.channels[0].count == 0) #endif { /* Wait for the specified duration */