@@ -166,7 +166,20 @@ void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) {
166166
167167void common_hal_pwmio_pwmout_reset_ok (pwmio_pwmout_obj_t * self ) {
168168 never_reset_tim [self -> tim_handle .timer_num ] = false;
169- never_reset_chan [self -> chan_handle .channel ] = 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+ }
170183}
171184
172185bool common_hal_pwmio_pwmout_deinited (pwmio_pwmout_obj_t * self ) {
@@ -182,11 +195,13 @@ void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t *self) {
182195 ledc_stop (LEDC_LOW_SPEED_MODE , self -> chan_handle .channel , 0 );
183196 }
184197 reserved_channels [self -> chan_handle .channel ] = INDEX_EMPTY ;
198+ never_reset_chan [self -> chan_handle .channel ] = false;
185199 // Search if any other channel is using the timer
186200 bool taken = false;
187201 for (size_t i = 0 ; i < LEDC_CHANNEL_MAX ; i ++ ) {
188202 if (reserved_channels [i ] == self -> tim_handle .timer_num ) {
189203 taken = true;
204+ break ;
190205 }
191206 }
192207 // Variable frequency means there's only one channel on the timer
@@ -195,6 +210,7 @@ void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t *self) {
195210 reserved_timer_freq [self -> tim_handle .timer_num ] = 0 ;
196211 // if timer isn't varfreq this will be off aleady
197212 varfreq_timers [self -> tim_handle .timer_num ] = false;
213+ never_reset_tim [self -> tim_handle .timer_num ] = false;
198214 }
199215 common_hal_reset_pin (self -> pin );
200216 self -> deinited = true;
0 commit comments