Skip to content

Commit

Permalink
use led_indicator instead of led_strip
Browse files Browse the repository at this point in the history
  • Loading branch information
pborcin committed Nov 24, 2023
1 parent b5b3493 commit ceebbe5
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 64 deletions.
2 changes: 1 addition & 1 deletion bsp/esp32_s3_korvo_1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ else()
endif()

idf_component_register(
SRCS "esp32_s3_korvo_1.c" ${SRC_VER}
SRCS "esp32_s3_korvo_1.c" ${SRC_VER} "led_blink_defaults.c"
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "priv_include"
REQUIRES ${REQ}
Expand Down
75 changes: 39 additions & 36 deletions bsp/esp32_s3_korvo_1/esp32_s3_korvo_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,27 @@

#include "esp_err.h"
#include "esp_log.h"
#include "led_strip.h"

#include "iot_button.h"
#include "bsp/esp-bsp.h"
#include "bsp_err_check.h"
#include "esp_spiffs.h"
#include "led_indicator.h"

static const char *TAG = "S3-Korvo-1";

static led_strip_handle_t led_strip;

/**
* @brief led configuration structure
*
* This configuration is used by default in bsp_led_init()
*/
static const led_strip_config_t bsp_strip_config = {
.strip_gpio_num = BSP_LED_RGB_IO,
.max_leds = BSP_RGB_LEDS_NUM,
.led_pixel_format = LED_PIXEL_FORMAT_GRB,
.led_model = LED_MODEL_WS2812,
.flags.invert_out = false,
};

static const led_strip_rmt_config_t bsp_rmt_config = {
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
.rmt_channel = 0,
#else
.clk_src = RMT_CLK_SRC_DEFAULT,
.resolution_hz = 10 * 1000 * 1000,
.flags.with_dma = false,
#endif
};

#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
static adc_oneshot_unit_handle_t bsp_adc_handle = NULL;
#endif

extern blink_step_t const *bsp_led_blink_defaults_lists[];

static const button_config_t bsp_button_config[BSP_BUTTON_NUM] = {
{
.type = BUTTON_TYPE_ADC,
Expand Down Expand Up @@ -136,28 +119,48 @@ esp_err_t bsp_iot_button_create(button_handle_t btn_array[], int *btn_cnt, int b
return ret;
}

esp_err_t bsp_led_init()
{
ESP_LOGI(TAG, "BLINK_GPIO setting %d", bsp_strip_config.strip_gpio_num);
static const led_strip_config_t bsp_leds_rgb_strip_config = {
.strip_gpio_num = BSP_LED_RGB_GPIO, // The GPIO that connected to the LED strip's data line
.max_leds = BSP_LED_NUM, // The number of LEDs in the strip,
.led_pixel_format = LED_PIXEL_FORMAT_GRB, // Pixel format of your LED strip
.led_model = LED_MODEL_WS2812, // LED strip model
.flags.invert_out = false, // whether to invert the output signal
};

ESP_ERROR_CHECK(led_strip_new_rmt_device(&bsp_strip_config, &bsp_rmt_config, &led_strip));
for (uint32_t index = 0; index < BSP_RGB_LEDS_NUM; ++index) {
led_strip_set_pixel(led_strip, index, 0x00, 0x00, 0x00);
}
led_strip_refresh(led_strip);
static const led_strip_rmt_config_t bsp_leds_rgb_rmt_config = {
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
.rmt_channel = 0,
#else
.clk_src = RMT_CLK_SRC_DEFAULT, // different clock source can lead to different power consumption
.resolution_hz = 10 * 1000 * 1000, // RMT counter clock frequency = 10MHz
.flags.with_dma = false, // DMA feature is available on ESP target like ESP32-S3
#endif
};

return ESP_OK;
}
static led_indicator_strips_config_t bsp_leds_rgb_config = {
.is_active_level_high = 1,
.led_strip_cfg = bsp_leds_rgb_strip_config,
.led_strip_driver = LED_STRIP_RMT,
.led_strip_rmt_cfg = bsp_leds_rgb_rmt_config,
};

esp_err_t bsp_led_rgb_set(uint8_t r, uint8_t g, uint8_t b)
{
esp_err_t ret = ESP_OK;
static const led_indicator_config_t bsp_leds_config = {
.mode = LED_STRIPS_MODE,
.led_indicator_strips_config = &bsp_leds_rgb_config,
.blink_lists = bsp_led_blink_defaults_lists,
.blink_list_num = BSP_LED_MAX,
};

for (uint32_t index = 0; index < BSP_RGB_LEDS_NUM; ++index) {
ret |= led_strip_set_pixel(led_strip, index, r, g, b);
esp_err_t bsp_led_indicator_create(led_indicator_handle_t led_array[], int *led_cnt, int led_array_size)
{
if (led_array == NULL) {
return ESP_ERR_INVALID_ARG;
}

ret |= led_strip_refresh(led_strip);
led_array[0] = led_indicator_create(&bsp_leds_config[0]);
if (led_array[0] == NULL) {
return ESP_FAIL;
}
return ret;
}

Expand Down
4 changes: 2 additions & 2 deletions bsp/esp32_s3_korvo_1/idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ targets:
dependencies:
idf: ">=4.4"

led_strip:
version: "^2"
led_indicator:
version: "^0.7"
public: true

button:
Expand Down
40 changes: 15 additions & 25 deletions bsp/esp32_s3_korvo_1/include/bsp/esp32_s3_korvo_1.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
#pragma once

#include "iot_button.h"
#include "led_indicator.h"

/**************************************************************************************************
* ESP32-S3-Korvo-1 pinout
**************************************************************************************************/

/* Leds */
#define BSP_LED_RGB_IO (GPIO_NUM_19)
#define BSP_RGB_LEDS_NUM (12)
#define BSP_LED_RGB_GPIO (GPIO_NUM_19)
#define BSP_LED_NUM (12)

/* Buttons */
#define BSP_BUTTONS_IO (GPIO_NUM_8) // All 6 buttons mapped to this GPIO
Expand All @@ -29,6 +30,17 @@
extern "C" {
#endif

/* Default LED effects */
enum {
BSP_LED_ON,
BSP_LED_OFF,
BSP_LED_BLINK_FAST,
BSP_LED_BLINK_SLOW,
BSP_LED_BREATHE_FAST,
BSP_LED_BREATHE_SLOW,
BSP_LED_MAX,
};

/**************************************************************************************************
*
* Buttons interface
Expand Down Expand Up @@ -104,29 +116,7 @@ esp_err_t bsp_iot_button_create(button_handle_t btn_array[], int *btn_cnt, int b
*
* There's twelve RGB lights on ESP32-S3-Korvo-1:
**************************************************************************************************/

/**
* @brief Initialize WS2812
*
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
*/
esp_err_t bsp_led_init();

/**
* @brief Set RGB for a specific pixel
*
* @param r: red part of color
* @param g: green part of color
* @param b: blue part of color
*
* @return
* - ESP_OK: Set RGB for a specific pixel successfully
* - ESP_ERR_INVALID_ARG: Set RGB for a specific pixel failed because of invalid parameters
* - ESP_FAIL: Set RGB for a specific pixel failed because other error occurred
*/
esp_err_t bsp_led_rgb_set(uint8_t r, uint8_t g, uint8_t b);
esp_err_t bsp_led_indicator_create(led_indicator_handle_t led_array[], int *led_cnt, int led_array_size);

/**************************************************************************************************
*
Expand Down
83 changes: 83 additions & 0 deletions bsp/esp32_s3_korvo_1/led_blink_defaults.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "led_indicator.h"
#include "bsp/esp-bsp.h"

/*********************************** Config Blink List ***********************************/
/**
* @brief LED on
*
*/
static const blink_step_t bsp_led_on[] = {
{LED_BLINK_HOLD, LED_STATE_ON, 0},
{LED_BLINK_STOP, 0, 0},
};

/**
* @brief LED off
*
*/
static const blink_step_t bsp_led_off[] = {
{LED_BLINK_HOLD, LED_STATE_OFF, 0},
{LED_BLINK_STOP, 0, 0},
};

/**
* @brief LED blink fast
*
*/
static const blink_step_t bsp_led_blink_fast[] = {
{LED_BLINK_HOLD, LED_STATE_ON, 500},
{LED_BLINK_HOLD, LED_STATE_OFF, 500},
{LED_BLINK_LOOP, 0, 0},
};

/**
* @brief LED blink slow
*
*/
static const blink_step_t bsp_led_blink_slow[] = {
{LED_BLINK_HOLD, LED_STATE_ON, 1000},
{LED_BLINK_HOLD, LED_STATE_OFF, 1000},
{LED_BLINK_LOOP, 0, 0},
};

/**
* @brief LED breathe fast
*
*/
static const blink_step_t bsp_led_breathe_fast[] = {
{LED_BLINK_BREATHE, LED_STATE_ON, 500},
{LED_BLINK_HOLD, LED_STATE_ON, 500},
{LED_BLINK_BREATHE, LED_STATE_OFF, 500},
{LED_BLINK_HOLD, LED_STATE_OFF, 500},
{LED_BLINK_LOOP, 0, 0},
};

/**
* @brief LED breathe slow
*
*/
static const blink_step_t bsp_led_breathe_slow[] = {
{LED_BLINK_BREATHE, LED_STATE_OFF, 2000},
{LED_BLINK_BREATHE, LED_STATE_ON, 2000},
{LED_BLINK_LOOP, 0, 0},
};

/**
* @brief LED blink lists
*
*/
blink_step_t const *bsp_led_blink_defaults_lists[] = {
[BSP_LED_ON] = bsp_led_on,
[BSP_LED_OFF] = bsp_led_off,
[BSP_LED_BLINK_FAST] = bsp_led_blink_fast,
[BSP_LED_BLINK_SLOW] = bsp_led_blink_slow,
[BSP_LED_BREATHE_FAST] = bsp_led_breathe_fast,
[BSP_LED_BREATHE_SLOW] = bsp_led_breathe_slow,
[BSP_LED_MAX] = NULL,
};

0 comments on commit ceebbe5

Please sign in to comment.