Skip to content

Commit

Permalink
Testing heap_caps_[mc]alloc_prefer over more complex logic
Browse files Browse the repository at this point in the history
  • Loading branch information
troyhacks committed Sep 15, 2024
1 parent 1615553 commit e352889
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion wled00/FX_2Dfcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void WS2812FX::setUpMatrix() {
// #else
// customMappingTable = (uint16_t*) calloc(size, sizeof(uint16_t));
// #endif
customMappingTable = (uint16_t*) heap_caps_calloc_prefer(size, sizeof(uint16_t),MALLOC_CAP_SPIRAM,MALLOC_CAP_INTERNAL);
customMappingTable = (uint16_t*) heap_caps_calloc_prefer(size, sizeof(uint16_t),2,MALLOC_CAP_SPIRAM,MALLOC_CAP_INTERNAL);
if (customMappingTable == nullptr) {
USER_PRINTLN("setUpMatrix: alloc failed");
errorFlag = ERR_LOW_MEM; // WLEDMM raise errorflag
Expand Down
42 changes: 22 additions & 20 deletions wled00/bus_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,16 +473,17 @@ BusNetwork::BusNetwork(BusConfig &bc, const ColorOrderMap &com) : Bus(bc.type, b
break;
}
_UDPchannels = _rgbw ? 4 : 3;
#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM)
if (psramFound()){
_data = (byte*) ps_calloc((bc.count * _UDPchannels)+15, sizeof(byte)); // adding 15 as SIMD math is aligned to 16 units per calculation
} else {
_data = (byte*) calloc((bc.count * _UDPchannels)+15, sizeof(byte));
}
#else
_data = (byte*) calloc((bc.count * _UDPchannels)+15, sizeof(byte));
#endif

// #if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM)
// if (psramFound()){
// _data = (byte*) ps_calloc((bc.count * _UDPchannels)+15, sizeof(byte)); // adding 15 as SIMD math is aligned to 16 units per calculation
// } else {
// _data = (byte*) calloc((bc.count * _UDPchannels)+15, sizeof(byte));
// }
// #else
// _data = (byte*) calloc((bc.count * _UDPchannels)+15, sizeof(byte));
// #endif
_data = (byte*) heap_caps_calloc_prefer((bc.count * _UDPchannels)+15, sizeof(byte), 2, MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT);

if (_data == nullptr) return;
_len = bc.count;
_colorOrder = bc.colorOrder;
Expand Down Expand Up @@ -842,7 +843,7 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh
if (_ledsDirty) free(_ledsDirty); // should not happen

// _ledsDirty = (byte*) malloc(getBitArrayBytes(_len)); // create LEDs dirty bits
_ledsDirty = (byte*) heap_caps_malloc_prefer(getBitArrayBytes(_len),MALLOC_CAP_INTERNAL|MALLOC_CAP_DMA,MALLOC_CAP_DEFAULT); // create LEDs dirty bits
_ledsDirty = (byte*) heap_caps_malloc_prefer(getBitArrayBytes(_len),2,MALLOC_CAP_INTERNAL|MALLOC_CAP_DMA,MALLOC_CAP_DEFAULT); // create LEDs dirty bits

if (_ledsDirty == nullptr) {
realdisplay->stopDMAoutput();
Expand All @@ -855,15 +856,16 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh
setBitArray(_ledsDirty, _len, false); // reset dirty bits

if (mxconfig.double_buff == false) {
#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM)
if (psramFound()){
_ledBuffer = (CRGB*) ps_calloc(_len, sizeof(CRGB)); // create LEDs buffer (initialized to BLACK)
} else {
_ledBuffer = (CRGB*) calloc(_len, sizeof(CRGB)); // create LEDs buffer (initialized to BLACK)
}
#else
_ledBuffer = (CRGB*) calloc(_len, sizeof(CRGB)); // create LEDs buffer (initialized to BLACK)
#endif
// #if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM)
// if (psramFound()){
// _ledBuffer = (CRGB*) ps_calloc(_len, sizeof(CRGB)); // create LEDs buffer (initialized to BLACK)
// } else {
// _ledBuffer = (CRGB*) calloc(_len, sizeof(CRGB)); // create LEDs buffer (initialized to BLACK)
// }
// #else
// _ledBuffer = (CRGB*) calloc(_len, sizeof(CRGB)); // create LEDs buffer (initialized to BLACK)
// #endif
_ledBuffer = (CRGB*) heap_caps_calloc_prefer(_len, sizeof(CRGB),3,MALLOC_CAP_SPIRAM,MALLOC_CAP_INTERNAL|MALLOC_CAP_DMA,MALLOC_CAP_DEFAULT); // create LEDs buffer (initialized to BLACK)
}
}

Expand Down

0 comments on commit e352889

Please sign in to comment.