lib: tizen: Add support for thor status notifications on video console
authorSylwester Nawrocki <s.nawrocki@samsung.com>
Tue, 8 Dec 2020 18:28:58 +0000 (19:28 +0100)
committerJaehoon Chung <jh80.chung@samsung.com>
Tue, 17 Oct 2023 04:19:27 +0000 (13:19 +0900)
This patch implements thor flashing progress bar and status notifications
on graphics console.

Change-Id: Iba4945ae26358936de1e1847d0095f97e6ab3498
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
lib/tizen/tizen.c

index 680cd5d..9331d7d 100644 (file)
@@ -9,6 +9,11 @@
 #include <malloc.h>
 #include <version.h>
 #include <libtizen.h>
+#include <thor.h>
+#include <video.h>
+#include <video_console.h>
+#include <dm/device.h>
+#include <dm/uclass.h>
 
 #include "tizen_logo_16bpp.h"
 #include "tizen_logo_16bpp_gzip.h"
@@ -177,3 +182,99 @@ void draw_thor_progress(unsigned long long int total_file_size,
        last_percent = current_percent;
 }
 #endif
+
+/* XRGB */
+#define PROGRESS_BAR_COLOR     0x0000B3F1
+#define PROGRESS_FRAME_COLOR   0x00F8FBF9
+
+static struct udevice *vidcon_dev;
+
+static inline void put_pixel(struct video_priv *vid_priv, int x, int y,
+                            unsigned int colour)
+{
+       u32 *screen = vid_priv->fb;
+       screen[y * vid_priv->xsize + x] = colour;
+}
+
+static void draw_progress_bar(unsigned int progress_value)
+{
+       struct udevice *vid_dev = vidcon_dev->parent;
+       struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
+       static int xpos, ypos, bar_width, bar_height;
+       int x, y;
+
+       if (bar_width == 0) {
+               xpos = vid_priv->ysize / 8;
+               ypos = vid_priv->ysize * 7 / 8;
+               bar_width = vid_priv->xsize - 2 * xpos;
+               bar_height = vid_priv->ysize * 6 / 256;
+       }
+
+       if (progress_value > 100)
+               progress_value = 100;
+
+       for (y = ypos; y <= ypos + bar_height; y++) {
+               put_pixel(vid_priv, xpos, y, PROGRESS_FRAME_COLOR);
+               put_pixel(vid_priv, xpos + bar_width, y, PROGRESS_FRAME_COLOR);
+       }
+
+       for (x = xpos; x - xpos < bar_width; x++) {
+               put_pixel(vid_priv, x, ypos, PROGRESS_FRAME_COLOR);
+               put_pixel(vid_priv, x, ypos + bar_height, PROGRESS_FRAME_COLOR);
+       }
+
+       for (y = ypos + 1; y < ypos + bar_height; y++)
+               for (x = 1; x < (bar_width * progress_value / 100); x++)
+                       put_pixel(vid_priv, x + xpos, y, PROGRESS_BAR_COLOR);
+
+       video_sync(vid_dev, false);
+}
+
+void thor_status_notify(enum thor_notify_type type, struct thor_notify_data *nd)
+{
+       /*  Clear rows 5, 7; output text in rows 5, 7 starting from column 5 */
+       static const char *init_text =
+               "\x1b[5,1f\x1b[2K\x1b[7,1f\x1b[2K\x1b[5,5f\x1b[31mTHOR MODE"
+               "\x1b[7,5f\x1b[31mPlease connect USB cable\33[0m\n";
+       /*  Clear row 7, output text starting from column 5 */
+       static const char *conn_text = "\x1b[7,1f\x1b[2K\x1b[7,5f"
+               "\x1b[31mWARNING: Do not power off the device\33[0m\n";
+       /* Clear row 7, output text starting from column 5 */
+       static const char *fail_text = "\x1b[7,1f\x1b[2K\n"
+               "\x1b[7,5f\x1b[31mERROR: Downloading failed!\33[0m\n";
+       unsigned int total_size, current_size;
+       int ret;
+
+       if (!vidcon_dev) {
+               ret = uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &vidcon_dev);
+               if (ret || !vidcon_dev)
+                       return;
+       }
+
+       switch (type) {
+       case THOR_NOTIFY_INIT:
+               vidconsole_put_string(vidcon_dev, init_text);
+               break;
+
+       case THOR_NOTIFY_CONNECTED:
+               vidconsole_put_string(vidcon_dev, conn_text);
+               break;
+
+       case THOR_NOTIFY_PROGRESS:
+               if (!nd)
+                       break;
+               /* Shift to prevent int overflow */
+               total_size = nd->total_size >> 6;
+               current_size = nd->current_size >> 6;
+               if (total_size)
+                       draw_progress_bar(current_size * 100 / total_size);
+               break;
+
+       case THOR_NOTIFY_DOWNLOAD_FAILED:
+               vidconsole_put_string(vidcon_dev, fail_text);
+               break;
+
+       default:
+               break;
+       }
+}