Hi, The attached file is a LCD test program. Please using "arm-linux-gcc -static -o lcdtest lcdtest.c" to compile and test it. Linux/Brutus uses frame buffer in LCD. Each pixel in frame buffer is a color index. Shang-te Hsu. Harsha Sanjeewa wrote: > Hi everybody, > I want to do graphics on LCD that comes with Brutus board. Can some > one tell me from where > should I start. I also want to know where can I get information about > kernel header files. I cant figure out what the funcitons are actually > doing, especially fb.h . > Regards > Harsha > > unsubscribe: body of `unsubscribe linux-arm' to [EMAIL PROTECTED] > ++ Please use [EMAIL PROTECTED] for ++ > ++ kernel-related discussions. ++
#include <stdio.h> #include <math.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/mman.h> #include <signal.h> #include <sys/time.h> #define MAX_X 320 #define MAX_Y 240 #define MAX_SIZE (MAX_X * MAX_Y) #define SWAP(x1, y1, x2, y2, tmp) {\ tmp = x1; \ x1 = x2; \ x2 = tmp; \ tmp = y1; \ y1 = y2; \ y2 = tmp; } char *fbp; int draw_pixel(int x, int y, unsigned char color_index) { if ((x < 0) || (y < 0) || (x >= MAX_X) || (y >= MAX_Y)) return -1; *(fbp + y * MAX_X + x) = color_index; } int h_line(int x, int y, int length, unsigned char color_index) { int i; if (length <= 0) return -1; for (i=x;i<(x+length);i++) draw_pixel(i, y, color_index); } int v_line(int x, int y, int length, unsigned char color_index) { int i; if (length <= 0) return -1; for (i=y;i<(y+length);i++) draw_pixel(x, i, color_index); } int box(int x, int y, int dx, int dy, unsigned char color_index) { h_line(x, y, dx, color_index); h_line(x, y+dy-1, dx, color_index); v_line(x, y+1, dy-1, color_index); v_line(x+dx-1,y+1, dy-1, color_index); } int two_point_line(int x1, int y1, int x2, int y2, unsigned char color_index) { int t,x,y,dx,dy,sign,i,e; if (x1 == x2) { if (y1 == y2) draw_pixel(x1, y1, color_index); else v_line(x1, (y1 > y2)? y2:y1, abs(y1 - y2), color_index); } else if (y1 == y2) { h_line((x1 > x2)? x2:x1, y1, abs(x1 - x2), color_index); } dx = abs(x2 - x1); dy = abs(y2 - y1); if (dx >= dy) { /* x-major */ e = dy - dx; if (x1 > x2) SWAP(x1, y1, x2, y2, t); sign = (y1 > y2)? -1 : 1; x = x1; y = y1; for (i=0;i<dx;i++,x++,e += dy) { draw_pixel(x, y, color_index); if (e >= 0) { y += sign; e -= dx; } } } else { /* y-major */ e = dx - dy; if (y1 > y2) SWAP(x1, y1, x2, y2, t); sign = (x1 > x2)? -1 : 1; x = x1; y = y1; for (i=0;i<dy;i++,y++, e += dx) { draw_pixel(x, y, color_index); if (e >= 0) { x += sign; e -= dy; } } } } int FillRectangleSolid(int x, int y, int width, int height, unsigned char color) { int i; if ((width <= 0) || (height <= 0)) return -1; for (i=0;i<height;i++) h_line(x, y+i, width, color); } main() { int f; int i,j,color; int x,y,w,h; int x1,y1,x2,y2; f = open("/dev/fb", O_RDWR); if (f < 0) { printf("Can't open /dev/fb\n"); exit(1); } fbp = mmap(0, MAX_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, f, 0); if ((int)fbp < 0) { printf("Can't mmap /dev/fb\n"); exit(1); } for (i=0;i<16;i++) { for (j=0;j<16;j++) { FillRectangleSolid( j*20, i*15, 20, 15, i*16+j); } } #if 0 while (1) { #if 0 x = random()%MAX_X; y = random()%MAX_Y; w = random()%50; h = random()%50; color = random()%16; FillRectangleSolid(x,y, w, h, color); #endif x1 = random()%MAX_X; x2 = random()%MAX_X; y1 = random()%MAX_Y; y2 = random()%MAX_Y; color = random()%255; two_point_line(x1, y1, x2, y2, color); usleep(8000); two_point_line(x1, y1, x2, y2, 0); usleep(8000); } #endif close(f); }