我是靠谱客的博主 义气缘分,最近开发中收集的这篇文章主要介绍34.【linux驱动】framebuffer驱动,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1.framebuffer驱动
2.spi framebuffer驱动
3.spi framebuffer驱动(切换并显示虚拟终端)

framebuffer驱动

framebuffer最基本的驱动只需要填充并注册fb_info结构体

struct fb_info {
atomic_t count;
int node;
int flags;
struct mutex lock;
/* Lock for open/release/ioctl funcs */
struct mutex mm_lock;
/* Lock for fb_mmap and smem_* fields */
struct fb_var_screeninfo var;	/* Current var */
struct fb_fix_screeninfo fix;	/* Current fix */
struct fb_monspecs monspecs;	/* Current Monitor specs */
struct work_struct queue;	/* Framebuffer event queue */
struct fb_pixmap pixmap;	/* Image hardware mapper */
struct fb_pixmap sprite;	/* Cursor hardware mapper */
struct fb_cmap cmap;
/* Current cmap */
struct list_head modelist;
/* mode list */
struct fb_videomode *mode;	/* current mode */
#ifdef CONFIG_FB_BACKLIGHT
/* assigned backlight device */
/* set before framebuffer registration,
remove after unregister */
struct backlight_device *bl_dev;
/* Backlight level curve */
struct mutex bl_curve_mutex;
u8 bl_curve[FB_BACKLIGHT_LEVELS];
#endif
#ifdef CONFIG_FB_DEFERRED_IO
struct delayed_work deferred_work;
struct fb_deferred_io *fbdefio;
#endif
struct fb_ops *fbops;
struct device *device;
/* This is the parent */
struct device *dev;
/* This is this fb device */
int class_flag;
/* private sysfs flags */
#ifdef CONFIG_FB_TILEBLITTING
struct fb_tile_ops *tileops;
/* Tile Blitting */
#endif
char __iomem *screen_base;	/* Virtual address */
unsigned long screen_size;	/* Amount of ioremapped VRAM or 0 */
void *pseudo_palette;
/* Fake palette of 16 colors */
#define FBINFO_STATE_RUNNING	0
#define FBINFO_STATE_SUSPENDED	1
u32 state;
/* Hardware state i.e suspend */
void *fbcon_par;
/* fbcon use-only private area */
/* From here on everything is device dependent */
void *par;
/* we need the PCI or similar aperture base/size not
smem_start/size as smem_start may just be an object
allocated inside the aperture so may not actually overlap */
struct apertures_struct {
unsigned int count;
struct aperture {
resource_size_t base;
resource_size_t size;
} ranges[0];
} *apertures;
};

参数比较多,不解释,看一个范例

#include <linux/init.h>
#include <linux/module.h>
#include <linux/fb.h>
#include <linux/dma-mapping.h>
#define X 1024
#define Y 768
u32 p_addr; //用于存放显存的物理地址
u8 *v_addr; //用于存放显存的虚拟地址, 在驱动代码,我们也只能操作缓存的虚拟地址
struct fb_ops fops = { //这里不实现操作函数,使用fbmem.c里实现的功能函数
//如果这里实现了功能函数,则会调用这里实现的函数
};
struct fb_info *fbi;
static int __init framebuffer_init(void)
{
v_addr = dma_alloc_coherent(NULL, X*Y*4, &p_addr, GFP_KERNEL); //分配显存的缓冲区
//动态分配fb_info的对象空间, 而且额外分配100个字节(这100字节空间的地址==&fbi[1])
fbi = framebuffer_alloc(100, NULL);
fbi->var.xres = X; //分辨率
fbi->var.yres = Y;
fbi->var.xres_virtual = X;
fbi->var.yres_virtual = Y;
fbi->var.bits_per_pixel = 32; // 32位每个像素
fbi->var.red.offset = 16; //像素数据里的红
fbi->var.red.length = 8;
fbi->var.green.offset = 8; //像素数据里的绿
fbi->var.green.length = 8;
fbi->var.blue.offset = 0; //像素数据里的蓝
fbi->var.blue.length = 8;
strcpy(fbi->fix.id, "myfb");
fbi->fix.smem_start = p_addr; //显存的物理地址
fbi->fix.smem_len = X*Y*4; //显存缓冲区大小
fbi->fix.type = FB_TYPE_PACKED_PIXELS; //像素数据是打包的方式
fbi->fix.visual = FB_VISUAL_TRUECOLOR; //真彩色
fbi->fix.line_length = X*4; //每一行多少个字节
fbi->fbops = &fops;
fbi->screen_base = v_addr; // 显示缓冲区的虚拟地址
fbi->screen_size = X*Y*4;
return register_framebuffer(fbi); //注册fb设备
}
static void __exit framebuffer_exit(void)
{
unregister_framebuffer(fbi);
framebuffer_release(fbi);
dma_free_coherent(NULL, X*Y*4, v_addr, p_addr);
}
module_init(framebuffer_init);
module_exit(framebuffer_exit);
MODULE_LICENSE("GPL");

fb内存缓冲区使用dma_alloc_coherent申请物理连续大内存。使用register_framebuffer注册结构体就完成了framebuffer设备的注册,/dev目录下可以看到生成了一个新的fb设备。

最后

以上就是义气缘分为你收集整理的34.【linux驱动】framebuffer驱动的全部内容,希望文章能够帮你解决34.【linux驱动】framebuffer驱动所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(41)

评论列表共有 0 条评论

立即
投稿
返回
顶部