stm32_pwm: fixes for PULSECOUNT support
1. generate an indefinite number of pulses when info->count = 0 2. timers that don't support pulse-count shouldn't use pulse-count logic
This commit is contained in:
parent
873293cc3f
commit
7cb7fe3f38
@ -410,9 +410,8 @@ struct stm32_pwmtimer_s
|
||||
uint8_t prev; /* The previous value of the RCR (pre-loaded) */
|
||||
uint8_t curr; /* The current value of the RCR (pre-loaded) */
|
||||
uint32_t count; /* Remaining pulse count */
|
||||
#else
|
||||
uint32_t frequency; /* Current frequency setting */
|
||||
#endif
|
||||
uint32_t frequency; /* Current frequency setting */
|
||||
uint32_t base; /* The base address of the timer */
|
||||
uint32_t pclk; /* The frequency of the peripheral
|
||||
* clock that drives the timer module
|
||||
@ -488,10 +487,9 @@ static int pwm_configure(FAR struct pwm_lowerhalf_s *dev);
|
||||
#ifdef CONFIG_PWM_PULSECOUNT
|
||||
static int pwm_pulsecount_timer(FAR struct pwm_lowerhalf_s *dev,
|
||||
FAR const struct pwm_info_s *info);
|
||||
#else
|
||||
#endif
|
||||
static int pwm_timer(FAR struct pwm_lowerhalf_s *dev,
|
||||
FAR const struct pwm_info_s *info);
|
||||
#endif
|
||||
#ifdef HAVE_PWM_INTERRUPT
|
||||
static int pwm_interrupt(FAR struct pwm_lowerhalf_s *dev);
|
||||
# ifdef CONFIG_STM32_TIM1_PWM
|
||||
@ -509,13 +507,12 @@ static int pwm_setup(FAR struct pwm_lowerhalf_s *dev);
|
||||
static int pwm_shutdown(FAR struct pwm_lowerhalf_s *dev);
|
||||
|
||||
#ifdef CONFIG_PWM_PULSECOUNT
|
||||
static int pwm_start(FAR struct pwm_lowerhalf_s *dev,
|
||||
FAR const struct pwm_info_s *info,
|
||||
FAR void *handle);
|
||||
#else
|
||||
static int pwm_start_pulsecount(FAR struct pwm_lowerhalf_s *dev,
|
||||
FAR const struct pwm_info_s *info,
|
||||
FAR void *handle);
|
||||
#endif
|
||||
static int pwm_start(FAR struct pwm_lowerhalf_s *dev,
|
||||
FAR const struct pwm_info_s *info);
|
||||
#endif
|
||||
|
||||
static int pwm_stop(FAR struct pwm_lowerhalf_s *dev);
|
||||
static int pwm_ioctl(FAR struct pwm_lowerhalf_s *dev,
|
||||
@ -533,7 +530,11 @@ static const struct pwm_ops_s g_pwmops =
|
||||
{
|
||||
.setup = pwm_setup,
|
||||
.shutdown = pwm_shutdown,
|
||||
#ifdef CONFIG_PWM_PULSECOUNT
|
||||
.start = pwm_start_pulsecount,
|
||||
#else
|
||||
.start = pwm_start,
|
||||
#endif
|
||||
.stop = pwm_stop,
|
||||
.ioctl = pwm_ioctl,
|
||||
};
|
||||
@ -3376,7 +3377,6 @@ static int pwm_pulsecount_timer(FAR struct pwm_lowerhalf_s *dev,
|
||||
FAR struct stm32_pwmtimer_s *priv = (FAR struct stm32_pwmtimer_s *)dev;
|
||||
ub16_t duty = 0;
|
||||
uint8_t channel = 0;
|
||||
uint32_t mode = 0;
|
||||
uint16_t outputs = 0;
|
||||
int ret = OK;
|
||||
|
||||
@ -3394,7 +3394,6 @@ static int pwm_pulsecount_timer(FAR struct pwm_lowerhalf_s *dev,
|
||||
|
||||
duty = info->duty;
|
||||
channel = priv->channels[0].channel;
|
||||
mode = priv->channels[0].mode;
|
||||
|
||||
/* Disable all interrupts and DMA requests, clear all pending status */
|
||||
|
||||
@ -3503,7 +3502,7 @@ errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
#else /* !CONFIG_PWM_PULSECOUNT */
|
||||
#endif /* CONFIG_PWM_PULSECOUNT */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pwm_configure
|
||||
@ -3795,7 +3794,6 @@ static int pwm_timer(FAR struct pwm_lowerhalf_s *dev,
|
||||
errout:
|
||||
return ret;
|
||||
}
|
||||
#endif /* CONFIG_PWM_PULSECOUNT */
|
||||
|
||||
#ifdef HAVE_PWM_INTERRUPT
|
||||
|
||||
@ -4230,10 +4228,16 @@ static int pwm_setup(FAR struct pwm_lowerhalf_s *dev)
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_PWM_PULSECOUNT
|
||||
ret = pwm_pulsecount_configure(dev);
|
||||
#else
|
||||
ret = pwm_configure(dev);
|
||||
if (priv->timtype == TIMTYPE_ADVANCED)
|
||||
{
|
||||
ret = pwm_pulsecount_configure(dev);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
ret = pwm_configure(dev);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
pwmerr("failed to configure PWM %d\n", priv->timid);
|
||||
@ -4331,12 +4335,19 @@ errout:
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_PWM_PULSECOUNT
|
||||
static int pwm_start(FAR struct pwm_lowerhalf_s *dev,
|
||||
FAR const struct pwm_info_s *info,
|
||||
FAR void *handle)
|
||||
static int pwm_start_pulsecount(FAR struct pwm_lowerhalf_s *dev,
|
||||
FAR const struct pwm_info_s *info,
|
||||
FAR void *handle)
|
||||
{
|
||||
FAR struct stm32_pwmtimer_s *priv = (FAR struct stm32_pwmtimer_s *)dev;
|
||||
|
||||
/* Generate an indefinite number of pulses */
|
||||
|
||||
if (info->count == 0)
|
||||
{
|
||||
return pwm_start(dev, info);
|
||||
}
|
||||
|
||||
/* Check if a pulsecount has been selected */
|
||||
|
||||
if (info->count > 0)
|
||||
@ -4361,7 +4372,8 @@ static int pwm_start(FAR struct pwm_lowerhalf_s *dev,
|
||||
|
||||
return pwm_pulsecount_timer(dev, info);
|
||||
}
|
||||
#else /* !CONFIG_PWM_PULSECOUNT */
|
||||
#endif /* CONFIG_PWM_PULSECOUNT */
|
||||
|
||||
static int pwm_start(FAR struct pwm_lowerhalf_s *dev,
|
||||
FAR const struct pwm_info_s *info)
|
||||
{
|
||||
@ -4403,7 +4415,6 @@ static int pwm_start(FAR struct pwm_lowerhalf_s *dev,
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* CONFIG_PWM_PULSECOUNT */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pwm_stop
|
||||
@ -4587,11 +4598,9 @@ static int pwm_stop(FAR struct pwm_lowerhalf_s *dev)
|
||||
|
||||
flags = enter_critical_section();
|
||||
|
||||
#ifndef CONFIG_PWM_PULSECOUNT
|
||||
/* Stopped so frequency is zero */
|
||||
|
||||
priv->frequency = 0;
|
||||
#endif
|
||||
|
||||
/* Disable further interrupts and stop the timer */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user