Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: end frame for SK9822 LEDs #50

Merged
merged 1 commit into from
Jan 19, 2025
Merged
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
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
Loading