From patchwork Thu Mar 19 08:37:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Schmelzer X-Patchwork-Id: 451780 X-Patchwork-Delegate: agust@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 4476E1400D5 for ; Thu, 19 Mar 2015 19:38:28 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7DDD54A04A; Thu, 19 Mar 2015 09:38:25 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mmGOSQD3rqIA; Thu, 19 Mar 2015 09:38:25 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5D5D2A7422; Thu, 19 Mar 2015 09:38:24 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9F381A7432 for ; Thu, 19 Mar 2015 09:38:21 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hFLub-zJrE2Y for ; Thu, 19 Mar 2015 09:38:21 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from s15287728.onlinehome-server.info (hamspirit.at [87.106.47.214]) by theia.denx.de (Postfix) with ESMTP id 178C74A047 for ; Thu, 19 Mar 2015 09:38:16 +0100 (CET) Received: from localhost (s15287728.onlinehome-server.info [127.0.0.1]) by s15287728.onlinehome-server.info (Postfix) with ESMTP id 082A58F480C9; Thu, 19 Mar 2015 08:38:16 +0000 (UTC) Received: from s15287728.onlinehome-server.info ([127.0.0.1]) by localhost (s15287728.onlinehome-server.info [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UVGUdwiEF4ez; Thu, 19 Mar 2015 08:38:10 +0000 (UTC) Received: from hannes-werkstatt.scm.lan (88-117-20-144.adsl.highway.telekom.at [88.117.20.144]) by s15287728.onlinehome-server.info (Postfix) with ESMTP id E3A5D8F480CA; Thu, 19 Mar 2015 08:38:05 +0000 (UTC) From: Hannes Petermaier To: u-boot@lists.denx.de Date: Thu, 19 Mar 2015 09:37:42 +0100 Message-Id: <1426754263-29073-4-git-send-email-oe5hpm@oevsv.at> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1426754263-29073-1-git-send-email-oe5hpm@oevsv.at> References: <1426664243-30998-2-git-send-email-oe5hpm@oevsv.at> <1426754263-29073-1-git-send-email-oe5hpm@oevsv.at> Cc: Tom Rini , sjg@google.com Subject: [U-Boot] [PATCH v3 3/4] common/lcd_console: move single static variables into common (static) structure X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 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" From: Hannes Petermaier For coming implementation of lcd_console rotation, we will need some more variables for holding information about framebuffer size, rotation, ... For better readability we catch all them into a common structure. Signed-off-by: Hannes Petermaier Signed-off-by: Hannes Petermaier --- Changes in v3: None Changes in v2: None common/lcd_console.c | 76 +++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/common/lcd_console.c b/common/lcd_console.c index b7dda7a..cac77be 100644 --- a/common/lcd_console.c +++ b/common/lcd_console.c @@ -11,48 +11,49 @@ #include /* Get font data, width and height */ #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length) -#define CONSOLE_ROW_FIRST lcd_console_address -#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * console_rows) +#define CONSOLE_ROW_FIRST cons.lcd_address +#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * cons.rows) -static short console_curr_col; -static short console_curr_row; -static short console_cols; -static short console_rows; -static void *lcd_console_address; +struct console_t { + short curr_col, curr_row; + short cols, rows; + void *lcd_address; +}; +static struct console_t cons; void lcd_init_console(void *address, int rows, int cols) { - console_curr_col = 0; - console_curr_row = 0; - console_cols = cols; - console_rows = rows; - lcd_console_address = address; + memset(&cons, 0, sizeof(cons)); + cons.cols = cols; + cons.rows = rows; + cons.lcd_address = address; + } void lcd_set_col(short col) { - console_curr_col = col; + cons.curr_col = col; } void lcd_set_row(short row) { - console_curr_row = row; + cons.curr_row = row; } void lcd_position_cursor(unsigned col, unsigned row) { - console_curr_col = min_t(short, col, console_cols - 1); - console_curr_row = min_t(short, row, console_rows - 1); + cons.curr_col = min_t(short, col, cons.cols - 1); + cons.curr_row = min_t(short, row, cons.rows - 1); } int lcd_get_screen_rows(void) { - return console_rows; + return cons.rows; } int lcd_get_screen_columns(void) { - return console_cols; + return cons.cols; } static void lcd_putc_xy(ushort x, ushort y, char c) @@ -63,7 +64,7 @@ static void lcd_putc_xy(ushort x, ushort y, char c) int bg_color = lcd_getbgcolor(); int i; - dest = (uchar *)(lcd_console_address + + dest = (uchar *)(cons.lcd_address + y * lcd_line_length + x * NBITS(LCD_BPP) / 8); for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) { @@ -91,7 +92,7 @@ static void console_scrollup(void) /* Copy up rows ignoring those that will be overwritten */ memcpy(CONSOLE_ROW_FIRST, - lcd_console_address + CONSOLE_ROW_SIZE * rows, + cons.lcd_address + CONSOLE_ROW_SIZE * rows, CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows); /* Clear the last rows */ @@ -99,7 +100,7 @@ static void console_scrollup(void) memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows, bg_color, CONSOLE_ROW_SIZE * rows); #else - u32 *ppix = lcd_console_address + + u32 *ppix = cons.lcd_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows; u32 i; for (i = 0; @@ -109,27 +110,27 @@ static void console_scrollup(void) } #endif lcd_sync(); - console_curr_row -= rows; + cons.curr_row -= rows; } static inline void console_back(void) { - if (--console_curr_col < 0) { - console_curr_col = console_cols - 1; - if (--console_curr_row < 0) - console_curr_row = 0; + if (--cons.curr_col < 0) { + cons.curr_col = cons.cols - 1; + if (--cons.curr_row < 0) + cons.curr_row = 0; } - lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH, - console_curr_row * VIDEO_FONT_HEIGHT, ' '); + lcd_putc_xy(cons.curr_col * VIDEO_FONT_WIDTH, + cons.curr_row * VIDEO_FONT_HEIGHT, ' '); } static inline void console_newline(void) { - console_curr_col = 0; + cons.curr_col = 0; /* Check if we need to scroll the terminal */ - if (++console_curr_row >= console_rows) + if (++cons.curr_row >= cons.rows) console_scrollup(); else lcd_sync(); @@ -145,18 +146,17 @@ void lcd_putc(const char c) switch (c) { case '\r': - console_curr_col = 0; - + cons.curr_col = 0; return; case '\n': console_newline(); return; case '\t': /* Tab (8 chars alignment) */ - console_curr_col += 8; - console_curr_col &= ~7; + cons.curr_col += 8; + cons.curr_col &= ~7; - if (console_curr_col >= console_cols) + if (cons.curr_col >= cons.cols) console_newline(); return; @@ -165,9 +165,9 @@ void lcd_putc(const char c) return; default: - lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH, - console_curr_row * VIDEO_FONT_HEIGHT, c); - if (++console_curr_col >= console_cols) + lcd_putc_xy(cons.curr_col * VIDEO_FONT_WIDTH, + cons.curr_row * VIDEO_FONT_HEIGHT, c); + if (++cons.curr_col >= cons.cols) console_newline(); } }