⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd.c

📁 F:worksip2440a board可启动u-boot-like.tar.gz F:worksip2440a board可启动u-boot-like.tar.gz
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Common LCD routines for supported CPUs * * (C) Copyright 2001-2002 * Wolfgang Denk, DENX Software Engineering -- wd@denx.de * * See file CREDITS for list of people who contributed to this * project. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA *//************************************************************************//* ** HEADER FILES							*//************************************************************************//* #define DEBUG */#include <config.h>#include <common.h>#include <command.h>#include <version.h>#include <stdarg.h>#include <linux/types.h>#include <devices.h>#if defined(CONFIG_POST)#include <post.h>#endif#include <lcd.h>#if defined(CONFIG_PXA250)#include <asm/byteorder.h>#endif#if defined(CONFIG_MPC823)#include <watchdog.h>#include <lcdvideo.h>#endif#ifdef CONFIG_LCD/************************************************************************//* ** FONT DATA								*//************************************************************************/#include <video_font.h>		/* Get font data, width and height	*/ulong lcd_setmem (ulong addr);static void lcd_drawchars (ushort x, ushort y, uchar *str, int count);static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);static inline void lcd_putc_xy (ushort x, ushort y, uchar  c);static int lcd_init (void *lcdbase);static int lcd_clear (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]);extern void lcd_ctrl_init (void *lcdbase);extern void lcd_enable (void);static void *lcd_logo (void);#if LCD_BPP == LCD_COLOR8extern void lcd_setcolreg (ushort regno,				ushort red, ushort green, ushort blue);#endif#if LCD_BPP == LCD_MONOCHROMEextern void lcd_initcolregs (void);#endifstatic int lcd_getbgcolor (void);static void lcd_setfgcolor (int color);static void lcd_setbgcolor (int color);char lcd_is_enabled = 0;extern vidinfo_t panel_info;#ifdef	NOT_USED_SO_FARstatic void lcd_getcolreg (ushort regno,				ushort *red, ushort *green, ushort *blue);static int lcd_getfgcolor (void);#endif	/* NOT_USED_SO_FAR *//************************************************************************//*----------------------------------------------------------------------*/static void console_scrollup (void){#if 1	/* Copy up rows ignoring the first one */	memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);	/* Clear the last one */	memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);#else	/*	 * Poor attempt to optimize speed by moving "long"s.	 * But the code is ugly, and not a bit faster :-(	 */	ulong *t = (ulong *)CONSOLE_ROW_FIRST;	ulong *s = (ulong *)CONSOLE_ROW_SECOND;	ulong    l = CONSOLE_SCROLL_SIZE / sizeof(ulong);	uchar  c = lcd_color_bg & 0xFF;	ulong val= (c<<24) | (c<<16) | (c<<8) | c;	while (l--)		*t++ = *s++;	t = (ulong *)CONSOLE_ROW_LAST;	l = CONSOLE_ROW_SIZE / sizeof(ulong);	while (l-- > 0)		*t++ = val;#endif}/*----------------------------------------------------------------------*/static inline void console_back (void){	if (--console_col < 0) {		console_col = CONSOLE_COLS-1 ;		if (--console_row < 0) {			console_row = 0;		}	}	lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,		     console_row * VIDEO_FONT_HEIGHT,		     ' ');}/*----------------------------------------------------------------------*/static inline void console_newline (void){	++console_row;	console_col = 0;	/* Check if we need to scroll the terminal */	if (console_row >= CONSOLE_ROWS) {		/* Scroll everything up */		console_scrollup () ;		--console_row;	}}/*----------------------------------------------------------------------*/void lcd_putc (const char c){	if (!lcd_is_enabled) {		serial_putc(c);		return;	}	switch (c) {	case '\r':	console_col = 0;			return;	case '\n':	console_newline();			return;	case '\t':	/* Tab (8 chars alignment) */			console_col |=  8;			console_col &= ~7;			if (console_col >= CONSOLE_COLS) {				console_newline();			}			return;	case '\b':	console_back();			return;	default:	lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,				     console_row * VIDEO_FONT_HEIGHT,				     c);			if (++console_col >= CONSOLE_COLS) {				console_newline();			}			return;	}	/* NOTREACHED */}/*----------------------------------------------------------------------*/void lcd_puts (const char *s){	if (!lcd_is_enabled) {		serial_puts (s);		return;	}	while (*s) {		lcd_putc (*s++);	}}/************************************************************************//* ** Low-Level Graphics Routines					*//************************************************************************/static void lcd_drawchars (ushort x, ushort y, uchar *str, int count){	uchar *dest;	ushort off, row;	dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);	off  = x * (1 << LCD_BPP) % 8;	for (row=0;  row < VIDEO_FONT_HEIGHT;  ++row, dest += lcd_line_length)  {		uchar *s = str;		uchar *d = dest;		int i;#if LCD_BPP == LCD_MONOCHROME		uchar rest = *d & -(1 << (8-off));		uchar sym;#endif		for (i=0; i<count; ++i) {			uchar c, bits;			c = *s++;			bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];#if LCD_BPP == LCD_MONOCHROME			sym  = (COLOR_MASK(lcd_color_fg) & bits) |			       (COLOR_MASK(lcd_color_bg) & ~bits);			*d++ = rest | (sym >> off);			rest = sym << (8-off);#elif LCD_BPP == LCD_COLOR8			for (c=0; c<8; ++c) {				*d++ = (bits & 0x80) ?						lcd_color_fg : lcd_color_bg;				bits <<= 1;			}#elif LCD_BPP == LCD_COLOR16			for (c=0; c<16; ++c) {				*d++ = (bits & 0x80) ?						lcd_color_fg : lcd_color_bg;				bits <<= 1;			}#endif		}#if LCD_BPP == LCD_MONOCHROME		*d  = rest | (*d & ((1 << (8-off)) - 1));#endif	}}/*----------------------------------------------------------------------*/static inline void lcd_puts_xy (ushort x, ushort y, uchar *s){#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)	lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s));#else	lcd_drawchars (x, y, s, strlen (s));#endif}/*----------------------------------------------------------------------*/static inline void lcd_putc_xy (ushort x, ushort y, uchar c){#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)	lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);#else	lcd_drawchars (x, y, &c, 1);#endif}/************************************************************************//**  Small utility to check that you got the colours right		*//************************************************************************/#ifdef LCD_TEST_PATTERN#define	N_BLK_VERT	2#define	N_BLK_HOR	3static int test_colors[N_BLK_HOR*N_BLK_VERT] = {	CONSOLE_COLOR_RED,	CONSOLE_COLOR_GREEN,	CONSOLE_COLOR_YELLOW,	CONSOLE_COLOR_BLUE,	CONSOLE_COLOR_MAGENTA,	CONSOLE_COLOR_CYAN,};static void test_pattern (void){	ushort v_max  = panel_info.vl_row;	ushort h_max  = panel_info.vl_col;	ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;	ushort h_step = (h_max + N_BLK_HOR  - 1) / N_BLK_HOR;	ushort v, h;	uchar *pix = (uchar *)lcd_base;	printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",		h_max, v_max, h_step, v_step);	/* WARNING: Code silently assumes 8bit/pixel */	for (v=0; v<v_max; ++v) {		uchar iy = v / v_step;		for (h=0; h<h_max; ++h) {			uchar ix = N_BLK_HOR * iy + (h/h_step);			*pix++ = test_colors[ix];		}	}}#endif /* LCD_TEST_PATTERN *//************************************************************************//* ** GENERIC Initialization Routines					*//************************************************************************/int drv_lcd_init (void){	DECLARE_GLOBAL_DATA_PTR;	device_t lcddev;	int rc;	lcd_base = (void *)(gd->fb_base);	lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;	lcd_init (lcd_base);		/* LCD initialization */	/* Device initialization */	memset (&lcddev, 0, sizeof (lcddev));	strcpy (lcddev.name, "lcd");	lcddev.ext   = 0;			/* No extensions */	lcddev.flags = DEV_FLAGS_OUTPUT;	/* Output only */	lcddev.putc  = lcd_putc;		/* 'putc' function */	lcddev.puts  = lcd_puts;		/* 'puts' function */	rc = device_register (&lcddev);	return (rc == 0) ? 1 : rc;}/*----------------------------------------------------------------------*/static int lcd_clear (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]){#if LCD_BPP == LCD_MONOCHROME	/* Setting the palette */	lcd_initcolregs();#elif LCD_BPP == LCD_COLOR8	/* Setting the palette */	lcd_setcolreg  (CONSOLE_COLOR_BLACK,       0,    0,    0);	lcd_setcolreg  (CONSOLE_COLOR_RED,	0xFF,    0,    0);	lcd_setcolreg  (CONSOLE_COLOR_GREEN,       0, 0xFF,    0);	lcd_setcolreg  (CONSOLE_COLOR_YELLOW,	0xFF, 0xFF,    0);	lcd_setcolreg  (CONSOLE_COLOR_BLUE,        0,    0, 0xFF);	lcd_setcolreg  (CONSOLE_COLOR_MAGENTA,	0xFF,    0, 0xFF);	lcd_setcolreg  (CONSOLE_COLOR_CYAN,	   0, 0xFF, 0xFF);	lcd_setcolreg  (CONSOLE_COLOR_GREY,	0xAA, 0xAA, 0xAA);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -