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

[Picture2HTML branch] Framebuffer access for GxEPD2 #111

Open
speters opened this issue Nov 5, 2024 · 4 comments
Open

[Picture2HTML branch] Framebuffer access for GxEPD2 #111

speters opened this issue Nov 5, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@speters
Copy link

speters commented Nov 5, 2024

Concerning your experiments in Picture2HTML branch:

GxEPD2 does not provide access to its framebuffer, as the buffers are marked "private".

IMO access would require patching the GxEPD2 library, as fiddling with linker scripts to get the buffer's memory location is a bad approach on PlatformIO.

The following is my untested proposal which follows Adafruit_GFX.h conventions:

diff --git i/src/GxEPD2_3C.h w/src/GxEPD2_3C.h
index 71fd96a..20cc71c 100644
--- i/src/GxEPD2_3C.h
+++ w/src/GxEPD2_3C.h
@@ -631,6 +631,11 @@ class GxEPD2_3C : public GxEPD2_GFX_BASE_CLASS
     {
       epd2.hibernate();
     }
+    // returns a pointer to the internal black buffer memory
+    uint8_t *getBuffer(void) { return _black_buffer; }
+    uint8_t *getBlackBuffer(void) { return _black_buffer; }
+    // returns a pointer to the internal color buffer memory
+    uint8_t *getColorBuffer(void) { return _color_buffer; }
   private:
     template <typename T> static inline void
     _swap_(T & a, T & b)
@@ -667,9 +672,12 @@ class GxEPD2_3C : public GxEPD2_GFX_BASE_CLASS
           break;
       }
     }
-  private:
+
+  protected:
     uint8_t _black_buffer[(GxEPD2_Type::WIDTH / 8) * page_height];
     uint8_t _color_buffer[(GxEPD2_Type::WIDTH / 8) * page_height];
+
+  private:
     bool _using_partial_mode, _second_phase, _mirror;
     uint16_t _width_bytes, _pixel_bytes;
     int16_t _current_page;
diff --git i/src/GxEPD2_4C.h w/src/GxEPD2_4C.h
index 5a31a4a..0e441f1 100644
--- i/src/GxEPD2_4C.h
+++ w/src/GxEPD2_4C.h
@@ -480,6 +480,8 @@ class GxEPD2_4C : public GxEPD2_GFX_BASE_CLASS
     {
       epd2.hibernate();
     }
+    // returns a pointer to the internal pixel buffer memory
+    uint8_t *getBuffer(void) { return _pixel_buffer; }
   private:
     template <typename T> static inline void
     _swap_(T & a, T & b)
@@ -551,8 +553,9 @@ class GxEPD2_4C : public GxEPD2_GFX_BASE_CLASS
       _prev_color4 = cv4;
       return cv4;
     }
-  private:
+  protected:
     uint8_t _pixel_buffer[(GxEPD2_Type::WIDTH / 4) * page_height];
+  private:
     bool _using_partial_mode, _second_phase, _mirror;
     uint16_t _width_bytes, _pixel_bytes;
     int16_t _current_page;
diff --git i/src/GxEPD2_BW.h w/src/GxEPD2_BW.h
index 045dc78..678123a 100644
--- i/src/GxEPD2_BW.h
+++ w/src/GxEPD2_BW.h
@@ -711,6 +711,8 @@ class GxEPD2_BW : public GxEPD2_GFX_BASE_CLASS
     {
       epd2.hibernate();
     }
+    // returns a pointer to the internal buffer memory
+    uint8_t *getBuffer(void) { return _buffer; }
   private:
     template <typename T> static inline void
     _swap_(T & a, T & b)
@@ -747,8 +749,10 @@ class GxEPD2_BW : public GxEPD2_GFX_BASE_CLASS
           break;
       }
     }
-  private:
+  protected:
     uint8_t _buffer[(GxEPD2_Type::WIDTH / 8) * page_height];
+
+  private:
     bool _using_partial_mode, _second_phase, _mirror, _reverse;
     uint16_t _width_bytes, _pixel_bytes;
     int16_t _current_page;

Best solution would be to get a feature like this directly in upstream GxEPD2 library.
I think you contacted the author Jean-Marc (@ZinggJM) before - maybe he is willing to incorporate such a feature. His repository has no "Issues" and I hesitate to file a pull request, as I have no hardware at hands currently to test it (OBP60 left on boat, no other epaper display to try).

@thooge
Copy link

thooge commented Nov 20, 2024

This seems to be the way to go.
Modified GxEPD2_BW.h with function getBuffer().
Successfully ran some tests.
Had to remove the "const".
Tests ongoing...

@speters
Copy link
Author

speters commented Dec 2, 2024

Thx, for mentioning the "const". Changed post above to reflect your findings.

@thooge
Copy link

thooge commented Dec 9, 2024

Additional mutex needed to sync page drawing task and buffer reading task (webserver).

@thooge
Copy link

thooge commented Dec 26, 2024

Code for screenshot is now available in master branch.
Uses forked GxEPD2 with buffer access for b/w.

@norbert-walter norbert-walter added the enhancement New feature or request label Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants