@@ -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,28 @@ 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
+ }
146
+ else if (duty_cycle == period_cycles && !pulse_cycles ) {
147
+ polarity = FLEXIO_PWM_ACTIVE_HIGH ;
148
+ is_only_low_or_high = true;
137
149
}
138
150
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 ) {
141
154
timerConfig .timerMode = kFLEXIO_TimerModeDual8BitPWM ;
142
155
143
156
} else {
144
- timerConfig .timerOutput = kFLEXIO_TimerOutputZeroNotAffectedByReset ;
145
157
timerConfig .timerMode = kFLEXIO_TimerModeDual8BitPWMLow ;
146
158
}
147
159
@@ -151,6 +163,7 @@ static int pwm_nxp_flexio_set_cycles(const struct device *dev,
151
163
((uint8_t )(data -> period_cycles [channel ] - pulse_cycles - 1U )
152
164
<< FLEXIO_PWM_TIMCMP_CMP_UPPER_SHIFT );
153
165
166
+ timerConfig .timerOutput = kFLEXIO_TimerOutputZeroNotAffectedByReset ;
154
167
timerConfig .timerDecrement = pwm_info -> prescaler ;
155
168
timerConfig .timerStop = kFLEXIO_TimerStopBitDisabled ;
156
169
timerConfig .timerEnable = kFLEXIO_TimerEnabledAlways ;
0 commit comments