Fix unintended timer reset, style changes
This commit is contained in:
parent
61a2e4f94b
commit
cf0a4d208e
@ -34,7 +34,7 @@
|
|||||||
#define INDEX_EMPTY 0xFF
|
#define INDEX_EMPTY 0xFF
|
||||||
|
|
||||||
STATIC uint32_t reserved_timer_freq[LEDC_TIMER_MAX];
|
STATIC uint32_t reserved_timer_freq[LEDC_TIMER_MAX];
|
||||||
STATIC uint8_t reserved_channels[LEDC_CHANNEL_MAX] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
|
STATIC uint8_t reserved_channels[LEDC_CHANNEL_MAX];
|
||||||
STATIC bool never_reset_tim[LEDC_TIMER_MAX];
|
STATIC bool never_reset_tim[LEDC_TIMER_MAX];
|
||||||
STATIC bool never_reset_chan[LEDC_CHANNEL_MAX];
|
STATIC bool never_reset_chan[LEDC_CHANNEL_MAX];
|
||||||
|
|
||||||
@ -135,8 +135,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
|
|||||||
claim_pin(pin);
|
claim_pin(pin);
|
||||||
|
|
||||||
// Set initial duty
|
// Set initial duty
|
||||||
ledc_set_duty(LEDC_LOW_SPEED_MODE, self->chan_handle.channel, duty >> (16 - duty_bits));
|
common_hal_pulseio_pwmout_set_duty_cycle(self, duty);
|
||||||
ledc_update_duty(LEDC_LOW_SPEED_MODE, self->chan_handle.channel);
|
|
||||||
|
|
||||||
return PWMOUT_OK;
|
return PWMOUT_OK;
|
||||||
}
|
}
|
||||||
@ -160,7 +159,6 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ledc_stop(LEDC_LOW_SPEED_MODE, self->chan_handle.channel, 0);
|
ledc_stop(LEDC_LOW_SPEED_MODE, self->chan_handle.channel, 0);
|
||||||
ledc_timer_rst(LEDC_LOW_SPEED_MODE, self->tim_handle.timer_num);
|
|
||||||
// Search if any other channel is using the timer
|
// Search if any other channel is using the timer
|
||||||
bool taken = false;
|
bool taken = false;
|
||||||
for (size_t i =0; i < LEDC_CHANNEL_MAX; i++) {
|
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) {
|
|||||||
}
|
}
|
||||||
// Variable frequency means there's only one channel on the timer
|
// Variable frequency means there's only one channel on the timer
|
||||||
if (!taken || self->variable_frequency) {
|
if (!taken || self->variable_frequency) {
|
||||||
|
ledc_timer_rst(LEDC_LOW_SPEED_MODE, self->tim_handle.timer_num);
|
||||||
reserved_timer_freq[self->tim_handle.timer_num] = 0;
|
reserved_timer_freq[self->tim_handle.timer_num] = 0;
|
||||||
}
|
}
|
||||||
reset_pin_number(self->pin_number);
|
reset_pin_number(self->pin_number);
|
||||||
@ -178,7 +177,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self, uint16_t duty) {
|
void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self, uint16_t duty) {
|
||||||
ledc_set_duty(LEDC_LOW_SPEED_MODE, self->chan_handle.channel, duty >> (16 - self->duty_resolution));
|
ledc_set_duty(LEDC_LOW_SPEED_MODE, self->chan_handle.channel, duty >> (16 - self->duty_resolution));
|
||||||
ledc_update_duty(LEDC_LOW_SPEED_MODE, self->chan_handle.channel);
|
ledc_update_duty(LEDC_LOW_SPEED_MODE, self->chan_handle.channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user