@@ -39,13 +39,17 @@ STATIC bool never_reset_chan[LEDC_CHANNEL_MAX];
3939
4040void pwmout_reset (void ) {
4141 for (size_t i = 0 ; i < LEDC_CHANNEL_MAX ; i ++ ) {
42- ledc_stop (LEDC_LOW_SPEED_MODE , i , 0 );
42+ if (reserved_channels [i ] != INDEX_EMPTY ) {
43+ ledc_stop (LEDC_LOW_SPEED_MODE , i , 0 );
44+ }
4345 if (!never_reset_chan [i ]) {
4446 reserved_channels [i ] = INDEX_EMPTY ;
4547 }
4648 }
4749 for (size_t i = 0 ; i < LEDC_TIMER_MAX ; i ++ ) {
48- ledc_timer_rst (LEDC_LOW_SPEED_MODE , i );
50+ if (reserved_timer_freq [i ]) {
51+ ledc_timer_rst (LEDC_LOW_SPEED_MODE , i );
52+ }
4953 if (!never_reset_tim [i ]) {
5054 reserved_timer_freq [i ] = 0 ;
5155 }
@@ -157,7 +161,10 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
157161 if (common_hal_pulseio_pwmout_deinited (self )) {
158162 return ;
159163 }
160- ledc_stop (LEDC_LOW_SPEED_MODE , self -> chan_handle .channel , 0 );
164+
165+ if (reserved_channels [self -> chan_handle .channel ] != INDEX_EMPTY ) {
166+ ledc_stop (LEDC_LOW_SPEED_MODE , self -> chan_handle .channel , 0 );
167+ }
161168 // Search if any other channel is using the timer
162169 bool taken = false;
163170 for (size_t i = 0 ; i < LEDC_CHANNEL_MAX ; i ++ ) {
@@ -167,7 +174,9 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
167174 }
168175 // Variable frequency means there's only one channel on the timer
169176 if (!taken || self -> variable_frequency ) {
170- ledc_timer_rst (LEDC_LOW_SPEED_MODE , self -> tim_handle .timer_num );
177+ if (reserved_timer_freq [self -> tim_handle .timer_num ] != 0 ) {
178+ ledc_timer_rst (LEDC_LOW_SPEED_MODE , self -> tim_handle .timer_num );
179+ }
171180 reserved_timer_freq [self -> tim_handle .timer_num ] = 0 ;
172181 }
173182 reset_pin_number (self -> pin_number );
0 commit comments