-
Notifications
You must be signed in to change notification settings - Fork 92
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
242 additions
and
108 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
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,37 @@ | ||
/* | ||
* 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 "led_strip_common.h" | ||
|
||
static const char *TAG = "led_strip_common"; | ||
|
||
esp_err_t led_strip_set_color_order(uint8_t *led_pixel_offset, const uint8_t pixel_order, const uint8_t bytes_per_pixel) | ||
{ | ||
if (pixel_order) { | ||
uint8_t r_order = (pixel_order >> 0) & 0x03; | ||
uint8_t g_order = (pixel_order >> 2) & 0x03; | ||
uint8_t b_order = (pixel_order >> 4) & 0x03; | ||
uint8_t w_order = (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 { | ||
// If pixel_order is not set, set default GRB(GRBW) order as fallback path | ||
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 ESP_OK; | ||
} |
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 Set LED color order | ||
* | ||
* @param led_pixel_offset Each pixel's offset | ||
* @param pixel_order `pixel_order` parameter in LED strip configuration | ||
* @param bytes_per_pixel bytes per pixel | ||
* @return | ||
* - ESP_OK: Set LED color order successfully | ||
* - ESP_ERR_INVALID_ARG: Set LED color order failed because of invalid argument | ||
*/ | ||
esp_err_t led_strip_set_color_order(uint8_t *led_pixel_offset, const uint8_t pixel_order, const uint8_t bytes_per_pixel); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
Oops, something went wrong.