Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tasssadar committed Jul 9, 2023
1 parent 29cfb77 commit 3dcc94b
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 64 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: PlatformIO CI

on: [push]

jobs:
build-test:
runs-on: ubuntu-22.04
strategy:
matrix:
example:
- examples/basic
conf:
- esp32-idf4-arduino.ini
- esp32-idf5-idf.ini
- esp32s3-idf4-arduino.ini
- esp32s3-idf5-idf.ini
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install platformio
- name: Build examples
run: platformio ci --lib="." --project-conf="./test-inis/${{ matrix.conf }}"
env:
PLATFORMIO_CI_SRC: ${{ matrix.example }}
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.0)

set(SRCS
"src/Color.cpp"
"src/RmtDriver4.cpp"
"src/RmtDriver5.cpp"
"src/SmartLeds.cpp"
)

idf_component_register(
SRCS ${SRCS}
INCLUDE_DIRS "./src"
REQUIRES driver
)
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

Simple & intuitive way to drive various smart LEDs on ESP32.

Requires ESP-IDF >=4.0

## Supported LEDs:

- WS2812 (RMT driver)
- WS2812 (RMT driver)
- WS2812B (RMT driver)
- SK6812 (RMT driver)
- WS2813 (RMT driver)
- APA102 (SPI driver)
- LPD8806 (SPI driver)
- SK6812 (RMT driver)
- WS2813 (RMT driver)
- APA102 (SPI driver)
- LPD8806 (SPI driver)

All the LEDs are driven by hardware peripherals in order to achieve high
performance.
Expand All @@ -28,4 +30,5 @@ performance.
- clock at 10 MHz

## Available
[PlatformIO - library 1740 - SmartLeds](https://platformio.org/lib/show/1740/SmartLeds)

[PlatformIO - library 1740 - SmartLeds](https://platformio.org/lib/show/1740/SmartLeds)
62 changes: 62 additions & 0 deletions examples/basic/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#ifdef LX16A_ARDUINO
#include <Arduino.h>
#else
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
static void delay(int ms) { vTaskDelay(pdMS_TO_TICKS(ms)); }
static uint32_t millis() { return xTaskGetTickCount(); }
#endif

#include <SmartLeds.h>

const int LED_COUNT = 15;
const int DATA_PIN = 22;
const int CHANNEL = 0;

// SmartLed -> RMT driver (WS2812/WS2812B/SK6812/WS2813)
SmartLed leds(LED_WS2812B, LED_COUNT, DATA_PIN, CHANNEL, DoubleBuffer);

const int CLK_PIN = 23;
// APA102 -> SPI driver
//Apa102 leds(LED_COUNT, CLK_PIN, DATA_PIN, DoubleBuffer);

void setup() {}

uint8_t hue;
void showGradient() {
hue++;
// Use HSV to create nice gradient
for (int i = 0; i != LED_COUNT; i++)
leds[i] = Hsv { static_cast<uint8_t>(hue + 30 * i), 255, 255 };
leds.show();
// Show is asynchronous; if we need to wait for the end of transmission,
// we can use leds.wait(); however we use double buffered mode, so we
// can start drawing right after showing.
}

void showRgb() {
leds[0] = Rgb { 255, 0, 0 };
leds[1] = Rgb { 0, 255, 0 };
leds[2] = Rgb { 0, 0, 255 };
leds[3] = Rgb { 0, 0, 0 };
leds[4] = Rgb { 255, 255, 255 };
leds.show();
}

void loop() {
if (millis() % 10000 < 5000)
showGradient();
else
showRgb();
delay(50);
}

#ifndef ARDUINO
extern "C" void app_main() {
setup();
while (true) {
loop();
vTaskDelay(0);
}
}
#endif
48 changes: 0 additions & 48 deletions examples/basicExample/basicExample.ino

This file was deleted.

8 changes: 6 additions & 2 deletions src/RmtDriver.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#pragma once

#include <esp_idf_version.h>
#include <esp_system.h>
#include <stdint.h>

#if (defined(ESP_IDF_VERSION) && ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0))
#if defined(ESP_IDF_VERSION)
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
#define SMARTLEDS_NEW_RMT_DRIVER 1
#else
#define SMARTLEDS_NEW_RMT_DRIVER 0
#endif
#else
#define SMARTLEDS_NEW_RMT_DRIVER 0
#endif

namespace detail {

Expand Down
9 changes: 7 additions & 2 deletions src/RmtDriver5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace detail {

static constexpr const uint32_t RMT_RESOLUTION_HZ = 20 * 1000 * 1000; // 20 MHz
static constexpr const uint32_t RMT_NS_PER_TICK = 1000000000LU / RMT_RESOLUTION_HZ;
static constexpr const uint32_t RMT_NS_PER_TICK = 1000000000LLU / RMT_RESOLUTION_HZ;

static RmtEncoderWrapper* IRAM_ATTR encSelf(rmt_encoder_t* encoder) {
return (RmtEncoderWrapper*)(((intptr_t)encoder) - offsetof(RmtEncoderWrapper, base));
Expand Down Expand Up @@ -124,7 +124,7 @@ esp_err_t RmtDriver::registerIsr(bool isFirstRegisteredChannel) {
.gpio_num = _pin,
.clk_src = RMT_CLK_SRC_APB,
.resolution_hz = RMT_RESOLUTION_HZ,
.mem_block_symbols = 64,
.mem_block_symbols = SOC_RMT_MEM_WORDS_PER_CHANNEL,
.trans_queue_depth = 1,
.flags = {},
};
Expand All @@ -151,6 +151,11 @@ esp_err_t RmtDriver::unregisterIsr() {
return err;
}

err = rmt_disable(_channel);
if (err != ESP_OK) {
return err;
}

return rmt_del_channel(_channel);
}

Expand Down
2 changes: 1 addition & 1 deletion src/RmtDriver5.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct RmtEncoderWrapper {
RmtDriver* driver;
rmt_symbol_word_t reset_code;

uint8_t buffer[64 / 8]; // RMT peripherial has buffer for 64 bits
uint8_t buffer[SOC_RMT_MEM_WORDS_PER_CHANNEL / 8];
rmt_encode_state_t last_state;
size_t frame_idx;
uint8_t component_idx;
Expand Down
2 changes: 1 addition & 1 deletion src/SmartLeds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
IsrCore SmartLed::_interruptCore = CoreCurrent;

SmartLed*& IRAM_ATTR SmartLed::ledForChannel(int channel) {
static SmartLed* table[detail::CHANNEL_COUNT] = { nullptr };
static SmartLed* table[detail::CHANNEL_COUNT] = {};
assert(channel < detail::CHANNEL_COUNT);
return table[channel];
}
6 changes: 2 additions & 4 deletions src/SmartLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,10 @@ class SmartLed {
std::unique_ptr<Rgb[]> _secondBuffer;
};

#ifdef CONFIG_IDF_TARGET_ESP32
#define _SMARTLEDS_SPI_HOST HSPI_HOST
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
#if defined(CONFIG_IDF_TARGET_ESP32S3)
#define _SMARTLEDS_SPI_HOST SPI2_HOST
#else
#error "SmartLeds SPI host not defined for this chip/esp-idf version."
#define _SMARTLEDS_SPI_HOST HSPI_HOST
#endif

class Apa102 {
Expand Down
23 changes: 23 additions & 0 deletions test-inis/esp32-idf4-arduino.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html

[env:esp32dev]
platform = espressif32@5.3.0
board = esp32dev
framework = arduino

upload_speed = 921600
monitor_speed = 115200

build_unflags = -std=gnu++11
build_flags =
-std=gnu++14
-fmax-errors=5
-DLX16A_ARDUINO=1
22 changes: 22 additions & 0 deletions test-inis/esp32-idf5-idf.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html

[env:esp32dev]
platform = espressif32@6.3.2
board = esp32dev
framework = espidf

upload_speed = 921600
monitor_speed = 115200

build_unflags = -std=gnu++11
build_flags =
-std=gnu++14
-fmax-errors=5
23 changes: 23 additions & 0 deletions test-inis/esp32s3-idf4-arduino.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html

[env:esp32dev]
platform = espressif32@6.3.2
board = esp32-s3-devkitc-1
framework = arduino

upload_speed = 921600
monitor_speed = 115200

build_unflags = -std=gnu++11
build_flags =
-std=gnu++14
-fmax-errors=5
-DLX16A_ARDUINO=1
22 changes: 22 additions & 0 deletions test-inis/esp32s3-idf5-idf.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html

[env:esp32dev]
platform = espressif32@6.3.2
board = esp32-s3-devkitc-1
framework = espidf

upload_speed = 921600
monitor_speed = 115200

build_unflags = -std=gnu++11
build_flags =
-std=gnu++14
-fmax-errors=5

0 comments on commit 3dcc94b

Please sign in to comment.