Skip to content

Commit d163247

Browse files
committed
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. Signed-off-by: Emilio Benavente <emilio.benavente@nxp.com>
1 parent da358aa commit d163247

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

drivers/pwm/pwm_nxp_flexio.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ static int pwm_nxp_flexio_set_cycles(const struct device *dev,
101101
FLEXIO_Type *flexio_base = (FLEXIO_Type *)(config->flexio_base);
102102
struct nxp_flexio_child *child = (struct nxp_flexio_child *)(config->child);
103103
enum pwm_nxp_flexio_polarity polarity;
104+
uint32_t duty_cycle = period_cycles - pulse_cycles;
105+
bool is_only_low_or_high = false;
104106

105107
/* Check received parameters for sanity */
106108
if (channel >= config->pulse_info->pwm_pulse_channels) {
@@ -130,18 +132,28 @@ static int pwm_nxp_flexio_set_cycles(const struct device *dev,
130132

131133
pwm_info = &config->pulse_info->pwm_info[channel];
132134

133-
if ((flags & PWM_POLARITY_INVERTED) == 0) {
134-
polarity = FLEXIO_PWM_ACTIVE_HIGH;
135-
} else {
135+
polarity = (flags & PWM_POLARITY_INVERTED) == 0 ?
136+
FLEXIO_PWM_ACTIVE_HIGH : FLEXIO_PWM_ACTIVE_LOW;
137+
138+
/*
139+
* Checking to see if duty cycle is 0% or 100%
140+
* If so manually keep the GPIO HIGH or LOW.
141+
*/
142+
if (period_cycles == pulse_cycles) {
136143
polarity = FLEXIO_PWM_ACTIVE_LOW;
144+
is_only_low_or_high = true;
145+
}
146+
else if (duty_cycle == period_cycles && !pulse_cycles) {
147+
polarity = FLEXIO_PWM_ACTIVE_HIGH;
148+
is_only_low_or_high = true;
137149
}
138150

139-
if (polarity == FLEXIO_PWM_ACTIVE_HIGH) {
140-
timerConfig.timerOutput = kFLEXIO_TimerOutputOneNotAffectedByReset;
151+
if (is_only_low_or_high) {
152+
timerConfig.timerMode = kFLEXIO_TimerModeDisabled;
153+
} else if (polarity == FLEXIO_PWM_ACTIVE_HIGH) {
141154
timerConfig.timerMode = kFLEXIO_TimerModeDual8BitPWM;
142155

143156
} else {
144-
timerConfig.timerOutput = kFLEXIO_TimerOutputZeroNotAffectedByReset;
145157
timerConfig.timerMode = kFLEXIO_TimerModeDual8BitPWMLow;
146158
}
147159

@@ -151,6 +163,7 @@ static int pwm_nxp_flexio_set_cycles(const struct device *dev,
151163
((uint8_t)(data->period_cycles[channel] - pulse_cycles - 1U)
152164
<< FLEXIO_PWM_TIMCMP_CMP_UPPER_SHIFT);
153165

166+
timerConfig.timerOutput = kFLEXIO_TimerOutputZeroNotAffectedByReset;
154167
timerConfig.timerDecrement = pwm_info->prescaler;
155168
timerConfig.timerStop = kFLEXIO_TimerStopBitDisabled;
156169
timerConfig.timerEnable = kFLEXIO_TimerEnabledAlways;

0 commit comments

Comments
 (0)