FBTFT st7789v
发表于:2022-05-27 | 分类: Linux

初始化spi屏幕

V3s

主线Linux5.14

st7789V 240*240

1.修改fbtft-core.c申请GPIO函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//添加头文件
#include <linux/gpio.h>
#include <linux/of_gpio.h>
//.......
//找到fbtft_request_one_gpio()函数,替换
static int fbtft_request_one_gpio(struct fbtft_par *par,
const char *name, int index,
struct gpio_desc **gpiop)
{
struct device *dev = par->info->device;
struct device_node *node = dev->of_node;
int gpio, flags, ret = 0;
enum of_gpio_flags of_flags;

if (of_find_property(node, name, NULL)) {
gpio = of_get_named_gpio_flags(node, name, index, &of_flags);
if (gpio == -ENOENT)
return 0;
if (gpio == -EPROBE_DEFER)
return gpio;
if (gpio < 0) {
dev_err(dev,
"failed to get '%s' from DT\n", name);
return gpio;
}
flags = (of_flags & OF_GPIO_ACTIVE_LOW) ? GPIOF_OUT_INIT_LOW :
GPIOF_OUT_INIT_HIGH;
ret = devm_gpio_request_one(dev, gpio, flags,
dev->driver->name);
if (ret) {
dev_err(dev,
"gpio_request_one('%s'=%d) failed with %d\n",
name, gpio, ret);
return ret;
}

*gpiop = gpio_to_desc(gpio);
fbtft_par_dbg(DEBUG_REQUEST_GPIOS, par, "%s: '%s' = GPIO%d\n",
__func__, name, gpio);
}

return ret;
}

2.修改RESET函数

1
2
3
4
5
6
7
8
9
10
11
12
static void fbtft_reset(struct fbtft_par *par)
{
if (!par->gpio.reset)
return;
fbtft_par_dbg(DEBUG_RESET, par, "%s()\n", __func__);
gpiod_set_value_cansleep(par->gpio.reset, 1);
msleep(10);
gpiod_set_value_cansleep(par->gpio.reset, 0);
msleep(200);
gpiod_set_value_cansleep(par->gpio.reset, 1);
msleep(10);
}

3.修改st7789v初始化函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
static int init_display(struct fbtft_par *par)
{
par->fbtftops.reset(par);
mdelay(50);
write_reg(par,0x36,0x00);
write_reg(par,0x3A,0x05);
write_reg(par,0xB2,0x0C,0x0C,0x00,0x33,0x33);
write_reg(par,0xB7,0x35);
write_reg(par,0xBB,0x19);
write_reg(par,0xC0,0x2C);
write_reg(par,0xC2,0x01);
write_reg(par,0xC3,0x12);
write_reg(par,0xC4,0x20);
write_reg(par,0xC6,0x0F);
write_reg(par,0xD0,0xA4,0xA1);
write_reg(par,0xE0,0xD0,0x04,0x0D,0x11,0x13,0x2B,0x3F,0x54,0x4C,0x18,0x0D,0x0B,0x1F,0x23);
write_reg(par,0xE1,0xD0,0x04,0x0C,0x11,0x13,0x2C,0x3F,0x44,0x51,0x2F,0x1F,0x1F,0x20,0x23);
write_reg(par,0x21);
write_reg(par,0x11);
mdelay(50);
write_reg(par,0x29);
mdelay(200);
return 0;
}

4.添加设备树

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
&spi0 {
clock-frequency = <100000000>;
pinctrl-0 = <&spi0_pins_a &spi0_pins_b>;
status = "okay";

st7789v@0 {
status = "okay";
compatible = "sitronix,st7789v";
reg = <0>;
spi-max-frequency = <32000000>;
rotate = <90>;
rgb;
fps = <30>;
buswidth = <8>;
reset = <&pio PC 6 GPIO_ACTIVE_LOW>;
dc = <&pio PC 5 GPIO_ACTIVE_LOW>;
led = <&pio PD 18 GPIO_ACTIVE_HIGH>;
debug = <1>;
};
};

5.配置内核

1
2
3
4
Device Drivers  --->
[*] Staging drivers --->
<*> Support for small TFT LCD display modules --->
<*> FB driver for the ST7789V LCD Controller

6.编译

1
make -j8

不出意外的话,会输出

1
2
3
4
5
6
7
[    1.041255] fbtft_of_value: width = 240
[ 1.045110] fbtft_of_value: height = 240
[ 1.049035] fbtft_of_value: buswidth = 8
[ 1.053007] fbtft_of_value: debug = 0
[ 1.056675] fbtft_of_value: rotate = 0
[ 1.060425] fbtft_of_value: fps = 33
[ 1.601827] graphics fb0: fb_st7789v frame buffer, 240x240, 112 KiB video memory, 4 KiB buffer memory, fps=33, spi0.0 at 96 MHz

7.测试

1
# cat /dev/urandom > /dev/fb0 //雪花屏

设置 TFT-LCD作为终端控制台

1.设置 uboot中的 bootargs

1
setenv bootargs 'console=tty0 ......'
1
saveenv

2.修改/etc/inittab文件

1
2
3
console::respawn:/sbin/qetty -L console 0 vt100
#添加下面一句
tty0::askfirst:-/bin/sh

3.重启

1
reboot

1

上一篇:
Tina修改串口
下一篇:
全志D1 主线U-Boot