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

SmartMatrix #87

Closed
wants to merge 25 commits into from
Closed
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
17 changes: 10 additions & 7 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ default_envs =
esp32_4MB_M ;; esp32 recommended default
esp32_4MB_M_eth
esp32_4MB_M_debug
esp32_4MB_XL
; esp32_4MB_XL -- temp disable
; esp32_16MB_S ;; experimental, optimized for speed
esp32_16MB_M ;; esp32 recommended for boards with 16MB flash
; esp32_16MB_M_debug
Expand All @@ -70,17 +70,17 @@ default_envs =
esp32_pico_4MB_M
esp32_4MB_PSRAM_S
; esp32_4MB_PSRAM_REV3_S ;; experimental, optimized for WROVER-E with "revision3" chip
esp32S3_8MB_S ;; experimental, optimized for speed
esp32S3_8MB_M
; esp32S3_8MB_S ;; experimental, optimized for speed
; esp32S3_8MB_M
;; esp32S3_8MB_PSRAM_M ;; experiemental
;; esp32s2_tinyUF2_PSRAM_S ;; experimental - only for adafruit -S2 boards with tinyUF2 bootloader !!!
esp32s2_PSRAM_M ;; experimental
esp32c3dev_4MB_M ;; experimental
; esp32s2_PSRAM_M ;; experimental
; esp32c3dev_4MB_M ;; experimental
seeed_esp32c3_4MB_S ;; experimental
esp32_4MB_V4_S ;; experimental
esp32_16MB_V4_S ;; experimental, optimized for speed
esp32_16MB_V4_M ;; experimental
esp32_16MB_V4_M_debug ;; experimental
; esp32_16MB_V4_M_debug ;; experimental -- temp disable
esp32_pico_4MB_V4_S ;; experimental - may work better in case you experience wifi connectivity problems
esp8266pro_16MB_S
esp8266pro_16MB_M
Expand Down Expand Up @@ -944,6 +944,7 @@ build_flags_M =
-D USERMOD_ROTARY_ENCODER_UI
-D USERMOD_AUTO_SAVE
${common_mm.animartrix_build_flags}
-D WLED_ENABLE_SMARTMATRIX
;WLEDMM: only setting WLED_DEBUG_HOST is enough, ip and port can be defined in sync settings as well
-D WLED_DEBUG_HOST='"192.168.x.x"' ;; to send debug messages over network to host 192.168.x.y - FQDN is also possible
-D WLED_DEBUG_PORT=1768 ;; port for network debugging. default = 7868
Expand All @@ -953,12 +954,14 @@ 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
paulstoffregen/OneWire@ ^2.3.7 ; used for USERMOD_DALLASTEMPERATURE -> need newer release with bugfixes for -S3; still requires TEMPERATURE_PIN < 46
olikraus/U8g2@ ^2.34.5 ; used for USERMOD_FOUR_LINE_DISPLAY -> need newer version with bugfixes for arduino-esp32 v2.0.4 (Wire inititialization)
${common_mm.animartrix_lib_deps}
https://github.com/netmindz/SmartMatrix.git#platform-2-support

build_flags_XL =
-D USERMOD_WEATHER ; WLEDMM usermod
Expand All @@ -980,7 +983,7 @@ build_flags_XL =
-D USERMOD_BME280
-D USERMOD_DHT
; -D USERMOD_SHT ;; experimental
-D USERMOD_VL53L0X_GESTURES
; -D USERMOD_VL53L0X_GESTURES ;; save space for now
-D WLED_ENABLE_PIXART
${common_mm.animartrix_build_flags}

Expand Down
25 changes: 25 additions & 0 deletions wled00/MatrixHardware_MatrixPortal_S3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#define GPIOPINOUT 99

// ADDX is output directly using GPIO
#define CLKS_DURING_LATCH 0
#define MATRIX_I2S_MODE I2S_PARALLEL_BITS_16
#define MATRIX_DATA_STORAGE_TYPE uint16_t


#define R1_PIN GPIO_NUM_42
#define G1_PIN GPIO_NUM_41
#define B1_PIN GPIO_NUM_40
#define R2_PIN GPIO_NUM_38
#define G2_PIN GPIO_NUM_39
#define B2_PIN GPIO_NUM_37

#define A_PIN GPIO_NUM_45
#define B_PIN GPIO_NUM_36
#define C_PIN GPIO_NUM_48
#define D_PIN GPIO_NUM_35
#define E_PIN GPIO_NUM_21

#define LAT_PIN GPIO_NUM_47
#define OE_PIN GPIO_NUM_14

#define CLK_PIN GPIO_NUM_2
56 changes: 56 additions & 0 deletions wled00/bus_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,56 @@ void BusNetwork::cleanup() {
_data = nullptr;
}

// ***************************************************************************

#ifdef WLED_ENABLE_SMARTMATRIX

BusSmartMatrix::BusSmartMatrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWhite) {

#define num_x 32 // how many LEDs are in one row?
#define num_y 32 // how many rows?

#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 = 24; // 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);

USER_PRINTF("BusSmartMatrix: kMatrixWidth=%u, kMatrixHeight=%u", kMatrixWidth, kMatrixHeight);

SMARTMATRIX_ALLOCATE_BUFFERS(smartMatrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);

this->_len = (kMatrixWidth * kMatrixHeight);

smartMatrix.addLayer(&backgroundLayer);
smartMatrix.begin();

this->buffer = backgroundLayer.backBuffer();

backgroundLayer.swapBuffers(true);

this->backgroundLayer = &backgroundLayer;
// this->smartMatrix = &smartMatrix;
}

void BusSmartMatrix::setPixelColor(uint16_t pix, uint32_t c) {
uint8_t r = R(c);
uint8_t g = G(c);
uint8_t b = B(c);
this->buffer[pix] = rgb24(r, g, b);
}

void BusSmartMatrix::setBrightness(uint8_t b, bool immediate) {
this->smartMatrix->setBrightness(b);
}
#endif
// ***************************************************************************

//utility to get the approx. memory usage of a given BusConfig
uint32_t BusManager::memUsage(BusConfig &bc) {
Expand All @@ -483,8 +533,14 @@ uint32_t BusManager::memUsage(BusConfig &bc) {

int BusManager::add(BusConfig &bc) {
if (getNumBusses() - getNumVirtualBusses() >= WLED_MAX_BUSSES) return -1;
USER_PRINTF("BusManager::add(bc.type=%u)\n", bc.type);
if (bc.type >= TYPE_NET_DDP_RGB && bc.type < 96) {
busses[numBusses] = new BusNetwork(bc);
#ifdef WLED_ENABLE_SMARTMATRIX
} else if (bc.type == TYPE_SMARTMATRIX) {
USER_PRINTLN("BusManager::add - Adding BusSmartMatrix");
busses[numBusses] = new BusSmartMatrix(bc);
#endif
} else if (IS_DIGITAL(bc.type)) {
busses[numBusses] = new BusDigital(bc, numBusses, colorOrderMap);
} else if (bc.type == TYPE_ONOFF) {
Expand Down
46 changes: 46 additions & 0 deletions wled00/bus_manager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#ifndef BusManager_h
#define BusManager_h

#ifdef WLED_ENABLE_SMARTMATRIX
#ifdef ARDUINO_ADAFRUIT_MATRIXPORTAL_ESP32S3
#include <MatrixHardware_MatrixPortal_S3.h>
#else
#include <MatrixHardware_ESP32_V0.h>
#endif
#include <SmartMatrix.h>
#endif
/*
* Class for addressing various light types
*/
Expand Down Expand Up @@ -38,6 +46,7 @@ struct BusConfig {
if (type >= TYPE_NET_DDP_RGB && type < 96) nPins = 4; //virtual network bus. 4 "pins" store IP address
else if (type > 47) nPins = 2;
else if (type > 40 && type < 46) nPins = NUM_PWM_PINS(type);
else if (type == TYPE_SMARTMATRIX) nPins = 0;
for (uint8_t i = 0; i < nPins; i++) pins[i] = ppins[i];
}

Expand Down Expand Up @@ -326,6 +335,43 @@ 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);

void show() {
// Serial.println("SmartMatrix: show()");
backgroundLayer->swapBuffers(true);
}

bool canShow() {
// busy swapping still
return !backgroundLayer->isSwapPending();
}

void setBrightness(uint8_t b, bool immediate);

// uint8_t getPins(uint8_t* pinArray) {} // todo

void cleanup() {}

~BusSmartMatrix() {
cleanup();
}

private:
rgb24* buffer;
SMLayerBackground<rgb24, 0u>* backgroundLayer;
// SmartMatrixHub75Calc<36, 32, 32, 0u, 0u>* smartMatrix;

};
#endif

class BusManager {
public:
Expand Down
3 changes: 3 additions & 0 deletions wled00/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@
#define TYPE_LPD8806 52
#define TYPE_P9813 53
#define TYPE_LPD6803 54

#define TYPE_SMARTMATRIX 100

//Network types (master broadcast) (80-95)
#define TYPE_NET_DDP_RGB 80 //network DDP RGB bus (master broadcast bus)
#define TYPE_NET_E131_RGB 81 //network E131 RGB bus (master broadcast bus, unused)
Expand Down
29 changes: 23 additions & 6 deletions wled00/data/settings_leds.htm
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,24 @@

memu += getMem(t, n); // calc memory

if(t >= 100 && t < 110) {
var LK = d.getElementsByName("L00")[0]; // data pin
LK.style.display = "none";
LK.required = false;
LK.value="";
}

// enumerate pins
for (p=1; p<5; p++) {
var LK = d.getElementsByName("L"+p+n)[0]; // secondary pins
if (!LK) continue;
if (((t>=80 && t<96) && p<4) || (t>49 && p==1) || (t>41 && t < 50 && (p+40 < t))) // TYPE_xxxx values from const.h
if(t >= 100 && t < 110) {
// hide pin field
LK.style.display = "none";
LK.required = false;
LK.value="";
}
else if (((t>=80 && t<96) && p<4) || (t>49 && p==1) || (t>41 && t < 50 && (p+40 < t))) // TYPE_xxxx values from const.h
{
// display pin field
LK.style.display = "inline";
Expand All @@ -190,15 +203,15 @@
}
gId("rf"+n).onclick = (t == 31) ? (()=>{return false}) : (()=>{}); // prevent change for TM1814
gRGBW |= isRGBW = ((t > 17 && t < 22) || (t > 28 && t < 32) || (t > 40 && t < 46 && t != 43) || t == 88); // RGBW checkbox, TYPE_xxxx values from const.h
gId("co"+n).style.display = ((t >= 80 && t < 96) || (t >= 40 && t < 48)) ? "none":"inline"; // hide color order for PWM
gId("co"+n).style.display = ((t >= 80 && t < 96) || (t >= 40 && t < 48)||(t >= 100 && t < 110)) ? "none":"inline"; // hide color order for PWM
gId("dig"+n+"w").style.display = (t > 28 && t < 32) ? "inline":"none"; // show swap channels dropdown
if (!(t > 28 && t < 32)) d.getElementsByName("WO"+n)[0].value = 0; // reset swapping
gId("dig"+n+"c").style.display = (t >= 40 && t < 48) ? "none":"inline"; // hide count for analog
gId("dig"+n+"r").style.display = (t >= 80 && t < 96) ? "none":"inline"; // hide reversed for virtual
gId("dig"+n+"s").style.display = ((t >= 80 && t < 96) || (t >= 40 && t < 48)) ? "none":"inline"; // hide skip 1st for virtual & analog
gId("dig"+n+"c").style.display = ((t >= 40 && t < 48)||(t >= 100 && t < 110)) ? "none":"inline"; // hide count for analog
gId("dig"+n+"r").style.display = (t >= 80) ? "none":"inline"; // hide reversed for virtual
gId("dig"+n+"s").style.display = ((t >= 80) || (t >= 40 && t < 48)) ? "none":"inline"; // hide skip 1st for virtual & analog
gId("dig"+n+"f").style.display = ((t >= 16 && t < 32) || (t >= 50 && t < 64)) ? "inline":"none"; // hide refresh
gId("dig"+n+"a").style.display = (isRGBW && t != 40) ? "inline":"none"; // auto calculate white
gId("dig"+n+"l").style.display = (t > 48 && t < 64) ? "inline":"none"; // bus clock speed
gId("dig"+n+"l").style.display = ((t > 48 && t < 64) && !(t >= 100 && t < 110)) ? "inline":"none"; // bus clock speed
gId("rev"+n).innerHTML = (t >= 40 && t < 48) ? "Inverted output":"Reversed (rotated 180°)"; // change reverse text for analog
gId("psd"+n).innerHTML = (t >= 40 && t < 48) ? "Index:":"Start:"; // change analog start description
}
Expand Down Expand Up @@ -355,6 +368,9 @@
<!--option value="81">E1.31 RGB (network)</option-->
<option value="82">Art-Net RGB (network)</option>
<option value="88">DDP RGBW (network)</option>
<option value="101">SmartMatrix 32x32</option>
<option value="102">SmartMatrix 64x32</option>
<option value="103">SmartMatrix 64x64</option>
</select><br>
<div id="co${i}" style="display:inline">Color Order:
<select name="CO${i}">
Expand Down Expand Up @@ -382,6 +398,7 @@
<div id="dig${i}a" style="display:inline"><br>Auto-calculate white channel from RGB:<br><select name="AW${i}"><option value=0>None</option><option value=1>Brighter</option><option value=2>Accurate</option><option value=3>Dual</option><option value=4>Max</option></select>&nbsp;</div>
</div>`;
f.insertAdjacentHTML("beforeend", cn);
// TODO: selective addition of SM
}
if (n==-1) {
o[--i].remove();--i;
Expand Down
2 changes: 1 addition & 1 deletion wled00/html_cpal.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Autogenerated from wled00/data/cpal/cpal.htm, do not edit!!
const uint16_t PAGE_cpal_L = 4721;
const uint8_t PAGE_cpal[] PROGMEM = {
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x13, 0xbd, 0x3b, 0x7f, 0x73, 0xdb, 0xb6,
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0xbd, 0x3b, 0x7f, 0x73, 0xdb, 0xb6,
0x92, 0xff, 0xe7, 0x53, 0x20, 0x4c, 0x5f, 0x42, 0xd6, 0x14, 0x45, 0xd2, 0xb6, 0x64, 0x4b, 0xa2,
0x3b, 0xa9, 0x93, 0x77, 0xce, 0x8d, 0xdd, 0x64, 0x5e, 0x7c, 0x6e, 0x7b, 0x3e, 0xbf, 0x31, 0x4d,
0x42, 0x12, 0x1b, 0x8a, 0xe0, 0x03, 0x21, 0xd9, 0xae, 0xac, 0xef, 0x7e, 0xbb, 0x00, 0x48, 0x91,
Expand Down
Loading