TFT LCD Framebuffer驱动配置
文章目录
- TFT LCD Framebuffer驱动配置
- 1、硬件准备
- 2、软件配置
- 2.1 启用SPI驱动
- 2.2 TFT LCD设备驱动树配置
本文将以ILI9341 LCD为例,将详细介绍如何配置TFT LCD的Framebuffer驱动。
1、硬件准备
- Raspberry Pi Zero W开发板一个(镜像Linux内核版本为5.18.84+)
- TFT LCD 模块一个(ILI9341驱动IC)
- 连接线
- 数据线
- 面包板
TFT LCD与Raspberry Pi Zero W接线如下:
序号 | TFT LCD | Raspberry PI |
---|---|---|
1 | VCC | 3.3V或5V |
2 | GND | GND |
3 | SCK | GPIO 11 SCLK (SPI0) |
4 | SDA | GPIO10 MOSI (SPI0) |
5 | RST | GPIO 6 |
6 | DC | GPIO 5 |
7 | CS | GPIO8 Chip-Enable-CE0(SPI0) |
Raspberry PI Zero W的引脚如下:
2、软件配置
2.1 启用SPI驱动
在命令行中输入:
sudo raspi-config
选择3 Interface Options
进入接口驱动配置页面:
选择I4 SPI Enable/disable automatic loading of SPI kernel module
开启或关闭SPI驱动。
另外,如果不想在命令中配置,也可以在图形界面中配置。还可以修改/boot/config.txt文件:
将 #
符号删除即可启用spi。
2.2 TFT LCD设备驱动树配置
下面将创建自定义的DTS文件。下面将创建一个名称为ili9341.dts
的文件。其内容如下:
/dts-v1/;
/plugin/;/ {compatible = "brcm,bcm2835";// Enable the SPI controllerfragment@0 {target = <&spi0>;__overlay__ {status = "okay";};};// Enabling the SPI controller also enables spidev on cs0, so we have disable itfragment@1 {target = <&spidev0>;__overlay__ {status = "disabled";};};fragment@2 {target = <&spi0>;__overlay__ {/* needed to avoid dtc warning */#address-cells = <1>;#size-cells = <0>;display: display@0{// MIPI DBI compatible driver// This driver is used because it can ignore an illegal rotate value// and doesn't have a set_gamma() function.compatible = "ilitek,ili9341";reg = <0>; // Chip Select 0spi-max-frequency = <32000000>; // 32MHzreset-gpios = <&gpio 6 1>; // reset is active low hence the 1dc-gpios = <&gpio 5 0>;width = <320>;height = <240>;buswidth = <8>; // Most controllers use this value// This is a hack to prevent fb_s6d02a1.c:set_var() from issuing// command 0x36 after the init sequence has been applied and thus// changing the config.rotate = <1>;// see drivers/staging/fbtft/fb_ili9341.c:init_display() for how this looks in the driver// Command 0x36 is taken from the fb_ili9341.c:set_var() function.init = <0x10000010x20000050x10000280x10000cf 0x00 0x83 0x300x10000ed 0x64 0x03 0x12 0x810x10000e8 0x85 0x01 0x790x10000cb 0x39 0x2c 0x00 0x34 0x020x10000f7 0x200x10000ea 0x00 0x000x10000c0 0x260x10000c1 0x110x10000c5 0x35 0x3e0x10000c7 0xbe0x100003a 0x550x1000036 0x280x10000b1 0x00 0x1b0x1000026 0x010x10000f2 0x080x1000026 0x010x10000e0 0x1f 0x1a 0x18 0x0a 0x0f 0x06 0x45 0x87 0x32 0x0a 0x07 0x02 0x07 0x05 0x000x10000e1 0x00 0x25 0x27 0x05 0x10 0x09 0x3a 0x78 0x4d 0x05 0x18 0x0d 0x38 0x3a 0x1f0x10000b7 0x070x10000b6 0x0a 0x82 0x27 0x000x10000110x20000640x10000290x2000064>;debug = <0x4000000>; // print init commands to the kernel log};};};
};
请根据自己的接线修改引脚:
reset-gpios
:LCD 的RES引脚dc-gpios
:LCD的DC引脚
init
为LCD的初始化指令。
编译DTS
在命令行中,执行如下命令:
dtc -o ili9341.dtbo ili9341.dts
将编译好的dtbo文件复制到/boot/overlays/
:
sudo cp ili9341.dtbo /boot/overlays/
配置overlays
打开/boot/config.txt文件,在文件末尾添加如下内容:
dtoverlay=ili9341
保存并重新启动系统。在系统启动完成后,在命令行执行命令:
dmesg
可以看到TFT的Framebuffer内核日志信息:
[ 40.657276] fbtft: module is from the staging directory, the quality is unknown, you have been warned.
[ 40.911475] fb_ili9341: module is from the staging directory, the quality is unknown, you have been warned.
[ 41.314042] SPI driver fb_ili9341 has no spi_device_id for ilitek,ili9341
[ 41.314487] fb_ili9341 spi0.0: fbtft_property_value: width = 320
[ 41.314532] fb_ili9341 spi0.0: fbtft_property_value: height = 240
[ 41.314562] fb_ili9341 spi0.0: fbtft_property_value: buswidth = 8
[ 41.314594] fb_ili9341 spi0.0: fbtft_property_value: debug = 67108864
[ 41.314620] fb_ili9341 spi0.0: fbtft_property_value: rotate = 1
[ 41.457358] cfg80211: Loading compiled-in X.509 certificates for regulatory database
[ 41.515507] fb_ili9341 spi0.0: init: write_register:
[ 41.515554] fb_ili9341 spi0.0: buf[0] = 01
[ 41.515705] fb_ili9341 spi0.0: init: msleep(5)
[ 41.547050] fb_ili9341 spi0.0: init: write_register:
[ 41.547097] fb_ili9341 spi0.0: buf[0] = 28
[ 41.549533] fb_ili9341 spi0.0: init: write_register:
[ 41.549576] fb_ili9341 spi0.0: buf[0] = CF
[ 41.549607] fb_ili9341 spi0.0: buf[1] = 00
[ 41.549628] fb_ili9341 spi0.0: buf[2] = 83
[ 41.549649] fb_ili9341 spi0.0: buf[3] = 30
[ 41.550784] fb_ili9341 spi0.0: init: write_register:
[ 41.550821] fb_ili9341 spi0.0: buf[0] = ED
[ 41.550848] fb_ili9341 spi0.0: buf[1] = 64
[ 41.550868] fb_ili9341 spi0.0: buf[2] = 03
[ 41.550888] fb_ili9341 spi0.0: buf[3] = 12
[ 41.550907] fb_ili9341 spi0.0: buf[4] = 81
[ 41.551978] fb_ili9341 spi0.0: init: write_register:
[ 41.552019] fb_ili9341 spi0.0: buf[0] = E8
[ 41.552045] fb_ili9341 spi0.0: buf[1] = 85
[ 41.552067] fb_ili9341 spi0.0: buf[2] = 01
[ 41.552088] fb_ili9341 spi0.0: buf[3] = 79
[ 41.556254] fb_ili9341 spi0.0: init: write_register:
[ 41.556350] fb_ili9341 spi0.0: buf[0] = CB
[ 41.556382] fb_ili9341 spi0.0: buf[1] = 39
[ 41.556404] fb_ili9341 spi0.0: buf[2] = 2C
[ 41.556424] fb_ili9341 spi0.0: buf[3] = 00
[ 41.556444] fb_ili9341 spi0.0: buf[4] = 34
[ 41.556464] fb_ili9341 spi0.0: buf[5] = 02
[ 41.558014] fb_ili9341 spi0.0: init: write_register:
[ 41.558055] fb_ili9341 spi0.0: buf[0] = F7
[ 41.558083] fb_ili9341 spi0.0: buf[1] = 20
[ 41.559167] fb_ili9341 spi0.0: init: write_register:
[ 41.559208] fb_ili9341 spi0.0: buf[0] = EA
[ 41.559236] fb_ili9341 spi0.0: buf[1] = 00
[ 41.559257] fb_ili9341 spi0.0: buf[2] = 00
[ 41.561600] fb_ili9341 spi0.0: init: write_register:
[ 41.561643] fb_ili9341 spi0.0: buf[0] = C0
[ 41.561672] fb_ili9341 spi0.0: buf[1] = 26
[ 41.561848] fb_ili9341 spi0.0: init: write_register:
[ 41.561904] fb_ili9341 spi0.0: buf[0] = C1
[ 41.561935] fb_ili9341 spi0.0: buf[1] = 11
[ 41.566661] fb_ili9341 spi0.0: init: write_register:
[ 41.566706] fb_ili9341 spi0.0: buf[0] = C5
[ 41.566736] fb_ili9341 spi0.0: buf[1] = 35
[ 41.566757] fb_ili9341 spi0.0: buf[2] = 3E
[ 41.569197] fb_ili9341 spi0.0: init: write_register:
[ 41.569236] fb_ili9341 spi0.0: buf[0] = C7
[ 41.569267] fb_ili9341 spi0.0: buf[1] = BE
[ 41.569440] fb_ili9341 spi0.0: init: write_register:
[ 41.569465] fb_ili9341 spi0.0: buf[0] = 3A
[ 41.569489] fb_ili9341 spi0.0: buf[1] = 55
[ 41.571529] fb_ili9341 spi0.0: init: write_register:
[ 41.571572] fb_ili9341 spi0.0: buf[0] = 36
[ 41.571600] fb_ili9341 spi0.0: buf[1] = 28
[ 41.580923] fb_ili9341 spi0.0: init: write_register:
[ 41.580969] fb_ili9341 spi0.0: buf[0] = B1
[ 41.580998] fb_ili9341 spi0.0: buf[1] = 00
[ 41.581019] fb_ili9341 spi0.0: buf[2] = 1B
[ 41.588734] fb_ili9341 spi0.0: init: write_register:
[ 41.588781] fb_ili9341 spi0.0: buf[0] = 26
[ 41.588811] fb_ili9341 spi0.0: buf[1] = 01
[ 41.633770] fb_ili9341 spi0.0: init: write_register:
[ 41.633816] fb_ili9341 spi0.0: buf[0] = F2
[ 41.633847] fb_ili9341 spi0.0: buf[1] = 08
[ 41.636043] fb_ili9341 spi0.0: init: write_register:
[ 41.636086] fb_ili9341 spi0.0: buf[0] = 26
[ 41.636116] fb_ili9341 spi0.0: buf[1] = 01
[ 41.669646] fb_ili9341 spi0.0: init: write_register:
[ 41.669691] fb_ili9341 spi0.0: buf[0] = E0
[ 41.669720] fb_ili9341 spi0.0: buf[1] = 1F
[ 41.669740] fb_ili9341 spi0.0: buf[2] = 1A
[ 41.669759] fb_ili9341 spi0.0: buf[3] = 18
[ 41.669779] fb_ili9341 spi0.0: buf[4] = 0A
[ 41.669800] fb_ili9341 spi0.0: buf[5] = 0F
[ 41.669819] fb_ili9341 spi0.0: buf[6] = 06
[ 41.669838] fb_ili9341 spi0.0: buf[7] = 45
[ 41.669857] fb_ili9341 spi0.0: buf[8] = 87
[ 41.669877] fb_ili9341 spi0.0: buf[9] = 32
[ 41.669897] fb_ili9341 spi0.0: buf[10] = 0A
[ 41.669918] fb_ili9341 spi0.0: buf[11] = 07
[ 41.669938] fb_ili9341 spi0.0: buf[12] = 02
[ 41.669958] fb_ili9341 spi0.0: buf[13] = 07
[ 41.669977] fb_ili9341 spi0.0: buf[14] = 05
[ 41.669997] fb_ili9341 spi0.0: buf[15] = 00
[ 41.683625] fb_ili9341 spi0.0: init: write_register:
[ 41.683670] fb_ili9341 spi0.0: buf[0] = E1
[ 41.683788] fb_ili9341 spi0.0: buf[1] = 00
[ 41.683815] fb_ili9341 spi0.0: buf[2] = 25
[ 41.683838] fb_ili9341 spi0.0: buf[3] = 27
[ 41.683859] fb_ili9341 spi0.0: buf[4] = 05
[ 41.683879] fb_ili9341 spi0.0: buf[5] = 10
[ 41.683899] fb_ili9341 spi0.0: buf[6] = 09
[ 41.683919] fb_ili9341 spi0.0: buf[7] = 3A
[ 41.683939] fb_ili9341 spi0.0: buf[8] = 78
[ 41.683958] fb_ili9341 spi0.0: buf[9] = 4D
[ 41.683977] fb_ili9341 spi0.0: buf[10] = 05
[ 41.683998] fb_ili9341 spi0.0: buf[11] = 18
[ 41.684019] fb_ili9341 spi0.0: buf[12] = 0D
[ 41.684038] fb_ili9341 spi0.0: buf[13] = 38
[ 41.684059] fb_ili9341 spi0.0: buf[14] = 3A
[ 41.684079] fb_ili9341 spi0.0: buf[15] = 1F
[ 41.693430] fb_ili9341 spi0.0: init: write_register:
[ 41.693474] fb_ili9341 spi0.0: buf[0] = B7
[ 41.693504] fb_ili9341 spi0.0: buf[1] = 07
[ 41.707164] fb_ili9341 spi0.0: init: write_register:
[ 41.707209] fb_ili9341 spi0.0: buf[0] = B6
[ 41.707240] fb_ili9341 spi0.0: buf[1] = 0A
[ 41.707261] fb_ili9341 spi0.0: buf[2] = 82
[ 41.707283] fb_ili9341 spi0.0: buf[3] = 27
[ 41.707303] fb_ili9341 spi0.0: buf[4] = 00
[ 41.719204] fb_ili9341 spi0.0: init: write_register:
[ 41.719250] fb_ili9341 spi0.0: buf[0] = 11
[ 41.721594] fb_ili9341 spi0.0: init: msleep(100)
[ 41.833878] fb_ili9341 spi0.0: init: write_register:
[ 41.833925] fb_ili9341 spi0.0: buf[0] = 29
[ 41.834076] fb_ili9341 spi0.0: init: msleep(100)
在设备目录中,我们将可以看到有两个framebuffer设备文件,fb0,fb1,其中fb1就是我们的TFT LCD的Framebuffer设备。
从内核日志输出可以知道,fb_ili9341已经启动。结果如下: