LCD模组驱动开发

2024-08-24 20:36
文章标签 开发 驱动 lcd 模组

本文主要是介绍LCD模组驱动开发,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Linux 5.15 内核适配

驱动勾选

由于使用的是 SPI0,所以 TinyVision 的 LCD 模块并不支持使用MIPI-DBI进行驱动,这里我们使用普通的SPI模拟时序。

勾选 SPI 驱动

这里我们使用 SPI-NG 驱动,勾选 <*> SPI NG Driver Support for Allwinner SoCs

在这里插入图片描述

勾选 Linux FrameBuffer 驱动

前往如下地址,勾选驱动

Device Drivers  --->Graphics support  --->Frame buffer Devices  ---><*> Support for frame buffer devicesConsole display driver support  --->[*] Framebuffer Console support[*]   Map the console to the primary display device[*] Staging drivers  ---><*>   Support for small TFT LCD display modules  ---><*>   FB driver for the ST7789V LCD Controller

适配 FBTFT 的设备树接口

进入内核文件夹,找到 kernel/linux-5.15/drivers/staging/fbtft/fbtft-core.c

添加头文件

#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;
}

编写配套屏幕 ST7789v 驱动

进入内核文件夹,找到 kernel/linux-5.15/drivers/staging/fbtft/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/gpio/consumer.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/interrupt.h>
#include <linux/completion.h>
#include <linux/module.h>#include <video/mipi_display.h>#include "fbtft.h"#define DRVNAME "fb_st7789v"#define DEFAULT_GAMMA \"70 2C 2E 15 10 09 48 33 53 0B 19 18 20 25\n" \"70 2C 2E 15 10 09 48 33 53 0B 19 18 20 25"#define HSD20_IPS_GAMMA \"D0 05 0A 09 08 05 2E 44 45 0F 17 16 2B 33\n" \"D0 05 0A 09 08 05 2E 43 45 0F 16 16 2B 33"#define HSD20_IPS 1/*** enum st7789v_command - ST7789V display controller commands** @PORCTRL: porch setting* @GCTRL: gate control* @VCOMS: VCOM setting* @VDVVRHEN: VDV and VRH command enable* @VRHS: VRH set* @VDVS: VDV set* @VCMOFSET: VCOM offset set* @PWCTRL1: power control 1* @PVGAMCTRL: positive voltage gamma control* @NVGAMCTRL: negative voltage gamma control** The command names are the same as those found in the datasheet to ease* looking up their semantics and usage.** Note that the ST7789V display controller offers quite a few more commands* which have been omitted from this list as they are not used at the moment.* Furthermore, commands that are compliant with the MIPI DCS have been left* out as well to avoid duplicate entries.*/
enum st7789v_command {PORCTRL = 0xB2,GCTRL = 0xB7,VCOMS = 0xBB,VDVVRHEN = 0xC2,VRHS = 0xC3,VDVS = 0xC4,VCMOFSET = 0xC5,PWCTRL1 = 0xD0,PVGAMCTRL = 0xE0,NVGAMCTRL = 0xE1,
};#define MADCTL_BGR BIT(3) /* bitmask for RGB/BGR order */
#define MADCTL_MV BIT(5) /* bitmask for page/column order */
#define MADCTL_MX BIT(6) /* bitmask for column address order */
#define MADCTL_MY BIT(7) /* bitmask for page address order *//* 60Hz for 16.6ms, configured as 2*16.6ms */
#define PANEL_TE_TIMEOUT_MS  33static struct completion panel_te; /* completion for panel TE line */
static int irq_te; /* Linux IRQ for LCD TE line */static irqreturn_t panel_te_handler(int irq, void *data)
{complete(&panel_te);return IRQ_HANDLED;
}/*** init_display() - initialize the display controller** @par: FBTFT parameter object** Most of the commands in this init function set their parameters to the* same default values which are already in place after the display has been* powered up. (The main exception to this rule is the pixel format which* would default to 18 instead of 16 bit per pixel.)* Nonetheless, this sequence can be used as a template for concrete* displays which usually need some adjustments.** Return: 0 on success, < 0 if error occurred.*/
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,0x1F,0x1F,0x00,0x33,0x33);write_reg(par,0xB7,0x35);write_reg(par,0xBB,0x20);write_reg(par,0xC0,0x2C);write_reg(par,0xC2,0x01);write_reg(par,0xC3,0x01);write_reg(par,0xC4,0x18);write_reg(par,0xC6,0x13);write_reg(par,0xD0,0xA4,0xA1);write_reg(par,0xE0,0xF0,0x04,0x07,0x04,0x04,0x04,0x25,0x33,0x3C,0x36,0x14,0x12,0x29,0x30);write_reg(par,0xE1,0xF0,0x02,0x04,0x05,0x05,0x21,0x25,0x32,0x3B,0x38,0x12,0x14,0x27,0x31);write_reg(par,0xE4,0x1D,0x00,0x00);write_reg(par,0x21);write_reg(par,0x11);mdelay(50);write_reg(par,0x29);mdelay(200);return 0;
}/** write_vmem() - write data to display.* @par: FBTFT parameter object.* @offset: offset from screen_buffer.* @len: the length of data to be writte.** Return: 0 on success, or a negative error code otherwise.*/
static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
{struct device *dev = par->info->device;int ret;if (irq_te) {enable_irq(irq_te);reinit_completion(&panel_te);ret = wait_for_completion_timeout(&panel_te,msecs_to_jiffies(PANEL_TE_TIMEOUT_MS));if (ret == 0)dev_err(dev, "wait panel TE timeout\n");disable_irq(irq_te);}switch (par->pdata->display.buswidth) {case 8:ret = fbtft_write_vmem16_bus8(par, offset, len);break;case 9:ret = fbtft_write_vmem16_bus9(par, offset, len);break;case 16:ret = fbtft_write_vmem16_bus16(par, offset, len);break;default:dev_err(dev, "Unsupported buswidth %d\n",par->pdata->display.buswidth);ret = 0;break;}return ret;
}/*** set_var() - apply LCD properties like rotation and BGR mode** @par: FBTFT parameter object** Return: 0 on success, < 0 if error occurred.*/
static int set_var(struct fbtft_par *par)
{u8 madctl_par = 0;if (par->bgr)madctl_par |= MADCTL_BGR;switch (par->info->var.rotate) {case 0:break;case 90:madctl_par |= (MADCTL_MV | MADCTL_MY);break;case 180:madctl_par |= (MADCTL_MX | MADCTL_MY);break;case 270:madctl_par |= (MADCTL_MV | MADCTL_MX);break;default:return -EINVAL;}write_reg(par, MIPI_DCS_SET_ADDRESS_MODE, madctl_par);return 0;
}/*** set_gamma() - set gamma curves** @par: FBTFT parameter object* @curves: gamma curves** Before the gamma curves are applied, they are preprocessed with a bitmask* to ensure syntactically correct input for the display controller.* This implies that the curves input parameter might be changed by this* function and that illegal gamma values are auto-corrected and not* reported as errors.** Return: 0 on success, < 0 if error occurred.*/
static int set_gamma(struct fbtft_par *par, u32 *curves)
{int i;int j;int c; /* curve index offset *//** Bitmasks for gamma curve command parameters.* The masks are the same for both positive and negative voltage* gamma curves.*/static const u8 gamma_par_mask[] = {0xFF, /* V63[3:0], V0[3:0]*/0x3F, /* V1[5:0] */0x3F, /* V2[5:0] */0x1F, /* V4[4:0] */0x1F, /* V6[4:0] */0x3F, /* J0[1:0], V13[3:0] */0x7F, /* V20[6:0] */0x77, /* V36[2:0], V27[2:0] */0x7F, /* V43[6:0] */0x3F, /* J1[1:0], V50[3:0] */0x1F, /* V57[4:0] */0x1F, /* V59[4:0] */0x3F, /* V61[5:0] */0x3F, /* V62[5:0] */};for (i = 0; i < par->gamma.num_curves; i++) {c = i * par->gamma.num_values;for (j = 0; j < par->gamma.num_values; j++)curves[c + j] &= gamma_par_mask[j];write_reg(par, PVGAMCTRL + i,curves[c + 0],  curves[c + 1],  curves[c + 2],curves[c + 3],  curves[c + 4],  curves[c + 5],curves[c + 6],  curves[c + 7],  curves[c + 8],curves[c + 9],  curves[c + 10], curves[c + 11],curves[c + 12], curves[c + 13]);}return 0;
}/*** blank() - blank the display** @par: FBTFT parameter object* @on: whether to enable or disable blanking the display** Return: 0 on success, < 0 if error occurred.*/
static int blank(struct fbtft_par *par, bool on)
{if (on)write_reg(par, MIPI_DCS_SET_DISPLAY_OFF);elsewrite_reg(par, MIPI_DCS_SET_DISPLAY_ON);return 0;
}static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
{switch(par->info->var.rotate){case   0: break;case  90: xs+=80;xe+=80;break;case 180:break;case 270: xs+=80;xe+=80;break;default :break;}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 void reset(struct fbtft_par *par)
{if (!par->gpio.reset)return;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);gpiod_set_value_cansleep(par->gpio.cs, 1);  /* Activate chip */
}static struct fbtft_display display = {.regwidth = 8,.width = 240,.height = 240,.gamma_num = 2,.gamma_len = 14,.gamma = HSD20_IPS_GAMMA,.fbtftops = {.init_display = init_display,.set_addr_win = set_addr_win,.write_vmem = write_vmem,.set_var = set_var,.set_gamma = set_gamma,.blank = blank,.reset = reset,},
};FBTFT_REGISTER_DRIVER(DRVNAME, "sitronix,st7789v", &display);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");

编写设备树

&pio {spi0_pins_default: spi0@0 {pins = "PC0", "PC2", "PC3"; /* clk, mosi, miso */function = "spi0";drive-strength = <10>;};spi0_pins_cs: spi0@1 {pins = "PC1", "PC4", "PC5"; /* cs, wp, hold */function = "spi0";drive-strength = <10>;bias-pull-up;};spi0_pins_lcd: spi0@2 {pins = "PC0", "PC2"; /* clk, mosi */function = "spi0";drive-strength = <10>;};spi0_pins_lcd_cs: spi0@3 {pins = "PC1"; /* cs */function = "spi0";drive-strength = <10>;};spi0_pins_sleep: spi0@4 {pins = "PC0", "PC2", "PC3", "PC1", "PC4", "PC5";function = "gpio_in";drive-strength = <10>;};
};&spi0 {pinctrl-0 = <&spi0_pins_lcd &spi0_pins_lcd_cs>;pinctrl-1 = <&spi0_pins_sleep>;pinctrl-names = "default", "sleep";sunxi,spi-bus-mode = <SUNXI_SPI_BUS_MASTER>;sunxi,spi-cs-mode = <SUNXI_SPI_CS_AUTO>;status = "okay";st7789v@0 {status = "okay";compatible = "sitronix,st7789v";reg = <0>;spi-max-frequency = <30000000>;rotate = <0>;bgr;fps = <30>;buswidth = <8>;reset = <&pio PC 5 GPIO_ACTIVE_LOW>;dc = <&pio PC 4 GPIO_ACTIVE_LOW>;debug = <1>;};
};

Linux 4.9 内核适配

驱动勾选

由于使用的是 SPI0,所以 TinyVision 的 LCD 模块并不支持使用MIPI-DBI进行驱动,这里我们使用普通的SPI模拟时序。

勾选 SPI 驱动

这里我们使用 SPI-NG 驱动,勾选 Device Drivers ---> [*] SPI support ---><*> SUNXI SPI Controller

在这里插入图片描述

勾选 Linux FrameBuffer 驱动

前往如下地址,勾选驱动

Device Drivers  --->Graphics support  --->Frame buffer Devices  ---><*> Support for frame buffer devicesConsole display driver support  --->[*] Framebuffer Console support[*]   Map the console to the primary display device[*] Staging drivers  ---><*>   Support for small TFT LCD display modules  ---><*>   FB driver for the ST7789V LCD Controller

适配 FBTFT 的设备树接口

进入内核文件夹,找到 lichee/linux-4.9/drivers/staging/fbtft/fbtft-core.c

添加头文件

#include <linux/sunxi-gpio.h>

修改驱动注册接口

static int fbtft_request_one_gpio(struct fbtft_par *par,const char *name, int index, int *gpiop)
{struct device *dev = par->info->device;struct device_node *node = dev->of_node;int gpio, flags, ret = 0;struct gpio_config gpio_of_flags;if (of_find_property(node, name, NULL)) {gpio = of_get_named_gpio_flags(node, name, index, (enum of_gpio_flags *)&gpio_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;}/* active low translates to initially low */flags = (gpio_of_flags.data & 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;}if (gpiop)*gpiop = gpio;fbtft_par_dbg(DEBUG_REQUEST_GPIOS, par, "%s: '%s' = GPIO%d\n",__func__, name, gpio);}return ret;
}static int fbtft_request_gpios_dt(struct fbtft_par *par)
{int i;int ret;if (!par->info->device->of_node)return -EINVAL;ret = fbtft_request_one_gpio(par, "reset", 0, &par->gpio.reset);if (ret)return ret;ret = fbtft_request_one_gpio(par, "dc", 0, &par->gpio.dc);if (ret)return ret;ret = fbtft_request_one_gpio(par, "rd", 0, &par->gpio.rd);if (ret)return ret;ret = fbtft_request_one_gpio(par, "wr", 0, &par->gpio.wr);if (ret)return ret;ret = fbtft_request_one_gpio(par, "cs", 0, &par->gpio.cs);if (ret)return ret;ret = fbtft_request_one_gpio(par, "latch", 0, &par->gpio.latch);if (ret)return ret;for (i = 0; i < 16; i++) {ret = fbtft_request_one_gpio(par, "db", i,&par->gpio.db[i]);if (ret)return ret;ret = fbtft_request_one_gpio(par, "led", i,&par->gpio.led[i]);if (ret)return ret;ret = fbtft_request_one_gpio(par, "aux", i,&par->gpio.aux[i]);if (ret)return ret;}return 0;
}

编写配套屏幕 ST7789v 驱动

/** FB driver for the ST7789V LCD Controller** Copyright (C) 2015 Dennis Menschel** This program is free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License as published by* the Free Software Foundation; either version 2 of the License, or* (at your option) any later version.** This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the* GNU General Public License for more details.*/#include <linux/bitops.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/gpio.h>
#include <video/mipi_display.h>#include "fbtft.h"#define DRVNAME "fb_st7789v"#define DEFAULT_GAMMA \"70 2C 2E 15 10 09 48 33 53 0B 19 18 20 25\n" \"70 2C 2E 15 10 09 48 33 53 0B 19 18 20 25"#define HSD20_IPS_GAMMA \"D0 05 0A 09 08 05 2E 44 45 0F 17 16 2B 33\n" \"D0 05 0A 09 08 05 2E 43 45 0F 16 16 2B 33"/*** enum st7789v_command - ST7789V display controller commands** @PORCTRL: porch setting* @GCTRL: gate control* @VCOMS: VCOM setting* @VDVVRHEN: VDV and VRH command enable* @VRHS: VRH set* @VDVS: VDV set* @VCMOFSET: VCOM offset set* @PWCTRL1: power control 1* @PVGAMCTRL: positive voltage gamma control* @NVGAMCTRL: negative voltage gamma control** The command names are the same as those found in the datasheet to ease* looking up their semantics and usage.** Note that the ST7789V display controller offers quite a few more commands* which have been omitted from this list as they are not used at the moment.* Furthermore, commands that are compliant with the MIPI DCS have been left* out as well to avoid duplicate entries.*/
enum st7789v_command {PORCTRL = 0xB2,GCTRL = 0xB7,VCOMS = 0xBB,VDVVRHEN = 0xC2,VRHS = 0xC3,VDVS = 0xC4,VCMOFSET = 0xC5,PWCTRL1 = 0xD0,PVGAMCTRL = 0xE0,NVGAMCTRL = 0xE1,
};#define MADCTL_BGR BIT(3) /* bitmask for RGB/BGR order */
#define MADCTL_MV BIT(5) /* bitmask for page/column order */
#define MADCTL_MX BIT(6) /* bitmask for column address order */
#define MADCTL_MY BIT(7) /* bitmask for page address order *//*** init_display() - initialize the display controller** @par: FBTFT parameter object** Most of the commands in this init function set their parameters to the* same default values which are already in place after the display has been* powered up. (The main exception to this rule is the pixel format which* would default to 18 instead of 16 bit per pixel.)* Nonetheless, this sequence can be used as a template for concrete* displays which usually need some adjustments.** Return: 0 on success, < 0 if error occurred.*/
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,0x1F,0x1F,0x00,0x33,0x33);write_reg(par,0xB7,0x35);write_reg(par,0xBB,0x20);write_reg(par,0xC0,0x2C);write_reg(par,0xC2,0x01);write_reg(par,0xC3,0x01);write_reg(par,0xC4,0x18);write_reg(par,0xC6,0x13);write_reg(par,0xD0,0xA4,0xA1);write_reg(par,0xE0,0xF0,0x04,0x07,0x04,0x04,0x04,0x25,0x33,0x3C,0x36,0x14,0x12,0x29,0x30);write_reg(par,0xE1,0xF0,0x02,0x04,0x05,0x05,0x21,0x25,0x32,0x3B,0x38,0x12,0x14,0x27,0x31);write_reg(par,0xE4,0x1D,0x00,0x00);write_reg(par,0x21);write_reg(par,0x11);mdelay(50);write_reg(par,0x29);mdelay(200);return 0;return 0;
}/*** set_var() - apply LCD properties like rotation and BGR mode** @par: FBTFT parameter object** Return: 0 on success, < 0 if error occurred.*/
static int set_var(struct fbtft_par *par)
{u8 madctl_par = 0;if (par->bgr)madctl_par |= MADCTL_BGR;switch (par->info->var.rotate) {case 0:break;case 90:madctl_par |= (MADCTL_MV | MADCTL_MY);break;case 180:madctl_par |= (MADCTL_MX | MADCTL_MY);break;case 270:madctl_par |= (MADCTL_MV | MADCTL_MX);break;default:return -EINVAL;}write_reg(par, MIPI_DCS_SET_ADDRESS_MODE, madctl_par);return 0;
}/*** set_gamma() - set gamma curves** @par: FBTFT parameter object* @curves: gamma curves** Before the gamma curves are applied, they are preprocessed with a bitmask* to ensure syntactically correct input for the display controller.* This implies that the curves input parameter might be changed by this* function and that illegal gamma values are auto-corrected and not* reported as errors.** Return: 0 on success, < 0 if error occurred.*/
static int set_gamma(struct fbtft_par *par, unsigned long *curves)
{int i;int j;int c; /* curve index offset *//** Bitmasks for gamma curve command parameters.* The masks are the same for both positive and negative voltage* gamma curves.*/const u8 gamma_par_mask[] = {0xFF, /* V63[3:0], V0[3:0]*/0x3F, /* V1[5:0] */0x3F, /* V2[5:0] */0x1F, /* V4[4:0] */0x1F, /* V6[4:0] */0x3F, /* J0[1:0], V13[3:0] */0x7F, /* V20[6:0] */0x77, /* V36[2:0], V27[2:0] */0x7F, /* V43[6:0] */0x3F, /* J1[1:0], V50[3:0] */0x1F, /* V57[4:0] */0x1F, /* V59[4:0] */0x3F, /* V61[5:0] */0x3F, /* V62[5:0] */};for (i = 0; i < par->gamma.num_curves; i++) {c = i * par->gamma.num_values;for (j = 0; j < par->gamma.num_values; j++)curves[c + j] &= gamma_par_mask[j];write_reg(par, PVGAMCTRL + i,curves[c + 0], curves[c + 1], curves[c + 2],curves[c + 3], curves[c + 4], curves[c + 5],curves[c + 6], curves[c + 7], curves[c + 8],curves[c + 9], curves[c + 10], curves[c + 11],curves[c + 12], curves[c + 13]);}return 0;
}/*** blank() - blank the display** @par: FBTFT parameter object* @on: whether to enable or disable blanking the display** Return: 0 on success, < 0 if error occurred.*/
static int blank(struct fbtft_par *par, bool on)
{if (on)write_reg(par, MIPI_DCS_SET_DISPLAY_OFF);elsewrite_reg(par, MIPI_DCS_SET_DISPLAY_ON);return 0;
}static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
{switch(par->info->var.rotate){case   0: break;case  90: xs+=80;xe+=80;break;case 180:break;case 270: xs+=80;xe+=80;break;default :break;}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 void reset(struct fbtft_par *par)
{if (par->gpio.reset == -1)return;fbtft_par_dbg(DEBUG_RESET, par, "%s()\n", __func__);gpio_set_value(par->gpio.reset, 1);mdelay(20);gpio_set_value(par->gpio.reset, 0);mdelay(20);gpio_set_value(par->gpio.reset, 1);mdelay(120);
}static struct fbtft_display display = {.regwidth = 8,.width = 240,.height = 240,.gamma_num = 2,.gamma_len = 14,.gamma = HSD20_IPS_GAMMA,.fbtftops = {.init_display = init_display,.set_addr_win = set_addr_win,.set_var = set_var,.set_gamma = set_gamma,.blank = blank,.reset = reset,},
};FBTFT_REGISTER_DRIVER(DRVNAME, "sitronix,st7789v", &display);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");

编写设备树

&pio {spi0_pins_a: spi0@0 {allwinner,pins = "PC0", "PC2", "PC3";allwinner,pname = "spi0_sclk", "spi0_mosi", "spi0_miso";allwinner,function = "spi0";allwinner,muxsel = <4>;allwinner,drive = <1>;allwinner,pull = <0>;};spi0_pins_b: spi0@1 {allwinner,pins = "PC1", "PC5", "PC4";allwinner,pname = "spi0_cs0", "spi0_hold", "spi0_wp";allwinner,function = "spi0";allwinner,muxsel = <4>;allwinner,drive = <1>;allwinner,pull = <1>;   // only CS should be pulled up};spi0_pins_c: spi0@2 {allwinner,pins = "PC0", "PC1", "PC2", "PC3", "PC4", "PC5";allwinner,function = "io_disabled";allwinner,muxsel = <7>;allwinner,drive = <1>;allwinner,pull = <0>;};spi0_pins_lcd: spi0@3 {allwinner,pins = "PC0", "PC2"; /* clk, mosi */allwinner,function = "spi0";allwinner,muxsel = <4>;allwinner,drive = <1>;allwinner,pull = <0>;};spi0_pins_lcd_cs: spi0@4 {allwinner,pins = "PC1"; /* cs */allwinner,function = "spi0";allwinner,muxsel = <4>;allwinner,pull = <1>;allwinner,drive = <1>;};
};&spi0 {clock-frequency = <100000000>;pinctrl-0 = <&spi0_pins_lcd &spi0_pins_lcd_cs>;pinctrl-1 = <&spi0_pins_c>;pinctrl-names = "default", "sleep";spi_slave_mode = <0>;spi_dbi_enable = <0>;spi0_cs_number = <1>;status = "okay";st7789v@0 {status = "okay";compatible = "sitronix,st7789v";reg = <0>;spi-max-frequency = <30000000>;rotate = <0>;bgr;fps = <30>;buswidth = <8>;reset = <&pio PC 5 1 1 2 1>;dc = <&pio PC 4 1 1 2 0>;debug = <1>;};
};

显示 Linux 终端

前往驱动勾选如下选项

Device Drivers  --->Graphics support  --->Frame buffer Devices  ---><*> Support for frame buffer devicesConsole display driver support  --->[*] Framebuffer Console support[*]   Map the console to the primary display device

在这里插入图片描述

然后在 bootargs 添加一行 console=tty0 即可显示。

这篇关于LCD模组驱动开发的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1103532

相关文章

Spring Boot + MyBatis Plus 高效开发实战从入门到进阶优化(推荐)

《SpringBoot+MyBatisPlus高效开发实战从入门到进阶优化(推荐)》本文将详细介绍SpringBoot+MyBatisPlus的完整开发流程,并深入剖析分页查询、批量操作、动... 目录Spring Boot + MyBATis Plus 高效开发实战:从入门到进阶优化1. MyBatis

Python基于wxPython和FFmpeg开发一个视频标签工具

《Python基于wxPython和FFmpeg开发一个视频标签工具》在当今数字媒体时代,视频内容的管理和标记变得越来越重要,无论是研究人员需要对实验视频进行时间点标记,还是个人用户希望对家庭视频进行... 目录引言1. 应用概述2. 技术栈分析2.1 核心库和模块2.2 wxpython作为GUI选择的优

利用Python开发Markdown表格结构转换为Excel工具

《利用Python开发Markdown表格结构转换为Excel工具》在数据管理和文档编写过程中,我们经常使用Markdown来记录表格数据,但它没有Excel使用方便,所以本文将使用Python编写一... 目录1.完整代码2. 项目概述3. 代码解析3.1 依赖库3.2 GUI 设计3.3 解析 Mark

利用Go语言开发文件操作工具轻松处理所有文件

《利用Go语言开发文件操作工具轻松处理所有文件》在后端开发中,文件操作是一个非常常见但又容易出错的场景,本文小编要向大家介绍一个强大的Go语言文件操作工具库,它能帮你轻松处理各种文件操作场景... 目录为什么需要这个工具?核心功能详解1. 文件/目录存javascript在性检查2. 批量创建目录3. 文件

基于Python开发批量提取Excel图片的小工具

《基于Python开发批量提取Excel图片的小工具》这篇文章主要为大家详细介绍了如何使用Python中的openpyxl库开发一个小工具,可以实现批量提取Excel图片,有需要的小伙伴可以参考一下... 目前有一个需求,就是批量读取当前目录下所有文件夹里的Excel文件,去获取出Excel文件中的图片,并

基于Python开发PDF转PNG的可视化工具

《基于Python开发PDF转PNG的可视化工具》在数字文档处理领域,PDF到图像格式的转换是常见需求,本文介绍如何利用Python的PyMuPDF库和Tkinter框架开发一个带图形界面的PDF转P... 目录一、引言二、功能特性三、技术架构1. 技术栈组成2. 系统架构javascript设计3.效果图

基于Python开发PDF转Doc格式小程序

《基于Python开发PDF转Doc格式小程序》这篇文章主要为大家详细介绍了如何基于Python开发PDF转Doc格式小程序,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 用python实现PDF转Doc格式小程序以下是一个使用Python实现PDF转DOC格式的GUI程序,采用T

使用Python开发一个图像标注与OCR识别工具

《使用Python开发一个图像标注与OCR识别工具》:本文主要介绍一个使用Python开发的工具,允许用户在图像上进行矩形标注,使用OCR对标注区域进行文本识别,并将结果保存为Excel文件,感兴... 目录项目简介1. 图像加载与显示2. 矩形标注3. OCR识别4. 标注的保存与加载5. 裁剪与重置图像

Android开发中gradle下载缓慢的问题级解决方法

《Android开发中gradle下载缓慢的问题级解决方法》本文介绍了解决Android开发中Gradle下载缓慢问题的几种方法,本文给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录一、网络环境优化二、Gradle版本与配置优化三、其他优化措施针对android开发中Gradle下载缓慢的问

使用Go语言开发一个命令行文件管理工具

《使用Go语言开发一个命令行文件管理工具》这篇文章主要为大家详细介绍了如何使用Go语言开发一款命令行文件管理工具,支持批量重命名,删除,创建,移动文件,需要的小伙伴可以了解下... 目录一、工具功能一览二、核心代码解析1. 主程序结构2. 批量重命名3. 批量删除4. 创建文件/目录5. 批量移动三、如何安