-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(led_strip): Support configure pixel orders
- Loading branch information
Showing
13 changed files
with
204 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include "esp_err.h" | ||
#include "led_strip_types.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @brief LED strip pixel order index | ||
*/ | ||
typedef enum { | ||
LED_PIXEL_INDEX_RED, /*!< Red pixel index */ | ||
LED_PIXEL_INDEX_GREEN, /*!< Green pixel index */ | ||
LED_PIXEL_INDEX_BLUE, /*!< Blue pixel index */ | ||
LED_PIXEL_INDEX_WHITE, /*!< White pixel index */ | ||
LED_PIXEL_INDEX_MAX /*!< Max pixel index */ | ||
} led_pixel_order_index_t; | ||
|
||
/** | ||
* @brief Adjust LED color order | ||
* | ||
* @param led_pixel_offset Each pixel's offset | ||
* @param config_pixel_order `config_pixel_order` parameter in LED strip configuration | ||
* @param bytes_per_pixel bytes per pixel | ||
* @return | ||
* - ESP_OK: Adjust LED color order successfully | ||
* - ESP_ERR_INVALID_ARG: Adjust LED color order failed because of invalid argument | ||
*/ | ||
esp_err_t led_strip_adjust_color_order(uint8_t *led_pixel_offset, const uint8_t config_pixel_order, const uint8_t bytes_per_pixel); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include <stdbool.h> | ||
#include "esp_log.h" | ||
#include "esp_check.h" | ||
#include "esp_bit_defs.h" | ||
#include "esp_private/led_strip_common.h" | ||
|
||
static const char *TAG = "led_strip_common"; | ||
|
||
esp_err_t led_strip_adjust_color_order(uint8_t *led_pixel_offset, const uint8_t config_pixel_order, const uint8_t bytes_per_pixel) | ||
{ | ||
esp_err_t ret = ESP_OK; | ||
ESP_RETURN_ON_FALSE(led_pixel_offset && bytes_per_pixel, ESP_ERR_INVALID_ARG, TAG, "invalid argument"); | ||
if (config_pixel_order) { | ||
uint8_t r_order = (config_pixel_order >> 0) & 0x03; | ||
uint8_t g_order = (config_pixel_order >> 2) & 0x03; | ||
uint8_t b_order = (config_pixel_order >> 4) & 0x03; | ||
uint8_t w_order = (config_pixel_order >> 6) & 0x03; | ||
uint8_t mask = bytes_per_pixel == 3 ? BIT(r_order) | BIT(g_order) | BIT(b_order) : BIT(r_order) | BIT(g_order) | BIT(b_order) | BIT(w_order); | ||
// Check for invalid values | ||
ESP_RETURN_ON_FALSE(__builtin_popcount(mask) == bytes_per_pixel && r_order < bytes_per_pixel && g_order < bytes_per_pixel && b_order < bytes_per_pixel && w_order < bytes_per_pixel, | ||
ESP_ERR_INVALID_ARG, TAG, "invalid order argument"); | ||
led_pixel_offset[LED_PIXEL_INDEX_RED] = r_order; | ||
led_pixel_offset[LED_PIXEL_INDEX_GREEN] = g_order; | ||
led_pixel_offset[LED_PIXEL_INDEX_BLUE] = b_order; | ||
led_pixel_offset[LED_PIXEL_INDEX_WHITE] = w_order; | ||
} else { | ||
led_pixel_offset[LED_PIXEL_INDEX_RED] = 1; | ||
led_pixel_offset[LED_PIXEL_INDEX_GREEN] = 0; | ||
led_pixel_offset[LED_PIXEL_INDEX_BLUE] = 2; | ||
led_pixel_offset[LED_PIXEL_INDEX_WHITE] = 3; | ||
} | ||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.