鍍金池/ 教程/ 嵌入式/ 樹(shù)莓派 spi 液晶屏支持
樹(shù)莓派 GPIO 控制
樹(shù)莓派介紹
樹(shù)莓派做 wifi 熱點(diǎn)
樹(shù)莓派網(wǎng)絡(luò)與更新配置
樹(shù)莓派內(nèi)核編譯與固件升級(jí)
樹(shù)莓派做 web 服務(wù)器
樹(shù)莓派啟動(dòng)方式及支持的系統(tǒng)
樹(shù)莓派配置
樹(shù)莓派 spi 液晶屏支持
樹(shù)莓派常用軟件及服務(wù)

樹(shù)莓派 spi 液晶屏支持

樹(shù)莓派官方支持 av 及 HDMI 輸出,板子上預(yù)留了一個(gè) csi 接口的液晶顯示屏,但是一直沒(méi)有相應(yīng)的模組出現(xiàn)。在很多應(yīng)用場(chǎng)合我們需要一些小型的液晶屏顯示一些基本的信息,所以小屏驅(qū)動(dòng)很是必要。

在 github 上有一個(gè)開(kāi)源工程:notro/fbtft,完整的實(shí)現(xiàn)了 framebuffer 驅(qū)動(dòng),讓樹(shù)莓派完美支持 tft 液晶,下面對(duì)移植過(guò)程進(jìn)行一個(gè)簡(jiǎn)單說(shuō)明。

官網(wǎng)地址

工程首頁(yè):https://github.com/notro

fbtft 源碼:https://github.com/notro/fbtft

編譯好的固件(基于3.12.25+):https://github.com/notro/rpi-firmware

使用說(shuō)明(wiki):https://github.com/notro/fbtft/wiki

使用編譯好的固件(3.12.25+)

環(huán)境:樹(shù)莓派

https://github.com/notro/rpi-firmware

打開(kāi) SPI

樹(shù)莓派默認(rèn) spi 是關(guān)掉的,我們需要打開(kāi)

sudo vi /etc/modprobe.d/raspi-blacklist.conf

把下面這句話(huà)前面的#號(hào)刪掉

blacklist spi-bcm2708

下載

配置

手動(dòng)加載模塊

sudo modprobe fbtft_device name=adafruit22

name 后面的名字,要跟相應(yīng)的液晶驅(qū)動(dòng)芯片移植,使用的液晶芯片為:fb_ra8875,所以這里寫(xiě)的是:er_tftm050_2。其它芯片請(qǐng)查閱:https://github.com/notro/fbtft/blob/master/fbtft_device.c 文件。正常會(huì)提示以下信息。

fbtft_device:  SPI devices registered:
   fbtft_device:      spidev spi0.0 500kHz 8 bits mode=0x00
   fbtft_device:      spidev spi0.1 500kHz 8 bits mode=0x00
   fbtft_device:  'fb' Platform devices registered:
   fbtft_device:      bcm2708_fb id=-1 pdata? no
   fbtft_device: Deleting spi0.0
   fbtft_device:  GPIOS used by 'adafruit22':
   fbtft_device:    'reset' = GPIO25
   fbtft_device:    'led' = GPIO23
   fbtft_device:  SPI devices registered:
   fbtft_device:      spidev spi0.1 500kHz 8 bits mode=0x00
   fbtft_device:      fb_hx8340bn spi0.0 32000kHz 8 bits mode=0x00
   graphics fb1: fb_hx8340bn frame buffer, 176x220, 75 KiB video memory, 16 KiB buffer memory, fps=20, spi0.0 at 32 MHz

在/dev/目錄下出現(xiàn): /dev/fb1 設(shè)備

自動(dòng)加載模塊

sudo vi  /etc/modules

加入以下語(yǔ)句,既可以在啟動(dòng)時(shí)自動(dòng)加載模塊。

spi-bcm2708
fbtft_device name=er_tftm050_2 speed=28000000 fps=25 verbose=0

使用

手動(dòng)啟動(dòng) x11 和控制臺(tái)到新的液晶屏

X Windows 顯示在 fb1 上:

$FRAMEBUFFER=/dev/fb1 startx

Console 顯示在 fb1 上:

$con2fbmap 1 1

自動(dòng)登陸 x11

sudo vi /etc/inittab
    #1:2345:respawn:/sbin/getty --noclear 38400 tty1
    1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1

sudo vi /etc/rc.local
    su -l pi -c "env FRAMEBUFFER=/dev/fb1 startx &"

測(cè)試

將 fb0 上的內(nèi)容直接拷貝到 fb1 上,fb0 和 fb1 同步

https://github.com/notro/fbtft/wiki/Framebuffer-use#framebuffer-mirroring

$git clone https://github.com/tasanakorn/rpi-fbcp
$cd rpi-fbcp/
$mkdir build
$cd build/
$cmake ..
$make
$sudo install fbcp /usr/local/bin/fbcp

啟動(dòng):fbcp &
關(guān)閉fbcp:killall fbcp

啟動(dòng)時(shí)使用 fb1

$sudo apt-get install xserver-xorg-video-fbdev

$sudo vi /usr/share/X11/xorg.conf.d/99-fbdev.conf

加入以下語(yǔ)句:

Section "Device"  
  Identifier "myfb"
  Driver "fbdev"
  Option "fbdev" "/dev/fb1"
EndSection

啟動(dòng):startx

測(cè)試:

apt-get -y install fbi
fbi -d /dev/fb1 -T 1 -noverbose -a test.jpg

由內(nèi)核及源碼編譯

下載、編譯內(nèi)核源碼

請(qǐng)見(jiàn)《樹(shù)莓派內(nèi)核編譯與固件升級(jí)》

下載、編譯 fbtft 源碼

$cd linux(進(jìn)入下載好的內(nèi)核源碼目錄)
$cd drivers/video
$git clone https://github.com/notro/fbtft.git

修改內(nèi)核源碼的 Kconfig 及 Makefine

 Add to drivers/video/Kconfig:   source "drivers/video/fbtft/Kconfig"
 Add to drivers/video/Makefile:  obj-y += fbtft/
$make menuconfig(在配置界面加入所選用液晶的驅(qū)動(dòng)支持)
Device Drivers  --->   
 Graphics support  --->   
<M> Support for small TFT LCD display modules  --->  

<M>   FB driver for the HX8353D LCD Controller  
<M>   FB driver for the ILI9320 LCD Controller                                                 
<M>   FB driver for the ILI9325 LCD Controller                                   
<M>   FB driver for the ILI9340 LCD Controller                                     
<M>   FB driver for the ILI9341 LCD Controller                              
< >     FB driver for the ILI9481 LCD Controller                                             
<M>   FB driver for the ILI9486 LCD Controller                                         
<M>   FB driver for the PCD8544 LCD Controller                                       
<M>   FB driver for the RA8875 LCD Controller