34
34
#define INDEX_EMPTY 0xFF
35
35
36
36
STATIC uint32_t reserved_timer_freq [LEDC_TIMER_MAX ];
37
- STATIC uint8_t reserved_channels [LEDC_CHANNEL_MAX ] = { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } ;
37
+ STATIC uint8_t reserved_channels [LEDC_CHANNEL_MAX ];
38
38
STATIC bool never_reset_tim [LEDC_TIMER_MAX ];
39
39
STATIC bool never_reset_chan [LEDC_CHANNEL_MAX ];
40
40
@@ -135,8 +135,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
135
135
claim_pin (pin );
136
136
137
137
// Set initial duty
138
- ledc_set_duty (LEDC_LOW_SPEED_MODE , self -> chan_handle .channel , duty >> (16 - duty_bits ));
139
- ledc_update_duty (LEDC_LOW_SPEED_MODE , self -> chan_handle .channel );
138
+ common_hal_pulseio_pwmout_set_duty_cycle (self , duty );
140
139
141
140
return PWMOUT_OK ;
142
141
}
@@ -160,7 +159,6 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
160
159
return ;
161
160
}
162
161
ledc_stop (LEDC_LOW_SPEED_MODE , self -> chan_handle .channel , 0 );
163
- ledc_timer_rst (LEDC_LOW_SPEED_MODE , self -> tim_handle .timer_num );
164
162
// Search if any other channel is using the timer
165
163
bool taken = false;
166
164
for (size_t i = 0 ; i < LEDC_CHANNEL_MAX ; i ++ ) {
@@ -170,6 +168,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
170
168
}
171
169
// Variable frequency means there's only one channel on the timer
172
170
if (!taken || self -> variable_frequency ) {
171
+ ledc_timer_rst (LEDC_LOW_SPEED_MODE , self -> tim_handle .timer_num );
173
172
reserved_timer_freq [self -> tim_handle .timer_num ] = 0 ;
174
173
}
175
174
reset_pin_number (self -> pin_number );
@@ -178,7 +177,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
178
177
}
179
178
180
179
void common_hal_pulseio_pwmout_set_duty_cycle (pulseio_pwmout_obj_t * self , uint16_t duty ) {
181
- ledc_set_duty (LEDC_LOW_SPEED_MODE , self -> chan_handle .channel , duty >> (16 - self -> duty_resolution ));
180
+ ledc_set_duty (LEDC_LOW_SPEED_MODE , self -> chan_handle .channel , duty >> (16 - self -> duty_resolution ));
182
181
ledc_update_duty (LEDC_LOW_SPEED_MODE , self -> chan_handle .channel );
183
182
}
184
183
0 commit comments