@@ -166,7 +166,20 @@ void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) {
166
166
167
167
void common_hal_pwmio_pwmout_reset_ok (pwmio_pwmout_obj_t * self ) {
168
168
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
+ }
170
183
}
171
184
172
185
bool 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) {
182
195
ledc_stop (LEDC_LOW_SPEED_MODE , self -> chan_handle .channel , 0 );
183
196
}
184
197
reserved_channels [self -> chan_handle .channel ] = INDEX_EMPTY ;
198
+ never_reset_chan [self -> chan_handle .channel ] = false;
185
199
// Search if any other channel is using the timer
186
200
bool taken = false;
187
201
for (size_t i = 0 ; i < LEDC_CHANNEL_MAX ; i ++ ) {
188
202
if (reserved_channels [i ] == self -> tim_handle .timer_num ) {
189
203
taken = true;
204
+ break ;
190
205
}
191
206
}
192
207
// 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) {
195
210
reserved_timer_freq [self -> tim_handle .timer_num ] = 0 ;
196
211
// if timer isn't varfreq this will be off aleady
197
212
varfreq_timers [self -> tim_handle .timer_num ] = false;
213
+ never_reset_tim [self -> tim_handle .timer_num ] = false;
198
214
}
199
215
common_hal_reset_pin (self -> pin );
200
216
self -> deinited = true;
0 commit comments