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

📄 level3.c

📁 USB Pad test source code with SL811 usb host ic
💻 C
📖 第 1 页 / 共 2 页
字号:

/* FileName: Level3.c  */

#include	"io51.h"
#include 	"usb_def.h"
extern unsigned char x_10x2_flag,i_10x2_flag;
extern unsigned char y_10x2_flag,j_10x2_flag;

extern interrupt void T0_int(void);
extern interrupt void EX0_int(void);

/* the  external variable used in level3.c */
extern unsigned char ep1_squ;

/* the variable defined in level3.c */
unsigned char usb_error,wake_up;
unsigned char product_id[2];
unsigned char data_in[8];
unsigned char dev_desc[18];
unsigned char x_data;
unsigned char y_data;
unsigned char i_data;
unsigned char j_data; 
unsigned char Led_D1_8;
unsigned char Led_D9_16;
unsigned char Led_D17_24; 
unsigned char dis_data_buf[16];
 

static const unsigned char motor_report[]       ={0x21, 0x09, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00};
static const unsigned char GoPad_motor_report[] ={0x21, 0x09, 0x00, 0x02, 0x00, 0x00, 0x04, 0x00};


static const unsigned char get_cnf_desc[] = {0x80, 0x06, 0x00, 0x02, 0x00, 0x00, 0x12, 0x00};
static const unsigned char setaddr[] = {0x00, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char get_dev_desc[] = {0x80, 0x06, 0x00, 0x01, 0x00, 0x00, 0x12, 0x00};
static const unsigned char set_dev_cnf[] = {0x00, 0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char get_dev_cnf[] = {0x80, 0x08, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00};
static const unsigned char set_feature[] = {0x00, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char clear_feature[] = {0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char get_status[] ={0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00};
static const unsigned char out_report[] ={0x21, 0x09, 0x00, 0x02, 0x00, 0x00, 0x04, 0x00};
static const unsigned char in_report[] ={0xA1, 0x01, 0x00, 0x01, 0x00, 0x00, 0x06, 0x00};
                                        /* 0      1    2                                9     .   off */                
static const unsigned char segment_map[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x80,0x00};

/* the function defined in level3.c */
void Bus_enum(void);
void set_report(unsigned char i,unsigned char * data_in);
void set_motor(unsigned char i,unsigned char * data_in);
void GoPad_set_motor(unsigned char i,unsigned char * data_in);

void poll_data(unsigned char, unsigned char*);
void Strobe_dis_bit (unsigned char dis_bit_position );
void DisableAll_dis_bit (void);
void SendAClock_164 (void);
void SendDataTo_DisBit ( unsigned char dis_bit);
void OneAxialDataTo_SegmentMap (unsigned char DataType_num,unsigned char BeChanged_data );
void AllAxialDataTo_SegmentMap (void);
void Dis_all(void);
void Dis_ver(void);
void Dis_error(void);


/* the external function defined in level2.c */
extern unsigned char set_cmd(unsigned char,unsigned char*);
extern unsigned char get_desc(unsigned char,unsigned char *, unsigned char*);
extern unsigned char send_data(unsigned char,unsigned char *, unsigned char*);
extern unsigned char get_data(unsigned char, unsigned char*);

/* the external function defined in level1.c */
extern void host_blk_write(unsigned char, unsigned char *, unsigned char);
extern void host_blk_read(unsigned char, unsigned char *, unsigned char);
extern void reset_root_hub(void);
extern void host_init(void);
extern void host_int(void);
extern void send_setup(unsigned char, unsigned char,unsigned char *);
extern void xfer_data(unsigned char, unsigned char, unsigned char,unsigned char, unsigned char);
extern void sof_emit(void);
extern unsigned char crc5(unsigned int crc_input);

/* the external function defined in level0.c */
extern void	write_host_addr(unsigned char addr);
extern void    write_host_data(unsigned char datum);
extern unsigned char	read_host_data(void);
extern void	i_write_host_addr(unsigned char addr);
extern void    i_write_host_data(unsigned char datum);
extern unsigned char	i_read_host_data(void);
extern void	enable_tmr(void);
extern void	disable_tmr(void);
extern void 	delay ( unsigned int cnt);
extern void 	i_delay ( unsigned int cnt); 

/************************************************/
void Bus_enum(void)
{
	delay(1000);
	reset_root_hub();
	delay(5000); 
	reset_root_hub();
	delay(5000);	

	if (!(set_cmd(0, setaddr)))		/* set USB address from 0 to 2	*/
	   {	
		usb_error = 1;
		return;
	   }
	delay(100);
         	         
        if (!(get_desc(2, get_dev_desc, dev_desc)))	/* get device descriptor */
	   {	
		usb_error = 1;
		return;
	   }
	delay(100);

        get_desc(2, get_cnf_desc, dev_desc);	 /* get configure descriptor */
        wake_up=dev_desc[7];

        

	if (!(set_cmd(2, set_dev_cnf)))		/* set configuration value to 1 */
	   {	
		usb_error = 1;
		return;
	   }
	delay(100);

       
	if (!(get_desc(2,get_dev_cnf,dev_desc)))	 /*get device configuration*/
	   {	
		usb_error = 1;
		return;
	   }
	product_id[0] = dev_desc[10];
	product_id[1] = dev_desc[11];
	delay(100);
        /***************Add for checking ms9901' GetDeviceDescriptor ************/
         if (!(get_desc(2, get_dev_desc, dev_desc)))	/* get device descriptor*/
	   {	
		usb_error = 1;
		return;
	   }
	delay(100);
        if(product_id[0] ==0x3c && product_id[1] ==0x00)
          {
            if(dev_desc[0]!=0x12 || dev_desc[1]!=0x01 || dev_desc[2]!=0x10 || dev_desc[3]!=0x01 || dev_desc[7]!=0x08)
             { usb_error = 1;return;};
            if(dev_desc[8]!=0x5e || dev_desc[9]!=0x04 || dev_desc[10]!=0x3c || dev_desc[14]!=0x01 || dev_desc[15]!=0x02)
             { usb_error = 1;return;};
            if(dev_desc[16]!=0x00 || dev_desc[17]!=0x01)
             { usb_error = 1;return;};
           }

       /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

        if (!(set_cmd(2, clear_feature)))              /* clear feature */
	   {	
		usb_error = 1;
		return;
	   }
	delay(100);

        if (!(get_desc(2, get_status, dev_desc)))       /* get status */
	   {	
		usb_error = 1;
		return;
	   }
        delay(100);

	if (wake_up & 0x20)
	  if(!(set_cmd(2, set_feature)))
	    {
		usb_error=1;
		return;
	     }

	ep1_squ = DATA0;
  }
/********************************************************************/
void set_report(unsigned char len,unsigned char * buf)
  {
	if (!(send_data(2,out_report,buf)))
		usb_error = 1;
  }
/********************************************************************/
void set_motor(unsigned char len,unsigned char * buf)
  {
	if (!(send_data(2,motor_report,buf)))
		usb_error = 0;
  }
/********************************************************************/
void GoPad_set_motor(unsigned char len,unsigned char * buf)
  {
	if (!(send_data(2,GoPad_motor_report,buf)))
		usb_error = 0;
  }

/********************************************************************/
void	poll_data(unsigned char cnt,unsigned char* buf)
  {
	delay(10); 
	if (!(get_data(cnt, buf)))
		usb_error = 1;
  }
/**************************************************************
  Function Name: Strobe_dis_bit(unsigned char dis_bit_position )
  Function     : To strobe the display bit
  Input        : dis_bit_position--->1/2/3/4/5/6
  Output       : Non
  scop         : MakeAllLine_in_Z ( );
  Debug status :  ;2000/3/16
****************************************************************/
  void  Strobe_dis_bit ( unsigned char dis_bit_position )
  { 
    unsigned char i;
    RA3_RST=1;
    delay(1);
    RA3_RST=0;   
    for(i=0;i<=dis_bit_position;i++)
       {
        RA2_CLK=0;
        RA2_CLK=1;
       }
  }    
/******************************************************************
 Function Name: DisableAll_dis_bit ( void )
 Function     : To closing all the dis_bit that was selected before 
 Input        : dis_position
 Output       : Non
 scop         : display.c
 Debug status : ok; 2000/3/16
*******************************************************************/
   void DisableAll_dis_bit (void)
       { 
	 RA3_RST=0;
     /*  delay(1);  */
         RA3_RST=1;
    /*   delay(1);  */
       }
/***************************************************************************
 Function Name : void SendDataTo_DisBit (unsigned char dis_bit)
 Function  : to sending the dis_data to the displaying bit(line 1/2/3);
             and make 74hc37 be in belock status. 
 Input     : dis_bit--1/2/3/4/5/6; ( dis_data_buf[15] by globe variable)
 Output    : non
 Scop      : display.c
 Debug staus:
***************************************************************************/
  void SendAClock_164 (void)
     {
       RA1_CLR=1;
       RA0_CLK=0;
      /* delay (1); */
       RA0_CLK=1;
    }
/*******************************************************/
  void SendDataTo_DisBit ( unsigned char dis_bit)
     { 
         if (dis_bit==3 || dis_bit==4 || dis_bit==5 )  
              { 
                /* for line 1 */
                PORTC=dis_data_buf[dis_bit];

⌨️ 快捷键说明

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