int mymain(void) { char * p = (char *)BMP_ADDR; char red, blue, green; int color; int i, j; puts("vga init\n"); vga_init(); puts("lcd init\n"); lcd_init(); lcd_clear_screen(0x000000); // black puts("lcd draw line\n"); lcd_draw_hline(100, 100, 640-100, 0xff0000); // red lcd_draw_hline(200, 100, 640-100, 0x00ff00); // green lcd_draw_hline(300, 100, 640-100, 0x0000ff); // blue lcd_draw_hline(400, 100, 640-100, 0xffffff); // white lcd_draw_vline(640/2, 50, 480-50, 0xffffff); // white #define POS 50 #define HALF 20 lcd_draw_cross(POS, POS, HALF); lcd_draw_cross(POS, 640-POS, HALF); lcd_draw_cross(480-POS, POS, HALF); lcd_draw_cross(480-POS, 640-POS, HALF); //while (1); // show BMP file // read bmp file // bmp file header is 54 bytes p += 54; for (i = 0; i < 272; i++) for (j = 0; j < 480; j++) { blue = *p++; green = *p++; red = *p++; color = red << 16 | green << 8 | blue << 0; lcd_draw_pixel(272-i, j, color); } while (1); return 0; }
void lcd_draw_cross(int row, int col, int halflen, int color) { lcd_draw_hline(row, col-halflen, col+halflen, color); lcd_draw_vline(col, row-halflen, row+halflen, color); return; }
void lcd_draw_cross(int row, int col, int halflen) { int color = 0xff0000; lcd_draw_hline(row, col-halflen, col+halflen, color); lcd_draw_vline(col, row-halflen, row+halflen, color); }
int main(void) { int c = 0; init_uart(); // 初始化LCD控制器 lcd_init(); // 打印菜单 while(1) { printf("\r\n###############lcd test##############\r\n"); printf("[1] lcd_clear_screen\r\n"); printf("[2] lcd_draw_cross\r\n"); printf("[3] lcd_draw_hline\r\n"); printf("[4] lcd_draw_vline\r\n"); printf("[5] lcd_draw_circle\r\n"); printf("Enter your choice:"); c = getc(); printf("%c\r\n",c); switch(c) { case '1': // 清屏 lcd_clear_screen(0xFFFFFF); break; case '2': // 划十字 lcd_draw_cross(50, 50, 20, 0x000000); break; case '3': // 划横线 lcd_draw_hline(HEIGHT/2, 100, WIDTHEIGHT-100, 0xff0000); break; case '4': // 划竖线 lcd_draw_vline(WIDTHEIGHT/2, 50, HEIGHT-50, 0xff0000); break; case '5': // 划圆 lcd_draw_circle(); break; } } return 0; }
int mymain(void) { int i; for (i = 0; i < 0x100000; i++) { *(char *)(0x30000000 + i) = 0; } #if 0 //*(volatile unsigned int *)0x48000000 = 0x2211d120; //*(volatile unsigned int *)0x48000004 = 0x00000700; //*(volatile unsigned int *)0x48000008 = 0x00000700; //*(volatile unsigned int *)0x4800000c = 0x00000700; //*(volatile unsigned int *)0x48000010 = 0x00001f4c; //*(volatile unsigned int *)0x48000014 = 0x00000700; //*(volatile unsigned int *)0x48000018 = 0x00000700; //*(volatile unsigned int *)0x4800001c = 0x00018005; //*(volatile unsigned int *)0x48000020 = 0x00018005; //*(volatile unsigned int *)0x48000024 = 0x008e0459; //*(volatile unsigned int *)0x48000028 = 0x00000032; *(volatile unsigned int *)0x4800002c = 0x00000030; //*(volatile unsigned int *)0x48000030 = 0x00000030; ; #endif #if 0 *(volatile unsigned int *)0x4c000000 = 0x00ffffff; *(volatile unsigned int *)0x4c000004 = 0x00044011; *(volatile unsigned int *)0x4c000008 = 0x00038042; *(volatile unsigned int *)0x4c00000c = 0x00fffff0; *(volatile unsigned int *)0x4c000010 = 0x00000004; *(volatile unsigned int *)0x4c000014 = 0x00000007; *(volatile unsigned int *)0x4c000018 = 0x00000000; *(volatile unsigned int *)0x4c00001c = 0x00000000; *(volatile unsigned int *)0x4c000020 = 0x00ffffff; *(volatile unsigned int *)0x4c000024 = 0x00044011; ; #endif #if 0 *(volatile unsigned int *)0x4d000000 = 0x00000000; *(volatile unsigned int *)0x4d000004 = 0x00000000; *(volatile unsigned int *)0x4d000008 = 0x00000000; *(volatile unsigned int *)0x4d00000c = 0x00000000; *(volatile unsigned int *)0x4d000010 = 0x00000000; *(volatile unsigned int *)0x4d000014 = 0x00000000; *(volatile unsigned int *)0x4d000018 = 0x00000000; *(volatile unsigned int *)0x4d00001c = 0x00000000; *(volatile unsigned int *)0x4d000020 = 0x00000000; *(volatile unsigned int *)0x4d000024 = 0x00000000; *(volatile unsigned int *)0x4d000028 = 0x00000000; *(volatile unsigned int *)0x4d00002c = 0x0000a5a5; *(volatile unsigned int *)0x4d000030 = 0x0ba5da65; *(volatile unsigned int *)0x4d000034 = 0x000a5a5f; *(volatile unsigned int *)0x4d000038 = 0x00000d6b; *(volatile unsigned int *)0x4d00003c = 0x0eb7b5ed; *(volatile unsigned int *)0x4d000040 = 0x00007dbe; *(volatile unsigned int *)0x4d000044 = 0x0007ebdf; *(volatile unsigned int *)0x4d000048 = 0x07fdfbfe; *(volatile unsigned int *)0x4d00004c = 0x00000000; *(volatile unsigned int *)0x4d000050 = 0x00000000; *(volatile unsigned int *)0x4d000054 = 0x00000000; *(volatile unsigned int *)0x4d000058 = 0x00000001; *(volatile unsigned int *)0x4d00005c = 0x00000003; *(volatile unsigned int *)0x4d000060 = 0x00000ce6; *(volatile unsigned int *)0x4d000064 = 0x00000000; *(volatile unsigned int *)0x4d000068 = 0x00000000; *(volatile unsigned int *)0x4d00006c = 0x00000000; *(volatile unsigned int *)0x4d000070 = 0x00000000; *(volatile unsigned int *)0x4d000074 = 0x00000000; ; #endif #if 0 *(volatile unsigned int *)0x56000000 = 0x007fffff; *(volatile unsigned int *)0x56000004 = 0x00000000; *(volatile unsigned int *)0x56000008 = 0x00000000; *(volatile unsigned int *)0x5600000c = 0x00000000; *(volatile unsigned int *)0x56000010 = 0x002a9655; *(volatile unsigned int *)0x56000014 = 0x0000028e; *(volatile unsigned int *)0x56000018 = 0x000007ff; *(volatile unsigned int *)0x5600001c = 0x00000000; *(volatile unsigned int *)0x56000020 = 0xaaaaaaaa; *(volatile unsigned int *)0x56000024 = 0x00000000; *(volatile unsigned int *)0x56000028 = 0x0000ffff; *(volatile unsigned int *)0x5600002c = 0x00000000; *(volatile unsigned int *)0x56000030 = 0xaaaaaaaa; *(volatile unsigned int *)0x56000034 = 0x00000000; *(volatile unsigned int *)0x56000038 = 0x0000ffff; *(volatile unsigned int *)0x5600003c = 0x00000000; *(volatile unsigned int *)0x56000040 = 0xaaaaaaaa; *(volatile unsigned int *)0x56000044 = 0x0000cfe5; *(volatile unsigned int *)0x56000048 = 0x0000ffff; *(volatile unsigned int *)0x5600004c = 0x00000000; *(volatile unsigned int *)0x56000050 = 0x000055aa; *(volatile unsigned int *)0x56000054 = 0x00000005; *(volatile unsigned int *)0x56000058 = 0x000000ff; *(volatile unsigned int *)0x5600005c = 0x00000000; *(volatile unsigned int *)0x56000060 = 0xfd95ffba; *(volatile unsigned int *)0x56000064 = 0x0000b020; *(volatile unsigned int *)0x56000068 = 0x0000ffff; *(volatile unsigned int *)0x5600006c = 0x00000000; *(volatile unsigned int *)0x56000070 = 0x00000aa0; *(volatile unsigned int *)0x56000074 = 0x0000013c; *(volatile unsigned int *)0x56000078 = 0x000007ff; *(volatile unsigned int *)0x5600007c = 0x00000000; *(volatile unsigned int *)0x56000080 = 0x00010330; *(volatile unsigned int *)0x56000084 = 0x00000000; *(volatile unsigned int *)0x56000088 = 0x00000000; *(volatile unsigned int *)0x5600008c = 0x00000000; *(volatile unsigned int *)0x56000090 = 0x00000000; *(volatile unsigned int *)0x56000094 = 0x00000000; *(volatile unsigned int *)0x56000098 = 0x00000000; *(volatile unsigned int *)0x5600009c = 0x00000000; *(volatile unsigned int *)0x560000a0 = 0x00000000; *(volatile unsigned int *)0x560000a4 = 0x00fffff0; *(volatile unsigned int *)0x560000a8 = 0x00080b00; *(volatile unsigned int *)0x560000ac = 0x0000000b; *(volatile unsigned int *)0x560000b0 = 0x32440001; *(volatile unsigned int *)0x560000b4 = 0x00000001; *(volatile unsigned int *)0x560000b8 = 0x00000000; *(volatile unsigned int *)0x560000bc = 0x00000000; *(volatile unsigned int *)0x560000c0 = 0x00b00000; *(volatile unsigned int *)0x560000c4 = 0x00000000; *(volatile unsigned int *)0x560000c8 = 0x00000000; *(volatile unsigned int *)0x560000cc = 0x00000000; *(volatile unsigned int *)0x560000d0 = 0x02aaaaaa; *(volatile unsigned int *)0x560000d4 = 0x000007ff; *(volatile unsigned int *)0x560000d8 = 0x00000000; *(volatile unsigned int *)0x560000dc = 0x00000000; *(volatile unsigned int *)0x560000e0 = 0x00000000; *(volatile unsigned int *)0x560000e4 = 0x00000000; *(volatile unsigned int *)0x560000e8 = 0x00000000; *(volatile unsigned int *)0x560000ec = 0x00000000; *(volatile unsigned int *)0x560000f0 = 0x00000000; *(volatile unsigned int *)0x560000f4 = 0x00000000; *(volatile unsigned int *)0x560000f8 = 0x00000000; *(volatile unsigned int *)0x560000fc = 0x00000000; *(volatile unsigned int *)0x4c000000 = 0x00ffffff; *(volatile unsigned int *)0x4c000004 = 0x00044011; *(volatile unsigned int *)0x4c000008 = 0x00038042; *(volatile unsigned int *)0x4c00000c = 0x00fffff0; *(volatile unsigned int *)0x4c000010 = 0x00000004; *(volatile unsigned int *)0x4c000014 = 0x00000007; *(volatile unsigned int *)0x4c000018 = 0x00000000; *(volatile unsigned int *)0x4c00001c = 0x00000000; #endif puts("uboot init regs finished \n"); #if 0 *(volatile unsigned int *)0x56000020 = 0xaaaaaaaa; *(volatile unsigned int *)0x56000024 = 0x00000000; *(volatile unsigned int *)0x56000028 = 0x0000ffff; *(volatile unsigned int *)0x56000030 = 0xaaaaaaaa; *(volatile unsigned int *)0x56000034 = 0x00000000; *(volatile unsigned int *)0x56000038 = 0x0000ffff; #endif puts("vga init\n"); vga_init(); #if 1 puts("lcd init\n"); lcd_init(); lcd_clear_screen(0x000000); // black puts("lcd draw line\n"); lcd_draw_hline(100, 100, 640-100, 0xff0000); // red lcd_draw_hline(200, 100, 640-100, 0x00ff00); // green lcd_draw_hline(300, 100, 640-100, 0x0000ff); // blue lcd_draw_hline(400, 100, 640-100, 0xffffff); // white lcd_draw_vline(640/2, 50, 480-50, 0xffffff); // white #define POS 50 #define HALF 20 lcd_draw_cross(POS, POS, HALF); lcd_draw_cross(POS, 640-POS, HALF); lcd_draw_cross(480-POS, POS, HALF); lcd_draw_cross(480-POS, 640-POS, HALF); puts("lcd test over\n"); #endif //while (1); puts("nand init\n"); // nand read 16M (size = 1M) to sdram BMP_ADDR 0x33000000 nand_init(); // read bmp from 16M puts("nand read bmp 13M\n"); nand_read(0x1000000, BMP_ADDR, 0xD00000); puts("nand read bmp finished \n"); // read wav from 32M nand_read(0x2000000, WAV_ADDR, 0x100000); #if 0 // show BMP file puts("draw bmp file\n"); lcd_draw_bmp(BMP_ADDR); lcd_clear_screen(0x000000); // black puts("draw bmp file using DMA \n"); lcd_draw_bmp_to_mem(BMP_ADDR, 0x33800000); dma_memcpy(0x33800000, 0x32000000, 0xFFFFF); puts("draw bmp file finished \n"); audio_init(); puts("play wav file\n"); play_wav(WAV_ADDR); puts("play wav file finished \n"); puts("play wav file with DMA \n"); dma_play_wav2(WAV_ADDR); puts("play wav file with DMA finished \n"); #endif // deal with IRQ *(int *)0x18 = 0xE59ff000; // ldr pc, [pc] *(int *)0x20 = (int)dma_handler; // unmask INTMSK &= ~(1<<19); // enable CPSR IRQ-bit // write to CPSR with value 0x53 // CPSR = 0x53; __asm { msr CPSR_cxsf, #0x53 } while (1) { puts("while draw bmp file \n"); lcd_draw_bmp(BMP_ADDR); //lcd_clear_screen(0x000000); // black delay(); dma_clear_lcd(); } //while (1) { } while (1); return 0; }
int mymain(void) { char * p = (char *)BMP_ADDR; char red, blue, green; int color; int i, j; vga_init(); lcd_init(); lcd_clear_screen(0x000000); // black draw_xy(0, 0, 0xff0000); draw_xy(0, 200, 0x00ff00); draw_xy(300, 0, 0x0000ff); for (i = -320; i < 320; i++) for (j = -240; j < 240; j++) { double x, y; int color = 0xff0000; x = (double)i / (double)150; y = (double)j / (double)150; color = get_fratal(x, y); draw_xy(i, j, color); //printf("i = %d, j = %d, color = %d \n", i, j, color); } while(1); lcd_draw_hline(100, 100, 640-100, 0xff0000); // red lcd_draw_hline(200, 100, 640-100, 0x00ff00); // green lcd_draw_hline(300, 100, 640-100, 0x0000ff); // blue lcd_draw_hline(400, 100, 640-100, 0xffffff); // white lcd_draw_vline(640/2, 50, 480-50, 0xffffff); // white #define POS 50 #define HALF 20 lcd_draw_cross(POS, POS, HALF); lcd_draw_cross(POS, 640-POS, HALF); lcd_draw_cross(480-POS, POS, HALF); lcd_draw_cross(480-POS, 640-POS, HALF); //while (1); // show BMP file // read bmp file // bmp file header is 54 bytes p += 54; for (i = 0; i < 272; i++) for (j = 0; j < 480; j++) { blue = *p++; green = *p++; red = *p++; color = red << 16 | green << 8 | blue << 0; lcd_draw_pixel(272-i, j, color); } while (1); return 0; }
static int lcd_init(void) { /* 1. 分配一个fb_info */ s3c_lcd = framebuffer_alloc(0, NULL); /* 参数0是额外分配的大小,设置为0 */ /* 2. 设置 */ /* 2.1 设置固定的参数 */ strcpy(s3c_lcd->fix.id, "mylcd"); s3c_lcd->fix.smem_len = 272*480*16/8; s3c_lcd->fix.type = FB_TYPE_PACKED_PIXELS; s3c_lcd->fix.visual = FB_VISUAL_TRUECOLOR; /* TFT */ s3c_lcd->fix.line_length = 480*2; /* 2.2 设置可变的参数 */ s3c_lcd->var.xres = 480; s3c_lcd->var.yres = 272; s3c_lcd->var.xres_virtual = 480; s3c_lcd->var.yres_virtual = 272; s3c_lcd->var.bits_per_pixel = 16; /* RGB:565 */ s3c_lcd->var.red.offset = 11; s3c_lcd->var.red.length = 5; s3c_lcd->var.green.offset = 5; s3c_lcd->var.green.length = 6; s3c_lcd->var.blue.offset = 0; s3c_lcd->var.blue.length = 5; s3c_lcd->var.activate = FB_ACTIVATE_NOW; /* 2.3 设置操作函数 */ s3c_lcd->fbops = &s3c_fb_ops; /* 2.4 其他的设置 */ //s3c_lcd->pseudo_palette =; // //s3c_lcd->screen_base = xxx; /* 显存的虚拟地址 */ s3c_lcd->screen_size = 272*480*16/8; /* 3. 硬件相关的操作 */ /* 3.1 配置GPIO用于LCD */ gpbcon = ioremap(0x56000010, 8); gpbdat = gpbcon+1; gpccon = ioremap(0x56000020, 4); gpdcon = ioremap(0x56000030, 4); *gpccon = 0xaaaaaaaa; /* GPIO管脚用于VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND */ *gpdcon = 0xaaaaaaaa; /* GPIO管脚用于VD[23:8] */ *gpbcon &= ~(0x03<<(3*2)); /* GPB3设置为输出引脚 */ *gpbcon |= ( 0x1<<(3*2) ); *gpbdat |= (0x1<<3); /* 背光亮 */ /* 3.2 根据LCD手册设置LCD控制器, 比如VCLK的频率等 */ lcd_regs = ioremap(0x4C800000, 0x200); VIDCON0 = ioremap(0x4c800000, 4); VIDCON1 = ioremap(0x4c800004, 4); VIDTCON0 = ioremap(0x4c800008, 4); VIDTCON1 = ioremap(0x4c80000C, 4); VIDTCON2 = ioremap(0x4c800010, 4); WINCON0 = ioremap(0x4c800014, 4); VIDOSD0A = ioremap(0x4c800028, 4); VIDOSD0B = ioremap(0x4c80002C, 4); VIDW00ADD0B0 = ioremap(0x4c800064, 4); VIDW00ADD1B0 = ioremap(0x4c80007C, 4); // 配置VIDCONx,设置接口类型、时钟、极性和使能LCD控制器等 *VIDCON0 = (0<<22)|(0<<13)|(9<<6)|(1<<5)|(1<<4)|(0<<2)|(3<<0); *VIDCON1 = (0<<7)|(1<<6)|(1<<5)|(0<<4); /* VCLK在下降沿取数据。VSYNC和HSYNC都是低电平有效,平时是高电平。VDEN高有效 */ // 配置VIDTCONx,设置时序和长宽等 // 设置时序 *VIDTCON0 = VBPD<<16 | VFPD<<8 | VSPW<<0; *VIDTCON1 = HBPD<<16 | HFPD<<8 | HSPW<<0; // 设置长宽 *VIDTCON2 = (LINEVAL << 11) | (HOZVAL << 0); // 配置WINCON0,设置window0的数据格式 // 需要配置BITSWP,BYTSWP,HAWSWP *WINCON0 = (1<<0); *WINCON0 |= (1<<16); /* HAWSWP=1 */ *WINCON0 &= ~(0xf << 2); *WINCON0 |= 0x5<<2; /* 选择16bpp,即5-6-5模式 */ // 配置VIDOSD0A/B/C,设置window0的坐标系 #define LeftTopX 0 #define LeftTopY 0 #define RightBotX 479 /* 这里x,y和韦东山相反 */ #define RightBotY 271 *VIDOSD0A = (LeftTopX<<11) | (LeftTopY << 0); *VIDOSD0B = (RightBotX<<11) | (RightBotY << 0); /* 3.3 分配显存(framebuffer), 并把地址告诉LCD控制器 */ //申请显存,返回虚拟地址,申请后s3c_lcd->fix.smem_start存放显存物理地址 s3c_lcd->screen_base = dma_alloc_writecombine(NULL, s3c_lcd->fix.smem_len, &s3c_lcd->fix.smem_start, GFP_KERNEL); // 置VIDW00ADD0B0和VIDW00ADD1B0,设置framebuffer的地址 *VIDW00ADD0B0 = s3c_lcd->fix.smem_start; *VIDW00ADD1B0 = s3c_lcd->fix.smem_start + s3c_lcd->fix.smem_len; printk("s3c_lcd->fix.smem_start=0x%08x\n", (unsigned int)s3c_lcd->fix.smem_start); printk("*VIDW00ADD0B0=0x%08x\n", (unsigned int)*VIDW00ADD0B0); printk("s3c_lcd->screen_base=0x%08x\n", (unsigned int)s3c_lcd->screen_base); lcd_clear_screen(((0xFF >> 3) << 11)|((0x00 >> 2) << 5)|((0x00 >> 3) << 0)); // 绿色 // 黑色 lcd_clear_screen(((0x00 >> 3) << 11)|((0xFF >> 2) << 5)|((0x00 >> 3) << 0)); //红色 lcd_clear_screen(((0x00 >> 3) << 11)|((0x00 >> 2) << 5)|((0xFF >> 3) << 0)); //蓝色 lcd_draw_hline(10, 20 ,100 , 0x000000); lcd_draw_vline(30, 5, 200, 0xff0000); //s3c_lcd->smem_start = xxx /* 显存的物理地址 */ /* 4. 注册 */ register_framebuffer(s3c_lcd); return 0; }