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

📄 au1100_lcd.c

📁 umon bootloader source code, support mips cpu.
💻 C
📖 第 1 页 / 共 2 页
字号:

	printf("Frame Buffer R/W...");
	// do an address=data read/write test on the frame buffer
	// PIXELS_PER_COL * PIXELS_PER_ROW is the highest pixel.  
	// Multiply by bits_per_pixel (sed_color_depth), then
	// divide by 8 to get the actual byte count.
	for (i = 0; i < LCD_FB_SIZE(lcd_color_depth); i += 2){	
		LCD_BUF(i) = i & 0xffff;
		rd16 = LCD_BUF(i);
		if(rd16 != (i & 0xffff)){
			printf("Fail at 0x%08x, WR 0x%08x, RD 0x%04x!\n",LCD_BUF_ADD + i, i, rd16);
			lcd_off();
			return -1;
		}
	} 

	printf("OK!, Press key to continue.\n");

	c = getchar();

	printf("Frame Buffer Start: 0x%08x, End 0x%08x\n",LCD_BUF_ADD, LCD_BUF_ADD + LCD_FB_SIZE(lcd_color_depth));
	if (no_wait)
	{
		printf("Begin Full Screen Color Test.\n");
		while(1){
			// fill the frame buffer with incrementing color values
			for (x = 0; x < 16; x++){
				switch (lcd_color_depth){
					case 4:  wr16 = x | x << 4 | x << 8 | x << 12; break;
					case 8:  wr16 = x | x << 8; break;
					default: wr16 = vga_lookup[x]; break;	// 16-bits bypasses the lookup table
				}
				for (i = 0; i < LCD_FB_SIZE(lcd_color_depth); i += 2){	
					LCD_BUF(i) = wr16;
				}
			} // for x
		} // while
	} // no_wait
	else
	{
		printf("Begin Full Screen Color Test, Press any key to go to next color, \'x\' to end.\n");
		while(1){
			// fill the frame buffer with incrementing color values
			for (x = 0; x < 16; x++){
				switch (lcd_color_depth){
					case 4:  wr16 = x | x << 4 | x << 8 | x << 12; break;
					case 8:  wr16 = x | x << 8; break;
					default: wr16 = vga_lookup[x]; break;	// 16-bits bypasses the lookup table
				}
				for (i = 0; i < LCD_FB_SIZE(lcd_color_depth); i += 2){	
					LCD_BUF(i) = wr16;
				}
				c = getchar();
				if (c == 'x') goto lcd_tst_next;
			} // for x
		} // while
	} // else no keycheck test

	lcd_tst_next:

	lcd_off();
	lcd_tst_mode = 0;
	return 0;
}

// lcd_scroll()
//
// Because we are most likely running out of FLASH and probably also with
// cache disabled, a brute force memcpy of the whole screen would be very
// slow, even with reduced color depths.  Instead, we define a frame buffer
// that is twice the size of our actual display.
//
// With the double buffering, we always write to the first buffer, even
// when the second buffer is active.  This allows us to scroll by adjusting
// the starting and ending addresses in the Au1100 by one row.  When we
// reach the end of our virtual buffer, we reset the starting and ending
// addresses to the first buffer.
//
ulong lcd_scroll(){

	lcd_row++;

	// clear the new row(s)
	lcd_clr_row(lcd_row);
	if (lcd_row > (ROWS_PER_SCREEN - 1)){
		lcd_clr_row(lcd_row - ROWS_PER_SCREEN);
	}
	// when lcd_y_pos is greater than ROWS_PER_SCREEN we just adjust the
	// start and end addresses in the Au1100.  If it is equal to 2 *
	// ROWS_PER_SCREEN, we reset the start and end addresses to LCD_MEM_BASE.
	if (lcd_row > (ROWS_PER_SCREEN - 1))
	{
		if (lcd_row > ((ROWS_PER_SCREEN * 2) - 1))
		{
			lcd_fb_offset = 0x00;
			lcd_row = ROWS_PER_SCREEN - 1;
		}
		else
		{
			// calculate the new offset address of the frame buffer in words
			lcd_fb_offset += (LCD_GET_ADD(1, 0, lcd_color_depth));
		}

#ifdef LCD_DBG
	lcd_tst_mode = 1;
	printf("LCD New FB Offset = 0x%08lx.\n ", lcd_fb_offset);
	lcd_tst_mode = 0;
#endif

		// we have to wait for the LCD_INT_S0 bit to go true
		// indicating the Au1100 LCD controller has read the
		// address before we write the new frame buffer address
		while (!(LCD_REG(LCD_ISTAT) & LCD_INT_S0)){}
		LCD_REG(LCD_DMA0) = LCD_DMA0_ADD((LCD_BUF_ADD + lcd_fb_offset));			//new frame buffer start address

	} // if (lcd_row > (ROWS_PER_SCREEN - 1))
	return(0);
		

} // 

//--------------------------------------------------------------------------
// lcd_clr_row()
//
// This routine writes the background color to the font row specified
//
void lcd_clr_row(int char_row){

	ulong lcd_mem_add;
	int i;
	ushort wr16;

	// clear the desired row
	lcd_mem_add = LCD_GET_ADD(char_row, 0, lcd_color_depth);

#ifdef LCD_DBG
	lcd_tst_mode = 1;
	printf("LCD Clear Row %d, FB Add 0x%08lx.\n ", char_row, lcd_mem_add);
	lcd_tst_mode = 0;
#endif

	switch (lcd_color_depth)
	{
		case 4:
			wr16 = ((lcd_bg_color << 12) | (lcd_bg_color << 8) | (lcd_bg_color << 4) | (lcd_bg_color << 0));
			for (i = 0; i < ((PIXELS_PER_ROW * FONT_HEIGHT) / 2); i += 2){
				LCD_BUF(lcd_mem_add) = wr16;
				lcd_mem_add += 2;
			} // for font_row
			break;
		case 8:
			wr16 = ((lcd_bg_color << 8) | (lcd_bg_color << 0));
			for (i = 0; i < (PIXELS_PER_ROW * FONT_HEIGHT); i += 2){
				LCD_BUF(lcd_mem_add) = wr16;
				lcd_mem_add += 2;
			} // for font_row
			break;
		case 16:
			wr16 = (lcd_bg_color << 0);
			for (i = 0; i < ((PIXELS_PER_ROW * FONT_HEIGHT) * 2); i += 2){
				LCD_BUF(lcd_mem_add) = wr16;
				lcd_mem_add += 2;
			} // for font_row
			break;
	} // switch lcd_color_depth
} // lcd_clr_row


//--------------------------------------------------------------------------
// lcd_putchar()
//
// This routine parses the character and calls lcd_writechar if it is a
// printable character
//
void lcd_putchar(char c){

	if (lcd_tst_mode) return;

	// First parse the character to see if it is printable or an acceptable control
    switch (c) {
	    case '\r':
	        lcd_col = 0;
	        return;
	    case '\n':
	        lcd_scroll();
	        return;
	    case '\b':
	        lcd_col--;
	        if (lcd_col < 0)
	        {
	            lcd_row--;
	            if (lcd_row < 0) lcd_row = 0;
	            lcd_col = COLS_PER_SCREEN - 1;
		    }
			c = 0;		// erase the character
			lcd_writechar(c);
	        break;
	    default:
	        if (((uchar)c < FIRST_CHAR) || ((uchar)c > LAST_CHAR)) return; // drop anything we can't print
			c -= FIRST_CHAR;	// get aligned to the first printable character
			lcd_writechar(c);
			// advance to next column
			lcd_col++;
		    if (lcd_col == COLS_PER_SCREEN)
		    {
				lcd_col = 0;
			    lcd_scroll();
			}
			break;
    } 

} // lcd_putchar()

//--------------------------------------------------------------------------
// lcd_writechar()
//
// This routine writes the character to the screen at the current cursor
// location.
//
void lcd_writechar(uchar c) {

	ulong lcd_mem_add;
	int font_row, font_col;
	uchar font_data8;
	ushort wr16;

	// Convert the current row,col and color depth values 
	// into an address
	lcd_mem_add = LCD_GET_ADD(lcd_row, lcd_col, lcd_color_depth);

#ifdef LCD_DBG
	lcd_tst_mode = 1;
	printf("LCD writechar at row %d, col %d, FB Add 0x%08lx.\n ", lcd_row, lcd_col, lcd_mem_add);
	lcd_tst_mode = 0;
#endif

	if (FONT_WIDTH == 8)
	{
		switch (lcd_color_depth){
			case 4:
				// Now render the font by painting one font row at a time
				for (font_row = 0; font_row < FONT_HEIGHT; font_row++){
					// get the font row of data
					font_data8 = font8x16[(c * FONT_HEIGHT) + font_row];
					for (font_col = 0; font_col < 8; font_col += 4)
					{
						// get a words worth of pixels
						wr16 = (((font_data8 & 0x80) ? lcd_fg_color << 0 : lcd_bg_color << 0)
							  | ((font_data8 & 0x40) ? lcd_fg_color << 4 : lcd_bg_color << 4)
							  | ((font_data8 & 0x20) ? lcd_fg_color << 8 : lcd_bg_color << 8)
							  | ((font_data8 & 0x10) ? lcd_fg_color << 12 : lcd_bg_color << 12));
						font_data8 = font_data8 << 4;
//						wr16 = (((font_data8 & 0x80) ? lcd_fg_color << 12 : lcd_bg_color << 12)
//							  | ((font_data8 & 0x40) ? lcd_fg_color << 8 : lcd_bg_color << 8)
//							  | ((font_data8 & 0x20) ? lcd_fg_color << 4 : lcd_bg_color << 4)
//							  | ((font_data8 & 0x10) ? lcd_fg_color << 0 : lcd_bg_color << 0));
//						font_data8 = font_data8 << 4;
						LCD_BUF(lcd_mem_add) = wr16;
						// if we are in the 2nd frame buffer, write to the 1st frame buffer also
						if (lcd_row > (ROWS_PER_SCREEN - 1)){
							LCD_BUF(lcd_mem_add - LCD_FB_SIZE(lcd_color_depth)) = wr16;
						}
						lcd_mem_add += 2;
					} // for font_col
					// go to the next pixel row
					lcd_mem_add += (LCD_ROW_SIZE(lcd_color_depth) - ((FONT_WIDTH * lcd_color_depth) / 8));
				} // for font_row
				break;

			case 8:
				// Now render the font by painting one font row at a time
				for (font_row = 0; font_row < FONT_HEIGHT; font_row++){
					// get the font row of data
					font_data8 = font8x16[(c * FONT_HEIGHT) + font_row];
					for (font_col = 0; font_col < 8; font_col += 2)
					{
						// get a words worth of pixels
						wr16 = (((font_data8 & 0x80) ? lcd_fg_color << 0 : lcd_bg_color << 0)
							  | ((font_data8 & 0x40) ? lcd_fg_color << 8 : lcd_bg_color << 8));
						font_data8 = font_data8 << 2;
//						wr16 = (((font_data8 & 0x80) ? lcd_fg_color << 8 : lcd_bg_color << 8)
//							  | ((font_data8 & 0x40) ? lcd_fg_color << 0 : lcd_bg_color << 0));
//						font_data8 = font_data8 << 2;
						LCD_BUF(lcd_mem_add) = wr16;
						// if we are in the 2nd frame buffer, write to the 1st frame buffer also
						if (lcd_row > (ROWS_PER_SCREEN - 1)){
							LCD_BUF(lcd_mem_add - LCD_FB_SIZE(lcd_color_depth)) = wr16;
						}
						lcd_mem_add += 2;
					} // for font_col
					// go to the next pixel row
					lcd_mem_add += (LCD_ROW_SIZE(lcd_color_depth) - ((FONT_WIDTH * lcd_color_depth) / 8));
				} // for font_row
				break;

			default:	// 16bpp is the default
				// Now render the font by painting one font row at a time
				for (font_row = 0; font_row < FONT_HEIGHT; font_row++){
					// get the font row of data
					font_data8 = font8x16[(c * FONT_HEIGHT) + font_row];
					for (font_col = 0; font_col < 8; font_col++)
					{
						// get a words worth of pixels
						wr16 = ((font_data8 & 0x80) ? lcd_fg_color : lcd_bg_color);
						font_data8 = font_data8 << 1;
						LCD_BUF(lcd_mem_add) = wr16;
						// if we are in the 2nd frame buffer, write to the 1st frame buffer also
						if (lcd_row > (ROWS_PER_SCREEN - 1)){
							LCD_BUF(lcd_mem_add - LCD_FB_SIZE(lcd_color_depth)) = wr16;
						}
						lcd_mem_add += 2;
					} // for font_col
					// go to the next pixel row
					lcd_mem_add += (LCD_ROW_SIZE(lcd_color_depth) - ((FONT_WIDTH * lcd_color_depth) / 8));
				} // for font_row
				break;
		} // switch lcd_color depth
	} // FONT_WIDTH == 8
	else
	{
		return;
	}
} // lcd_writechar()	

⌨️ 快捷键说明

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