树莓派屏幕线缆连接顺序:

DRM显示框架适配(推荐)
创建command.txt
# MIPI_DCS_SOFT_RESET
command 0x01
delay 150
command 0xF0 0xC3
command 0xF0 0x96
command 0x36 0x68
# MIPI_DCS_SET_PIXEL_FORMAT
# 16-bit data bus for 16-bit/pixel (RGB 5-6-5-bit input) 65K-Color
command 0x3A 0x05
command 0xB0 0x80
command 0xB6 0x00 0x02
command 0xB5 0x02 0x03 0x00 0x04
command 0xB1 0x80 0x10
command 0xB4 0x00
command 0xB7 0xC6
command 0xC5 0x24
command 0xE4 0x31
command 0xE8 0x40 0x8A 0x00 0x00 0x29 0x19 0xA5 0x33
command 0xC2
command 0xA7
command 0xE0 0xF0 0x09 0x13 0x12 0x12 0x2B 0x3C 0x44 0x4B 0x1B 0x18 0x17 0x1D 0x21
command 0xE1 0xF0 0x09 0x13 0x0C 0x0D 0x27 0x3B 0x44 0x4D 0x0B 0x17 0x17 0x1D 0x21
command 0x36 0xEC
command 0xF0 0xC3
command 0xF0 0x69
# MIPI_DCS_ENTER_NORMAL_MODE
command 0x13
delay 20
# MIPI_DCS_EXIT_SLEEP_MODE
# Sleep out
command 0x11
# MIPI_DCS_ENTER_NORMAL_MODE
# Display on
command 0x29
delay 100
创建python脚本,命名为mipi-dbi-cmd
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: CC0-1.0
#
# Written in 2022 by Noralf Trønnes <noralf@tronnes.org>
#
# To the extent possible under law, the author(s) have dedicated all copyright and related and
# neighboring rights to this software to the public domain worldwide. This software is
# distributed without any warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication along with this software.
# If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
from __future__ import print_function
import argparse
import sys
def hexstr(buf):
return ' '.join('{:02x}'.format(x) for x in buf)
def parse_binary(buf):
if len(buf) < 18:
raise ValueError('file too short, len=%d' % len(buf))
if buf[:15] != b'MIPI DBI\x00\x00\x00\x00\x00\x00\x00':
raise ValueError('wrong magic: %s' % hexstr(buf[:15]))
if buf[15] != 1:
raise ValueError('wrong version: %d' % (buf[15]))
result = ''
cmds = buf[16:]
i = 0
while i < len(cmds):
try:
pos = i
cmd = cmds[i]
i += 1
num_params = cmds[i]
i += 1
params = cmds[i:i+num_params]
if len(params) != num_params:
raise IndexError()
if cmd == 0x00 and num_params == 1:
s = 'delay %d\n' % params[0]
else:
s = 'command 0x%02x' % cmd
if params:
s += ' '
s += ' '.join('0x{:02x}'.format(x) for x in params)
s += '\n'
except IndexError:
raise ValueError('malformed file at offset %d: %s' % (pos + 16, hexstr(cmds[pos:])))
i += num_params
result += s
return result
def print_file(fn):
with open(args.fw_file, mode='rb') as f:
fw = f.read()
s = parse_binary(bytearray(fw))
print(s)
def parse_values(parts):
vals = []
for x in parts:
try:
val = int(x, 0)
except ValueError:
raise ValueError('not a number: %s' % x)
if val < 0 or val > 255:
raise ValueError('value out of bounds: %s (%d)' % (hex(val), val))
vals.append(val)
return vals
def make_file(fw_file, input_file):
with open(input_file, mode='r') as f:
lines = f.readlines()
buf = bytearray()
buf.extend(b'MIPI DBI\x00\x00\x00\x00\x00\x00\x00') # magic
buf.append(1) # version
for idx, line in enumerate(lines):
# strip off comments and skip empty lines
comment_idx = line.find('#')
if comment_idx >= 0:
line = line[:comment_idx]
line = line.strip()
if not line:
continue
try:
parts = line.split()
if parts[0] == 'command':
vals = parse_values(parts[1:])
buf.append(vals[0])
num_params = len(vals) - 1
buf.append(num_params)
if num_params:
buf.extend(vals[1:])
elif parts[0] == 'delay':
vals = parse_values(parts[1:])
if len(vals) != 1:
raise ValueError('delay takes exactly one argument')
buf.append(0x00)
buf.append(1)
buf.append(vals[0])
else:
raise ValueError('unknown keyword: %s' % parts[0])
except ValueError as e:
raise ValueError('error: %s\nline %d: %s' % (e, idx + 1, line))
with open(fw_file, mode='wb') as f:
f.write(buf)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='MIPI DBI Linux driver firmware tool')
parser.add_argument('fw_file', help='firmware binary file')
parser.add_argument('input', nargs='?', help='Input commands file')
parser.add_argument('-v', '--verbose', action='store_true', help='Verbose output')
parser.add_argument('-d', '--debug', action='store_true', help='Print exception callstack')
args = parser.parse_args()
try:
if args.input:
make_file(args.fw_file, args.input)
if args.verbose:
print_file(args.fw_file)
else:
print_file(args.fw_file)
except Exception as e:
if args.debug:
raise
print(e, file=sys.stderr)
sys.exit(1)
执行以下命令
(踩坑!不知道为何,使用别的自定义bin文件名是不行的,必须使用默认文件名panel.bin)
创建bin文件:
./mipi-dbi-cmd panel.bin command.txt
复制到固件文件夹
sudo cp ./panel.bin /lib/firmware/vim /boot/firmware/config.txt
在文件末尾添加:
dtoverlay=mipi-dbi-spi,spi0-0,speed=48000000
dtparam=width=480,height=320
dtparam=reset-gpio=6,dc-gpio=5
dtparam=write-only
fbtft显示框架适配
首先请克隆我创建的驱动仓库:https://github.com/sAkuraOfficial/st7796_linux_driver
dts文件编译
dtc -I dts -O dtb -o rpi5-st7796s.dtbo rpi5-st7796s.dts
sudo cp ./rpi5-st7796s.dtbo /boot/firmware/overlays 内核模块文件编译
make clean && make
sudo make rpi-install 添加overlay
dtoverlay=rpi5-st7796s内核版本太新的情况下,会导致在镜像源中无法下载到相应的内核头文件,需要降级内核
zhouzihao@zhouzihao ~ ❯ sudo apt install linux-image-6.12.34+rpt-rpi-v8
zhouzihao@zhouzihao ~ ❯ sudo update-initramfs -u
zhouzihao@zhouzihao ~ ❯ sudo cp /boot/vmlinuz-6.12.34+rpt-rpi-v8 /boot/firmware/
sudo cp /boot/initrd.img-6.12.34+rpt-rpi-v8 /boot/firmware/
sudo chmod 755 /boot/firmware/vmlinuz-6.12.34+rpt-rpi-v8
sudo chmod 755 /boot/firmware/initrd.img-6.12.34+rpt-rpi-v8编辑/boot/firmware/config.txt
末尾加入
kernel=vmlinuz-6.12.34+rpt-rpi-v8
initramfs initrd.img-6.12.34+rpt-rpi-v8 followkernel
重启树莓派
sudo reboot触摸屏驱动适配(Linux官方优化较差、不推荐使用)
dtoverlay=ads7846,cs=1,penirq=16,penirq_pull=2,speed=1000000,swapxy=1,xmin=260,xmax=3920,ymin=228,ymax=3944
附件: