Skip to content

Commit

Permalink
samv7: add support for complementary PWM output
Browse files Browse the repository at this point in the history
SAMv7 PWM driver supports complementary PWM output if both pins (H and L)
are defined and configured. This commit adds a configuration option to
configure the complementary L pin.

The pin definition has to be provided by board level support.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
  • Loading branch information
michallenc committed Feb 21, 2023
1 parent 8ef0c40 commit 3b3e23b
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 13 deletions.
64 changes: 64 additions & 0 deletions arch/arm/src/samv7/Kconfig
Expand Up @@ -612,18 +612,50 @@ config SAMV7_PWM0_CH0
bool "PWM0 Channel 0"
default n

if SAMV7_PWM0_CH0

config SAMV7_PWM0_CH0_COMP
bool "Use complementary output"
default n

endif

config SAMV7_PWM0_CH1
bool "PWM0 Channel 1"
default n

if SAMV7_PWM0_CH1

config SAMV7_PWM0_CH1_COMP
bool "Use complementary output"
default n

endif

config SAMV7_PWM0_CH2
bool "PWM0 Channel 2"
default n

if SAMV7_PWM0_CH2

config SAMV7_PWM0_CH2_COMP
bool "Use complementary output"
default n

endif

config SAMV7_PWM0_CH3
bool "PWM0 Channel 3"
default n

if SAMV7_PWM0_CH3

config SAMV7_PWM0_CH3_COMP
bool "Use complementary output"
default n

endif

endif

menuconfig SAMV7_PWM1
Expand All @@ -639,18 +671,50 @@ config SAMV7_PWM1_CH0
bool "PWM1 Channel 0"
default n

if SAMV7_PWM1_CH0

config SAMV7_PWM1_CH0_COMP
bool "Use complementary output"
default n

endif

config SAMV7_PWM1_CH1
bool "PWM1 Channel 1"
default n

if SAMV7_PWM1_CH1

config SAMV7_PWM1_CH1_COMP
bool "Use complementary output"
default n

endif

config SAMV7_PWM1_CH2
bool "PWM1 Channel 2"
default n

if SAMV7_PWM1_CH2

config SAMV7_PWM1_CH2_COMP
bool "Use complementary output"
default n

endif

config SAMV7_PWM1_CH3
bool "PWM1 Channel 3"
default n

if SAMV7_PWM1_CH3

config SAMV7_PWM1_CH3_COMP
bool "Use complementary output"
default n

endif

endif

config SAMV7_QSPI
Expand Down
74 changes: 61 additions & 13 deletions arch/arm/src/samv7/sam_pwm.c
Expand Up @@ -73,7 +73,8 @@
struct sam_pwm_channel_s
{
uint8_t channel; /* Number of PWM module */
gpio_pinset_t pin; /* PWM output pin */
gpio_pinset_t pin_h; /* PWM H output pin */
gpio_pinset_t pin_l; /* PWM L output pin */
};

struct sam_pwm_s
Expand Down Expand Up @@ -114,25 +115,45 @@ static struct sam_pwm_channel_s g_pwm0_channels[] =
#ifdef CONFIG_SAMV7_PWM0_CH0
{
.channel = 0,
.pin = GPIO_PWMC0_H0,
.pin_h = GPIO_PWMC0_H0,
#ifdef CONFIG_SAMV7_PWM0_CH0_COMP
.pin_l = GPIO_PWMC0_L0,
#else
.pin_l = 0,
#endif
},
#endif
#ifdef CONFIG_SAMV7_PWM0_CH1
{
.channel = 1,
.pin = GPIO_PWMC0_H1,
.pin_h = GPIO_PWMC0_H1,
#ifdef CONFIG_SAMV7_PWM0_CH1_COMP
.pin_l = GPIO_PWMC0_L1,
#else
.pin_l = 0,
#endif
},
#endif
#ifdef CONFIG_SAMV7_PWM0_CH2
{
.channel = 2,
.pin = GPIO_PWMC0_H2,
.pin_h = GPIO_PWMC0_H2,
#ifdef CONFIG_SAMV7_PWM0_CH2_COMP
.pin_l = GPIO_PWMC0_L2,
#else
.pin_l = 0,
#endif
},
#endif
#ifdef CONFIG_SAMV7_PWM0_CH3
{
.channel = 3,
.pin = GPIO_PWMC0_H3,
.pin_h = GPIO_PWMC0_H3,
#ifdef CONFIG_SAMV7_PWM0_CH3_COMP
.pin_l = GPIO_PWMC0_L3,
#else
.pin_l = 0,
#endif
},
#endif
};
Expand All @@ -153,25 +174,45 @@ static struct sam_pwm_channel_s g_pwm1_channels[] =
#ifdef CONFIG_SAMV7_PWM1_CH0
{
.channel = 0,
.pin = GPIO_PWMC1_H0
.pin_h = GPIO_PWMC1_H0,
#ifdef CONFIG_SAMV7_PWM1_CH0_COMP
.pin_l = GPIO_PWMC1_L0,
#else
.pin_l = 0,
#endif
},
#endif
#ifdef CONFIG_SAMV7_PWM1_CH1
{
.channel = 1,
.pin = GPIO_PWMC1_H1
.pin_h = GPIO_PWMC1_H1,
#ifdef CONFIG_SAMV7_PWM1_CH1_COMP
.pin_l = GPIO_PWMC1_L1,
#else
.pin_l = 0,
#endif
},
#endif
#ifdef CONFIG_SAMV7_PWM1_CH2
{
.channel = 2,
.pin = GPIO_PWMC1_H2
.pin_h = GPIO_PWMC1_H2,
#ifdef CONFIG_SAMV7_PWM1_CH2_COMP
.pin_l = GPIO_PWMC1_L2,
#else
.pin_l = 0,
#endif
},
#endif
#ifdef CONFIG_SAMV7_PWM1_CH3
{
.channel = 3,
.pin = GPIO_PWMC1_H3
.pin_h = GPIO_PWMC1_H3,
#ifdef CONFIG_SAMV7_PWM1_CH3_COMP
.pin_l = GPIO_PWMC1_L3,
#else
.pin_l = 0,
#endif
},
#endif
}; /* CONFIG_SAMV7_PWM1 */
Expand Down Expand Up @@ -348,7 +389,8 @@ static void pwm_set_output(struct pwm_lowerhalf_s *dev, uint8_t channel,
static int pwm_setup(struct pwm_lowerhalf_s *dev)
{
struct sam_pwm_s *priv = (struct sam_pwm_s *)dev;
gpio_pinset_t pin = 0;
gpio_pinset_t pin_h = 0;
gpio_pinset_t pin_l = 0;
uint8_t channel;
uint32_t regval;

Expand All @@ -364,11 +406,17 @@ static int pwm_setup(struct pwm_lowerhalf_s *dev)

for (int i = 0; i < priv->channels_num; i++)
{
pin = priv->channels[i].pin;
pin_h = priv->channels[i].pin_h;
pin_l = priv->channels[i].pin_l;

if (pin_h != 0)
{
sam_configgpio(pin_h);
}

if (pin != 0)
if (pin_l != 0)
{
sam_configgpio(pin);
sam_configgpio(pin_l);
}

channel = priv->channels[i].channel;
Expand Down

0 comments on commit 3b3e23b

Please sign in to comment.