Skip to content

Commit c632410

Browse files
committed
Direct Framebuffer Access and GEQ PPA demo
1 parent b840402 commit c632410

File tree

6 files changed

+372
-372
lines changed

6 files changed

+372
-372
lines changed

wled00/FX.cpp

Lines changed: 306 additions & 364 deletions
Large diffs are not rendered by default.

wled00/FX.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ bool strip_uses_global_leds(void) __attribute__((pure)); // WLEDMM implemented
337337
#define FX_MODE_GEQLASER 195 // WLED-MM GEQ Laser
338338
#define FX_MODE_2DPAINTBRUSH 196 // WLED-MM Paintbrush
339339
#define FX_MODE_2DSNOWFALL 197 // WLED-MM Snowfall
340-
#define MODE_COUNT 198
340+
#define FX_MODE_GEQPPA 198
341+
#define MODE_COUNT 199
341342

342343
typedef enum mapping1D2D {
343344
M12_Pixels = 0,

wled00/FX_2Dfcn.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ void WS2812FX::setUpMatrix() {
199199
void IRAM_ATTR __attribute__((hot)) WS2812FX::setPixelColorXY_fast(int x, int y, uint32_t col) //WLEDMM: IRAM_ATTR conditionally
200200
{
201201
uint_fast32_t index = y * Segment::maxWidth + x;
202+
#ifndef WLEDMM_REMAP_AT_OUTPUT
202203
if (index < customMappingSize) index = customMappingTable[index];
204+
#endif
203205
if (index >= _length) return;
204206
busses.setPixelColor(index, col);
205207
}
@@ -213,7 +215,9 @@ void IRAM_ATTR_YN WS2812FX::setPixelColorXY(int x, int y, uint32_t col) //WLEDMM
213215
#else
214216
uint16_t index = x;
215217
#endif
218+
#ifndef WLEDMM_REMAP_AT_OUTPUT
216219
if (index < customMappingSize) index = customMappingTable[index];
220+
#endif
217221
if (index >= _length) return;
218222
busses.setPixelColor(index, col);
219223
}
@@ -225,7 +229,9 @@ uint32_t __attribute__((hot)) WS2812FX::getPixelColorXY(uint16_t x, uint16_t y)
225229
#else
226230
uint16_t index = x;
227231
#endif
232+
#ifndef WLEDMM_REMAP_AT_OUTPUT
228233
if (index < customMappingSize) index = customMappingTable[index];
234+
#endif
229235
if (index >= _length) return 0;
230236
return busses.getPixelColor(index);
231237
}
@@ -236,7 +242,9 @@ uint32_t __attribute__((hot)) WS2812FX::getPixelColorXYRestored(uint16_t x, uint
236242
#else
237243
uint16_t index = x;
238244
#endif
245+
#ifndef WLEDMM_REMAP_AT_OUTPUT
239246
if (index < customMappingSize) index = customMappingTable[index];
247+
#endif
240248
if (index >= _length) return 0;
241249
return busses.getPixelColorRestored(index);
242250
}

wled00/FX_fcn.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,9 @@ void Segment::refreshLightCapabilities() {
13661366
// we are withing 2D matrix (includes 1D segments)
13671367
for (int y = startY; y < stopY; y++) for (int x = start; x < stop; x++) {
13681368
uint16_t index = x + Segment::maxWidth * y;
1369+
#ifndef WLEDMM_REMAP_AT_OUTPUT
13691370
if (index < strip.customMappingSize) index = strip.customMappingTable[index]; // convert logical address to physical
1371+
#endif
13701372
if (index < 0xFFFFU) {
13711373
if (segStartIdx > index) segStartIdx = index;
13721374
if (segStopIdx < index) segStopIdx = index;
@@ -1973,21 +1975,27 @@ void WS2812FX::service() {
19731975

19741976
void IRAM_ATTR WS2812FX::setPixelColor(int i, uint32_t col)
19751977
{
1978+
#ifndef WLEDMM_REMAP_AT_OUTPUT
19761979
if (i < customMappingSize) i = customMappingTable[i];
1980+
#endif
19771981
if (i >= _length) return;
19781982
busses.setPixelColor(i, col);
19791983
}
19801984

19811985
uint32_t WS2812FX::getPixelColor(uint_fast16_t i) const // WLEDMM fast int types
19821986
{
1987+
#ifndef WLEDMM_REMAP_AT_OUTPUT
19831988
if (i < customMappingSize) i = customMappingTable[i];
1989+
#endif
19841990
if (i >= _length) return 0;
19851991
return busses.getPixelColor(i);
19861992
}
19871993

19881994
uint32_t WS2812FX::getPixelColorRestored(uint_fast16_t i) const // WLEDMM gets the original color from the driver (without downscaling by _bri)
19891995
{
1996+
#ifndef WLEDMM_REMAP_AT_OUTPUT
19901997
if (i < customMappingSize) i = customMappingTable[i];
1998+
#endif
19911999
if (i >= _length) return 0;
19922000
return busses.getPixelColorRestored(i);
19932001
}

wled00/bus_manager.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class Bus {
158158
inline bool isOffRefreshRequired() const { return _needsRefresh; }
159159
//inline bool containsPixel(uint32_t pix) const { return pix >= _start && pix < _start+_len; } // WLEDMM not used, plus wrong - it does not consider skipped pixels
160160
virtual uint32_t getMaxPixels() const { return MAX_LEDS_PER_BUS; }
161+
virtual byte* getPixelData() { return nullptr; } // TroyHacks
161162

162163
virtual bool hasRGB() const {
163164
if ((_type >= TYPE_WS2812_1CH && _type <= TYPE_WS2812_WWA) || _type == TYPE_ANALOG_1CH || _type == TYPE_ANALOG_2CH || _type == TYPE_ONOFF) return false;
@@ -337,7 +338,7 @@ class BusNetwork : public Bus {
337338
public:
338339
BusNetwork(BusConfig &bc, const ColorOrderMap &com);
339340

340-
uint32_t getMaxPixels() const override { return 4096; };
341+
uint32_t getMaxPixels() const override { return 65536; };
341342
bool hasRGB() const { return true; }
342343
bool hasWhite() const { return _rgbw; }
343344

@@ -346,6 +347,8 @@ class BusNetwork : public Bus {
346347
uint32_t __attribute__((pure)) getPixelColor(uint32_t pix) const; // WLEDMM attribute added
347348
uint32_t __attribute__((pure)) getPixelColorRestored(uint32_t pix) const override { return getPixelColor(pix);} // WLEDMM BusNetwork ignores brightness
348349

350+
byte* getPixelData() override { return _data; }
351+
349352
void show();
350353

351354
bool canShow() override {
@@ -467,7 +470,9 @@ class BusManager {
467470

468471
void setStatusPixel(uint32_t c);
469472

470-
void setPixelColor(uint32_t pix, uint32_t c, int16_t cct=-1);
473+
void setPixelColor(uint32_t pix, uint32_t c, int16_t cct=-1);
474+
inline void setPixelColor(uint32_t pix, CRGB c, int16_t cct=-1) { setPixelColor(pix, RGBW32(c.r,c.g,c.b,0)); }
475+
inline void setPixelColorXY(int x, int y, int cols, CRGB c) { setPixelColor((x + y*cols), RGBW32(c.r,c.g,c.b,0)); } // TroyHacks we don't have a sense of a physical input having "dimensions" yet.
471476

472477
void setBrightness(uint8_t b, bool immediate=false); // immediate=true is for use in ABL, it applies brightness immediately (warning: inefficient)
473478

wled00/udp.cpp

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,14 +1086,45 @@ uint8_t IRAM_ATTR __attribute__((hot)) realtimeBroadcast(uint8_t type, IPAddress
10861086
return 0; // let's give it a frame to set up.
10871087
}
10881088

1089-
static uint16_t *parallel_buffer_repacked = NULL;
1089+
1090+
static byte *parallel_buffer_remapped = NULL;
1091+
#ifdef WLEDMM_REMAP_AT_OUTPUT
1092+
static byte *parallel_buffer_remapped1 = (byte*) heap_caps_calloc_prefer((1024 * 16 * 4)+15, sizeof(byte), 3, MALLOC_CAP_SPIRAM|MALLOC_CAP_DMA|MALLOC_CAP_32BIT|MALLOC_CAP_CACHE_ALIGNED|MALLOC_CAP_SIMD, MALLOC_CAP_DMA|MALLOC_CAP_32BIT|MALLOC_CAP_CACHE_ALIGNED|MALLOC_CAP_SIMD, MALLOC_CAP_INTERNAL);
1093+
static byte *parallel_buffer_remapped2 = (byte*) heap_caps_calloc_prefer((1024 * 16 * 4)+15, sizeof(byte), 3, MALLOC_CAP_SPIRAM|MALLOC_CAP_DMA|MALLOC_CAP_32BIT|MALLOC_CAP_CACHE_ALIGNED|MALLOC_CAP_SIMD, MALLOC_CAP_DMA|MALLOC_CAP_32BIT|MALLOC_CAP_CACHE_ALIGNED|MALLOC_CAP_SIMD, MALLOC_CAP_INTERNAL);
1094+
#endif
1095+
static uint16_t *parallel_buffer_repacked = NULL;
10901096
static uint16_t *parallel_buffer_repacked1 = (uint16_t *) heap_caps_calloc_prefer((1024 * 16 * 16), 1, 3, MALLOC_CAP_SPIRAM|MALLOC_CAP_DMA|MALLOC_CAP_32BIT|MALLOC_CAP_CACHE_ALIGNED|MALLOC_CAP_SIMD, MALLOC_CAP_DMA|MALLOC_CAP_32BIT|MALLOC_CAP_CACHE_ALIGNED|MALLOC_CAP_SIMD, MALLOC_CAP_INTERNAL);
10911097
static uint16_t *parallel_buffer_repacked2 = (uint16_t *) heap_caps_calloc_prefer((1024 * 16 * 16), 1, 3, MALLOC_CAP_SPIRAM|MALLOC_CAP_DMA|MALLOC_CAP_32BIT|MALLOC_CAP_CACHE_ALIGNED|MALLOC_CAP_SIMD, MALLOC_CAP_DMA|MALLOC_CAP_32BIT|MALLOC_CAP_CACHE_ALIGNED|MALLOC_CAP_SIMD, MALLOC_CAP_INTERNAL);
10921098

1093-
parallel_buffer_repacked = (parallel_buffer_repacked == parallel_buffer_repacked1) ? parallel_buffer_repacked2 : parallel_buffer_repacked1;
1094-
1095-
create_transposed_led_output_optimized(buffer_in, parallel_buffer_repacked, leds_per_output, outputs, isRGBW, bri);
1096-
1099+
if (parallel_buffer_repacked == NULL) parallel_buffer_repacked = parallel_buffer_repacked1;
1100+
#ifdef WLEDMM_REMAP_AT_OUTPUT
1101+
if (parallel_buffer_remapped == NULL) parallel_buffer_remapped = parallel_buffer_remapped1;
1102+
1103+
uint32_t* mappingTable = strip.getCustomMappingTable();
1104+
uint32_t mappingTableSize = strip.getCustomMappingTableSize();
1105+
int my_bytes_per_pixel = isRGBW ? 4 : 3;
1106+
1107+
uint32_t buf_pos = 0;
1108+
1109+
for (uint32_t i = 0; i < length; i++) {
1110+
uint32_t dest_pixel_index = i;
1111+
if (mappingTable && i < mappingTableSize) {
1112+
dest_pixel_index = mappingTable[i];
1113+
}
1114+
uint32_t dest_byte_pos = dest_pixel_index * my_bytes_per_pixel;
1115+
parallel_buffer_remapped[dest_byte_pos + 0] = buffer_in[buf_pos++];
1116+
parallel_buffer_remapped[dest_byte_pos + 1] = buffer_in[buf_pos++];
1117+
parallel_buffer_remapped[dest_byte_pos + 2] = buffer_in[buf_pos++];
1118+
if (isRGBW) {
1119+
parallel_buffer_remapped[dest_byte_pos + 3] = buffer_in[buf_pos++];
1120+
}
1121+
}
1122+
#else
1123+
parallel_buffer_remapped = buffer_in;
1124+
#endif
1125+
1126+
create_transposed_led_output_optimized(parallel_buffer_remapped, parallel_buffer_repacked, leds_per_output, outputs, isRGBW, bri);
1127+
10971128
// Calculate the exact size of ONE PIXEL's data in bits and bytes.
10981129
const uint32_t symbols_per_pixel = isRGBW ? 128 : 96;
10991130
const uint32_t bits_per_pixel = symbols_per_pixel * parlio_config.data_width;;
@@ -1133,6 +1164,11 @@ uint8_t IRAM_ATTR __attribute__((hot)) realtimeBroadcast(uint8_t type, IPAddress
11331164
ESP_ERROR_CHECK(parlio_tx_unit_wait_all_done(parlio_tx_unit, -1));
11341165
unsigned long after = micros();
11351166

1167+
#ifdef WLEDMM_REMAP_AT_OUTPUT
1168+
parallel_buffer_remapped = (parallel_buffer_remapped == parallel_buffer_remapped1) ? parallel_buffer_remapped2 : parallel_buffer_remapped1;
1169+
#endif
1170+
parallel_buffer_repacked = (parallel_buffer_repacked == parallel_buffer_repacked1) ? parallel_buffer_repacked2 : parallel_buffer_repacked1;
1171+
11361172
if (after-before > 50) delayMicroseconds(20);
11371173

11381174
for (int i = 0; i < num_chunks && i < 4; ++i) {

0 commit comments

Comments
 (0)