新增测试动态效果

This commit is contained in:
hongbochen 2015-10-29 16:47:41 +08:00
parent fd78dad719
commit 57e26b8fca
19 changed files with 0 additions and 3093 deletions

1238
fb1/fb.h~

File diff suppressed because it is too large Load Diff

View File

@ -1,107 +0,0 @@
#include "fbtool.h"
//打开并且初始化该frame buffer
int fb_open(PFBDEV pFbdev)
{
//打开frame buffer
pFbdev->fb = open(pFbdev->dev,O_RDWR);
if(pFbdev->fb < 0)
{
printf("打开错误 %s : %n.请检查内核配置\n",pFbdev->dev);
return 0;
}
// 初始化fb_var
if(-1 == ioctl(pFbdev->fb,FBIOGET_VSCREENINFO,&(pFbdev->fb_var)))
{
printf("ioctl FBIOGET_VSCREENINFO\n");
return 0;
}
// 初始化fb_fix
if(-1 == ioctl(pFbdev->fb,FBIOGET_FSCREENINFO,&(pFbdev->fb_fix)))
{
printf("ioctl FBIOGET_FSCREENINFO\n");
return 0;
}
return 1;
}
//关闭frame buffer
int fb_close(PFBDEV pFbdev)
{
close(pFbdev->fb);
pFbdev->fb = -1;
}
//打印frame buffer 所占内存的开始地址 
void pmem_start(PFBDEV pFbdev)
{
printf("frame buffer所占内存的开始地址为:%lu\n",pFbdev->fb_fix.smem_start);
}
//打印FB_TYPE
void p_type(PFBDEV pFbdev)
{
printf("frame buffer 的类型为:%d\n",pFbdev->fb_fix.type);
}
//打印可见清晰度
void p_visible_res(PFBDEV pFbdev)
{
printf("frame buffer的可见清晰度为\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xres,pFbdev->fb_var.yres);
}
//打印虚拟分辨率
void p_virt_res(PFBDEV pFbdev)
{
printf("frame buffer的虚拟清晰度为\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xres_virtual,pFbdev->fb_var.yres_virtual);
}
//打印虚拟到可见的偏移量
void p_offset(PFBDEV pFbdev)
{
printf("frame buffer的虚拟分辨率到可见分辨率的偏移量为:\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xoffset,pFbdev->fb_var.yoffset);
}
//打印每个像素的位数
void p_bpp(PFBDEV pFbdev)
{
printf("frame buffer的BPP为%d\n",pFbdev->fb_var.bits_per_pixel);
}
//打印R,G,B和透明度
void p_rgbt(PFBDEV pFbdev)
{
printf("这个后面再说!!\n");
}
//打印在内存中的高度和宽度
void p_hw(PFBDEV pFbdev)
{
printf("frame buffer在内存中所占的高度和宽度分别是:\n\t宽度 = %d\n\t高度 = %d\n",pFbdev->fb_var.height,pFbdev->fb_var.width);
}

View File

@ -1,41 +0,0 @@
#ifndef __FBTOOL_H_
#define __FBTOOL_H_
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <stddef.h>
#include <string.h>
typedef struct fbdev{
int fb; //framebuffer打开后的唯一标识符
struct fb_fix_screeninfo fb_fix;
struct fb_var_screeninfo fb_var;
char dev[20];
}FBDEV,*PFBDEV;
//打开framebuffer
int fb_open(PFBDEV pFbdev);
//关闭framebuffer
int fb_close(PFBDEV pFbdev);
//打印frame buffer 所占内存的开始地址 
void pmem_start(PFBDEV pFbdev);
//打印FB_TYPE
void p_type(PFBDEV pFbdev);
//打印可见清晰度
void p_visible_res(PFBDEV pFbdev);
//打印虚拟分辨率
void p_virt_res(PFBDEV pFbdev);
//打印虚拟到可见的偏移量
void p_offset(PFBDEV pFbdev);
//打印每个像素的位数
void p_bpp(PFBDEV pFbdev);
//打印R,G,B和透明度
void p_rgbt(PFBDEV pFbdev);
//打印在内存中的高度和宽度
void p_hw(PFBDEV pFbdev);
#endif

View File

@ -1,34 +0,0 @@
#include "fbtool.h"
int main()
{
FBDEV fbdev;
memset(&fbdev,0,sizeof(FBDEV));
strcpy(fbdev.dev,"/dev/fb0");
if(0 == fb_open(&fbdev)){
printf("Open fail!!\n");
return -1;
}
//打印frame buffer 所占内存的开始地址 
pmem_start(&fbdev);
//打印FB_TYPE
p_type(&fbdev);
//打印可见清晰度
p_visible_res(&fbdev);
//打印虚拟分辨率
p_virt_res(&fbdev);
//打印虚拟到可见的偏移量
p_offset(&fbdev);
//打印每个像素的位数
p_bpp(&fbdev);
//打印R,G,B和透明度
p_rgbt(&fbdev);
//打印在内存中的高度和宽度
p_hw(&fbdev);
fb_close(PFBDEV pFbdev);
return 0;
}

View File

@ -1,133 +0,0 @@
#include "fbtool.h"
//打开并且初始化该frame buffer
int fb_open(PFBDEV pFbdev)
{
//打开frame buffer
pFbdev->fb = open(pFbdev->dev,O_RDWR);
if(pFbdev->fb < 0)
{
printf("打开错误 %s : %n.请检查内核配置\n",pFbdev->dev);
return 0;
}
// 初始化fb_var
if(-1 == ioctl(pFbdev->fb,FBIOGET_VSCREENINFO,&(pFbdev->fb_var)))
{
printf("ioctl FBIOGET_VSCREENINFO\n");
return 0;
}
// 初始化fb_fix
if(-1 == ioctl(pFbdev->fb,FBIOGET_FSCREENINFO,&(pFbdev->fb_fix)))
{
printf("ioctl FBIOGET_FSCREENINFO\n");
return 0;
}
return 1;
}
//关闭frame buffer
int fb_close(PFBDEV pFbdev)
{
close(pFbdev->fb);
pFbdev->fb = -1;
}
//打印frame buffer 所占内存的开始地址 
void pmem_start(PFBDEV pFbdev)
{
printf("frame buffer所占内存的开始地址为:%d\n",pFbdev->fb_fix.smem_start);
}
//打印FB_TYPE
void p_type(PFBDEV pFbdev)
{
printf("frame buffer 的类型为:%d\n",pFbdev->fb_fix.type);
}
//打印可见清晰度
void p_visible_res(PFBDEV pFbdev)
{
printf("frame buffer的可见清晰度为\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xres,pFbdev->fb_var.yres);
}
//打印虚拟分辨率
void p_virt_res(PFBDEV pFbdev)
{
printf("frame buffer的虚拟清晰度为\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xres_virtual,pFbdev->fb_var.yres_virtual);
}
//打印虚拟到可见的偏移量
void p_offset(PFBDEV pFbdev)
{
printf("frame buffer的虚拟分辨率到可见分辨率的偏移量为:\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xoffset,pFbdev->fb_var.yoffset);
}
//打印每个像素的位数
void p_bpp(PFBDEV pFbdev)
{
printf("frame buffer的BPP为%d\n",pFbdev->fb_var.bits_per_pixel);
}
//打印R,G,B和透明度
void p_rgbt(PFBDEV pFbdev)
{
//R位域
printf("R位域:\n");
struct fb_bitfield bf = pFbdev->fb_var.red;
printf("\t开始:%d\n",bf.offset);
printf("\t长度:%d\n",bf.length);
printf("\tMSB:%d\n",bf.msb_right);
//G位域
printf("G位域:\n");
bf = pFbdev->fb_var.green;
printf("\t开始:%d\n",bf.offset);
printf("\t长度:%d\n",bf.length);
printf("\tMSB:%d\n",bf.msb_right);
// B位域
printf("B位域:\n");
bf = pFbdev->fb_var.blue;
printf("\t开始:%d\n",bf.offset);
printf("\t长度:%d\n",bf.length);
printf("\tMSB:%d\n",bf.msb_right);
// 透明度位域
printf("透明度位域:\n");
bf = pFbdev->fb_var.transp;
printf("\t开始:%d\n",bf.offset);
printf("\t长度:%d\n",bf.length);
printf("\tMSB:%d\n",bf.msb_right);
}
//打印在内存中的高度和宽度
void p_hw(PFBDEV pFbdev)
{
printf("frame buffer在内存中所占的高度和宽度分别是:\n\t宽度 = %d\n\t高度 = %d\n",pFbdev->fb_var.height,pFbdev->fb_var.width);
}

View File

@ -1,41 +0,0 @@
#ifndef __FBTOOL_H_
#define __FBTOOL_H_
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <stddef.h>
#include <string.h>
typedef struct fbdev{
int fb; //framebuffer打开后的唯一标识符
struct fb_fix_screeninfo fb_fix;
struct fb_var_screeninfo fb_var;
char dev[20];
}FBDEV,*PFBDEV;
//打开framebuffer
int fb_open(PFBDEV pFbdev);
//关闭framebuffer
int fb_close(PFBDEV pFbdev);
//打印frame buffer 所占内存的开始地址 
void pmem_start(PFBDEV pFbdev);
//打印FB_TYPE
void p_type(PFBDEV pFbdev);
//打印可见清晰度
void p_visible_res(PFBDEV pFbdev);
//打印虚拟分辨率
void p_virt_res(PFBDEV pFbdev);
//打印虚拟到可见的偏移量
void p_offset(PFBDEV pFbdev);
//打印每个像素的位数
void p_bpp(PFBDEV pFbdev);
//打印R,G,B和透明度
void p_rgbt(PFBDEV pFbdev);
//打印在内存中的高度和宽度
void p_hw(PFBDEV pFbdev);
#endif

View File

@ -1,38 +0,0 @@
#include "fbtool.h"
int main()
{
FBDEV fbdev;
memset(&fbdev,0,sizeof(FBDEV));
strcpy(fbdev.dev,"/dev/fb0");
if(0 == fb_open(&fbdev)){
printf("Open fail!!\n");
return -1;
}
//打印frame buffer 所占内存的开始地址 
pmem_start(&fbdev);
//打印FB_TYPE
p_type(&fbdev);
//打印可见清晰度
p_visible_res(&fbdev);
//打印虚拟分辨率
p_virt_res(&fbdev);
//打印虚拟到可见的偏移量
p_offset(&fbdev);
//打印每个像素的位数
p_bpp(&fbdev);
//打印R,G,B和透明度
p_rgbt(&fbdev);
//打印在内存中的高度和宽度
p_hw(&fbdev);
//打印fb的RGB和透明度的位域
p_rgbt(&fbdev);
fb_close(&fbdev);
return 0;
}

View File

@ -1,107 +0,0 @@
#include "fbtool.h"
//打开并且初始化该frame buffer
int fb_open(PFBDEV pFbdev)
{
//打开frame buffer
pFbdev->fb = open(pFbdev->dev,O_RDWR);
if(pFbdev->fb < 0)
{
printf("打开错误 %s : %n.请检查内核配置\n",pFbdev->dev);
return 0;
}
// 初始化fb_var
if(-1 == ioctl(pFbdev->fb,FBIOGET_VSCREENINFO,&(pFbdev->fb_var)))
{
printf("ioctl FBIOGET_VSCREENINFO\n");
return 0;
}
// 初始化fb_fix
if(-1 == ioctl(pFbdev->fb,FBIOGET_FSCREENINFO,&(pFbdev->fb_fix)))
{
printf("ioctl FBIOGET_FSCREENINFO\n");
return 0;
}
return 1;
}
//关闭frame buffer
int fb_close(PFBDEV pFbdev)
{
close(pFbdev->fb);
pFbdev->fb = -1;
}
//打印frame buffer 所占内存的开始地址 
void pmem_start(PFBDEV pFbdev)
{
printf("frame buffer所占内存的开始地址为:%lu\n",pFbdev->fb_fix.smem_start);
}
//打印FB_TYPE
void p_type(PFBDEV pFbdev)
{
printf("frame buffer 的类型为:%u\n",pFbdev->fb_fix.type);
}
//打印可见清晰度
void p_visible_res(PFBDEV pFbdev)
{
printf("frame buffer的可见清晰度为\n\tx = %u\n\ty = %u\n",pFbdev->fb_var.xres,pFbdev->fb_var.yres);
}
//打印虚拟分辨率
void p_virt_res(PFBDEV pFbdev)
{
printf("frame buffer的虚拟清晰度为\n\tx = %u\n\ty = %u\n",pFbdev->fb_var.xres_virtual,pFbdev->fb_var.yres_virtual);
}
//打印虚拟到可见的偏移量
void p_offset(PFBDEV pFbdev)
{
printf("frame buffer的虚拟分辨率到可见分辨率的偏移量为:\n\tx = %u\n\ty = %u\n",pFbdev->fb_var.xoffset,pFbdev->fb_var.yoffset);
}
//打印每个像素的位数
void p_bpp(PFBDEV pFbdev)
{
printf("frame buffer的BPP为%d\n",pFbdev->fb_var.bits_per_pixel);
}
//打印R,G,B和透明度
void p_rgbt(PFBDEV pFbdev)
{
printf("这个后面再说!!\n");
}
//打印在内存中的高度和宽度
void p_hw(PFBDEV pFbdev)
{
printf("frame buffer在内存中所占的高度和宽度分别是:\n\t宽度 = %u\n\t高度 = %u\n",pFbdev->fb_var.height,pFbdev->fb_var.width);
}

View File

@ -1,41 +0,0 @@
#ifndef __FBTOOL_H_
#define __FBTOOL_H_
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <stddef.h>
#include <string.h>
typedef struct fbdev{
int fb; //framebuffer打开后的唯一标识符
struct fb_fix_screeninfo fb_fix;
struct fb_var_screeninfo fb_var;
char dev[20];
}FBDEV,*PFBDEV;
//打开framebuffer
int fb_open(PFBDEV pFbdev);
//关闭framebuffer
int fb_close(PFBDEV pFbdev);
//打印frame buffer 所占内存的开始地址 
void pmem_start(PFBDEV pFbdev);
//打印FB_TYPE
void p_type(PFBDEV pFbdev);
//打印可见清晰度
void p_visible_res(PFBDEV pFbdev);
//打印虚拟分辨率
void p_virt_res(PFBDEV pFbdev);
//打印虚拟到可见的偏移量
void p_offset(PFBDEV pFbdev);
//打印每个像素的位数
void p_bpp(PFBDEV pFbdev);
//打印R,G,B和透明度
void p_rgbt(PFBDEV pFbdev);
//打印在内存中的高度和宽度
void p_hw(PFBDEV pFbdev);
#endif

View File

@ -1,34 +0,0 @@
#include "fbtool.h"
int main()
{
FBDEV fbdev;
memset(&fbdev,0,sizeof(FBDEV));
strcpy(fbdev.dev,"/dev/fb0");
if(0 == fb_open(&fbdev)){
printf("Open fail!!\n");
return -1;
}
//打印frame buffer 所占内存的开始地址 
pmem_start(&fbdev);
//打印FB_TYPE
p_type(&fbdev);
//打印可见清晰度
p_visible_res(&fbdev);
//打印虚拟分辨率
p_virt_res(&fbdev);
//打印虚拟到可见的偏移量
p_offset(&fbdev);
//打印每个像素的位数
p_bpp(&fbdev);
//打印R,G,B和透明度
p_rgbt(&fbdev);
//打印在内存中的高度和宽度
p_hw(&fbdev);
fb_close(PFBDEV pFbdev);
return 0;
}

View File

@ -1,4 +0,0 @@
all:
gcc page.h fbtool.h fbtool.c test.c -o test
clean:
rm test

View File

@ -1,226 +0,0 @@
#include "fbtool.h"
//打开并且初始化该frame buffer
int fb_open(PFBDEV pFbdev)
{
//打开frame buffer
pFbdev->fb = open(pFbdev->dev,O_RDWR);
if(pFbdev->fb < 0)
{
printf("打开错误 %s : %n.请检查内核配置\n",pFbdev->dev);
return 0;
}
// 初始化fb_var
if(-1 == ioctl(pFbdev->fb,FBIOGET_VSCREENINFO,&(pFbdev->fb_var)))
{
printf("ioctl FBIOGET_VSCREENINFO\n");
return 0;
}
// 初始化fb_fix
if(-1 == ioctl(pFbdev->fb,FBIOGET_FSCREENINFO,&(pFbdev->fb_fix)))
{
printf("ioctl FBIOGET_FSCREENINFO\n");
return 0;
}
//将物理地址映射到虚拟地址
pFbdev->fb_mem_offset = (unsigned long)pFbdev->fb_fix.smem_start & (~PAGE_MASK);
pFbdev->fb_mem = (unsigned long int)mmap(NULL,pFbdev->fb_fix.smem_len + pFbdev->fb_mem_offset,PROT_READ|PROT_WRITE,MAP_SHARED,pFbdev->fb,0);
if(-1L == (long)pFbdev->fb_mem){
printf("mmap error with mem:%lu,mem_offset:%lu\n",pFbdev->fb_mem_offset,pFbdev->fb_mem);
return 0;
}
return 1;
}
//关闭frame buffer
int fb_close(PFBDEV pFbdev)
{
close(pFbdev->fb);
pFbdev->fb = -1;
}
//打印frame buffer 所占内存的开始地址 
void pmem_start(PFBDEV pFbdev)
{
printf("frame buffer所占内存的开始地址为:%lu\n",pFbdev->fb_fix.smem_start);
}
//打印FB_TYPE
void p_type(PFBDEV pFbdev)
{
printf("frame buffer 的类型为:%d\n",pFbdev->fb_fix.type);
}
//打印可见清晰度
void p_visible_res(PFBDEV pFbdev)
{
printf("frame buffer的可见清晰度为\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xres,pFbdev->fb_var.yres);
}
//打印虚拟分辨率
void p_virt_res(PFBDEV pFbdev)
{
printf("frame buffer的虚拟清晰度为\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xres_virtual,pFbdev->fb_var.yres_virtual);
}
//打印虚拟到可见的偏移量
void p_offset(PFBDEV pFbdev)
{
printf("frame buffer的虚拟分辨率到可见分辨率的偏移量为:\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xoffset,pFbdev->fb_var.yoffset);
}
//打印每个像素的位数
void p_bpp(PFBDEV pFbdev)
{
printf("frame buffer的BPP为%d\n",pFbdev->fb_var.bits_per_pixel);
}
//打印R,G,B和透明度
void p_rgbt(PFBDEV pFbdev)
{
//R位域
printf("R位域:\n");
struct fb_bitfield bf = pFbdev->fb_var.red;
printf("\t开始:%d\n",bf.offset);
printf("\t长度:%d\n",bf.length);
printf("\tMSB:%d\n",bf.msb_right);
//G位域
printf("G位域:\n");
bf = pFbdev->fb_var.green;
printf("\t开始:%d\n",bf.offset);
printf("\t长度:%d\n",bf.length);
printf("\tMSB:%d\n",bf.msb_right);
// B位域
printf("B位域:\n");
bf = pFbdev->fb_var.blue;
printf("\t开始:%d\n",bf.offset);
printf("\t长度:%d\n",bf.length);
printf("\tMSB:%d\n",bf.msb_right);
// 透明度位域
printf("透明度位域:\n");
bf = pFbdev->fb_var.transp;
printf("\t开始:%d\n",bf.offset);
printf("\t长度:%d\n",bf.length);
printf("\tMSB:%d\n",bf.msb_right);
}
//打印在内存中的高度和宽度
void p_hw(PFBDEV pFbdev)
{
printf("frame buffer在内存中所占的高度和宽度分别是:\n\t宽度 = %d\n\t高度 = %d\n",pFbdev->fb_var.height,pFbdev->fb_var.width);
}
//清空控制台 
void clear_con(void *addr,int n,size_t len)
{
memset(addr,n,len);
}
//映射到内存
void fb_memcpy(void *addr,void *color,size_t len)
{
memcpy(addr,color,len);
}
//画点
void draw_dot(PFBDEV pFbdev,POINT p,uint8_t r,uint8_t g,uint8_t b)
{
uint32_t offset;
uint8_t color[4];
color[0] = b;
color[1] = g;
color[2] = r;
color[3] = 0x0; //透明度
offset = p.y * pFbdev->fb_fix.line_length + 4 * p.x;
//将操作映射到内存中
fb_memcpy((void*)pFbdev->fb_mem + pFbdev->fb_mem_offset + offset,color,4);
}
//画横线
void draw_h_line(PFBDEV pFbdev,POINT minX,POINT maxX,uint8_t r,uint8_t g,uint8_t b)
{
int m;
int length = maxX.x - minX.x;
for(m = 0;m < length;m++){
POINT tp;
tp.x = minX.x + m;
tp.y = minX.y;
draw_dot(pFbdev,tp,r,g,b);
}
}
//画竖线
void draw_v_line(PFBDEV pFbdev,POINT minY,POINT maxY,uint8_t r,uint8_t g,uint8_t b)
{
int m;
int length = maxY.y - minY.y;
for(m = 0;m < length;m++){
POINT tp;
tp.x = minY.x;
tp.y = minY.y + m;
draw_dot(pFbdev,tp,r,g,b);
}
}
//画一个矩形框
void draw_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b)
{
draw_h_line(pFbdev,lu,ru,r,g,b);
draw_h_line(pFbdev,ld,rd,r,g,b);
draw_v_line(pFbdev,lu,ld,r,g,b);
draw_v_line(pFbdev,ru,rd,r,g,b);
}
//填充一个矩形框
void fill_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b)
{
int xlen = ru.x - lu.x;
int ylen = ld.y - lu.y;
int m,n;
for(m = 0;m < ylen;m++){
for(n = 0;n < xlen;n++){
POINT p;
p.x = lu.x + n;
p.y = lu.y + m;
draw_dot(pFbdev,p,r,g,b);
}
}
}

View File

@ -1,80 +0,0 @@
#ifndef __FBTOOL_H_
#define __FBTOOL_H_
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <stddef.h>
#include <string.h>
#include <sys/mman.h>
#include <math.h>
#include <stdint.h>
#include "page.h"
typedef struct fbdev{
int fb; //framebuffer打开后的唯一标识符
struct fb_fix_screeninfo fb_fix;
struct fb_var_screeninfo fb_var;
/* 新增 */
unsigned long fb_mem_offset; //frame buffer所占内存的偏移量
unsigned long fb_mem; //frame buffer的映射到进程内存空间的起始地址
char dev[20];
}FBDEV,*PFBDEV;
typedef struct point{
int x;
int y;
int z;
}POINT,*PPOINT;
//打开framebuffer
int fb_open(PFBDEV pFbdev);
//关闭framebuffer
int fb_close(PFBDEV pFbdev);
//打印frame buffer 所占内存的开始地址 
void pmem_start(PFBDEV pFbdev);
//打印FB_TYPE
void p_type(PFBDEV pFbdev);
//打印可见清晰度
void p_visible_res(PFBDEV pFbdev);
//打印虚拟分辨率
void p_virt_res(PFBDEV pFbdev);
//打印虚拟到可见的偏移量
void p_offset(PFBDEV pFbdev);
//打印每个像素的位数
void p_bpp(PFBDEV pFbdev);
//打印R,G,B和透明度
void p_rgbt(PFBDEV pFbdev);
//打印在内存中的高度和宽度
void p_hw(PFBDEV pFbdev);
//清空控制台 
void clear_con(void *addr,int n,size_t len);
//映射到内存
void fb_memcpy(void *addr,void *color,size_t len);
//画点
void draw_dot(PFBDEV pFbdev,POINT p,uint8_t r,uint8_t g,uint8_t b);
//画横线
void draw_h_line(PFBDEV pFbdev,POINT minX,POINT maxX,uint8_t r,uint8_t g,uint8_t b);
//画竖线
void draw_v_line(PFBDEV pFbdev,POINT minY,POINT maxY,uint8_t r,uint8_t g,uint8_t b);
//画一个矩形框
void draw_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b);
//填充一个矩形框
#endif

View File

@ -1,109 +0,0 @@
#include "fbtool.h"
int main()
{
FBDEV fbdev;
memset(&fbdev,0,sizeof(FBDEV));
strcpy(fbdev.dev,"/dev/fb0");
if(0 == fb_open(&fbdev)){
printf("Open fail!!\n");
return -1;
}
/**
//打印frame buffer 所占内存的开始地址 
pmem_start(&fbdev);
//打印FB_TYPE
p_type(&fbdev);
//打印可见清晰度
p_visible_res(&fbdev);
//打印虚拟分辨率
p_virt_res(&fbdev);
//打印虚拟到可见的偏移量
p_offset(&fbdev);
//打印每个像素的位数
p_bpp(&fbdev);
//打印R,G,B和透明度
p_rgbt(&fbdev);
//打印在内存中的高度和宽度
p_hw(&fbdev);
//打印fb的RGB和透明度的位域
p_rgbt(&fbdev);
getchar();
//清屏
clear_con(fbdev.fb_mem + fbdev.fb_mem_offset,-1,fbdev.fb_fix.smem_len); */
POINT p;
p.x = 100;
p.y = 100;
//画点
draw_dot(&fbdev,p,0x0,0xff,0x0);
//划横线
//画横线
POINT p21;
p21.x = 120;
p21.y = 100;
POINT p2;
p2.x = 160;
p2.y = 160;
draw_h_line(&fbdev,p21,p2,0x0,0xff,0x0);
//画竖线
POINT p31;
p31.x = 100;
p31.y = 120;
POINT p3;
p3.x = 100;
p3.y = 160;
draw_v_line(&fbdev,p31,p3,0x0,0xff,0x0);
POINT p40;
p40.x = 120;
p40.y = 120;
POINT p41;
p41.x = 160;
p41.y = 120;
POINT p42;
p42.x = 120;
p42.y = 160;
POINT p43;
p43.x = 160;
p43.y = 160;
//画矩形
draw_rec(&fbdev,p40,p42,p41,p43,0x0,0xff,0x0);
POINT p50;
p50.x = 100;
p50.y = 180;
POINT p51;
p51.x = 160;
p51.y = 180;
POINT p52;
p52.x = 100;
p52.y = 220;
POINT p53;
p53.x = 160;
p53.y = 220;
//填充矩形
fill_rec(&fbdev,p50,p52,p51,p53,0x0,0xff,0x0);
return 0;
}

View File

@ -1,4 +0,0 @@
all:
gcc page.h fbtool.h fbtool.c test.c -o test -lm
clean:
rm test

View File

@ -1,47 +0,0 @@
#ifndef _COLOR_H_
#define _COLOR_H_
/**
*
* @property r R值
* @property g G值
 * @property b B值
* @property t T值
*/
typedef struct rgbt{
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t t;
}RGBT;
//定义一些常用的颜色属性
#define BLACK "00000000"  //黑色
#define YELLOW "ffff0000" //黄色
#define BLUE_LIGHT "B0E0E600" //淡蓝色
#define YELLOW_BANANA "E3CF5700" //香蕉色
#define BLUE_SKY "87CEEB00" //天蓝色
#define ORIANGE "ff610000" //橙色
#define GREEN "00ff0000" //绿色
#define PURPLE "A020F000" //紫色
#define RED "FF000000" //红色
#endif //_COLOR_H_

View File

@ -1,358 +0,0 @@
#include "fbtool.h"
//打开并且初始化该frame buffer
int fb_open(PFBDEV pFbdev)
{
//打开frame buffer
pFbdev->fb = open(pFbdev->dev,O_RDWR);
if(pFbdev->fb < 0)
{
printf("打开错误 %s : %n.请检查内核配置\n",pFbdev->dev);
return 0;
}
// 初始化fb_var
if(-1 == ioctl(pFbdev->fb,FBIOGET_VSCREENINFO,&(pFbdev->fb_var)))
{
printf("ioctl FBIOGET_VSCREENINFO\n");
return 0;
}
// 初始化fb_fix
if(-1 == ioctl(pFbdev->fb,FBIOGET_FSCREENINFO,&(pFbdev->fb_fix)))
{
printf("ioctl FBIOGET_FSCREENINFO\n");
return 0;
}
//将物理地址映射到虚拟地址
pFbdev->fb_mem_offset = (unsigned long)pFbdev->fb_fix.smem_start & (~PAGE_MASK);
pFbdev->fb_mem = (unsigned long int)mmap(NULL,pFbdev->fb_fix.smem_len + pFbdev->fb_mem_offset,PROT_READ|PROT_WRITE,MAP_SHARED,pFbdev->fb,0);
if(-1L == (long)pFbdev->fb_mem){
printf("mmap error with mem:%lu,mem_offset:%lu\n",pFbdev->fb_mem_offset,pFbdev->fb_mem);
return 0;
}
return 1;
}
//关闭frame buffer
int fb_close(PFBDEV pFbdev)
{
int r = close(pFbdev->fb);
pFbdev->fb = -1;
return r;
}
//打印frame buffer 所占内存的开始地址 
void pmem_start(PFBDEV pFbdev)
{
printf("frame buffer所占内存的开始地址为:%lu\n",pFbdev->fb_fix.smem_start);
}
//打印FB_TYPE
void p_type(PFBDEV pFbdev)
{
printf("frame buffer 的类型为:%d\n",pFbdev->fb_fix.type);
}
//打印可见清晰度
void p_visible_res(PFBDEV pFbdev)
{
printf("frame buffer的可见清晰度为\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xres,pFbdev->fb_var.yres);
}
//打印虚拟分辨率
void p_virt_res(PFBDEV pFbdev)
{
printf("frame buffer的虚拟清晰度为\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xres_virtual,pFbdev->fb_var.yres_virtual);
}
//打印虚拟到可见的偏移量
void p_offset(PFBDEV pFbdev)
{
printf("frame buffer的虚拟分辨率到可见分辨率的偏移量为:\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xoffset,pFbdev->fb_var.yoffset);
}
//打印每个像素的位数
void p_bpp(PFBDEV pFbdev)
{
printf("frame buffer的BPP为%d\n",pFbdev->fb_var.bits_per_pixel);
}
//打印R,G,B和透明度
void p_rgbt(PFBDEV pFbdev)
{
//R位域
printf("R位域:\n");
struct fb_bitfield bf = pFbdev->fb_var.red;
printf("\t开始:%d\n",bf.offset);
printf("\t长度:%d\n",bf.length);
printf("\tMSB:%d\n",bf.msb_right);
//G位域
printf("G位域:\n");
bf = pFbdev->fb_var.green;
printf("\t开始:%d\n",bf.offset);
printf("\t长度:%d\n",bf.length);
printf("\tMSB:%d\n",bf.msb_right);
// B位域
printf("B位域:\n");
bf = pFbdev->fb_var.blue;
printf("\t开始:%d\n",bf.offset);
printf("\t长度:%d\n",bf.length);
printf("\tMSB:%d\n",bf.msb_right);
// 透明度位域
printf("透明度位域:\n");
bf = pFbdev->fb_var.transp;
printf("\t开始:%d\n",bf.offset);
printf("\t长度:%d\n",bf.length);
printf("\tMSB:%d\n",bf.msb_right);
}
//打印在内存中的高度和宽度
void p_hw(PFBDEV pFbdev)
{
printf("frame buffer在内存中所占的高度和宽度分别是:\n\t宽度 = %d\n\t高度 = %d\n",pFbdev->fb_var.height,pFbdev->fb_var.width);
}
//清空控制台 
void clear_con(void *addr,int n,size_t len)
{
memset(addr,n,len);
}
//映射到内存
void fb_memcpy(void *addr,void *color,size_t len)
{
memcpy(addr,color,len);
}
//画点
void draw_dot(PFBDEV pFbdev,POINT p,uint8_t r,uint8_t g,uint8_t b)
{
uint32_t offset;
uint8_t color[4];
color[0] = b;
color[1] = g;
color[2] = r;
color[3] = 0x0; //透明度
offset = p.y * pFbdev->fb_fix.line_length + 4 * p.x;
//将操作映射到内存中
fb_memcpy((void*)pFbdev->fb_mem + pFbdev->fb_mem_offset + offset,color,4);
}
//画点
void draw_dot_with_trans(PFBDEV pFbdev,POINT p,uint8_t r,uint8_t g,uint8_t b,uint8_t t)
{
uint32_t offset;
uint8_t color[4];
color[0] = b;
color[1] = g;
color[2] = r;
color[3] = t; //透明度
offset = p.y * pFbdev->fb_fix.line_length + 4 * p.x;
//将操作映射到内存中
fb_memcpy((void*)pFbdev->fb_mem + pFbdev->fb_mem_offset + offset,color,4);
}
//画横线
void draw_h_line(PFBDEV pFbdev,POINT minX,POINT maxX,uint8_t r,uint8_t g,uint8_t b)
{
int m;
int length = maxX.x - minX.x;
for(m = 0;m < length;m++){
POINT tp;
tp.x = minX.x + m;
tp.y = minX.y;
draw_dot(pFbdev,tp,r,g,b);
}
}
void draw_h_line_with_trans(PFBDEV pFbdev,POINT minX,POINT maxX,uint8_t r,uint8_t g,uint8_t b,uint8_t t){
int m;
int length = maxX.x - minX.x;
for(m = 0;m < length;m++){
POINT tp;
tp.x = minX.x + m;
tp.y = minX.y;
draw_dot_with_trans(pFbdev,tp,r,g,b,t);
}
}
//画竖线
void draw_v_line(PFBDEV pFbdev,POINT minY,POINT maxY,uint8_t r,uint8_t g,uint8_t b)
{
int m;
int length = maxY.y - minY.y;
for(m = 0;m < length;m++){
POINT tp;
tp.x = minY.x;
tp.y = minY.y + m;
draw_dot(pFbdev,tp,r,g,b);
}
}
//画一个矩形框
void draw_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b)
{
draw_h_line(pFbdev,lu,ru,r,g,b);
draw_h_line(pFbdev,ld,rd,r,g,b);
draw_v_line(pFbdev,lu,ld,r,g,b);
draw_v_line(pFbdev,ru,rd,r,g,b);
}
//填充一个矩形框
void fill_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b)
{
int xlen = ru.x - lu.x;
int ylen = ld.y - lu.y;
int m,n;
for(m = 0;m < ylen;m++){
for(n = 0;n < xlen;n++){
POINT p;
p.x = lu.x + n;
p.y = lu.y + m;
draw_dot(pFbdev,p,r,g,b);
}
}
}
//画点
void draw_x_y_dot(PFBDEV pFbdev,int x,int y,uint8_t r,uint8_t g,uint8_t b)
{
POINT p;
p.x = x;
p.y = y;
draw_dot(pFbdev,p,r,g,b);
}
//画点
void draw_x_y_dot_with_trans(PFBDEV pFbdev,int x,int y,uint8_t r,uint8_t g,uint8_t b,uint8_t t)
{
POINT p;
p.x = x;
p.y = y;
draw_dot_with_trans(pFbdev,p,r,g,b,t);
}
//画点
void draw_x_y_color_dot(PFBDEV pFbdev,int x,int y,RGBT c)
{
draw_x_y_dot(pFbdev,x,y,c.r,c.g,c.b);
}
//画点
void draw_x_y_color_dot_with_trans(PFBDEV pFbdev,int x,int y,RGBT c)
{
draw_x_y_dot_with_trans(pFbdev,x,y,c.r,c.g,c.b,c.t);
}
RGBT getRGBT(const char *temp){
RGBT rgbt;
char *c_tmp;
c_tmp = (char *)malloc(4 * sizeof(int));
c_tmp[0] = '0';
c_tmp[1] = 'x';
int r,g,b,t;
//RGBT值的计算
c_tmp[2] = temp[0];
c_tmp[3] = temp[1];
r = strtol(c_tmp,NULL,16);
c_tmp[2] = temp[2];
c_tmp[3] = temp[3];
g = strtol(c_tmp,NULL,16);
c_tmp[2] = temp[4];
c_tmp[3] = temp[5];
b = strtol(c_tmp,NULL,16);
c_tmp[2] = temp[6];
c_tmp[3] = temp[7];
t = strtol(c_tmp,NULL,16);
rgbt.r = r;
rgbt.g = g;
rgbt.b = b;
rgbt.t = t;
return rgbt;
}
//画点 color分别代表RGBT
void draw_x_y_color_dot_with_string(PFBDEV pFbdev,int x,int y,const char *temp)
{
RGBT rgbt = getRGBT(temp);
draw_x_y_dot_with_trans(pFbdev,x,y,rgbt.r,rgbt.g,rgbt.b,rgbt.t);
}
//划横线
void draw_h_line_with_string(PFBDEV pFbdev,POINT minX,POINT maxX,const char *color)
{
RGBT rgbt = getRGBT(color);
draw_h_line_with_trans(pFbdev,minX,maxX,rgbt.r,rgbt.g,rgbt.b,rgbt.t);
}
//画圆
void draw_circle(PFBDEV pFbdev,int x,int y,int radius,const char *color)
{
double i;
int tmp;
for(i = x - radius; i < x + radius;i+=0.01){
tmp = sqrt(radius * radius - (i - x) * (i - x));
draw_x_y_color_dot_with_string(pFbdev,i,(tmp + y),color);
draw_x_y_color_dot_with_string(pFbdev,i,(-tmp + y),color);
}
}

View File

@ -1,326 +0,0 @@
#ifndef __FBTOOL_H_
#define __FBTOOL_H_
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <stddef.h>
#include <string.h>
#include <sys/mman.h>
#include <math.h>
#include <stdint.h>
#include "page.h"
#include "color.h"
/**
* frame buffer的属性
* @property fb frame buffer打开后的唯一标识符
* @property fb_fix frame buffer的固定属性就保存在这个结构体中
* @property fb_var frame buffer的可变属性保存在这个结构体中
* @property fb_mem_offset frame buffer所占内存的偏移量
* @property fb_mem frame buffer的映射到进程内存空间的起始地址
*/
typedef struct fbdev{
int fb;
struct fb_fix_screeninfo fb_fix;
struct fb_var_screeninfo fb_var;
/* 新增 */
unsigned long fb_mem_offset;
unsigned long fb_mem;
char dev[20];
}FBDEV,*PFBDEV;
/**
*
* @property x
* @property y
* @property z 3D
*/
typedef struct point{
int x;
int y;
int z;
}POINT,*PPOINT;
/*
* frame buffer
* @param pFbdev fbdev
* @return 0 -
 * 1 -
*/
int fb_open(PFBDEV pFbdev);
/*
* frame buffer设备
* @param pFbdev fbdev
* @return 0 -
* >0 -
*/
int fb_close(PFBDEV pFbdev);
/*
* frame buffer  
* @param pFbdev fbdev
* @return void
*/
void pmem_start(PFBDEV pFbdev);
/*
* FB_TYPE
* @param pFbdev fbdev
* @return void
*/
void p_type(PFBDEV pFbdev);
/*
*
* @param pFbdev fbdev
* @return void
*/
void p_visible_res(PFBDEV pFbdev);
/*
*
* @param pFbdev fbdev
* @return void
*/
void p_virt_res(PFBDEV pFbdev);
/*
*
* @param pFbdev fbdev
* @return void
*/
void p_offset(PFBDEV pFbdev);
/*
*
* @param pFbdev fbdev
* @return void
*/
void p_bpp(PFBDEV pFbdev);
/*
* R,G,B和透明度
* @param pFbdev fbdev
* @return void
*/
void p_rgbt(PFBDEV pFbdev);
/*
*
* @param pFbdev fbdev
* @return void
*/
void p_hw(PFBDEV pFbdev);
/*
* addr开始的len个字符用n替换
* @param addr
* @param n
* @param len
* @return void
*/
void clear_con(void *addr,int n,size_t len);
/*
*
* @param addr
* @param color
* @param len
 * @return void
*/
void fb_memcpy(void *addr,void *color,size_t len);
/*
*
* @param pFbdev fbdev
* @param p
* @param r R值
 * @param g G值
* @param b B值
* @return void
*/
void draw_dot(PFBDEV pFbdev,POINT p,uint8_t r,uint8_t g,uint8_t b);
/*
*
* @param pFbdev fbdev
* @param p
* @param r R值
 * @param g G值
* @param b B值
 * @param t
* @return void
*/
void draw_dot_with_trans(PFBDEV pFbdev,POINT p,uint8_t r,uint8_t g,uint8_t b,uint8_t t);
/*
*
* @param pFbdev fbdev
* @param x
* @param y
* @param r R值
 * @param g G值
* @param b B值
*/
void draw_x_y_dot(PFBDEV pFbdev,int x,int y,uint8_t r,uint8_t g,uint8_t b);
/*
*
* @param pFbdev fbdev
* @param x
* @param y
* @param r R值
 * @param g G值
* @param b B值
 * @param t
*/
void draw_x_y_dot_with_trans(PFBDEV pFbdev,int x,int y,uint8_t r,uint8_t g,uint8_t b,uint8_t t);
/*
* 使rgbt来代替颜色来画点
* @param pFbdev fbdev
* @param x
* @param y
* @param c
* @return void
*
*/
void draw_x_y_color_dot(PFBDEV pFbdev,int x,int y,RGBT c);
/*
* 使rgbt来代替颜色来画点,
* @param pFbdev fbdev
* @param x
* @param y
* @param c
* @return void
*
*/
void draw_x_y_color_dot_with_trans(PFBDEV pFbdev,int x,int y,RGBT c);
/*
* 使
 * 16,"ffff0000"
*
* @param pFbdev fbdev
* @param x
* @param y
* @param c
* @param color
* @return void
*
*/
void draw_x_y_color_dot_with_string(PFBDEV pFbdev,int x,int y,const char *color);
/*
* x值较小的点和x值较大的点rgb值画一条横线
* @param pFbdev fbdev
* @param minX x较小的点
* @param maxX x较大的点
 * @param r R值
* @param g G值
* @param b B值
* @return void
*/
void draw_h_line(PFBDEV pFbdev,POINT minX,POINT maxX,uint8_t r,uint8_t g,uint8_t b);
/*
* x值较小的点和x值较大的点rgb值和透明度画一条横线
* @param pFbdev fbdev
* @param minX x较小的点
* @param maxX x较大的点
 * @param r R值
* @param g G值
* @param b B值
 * @param t
* @return void
*
*/
void draw_h_line_with_trans(PFBDEV pFbdev,POINT minX,POINT maxX,uint8_t r,uint8_t g,uint8_t b,uint8_t t);
/*
* 使线
* @param pFbdev fbdev
* @param minX x较小的点
* @param maxX x较大的点
* @param color
* @return void
*/
void draw_h_line_with_string(PFBDEV pFbdev,POINT minX,POINT maxX,const char *color);
/*
* y最小的一个点和一个y较大的点RGB值画一条竖线
* @param pFbdev fbdev
* @param minY y较小的点
* @param maxY y较大的点
 * @param r R值
* @param g G值
* @param b B值
*/
void draw_v_line(PFBDEV pFbdev,POINT minY,POINT maxY,uint8_t r,uint8_t g,uint8_t b);
/*
*
* @param pFbdev fbdev
* @param lu
* @param ld
 * @param ru
* @param rd
* @param r R值
* @param g G值
* @param b B值
 * @return void
*/
void draw_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b);
/*
*
* @param pFbdev fbdev
* @param lu
* @param ld
 * @param ru
* @param rd
* @param r R值
* @param g G值
* @param b B值
 * @return void
*/
void fill_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b);
/*
* RGBT
* @param color
* @return RGBT
*/
RGBT getRGBT(const char *color);
/*
*
* @param pFbdev fbdev
 * @param x x值
* @param y y值
* @param radius
* @color
* @return void
*/
void draw_circle(PFBDEV pFbdev,int x,int y,int radius,const char *color);
#endif

View File

@ -1,125 +0,0 @@
#include "fbtool.h"
int main()
{
FBDEV fbdev;
memset(&fbdev,0,sizeof(FBDEV));
strcpy(fbdev.dev,"/dev/fb0");
if(0 == fb_open(&fbdev)){
printf("Open fail!!\n");
return -1;
}
/**
//打印frame buffer 所占内存的开始地址 
pmem_start(&fbdev);
//打印FB_TYPE
p_type(&fbdev);
//打印可见清晰度
p_visible_res(&fbdev);
//打印虚拟分辨率
p_virt_res(&fbdev);
//打印虚拟到可见的偏移量
p_offset(&fbdev);
//打印每个像素的位数
p_bpp(&fbdev);
//打印R,G,B和透明度
p_rgbt(&fbdev);
//打印在内存中的高度和宽度
p_hw(&fbdev);
//打印fb的RGB和透明度的位域
p_rgbt(&fbdev);
getchar();
//清屏
clear_con(fbdev.fb_mem + fbdev.fb_mem_offset,-1,fbdev.fb_fix.smem_len); */
POINT p;
p.x = 100;
p.y = 100;
//画点
draw_x_y_dot(&fbdev,100,100,0x0,0xff,0x0);
/*
RGBT c;
c.r = 0xff;
c.g = 0xff;
c.b = 0xff;
c.t = 0x00;
//draw_x_y_color_dot_with_trans(&fbdev,100,100,RED);
draw_x_y_color_dot_with_string(&fbdev,100,100,YELLOW);
//划横线
//画横线
POINT p21;
p21.x = 120;
p21.y = 100;
POINT p2;
p2.x = 160;
p2.y = 160;
//draw_h_line(&fbdev,p21,p2,0x0,0xff,0x0);
draw_h_line_with_string(&fbdev,p21,p2,RED);
//画竖线
POINT p31;
p31.x = 100;
p31.y = 120;
POINT p3;
p3.x = 100;
p3.y = 160;
draw_v_line(&fbdev,p31,p3,0x0,0xff,0x0);
POINT p40;
p40.x = 120;
p40.y = 120;
POINT p41;
p41.x = 160;
p41.y = 120;
POINT p42;
p42.x = 120;
p42.y = 160;
POINT p43;
p43.x = 160;
p43.y = 160;
//画矩形
draw_rec(&fbdev,p40,p42,p41,p43,0x0,0xff,0x0);
POINT p50;
p50.x = 100;
p50.y = 180;
POINT p51;
p51.x = 160;
p51.y = 180;
POINT p52;
p52.x = 100;
p52.y = 220;
POINT p53;
p53.x = 160;
p53.y = 220;
//填充矩形
fill_rec(&fbdev,p50,p52,p51,p53,0x0,0xff,0x0);*/
draw_circle(&fbdev,500,400,100,RED);
fb_close(&fbdev);
return 0;
}