在rk平台调试时候,经常遇到 LCD 厂商提供的参数格式不是我们需要的格式,这时候需要转换格式需要额外多做很多工作,如下格式为常见格式:
- Resolution:800x1280
- External system porch setting: VS=4 ,VBP=8 ,VFP=24 ,HS=18 ,HBP=18 ,HFP=18
- Frame rate:60HZ
- MIPI CLK:405Mbps
- Power:VCI=3.3, IOVCC=1.8
- LCD_nReset=1;
- Delayms(5);
- LCD_nReset=0;
- Delayms(10);
- LCD_nReset=1;
- Delayms(120);
- //========== JD9365 B0E10.1 initial setting ==========//
- //Page0
- SSD_Single(0xE0,0x00);
- //--- PASSWORD ----//
- SSD_Single(0xE1,0x93);
- SSD_Single(0xE2,0x65);
- SSD_Single(0xE3,0xF8);
- //Lane select by internal reg 4 lanes
- SSD_Single(0xE0,0x04);
- SSD_Single(0x2D,0x03);//defult 0x01
- SSD_Single(0xE0,0x00);
- SSD_Single(0x80,0x03);
- //--- Sequence Ctrl ----//
- SSD_Single(0x70,0x02); //DC0,DC1
- SSD_Single(0x71,0x23); //DC2,DC3
- SSD_Single(0x72,0x06); //DC7
- ... // 省略部分代码
- //DISP ON
- SSD_Number(0x01);
- SSD_CMD(0x29); // DSPON
- Delayms(5);
- //--- TE----//
- SSD_Single(0x35,0x00);
几百行转化成rk认可的格式如下:
- /*
- * Copyright (C) 2018 xxxx, Inc.
- * Licensed under GPLv2 or later.
- * fileName : lcd-JLT_BI10119P40-28D_JD9365-mipi.dtsi
- * author : W.Honee
- * create date : Thu Jan 4 10:44:06 2018
- * lcd model : JLT_BI10119P40-28D
- * resolution : 800 X 1280
- * mipi channel : four
- */
- / {
- /* mipi 相关配置
- * compatible -- 用户内核代码寻找对应dts配置的匹配字符串
- * rockchip,screen_init -- 配置是否需要初始化代码,为1时,disp_mipi_init_cmds 才有效果
- * rockchip,dsi_lane -- 配置MIPI的通道数
- * rockchip,dsi_hs_clk -- MIPI时钟
- * rockchip,mipi_dsi_num -- 配置MIPI的组数
- */
- disp_mipi_init: mipi_dsi_init{
- compatible = "rockchip,mipi_dsi_init";
- rockchip,screen_init = <1>;
- rockchip,dsi_lane = <4>;
- rockchip,dsi_hs_clk = <500>;
- rockchip,mipi_dsi_num = <1>;
- };
- /* mipi lcd 的电源配置( 说明:默认不需要开启脚位控制 )
- * compatible -- 用户内核代码寻找对应dts配置的匹配字符串
- * mipi_lcd_rst -- 配置复位脚
- * mipi_lcd_en -- 配置电源脚
- */
- disp_mipi_power_ctr: mipi_power_ctr {
- compatible = "rockchip,mipi_power_ctr";
- /*
- mipi_lcd_rst:mipi_lcd_rst{
- compatible = "rockchip,lcd_rst";
- rockchip,gpios = <&gpio2 GPIO_C2 GPIO_ACTIVE_HIGH>;
- rockchip,delay = <20>;
- };
- mipi_lcd_en:mipi_lcd_en {
- compatible = "rockchip,lcd_en";
- rockchip,gpios = <&gpio0 GPIO_C1 GPIO_ACTIVE_HIGH>;
- rockchip,delay = <100>;
- };
- */
- };
- /* mipi lcd 初始化代码
- * compatible -- 用户内核代码寻找对应dts配置的匹配字符串
- * rockchip,cmd_debug -- 配置是否启用debug模式
- * str_init_cmds -- 配置具体初始化值
- */
- disp_mipi_init_cmds: screen-on-cmds {
- compatible = "rockchip,screen-on-cmds";
- rockchip,cmd_debug = <0>;
- rockchip,on-cmds1{
- compatible = "rockchip,on-cmds";
- rockchip,cmd_type = ;
- rockchip,dsi_id = <0>;
- rockchip,cmd = <0x15 0xE0 0x00>;
- rockchip,cmd_delay = <1>;
- };
- rockchip,on-cmds2{
- compatible = "rockchip,on-cmds";
- rockchip,cmd_type = ;
- rockchip,dsi_id = <0>;
- rockchip,cmd = <0x15 0xE1 0x93>;
- rockchip,cmd_delay = <1>;
- };
- ... // 省略部分代码
- rockchip,on-cmds221{
- compatible = "rockchip,on-cmds";
- rockchip,cmd_type = ;
- rockchip,dsi_id = <0>;
- rockchip,cmd = <0x15 0x35 0x00>;
- rockchip,cmd_delay = <1>;
- };
- };
- /*
- * mipi lcd 时序配置,此部分需要手动修改细节。
- *
- */
- disp_timings: display-timings {
- native-mode = <&timing0>;
- compatible = "rockchip,display-timings";
- timing0: timing0 {
- screen-type = ;
- lvds-format = ;
- out-face = ;
- clock-frequency = <72000000>;
- hactive = <800>;
- vactive = <1280>;
- hback-porch = <18>; // 120
- hfront-porch = <18>;
- vback-porch = <8>; // 14
- vfront-porch = <24>; // 116
- hsync-len = <18>;
- vsync-len = <4>;
- hsync-active = <0>;
- vsync-active = <0>;
- de-active = <0>;
- pixelclk-active = <0>;
- swap-rb = <0>;
- swap-rg = <0>;
- swap-gb = <0>;
- };
- };
- };
手动修改劳神费力,所以我觉得应该写一个工具在提高效率,于是就有了如下代码:
- #!/usr/bin/python
- #-*- coding: utf-8 -*-
- '''
- NAME : 转化屏初始化代码为Rockchip芯片的dts格式
- AUTOR : W.Honee
- DATE : 20180102
- VERSION: V0.1
- '''
- import re
- import os
- import sys
- import time
- import getpass
- """
- 常量数据
- """
- DEFAULT_MIPI_CLK = 500
- DEFAULT_CMD_DELAY = 0
- DEFAULT_RESUME_DELAY = 120
- DEFAULT_EXIT_DELAY = 90
- '''
- 常量字符串定义
- '''
- FILE_HEAD = """
- /*
- * Copyright (C) 2018 xxxx, Inc.
- * Licensed under GPLv2 or later.
- * fileName : %str_fileName%
- * author : %str_author%
- * create date : %str_date%
- * lcd model : 请手动填入Model型号
- * resolution : 请手动填入分辨率
- * mipi channel : 请手动填入mipi通道数
- */
- """
- FILE_BODY_HEAD = """
- / {
- /* mipi 相关配置
- * compatible -- 用户内核代码寻找对应dts配置的匹配字符串
- * rockchip,screen_init -- 配置是否需要初始化代码,为1时,disp_mipi_init_cmds 才有效果
- * rockchip,dsi_lane -- 配置MIPI的通道数
- * rockchip,dsi_hs_clk -- MIPI时钟
- * rockchip,mipi_dsi_num -- 配置MIPI的组数
- */
- disp_mipi_init: mipi_dsi_init{
- compatible = "rockchip,mipi_dsi_init";
- rockchip,screen_init = <1>;
- rockchip,dsi_lane = <4>;
- rockchip,dsi_hs_clk = <%str_hs_clk%>;
- rockchip,mipi_dsi_num = <1>;
- };
- /* mipi lcd 的电源配置( 说明:默认不需要开启脚位控制 )
- * compatible -- 用户内核代码寻找对应dts配置的匹配字符串
- * mipi_lcd_rst -- 配置复位脚
- * mipi_lcd_en -- 配置电源脚
- */
- disp_mipi_power_ctr: mipi_power_ctr {
- compatible = "rockchip,mipi_power_ctr";
- /*
- mipi_lcd_rst:mipi_lcd_rst{
- compatible = "rockchip,lcd_rst";
- rockchip,gpios = <&gpio2 GPIO_C2 GPIO_ACTIVE_HIGH>;
- rockchip,delay = <20>;
- };
- mipi_lcd_en:mipi_lcd_en {
- compatible = "rockchip,lcd_en";
- rockchip,gpios = <&gpio0 GPIO_C1 GPIO_ACTIVE_HIGH>;
- rockchip,delay = <100>;
- };
- */
- };
- /* mipi lcd 初始化代码
- * compatible -- 用户内核代码寻找对应dts配置的匹配字符串
- * rockchip,cmd_debug -- 配置是否启用debug模式
- * str_init_cmds -- 配置具体初始化值
- */
- disp_mipi_init_cmds: screen-on-cmds {
- compatible = "rockchip,screen-on-cmds";
- rockchip,cmd_debug = <0>;
- """
- ROCKCHIP_INIT_CMD = """
- rockchip,on-cmds%str_count%{
- compatible = "rockchip,on-cmds";
- rockchip,cmd_type = ;
- rockchip,dsi_id = <0>;
- rockchip,cmd = <%str_cmds%>;
- rockchip,cmd_delay = <%str_delay%>;
- };
- """
- FILE_BODY_TAIL = """
- };
- /*
- * mipi lcd 时序配置,此部分需要手动修改细节。
- *
- */
- disp_timings: display-timings {
- native-mode = <&timing0>;
- compatible = "rockchip,display-timings";
- timing0: timing0 {
- screen-type = ;
- lvds-format = ;
- out-face = ;
- clock-frequency = <72000000>;
- hactive = <800>;
- vactive = <1280>;
- hback-porch = <18>; // 120
- hfront-porch = <18>;
- vback-porch = <8>; // 14
- vfront-porch = <24>; // 116
- hsync-len = <18>;
- vsync-len = <4>;
- hsync-active = <0>;
- vsync-active = <0>;
- de-active = <0>;
- pixelclk-active = <0>;
- swap-rb = <0>;
- swap-rg = <0>;
- swap-gb = <0>;
- };
- };
- };
- """
- BASEDIR = os.path.abspath(os.path.dirname(__file__))
- '''
- 定义各种函数
- '''
- def parse_init_files():
- '''
- 解析并写入文件
- '''
- fileHead = re.sub('%str_fileName%',sys.argv[1].split('.')[0]+'.dtsi',FILE_HEAD)
- fileHead = re.sub('%str_author%',getpass.getuser(),fileHead)
- fileHead = re.sub('%str_date%',time.asctime( time.localtime(time.time()) ),fileHead)
- fileHead = re.sub('%str_model_name%',"",fileHead)
- with open(sys.argv[1].split('.')[0]+'.dtsi', 'w') as f:
- f.write(fileHead)
- f.close()
- count=0
- with open(sys.argv[1], 'rb') as fi:
- with open(sys.argv[1].split('.')[0]+'.dtsi', 'aw') as fo:
- fo.write(re.sub('%str_hs_clk%',str(DEFAULT_MIPI_CLK),FILE_BODY_HEAD))
- for line in fi:
- if line.startswith("//"):
- #print " -- 注释行直接保留 -- " + ENTER
- #fo.write(line)
- continue
- elif line.startswith('SSD_Single'):
- count = count + 1
- params = line[11:].split(';')[0].split(')')[0].split(',')
- data = re.sub('%str_count%',str(count),ROCKCHIP_INIT_CMD)
- # 0x15 2段的数据
- if len(params) == 2:
- temp = "0x15 " + params[0] + " " + params[1]
- # 0x39 多段的数据
- elif len(params) > 2:
- temp = '0x39'
- for param in params:
- temp = temp + " " + param
- data = re.sub('%str_cmds%',temp,data)
- data = re.sub('%str_delay%',str(DEFAULT_CMD_DELAY),data)
- fo.write(data)
- elif line.startswith('SSD_CMD'):
- count = count + 1
- params = line[8:12]
- data = re.sub('%str_count%',str(count),ROCKCHIP_INIT_CMD)
- if params == '0x11':
- temp = "0x05 dcs_set_display_on"
- data = re.sub('%str_cmds%',temp,data)
- data = re.sub('%str_delay%',str(DEFAULT_RESUME_DELAY),data)
- elif params == '0x29':
- temp = "0x05 dcs_exit_sleep_mode"
- data = re.sub('%str_cmds%',temp,data)
- data = re.sub('%str_delay%',str(DEFAULT_EXIT_DELAY),data)
- fo.write(data)
- else:
- continue
- #print "---不需要处理,舍弃的数据----" + ENTER
- #print line
- fo.write(FILE_BODY_TAIL)
- fo.close()
- fi.close()
- def main( ):
- '''
- 入口函数
- '''
- parse_init_files( )
- if __name__ == '__main__':
- ''' 工具被调用的,入口按照main函数 '''
- if len(sys.argv) < 2:
- print "输出参数错误,请输入有效的文件名!"
- sys.exit()
- elif len(sys.argv) == 2:
- if not os.path.isfile(sys.argv[1]):
- print "原始驱动文件不存在,请确认文件名是否输入错误!"
- sys.exit()
- print "开始转换格式,请稍后 ..."
- main( )
- print '文件转换完毕!'
- exit( )
输入需要转化的LCD的原始文件,就可以输出我们需要的rk格式的代码。
当然其他格式的如 Generic_Short_Write_1P 和 DCS_Short_Write_1P 等都可以如法炮制。
版权所有丨如未注明,均为原创,转载请注明转自:https://whonee.net/rockchip-lcd-format-tools.html