diff --git a/platformio.ini b/platformio.ini index 1e511cf7..09120795 100644 --- a/platformio.ini +++ b/platformio.ini @@ -953,6 +953,7 @@ lib_deps_M = OneWire@~2.3.5 ; used for USERMOD_FOUR_LINE_DISPLAY and USERMOD_DALLASTEMPERATURE olikraus/U8g2 @ ^2.28.8 ; used for USERMOD_FOUR_LINE_DISPLAY ${common_mm.animartrix_lib_deps} + https://github.com/pixelmatix/SmartMatrix.git @ 4.0.3 lib_deps_V4_M = ;https://github.com/blazoncek/OneWire.git ; includes bugfixes for inconsistent readings diff --git a/wled00/bus_manager.cpp b/wled00/bus_manager.cpp index 2f330b75..dcb668d8 100644 --- a/wled00/bus_manager.cpp +++ b/wled00/bus_manager.cpp @@ -458,6 +458,33 @@ void BusNetwork::cleanup() { _data = nullptr; } +// *************************************************************************** +BusSmartMatrix::BusSmartMatrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWhite) { + + #define num_x 64 // how many LEDs are in one row? + #define num_y 64 // how many rows? + #define brightness 255 // please be aware that reducing brightness also reduces color resolution, use only in emergency + + #define radial_filter_radius 23.0; // on 32x32, use 11 for 16x16 + + #define COLOR_DEPTH 24 // Choose the color depth used for storing pixels in the layers: 24 or 48 (24 is good for most sketches - If the sketch uses type `rgb24` directly, COLOR_DEPTH must be 24) + const uint16_t kMatrixWidth = num_x; // Set to the width of your display, must be a multiple of 8 + const uint16_t kMatrixHeight = num_y; // Set to the height of your display + const uint8_t kRefreshDepth = 48; // Tradeoff of color quality vs refresh rate, max brightness, and RAM usage. 36 is typically good, drop down to 24 if you need to. On Teensy, multiples of 3, up to 48: 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48. On ESP32: 24, 36, 48 + const uint8_t kDmaBufferRows = 4; // known working: 2-4, use 2 to save RAM, more to keep from dropping frames and automatically lowering refresh rate. (This isn't used on ESP32, leave as default) + const uint8_t kPanelType = SM_PANELTYPE_HUB75_32ROW_MOD16SCAN; // Choose the configuration that matches your panels. See more details in MatrixCommonHub75.h and the docs: https://github.com/pixelmatix/SmartMatrix/wiki + const uint32_t kMatrixOptions = (SM_HUB75_OPTIONS_NONE); // see docs for options: https://github.com/pixelmatix/SmartMatrix/wiki + const uint8_t kBackgroundLayerOptions = (SM_BACKGROUND_OPTIONS_NONE); + + SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions); + SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions); + + matrix.addLayer(&backgroundLayer); + matrix.setBrightness(brightness); + matrix.begin(); +} + +// *************************************************************************** //utility to get the approx. memory usage of a given BusConfig uint32_t BusManager::memUsage(BusConfig &bc) { diff --git a/wled00/bus_manager.h b/wled00/bus_manager.h index 220fd930..b41a93e8 100644 --- a/wled00/bus_manager.h +++ b/wled00/bus_manager.h @@ -1,6 +1,12 @@ #ifndef BusManager_h #define BusManager_h +#define WLED_ENABLE_SMARTMATRIX + +#ifdef WLED_ENABLE_SMARTMATRIX +#include +#include +#endif /* * Class for addressing various light types */ @@ -326,6 +332,41 @@ class BusNetwork : public Bus { byte *_data; }; +#ifdef WLED_ENABLE_SMARTMATRIX +class BusSmartMatrix : public Bus { + public: + BusSmartMatrix(BusConfig &bc); + + bool hasRGB() { return true; } + bool hasWhite() { return false; } + + void setPixelColor(uint16_t pix, uint32_t c); + + uint32_t __attribute__((pure)) getPixelColor(uint16_t pix); // WLEDMM attribute added + + void show(); + + bool canShow() { + // this should be a return value from UDP routine if it is still sending data out + return true; // !_broadcastLock; // TODO + } + + uint8_t getPins(uint8_t* pinArray); + + uint16_t getLength() { + return _len; + } + + void cleanup(); + + ~BusSmartMatrix() { + cleanup(); + } + + private: + +}; +#endif class BusManager { public: