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

📄 splash.c

📁 PXA250上的XBOOT
💻 C
字号:
/*  * $Id: splash.c,v 1.1 2003/09/24 12:13:35 jfabo Exp $ * * Copyright (C) 2003 ETC s.r.o. * * 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. * * Written by Juraj Fabo <vinco@etc.sk>, 2003. * */#include <.config.h>#ifdef	CONFIG_SPLASH_SCREEN#include "splash.h"#include "board.h"#include "format.h"#include <pxa2x0/gpio.h>#include <pxa2x0/lcd.h>#include <pxa2x0/pwm.h>#include <pxa2x0/cm.h>#include "xboot.xpm"#ifdef CONFIG_EP250_SC09Q002_AZA#define NumOfPixels	9600   	/* 320x240 8 bit = 1 pixel */#define PB_LC_X		35#define PB_LC_Y		231#define PB_LENGTH	250#define PB_PERC_PIX	2.5#define PB_DIVISOR	10#endif#ifdef CONFIG_EP250_SC16H002_ZZA#define	NumOfPixels	19200   	/* 640x240 8 bit = 1 pixel */#define PB_LC_X		70#define PB_LC_Y		231#define PB_LENGTH	500#define PB_PERC_PIX	5#define PB_DIVISOR	20#endif#ifdef CONFIG_EP250_SX19V001_Z1A#define NumOfPixels	38400   	/* 640x480 8 bit = 1 pixel */#define PB_LC_X		70#define PB_LC_Y		231#define PB_LENGTH	500#define PB_PERC_PIX	5#define PB_DIVISOR	20#endif#define	OFFSET_X	CONFIG_X_OFFSET#define OFFSET_Y	CONFIG_Y_OFFSET#define VIRTTOPHYS(a) (uint32_t)(0x14000000 + a)#pragma pack(16)volatile struct pxadma_descriptor{	uint32_t fdadr;	uint32_t fsadr;	uint32_t fidr;	uint32_t ldcmd;};volatile struct LCDbuffer{	uint32_t surface[NumOfPixels/4];	/* We need to allocate location of 32-bit values so						   divide the NumOfPixels by 4 */	uint16_t palette[4];			/* Allocate palette for 256 colors */};struct xpm_attrib {	int width;	int height;	int palette;};unsigned char convert[256];struct pxadma_descriptor fbdesc, palette;struct LCDbuffer sLCDbuffer;struct xpm_attrib myxpm;#pragma pack()static voidinit_display_accessories( void ){	GPDR0 |= GPIO0_GP16 | GPIO0_GP17;	GAFR0_U |= GAFR0_U_AF16( ALT_FN_2_OUT ) | GAFR0_U_AF17( ALT_FN_2_OUT );	PWM_PERVAL0 = 0xff;	PWM_CTRL0   = 0x0;	PWM_PWDUTY0 = 0xa0;		PWM_PERVAL1 = 0x0f;	PWM_CTRL1   = 0x3f;	PWM_PWDUTY1 = 0x00;}voiddeinit_display_accessories( void ){	/* unset second alternate function on GPIO */	GAFR0_U = GAFR0_U & ~(GAFR0_U_AF16( 0 ) | GAFR0_U_AF17( 0 ));	/* set direction to input */	GPDR0 &= ~(GPIO0_GP16 | GPIO0_GP17);	}voidinit_lcd( void ){	GPDR1 |= GPIO1_GP58 | GPIO1_GP59 | GPIO1_GP60 | GPIO1_GP61 | GPIO1_GP62 | GPIO1_GP63;	GPDR2 |= GPIO2_GP64 | GPIO2_GP65 | GPIO2_GP74 | GPIO2_GP75 | GPIO2_GP76;	GAFR1_U = GAFR1_U_AF58(ALT_FN_2_OUT) | GAFR1_U_AF59(ALT_FN_2_OUT) | GAFR1_U_AF60(ALT_FN_2_OUT) |			GAFR1_U_AF61(ALT_FN_2_OUT) | GAFR1_U_AF62(ALT_FN_2_OUT) | GAFR1_U_AF63(ALT_FN_2_OUT);	GAFR2_L = GAFR2_L_AF64(ALT_FN_2_OUT) | GAFR2_L_AF65(ALT_FN_2_OUT) | GAFR2_L_AF74(ALT_FN_2_OUT) |			GAFR2_L_AF75(ALT_FN_2_OUT) | GAFR2_L_AF76(ALT_FN_2_OUT);	EdbgOutputDebugString( "Configuring LCD Controller for " );#ifdef CONFIG_EP250_SC09Q002_AZA	EdbgOutputDebugString( "Hitachi SC09Q002-AZA\n" );	LCCR1 = LCCR1_BLW(0) | LCCR1_ELW(0) | LCCR1_HSW(0) | LCCR1_PPL(319);	LCCR2 = LCCR2_BFW(0) | LCCR2_EFW(0) | LCCR2_VSW(5) | LCCR2_LPP(239);	LCCR3 = LCCR3_BPP(0) | LCCR3_PCP | LCCR3_ACB(0xFF) | LCCR3_PCD(22);#endif /* CONFIG_EP250_SC09Q002_AZA */#ifdef CONFIG_EP250_SC16H002_ZZA	EdbgOutputDebugString( "Hitachi SC16H002-ZZA\n" );	LCCR1 = LCCR1_BLW(0) | LCCR1_ELW(0) | LCCR1_HSW(0) | LCCR1_PPL(639);	LCCR2 = LCCR2_BFW(0) | LCCR2_EFW(0) | LCCR2_VSW(2) | LCCR2_LPP(239);	LCCR3 = LCCR3_BPP(0) | LCCR3_PCP | LCCR3_ACB(0xFF) | LCCR3_PCD(11);	#endif /* CONFIG_EP250_SC16H002_ZZA */#ifdef CONFIG_EP250_SX19V001_Z1A	EdbgOutputDebugString( "Hitachi SX19V001-Z1A\n" );	LCCR1 = LCCR1_BLW(2) | LCCR1_ELW(2) | LCCR1_HSW(2) | LCCR1_PPL(639);	LCCR2 = LCCR2_BFW(0) | LCCR2_EFW(0) | LCCR2_VSW(10) | LCCR2_LPP(479);	LCCR3 = LCCR3_BPP(0) | LCCR3_PCP | LCCR3_ACB(0xFF) | LCCR3_PCD(3);#endif /* CONFIG_EP250_SX19V001_Z1A */}voiddisplay_on( void ){	GPCR2 = GPIO2_GP77;	GPDR2 |= GPIO2_GP77;	GPSR2 = GPIO2_GP77;}voiddisplay_off( void ){	GPCR2 = GPIO2_GP77;	GPDR2 |= GPIO2_GP77;	LCCR0 |= LCCR0_DIS;		/* disable LCD controller */	while (!(LCSR & LCSR_LDD))	/* wait for LCSR[LDD] == 1 */		;	LCCR0 &= ~LCCR0_DIS;	}voidput_pixel( int x, int y, char color){	unsigned int tempx_div, tempx_rem;	uint32_t oldpix = 0;	tempx_div = x / 32;	tempx_rem = x % 32;	oldpix = sLCDbuffer.surface[tempx_div + y*PB_DIVISOR] & (~(0x1 << tempx_rem));	oldpix |= color << tempx_rem;	sLCDbuffer.surface[tempx_div + y*PB_DIVISOR] = oldpix;}voiddraw_square(int x1, int y1, int x2, int y2, char color){	int i = x1, j = y1;		for (j = y1; j < y2; j++) {		for (i = x1;i < x2; i++) {			put_pixel(i, j, color);		}	}	}static voidfill(uint32_t value){	memset(sLCDbuffer.surface, value, NumOfPixels);}static voidset_palette_entry(int index, uint32_t color){	uint8_t red = 0, green = 0, blue = 0;	red = (uint8_t)((color >> 16) & 0xFF );	green = (uint8_t)((color >> 8) & 0xFF );	blue = (uint8_t)(color & 0xFF );	sLCDbuffer.palette[index] = (uint16_t)(((red & 0xf8) << 8) | ((green & 0xFC ) << 3) | (blue >> 3));}static intstring_to_int(char *string, int length){	int i, retval = 0;	for (i = 0; i < length; i++) {		retval = retval*10 + string[i] - '0';	}	return retval;}static inthexstring_to_int(char *string, int length){	int i, retval = 0, delta;	for (i = 0; i < length; i++) {		delta = ((string[i] < 58) && (string[i] > 47)) ? (string[i] - '0'):(string[i] - 55);		retval = retval*16 + delta;	}	return retval;}static voidset_xpm_palette(void){	char stemp[3];	int itemp = 0, delta = 0, palette_index = 0;	/* read first number (the picture width) */	while(*(xboot_xpm[0] + itemp) != ' '){		stemp[itemp] = *(xboot_xpm[0] + itemp);		itemp++;		delta++;	}	myxpm.width = string_to_int(stemp, delta);	/* read second number (the picture width) */	itemp++;	delta = 0;	while(*(xboot_xpm[0] + itemp) != ' '){		stemp[delta] = *(xboot_xpm[0] + itemp);		itemp++;		delta++;	}	myxpm.height = string_to_int(stemp, delta);	/* read third number (number of colors) */	itemp++;	delta = 0;	while(*(xboot_xpm[0] + itemp) != ' '){		stemp[delta] = *(xboot_xpm[0] + itemp);		itemp++;		delta++;	}	myxpm.palette = string_to_int(stemp, delta);	/* init conversion array */	for (itemp = 1; itemp <= myxpm.palette;itemp++) {		convert[*xboot_xpm[itemp]] = (unsigned char)(itemp - 1);	}		/* setting palette */	for ( palette_index = 1; palette_index <= myxpm.palette; palette_index++) {		int hexstring = 0;		itemp = 0;		while(*(xboot_xpm[palette_index] + itemp) != '#')			itemp++;		itemp++;		for(hexstring = 0; hexstring < 6; hexstring++)			stemp[hexstring] = *(xboot_xpm[palette_index] + itemp + hexstring);		set_palette_entry(palette_index-1, hexstring_to_int(stemp,6));	}}static voiddraw_xpm_picture(int X_OFFSET, int Y_OFFSET){	int x, y;	uint32_t pixel;		pixel = convert[*xboot_xpm[1]] * 0x01010101;	fill(pixel);	for (y = 0; y < myxpm.height; y++) {		for (x = 0; x < myxpm.width; x++) {			pixel = convert[*(xboot_xpm[myxpm.palette + 1 + y] + x)];			put_pixel( x + X_OFFSET, y + Y_OFFSET, (unsigned char) pixel);		}	}}voidprogress_bar(unsigned char percentage, char color){	if (percentage > 100) {		percentage = 100;	}	draw_square(PB_LC_X, PB_LC_Y, PB_LC_X + percentage*PB_PERC_PIX, PB_LC_Y + 3, color);}static voiddraw_progress_bar( void ){	draw_square(PB_LC_X - 3, PB_LC_Y - 3, PB_LC_X + PB_LENGTH + 3, PB_LC_Y + 6, 1);	draw_square(PB_LC_X - 2, PB_LC_Y - 4, PB_LC_X + PB_LENGTH + 2, PB_LC_Y + 7, 1);	draw_square(PB_LC_X - 1, PB_LC_Y - 1, PB_LC_X + PB_LENGTH + 1, PB_LC_Y + 4, 0);}intsplash_screen( void ){	uint32_t temp = 0;		/* set initial display backlight and contrast */	init_display_accessories();	/* initialize LCD controller */	init_lcd();	/* initial surface */	fill(0);	/* init_palette	according to palette contained in the initial picture */	set_xpm_palette();	/* set DMAC descriptors */	palette.fdadr = VIRTTOPHYS((uint32_t)&fbdesc );	palette.fsadr = VIRTTOPHYS((uint32_t)&sLCDbuffer.palette);	palette.fidr = 0;	palette.ldcmd = LDCMD0_LEN(16) | LDCMD0_PAL;		fbdesc.fdadr = VIRTTOPHYS((uint32_t)&fbdesc);	fbdesc.fsadr = VIRTTOPHYS((uint32_t)&sLCDbuffer.surface);	fbdesc.fidr = 0;	fbdesc.ldcmd = NumOfPixels; /* size in bytes	*/		/* clear status register */	LCSR = LCSR_SINT | LCSR_BS | LCSR_EOF | LCSR_QD | LCSR_OU | LCSR_IUU 			| LCSR_IUL | LCSR_ABC | LCSR_BER | LCSR_SOF | LCSR_LDD;	/* mask interrupts */	LCCR0 |= LCCR0_OUM | LCCR0_BM | LCCR0_QDM | LCCR0_EFM | LCCR0_IUM | LCCR0_SFM | LCCR0_LDM;	/* setup initial DMA descriptor */	FDADR0 = VIRTTOPHYS((uint32_t)&palette);	/* enable LCD controller */	LCCR0 |= LCCR0_ENB;	/* turn on display */	display_on();	/* set DMAC branch control register */	temp = VIRTTOPHYS((uint32_t)&fbdesc);	temp &= ~0xF;	temp |= FBR0_BRA | FBR0_BINT;	FBR0 = temp;		draw_xpm_picture(OFFSET_X, OFFSET_Y);	draw_progress_bar();	return 1;}#endif	/* CONFIG_SPLASH_SCREEN	  */

⌨️ 快捷键说明

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