esp32/machine_pwm: Don't use LEDC_USE_REF_TICK on ESP32-C3 variants.

Because it's not supported by this particular MCU (since IDF v4.4.2).

Signed-off-by: Damien George <damien@micropython.org>
pull/9412/head
Damien George 2022-09-25 22:12:29 +10:00
rodzic 3abcfb9aec
commit dd9dcb594c
1 zmienionych plików z 6 dodań i 0 usunięć

Wyświetl plik

@ -97,8 +97,10 @@ STATIC ledc_timer_config_t timers[PWM_TIMER_MAX];
// How much to shift from the HIGHEST_PWM_RES duty resolution to the user interface duty resolution UI_RES_16_BIT
#define UI_RES_SHIFT (UI_RES_16_BIT - HIGHEST_PWM_RES) // 0 for ESP32, 2 for S2, S3, C3
#if SOC_LEDC_SUPPORT_REF_TICK
// If the PWM frequency is less than EMPIRIC_FREQ, then LEDC_REF_CLK_HZ(1 MHz) source is used, else LEDC_APB_CLK_HZ(80 MHz) source is used
#define EMPIRIC_FREQ (10) // Hz
#endif
// Config of timer upon which we run all PWM'ed GPIO pins
STATIC bool pwm_inited = false;
@ -208,9 +210,11 @@ STATIC void set_freq(machine_pwm_obj_t *self, unsigned int freq, ledc_timer_conf
if (freq != timer->freq_hz) {
// Find the highest bit resolution for the requested frequency
unsigned int i = LEDC_APB_CLK_HZ; // 80 MHz
#if SOC_LEDC_SUPPORT_REF_TICK
if (freq < EMPIRIC_FREQ) {
i = LEDC_REF_CLK_HZ; // 1 MHz
}
#endif
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
// original code
@ -243,9 +247,11 @@ STATIC void set_freq(machine_pwm_obj_t *self, unsigned int freq, ledc_timer_conf
timer->duty_resolution = res;
timer->freq_hz = freq;
timer->clk_cfg = LEDC_USE_APB_CLK;
#if SOC_LEDC_SUPPORT_REF_TICK
if (freq < EMPIRIC_FREQ) {
timer->clk_cfg = LEDC_USE_REF_TICK;
}
#endif
// Set frequency
esp_err_t err = ledc_timer_config(timer);