From f12c0f5b53c2a4a76e387a5021e96f76e456f70b Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Sat, 1 Apr 2023 20:40:45 +0200 Subject: [PATCH] shabadge display --- .gitmodules | 3 ++ ESP32/SHAdisplay | 1 + ESP32/console_esp32.cpp | 4 +-- ESP32/console_esp32.h | 2 +- ESP32/console_shabadge.cpp | 72 ++++++++++++++++++++++++++++++++++++++ ESP32/console_shabadge.h | 28 +++++++++++++++ ESP32/main.ino | 10 +++++- ESP32/platformio.ini | 9 +++-- console.cpp | 17 +++++---- console.h | 9 +++-- 10 files changed, 135 insertions(+), 20 deletions(-) create mode 100644 .gitmodules create mode 160000 ESP32/SHAdisplay create mode 100644 ESP32/console_shabadge.cpp create mode 100644 ESP32/console_shabadge.h diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..416c72b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "ESP32/SHAdisplay"] + path = ESP32/SHAdisplay + url = https://github.com/krzychb/esp-epaper-29-dke diff --git a/ESP32/SHAdisplay b/ESP32/SHAdisplay new file mode 160000 index 0000000..18b4249 --- /dev/null +++ b/ESP32/SHAdisplay @@ -0,0 +1 @@ +Subproject commit 18b42491ceecbfdb70e0dac69a379f5787a84a5d diff --git a/ESP32/console_esp32.cpp b/ESP32/console_esp32.cpp index 2db32cb..d4026dd 100644 --- a/ESP32/console_esp32.cpp +++ b/ESP32/console_esp32.cpp @@ -14,8 +14,8 @@ #define NEOPIXELS_PIN 25 -console_esp32::console_esp32(std::atomic_uint32_t *const stop_event, bus *const b, std::vector & io_ports) : - console(stop_event, b), +console_esp32::console_esp32(std::atomic_uint32_t *const stop_event, bus *const b, std::vector & io_ports, const int t_width, const int t_height) : + console(stop_event, b, t_width, t_height), io_ports(io_ports) { } diff --git a/ESP32/console_esp32.h b/ESP32/console_esp32.h index 69254be..fd3aa30 100644 --- a/ESP32/console_esp32.h +++ b/ESP32/console_esp32.h @@ -18,7 +18,7 @@ protected: void put_char_ll(const char c) override; public: - console_esp32(std::atomic_uint32_t *const stop_event, bus *const b, std::vector & io_ports); + console_esp32(std::atomic_uint32_t *const stop_event, bus *const b, std::vector & io_ports, const int t_width, const int t_height); virtual ~console_esp32(); void put_string_lf(const std::string & what) override; diff --git a/ESP32/console_shabadge.cpp b/ESP32/console_shabadge.cpp new file mode 100644 index 0000000..e063487 --- /dev/null +++ b/ESP32/console_shabadge.cpp @@ -0,0 +1,72 @@ +// (C) 2023 by Folkert van Heusden +// Released under MIT license + +#include +#include +#include +#include + +#include "console_shabadge.h" +#include "cpu.h" +#include "error.h" +#include "utils.h" + + +#define COLORED 0 +#define UNCOLORED 1 + +console_shabadge::console_shabadge(std::atomic_uint32_t *const stop_event, bus *const b, std::vector & io_ports) : + console_esp32(stop_event, b, io_ports, 296 / 8, 128 / 8) +{ + if (epd.Init() != 0) + Serial.println("Init of DEPG0290B01 failed"); + else { + Serial.println("DEPG0290B01 initialized"); + + paint = new Paint(image, 0, 0); + + paint->SetRotate(ROTATE_270); + paint->SetWidth(128); + paint->SetHeight(296); + paint->Clear(UNCOLORED); + + epd.ClearFrameMemory(UNCOLORED); + } +} + +console_shabadge::~console_shabadge() +{ + stop_thread(); + + delete paint; +} + +void console_shabadge::put_char_ll(const char c) +{ + screen_updated = true; +} + +void console_shabadge::panel_update_thread() +{ + for(;;) { + vTaskDelay(1000 / portTICK_RATE_MS); + + if (screen_updated.exchange(false)) { + paint->Clear(UNCOLORED); + + for(int y=0; yDrawCharAt(x * 8, y * 8, c, &Font8, COLORED); + } + } + + epd.SetFrameMemory(paint->GetImage(), 0, 0, paint->GetWidth(), paint->GetHeight()); + epd.DisplayFrame(); + } + } +} diff --git a/ESP32/console_shabadge.h b/ESP32/console_shabadge.h new file mode 100644 index 0000000..73fc0a4 --- /dev/null +++ b/ESP32/console_shabadge.h @@ -0,0 +1,28 @@ +// (C) 2023 by Folkert van Heusden +// Released under MIT license + +#include +#include +#include +#include + +#include "console_esp32.h" + + +class console_shabadge : public console_esp32 +{ +private: + unsigned char image[4736]; + Paint *paint { nullptr }; + Epd epd; + + std::atomic_bool screen_updated { false }; + + void put_char_ll(const char c) override; + +public: + console_shabadge(std::atomic_uint32_t *const stop_event, bus *const b, std::vector & io_ports); + virtual ~console_shabadge(); + + void panel_update_thread() override; +}; diff --git a/ESP32/main.ino b/ESP32/main.ino index 4afd2f5..f8abb98 100644 --- a/ESP32/main.ino +++ b/ESP32/main.ino @@ -14,7 +14,11 @@ #include #include +#if defined(SHA2017) +#include "console_shabadge.h" +#else #include "console_esp32.h" +#endif #include "cpu.h" #include "debugger.h" #include "disk_backend.h" @@ -513,7 +517,11 @@ void setup() Serial_RS232.println(F("\014Console enabled on TTY")); std::vector serial_ports { &Serial_RS232, &Serial }; - cnsl = new console_esp32(&stop_event, b, serial_ports); +#if defined(SHA2017) + cnsl = new console_shabadge(&stop_event, b, serial_ports); +#else + cnsl = new console_esp32(&stop_event, b, serial_ports, 80, 25); +#endif Serial.println(F("Start line-frequency interrupt")); kw11_l *lf = new kw11_l(b, cnsl); diff --git a/ESP32/platformio.ini b/ESP32/platformio.ini index 10114bd..b36016a 100644 --- a/ESP32/platformio.ini +++ b/ESP32/platformio.ini @@ -4,10 +4,10 @@ [platformio] default_envs = ESP32-wemos src_dir = . +lib_ignore = SHAdisplay [env:ESP32-wemos] -lib_ldf_mode = deep+ -build_src_filter = +<*> -<.git/> -<.svn/> - - - - - - +build_src_filter = +<*> -<.git/> -<.svn/> - - - - - - - - platform = espressif32 board = wemos_d1_mini32 framework = arduino @@ -21,8 +21,7 @@ build_flags = -std=gnu++17 -Ofast -DESP32=1 -ggdb3 -D_GLIBCXX_USE_C99 build_unflags = -std=gnu++11 -Os [env:SHA2017-badge] -lib_ldf_mode = deep+ -build_src_filter = +<*> -<.git/> -<.svn/> - - - - - - +build_src_filter = +<*> -<.git/> -<.svn/> - - - - - - - - - platform = espressif32 board = esp32doit-devkit-v1 framework = arduino @@ -32,6 +31,6 @@ board_build.filesystem = littlefs lib_deps = greiman/SdFat@^2.1.2 adafruit/Adafruit NeoPixel bblanchon/ArduinoJson@^6.19.4 -build_flags = -std=gnu++17 -Ofast -DESP32=1 -DSHA2017 -ggdb3 -D_GLIBCXX_USE_C99 +build_flags = -std=gnu++17 -Ofast -DESP32=1 -DSHA2017 -ggdb3 -D_GLIBCXX_USE_C99 -ISHAdisplay/Arduino/libraries/epd2in9-badge -ISHAdisplay/Arduino/libraries/epdpaint -ISHAdisplay/components/epaper-29-dke build_unflags = -std=gnu++11 -Os upload_protocol = esptool diff --git a/console.cpp b/console.cpp index 4e36c8d..68f98c1 100644 --- a/console.cpp +++ b/console.cpp @@ -15,11 +15,14 @@ #include "utils.h" -console::console(std::atomic_uint32_t *const stop_event, bus *const b) : +console::console(std::atomic_uint32_t *const stop_event, bus *const b, const int t_width, const int t_height) : stop_event(stop_event), - b(b) + b(b), + t_width(t_width), + t_height(t_height) { - memset(screen_buffer, ' ', sizeof screen_buffer); + + screen_buffer = new char[t_width * t_height](); } console::~console() @@ -27,6 +30,8 @@ console::~console() // done as well in subclasses but also here to // stop lgtm.com complaining about it stop_thread(); + + delete [] screen_buffer; } void console::start_thread() @@ -187,7 +192,7 @@ void console::put_char(const char c) tx--; } else { - screen_buffer[ty][tx++] = c; + screen_buffer[ty * t_width + tx++] = c; if (tx == t_width) { tx = 0; @@ -200,11 +205,11 @@ void console::put_char(const char c) } if (ty == t_height) { - memmove(&screen_buffer[0], &screen_buffer[1], sizeof(char) * t_width * (t_height - 1)); + memmove(&screen_buffer[0 * t_width], &screen_buffer[1 * t_width], sizeof(char) * t_width * (t_height - 1)); ty--; - memset(screen_buffer[t_height - 1], ' ', t_width); + memset(&screen_buffer[(t_height - 1) * t_width], ' ', t_width); } } diff --git a/console.h b/console.h index 0cf96e3..9beed04 100644 --- a/console.h +++ b/console.h @@ -16,9 +16,6 @@ #endif -constexpr const int t_width { 80 }; -constexpr const int t_height { 25 }; - class console { private: @@ -37,7 +34,9 @@ protected: bool stop_thread_flag { false }; - char screen_buffer[t_height][t_width]; + const int t_width { 0 }; + const int t_height { 0 }; + char *screen_buffer { nullptr }; uint8_t tx { 0 }; uint8_t ty { 0 }; @@ -48,7 +47,7 @@ protected: virtual void put_char_ll(const char c) = 0; public: - console(std::atomic_uint32_t *const stop_event, bus *const b); + console(std::atomic_uint32_t *const stop_event, bus *const b, const int t_width = 80, const int t_height = 25); virtual ~console(); void start_thread();