View
74.878
Download
1
Category
Preview:
Citation preview
Graphics Programming on Raspberry Pi- Framebuffer 介紹
台灣樹莓派 <sosorry@raspberrypi.com.tw>Jun 23, 2016/Raspberry Pi Meetup#14
姓名標示 — 非商業性 — 相同方式分享
CC (Creative Commons)
姓名標示 — 你必須給予 適當表彰、提供指向本授權條款的連結,以及 指出(本作品的原始版本)是否已被變更。你可以任何合理方式為前述表彰,但不得以任何方式暗示授權人為你或你的使用方式背書。
非商業性 — 你不得將本素材進行商業目的之使用。
相同方式分享 — 若你重混、轉換本素材,或依本素材建立新素材,你必須依本素材的授權條款來散布你的貢獻物。
● 什麼是 Framebuffer ?
● Framebuffer 怎麼用?
● Demo
Outline
● The frame buffer device provides an abstraction for the graphics hardware.
● It represents the frame buffer of some video hardware and allows application software to access the graphics hardware through a well-defined interface.
什麼是 Fraembuffer ?
https://www.kernel.org/doc/Documentation/fb/framebuffer.txt
● The frame buffer device provides an abstraction for the graphics hardware.
● It represents the frame buffer of some video hardware and allows application software to access the graphics hardware through a well-defined interface.
一塊記憶體 , 目的是抽象化顯示卡的硬體
什麼是 Fraembuffer ?
https://www.kernel.org/doc/Documentation/fb/framebuffer.txt
6
硬體抽象化
http://www.clivemaxfield.com/diycalculator/popup-h-console.shtml
Graphics Stack on Linux
Typical Desktop Linux
https://goo.gl/6plONc
Raspbian
https://goo.gl/6plONc
Raspbian without X
https://goo.gl/6plONc
Framebuffer 怎麼用?
● 螢幕截圖與還原● 顯示開機畫面● 自由繪圖● 鏡像畫面
常用情境
● 掛在 /dev 的裝置檔 , 預設 X server 會使用 /dev/fb0● 截圖: $ cp /dev/fb0 fb.raw● 還原: $ sudo cp fb.raw /dev/fb0
● 將 raw 轉成 PNG 格式
● 預設 320x240, 影像深度 16-bit● $ sudo apt-get install libnetpbm10● $ perl iraw2png <screen.raw >screen.png
螢幕截圖與還原
https://blackfin.uclinux.org/doku.php?id=uclinux-dist:framebuffer
● fbi - Linux framebuffer imageviewer
● 步驟● $ sudo apt-get install fbi● 建立一個 sysvinit 服務 , 包含以下指令● /usr/bin/fbi -T 1 -noverbose -a /etc/splash.png ● 設定開機就啟動
顯示開機畫面
http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/custom-boot-up-screen
自由繪圖
https://www.kernel.org/doc/Documentation/fb/framebuffer.txt
#include <linux/fb.h>
int main(int argc, char* argv[])
{
int fbfd = 0;
struct fb_var_screeninfo var_info;
fbfd = open("/dev/fb0", O_RDWR);
ioctl(fbfd, FBIOGET_VSCREENINFO, &var_info);
printf("%dx%d, %d bpp\n",
var_info.xres, var_info.yres, var_info.bits_per_pixel);
close(fbfd);
return 0;
}https://github.com/rst-/raspberry-compote
● 將檔案映射到虛擬記憶體● void *mmap( void *addr,
size_t len, int prot, int flag, int filedes, off_t off);
mmap
http://docs.linuxtone.org/ebooks/C&CPP/c/ch28s08.html
#include <linux/fb.h>
int main(int argc, char* argv[])
{
int fbfd = 0;
● struct fb_fix_screeninfo finfo;
● long int screensize = 0;
● char *fbp = 0;
● fbfd = open("/dev/fb0", O_RDWR);
● ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo);
● screensize = finfo.smem_len;
● fbp = (char*)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
● memset(fbp, 0xff, screensize/2);
● memset(fbp + screensize/2, 0x18, screensize/2);
●
● munmap(fbp, screensize);
● close(fbfd);
● return 0;
}
https://github.com/rst-/raspberry-compote
19
● LCD 和 Framebuffer 的關係
鏡像畫面
http://www.clivemaxfield.com/diycalculator/popup-h-console.shtml
20
透過 GPIO 將 RGB 寫到 TFT-LCD
http://www.myu.ac.jp/~xkozima/lab/raspTutorial3.html
21
● https://www.kernel.org/doc/Documentation/fb/framebuffer.txt
● http://tldp.org/HOWTO/Framebuffer-HOWTO/● http://raspberrycompote.blogspot.tw/● http://www.myu.ac.jp/~xkozima/lab/raspTutorial3.html
Reference
23
Raspberry Pi Rocks the World
Thanks
Recommended