Skip to content

Commit cedeea4

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 cedeea4

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

drivers/pwm/pwm_nxp_flexio.c

Lines changed: 18 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,27 @@ 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+
} else if (duty_cycle == period_cycles && !pulse_cycles) {
146+
polarity = FLEXIO_PWM_ACTIVE_HIGH;
147+
is_only_low_or_high = true;
137148
}
138149

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

143155
} else {
144-
timerConfig.timerOutput = kFLEXIO_TimerOutputZeroNotAffectedByReset;
145156
timerConfig.timerMode = kFLEXIO_TimerModeDual8BitPWMLow;
146157
}
147158

@@ -151,6 +162,7 @@ static int pwm_nxp_flexio_set_cycles(const struct device *dev,
151162
((uint8_t)(data->period_cycles[channel] - pulse_cycles - 1U)
152163
<< FLEXIO_PWM_TIMCMP_CMP_UPPER_SHIFT);
153164

165+
timerConfig.timerOutput = kFLEXIO_TimerOutputZeroNotAffectedByReset;
154166
timerConfig.timerDecrement = pwm_info->prescaler;
155167
timerConfig.timerStop = kFLEXIO_TimerStopBitDisabled;
156168
timerConfig.timerEnable = kFLEXIO_TimerEnabledAlways;

0 commit comments

Comments
 (0)