Merge pull request #4702 from rsbohn/patch-1

esp32-s2: Don't set PWMOut frequency to 0
This commit is contained in:
Scott Shawcroft 2021-05-03 11:01:59 -07:00 committed by GitHub
commit 678279720f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -63,6 +63,12 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
uint16_t duty,
uint32_t frequency,
bool variable_frequency) {
// check the frequency (avoid divide by zero below)
if (frequency == 0) {
return PWMOUT_INVALID_FREQUENCY;
}
// Calculate duty cycle
uint32_t duty_bits = 0;
uint32_t interval = LEDC_APB_CLK_HZ / frequency;