Slide 1

Slide 1 text

Graphics Programming on Raspberry Pi - Framebuffer 介紹 台灣樹莓派 Jun 23, 2016/Raspberry Pi Meetup#14

Slide 2

Slide 2 text

姓名標示 — 非商業性 — 相同方式分享 CC (Creative Commons) 姓名標示 — 你必須給予 適當表彰、提供指向本授權 條款的連結,以及 指出(本作品的原始版本)是否已 被變更。你可以任何合理方式為前述表彰,但不得以 任何方式暗示授權人為你或你的使用方式背書。 非商業性 — 你不得將本素材進行商業目的之使 用。 相同方式分享 — 若你重混、轉換本素材,或依本 素材建立新素材,你必須依本素材的授權條款來 散布你的貢獻物。

Slide 3

Slide 3 text

3 ● Raspberry Pi 官方經銷商 ● 專注 Raspberry Pi 應用與推廣 , 舉辦社群活動 關於我們

Slide 4

Slide 4 text

4 ● COSCUP,MakerConf,PyCon,HKOSCon 講者 ● 投影片 ● https://speakerdeck.com/piepie_tw ● 程式碼 ● https://github.com/piepie-tw 分享 x 教學

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

● 什麼是 Framebuffer ? ● Framebuffer 怎麼用? ● Demo Outline

Slide 7

Slide 7 text

● 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

Slide 8

Slide 8 text

● 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

Slide 9

Slide 9 text

9 硬體抽象化 http://www.clivemaxfield.com/diycalculator/popup-h-console.shtml

Slide 10

Slide 10 text

Graphics Stack on Linux

Slide 11

Slide 11 text

Typical Desktop Linux https://goo.gl/6plONc

Slide 12

Slide 12 text

Raspbian https://goo.gl/6plONc

Slide 13

Slide 13 text

Raspbian without X https://goo.gl/6plONc

Slide 14

Slide 14 text

Framebuffer 怎麼用?

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

● 掛在 /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

Slide 17

Slide 17 text

● 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

Slide 18

Slide 18 text

自由繪圖 https://www.kernel.org/doc/Documentation/fb/framebuffer.txt

Slide 19

Slide 19 text

#include 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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

#include 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

Slide 22

Slide 22 text

22 ● LCD 和 Framebuffer 的關係 鏡像畫面 http://www.clivemaxfield.com/diycalculator/popup-h-console.shtml

Slide 23

Slide 23 text

23 透過 GPIO 將 RGB 寫到 TFT-LCD http://www.myu.ac.jp/~xkozima/lab/raspTutorial3.html

Slide 24

Slide 24 text

24

Slide 25

Slide 25 text

● https://www.kernel.org/doc/Documentation/fb/frameb uffer.txt ● http://tldp.org/HOWTO/Framebuffer-HOWTO/ ● http://raspberrycompote.blogspot.tw/ ● http://www.myu.ac.jp/~xkozima/lab/raspTutorial3.html Reference

Slide 26

Slide 26 text

26 Raspberry Pi Rocks the World Thanks