From f2791fbc947f6717b970317febbff0080f7f7fbf Mon Sep 17 00:00:00 2001 From: Ihor Nehrutsa Date: Thu, 14 Nov 2024 09:36:38 +0200 Subject: [PATCH] Update ledc_check.c --- .../ledc/ledc_check/main/ledc_check.c | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/examples/peripherals/ledc/ledc_check/main/ledc_check.c b/examples/peripherals/ledc/ledc_check/main/ledc_check.c index 3243a0ebcdfd..1a11ca4e489b 100755 --- a/examples/peripherals/ledc/ledc_check/main/ledc_check.c +++ b/examples/peripherals/ledc/ledc_check/main/ledc_check.c @@ -53,7 +53,7 @@ static void check(uint32_t freq) uint32_t src_clk_freq; ESP_ERROR_CHECK(esp_clk_tree_src_get_freq_hz(LEDC_USE_APB_CLK, ESP_CLK_TREE_SRC_FREQ_PRECISION_EXACT, &src_clk_freq)); // Prepare and then apply the LEDC PWM timer configuration - timer = (ledc_timer_config_t){ + timer = (ledc_timer_config_t) { .speed_mode = LEDC_MODE, .timer_num = LEDC_TIMER, .duty_resolution = ledc_find_suitable_duty_resolution(src_clk_freq, freq), @@ -63,7 +63,7 @@ static void check(uint32_t freq) ESP_ERROR_CHECK(ledc_timer_config(&timer)); // Prepare and then apply the LEDC PWM channel configuration - channel = (ledc_channel_config_t){ + channel = (ledc_channel_config_t) { .speed_mode = LEDC_MODE, .channel = LEDC_CHANNEL, .timer_sel = LEDC_TIMER, @@ -74,7 +74,7 @@ static void check(uint32_t freq) }; ESP_ERROR_CHECK(ledc_channel_config(&channel)); - #if CHECK_SET +#if CHECK_SET uint32_t divider = ledc_calculate_divisor(src_clk_freq, timer.freq_hz, 0x1 << timer.duty_resolution); ESP_ERROR_CHECK(ledc_timer_set(timer.speed_mode, timer.timer_num, divider, timer.duty_resolution, timer.clk_cfg)); @@ -82,7 +82,7 @@ static void check(uint32_t freq) ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, LEDC_DUTY)); // Update duty to apply the new value ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL)); - #endif +#endif vTaskDelay((2000 / freq) / portTICK_PERIOD_MS); @@ -94,9 +94,9 @@ static void check(uint32_t freq) //if ((timer.freq_hz != get_freq) || (channel.duty != get_duty)) { if ((freq_percent >= FREQ_PERCENT) || (duty_percent >= DUTY_PERCENT)) { printf("%6.2f%% timer.freq_hz=%lu, get_freq=%lu, \t\t %6.2f%% channel.duty=%lu, get_duty=%lu \t\t timer.duty_resolution=%u\n", - freq_percent, timer.freq_hz, get_freq, - duty_percent, channel.duty, get_duty, - timer.duty_resolution); + freq_percent, timer.freq_hz, get_freq, + duty_percent, channel.duty, get_duty, + timer.duty_resolution); } else { printf("\n"); } @@ -104,23 +104,24 @@ static void check(uint32_t freq) void app_main(void) { uint32_t freq; - for(freq=1; freq<=40000000; freq+=1) { - #if CHECK_ALL != 1 - if (freq > 10000000) + for (freq = 1; freq <= 40000000; freq += 1) { +#if CHECK_ALL != 1 + if (freq > 10000000) { freq += 10000000 / FDIV - 1; - else if (freq > 1000000) + } else if (freq > 1000000) { freq += 1000000 / FDIV - 1; - else if (freq > 100000) + } else if (freq > 100000) { freq += 100000 / FDIV - 1; - else if (freq > 10000) + } else if (freq > 10000) { freq += 10000 / FDIV - 1; - else if (freq > 1000) + } else if (freq > 1000) { freq += 1000 / FDIV - 1; - else if (freq > 100) + } else if (freq > 100) { freq += 100 / FDIV - 1; - else if (freq > 10) + } else if (freq > 10) { freq += 10 / FDIV - 1; - #endif + } +#endif check(freq);