From 75c1e43334a134ac41eb3ebb7ac36709c5800ae3 Mon Sep 17 00:00:00 2001 From: Norman Rasmussen Date: Tue, 28 Dec 2021 03:04:12 -0800 Subject: [PATCH] increase number of supported PWM channels from 4 to 6 commit d8199fe460e432584125e73a4d9cceabd9baec74 changed Kconfig, but it looks like pwm_main.c should have been changed too. This adds support for the 5th and 6th channels to the code, and adds an error if more than 6 channels are configured. --- examples/pwm/pwm_main.c | 42 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/examples/pwm/pwm_main.c b/examples/pwm/pwm_main.c index d9c19c98a..a095484e5 100644 --- a/examples/pwm/pwm_main.c +++ b/examples/pwm/pwm_main.c @@ -65,6 +65,26 @@ # error "Channel numbers must be unique" # endif # 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 +# 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" +# endif #endif /**************************************************************************** @@ -142,6 +162,12 @@ static void pwm_help(FAR struct pwm_state_s *pwm) #endif #if CONFIG_PWM_NCHANNELS > 3 CONFIG_EXAMPLES_PWM_CHANNEL4, +#endif +#if CONFIG_PWM_NCHANNELS > 4 + CONFIG_EXAMPLES_PWM_CHANNEL5, +#endif +#if CONFIG_PWM_NCHANNELS > 5 + CONFIG_EXAMPLES_PWM_CHANNEL6, #endif }; @@ -156,6 +182,12 @@ static void pwm_help(FAR struct pwm_state_s *pwm) #endif #if CONFIG_PWM_NCHANNELS > 3 CONFIG_EXAMPLES_PWM_DUTYPCT4, +#endif +#if CONFIG_PWM_NCHANNELS > 4 + CONFIG_EXAMPLES_PWM_DUTYPCT5, +#endif +#if CONFIG_PWM_NCHANNELS > 5 + CONFIG_EXAMPLES_PWM_DUTYPCT6, #endif }; @@ -298,7 +330,7 @@ static void parse_args(FAR struct pwm_state_s *pwm, int argc, #ifdef CONFIG_PWM_MULTICHAN case 'c': nargs = arg_decimal(&argv[index], &value); - if (value < 1 || value > 4) + if (value < 1 || value > CONFIG_PWM_NCHANNELS) { printf("Channel out of range: %ld\n", value); exit(1); @@ -426,6 +458,14 @@ int main(int argc, FAR char *argv[]) g_pwmstate.channels[3] = CONFIG_EXAMPLES_PWM_CHANNEL4; g_pwmstate.duties[3] = CONFIG_EXAMPLES_PWM_DUTYPCT4; #endif +#if CONFIG_PWM_NCHANNELS > 4 + g_pwmstate.channels[4] = CONFIG_EXAMPLES_PWM_CHANNEL5; + g_pwmstate.duties[4] = CONFIG_EXAMPLES_PWM_DUTYPCT5; +#endif +#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