本帖最后由 charlieee 于 2023-5-12 18:12 编辑
软/硬件信息:lubancat1 + ubuntu22.04.1通用镜像 + st7789v驱动的172x320 IPS LCD。 通过fbtft来驱动lcd,fbtft在内核里有,但是没编译进去。 步骤如下:
一、把spi屏幕连接上 楼主用的spi3,具体接线如图2。
二、魔改一下驱动和设备树插件 第一步、下载和解压内核源码kernel-stable-4.19-rk356x 第二步、在/kernel-stable-4.19-rk356x/drivers/staging/fbtft目录下有很多lcd控制器的驱动名字叫 fb_****.c ,找到你的屏幕对应的那一个,没有也无所谓,随便进一个,我这里是fb_st7789v.c: - // SPDX-License-Identifier: GPL-2.0+
- /*
- * FB driver for the ST7789V LCD Controller
- *
- * Copyright (C) 2015 Dennis Menschel
- */
- #include <linux/bitops.h>
- #include <linux/delay.h>
- #include <linux/init.h>
- #include <linux/kernel.h>
- #include <linux/module.h>
- #include <video/mipi_display.h>
- #include "fbtft.h"
- #define DRVNAME "fb_st7789v" //驱动名字不要管
- //参考卖屏幕的给的初始化代码
- static int init_display(struct fbtft_par *par)
- {
- par->fbtftops.reset(par); //reset
- mdelay(50);
- write_reg(par,0x11);//Sleep exit
- write_reg(par,0x36,0x70); // 屏幕显示方向设置 横屏
- write_reg(par,0x3A,0x05); //65k mode
- //-------------ST7789V Frame rate setting-----------//
- write_reg(par,0xb2,0x0C,0x0C,0x00,0x33,0x33);
- write_reg(par,0xb7,0x35);
- //--------------ST7789V Power setting---------------//
- write_reg(par,0xbb,0x35);
- write_reg(par,0xc0,0x2c);
- write_reg(par,0xc2,0x01);
- write_reg(par,0xc3,0x13);
- write_reg(par,0xc4,0x20);
- write_reg(par,0xc6,0x0F);
- write_reg(par,0xd0,0xa4,0xa1);
- write_reg(par,0xD6,0xA1);
- //write_reg(par,0xe9,0x09,0x09,0x08);
- write_reg(par,0xe0,0xF0,0x00,0x04,0x04,0x04,0x05,0x29,0x33,0x3E,0x38,0x12,0x12,0x28,0x30);
- write_reg(par,0xe1,0xF0,0x07,0x0A,0x0D,0x0B,0x07,0x28,0x33,0x3E,0x36,0x14,0x14,0x29,0x32);
- write_reg(par,0x21); //反色显示 有的ips屏幕要设置反色才能正常显示
- write_reg(par,0x11);
- mdelay(120); //Delay 120ms
- write_reg(par,0x29);
- mdelay(200);
- return 0;
- };
- //本来就有 没动过
- static int blank(struct fbtft_par *par, bool on)
- {
- if (on)
- write_reg(par, MIPI_DCS_SET_DISPLAY_OFF);
- else
- write_reg(par, MIPI_DCS_SET_DISPLAY_ON);
- return 0;
- }
- //在init里设置过了
- static int set_var(struct fbtft_par *par)
- {
- return 0;
- }
- //在init里设置过了
- static int set_gamma(struct fbtft_par *par, u32 *curves)
- {
- return 0;
- }
- //设置屏幕显示位置
- static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe,
- int ye)
- {
- //硬件的偏移,参考卖屏幕的给的代码
- ys = ys + 34;
- ye = ye + 34;
- write_reg(par, MIPI_DCS_SET_COLUMN_ADDRESS,
- (xs >> 8) & 0xFF, xs & 0xFF, (xe >> 8) & 0xFF, xe & 0xFF);
- write_reg(par, MIPI_DCS_SET_PAGE_ADDRESS,
- (ys >> 8) & 0xFF, ys & 0xFF, (ye >> 8) & 0xFF, ye & 0xFF);
- write_reg(par, MIPI_DCS_WRITE_MEMORY_START);
- }
- static struct fbtft_display display = {
- .regwidth = 8,
- .width = 320, //自己配置
- .height = 172, //自己配置
- .fbtftops = {
- .init_display = init_display,
- .set_var = set_var,
- .set_gamma = set_gamma,
- .blank = blank,
- .set_addr_win = set_addr_win
- },
- };
- FBTFT_REGISTER_DRIVER(DRVNAME, "my,spi_lcd", &display); //这里的名字要和设备树里节点里的compatible属性值一样!
- MODULE_ALIAS("spi:" DRVNAME);
- MODULE_ALIAS("platform:" DRVNAME);
- MODULE_ALIAS("spi:st7789v");
- MODULE_ALIAS("platform:st7789v");
- MODULE_DESCRIPTION("FB driver for the ST7789V LCD Controller");
- MODULE_AUTHOR("Dennis Menschel");
- MODULE_LICENSE("GPL");
复制代码
第三步、在目录kernel-stable-4.19-rk356x/arch/arm64/boot/dts/rockchip/overlay/下创建一个新的设备树源码文件:my_lcd_fbtft.dts:代码如下:
然后在同目录下的makefile里面加上my_lcd_fbtft.dtbo,如图3
三、编译内核和设备树插件 在/kernel-stable-4.19-rk356x/目录下,终端输入: make menuconfig KCONFIG_CONFIG=arch/arm64/configs/ lubancat2_defconfig ARCH=arm64 进入图形化配置界面,然后依次选择:Device Drivers ---> Staging drivers ---> Support for small TFT LCD display modules ---> 把光标移到刚刚魔改的驱动上,然后按Y,就选上了:<*> FB driver for the ST7789V LCD Controller 然后选择save、选择ok、然后一直exit 最后,/kernel-stable-4.19-rk356x/目录下,终端输入:make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- bindeb-pkg -j8 等编译完 四、安装内核和配置lubancat 编译完后,kernel-stable-4.19-rk356x/的上级目录下生成了几个文件,把名字为linux-headers***.deb和linux-image***.deb的文件拷贝到lubancat上任意目录,用sudo dpkg -i ***.deb命令把这两装上 然后把lubancat上的/boot/uEnv/uEnvLubancat1.txt改成这样: - uname_r=4.19.232
- size=0x1000000
- bootargs=console=ttyFIQ0 console=tty1
- #dtb=rk3566-lubancat1.dtb
- enable_uboot_overlays=1
- #overlay_start
- #40pin
- #dtoverlay=/dtb/overlay/rk356x-lubancat-i2c3-m0-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk356x-lubancat-i2c5-m0-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk356x-lubancat-pwm8-m0-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk356x-lubancat-pwm9-m0-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk356x-lubancat-pwm10-m0-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk356x-lubancat-pwm11-ir-m0-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk356x-lubancat-pwm12-m0-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk356x-lubancat-pwm13-m0-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk356x-lubancat-pwm13-m1-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk356x-lubancat-pwm14-m0-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk356x-lubancat-pwm14-m1-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk356x-lubancat-pwm15-ir-m0-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk356x-lubancat-pwm15-ir-m1-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk356x-lubancat-spi3-m1-gpio-cs-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk356x-lubancat-spi3-m1-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk356x-lubancat-uart3-m0-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk356x-lubancat-uart3-m1-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk356x-lubancat-uart4-m1-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk356x-lubancat-uart5-m1-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk356x-lubancat-uart7-m1-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk356x-lubancat-uart9-m1-overlay.dtbo
- #mini-pcie 5G modules
- #dtoverlay=/dtb/overlay/rk356x-lubancat-pcie2x1-disabled-overlay.dtbo
- #display
- #dtoverlay=/dtb/overlay/rk3566-lubancat-dsi0-720p-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk3566-lubancat-dsi0-1080p-overlay.dtbo
- #dtoverlay=/dtb/overlay/rk3566-lubancat-dsi0-rpi-overlay.dtbo
- #新加的:
- dtoverlay=/dtb/overlay/my_lcd_fbtft.dtbo
- #overlay_end
复制代码ps:如果/boot/dtb/overlay/下没有my_lcd_fbtft.dtbo的话,自己去编译机器的kernel-stable-4.19-rk356x/arch/arm64/boot/dts/rockchip/overlay/里拷贝一份
然后在lubancat上 sudo reboot 这时候屏幕应该有启动信息了 然后按ctrl+alt+F2就可以显示登录界面了
|