23
Graphics Programming on Raspberry Pi - Framebuffer 介紹 台灣樹莓派 <[email protected]> Jun 23, 2016/Raspberry Pi Meetup#14

Introduction to Framebuffer

Embed Size (px)

Citation preview

Page 1: Introduction to Framebuffer

Graphics Programming on Raspberry Pi- Framebuffer 介紹

台灣樹莓派 <[email protected]>Jun 23, 2016/Raspberry Pi Meetup#14

Page 2: Introduction to Framebuffer

姓名標示 — 非商業性 — 相同方式分享

CC (Creative Commons)

姓名標示 — 你必須給予 適當表彰、提供指向本授權條款的連結,以及 指出(本作品的原始版本)是否已被變更。你可以任何合理方式為前述表彰,但不得以任何方式暗示授權人為你或你的使用方式背書。

非商業性 — 你不得將本素材進行商業目的之使用。

相同方式分享 — 若你重混、轉換本素材,或依本素材建立新素材,你必須依本素材的授權條款來散布你的貢獻物。

Page 3: Introduction to Framebuffer

● 什麼是 Framebuffer ?

● Framebuffer 怎麼用?

● Demo

Outline

Page 4: Introduction to Framebuffer

● 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

Page 5: Introduction to Framebuffer

● 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

Page 6: Introduction to Framebuffer

6

硬體抽象化

http://www.clivemaxfield.com/diycalculator/popup-h-console.shtml

Page 7: Introduction to Framebuffer

Graphics Stack on Linux

Page 8: Introduction to Framebuffer

Typical Desktop Linux

https://goo.gl/6plONc

Page 9: Introduction to Framebuffer

Raspbian

https://goo.gl/6plONc

Page 10: Introduction to Framebuffer

Raspbian without X

https://goo.gl/6plONc

Page 11: Introduction to Framebuffer

Framebuffer 怎麼用?

Page 12: Introduction to Framebuffer

● 螢幕截圖與還原● 顯示開機畫面● 自由繪圖● 鏡像畫面

常用情境

Page 13: Introduction to 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

Page 14: Introduction to 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

Page 15: Introduction to Framebuffer

自由繪圖

https://www.kernel.org/doc/Documentation/fb/framebuffer.txt

Page 16: Introduction to Framebuffer

#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

Page 17: Introduction to Framebuffer

● 將檔案映射到虛擬記憶體● 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

Page 18: Introduction to Framebuffer

#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

Page 19: Introduction to Framebuffer

19

● LCD 和 Framebuffer 的關係

鏡像畫面

http://www.clivemaxfield.com/diycalculator/popup-h-console.shtml

Page 20: Introduction to Framebuffer

20

透過 GPIO 將 RGB 寫到 TFT-LCD

http://www.myu.ac.jp/~xkozima/lab/raspTutorial3.html

Page 21: Introduction to Framebuffer

21

Page 22: Introduction to Framebuffer

● 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

Page 23: Introduction to Framebuffer

23

Raspberry Pi Rocks the World

Thanks