@@ -101,6 +101,8 @@ static int pwm_nxp_flexio_set_cycles(const struct device *dev,
101
101
FLEXIO_Type * flexio_base = (FLEXIO_Type * )(config -> flexio_base );
102
102
struct nxp_flexio_child * child = (struct nxp_flexio_child * )(config -> child );
103
103
enum pwm_nxp_flexio_polarity polarity ;
104
+ uint32_t duty_cycle = period_cycles - pulse_cycles ;
105
+ bool is_only_low_or_high = false;
104
106
105
107
/* Check received parameters for sanity */
106
108
if (channel >= config -> pulse_info -> pwm_pulse_channels ) {
@@ -130,18 +132,27 @@ static int pwm_nxp_flexio_set_cycles(const struct device *dev,
130
132
131
133
pwm_info = & config -> pulse_info -> pwm_info [channel ];
132
134
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 ) {
136
143
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;
137
148
}
138
149
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 ) {
141
153
timerConfig .timerMode = kFLEXIO_TimerModeDual8BitPWM ;
142
154
143
155
} else {
144
- timerConfig .timerOutput = kFLEXIO_TimerOutputZeroNotAffectedByReset ;
145
156
timerConfig .timerMode = kFLEXIO_TimerModeDual8BitPWMLow ;
146
157
}
147
158
@@ -151,6 +162,7 @@ static int pwm_nxp_flexio_set_cycles(const struct device *dev,
151
162
((uint8_t )(data -> period_cycles [channel ] - pulse_cycles - 1U )
152
163
<< FLEXIO_PWM_TIMCMP_CMP_UPPER_SHIFT );
153
164
165
+ timerConfig .timerOutput = kFLEXIO_TimerOutputZeroNotAffectedByReset ;
154
166
timerConfig .timerDecrement = pwm_info -> prescaler ;
155
167
timerConfig .timerStop = kFLEXIO_TimerStopBitDisabled ;
156
168
timerConfig .timerEnable = kFLEXIO_TimerEnabledAlways ;
0 commit comments