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

📄 main.c

📁 HDMI anx9021的驱动
💻 C
字号:
//********************************************************************************************
//********************************************************************************************
//***************************     Firmware for ANX9021     ***********************************
//********************************************************************************************
//********************************************************************************************

//******************************************************************************
//  ANALOGIX Company 
//  ANX9021 Firmware on AT89C51RC clean for customer
//  Version 1.51	2006/04/27
//******************************************************************************
//******************************************************************************
// Version 1.52    2006/05/19
// Disable HDCP auto reset before PLL reset and enable HDCP auto reset after PLL reset
// updated by XiaoYong 
//******************************************************************************

//******************************************************************************
// Version 1.53   2006/05/24
// Change POP Noise handling sequence and add more time slot for POP Noise handling routine "void ANX9021_POPNoise(void);"
// updated by XiaoYong 
//******************************************************************************

//******************************************************************************
// Version 1.54    2006/06/06
// Use hardware solution to handle POP Noise, change two registers' ( [0x60:0xB7] and [0x60:0xB4] ) value
// And remove the software POP Noise handling routine "void ANX9021_POPNoise(void);"
// updated by XiaoYong 
//******************************************************************************

#include <stdio.h>
#include <string.h>
#include "i2c_intf.h"
#include "uart_int.h"
#include "mcu.h"
#include "timer.h"
#include "ANX9021.h"

#define DEF_DEBUG_MODE 0

extern bit g_Restart_System;

char argc;
char *argv[3];
bit debug_mode;
bit enable_information;
bit port_sel;
	
void decode_term_str(void);
int hex_to_int(char *s);
void proc_term_cmd();
void CommandProcess ();


void serial_isr(void) interrupt 4
{
   prot_isr(); _NOP_;
}

void timer1_isr(void) interrupt 1
{
	timer_isr(); _NOP_;
}





void main () 
{
    enable_debug_output = 1;
    delay_ms(100);
    debug_mode = DEF_DEBUG_MODE;
    enable_information = 1;
    
    InitMCU();
    debug_printf("ANX9021 firmware ");
    debug_puts("start...");
    debug_printf("ANX9021 MCU FirmWare version: %.2f\n",ANX9021_FW_VER);

    ANX9021_Chip_Located();
    ANX9021_PowerCtrl_API(ANX9021_ON);
        
    while (1)
    {
        P2_7 = 0;
        port_sel = ~P2_6;

        ANX9021_HDMI_Port_Switch(port_sel);
        ANX9021_Int_Process();
        ANX9021_Timer_Process ();
        
        CommandProcess ();
        delay_ms(10);
    }

}

void decode_term_str(void)
{
    char *s, *s1;
    char space;
    
    s = command_buf;
    s1 = s;
    argc = 0;
    if (*s) {
        space = 0;
        argv[argc++] = s;
        while (*s) {
            if (*s == ' ') {
                *s = 0;
                if (!space) {
                    space = 1;
                }
            } else {
                    if (space)
                        argv[argc++] = s;
                   space = 0;
            }
            s++;
        }
    }
    
}

int hex_to_int(char *s)
{
    int r;
    
    r = 0;
    while (*s) {
        if (*s >= '0' && *s <= '9')
            r = (r << 4) + *s - '0';
        if (*s >= 'a' && *s <= 'f')
            r = (r << 4) + *s - 'a' + 10;
        if (*s >= 'A' && *s <= 'F')
            r = (r << 4) + *s - 'A' + 10;
        s++;
    }
    return r;
}


/* process terminal command */

void proc_term_cmd()
{
    unsigned char c, c1,i;
    if (argc == 0)
        return;
	// rp0 : read register in 0x60
	// "\rp0 0xaa" means read register 0x60:0xaa 
    if (!strcmp(argv[0], "rp0")) {
        c = i2c_read_p0_reg(hex_to_int(argv[1]), &c1);
        debug_printf("rp0: %.2x, [%s]=%.2x\n", (unsigned int)c, argv[1], (unsigned int)c1);
    } 
	// rp1 : read register in 0x68
	// "\rp1 0xaa" means read register 0x68:0xaa 
	else if (!strcmp(argv[0], "rp1")) {
        c = i2c_read_p1_reg(hex_to_int(argv[1]), &c1);
        debug_printf("rp1: %.2x, [%s]=%.2x\n", (unsigned int)c, argv[1], (unsigned int)c1);
    } 
	// wp0 : write register in 0x60
	// "\wp0 0xaa 0x00" means write register 0x60:0xaa to 0x00
	else if (!strcmp(argv[0], "wp0")) {
        c = i2c_write_p0_reg(hex_to_int(argv[1]), hex_to_int(argv[2]));
        debug_printf("wp0: %.2x, [%s]=%s\n", (unsigned int)c, argv[1], argv[2]);
    } 
	// wp1 : write register in 0x68
	// "\wp1 0xaa 0x00" means write register 0x68:0xaa to 0x00
	else if (!strcmp(argv[0], "wp1")) {
        c = i2c_write_p1_reg(hex_to_int(argv[1]), hex_to_int(argv[2]));
        debug_printf("wp1: %.2x, [%s]=%s\n", (unsigned int)c, argv[1], argv[2]);
    }  
	// infoon(information on) means display debug information via serial port
	// command format: "\infoon"
	else if (!strcmp(argv[0], "infoon")) {
      enable_information = 1;
    } 
	// infoon(information on) means don't display debug information via serial port
	// command format: "\infooff"
	else if (!strcmp(argv[0], "infooff")) {
      enable_information = 0;
    } 
	// reset chip via serial port
	// command format:"\rst"
	else if (!strcmp(argv[0], "rst")) {
        g_Restart_System = 1;
    } 
	else if (!strcmp(argv[0], "hpd")) {
        P3_4 = ~P3_4;
        P3_5 = ~P3_5;
        debug_puts("HPD issued.");
	}
	else if (!strcmp(argv[0], "cfix")) {
  //      fix_method = hex_to_int(argv[1]);
    }  
    else if (!strcmp(argv[0], "rp0all"))
    {
	for(i=0;i<128;i++) 
	{
	    i2c_read_p0_reg(i,&c1);
	if((i&0x0f)==0)
	    debug_printf("\n rp0: [%.2x]  %.2x  ", (unsigned int)i, (unsigned int)c1);
	else 
	    debug_printf("%.2x  ", (unsigned int)c1);
	}
	for(i=0;i<128;i++)
	{ 
	    i2c_read_p0_reg(i+128,&c1);
	    if((i&0x0f)==0)
	        debug_printf("\n rp0: [%.2x]  %.2x  ", (unsigned int)(i+128), (unsigned int)c1);
	    else 
		 debug_printf("%.2x  ", (unsigned int)c1);
	 }

	debug_printf("\n");
    }    
    else if (!strcmp(argv[0], "rp1all"))
    {
	for(i=0;i<128;i++)
	{
	    i2c_read_p1_reg(i,&c1);
	if((i&0x0f)==0)
	    debug_printf("\n rp1: [%.2x]  %.2x  ", (unsigned int)i, (unsigned int)c1);
	else 
	    debug_printf("%.2x  ", (unsigned int)c1);
	}
	for(i=0;i<128;i++)
	{
	    i2c_read_p1_reg(i+128,&c1);
	    if((i&0x0f)==0)
	        debug_printf("\n rp1: [%.2x]  %.2x  ", (unsigned int)(i+128), (unsigned int)c1);
	    else 
		 debug_printf("%.2x  ", (unsigned int)c1);
	 }

	debug_printf("\n");
    }
	else if (!strcmp(argv[0], "pop")) 
	{/*
		pop_en = !pop_en;
		if(pop_en)
		{
			debug_puts(" pop noise is handled.");
		}
		else
		{
			debug_puts(" pop noise is not handled.");

		}
	*/
	}
	else
        debug_printf("unknown command: %s\n", argv[0]);
}

void CommandProcess () 
{
    if (cmd_valid) 
	{
        cmd_valid = 0;
        process_cmd();
    }
    if (term_cmd_valid)
	{
        term_cmd_valid = 0;
        command_buf[command_buf_len] = 0;
        enable_debug_output = 1;
        decode_term_str();
        proc_term_cmd();
        enable_debug_output = enable_information;
    }
}



⌨️ 快捷键说明

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