Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
build/
sdkconfig*
202 changes: 0 additions & 202 deletions LICENSE

This file was deleted.

Empty file added component.mk
Empty file.
4 changes: 0 additions & 4 deletions components/led_strip/component.mk

This file was deleted.

8 changes: 8 additions & 0 deletions examples/simple/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#

PROJECT_NAME := simple

include $(IDF_PATH)/make/project.mk
Empty file.
31 changes: 28 additions & 3 deletions main/main.c → examples/simple/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
Author(s): Lucas Bruder <[email protected]>
Date Created: 11/23/2016
Last modified: 11/26/2016

------------------------------------------------------------------------- */

#include <stdio.h>

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#include "esp_system.h"
#include "esp_task.h"
#include "nvs_flash.h"
#include "driver/gpio.h"
#include "led_strip/led_strip.h"

#include <stdio.h>
#include <led_strip.h>

extern void main_led_task(void *args);

Expand All @@ -33,3 +33,28 @@ void app_main(void)
vTaskDelete(NULL);
}

#define LED_STRIP_LENGTH 477U
#define LED_STRIP_RMT_INTR_NUM 19U
#define DELAY_MS 400
#define WIDTH 5
#define MAX_BRIGHTNESS 2

static struct led_color_t led_strip_buf_1[LED_STRIP_LENGTH];
static struct led_color_t led_strip_buf_2[LED_STRIP_LENGTH];

void main_led_task(void *args)
{
struct led_strip_t led_strip = {
.rgb_led_type = RGB_LED_TYPE_WS2812,
.rmt_channel = RMT_CHANNEL_1,
.rmt_interrupt_num = LED_STRIP_RMT_INTR_NUM,
.gpio = GPIO_NUM_21,
.led_strip_buf_1 = led_strip_buf_1,
.led_strip_buf_2 = led_strip_buf_2,
.led_strip_length = LED_STRIP_LENGTH
};
led_strip.access_semaphore = xSemaphoreCreateBinary();

bool led_init_ok = led_strip_init(&led_strip);
assert(led_init_ok);
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ struct led_strip_t {
// RMT peripheral settings
rmt_channel_t rmt_channel;

/*
* Interrupt table is located in soc.h
* As of 11/27/16, reccomended interrupts are:
* 9, 12, 13, 17, 18, 19, 20, 21 or 23
* Ensure that the same interrupt number isn't used twice
* across all libraries
*/
int rmt_interrupt_num;

gpio_num_t gpio; // Must be less than GPIO_NUM_33

// Double buffering elements
Expand All @@ -69,8 +60,16 @@ bool led_strip_init(struct led_strip_t *led_strip);
/**
* Sets the pixel at pixel_num to color.
*/
bool led_strip_set_pixel_color(struct led_strip_t *led_strip, uint32_t pixel_num, struct led_color_t *color);
bool led_strip_set_pixel_rgb(struct led_strip_t *led_strip, uint32_t pixel_num, uint8_t red, uint8_t green, uint8_t blue);
bool led_strip_set_pixel_color(struct led_strip_t *led_strip,
const uint32_t pixel_num,
const struct led_color_t *color);

bool led_strip_set_pixel_rgb(struct led_strip_t *led_strip,
const uint32_t pixel_num,
const uint8_t red,
const uint8_t green,
const uint8_t blue);

/**
* Get the pixel color at pixel_num for the led strip that is currently being shown!
* NOTE: If you call set_pixel_color then get_pixel_color for the same pixel_num, you will not
Expand All @@ -79,7 +78,9 @@ bool led_strip_set_pixel_rgb(struct led_strip_t *led_strip, uint32_t pixel_num,
*
* If there is an invalid argument, color will point to NULL and this function will return false.
*/
bool led_strip_get_pixel_color(struct led_strip_t *led_strip, uint32_t pixel_num, struct led_color_t *color);
bool led_strip_get_pixel_color(struct led_strip_t *led_strip,
const uint32_t pixel_num,
struct led_color_t *color);

/**
* Updates the led buffer to be shown using double buffering.
Expand Down
10 changes: 5 additions & 5 deletions components/led_strip/led_strip.c → led_strip.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
and the task will look at buffer 2 for refreshing the LEDs
------------------------------------------------------------------------- */

#include "led_strip/led_strip.h"
#include "led_strip.h"
#include "freertos/task.h"

#include <string.h>

#define LED_STRIP_TASK_SIZE (512)
#define LED_STRIP_TASK_SIZE (2048)
#define LED_STRIP_TASK_PRIORITY (configMAX_PRIORITIES - 1)

#define LED_STRIP_REFRESH_PERIOD_MS (30U) // TODO: add as parameter to led_strip_init
Expand Down Expand Up @@ -346,7 +346,7 @@ bool led_strip_init(struct led_strip_t *led_strip)
return true;
}

bool led_strip_set_pixel_color(struct led_strip_t *led_strip, uint32_t pixel_num, struct led_color_t *color)
bool led_strip_set_pixel_color(struct led_strip_t *led_strip, const uint32_t pixel_num, const struct led_color_t *color)
{
bool set_led_success = true;

Expand All @@ -363,7 +363,7 @@ bool led_strip_set_pixel_color(struct led_strip_t *led_strip, uint32_t pixel_num
return set_led_success;
}

bool led_strip_set_pixel_rgb(struct led_strip_t *led_strip, uint32_t pixel_num, uint8_t red, uint8_t green, uint8_t blue)
bool led_strip_set_pixel_rgb(struct led_strip_t *led_strip, const uint32_t pixel_num, const uint8_t red, const uint8_t green, const uint8_t blue)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why apply const to copied values? I think const keyword is only relevant when using pointers so that you tell the users you won't modify the value they pass. Const for uint32_t and other copied values seems pointless to me (because you already can't modify it).

{
bool set_led_success = true;

Expand All @@ -384,7 +384,7 @@ bool led_strip_set_pixel_rgb(struct led_strip_t *led_strip, uint32_t pixel_num,
return set_led_success;
}

bool led_strip_get_pixel_color(struct led_strip_t *led_strip, uint32_t pixel_num, struct led_color_t *color)
bool led_strip_get_pixel_color(struct led_strip_t *led_strip, const uint32_t pixel_num, struct led_color_t *color)
{
bool get_success = true;

Expand Down
9 changes: 0 additions & 9 deletions main/component.mk

This file was deleted.