Skip to content

Commit

Permalink
Refactor to use the new driver on IDF 5.0 (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tasssadar authored Jul 9, 2023
1 parent 20426e0 commit cf2dbb4
Show file tree
Hide file tree
Showing 22 changed files with 1,141 additions and 493 deletions.
127 changes: 127 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
---
Language: Cpp
# BasedOnStyle: WebKit
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: false
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 0
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: false
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseTab: Never
ColumnLimit: 120
...
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.

Loading

0 comments on commit cf2dbb4

Please sign in to comment.