From 5f8514203253a83120b0b87d1a480d50b1dbb175 Mon Sep 17 00:00:00 2001
From: Sergiusz Bazanski <q3k@q3k.org>
Date: Sun, 28 Jul 2019 21:43:43 +0200
Subject: [PATCH] epicardium/modules/display: use struct disp_frambuffer.

---
 epicardium/epicardium.h      | 35 ++++++++++++++++++++++++++++++++++-
 epicardium/modules/display.c |  4 ++--
 2 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h
index 09151042..6b8e98aa 100644
--- a/epicardium/epicardium.h
+++ b/epicardium/epicardium.h
@@ -266,6 +266,37 @@ enum disp_fillstyle {
   FILLSTYLE_FILLED = 1
 };
 
+/** Width of display in pixels */
+#define DISP_WIDTH 160
+
+/** Height of display in pixels */
+#define DISP_HEIGHT 80
+
+/** Raw framebuffer */
+struct disp_framebuffer {
+  /**
+   * The frambuffer stores pixels as RGB565, but byte swapped.
+   * That is, for every (x, y) coordinate, there are two uint8_ts
+   * storing 16 bits of pixel data.
+   *
+   * **Example: fill framebuffer with red**:
+   *
+   * .. code-block:: cpp
+   *
+   * 	struct disp_framebuffer *fb = epic_disp_framebuffer();
+   * 	uint16_t red = 0b1111100000000000;
+   * 	for (int y = 0; y < DISP_HEIGHT; y++) {
+   * 		for (int x = 0; x < DISP_WIDTH; x++) {
+   * 			fb->fb[y][x][0] = red >> 8;
+   * 			fb->fb[y][x][1] = red & 0xFF;
+   * 		}
+   * 	}
+   * 	epic_disp_update();
+   *
+   */
+  uint8_t fb[DISP_HEIGHT][DISP_WIDTH][2];
+};
+
 /**
  * Locks the display.
  *
@@ -413,8 +444,10 @@ API(API_DISP_CIRC,
 /**
  * Returns the back framebuffer (the display buffer that's currently inactive
  * that will be shown after the next call to ``epic_disp_update``.
+ *
+ * :returns: pointer to a framebuffer
  */
-API(API_DISP_FRAMEBUFFER, uint16_t *epic_disp_framebuffer());
+API(API_DISP_FRAMEBUFFER, struct disp_framebuffer *epic_disp_framebuffer());
 
 
 /**
diff --git a/epicardium/modules/display.c b/epicardium/modules/display.c
index 2cabe397..2f5cf112 100644
--- a/epicardium/modules/display.c
+++ b/epicardium/modules/display.c
@@ -125,9 +125,9 @@ int epic_disp_update()
 	}
 }
 
-uint16_t *epic_disp_framebuffer()
+struct disp_framebuffer *epic_disp_framebuffer()
 {
-	return (uint16_t*) LCD_Framebuffer();
+	return (struct disp_framebuffer*)LCD_Framebuffer();
 }
 
 int epic_disp_open()
-- 
GitLab