Skip to content

Commit 8467f55

Browse files
EmilioCBencfriedt
authored andcommitted
drviers: pwm: Update flexio pwm update duty cycle
Updated the nxp flexio pwm driver to account for when the duty cycle is 100% or 0%. We switch off the counter of the flexio and manually set the GPIO High or Low. Otherwise Flexio Peripheral with default to a 50% duty cycle behavior. Factored out timerOutput variable. Signed-off-by: Emilio Benavente <[email protected]>
1 parent dece779 commit 8467f55

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

drivers/pwm/pwm_nxp_flexio.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,23 @@ static int pwm_nxp_flexio_set_cycles(const struct device *dev,
130130

131131
pwm_info = &config->pulse_info->pwm_info[channel];
132132

133-
if ((flags & PWM_POLARITY_INVERTED) == 0) {
134-
polarity = FLEXIO_PWM_ACTIVE_HIGH;
135-
} else {
133+
polarity = (flags & PWM_POLARITY_INVERTED) == 0 ?
134+
FLEXIO_PWM_ACTIVE_HIGH : FLEXIO_PWM_ACTIVE_LOW;
135+
136+
/*
137+
* Adjusting the timer mode to either add modulation
138+
* or pull the GPIO pin HIGH/LOW to simulate
139+
* 0% or 100% duty cycle.
140+
*/
141+
if (period_cycles == pulse_cycles) {
136142
polarity = FLEXIO_PWM_ACTIVE_LOW;
137-
}
138-
139-
if (polarity == FLEXIO_PWM_ACTIVE_HIGH) {
140-
timerConfig.timerOutput = kFLEXIO_TimerOutputOneNotAffectedByReset;
143+
timerConfig.timerMode = kFLEXIO_TimerModeDisabled;
144+
} else if (period_cycles && pulse_cycles == 0) {
145+
polarity = FLEXIO_PWM_ACTIVE_HIGH;
146+
timerConfig.timerMode = kFLEXIO_TimerModeDisabled;
147+
} else if (polarity == FLEXIO_PWM_ACTIVE_HIGH) {
141148
timerConfig.timerMode = kFLEXIO_TimerModeDual8BitPWM;
142-
143149
} else {
144-
timerConfig.timerOutput = kFLEXIO_TimerOutputZeroNotAffectedByReset;
145150
timerConfig.timerMode = kFLEXIO_TimerModeDual8BitPWMLow;
146151
}
147152

@@ -151,6 +156,7 @@ static int pwm_nxp_flexio_set_cycles(const struct device *dev,
151156
((uint8_t)(data->period_cycles[channel] - pulse_cycles - 1U)
152157
<< FLEXIO_PWM_TIMCMP_CMP_UPPER_SHIFT);
153158

159+
timerConfig.timerOutput = kFLEXIO_TimerOutputZeroNotAffectedByReset;
154160
timerConfig.timerDecrement = pwm_info->prescaler;
155161
timerConfig.timerStop = kFLEXIO_TimerStopBitDisabled;
156162
timerConfig.timerEnable = kFLEXIO_TimerEnabledAlways;

0 commit comments

Comments
 (0)