8000 Fix unintended timer reset, style changes · ansonhex/circuitpython@cf0a4d2 · GitHub
[go: up one dir, main page]

Skip to content

Commit cf0a4d2

Browse files
committed
Fix unintended timer reset, style changes
1 parent 61a2e4f commit cf0a4d2

File tree

1 file changed

+4
-5
lines changed
  • ports/esp32s2/common-hal/pulseio

1 file changed

+4
-5
lines changed

ports/esp32s2/common-hal/pulseio/PWMOut.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#define INDEX_EMPTY 0xFF
3535

3636
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];
3838
STATIC bool never_reset_tim[LEDC_TIMER_MAX];
3939
STATIC bool never_reset_chan[LEDC_CHANNEL_MAX];
4040

@@ -135,8 +135,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
135135
claim_pin(pin);
136136

137137
// 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);
140139

141140
return PWMOUT_OK;
142141
}
@@ -160,7 +159,6 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
160159
return;
161160
}
162161
ledc_stop(LEDC_LOW_SPEED_MODE, self->chan_handle.channel, 0);
163-
ledc_timer_rst(LEDC_LOW_SPEED_MODE, self->tim_handle.timer_num);
164162
// Search if any other channel is using the timer
165163
bool taken = false;
166164
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) {
170168
}
171169
// Variable frequency means there's only one channel on the timer
172170
if (!taken || self->variable_frequency) {
171+
ledc_timer_rst(LEDC_LOW_SPEED_MODE, self->tim_handle.timer_num);
173172
reserved_timer_freq[self->tim_handle.timer_num] = 0;
174173
}
175174
reset_pin_number(self->pin_number);
@@ -178,7 +177,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
178177
}
179178

180179
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));
182181
ledc_update_duty(LEDC_LOW_SPEED_MODE, self->chan_handle.channel);
183182
}
184183

0 commit comments

Comments
 (0)
0