博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
frambuffer lcd.c
阅读量:4556 次
发布时间:2019-06-08

本文共 2852 字,大约阅读时间需要 9 分钟。

1 /**  2 *lcd.c  3 */  4 #include 
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include "type.h" 14 #include "lcd.h" 15 16 17 lcd_t lcd; 18 19 s32 lcd_fb_init(void) 20 { 21 //打开显示设备 22 lcd.fd = open("/dev/fb0", O_RDWR); 23 if (!lcd.fd) 24 { 25 printf("Error: open /dev/fb0\n"); 26 return -1; 27 } 28 29 //get fix information 30 if (ioctl(lcd.fd, FBIOGET_FSCREENINFO, &lcd.finfo)) 31 { 32 printf("Error: get fix info"); 33 return -1; 34 } 35 36 //get variable information 37 if (ioctl(lcd.fd, FBIOGET_VSCREENINFO, &lcd.vinfo)) 38 { 39 printf("Error: get var info"); 40 return -1; 41 } 42 43 lcd.vinfo.bits_per_pixel = 16; 44 //lcd screen byte size 45 lcd.screensize = lcd.vinfo.xres * lcd.vinfo.bits_per_pixel / 8 + 46 lcd.vinfo.yres *lcd.vinfo.xres; 47 48 //对象映射 49 lcd.fbp = (u8 *)mmap(0, lcd.screensize, PROT_READ | PROT_WRITE, MAP_SHARED, lcd.fd, 0); 50 if ((int)lcd.fbp == -1) 51 { 52 printf("Error: mmap\n"); 53 return -1; 54 } 55 } 56 void lcd_fb_release(void) 57 { 58 /*释放缓冲区,关闭设备*/ 59 munmap(lcd.fbp, lcd.screensize); 60 close(lcd.fd); 61 return ; 62 } 63 64 void lcd_fb_clear(void) 65 { 66 memset(lcd.fbp, 0, lcd.screensize); 67 return ; 68 } 69 70 void lcd_fb_info(void) 71 { 72 printf("xres: %d\n", lcd.vinfo.xres); 73 printf("yres: %d\n", lcd.vinfo.yres); 74 printf("screensize: %d\n", lcd.screensize); 75 printf("bits_per_pixel: %d\n", lcd.vinfo.bits_per_pixel); 76 return; 77 } 78 79 80 void lcd_fb_put_pixel(u16 x, u16 y, color_t color) 81 { 82 u32 location; 83 if (x > lcd.vinfo.xres - 1) x = lcd.vinfo.xres - 1; 84 if (y > lcd.vinfo.yres - 1) y = lcd.vinfo.yres - 1; 85 location = x * lcd.vinfo.bits_per_pixel / 8 + y * lcd.vinfo.xres; 86 if (y%2) location -= (lcd.vinfo.yres + 80);/*if you know why? please tell me*/ 87 88 if (32 == lcd.vinfo.bits_per_pixel) 89 { 90 *((u8*) (lcd.fbp + location)) = color.r; 91 *((u8*) (lcd.fbp + location + 1)) = color.g; 92 *((u8*) (lcd.fbp + location + 2)) = color.b; 93 *((u8*) (lcd.fbp + location + 3)) = 0;/*transplite, unused*/ 94 } 95 else if (16 == lcd.vinfo.bits_per_pixel) 96 { 97 *((u16*)(lcd.fbp + location)) = (u16)(color.r << 11 | color.g << 5 |color.b ); 98 } 99 else 100 {101 ;//102 }103 }104 105 void lcd_fb_draw_line(u16 x1, u16 y1, u16 x2, u16 y2, color_t color)106 {107 int i = 0;108 int d = 0;109 if (abs(y2 - y1) > abs(x2 - x1))110 {111 d = (y2 > y1) ? 1 : -1;112 for (i = y1; i != y2; i +=d)113 {114 lcd_fb_put_pixel(x1 + (i - y1) * (x2 - x1) / (y2 - y1), i, color);115 }116 }117 else 118 {119 d = (x2 > x1) ? 1 : -1;120 for (i = x1; i != x2; i+=d)121 {122 lcd_fb_put_pixel(i, y1 + (i - x1) * (y2 - y1) / (x2 - x1), color);123 }124 }125 }

 

转载于:https://www.cnblogs.com/ganrui/p/3701649.html

你可能感兴趣的文章
HIVE的安装和使用
查看>>
CentOS使用Ubuntu的start-stop-daemon来启动守护进程
查看>>
FreeMarker-简单示例
查看>>
Working Plan 优先队列+贪心
查看>>
session和cookie
查看>>
二维数组排序 array_multisor
查看>>
添加工具条
查看>>
使用ListView和自定义Adapter完成列表信息
查看>>
js中邦定事件与解绑支持匿名函数
查看>>
Vue directive自定义指令
查看>>
JavaScript计算屏幕上元素位置
查看>>
整理 : 查看和修改 mysql库、表、字段编码
查看>>
36种按钮样式
查看>>
linux日常易忘指令
查看>>
C#用户控件的使用
查看>>
徽州行——太极湖村
查看>>
DIV+CSS 网页布局之:两列布局
查看>>
【leetcode刷题笔记】Linked List Cycle II
查看>>
C#高级编程(第9版)pdf
查看>>
Asp.Net 关于Could not load file or assembly 'Microsoft.Office.Interop.Excel, Version=11.0.0.0,解决办法...
查看>>