diff --git a/platformio.ini b/platformio.ini index 920a2b5..65b7986 100644 --- a/platformio.ini +++ b/platformio.ini @@ -135,7 +135,7 @@ board_build.arduino.earlephilhower.usb_pid = 0x1001 lib_deps = thomasfredericks/Bounce2 https://github.com/Cpasjuste/Adafruit_TinyUSB_Arduino#zedmd - https://github.com/PPUC/pimoroni-pico#0002c1d20a8a6c79c6a4125fe34f12815b0e2f2c + https://github.com/PPUC/hub75#012944057476da4e4e976db7ed3b5fbc0bb4f2d2 lib_ignore = SPI WiFi @@ -169,19 +169,29 @@ extends = pico board = pico build_flags = ${pico.build_flags} -DZEDMD_HD=1 + -DHUB75_MULTIPLEX_2_ROWS=1 [env:pico2_128x32] extends = pico board = rpipico2 build_flags = ${pico.build_flags} -DBOARD_HAS_PSRAM + -DHUB75_MULTIPLEX_2_ROWS=1 [env:pico2_256x64] extends = pico board = rpipico2 build_flags = ${pico.build_flags} -DBOARD_HAS_PSRAM - -DZEDMD_HD=1 + -DZEDMD_HD_HALF=1 + -DPICO_RP2350 + -DDATA_BASE_PIN=0 + -DROWSEL_BASE_PIN=6 + -DROWSEL_N_PINS=5 + -DCLK_PIN=11 + -DSTROBE_PIN=12 + -DOEN_PIN=13 + -DLATCH_BLANKING=4 [env:pico2_128x32_ppucdmd] extends = pico @@ -210,23 +220,26 @@ extends = pico board = rpipico2 build_flags = ${pico.build_flags} -DBOARD_HAS_PSRAM - -DZEDMD_HD=1 + -DZEDMD_HD_HALF=1 + -DZEDMD_NO_NETWORKING=1 + -DNO_PICO_GRAPHICS=1 + -DDISPLAY_LED_MATRIX=1 + -DMINIZ_NO_STDIO=1 + -DMINIZ_NO_TIME=1 + -DMINIZ_NO_DEFLATE_APIS=1 + -DMINIZ_NO_ARCHIVE_APIS=1 + -DMINIZ_NO_ZLIB_COMPATIBLE_NAMES=1 + -Wl,-Map,${BUILD_DIR}/firmware.map + -Os + -DRP2350 ; needed for dmdreader -DPICO_RP2350 -DPICO_RP2350A=0 ; Not RP2350A means RP2350B - -DHUB75_R0=30 - -DHUB75_G0=31 - -DHUB75_B0=32 - -DHUB75_R1=33 - -DHUB75_G1=34 - -DHUB75_B1=35 - -DHUB75_A=36 - -DHUB75_B=37 - -DHUB75_C=38 - -DHUB75_D=39 - -DHUB75_E=40 - -DHUB75_CLK=41 - -DHUB75_LAT=42 - -DHUB75_OE=43 + -DDATA_BASE_PIN=30 + -DROWSEL_BASE_PIN=36 + -DCLK_PIN=41 + -DSTROBE_PIN=42 + -DOEN_PIN=43 + -DHUB75_LINEDECODER_SM5368 [ppucdmd] platform = https://github.com/mkalkbrenner/platform-raspberrypi#issue-112 @@ -236,8 +249,8 @@ board_build.filesystem = littlefs board_build.filesystem_size = 1.5m lib_deps = thomasfredericks/Bounce2 - https://github.com/PPUC/pimoroni-pico#13f14db59efbabdbd51f0b4ab95269e18c7701ce https://github.com/PPUC/dmdreader#c627fbe48d67f094e4a59ecbea8bc4319e97a6d0 + https://github.com/PPUC/hub75#012944057476da4e4e976db7ed3b5fbc0bb4f2d2 lib_ignore = WiFi AsyncUDP @@ -257,20 +270,11 @@ build_flags = -DRP2350 ; needed for dmdreader -DPICO_RP2350 -DPICO_RP2350A=0 ; Not RP2350A means RP2350B - -DHUB75_R0=30 - -DHUB75_G0=31 - -DHUB75_B0=32 - -DHUB75_R1=33 - -DHUB75_G1=34 - -DHUB75_B1=35 - -DHUB75_A=36 - -DHUB75_B=37 - -DHUB75_C=38 - -DHUB75_D=39 - -DHUB75_E=40 - -DHUB75_CLK=41 - -DHUB75_LAT=42 - -DHUB75_OE=43 + -DDATA_BASE_PIN=30 + -DROWSEL_BASE_PIN=36 + -DCLK_PIN=41 + -DSTROBE_PIN=42 + -DOEN_PIN=43 build_unflags = -Og [env:ppucdmd_128x32] diff --git a/src/displays/PicoLedMatrix.cpp b/src/displays/PicoLedMatrix.cpp index 8ae74d6..b379d71 100644 --- a/src/displays/PicoLedMatrix.cpp +++ b/src/displays/PicoLedMatrix.cpp @@ -4,11 +4,6 @@ #include "pico/zedmd_pico.h" -static pimoroni::Hub75 *s_hub75; - -// interrupt callback required function -static void __isr dma_complete() { s_hub75->dma_complete(); } - static uint8_t r5_to_8[32]; static uint8_t g6_to_8[64]; static uint8_t b5_to_8[32]; @@ -24,61 +19,44 @@ static void init_rgb_tables() { } } -static uint16_t lut_table[256] = { - 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 22, 23, 24, 26, 27, - 29, 30, 32, 33, 35, 36, 38, 39, 41, 43, 44, 46, 48, 50, 51, - 53, 55, 57, 59, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, - 82, 84, 87, 89, 91, 93, 95, 98, 100, 102, 104, 107, 109, 112, 114, - 116, 119, 121, 124, 126, 129, 131, 134, 136, 139, 142, 144, 147, 150, 152, - 155, 158, 161, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193, 196, - 199, 202, 205, 208, 211, 214, 218, 221, 224, 227, 231, 234, 237, 241, 244, - 248, 251, 254, 258, 262, 265, 269, 272, 276, 280, 283, 287, 291, 295, 298, - 302, 306, 310, 314, 318, 322, 326, 330, 334, 338, 342, 346, 350, 354, 359, - 363, 367, 372, 376, 380, 385, 389, 394, 398, 403, 407, 412, 416, 421, 426, - 431, 435, 440, 445, 450, 455, 460, 465, 470, 475, 480, 485, 490, 495, 500, - 506, 511, 516, 522, 527, 532, 538, 543, 549, 555, 560, 566, 572, 577, 583, - 589, 595, 601, 607, 613, 619, 625, 631, 637, 643, 649, 656, 662, 668, 675, - 681, 688, 694, 701, 708, 714, 721, 728, 735, 741, 748, 755, 762, 769, 776, - 784, 791, 798, 805, 813, 820, 828, 835, 843, 850, 858, 866, 874, 881, 889, - 897, 905, 913, 921, 929, 938, 946, 954, 963, 971, 980, 988, 997, 1005, 1014, - 1023}; - PicoLedMatrix::PicoLedMatrix() { // rgb565 > rgb888 "fast" pixel conversion init_rgb_tables(); - s_hub75 = new pimoroni::Hub75( - TOTAL_WIDTH, PANEL_HEIGHT, nullptr, pimoroni::PANEL_FM6126A, false, - static_cast(color_order[rgbMode]), - lut_table); - s_hub75->start(dma_complete); + create_hub75_driver(TOTAL_WIDTH, PANEL_HEIGHT, PANEL_DP3246, false); + start_hub75_driver(); } -PicoLedMatrix::~PicoLedMatrix() { - s_hub75->stop(dma_complete); - delete s_hub75; -} +PicoLedMatrix::~PicoLedMatrix() {} void IRAM_ATTR PicoLedMatrix::DrawPixel(const uint16_t x, const uint16_t y, const uint8_t r, const uint8_t g, const uint8_t b) { - s_hub75->set_pixel(x, y + yOffset, r, g, b); + uint16_t pos = ((y + yOffset) * TOTAL_WIDTH + x) * 3; + drawBuffer[pos] = b; + drawBuffer[++pos] = g; + drawBuffer[++pos] = r; } void IRAM_ATTR PicoLedMatrix::DrawPixel(const uint16_t x, const uint16_t y, const uint16_t color) { - s_hub75->set_pixel(x, y + yOffset, r5_to_8[(color >> 11) & 0x1F], - g6_to_8[(color >> 5) & 0x3F], b5_to_8[color & 0x1F]); + uint16_t pos = ((y + yOffset) * TOTAL_WIDTH + x) * 3; + drawBuffer[pos] = r5_to_8[(color >> 11) & 0x1F]; + drawBuffer[++pos] = g6_to_8[(color >> 5) & 0x3F]; + drawBuffer[++pos] = b5_to_8[color & 0x1F]; } -void PicoLedMatrix::ClearScreen() { s_hub75->clear(); } +void PicoLedMatrix::ClearScreen() { memset(drawBuffer, 0, sizeof(drawBuffer)); } void PicoLedMatrix::SetBrightness(const uint8_t level) { // TODO: verify this (compare with an "esp board") ? const auto b = static_cast(static_cast(level) * 1.5f); - s_hub75->brightness = b; + setBasisBrightness(b); +} + +void PicoLedMatrix::Render() { + // double buffering is handled inside the hub75 driver + update_bgr(drawBuffer); } -void PicoLedMatrix::Render() { s_hub75->render(); } #endif // PICO_BUILD diff --git a/src/displays/PicoLedMatrix.h b/src/displays/PicoLedMatrix.h index afbc5a9..9a6c68f 100644 --- a/src/displays/PicoLedMatrix.h +++ b/src/displays/PicoLedMatrix.h @@ -2,7 +2,7 @@ #define PICO_LED_MATRIX_H #include "LedMatrix.h" -#include "hub75.hpp" +#include class PicoLedMatrix final : public LedMatrix { public: @@ -18,13 +18,16 @@ class PicoLedMatrix final : public LedMatrix { void Render() override; private: - uint8_t color_order[6] = { - static_cast(pimoroni::Hub75::COLOR_ORDER::RGB), - static_cast(pimoroni::Hub75::COLOR_ORDER::BRG), - static_cast(pimoroni::Hub75::COLOR_ORDER::GBR), - static_cast(pimoroni::Hub75::COLOR_ORDER::RBG), - static_cast(pimoroni::Hub75::COLOR_ORDER::GRB), - static_cast(pimoroni::Hub75::COLOR_ORDER::BGR)}; + /* + uint8_t color_order[6] = { + static_cast(pimoroni::Hub75::COLOR_ORDER::RGB), + static_cast(pimoroni::Hub75::COLOR_ORDER::BRG), + static_cast(pimoroni::Hub75::COLOR_ORDER::GBR), + static_cast(pimoroni::Hub75::COLOR_ORDER::RBG), + static_cast(pimoroni::Hub75::COLOR_ORDER::GRB), + static_cast(pimoroni::Hub75::COLOR_ORDER::BGR)}; + */ + uint8_t drawBuffer[TOTAL_WIDTH * PANEL_HEIGHT * 3]; }; #endif // PICO_LED_MATRIX_H diff --git a/src/main.cpp b/src/main.cpp index 81039bc..aad100a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -575,7 +575,7 @@ void LoadUsbPackageSizeMultiplier() { #ifdef ZEDMD_HD_HALF void SaveYOffset() { File f = LittleFS.open("/y_offset.val", "w"); - f.write(yOffset); + f.write(static_cast(yOffset)); f.close(); } @@ -585,7 +585,7 @@ void LoadYOffset() { SaveYOffset(); return; } - yOffset = f.read(); + yOffset = static_cast(f.read()); f.close(); } #endif @@ -2594,4 +2594,5 @@ void loop1() { delay(1); } } + #endif