欢迎光临
我们一直在努力

OPENWRT WIDORA 驱动SPI屏,芯片ST7789V SPI屏驱动记录

手里的板子是widora 的bit5,系统是 opwnwrt,下面是驱动记录,部分参考Widora的《WIKISPI驱动液晶屏(framebuffer方式)

拿到系统源码

  1. 进入内核视频驱动目录:cd build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7688/linux-3.18.29/drivers/video/
  2. 使用git下载fbtft工程到这里:git clone https://github.com/notro/fbtft.git ,下载完后文件列表如下:
    root@huangea-ubuntu:~/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7688/linux-3.18.29/drivers/video# ls backlight console fbdev hdmi.c logo modules.builtin of_display_timing.c vgastate.c built-in.o display_timing.c fbtft Kconfig Makefile modules.order of_videomode.c videomode.c
  3. 添加如下两句,让内核知道你这里添加了驱动
    • 在video/Makefile最后添加了一行 obj-y += fbtft
    • 在video/Kconfig 中source “drivers/video/fbdev/Kconfig”行下添加一行:source “drivers/video/fbtft/Kconfig”
  4. 回到openwrt_widora根目录,运行make kernel_menuconfig,找
    • Device Drivers  --->   Character devices  ---> 
    • Graphics support —>
    • Direct Rendering Manager  --->      < > Direct Rendering Manager (XFree86 4.1.0 and higher DRI support)  ----    Frame buffer Devices  --->      <*> Support for small TFT LCD display modules  --->       <*>   FB driver for the ILI9341 LCD Controller       -*- Backlight & LCD device support  ---> 这一项无需关心
    • Console display driver support
    • Bootup logo —>
  5. 修改DTS,这里对应NEO,我们修改Widora32M.dts,路径是:target/linux/ramips/dts/Widora32M.dts 从105行,spidev@1这一段整体换成:
    • st7735r@1 {                                #address-cells = <1>;                                #size-cells = <1>;                                status = "okay";                                compatible = "sitronix,st7735r";                                reg = <1 0>;                                spi-max-frequency = <96000000>;                                txbuflen = <16>;                                rotate = <0>;                                bgr;                                fps = <48>;                                buswidth = <8>;                                dc-gpios = <&gpio1 10 0>;        default-state = "on";                        };
  6. 修改video/fb_tft/fb_st7735r.c,根据厂家提供初始化代码按下面更改
/*
 * FB driver for the ST7735R LCD Controller
 *
 * Copyright (C) 2013 Noralf Tronnes
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/delay.h>

#include "fbtft.h"

#define DRVNAME "fb_st7735r"
#define DEFAULT_GAMMA "D0 06 0B 0A 09 06 2F 44 45 18 14 14 27 2D\n" \
                      "D0 06 0B 0A 09 05 2E 43 45 18 14 14 27 2D"

static int init_display(struct fbtft_par *par)
{
	fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);

	par->fbtftops.reset(par);

	write_reg(par, 0xb9,0x00);                               
	/* SLPOUT - Sleep out & booster on */
	write_reg(par, 0x11);          
	mdelay(120);    

	write_reg(par, 0xb9, 0x00,36,0x00);
	write_reg(par, 0x3a, 0x05);
	write_reg(par, 0x21);
	write_reg(par, 0x2a, 0x00,0x00,0x00,0xef);
	write_reg(par, 0x2b, 0x00,0x00,0x00,0xcb);
	write_reg(par, 0xb2, 0x0c,0x0c,0x00,0x33,0x33);
	write_reg(par, 0xb7, 0x35);
	write_reg(par, 0xbb, 0x15);
	write_reg(par, 0xc0, 0x2c);
	write_reg(par, 0xc2, 0x01);
	write_reg(par, 0xc3, 0x12);
	write_reg(par, 0xc4, 0x20);
	write_reg(par, 0xc6, 0xe1);
	write_reg(par, 0xd0, 0xa4,0xa1);

	mdelay(100);
	write_reg(par, 0x29); /* display on */
	mdelay(20);

	return 0;
}

static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
{
	fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
		"%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);

	/* Column address */
	write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);

	/* Row adress */
	write_reg(par, 0x2B, ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);

	/* Memory write */
	write_reg(par, 0x2C);
}

#define MY (1 << 7)
#define MX (1 << 6)
#define MV (1 << 5)
static int set_var(struct fbtft_par *par)
{
	fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);

	return 0;
}

#define CURVE(num, idx)  curves[num*par->gamma.num_values + idx]
static int set_gamma(struct fbtft_par *par, unsigned long *curves)
{
	int i,j;

	fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);

	for (i = 0; i < par->gamma.num_curves; i++)
		write_reg(par, 0xE0 + i,
			CURVE(i, 0), CURVE(i, 1), CURVE(i, 2),
			CURVE(i, 3), CURVE(i, 4), CURVE(i, 5),
			CURVE(i, 6), CURVE(i, 7), CURVE(i, 8),
			CURVE(i, 9), CURVE(i, 10), CURVE(i, 11),
			CURVE(i, 12), CURVE(i, 13));

	return 0;
}
#undef CURVE


static struct fbtft_display display = {
	.regwidth = 8,
	.width = 240,
	.height = 204,
	.gamma_num = 2,
	.gamma_len = 14,
	.gamma = DEFAULT_GAMMA,
	.fbtftops = {
		.init_display = init_display,
		.set_addr_win = set_addr_win,
		.set_var = set_var,
		.set_gamma = set_gamma,
	},
};


FBTFT_REGISTER_DRIVER(DRVNAME, "sitronix,st7735r", &display);

MODULE_ALIAS("spi:" DRVNAME);
MODULE_ALIAS("platform:" DRVNAME);
MODULE_ALIAS("spi:st7735r");
MODULE_ALIAS("platform:st7735r");

MODULE_DESCRIPTION("FB driver for the ST7735R LCD Controller");
MODULE_AUTHOR("Noralf Tronnes");
MODULE_LICENSE("GPL");

修改成功后编译源码,烧写镜像后可以正常打开/dev/fb0 来才做framebuffer

赞(0) 打赏
未经允许不得转载:huangea的博客 » OPENWRT WIDORA 驱动SPI屏,芯片ST7789V SPI屏驱动记录
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

有趣的网站

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏