入门linux之全志H3 nanopi 点亮ST7789VW IPS屏
- NanoPi-NEO-Air 入门
-
- Nnaopi的IO
- 设备树(sun8i-h3-nanopi-neo-air.dts)中禁用其他SPI节点和使能ST7789VW节点:
- 修改初始化函数
- 使用1.14(135*240)ips屏幕的注意修改函数set_addr_win
- 把驱动编译进内核
- 编译内核 设备树 下载重启看效果
- 实际效果
- 播放视频
- 运行QT
NanoPi-NEO-Air 入门
记录一下第一次尝试用linux点亮spi屏幕的过程,一共尝试了0.96 ST7735S(80160) \1.8 st7735R(128160) \1.14 st7789v(135240) \1.3 st7789vw (240240)这几个屏幕,有个奇怪的现象就是必须要接SPI0的CS引脚到显示屏上才能正常显示。
Nnaopi的IO
设备树(sun8i-h3-nanopi-neo-air.dts)中禁用其他SPI节点和使能ST7789VW节点:
在最后加上以下代码,st7735r和st7735s也调试过可用,7735超过48M显示的颜色就不正常了,7789vw可以96M正常显示,原始的IO口是
DC PA1 RESET PG11 BL PA0
我改成了
DC PA1 RESET PA2 BL PA0
同时禁用hdmi,防止开机从hdmi显示
&spi0{
spidev0:spi@0{
status="disable";
};
st7789vw: st7789vw@0{
compatible = "sitronix,st7789vw";
reg = <0>;
status = "okay";
spi-max-frequency = <96000000>;
buswidth = <8>;
rotate = <0>;
fps = <60>;
rgb;
dc-gpios = <&pio 0 1 GPIO_ACTIVE_HIGH>;
reset-gpios = <&pio 0 2 GPIO_ACTIVE_HIGH>;
led-gpios = <&pio 0 0 GPIO_ACTIVE_LOW>;
debug = <0x00>;
};
// st7735r: st7735r@0{
// compatible = "sitronix,st7735r";
// reg = <0>;
// status = "okay";
// spi-max-frequency = <36000000>;
// spi-cpol;
// spi-cpha;
// rotate = <90>;
// fps = <60>;
// buswidth = <8>;
// dc-gpios = <&pio 0 1 GPIO_ACTIVE_HIGH>;
// reset-gpios = <&pio 0 2 GPIO_ACTIVE_HIGH>;
// led-gpios = <&pio 0 0 GPIO_ACTIVE_LOW>;
// debug = <0x0>;
// };
// st7735s: st7735s@0{
// compatible = "sitronix,st7735s";
// reg = <0>;
// status = "okay";
// spi-max-frequency = <36000000>;
// spi-cpol;
// spi-cpha;
// rotate = <0>;
// fps = <60>;
// buswidth = <8>;
// dc-gpios = <&pio 0 1 GPIO_ACTIVE_HIGH>;
// reset-gpios = <&pio 0 2 GPIO_ACTIVE_HIGH>;
// led-gpios = <&pio 0 0 GPIO_ACTIVE_LOW>;
// debug = <0x0>;
// };
};
&hdmi {
status = "disable";
};
修改初始化函数
原始的初始化没有复位显示屏,在初始化中添加
par->fbtftops.reset(par);
write_reg(par, PVGAMCTRL, 0xD0, 0x04, 0x0D, 0x11, 0x13, 0x2B, 0x3F, 0x54, 0x4C, 0x18, 0x0D, 0x0B, 0x1F, 0x23);
write_reg(par, NVGAMCTRL, 0xD0, 0x04, 0x0C, 0x11, 0x13, 0x2C, 0x3F, 0x44, 0x51, 0x2F, 0x1F, 0x1F, 0x20, 0x23);
static int init_display(struct fbtft_par *par)
{
par->fbtftops.reset(par);
//
write_reg(par, MIPI_DCS_EXIT_SLEEP_MODE);
mdelay(120);
write_reg(par, MIPI_DCS_SET_ADDRESS_MODE, 0x0);
write_reg(par, MIPI_DCS_SET_PIXEL_FORMAT, MIPI_DCS_PIXEL_FMT_16BIT);
write_reg(par, PORCTRL, 0x0C, 0x0C, 0x00, 0x33, 0x33);
write_reg(par, GCTRL, 0x35);
write_reg(par, VCOMS, 0x19);
write_reg(par, LCMCTRL, 0x2C);
write_reg(par, VDVVRHEN, 0x01);
write_reg(par, VRHS, 0x12);
write_reg(par, VDVS, 0x20);
write_reg(par, FRCTRL2, 0x0F);
write_reg(par, PWCTRL1, 0xA4, 0xA1);
write_reg(par, PVGAMCTRL, 0xD0, 0x04, 0x0D, 0x11, 0x13, 0x2B, 0x3F, 0x54, 0x4C, 0x18, 0x0D, 0x0B, 0x1F, 0x23);
write_reg(par, NVGAMCTRL, 0xD0, 0x04, 0x0C, 0x11, 0x13, 0x2C, 0x3F, 0x44, 0x51, 0x2F, 0x1F, 0x1F, 0x20, 0x23);
write_reg(par, MIPI_DCS_ENTER_INVERT_MODE);
write_reg(par, MIPI_DCS_SET_DISPLAY_ON);
mdelay(120);
return 0;
}
使用1.14(135*240)ips屏幕的注意修改函数set_addr_win
原始的函数没有纠正偏移量,增加以下代码(只有135*240的需要增加,其他的屏不需要):
switch(par->info->var.rotate)
{
case 0: xs+=53;xe+=53;ys+=40;ye+=40;
break;
case 90: xs+=40;xe+=40;ys+=53;ye+=53;
break;
case 180: xs+=53;xe+=53;ys+=40;ye+=40;
break;
case 270: xs+=40;xe+=40;ys+=53;ye+=53;
break;
default :
break;
}
把驱动编译进内核
最原始的内核没有ST7789VW,只有ST7789V,所以把st7789v.c复制粘贴改名为st7789vw.c,相应驱动做一下修改,并且修改fbtft目录下的Kconfig和Makefile,这里我增加了ST7789VW和ST7735S的驱动
config FB_TFT_ST7789VW
tristate "FB driver for the ST7789VW LCD Controller"
depends on FB_TFT
help
This enables generic framebuffer support for the Sitronix ST7789VW
display controller. The controller is intended for small color
displays with a resolution of up to 240x240 pixels.
Say Y if you have such a display that utilizes this controller.
Makefile:
Kconfig:
再到menuconfig使能此驱动,
make menuconfig ARCH=arm CROSS_COMPILE=arm-linux- -j80
Device Drivers --->
[*] Staging drivers --->
<*> Support for small TFT LCD display modules --->
<*> FB driver for the ST7789VW LCD Controller
编译内核 设备树 下载重启看效果
make zImage dtbs ARCH=arm CROSS_COMPILE=arm-linux- -j80
网络更新内核
scp arch/arm/boot/zImage root@192.168.137.83:/boot
网络更新设备树
scp arch/arm/boot/dts/sun8i-h3-nanopi-neo-air.dtb root@192.168.137.83:/boot
实际效果
1.3寸 240*240 IPS效果:
播放视频
mplayer badapple_320_240_15fps.avi -vo fbdev
运行QT
apt-get update && apt-get install git
git clone https://github.com/friendlyarm/matrix.git
cd matrix/demo/nanopi-status
./build.sh
./run.sh /dev/fb_st7789vw