From 3d09e80160320113df42b76154ce5baeb2d94b79 Mon Sep 17 00:00:00 2001
From: schneider <schneider@blinkenlichts.net>
Date: Sun, 10 Jan 2021 20:55:14 +0100
Subject: [PATCH] change(display): Update blit documentation

---
 epicardium/epicardium.h         |  2 +-
 pycardium/modules/py/display.py | 67 ++++++++++++++++++++++++++++-----
 2 files changed, 59 insertions(+), 10 deletions(-)

diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h
index 48f7d4d6a..5f69fee25 100644
--- a/epicardium/epicardium.h
+++ b/epicardium/epicardium.h
@@ -1670,7 +1670,7 @@ API(API_DISP_PIXEL, int epic_disp_pixel(
  * :param w: image width
  * :param h: image height
  * :param img: image data (rgb565)
- * :param alpah: 8 bit alpha channel. Currently unused.
+ * :param alpha: 8 bit alpha channel. Currently unused.
  */
 API(API_DISP_BLIT, int epic_disp_blit(
 	int16_t x,
diff --git a/pycardium/modules/py/display.py b/pycardium/modules/py/display.py
index 20616e147..1c94d47b3 100644
--- a/pycardium/modules/py/display.py
+++ b/pycardium/modules/py/display.py
@@ -122,18 +122,67 @@ class Display:
 
     def blit(self, x, y, w, h, img, rgb565=False, alpha=None):
         """
-        Blit an image to the display
+        Draws an image on the display.
 
-        :param x: top left X coordinate
-        :param y: top left Y coordinate
-        :param w: image width
-        :param h: image height
-        :param img: a byte buffer with pixel data (RGB)
-        :param alpha: alpha mask for `img`
-        :param rgb565: Set to `True` if the data supplied is in rgb565 format
+        :param x: X coordinate
+        :param y: Y coordinate
+        :param w: Image width
+        :param h: Image height
+        :param img: Buffer with pixel data. Default format is RGB with 8 bits per channel.
+        :param alpha: Alpha mask for `img`
+        :param rgb565: Set to `True` if the data supplied is in rgb565 format instead of 8 bit RGB.
 
         .. note::
-           The alpha channel is not implemented yet.
+           Alpha mask support is not yet implemented.
+
+        .. versionadded:: 1.17
+
+        **Example with RGB data:**
+
+        .. code-block:: python
+
+           import display
+           import color
+
+           # Draw a blue 32x20 pixel rectangle:
+           # Each pixel is 3 bytes big. Order is red, green, blue
+           img = bytes(color.BLUE) * 32 * 20
+           with display.open() as d:
+               d.clear()
+               d.blit(10, 10, 32, 20, img)
+               d.update()
+
+
+        **Example with rgb565 data:**
+
+        .. code-block:: python
+
+           import array
+           import display
+
+           # Draw a green 32x20 pixel rectangle:
+           # 0x07E0 has all bits for green set to 1. Order is RRRR RGGG GGGB BBBB
+           img = array.array('H', [0x07E0 for x in range(32 * 20)])
+           with display.open() as d:
+               d.clear()
+               d.blit(10, 10, 32, 20, img, rgb565=True)
+               d.update()
+
+
+        **Example with a MicroPython FrameBuffer:**
+
+        .. code-block:: python
+
+           import framebuf
+           import display
+
+           # Create a 160x80 pixel frame buffer and write "Hello World" on the display
+           f = framebuf.FrameBuffer(bytearray(160 * 80 * 2), 160, 80, framebuf.RGB565)
+           with display.open() as d:
+               f.text("Hello World", 0, 0, 0xF800) # red
+               d.blit(0, 0, 160, 80, f, rgb565=True)
+               d.update()
+
 
         """
 
-- 
GitLab