Skip to content

Commit

Permalink
fix: end frame for SK9822 LEDs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tasssadar committed Dec 27, 2024
1 parent dd49716 commit 3bbc35f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"maintainer": true
}
],
"version": "3.1.4",
"version": "3.1.5",
"frameworks": ["arduino", "espidf"],
"platforms": "espressif32"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SmartLeds
version=3.1.4
version=3.1.5
author=Jan Mrázek
maintainer=Jan Mrázek <email@honzamrazek.cz>
sentence=Simple & intuitive way to drive various smart LEDs on ESP32.
Expand Down
9 changes: 6 additions & 3 deletions src/SmartLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class SmartLed {
#define _SMARTLEDS_SPI_DMA_CHAN 1
#endif

// Can also handle SK9822
class Apa102 {
public:
struct ApaRgb {
Expand Down Expand Up @@ -256,7 +257,7 @@ class Apa102 {
ret = spi_bus_add_device(_SMARTLEDS_SPI_HOST, &devcfg, &_spi);
assert(ret == ESP_OK);

std::fill_n(_finalFrame, FINAL_FRAME_SIZE, 0xFFFFFFFF);
std::fill_n(_finalFrame, FINAL_FRAME_SIZE, 0);
}

~Apa102() {
Expand Down Expand Up @@ -304,8 +305,10 @@ class Apa102 {
spi_device_queue_trans(_spi, _transactions + 1, portMAX_DELAY);
_transCount = 2;
// End frame
for (int i = 0; i != 1 + _count / 32 / FINAL_FRAME_SIZE; i++) {
_transactions[2 + i].length = 32 * FINAL_FRAME_SIZE;
// https://cpldcpu.com/2016/12/13/sk9822-a-clone-of-the-apa102/ - "Unified protocol"
const int end_bits = 32 + (_count/2 + 1);
for (int i = 0; i < end_bits; i += 32 * FINAL_FRAME_SIZE) {
_transactions[2 + i].length = std::min(32 * FINAL_FRAME_SIZE, end_bits - i);
_transactions[2 + i].tx_buffer = _finalFrame;
spi_device_queue_trans(_spi, _transactions + 2 + i, portMAX_DELAY);
_transCount++;
Expand Down

0 comments on commit 3bbc35f

Please sign in to comment.