ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
led_strip_api.c File Reference
#include "esp_log.h"
#include "esp_check.h"
#include "led_strip.h"
#include "led_strip_interface.h"
Include dependency graph for led_strip_api.c:

Go to the source code of this file.

Functions

esp_err_t led_strip_set_pixel (led_strip_handle_t strip, uint32_t index, uint32_t red, uint32_t green, uint32_t blue)
 Set RGB for a specific pixel.
esp_err_t led_strip_set_pixel_hsv (led_strip_handle_t strip, uint32_t index, uint16_t hue, uint8_t saturation, uint8_t value)
 Set HSV for a specific pixel.
esp_err_t led_strip_set_pixel_rgbw (led_strip_handle_t strip, uint32_t index, uint32_t red, uint32_t green, uint32_t blue, uint32_t white)
 Set RGBW for a specific pixel.
esp_err_t led_strip_refresh (led_strip_handle_t strip)
 Refresh memory colors to LEDs.
esp_err_t led_strip_clear (led_strip_handle_t strip)
 Clear LED strip (turn off all LEDs).
esp_err_t led_strip_del (led_strip_handle_t strip)
 Free LED strip resources.

Variables

static const char * TAG = "led_strip"

Function Documentation

◆ led_strip_clear()

esp_err_t led_strip_clear ( led_strip_handle_t strip)

Clear LED strip (turn off all LEDs).

Parameters
stripLED strip
Returns
  • ESP_OK: Clear LEDs successfully
  • ESP_FAIL: Clear LEDs failed because some other error occurred

Definition at line 84 of file led_strip_api.c.

85{
86 ESP_RETURN_ON_FALSE(strip, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
87 return strip->clear(strip);
88}
static const char * TAG
Definition main/main.c:31
esp_err_t(* clear)(led_strip_t *strip)
Clear LED strip (turn off all LEDs).

References led_strip_t::clear, and TAG.

◆ led_strip_del()

esp_err_t led_strip_del ( led_strip_handle_t strip)

Free LED strip resources.

Parameters
stripLED strip
Returns
  • ESP_OK: Free resources successfully
  • ESP_FAIL: Free resources failed because error occurred

Definition at line 90 of file led_strip_api.c.

91{
92 ESP_RETURN_ON_FALSE(strip, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
93 return strip->del(strip);
94}
esp_err_t(* del)(led_strip_t *strip)
Free LED strip resources.

References led_strip_t::del, and TAG.

◆ led_strip_refresh()

esp_err_t led_strip_refresh ( led_strip_handle_t strip)

Refresh memory colors to LEDs.

Parameters
stripLED strip
Returns
  • ESP_OK: Refresh successfully
  • ESP_FAIL: Refresh failed because some other error occurred
Note
: After updating the LED colors in the memory, a following invocation of this API is needed to flush colors to strip.

Definition at line 78 of file led_strip_api.c.

79{
80 ESP_RETURN_ON_FALSE(strip, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
81 return strip->refresh(strip);
82}
esp_err_t(* refresh)(led_strip_t *strip)
Refresh memory colors to LEDs.

References led_strip_t::refresh, and TAG.

Referenced by cdc_tx_task().

Here is the caller graph for this function:

◆ led_strip_set_pixel()

esp_err_t led_strip_set_pixel ( led_strip_handle_t strip,
uint32_t index,
uint32_t red,
uint32_t green,
uint32_t blue )

Set RGB for a specific pixel.

Parameters
stripLED strip
indexindex of pixel to set
redred part of color
greengreen part of color
blueblue part of color
Returns
  • 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

Definition at line 13 of file led_strip_api.c.

14{
15 ESP_RETURN_ON_FALSE(strip, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
16 return strip->set_pixel(strip, index, red, green, blue);
17}
esp_err_t(* set_pixel)(led_strip_t *strip, uint32_t index, uint32_t red, uint32_t green, uint32_t blue)
Set RGB for a specific pixel.

References led_strip_t::set_pixel, and TAG.

Referenced by cdc_tx_task().

Here is the caller graph for this function:

◆ led_strip_set_pixel_hsv()

esp_err_t led_strip_set_pixel_hsv ( led_strip_handle_t strip,
uint32_t index,
uint16_t hue,
uint8_t saturation,
uint8_t value )

Set HSV for a specific pixel.

Parameters
stripLED strip
indexindex of pixel to set
huehue part of color (0 - 360)
saturationsaturation part of color (0 - 255, rescaled from 0 - 1. e.g. saturation = 0.5, rescaled to 127)
valuevalue part of color (0 - 255, rescaled from 0 - 1. e.g. value = 0.5, rescaled to 127)
Returns
  • ESP_OK: Set HSV color for a specific pixel successfully
  • ESP_ERR_INVALID_ARG: Set HSV color for a specific pixel failed because of an invalid argument
  • ESP_FAIL: Set HSV color for a specific pixel failed because other error occurred

Definition at line 19 of file led_strip_api.c.

20{
21 ESP_RETURN_ON_FALSE(strip, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
22
23 uint32_t red = 0;
24 uint32_t green = 0;
25 uint32_t blue = 0;
26
27 uint32_t rgb_max = value;
28 uint32_t rgb_min = rgb_max * (255 - saturation) / 255.0f;
29
30 uint32_t i = hue / 60;
31 uint32_t diff = hue % 60;
32
33 // RGB adjustment amount by hue
34 uint32_t rgb_adj = (rgb_max - rgb_min) * diff / 60;
35
36 switch (i) {
37 case 0:
38 red = rgb_max;
39 green = rgb_min + rgb_adj;
40 blue = rgb_min;
41 break;
42 case 1:
43 red = rgb_max - rgb_adj;
44 green = rgb_max;
45 blue = rgb_min;
46 break;
47 case 2:
48 red = rgb_min;
49 green = rgb_max;
50 blue = rgb_min + rgb_adj;
51 break;
52 case 3:
53 red = rgb_min;
54 green = rgb_max - rgb_adj;
55 blue = rgb_max;
56 break;
57 case 4:
58 red = rgb_min + rgb_adj;
59 green = rgb_min;
60 blue = rgb_max;
61 break;
62 default:
63 red = rgb_max;
64 green = rgb_min;
65 blue = rgb_max - rgb_adj;
66 break;
67 }
68
69 return strip->set_pixel(strip, index, red, green, blue);
70}

References led_strip_t::set_pixel, and TAG.

◆ led_strip_set_pixel_rgbw()

esp_err_t led_strip_set_pixel_rgbw ( led_strip_handle_t strip,
uint32_t index,
uint32_t red,
uint32_t green,
uint32_t blue,
uint32_t white )

Set RGBW for a specific pixel.

Note
Only call this function if your led strip does have the white component (e.g. SK6812-RGBW)
Also see led_strip_set_pixel if you only want to specify the RGB part of the color and bypass the white component
Parameters
stripLED strip
indexindex of pixel to set
redred part of color
greengreen part of color
blueblue part of color
whiteseparate white component
Returns
  • ESP_OK: Set RGBW color for a specific pixel successfully
  • ESP_ERR_INVALID_ARG: Set RGBW color for a specific pixel failed because of an invalid argument
  • ESP_FAIL: Set RGBW color for a specific pixel failed because other error occurred

Definition at line 72 of file led_strip_api.c.

73{
74 ESP_RETURN_ON_FALSE(strip, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
75 return strip->set_pixel_rgbw(strip, index, red, green, blue, white);
76}
esp_err_t(* set_pixel_rgbw)(led_strip_t *strip, uint32_t index, uint32_t red, uint32_t green, uint32_t blue, uint32_t white)
Set RGBW for a specific pixel. Similar to set_pixel but also set the white component.

References led_strip_t::set_pixel_rgbw, and TAG.

Variable Documentation

◆ TAG

const char* TAG = "led_strip"
static

Definition at line 11 of file led_strip_api.c.