⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 analyse_file.py

📁 中星微301摄想头最新驱动
💻 PY
字号:
#! /usr/bin/env pythonimport osimport sys####zc030x Register map#-------------------#0x01d to 0x020  HSYNC/VSYNC (same values as hv7131b)#0x090 to 0x094: i2c bus control#0x10a to 0x112: A 3x3 matrix of bytes, which is an RGB->RGB transform#                (affected by changing backlight, hue and saturation settings)#0x120 to 0x13f: 32 bytes (affected by changing contrast, brightness#                and gamma)#0x186,0x18c,0x18f:  Affected by changing image size#0x195 to 0x197: Affected by changing image size#0x1c6 and 0x1cb: Controls the sharpness somehow### Declare the register map valueRegisterMap = []RegisterMap.append( (0x01d, 0x020, ">>> HSYNC/VSYNC") )RegisterMap.append( (0x090, 0x096, ">>> I2C Bus control") )RegisterMap.append( (0x10a, 0x112, ">>> 3x3 RGB matrix conversion") )RegisterMap.append( (0x120, 0x13f, ">>> Gamma matrix") )RegisterMap.append( (0x1c6, 0x1cb, ">>> Sharpness control") )Output = []flagged = 0Matrix = []try:    # Check argument is given    if (len(sys.argv) < 2):        print "Call analyse_file.py name"    else:        name = sys.argv[1]        print "Analysing " + name        file = open(name)        Read = ""        I2CSelection = 1        I2CReading   = 2        I2CAcking    = 3        I2CWriting   = 4        I2CChecking  = 5        RegisterRead = 6        RegisterWrite= 7        I2CRegister  = 0         I2CValue     = 0        PreviousState = 0        Matrix.append("")        Matrix.append("")        Matrix.append("")        Matrix.append("")        Matrix.append("")        Matrix.append("")        Matrix.append("")        Matrix.append("")        Matrix.append("")        Str = ""        lines = file.readlines()        for line in lines:            line = line.lstrip(" ")            line = line.lstrip("\t")            if (line[0] == '{'):                flagged = 0                try:                    dir, tmp, val, addr, size, tmp2 = line.split(",")                except ValueError:                    continue                # Now the logic state                direction = 0                Read = "Unknown"                try:                    direction = dir.index("0x40")                except ValueError:                    direction = -1                                    if (direction != -1):                    Read = "Writing"                try:                    direction = dir.index("0xc0")                except ValueError:                    direction = -1                                    if (direction != -1):                    Read = "Reading"                                    # Now the logic                address = int(addr, 16)                value = int(val, 16)                                # Start with HSYN/VSYNC                Register = RegisterMap[0]                if (address >= Register[0] and address <= Register[1]):                    # Now we are dealing with I2C, so                    flagged = 1                    Output.append(Register[2] + ":" + Read + " at address " + addr+" the value "+val+" ("+size+")")                                                # Start with I2C                Register = RegisterMap[1]                if (address >= Register[0] and address <= Register[1]):                    # Now we are dealing with I2C, so                    flagged = 1                    # Common                    if (address == 0x92):                        PreviousState = I2CSelection                        I2CRegister = val                                        # Writing                    if (address == 0x93 and PreviousState == I2CSelection):                        PreviousState = I2CWriting                        I2CValue = val                    if (address == 0x94 and PreviousState == I2CWriting):                        PreviousState = I2CAcking                    if (address == 0x90 and value == 1 and PreviousState == I2CAcking):                        Read = "Writing "                        PreviousState = I2CChecking                    if (address == 0x91 and value == 1 and PreviousState == I2CChecking):                        Output.append(Register[2]+": Writing @"+I2CRegister+"="+I2CValue+"("+size+")")                    # Reading                    if (address == 0x90 and value == 2 and PreviousState == I2CSelection):                        Read = "Reading "                        PreviousState = I2CReading                    if (address == 0x91 and value == 1 and PreviousState == I2CReading):                        PreviousState = I2CAcking                    if ( (address == 0x95 or address == 0x96) and PreviousState == I2CAcking):                        PreviousState = I2CChecking                        Output.append(Register[2]+": Reading @"+I2CRegister+"("+size+")")                # Start with RGB2RGB conversion                Register = RegisterMap[2]                if (address >= Register[0] and address <= Register[1]):                    # Now we are dealing with I2C, so                    flagged = 1                    # Reset the initial state                    if (address == Register[0]):                        PreviousState = 0                    # Fill the matrix                        Matrix[PreviousState] = val                    PreviousState = PreviousState+1                    if ((PreviousState-1) % 3 == 2):                        Output.append(Register[2] + ": [" + Matrix[PreviousState - 3] + " " + Matrix[PreviousState - 2] + " " + Matrix[PreviousState - 1] + "]" )                # Start with gamma matrix                Register = RegisterMap[3]                if (address >= Register[0] and address <= Register[1]):                    # Now we are dealing with I2C, so                    flagged = 1                    # Reset the initial state                    if (address == Register[0]):                        PreviousState = 0                    # Fill the matrix                        Str = Str + val[5:7]                    if (PreviousState % 16 != 15):                        Str = Str + ":"                    else:                        Str = Str + " "                    PreviousState = PreviousState+1                    if (PreviousState == 2):                        Output.append(Register[2] + ": [" + Str + "]" )                # Start with Sharpness control                Register = RegisterMap[4]                if (address >= Register[0] and address <= Register[1]):                    # Now we are dealing with I2C, so                    flagged = 1                    Output.append(Register[2] + ":" + Read + " at address " + addr+" the value "+val+" ("+size+")")                if (address == 0x10 and flagged == 0):                    flagged = 1                    Output.append(">>> Trying to read EEPROM and select I2C address @ "+val)                if (flagged == 0):                    Output.append(Read + " at address " + addr+" the value "+val+" ("+size+")")            else:                Output.append("--------------------")            #print Read, "at ", address, "=", value, "(", size, ")"    for line in Output:        print line    except KeyboardInterrupt:    sys.exit()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -