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

相关文章

这15个Vue指令,让你的项目开发爽到爆

1. V-Hotkey 仓库地址: github.com/Dafrok/v-ho… Demo: 戳这里 https://dafrok.github.io/v-hotkey 安装: npm install --save v-hotkey 这个指令可以给组件绑定一个或多个快捷键。你想要通过按下 Escape 键后隐藏某个组件,按住 Control 和回车键再显示它吗?小菜一碟: <template

Hadoop企业开发案例调优场景

需求 (1)需求:从1G数据中,统计每个单词出现次数。服务器3台,每台配置4G内存,4核CPU,4线程。 (2)需求分析: 1G / 128m = 8个MapTask;1个ReduceTask;1个mrAppMaster 平均每个节点运行10个 / 3台 ≈ 3个任务(4    3    3) HDFS参数调优 (1)修改:hadoop-env.sh export HDFS_NAMENOD

嵌入式QT开发:构建高效智能的嵌入式系统

摘要: 本文深入探讨了嵌入式 QT 相关的各个方面。从 QT 框架的基础架构和核心概念出发,详细阐述了其在嵌入式环境中的优势与特点。文中分析了嵌入式 QT 的开发环境搭建过程,包括交叉编译工具链的配置等关键步骤。进一步探讨了嵌入式 QT 的界面设计与开发,涵盖了从基本控件的使用到复杂界面布局的构建。同时也深入研究了信号与槽机制在嵌入式系统中的应用,以及嵌入式 QT 与硬件设备的交互,包括输入输出设

OpenHarmony鸿蒙开发( Beta5.0)无感配网详解

1、简介 无感配网是指在设备联网过程中无需输入热点相关账号信息,即可快速实现设备配网,是一种兼顾高效性、可靠性和安全性的配网方式。 2、配网原理 2.1 通信原理 手机和智能设备之间的信息传递,利用特有的NAN协议实现。利用手机和智能设备之间的WiFi 感知订阅、发布能力,实现了数字管家应用和设备之间的发现。在完成设备间的认证和响应后,即可发送相关配网数据。同时还支持与常规Sof

活用c4d官方开发文档查询代码

当你问AI助手比如豆包,如何用python禁止掉xpresso标签时候,它会提示到 这时候要用到两个东西。https://developers.maxon.net/论坛搜索和开发文档 比如这里我就在官方找到正确的id描述 然后我就把参数标签换过来

Linux_kernel驱动开发11

一、改回nfs方式挂载根文件系统         在产品将要上线之前,需要制作不同类型格式的根文件系统         在产品研发阶段,我们还是需要使用nfs的方式挂载根文件系统         优点:可以直接在上位机中修改文件系统内容,延长EMMC的寿命         【1】重启上位机nfs服务         sudo service nfs-kernel-server resta

【区块链 + 人才服务】区块链集成开发平台 | FISCO BCOS应用案例

随着区块链技术的快速发展,越来越多的企业开始将其应用于实际业务中。然而,区块链技术的专业性使得其集成开发成为一项挑战。针对此,广东中创智慧科技有限公司基于国产开源联盟链 FISCO BCOS 推出了区块链集成开发平台。该平台基于区块链技术,提供一套全面的区块链开发工具和开发环境,支持开发者快速开发和部署区块链应用。此外,该平台还可以提供一套全面的区块链开发教程和文档,帮助开发者快速上手区块链开发。

Vue3项目开发——新闻发布管理系统(六)

文章目录 八、首页设计开发1、页面设计2、登录访问拦截实现3、用户基本信息显示①封装用户基本信息获取接口②用户基本信息存储③用户基本信息调用④用户基本信息动态渲染 4、退出功能实现①注册点击事件②添加退出功能③数据清理 5、代码下载 八、首页设计开发 登录成功后,系统就进入了首页。接下来,也就进行首页的开发了。 1、页面设计 系统页面主要分为三部分,左侧为系统的菜单栏,右侧

v0.dev快速开发

探索v0.dev:次世代开发者之利器 今之技艺日新月异,开发者之工具亦随之进步不辍。v0.dev者,新兴之开发者利器也,迅速引起众多开发者之瞩目。本文将引汝探究v0.dev之基本功能与优势,助汝速速上手,提升开发之效率。 何谓v0.dev? v0.dev者,现代化之开发者工具也,旨在简化并加速软件开发之过程。其集多种功能于一体,助开发者高效编写、测试及部署代码。无论汝为前端开发者、后端开发者

pico2 开发环境搭建-基于ubuntu

pico2 开发环境搭建-基于ubuntu 安装编译工具链下载sdk 和example编译example 安装编译工具链 sudo apt install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib 注意cmake的版本,需要在3.17 以上 下载sdk 和ex