drivers: pwm: mcux_ftm: add support for inverted polarity pwm signals
Add support for specifying the PWM signal polarity through flags to the NXP Kinetis FlexTimer (FTM) PWM driver. Prior to this change the FTM PWM driver always produced inverted polarity (active-low) PWM signals. Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
parent
eafb9b17b6
commit
e2346cf6a2
1 changed files with 11 additions and 8 deletions
|
@ -52,16 +52,17 @@ static int mcux_ftm_pin_set(struct device *dev, u32_t pwm,
|
|||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (flags) {
|
||||
/* PWM polarity not supported (yet?) */
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
duty_cycle = pulse_cycles * 100U / period_cycles;
|
||||
data->channel[pwm].dutyCyclePercent = duty_cycle;
|
||||
|
||||
LOG_DBG("pulse_cycles=%d, period_cycles=%d, duty_cycle=%d",
|
||||
pulse_cycles, period_cycles, duty_cycle);
|
||||
if ((flags & PWM_POLARITY_INVERTED) == 0) {
|
||||
data->channel[pwm].level = kFTM_HighTrue;
|
||||
} else {
|
||||
data->channel[pwm].level = kFTM_LowTrue;
|
||||
}
|
||||
|
||||
LOG_DBG("pulse_cycles=%d, period_cycles=%d, duty_cycle=%d, flags=%d",
|
||||
pulse_cycles, period_cycles, duty_cycle, flags);
|
||||
|
||||
if (period_cycles != data->period_cycles) {
|
||||
u32_t pwm_freq;
|
||||
|
@ -104,6 +105,8 @@ static int mcux_ftm_pin_set(struct device *dev, u32_t pwm,
|
|||
} else {
|
||||
FTM_UpdatePwmDutycycle(config->base, pwm, config->mode,
|
||||
duty_cycle);
|
||||
FTM_UpdateChnlEdgeLevelSelect(config->base, pwm,
|
||||
data->channel[pwm].level);
|
||||
FTM_SetSoftwareTrigger(config->base, true);
|
||||
}
|
||||
|
||||
|
@ -149,7 +152,7 @@ static int mcux_ftm_init(struct device *dev)
|
|||
|
||||
for (i = 0; i < config->channel_count; i++) {
|
||||
channel->chnlNumber = i;
|
||||
channel->level = kFTM_LowTrue;
|
||||
channel->level = kFTM_NoPwmSignal;
|
||||
channel->dutyCyclePercent = 0;
|
||||
channel->firstEdgeDelayPercent = 0;
|
||||
channel++;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue