From 5903717de192095cc87c4b8b02785eda9e212185 Mon Sep 17 00:00:00 2001 From: Chen Jichang Date: Tue, 18 Jun 2024 11:00:29 +0800 Subject: [PATCH] fix(led_strip): fix the reset time and resolution bugs This commit add a delay to ensure that the reset time is enough during the initialization. And remove the rigorous judgment of the real spi clk resolution to support different XTAL freq. --- led_strip/idf_component.yml | 2 +- led_strip/src/led_strip_spi_dev.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/led_strip/idf_component.yml b/led_strip/idf_component.yml index e0e3fe375c..deda1bc743 100644 --- a/led_strip/idf_component.yml +++ b/led_strip/idf_component.yml @@ -1,4 +1,4 @@ -version: "2.5.3" +version: "2.5.4" description: Driver for Addressable LED Strip (WS2812, etc) url: https://github.com/espressif/idf-extra-components/tree/master/led_strip dependencies: diff --git a/led_strip/src/led_strip_spi_dev.c b/led_strip/src/led_strip_spi_dev.c index 12ea8fbf31..6c66d7e375 100644 --- a/led_strip/src/led_strip_spi_dev.c +++ b/led_strip/src/led_strip_spi_dev.c @@ -177,12 +177,14 @@ esp_err_t led_strip_new_spi_device(const led_strip_config_t *led_config, const l }; ESP_GOTO_ON_ERROR(spi_bus_add_device(spi_strip->spi_host, &spi_dev_cfg, &spi_strip->spi_device), err, TAG, "Failed to add spi device"); - + //ensure the reset time is enough + esp_rom_delay_us(10); int clock_resolution_khz = 0; spi_device_get_actual_freq(spi_strip->spi_device, &clock_resolution_khz); // TODO: ideally we should decide the SPI_BYTES_PER_COLOR_BYTE by the real clock resolution // But now, let's fixed the resolution, the downside is, we don't support a clock source whose frequency is not multiple of LED_STRIP_SPI_DEFAULT_RESOLUTION - ESP_GOTO_ON_FALSE(clock_resolution_khz == LED_STRIP_SPI_DEFAULT_RESOLUTION / 1000, ESP_ERR_NOT_SUPPORTED, err, + // clock_resolution between 2.2MHz to 2.8MHz is supported + ESP_GOTO_ON_FALSE((clock_resolution_khz < LED_STRIP_SPI_DEFAULT_RESOLUTION / 1000 + 300) && (clock_resolution_khz > LED_STRIP_SPI_DEFAULT_RESOLUTION / 1000 - 300), ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported clock resolution:%dKHz", clock_resolution_khz); spi_strip->bytes_per_pixel = bytes_per_pixel;