@@ -164,24 +164,6 @@ void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) {
164164 never_reset_pin_number (self -> pin -> number );
165165}
166166
167- void common_hal_pwmio_pwmout_reset_ok (pwmio_pwmout_obj_t * self ) {
168- never_reset_tim [self -> tim_handle .timer_num ] = false;
169- // Search if any other channel is using the timer and is never reset.
170- // Otherwise, we clear never_reset for the timer as well.
171- bool other_never_reset = false;
172- for (size_t i = 0 ; i < LEDC_CHANNEL_MAX ; i ++ ) {
173- if (i != self -> chan_handle .channel &&
174- reserved_channels [i ] == self -> tim_handle .timer_num &&
175- never_reset_chan [i ]) {
176- other_never_reset = true;
177- break ;
178- }
179- }
180- if (!other_never_reset ) {
181- never_reset_chan [self -> chan_handle .channel ] = false;
182- }
183- }
184-
185167bool common_hal_pwmio_pwmout_deinited (pwmio_pwmout_obj_t * self ) {
186168 return self -> deinited == true;
187169}
@@ -196,14 +178,21 @@ void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t *self) {
196178 }
197179 reserved_channels [self -> chan_handle .channel ] = INDEX_EMPTY ;
198180 never_reset_chan [self -> chan_handle .channel ] = false;
181+
199182 // Search if any other channel is using the timer
200183 bool taken = false;
184+ bool other_never_reset = false;
201185 for (size_t i = 0 ; i < LEDC_CHANNEL_MAX ; i ++ ) {
202186 if (reserved_channels [i ] == self -> tim_handle .timer_num ) {
203187 taken = true;
188+ other_never_reset = never_reset_chan [i ];
204189 break ;
205190 }
206191 }
192+ // Clear the timer's never reset if the other channel isn't never reset.
193+ if (!other_never_reset ) {
194+ never_reset_tim [self -> tim_handle .timer_num ] = false;
195+ }
207196 // Variable frequency means there's only one channel on the timer
208197 if (!taken || self -> variable_frequency ) {
209198 ledc_timer_rst (LEDC_LOW_SPEED_MODE , self -> tim_handle .timer_num );
0 commit comments