From patchwork Sun Sep 10 13:22:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 812147 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="NWutoXP7"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xqsMj15rpz9s7g for ; Sun, 10 Sep 2017 23:28:49 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id DE653C21F56; Sun, 10 Sep 2017 13:25:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id AEB75C21F75; Sun, 10 Sep 2017 13:23:49 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3C266C21E74; Sun, 10 Sep 2017 13:23:26 +0000 (UTC) Received: from mail-qk0-f196.google.com (mail-qk0-f196.google.com [209.85.220.196]) by lists.denx.de (Postfix) with ESMTPS id 3B71DC21F45 for ; Sun, 10 Sep 2017 13:23:17 +0000 (UTC) Received: by mail-qk0-f196.google.com with SMTP id o77so4071278qke.2 for ; Sun, 10 Sep 2017 06:23:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GnCbt6wDutOp1Its48Jw1KJBVrf0O/Td7i8nyOgJjQA=; b=NWutoXP7nSlXD8QxNZdmrtDGHRiHdZfY9FLDuaZxAgDWMSCKX7TOkR1JjjzaXyR7h0 V7aOvWBLK4DPVxG6zIbE/kpoNlcrUt1KYQBJpxRBcVpyi4Uj3PMYCLwrx8oPw9nFVucH 27xwbuwX6cocULjucyswWlXjZGXUL9E01CkRhijghzNejUqrKcVtxlyfLvyNkeCfda3P yIF1SWYe1Z3atUL+dy7+MUscdMr7Devm+LxOpURuY63oYpBpZAyKnm1t5LNOdS90efgq h06zDMqW9UgTLNs78skyMwM0HKdfnvi4BTVIOy2Dam4ce2vCp/8MHWJM9VFGVZKH+UVE VMEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GnCbt6wDutOp1Its48Jw1KJBVrf0O/Td7i8nyOgJjQA=; b=t4W2cOwn1b+HaCEvJiogH/j2xOJgrqRhv1LtZAuC7dmBHMZRZXSkzit6QDl0LFiYki +Df98uAU4eVSynQsVIYdU1qzPx9ik/bc5lM49456uwHujLcbXxo1lNxQGcsXr3T3Umwc 8QmbiE+Kgol+eHgJ2iQxxPcidQyvsfK9pZLScMcjUHUID0VX6ZH5CtvkTPlq1TNC71zJ f3sD6rYkJnO6F1Y0Gmzxrb64ppNYb/wD+2C1DWbx5MjSSek/+oaI+p260T84FooowrJX JPh9yysHVP8fBO+/HSQuYF4/EaXjqDcT3Ivmq7KhfWtmGeEmFOhVhvi9tswSzPYCGEA8 8wAg== X-Gm-Message-State: AHPjjUjX8HPX2PH8fGW01cxLs8JemiACHNyoFFd96cW5wfzYoqAp5BqN IvpdgCL3G3BcCzourVI= X-Google-Smtp-Source: AOwi7QB+WYqj917GWZexMVZQh2rGQJdNuJD3shb3AlahdiaVzhEDNdMZtZ0ihgUbjqPjAGMWq5c4Zg== X-Received: by 10.233.244.72 with SMTP id z8mr11594013qkl.186.1505049795877; Sun, 10 Sep 2017 06:23:15 -0700 (PDT) Received: from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a]) by smtp.gmail.com with ESMTPSA id m29sm3490521qtk.58.2017.09.10.06.23.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 10 Sep 2017 06:23:14 -0700 (PDT) From: Rob Clark To: U-Boot Mailing List Date: Sun, 10 Sep 2017 09:22:31 -0400 Message-Id: <20170910132236.14318-11-robdclark@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170910132236.14318-1-robdclark@gmail.com> References: <20170910132236.14318-1-robdclark@gmail.com> Cc: Heinrich Schuchardt , Leif Lindholm Subject: [U-Boot] [PATCH v1 10/12] dm: video: Add basic ANSI escape sequence support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Really just the subset that is needed by efi_console. Perhaps more will be added later, for example color support would be useful to implement efi_cout_set_attribute(). Signed-off-by: Rob Clark --- drivers/video/vidconsole-uclass.c | 112 ++++++++++++++++++++++++++++++++++++++ drivers/video/video-uclass.c | 4 +- include/video.h | 7 +++ include/video_console.h | 11 ++++ 4 files changed, 131 insertions(+), 3 deletions(-) diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index e081d5a0ee..7998b4cf5f 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -107,12 +108,123 @@ static void vidconsole_newline(struct udevice *dev) video_sync(dev->parent); } +/* + * Parse a number from string that ends in a non-numeric character.. + * sscanf() would be nice. This is just enough for parsing ANSI escape + * sequences. + */ +static char *parsenum(char *s, int *num) +{ + int n = 0; + + while (isdigit(*s)) { + n = (10 * n) + (*s - '0'); + s++; + } + + *num = n; + return s; +} + +static void vidconsole_escape_char(struct udevice *dev, char ch) +{ + struct vidconsole_priv *priv = dev_get_uclass_priv(dev); + + /* Sanity checking for bogus ESC sequences: */ + if (priv->escape_len >= sizeof(priv->escape_buf)) + goto error; + if (priv->escape_len == 0 && ch != '[') + goto error; + + priv->escape_buf[priv->escape_len++] = ch; + + /* + * Escape sequences are terminated by a letter, so keep + * accumulating until we get one: + */ + if (!isalpha(ch)) + return; + + /* + * clear escape mode first, otherwise things will get highly + * surprising if you hit any debug prints that come back to + * this console. + */ + priv->escape = 0; + + switch (ch) { + case 'H': + case 'f': { + int row, col; + char *s = priv->escape_buf; + + /* + * Set cursor position: [%d;%df or [%d;%dH + */ + s++; /* [ */ + s = parsenum(s, &row); + s++; /* ; */ + s = parsenum(s, &col); + + priv->ycur = row * priv->y_charsize; + priv->xcur_frac = priv->xstart_frac + + VID_TO_POS(col * priv->x_charsize); + + break; + } + case 'J': { + int mode; + + /* + * Clear part/all screen: + * [J or [0J - clear screen from cursor down + * [1J - clear screen from cursor up + * [2J - clear entire screen + * + * TODO we really only handle entire-screen case, others + * probably require some additions to video-uclass (and + * are not really needed yet by efi_console) + */ + parsenum(priv->escape_buf + 1, &mode); + + if (mode == 2) { + video_clear(dev->parent); + video_sync(dev->parent); + priv->ycur = 0; + priv->xcur_frac = priv->xstart_frac; + } else { + debug("unsupported clear mode: %d\n", mode); + } + break; + } + default: + debug("unrecognized escape sequence: %*s\n", + priv->escape_len, priv->escape_buf); + } + + return; + +error: + /* something went wrong, just revert to normal mode: */ + priv->escape = 0; + return; +} + int vidconsole_put_char(struct udevice *dev, char ch) { struct vidconsole_priv *priv = dev_get_uclass_priv(dev); int ret; + if (priv->escape) { + vidconsole_escape_char(dev, ch); + return 0; + } + switch (ch) { + case '\x1b': + priv->escape_len = 0; + priv->escape = 1; + break; case '\a': /* beep */ break; diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c index 3036e3a1f2..0163039821 100644 --- a/drivers/video/video-uclass.c +++ b/drivers/video/video-uclass.c @@ -87,7 +87,7 @@ int video_reserve(ulong *addrp) return 0; } -static int video_clear(struct udevice *dev) +void video_clear(struct udevice *dev) { struct video_priv *priv = dev_get_uclass_priv(dev); @@ -100,8 +100,6 @@ static int video_clear(struct udevice *dev) } else { memset(priv->fb, priv->colour_bg, priv->fb_size); } - - return 0; } /* Flush video activity to the caches */ diff --git a/include/video.h b/include/video.h index 5b4e78b182..61ff653121 100644 --- a/include/video.h +++ b/include/video.h @@ -115,6 +115,13 @@ struct video_ops { int video_reserve(ulong *addrp); /** + * video_clear() - Clear a device's frame buffer to background color. + * + * @dev: Device to clear + */ +void video_clear(struct udevice *dev); + +/** * video_sync() - Sync a device's frame buffer with its hardware * * Some frame buffers are cached or have a secondary frame buffer. This diff --git a/include/video_console.h b/include/video_console.h index 26047934da..9dce234bd9 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -29,6 +29,9 @@ * @xsize_frac: Width of the display in fractional units * @xstart_frac: Left margin for the text console in fractional units * @last_ch: Last character written to the text console on this line + * @escape: TRUE if currently accumulating an ANSI escape sequence + * @escape_len: Length of accumulated escape sequence so far + * @escape_buf: Buffer to accumulate escape sequence */ struct vidconsole_priv { struct stdio_dev sdev; @@ -42,6 +45,14 @@ struct vidconsole_priv { int xsize_frac; int xstart_frac; int last_ch; + /* + * ANSI escape sequences are accumulated character by character, + * starting after the ESC char (0x1b) until the entire sequence + * is consumed at which point it is acted upon. + */ + int escape; + int escape_len; + char escape_buf[32]; }; /**