当前位置:网站首页>LCD笔记(3)写出LCD基本驱动框架
LCD笔记(3)写出LCD基本驱动框架
2022-07-22 06:02:00 【翠果打烂她的嘴】
1. 分配fb_info
2. 设置fb_info
要设置哪些内容?根据APP的需求来。
3. 注册fb_info
主要是以上3步!
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/err.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/fb.h>
#include <linux/init.h>
#include <linux/dma-mapping.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/clk.h>
#include <linux/cpufreq.h>
#include <linux/io.h>
#include <asm/div64.h>
#include <asm/mach/map.h>
#include <mach/regs-lcd.h>
#include <mach/regs-gpio.h>
#include <mach/fb.h>
static struct fb_info *myfb_info; //定义了一个fb_info结构体
static struct fb_ops myfb_ops = {
.owner = THIS_MODULE,
.fb_fillrect = cfb_fillrect, //画一个矩形,read write open由fbmem提供
.fb_copyarea = cfb_copyarea, //将这块显存复制到另一个区域
.fb_imageblit = cfb_imageblit, //画图 ,这些函数都由系统提供 不用自己写
};
/* 1. 入口 */
int __init lcd_drv_init(void) //入口函数做分配、设置、注册fb_info结构体
{
dma_addr_t phy_addr; //定义一个变量存放物理地址
/* 1.1 分配fb_info */
myfb_info = framebuffer_alloc(0, NULL); //分配一个fb_info
/* 1.2 设置fb_info */ //主要设置 var fix fbops
/* a. var : LCD分辨率、颜色格式 */
myfb_info->var.xres = 1024;
myfb_info->var.yres = 600;
myfb_info->var.bits_per_pixel = 16; /* rgb565 */
myfb_info->var.red.offset = 11;
myfb_info->var.red.length = 5;
myfb_info->var.green.offset = 5;
myfb_info->var.green.length = 6;
myfb_info->var.blue.offset = 0;
myfb_info->var.blue.length = 5;
/* b. fix */
myfb_info->fix.smem_len = myfb_info->var.xres * myfb_info->var.yres * myfb_info->var.bits_per_pixel / 8; //像素长度
if (myfb_info->var.bits_per_pixel == 24)
myfb_info->fix.smem_len = myfb_info->var.xres * myfb_info->var.yres * 4;
/* fb的虚拟地址 */
myfb_info->screen_base = dma_alloc_wc(NULL, myfb_info->fix.smem_len, &phy_addr,
GFP_KERNEL);
myfb_info->fix.smem_start = phy_addr; /* fb的物理地址 */
myfb_info->fix.type = FB_TYPE_PACKED_PIXELS;
myfb_info->fix.visual = FB_VISUAL_TRUECOLOR;
/* c. fbops */
myfb_info->fbops = &myfb_ops;
/* 1.3 注册fb_info */
register_framebuffer(myfb_info);
/* 1.4 硬件操作 */
return 0;
}
/* 2. 出口 */
static void __exit lcd_drv_exit(void) //和入口函数反过来操作
{
/* 反过来操作 */
/* 2.1 反注册fb_info */
unregister_framebuffer(myfb_info);
/* 2.2 释放fb_info */
framebuffer_release(myfb_info);
}
module_init(lcd_drv_init);
module_exit(lcd_drv_exit);
MODULE_AUTHOR("www.100ask.net");
MODULE_DESCRIPTION("Framebuffer driver for the linux");
MODULE_LICENSE("GPL");
边栏推荐
- NFTFi赛道版图概览
- 【转载】UE4 面试基础知识(二)
- 电子信息工程专业毕设题目选题推荐
- Polygon chain matic concept and underlying mechanism
- 接招吧。最强“高并发”系统设计 46 连问,分分钟秒杀一众面试者
- How to implement Apache's built-in AB stress testing tool
- 从0到1建设智能灰度数据体系:以vivo游戏中心为例
- C语言分支结构和循环结构(1)
- UE4 key to open the door
- ABAQUS realizes modal calculation of two degree of freedom vibration system
猜你喜欢
Server network performance tuning tool
Realization of a springboard machine
Web3流量聚合平台Starfish OS,给玩家元宇宙新范式体验
浏览器页面的渲染流程
Application of workflow engine in vivo marketing automation | engine 03
Angr principle and Practice (I) -- principle
电子信息工程专业毕设题目选题推荐
MVC模式和三层架构
Activity recommendation | Apache pulsar's exploration and practice in vivo will be broadcast soon
MySQL中的日志“binlog”的三种格式这么好玩
随机推荐
polygon 链 matic概念及底层机制
一种跳板机的实现思路
Vivo official website app full model UI adaptation scheme
UE4 set collision body
mysql约束之默认约束default
Spark advanced features, 220720,
UE4 use of vegetation tools
服务器网络性能调优案例
What is I18N and what is its function
What if only the mouse displays when win11 is turned on?
flask框架添加异步任务处理模型任务
Application of workflow engine in vivo marketing automation | engine 03
Causes of server buffer/cache and buffer/cache release
pytorch优化器: optim.SGD && optimizer.zero_grad()
LVS load balancing cluster
Principle and performance analysis of lepton lossless compression
Gd32f470 serial port idle interrupt +dma
重装Win11系统如何在线一键进行?
STL resize容量规律集合
IO流的分类和方法