I.MX6 Linux mipi配置数据合成

/***************************************************************************
 *                     I.MX6 Linux mipi配置数据合成
 * 声明:
 *     由于现有mipi配置数据不符合I.MX6的配置参数,需要将该参数进行数据转换,
 * 而这又涉及到对数据处理简单算法,主要是为了验证转换代码可靠性。
 *
 *                                       2015-12-24 深圳 南山平山村 曾剑锋
 **************************************************************************/

#include <stdio.h>
#include <string.h>
#include <unistd.h>

#define REGFLAG_DELAY            0XFFE
#define REGFLAG_END_OF_TABLE    0xFFF   // END OF REGISTERS MARKER
#define DSI_CMD_BUF_MAXSIZE        32
// 嵌入式产品数据存储可能涉及到的大小端
#define BIG_ENDIAN              1
#define LITTLE_ENDIAN            2

struct LCM_setting_table {
    unsigned cmd;
    unsigned char count;
    unsigned char para_list[64];
};

static struct LCM_setting_table lcm_initialization_setting[] = {
    {0xB9,3,{0xFF,0x83,0x94}},

    //Set MIPI
    {0xBA,6,{0x63,0x03,0x68,0x6B,0xB2,0xC0}},

    //Set Power
    {0xB1,10,{0x48,0x12,0x72,0x09,0x32,0x44,0x71,0x31,0x4F,0x35}},

    //Set Display
    {0xB2,5,{0x65,0x80,0x64,0x05,0x07}},

    //Set CYC
    {0xB4,30,{0x26,0x76,0x26,0x76,0x26,0x26,0x05,0x10,0x86,0x35,0x00,0x3F,0x26,0x76,0x26,0x76,0x26,0x26,0x05,0x10,0x86,0x3F,0x00,0xFF,0x81,0x81,0x81,0x81,0x08,0x01}},

    //Set D3
    {0xD3,33,{0x00,0x00,0x0F,0x0F,0x01,0x01,0x10,0x10,0x32,0x10,0x00,0x00,0x00,0x32,0x15,0x04,0x05,0x04,0x32,0x15,0x14,0x05,0x14,0x37,0x33,0x04,0x04,0x37,0x00,0x00,0x47,0x05,0x40}},

    //Set GIP
    {0xD5,44,{0x18,0x18,0x25,0x24,0x27,0x26,0x11,0x10,0x15,0x14,0x13,0x12,0x17,0x16,0x01,0x00,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x05,0x04,0x03,0x02,0x07,0x06,0x18,0x18,0x18,0x18,0x21,0x20,0x23,0x22,0x18,0x18,0x18,0x18}},

    //Set D6
    {0xD6,44,{0x18,0x18,0x22,0x23,0x20,0x21,0x12,0x13,0x16,0x17,0x10,0x11,0x14,0x15,0x06,0x07,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x02,0x03,0x04,0x05,0x00,0x01,0x18,0x18,0x18,0x18,0x26,0x27,0x24,0x25,0x18,0x18,0x18,0x18}},

    //Set Gamma
    {0xE0,58,{0x00,0x03,0x0B,0x0E,0x10,0x13,0x17,0x15,0x2D,0x3D,0x51,0x51,0x5E,0x75,0x7C,0x84,0x94,0x9A,0x98,0xA6,0xB2,0x57,0x57,0x5A,0x60,0x64,0x6A,0x72,0x7F,0x00,0x03,0x0B,0x0E,0x10,0x13,0x17,0x15,0x2D,0x3D,0x51,0x51,0x5E,0x75,0x7C,0x84,0x94,0x9A,0x98,0xA6,0xB2,0x57,0x57,0x5A,0x60,0x64,0x6A,0x72,0x7F}},

    //Set VCOM
    {0xB6,2,{0x34,0x34}},

    //Set Panel
    {0xCC,1,{0x0D}},

    //Set C0
    {0xC0,2,{0x1F,0x31}},

    //Set D2
    {0xD2,1,{0x88}},

    //Set EMI,0xenhance
    {0xD4,1,{0x02}},

    //Set BD
    {0xBD,1,{0x01}},

    //Set Power
    {0xB1,1,{0x60}},

    //Set BD
    {0xBD,1,{0x00}},

    //Set Power,0xOption,0xHX5186,0xMode
    {0x11,1,    {0}},
    {REGFLAG_DELAY, 150,  {}},
    {0xBF,7,{0x40,0x81,0x50,0x00,0x1A,0xFC,0x01}},
    {0x29,1,    {0}},
    {REGFLAG_DELAY, 50,  {}},
    {REGFLAG_END_OF_TABLE, 0x00, {}}
};

/**
 * 合成数据
 *  1. buf:用于存储合成后的数据;
 *  2. pare_list:用于合成的数据源,是字节数据;
 *  3. count:调用当前函数时使用pare_list中的字节数;
 *  4. endianType:合成数据时采用大端、小端的那种。
 */
void compoundData(unsigned int *buf, unsigned char *para_list, int count, int endianType) {
    unsigned int tmp = 0;
    int i = 0;
    for ( i = 0; i < count; i++ ) {
        tmp <<= 8;
        switch ( endianType ) {
        case BIG_ENDIAN :
            tmp |= para_list[count-i-1];
            break;
        default :
            tmp |= para_list[i];
            break;
        }
    }
    *buf = tmp;
}

static void push_table(struct LCM_setting_table *table, unsigned int count)
{
    int index = 0;
    int err;
    int i, j;
    unsigned int buf[DSI_CMD_BUF_MAXSIZE] = {0};

    for (i = 0; i < count; i++) {

        printf("%02d | length: %03d |", i, table[i].count);

        unsigned cmd;
        cmd = table[i].cmd;

        switch (cmd) {

        case REGFLAG_DELAY :
            usleep(table[i].count);
            break;

        case REGFLAG_END_OF_TABLE :
            break;

        default:
            printf(" aliquot: %02d | 0x", (table[i].count)/4);

            /**
             * 合成数据,buf是整形,每次合成para_list中4个字节。
             * 这部分的是合成能够被整除的那一部分的数据,后面对余下的那一部分再进行合成。
             */
            for ( j = 0; j < ( (table[i].count)/4 ); j++ ) {
                index = j * 4;
                compoundData(buf + j, &(table[i].para_list[index]), 4, LITTLE_ENDIAN);
                //compoundData(buf + j, &(table[i].para_list[index]), 4, BIG_ENDIAN);

                //控制输出数据格式。
                printf("%08x", buf[j]);
            }

            /**
             * 接下来对4取余的余数进行合成
             */
            index = j * 4;
            int remainder = table[i].count - index;
            if (  remainder != 0 ) {
                compoundData(buf + j, &(table[i].para_list[index]), table[i].count - index, LITTLE_ENDIAN);
                //compoundData(buf + j, &(table[i].para_list[index]), table[i].count - index, BIG_ENDIAN);

                //控制输出数据格式。
                switch ( remainder ) {
                case 1:
                    printf("%02x", buf[j]);
                    break;
                case 2:
                    printf("%04x", buf[j]);
                    break;
                case 3:
                    printf("%06x", buf[j]);
                    break;
                }
            }

            // 对buf进行清空,对下次数据合成造成影响。
            bzero(buf, DSI_CMD_BUF_MAXSIZE);
            //memset(buf, 0, DSI_CMD_BUF_MAXSIZE);
            break;
        }
        printf("\n\r");
    }
}

int main( int argc, char** argv )
{
    push_table(lcm_initialization_setting, sizeof(lcm_initialization_setting) / sizeof(struct LCM_setting_table));
}

/**
 * 输出结果:
 *     00 | length: 003 | aliquot: 00 | 0xff8394
 *     01 | length: 006 | aliquot: 01 | 0x6303686bb2c0
 *     02 | length: 010 | aliquot: 02 | 0x48127209324471314f35
 *     03 | length: 005 | aliquot: 01 | 0x6580640507
 *     04 | length: 030 | aliquot: 07 | 0x26762676262605108635003f2676267626260510863f00ff818181810801
 *     05 | length: 033 | aliquot: 08 | 0x00000f0f0101101032100000003215040504321514051437330404370000470540
 *     06 | length: 044 | aliquot: 11 | 0x1818252427261110151413121716010018181818181818181818050403020706181818182120232218181818
 *     07 | length: 044 | aliquot: 11 | 0x1818222320211213161710111415060718181818181818181818020304050001181818182627242518181818
 *     08 | length: 058 | aliquot: 14 | 0x00030b0e101317152d3d51515e757c84949a98a6b257575a60646a727f00030b0e101317152d3d51515e757c84949a98a6b257575a60646a727f
 *     09 | length: 002 | aliquot: 00 | 0x3434
 *     10 | length: 001 | aliquot: 00 | 0x0d
 *     11 | length: 002 | aliquot: 00 | 0x1f31
 *     12 | length: 001 | aliquot: 00 | 0x88
 *     13 | length: 001 | aliquot: 00 | 0x02
 *     14 | length: 001 | aliquot: 00 | 0x01
 *     15 | length: 001 | aliquot: 00 | 0x60
 *     16 | length: 001 | aliquot: 00 | 0x00
 *     17 | length: 001 | aliquot: 00 | 0x00
 *     18 | length: 150 |
 *     19 | length: 007 | aliquot: 01 | 0x408150001afc01
 *     20 | length: 001 | aliquot: 00 | 0x00
 *     21 | length: 050 |
 *     22 | length: 000 |
 *
 *     shell returned 23
 *
 *     Press ENTER or type command to continue
 */
时间: 2024-08-04 15:09:37

I.MX6 Linux mipi配置数据合成的相关文章

I.MX6 Linux I2C device&amp; driver hacking

/******************************************************************************************* * I.MX6 Linux I2C device& driver hacking * 声明: * 1. 本文主要是对Linux I2C驱动进行代码跟踪,主要是为了能够对I2C驱动框架有个全面的了解: * 2. 本文源代码来自myzr_android4_2_2_1_1_0.tar.bz2: * 3. 如果你有兴趣,

Linux网络配置知识点详解

Linux网络配置知识点详解 一.Linux网络配置 1.网络配置文件 (1)/etc/sysconfig/network-scripts/ifcfg-en0xxx文件 用来指定服务器上的网络配置信息 (2)/etc/hostname文件 包含了Linux系统的主机名 (3)/etc/resolv.conf文件 文件配置了DNS客户,包含了主机的域名搜索顺序和DNS服务器地址 (4)/etc/hosts IP地址和主机名映射 (5)/etc/host.conf 和主机名解析顺序 (6)/etc/

linux FTP配置详解

一.vsftpd说明: LINUX下实现FTP服务的软件很多,最常见的有vsftpd,Wu-ftpd和Proftp等.Red Hat Enterprise Linux中默认安装的是vsftpd. 访问FTP服务器时需要经过验证,只有经过了FTP服务器的相关验证,用户才能访问和传输文件.vsftpd提供了3种ftp登录形式:  (1)anonymous(匿名帐号) 使用anonymous是应用广泛的一种FTP服务器.如果用户在FTP服务器上没有帐号,那么用户可以以anonymous为用户名,以自己

Linux网络配置及SSH和Shell基础

Linux网络配置及SSH和Shell基础 一.Linux网络配置     ifconfig命令被用于配置和显示Linux内核中网络接口的网络参数.用ifconfig命令配置的网卡信息,在网卡重启后机器重启后,配置就不存在.要想将上述的配置信息永远的存的电脑里,那就要修改网卡的配置文件了. 二.hosts文件的作用及修改主机名      Hosts : The static table lookup for host name(主机名查询静态表)       Linux 的/etc/hosts是

Linux bind9配置

Linux下配置DNS服务器: 域名软件 : bind # berkely internet name domain bind: /etc/named.conf : root : named /var/named/ : 工作目录 配置文件: /etc/named.conf options { #全局配置 directory "/var/named"; }; zone "." IN { type hint; #( master -> 住 slave ->

Linux目录配置

一  Linux目录配置的依据--FHS FHS定义了两层规范,第一层是, / 下面的各个目录应该要放什么文件数据,例如/etc应该要放置设置文件,/bin与/sbin则应该要放置可执行文件等等. 第二层则是针对/usr及/var这两个目录的子目录来定义.例如/var/log放置系统登录文件./usr/share放置共享数据等等. 由于FHS仅是定义出最上层(/)及子层(/usr, /var)的目录内容应该要放置的文件数据,因此,在其他子目录层级内,就可以随开发人员自行配置了. 另外,在Linu

linux网络配置命令(一)——ifconfig

linux网络配置命令(一)--ifconfig ifconfig 查看.配置网卡信息.已过时,推荐使用ip命令 格式:  ifconfig [interface]                                                         查看指定网卡信息,可不指定 ifconfig interface [aftype] options | address ...   设置指定网卡信息 选项 interface        网卡名 up          

Linux网络配置基础篇

Linux网络配置基础篇 一.如何实现linux网络通信? 1)指定IP/NETMASK可实现本地通信: 2)指定路由(网关)可实现跨网络通信: 3)指定DNS服务器地址可实现基于主机名的通信, 主DNS服务器地址(当前服务器不在线时,启用备用DNS服务器地址) 备用DNS服务器地址 第三备份DNS服务器地址 二.配置网络方式及网络接口命名 linux 网络属于内核的功能, 配置方式: 静态指定:使用命令直接指定或修改配置文件 动态分配:依赖于本地网络中有DHCP服务 网络接口命名方式: 传统命

I.MX6 Linux udev porting

/*********************************************************************** * I.MX6 Linux udev porting * 声明: * 在嵌入式产品上,我们可以使用mdev来解决热插拔的问题,同时也经常看到 * udev,所以尝试来移植一下,但是最终发现她会丢失内核阶段产生的uevent, * 这导致无法生成内核阶段产生的设备节点,目前采用了mdev来做完成内核阶段的 * 设备节点生成,之后使用udev完成热插拔,这