common/lcd.c is a mix of code portions that do different but related things. To improve modularity, the various code portions should be split into their own modules. Separate lcd console code into its own file. Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il> Cc: Anatolij Gustschin <agust@denx.de> Cc: Simon Glass <sjg@chromium.org> Cc: Stephen Warren <swarren@wwwdotorg.org> Acked-by: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org>master
parent
88b326a31e
commit
904672ee48
@ -0,0 +1,215 @@ |
||||
/*
|
||||
* (C) Copyright 2001-2014 |
||||
* DENX Software Engineering -- wd@denx.de |
||||
* Compulab Ltd - http://compulab.co.il/
|
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
#include <lcd.h> |
||||
#include <video_font.h> /* 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_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE) |
||||
#define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \ |
||||
- CONSOLE_ROW_SIZE) |
||||
#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * console_rows) |
||||
#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE) |
||||
|
||||
static short console_curr_col; |
||||
static short console_curr_row; |
||||
static short console_cols; |
||||
static short console_rows; |
||||
static void *lcd_console_address; |
||||
|
||||
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; |
||||
} |
||||
|
||||
void lcd_set_col(short col) |
||||
{ |
||||
console_curr_col = col; |
||||
} |
||||
|
||||
void lcd_set_row(short row) |
||||
{ |
||||
console_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); |
||||
} |
||||
|
||||
int lcd_get_screen_rows(void) |
||||
{ |
||||
return console_rows; |
||||
} |
||||
|
||||
int lcd_get_screen_columns(void) |
||||
{ |
||||
return console_cols; |
||||
} |
||||
|
||||
static void lcd_drawchars(ushort x, ushort y, uchar *str, int count) |
||||
{ |
||||
uchar *dest; |
||||
ushort row; |
||||
int fg_color, bg_color; |
||||
|
||||
dest = (uchar *)(lcd_console_address + |
||||
y * lcd_line_length + x * NBITS(LCD_BPP) / 8); |
||||
|
||||
for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) { |
||||
uchar *s = str; |
||||
int i; |
||||
#if LCD_BPP == LCD_COLOR16 |
||||
ushort *d = (ushort *)dest; |
||||
#elif LCD_BPP == LCD_COLOR32 |
||||
u32 *d = (u32 *)dest; |
||||
#else |
||||
uchar *d = dest; |
||||
#endif |
||||
|
||||
fg_color = lcd_getfgcolor(); |
||||
bg_color = lcd_getbgcolor(); |
||||
for (i = 0; i < count; ++i) { |
||||
uchar c, bits; |
||||
|
||||
c = *s++; |
||||
bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row]; |
||||
|
||||
for (c = 0; c < 8; ++c) { |
||||
*d++ = (bits & 0x80) ? fg_color : bg_color; |
||||
bits <<= 1; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
static inline void lcd_putc_xy(ushort x, ushort y, uchar c) |
||||
{ |
||||
lcd_drawchars(x, y, &c, 1); |
||||
} |
||||
|
||||
static void console_scrollup(void) |
||||
{ |
||||
const int rows = CONFIG_CONSOLE_SCROLL_LINES; |
||||
int bg_color = lcd_getbgcolor(); |
||||
|
||||
/* Copy up rows ignoring those that will be overwritten */ |
||||
memcpy(CONSOLE_ROW_FIRST, |
||||
lcd_console_address + CONSOLE_ROW_SIZE * rows, |
||||
CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows); |
||||
|
||||
/* Clear the last rows */ |
||||
#if (LCD_BPP != LCD_COLOR32) |
||||
memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows, |
||||
bg_color, CONSOLE_ROW_SIZE * rows); |
||||
#else |
||||
u32 *ppix = lcd_console_address + |
||||
CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows; |
||||
u32 i; |
||||
for (i = 0; |
||||
i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix); |
||||
i++) { |
||||
*ppix++ = bg_color; |
||||
} |
||||
#endif |
||||
lcd_sync(); |
||||
console_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; |
||||
} |
||||
|
||||
lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH, |
||||
console_curr_row * VIDEO_FONT_HEIGHT, ' '); |
||||
} |
||||
|
||||
static inline void console_newline(void) |
||||
{ |
||||
console_curr_col = 0; |
||||
|
||||
/* Check if we need to scroll the terminal */ |
||||
if (++console_curr_row >= console_rows) |
||||
console_scrollup(); |
||||
else |
||||
lcd_sync(); |
||||
} |
||||
|
||||
void lcd_putc(const char c) |
||||
{ |
||||
if (!lcd_is_enabled) { |
||||
serial_putc(c); |
||||
|
||||
return; |
||||
} |
||||
|
||||
switch (c) { |
||||
case '\r': |
||||
console_curr_col = 0; |
||||
|
||||
return; |
||||
case '\n': |
||||
console_newline(); |
||||
|
||||
return; |
||||
case '\t': /* Tab (8 chars alignment) */ |
||||
console_curr_col += 8; |
||||
console_curr_col &= ~7; |
||||
|
||||
if (console_curr_col >= console_cols) |
||||
console_newline(); |
||||
|
||||
return; |
||||
case '\b': |
||||
console_back(); |
||||
|
||||
return; |
||||
default: |
||||
lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH, |
||||
console_curr_row * VIDEO_FONT_HEIGHT, c); |
||||
if (++console_curr_col >= console_cols) |
||||
console_newline(); |
||||
} |
||||
} |
||||
|
||||
void lcd_puts(const char *s) |
||||
{ |
||||
if (!lcd_is_enabled) { |
||||
serial_puts(s); |
||||
|
||||
return; |
||||
} |
||||
|
||||
while (*s) |
||||
lcd_putc(*s++); |
||||
|
||||
lcd_sync(); |
||||
} |
||||
|
||||
void lcd_printf(const char *fmt, ...) |
||||
{ |
||||
va_list args; |
||||
char buf[CONFIG_SYS_PBSIZE]; |
||||
|
||||
va_start(args, fmt); |
||||
vsprintf(buf, fmt, args); |
||||
va_end(args); |
||||
|
||||
lcd_puts(buf); |
||||
} |
@ -0,0 +1,86 @@ |
||||
/*
|
||||
* Copyright (C) 2014, Compulab Ltd - http://compulab.co.il/
|
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
/* By default we scroll by a single line */ |
||||
#ifndef CONFIG_CONSOLE_SCROLL_LINES |
||||
#define CONFIG_CONSOLE_SCROLL_LINES 1 |
||||
#endif |
||||
|
||||
/**
|
||||
* lcd_init_console() - Initialize lcd console parameters |
||||
* |
||||
* Setup the address of console base, and the number of rows and columns the |
||||
* console has. |
||||
* |
||||
* @address: Console base address |
||||
* @rows: Number of rows in the console |
||||
* @cols: Number of columns in the console |
||||
*/ |
||||
void lcd_init_console(void *address, int rows, int cols); |
||||
|
||||
/**
|
||||
* lcd_set_col() - Set the number of the current lcd console column |
||||
* |
||||
* Set the number of the console column where the cursor is. |
||||
* |
||||
* @col: Column number |
||||
*/ |
||||
void lcd_set_col(short col); |
||||
|
||||
/**
|
||||
* lcd_set_row() - Set the number of the current lcd console row |
||||
* |
||||
* Set the number of the console row where the cursor is. |
||||
* |
||||
* @row: Row number |
||||
*/ |
||||
void lcd_set_row(short row); |
||||
|
||||
/**
|
||||
* lcd_position_cursor() - Position the cursor on the screen |
||||
* |
||||
* Position the cursor at the given coordinates on the screen. |
||||
* |
||||
* @col: Column number |
||||
* @row: Row number |
||||
*/ |
||||
void lcd_position_cursor(unsigned col, unsigned row); |
||||
|
||||
/**
|
||||
* lcd_get_screen_rows() - Get the total number of screen rows |
||||
* |
||||
* @return: Number of screen rows |
||||
*/ |
||||
int lcd_get_screen_rows(void); |
||||
|
||||
/**
|
||||
* lcd_get_screen_columns() - Get the total number of screen columns |
||||
* |
||||
* @return: Number of screen columns |
||||
*/ |
||||
int lcd_get_screen_columns(void); |
||||
|
||||
/**
|
||||
* lcd_putc() - Print to screen a single character at the location of the cursor |
||||
* |
||||
* @c: The character to print |
||||
*/ |
||||
void lcd_putc(const char c); |
||||
|
||||
/**
|
||||
* lcd_puts() - Print to screen a string at the location of the cursor |
||||
* |
||||
* @s: The string to print |
||||
*/ |
||||
void lcd_puts(const char *s); |
||||
|
||||
/**
|
||||
* lcd_printf() - Print to screen a formatted string at location of the cursor |
||||
* |
||||
* @fmt: The formatted string to print |
||||
* @...: The arguments for the formatted string |
||||
*/ |
||||
void lcd_printf(const char *fmt, ...); |
Loading…
Reference in new issue