?? usb.c
字號:
/* UsbTester Ver 05 ok HGM 01-07-05 */
#include "io51.h"
#include "usb_var.h"
#include "usb_def.h"
/* The function defined in usb.c */
interrupt void T0_int(void);
interrupt void EX0_int(void);
extern void set_report(unsigned char i,unsigned char * data_in);
extern void set_motor(unsigned char,unsigned char *);
extern void GoPad_set_motor(unsigned char,unsigned char *);
extern void set_usb_motor(unsigned char,unsigned char * );
/*For ShengYu Pad ST_L ST_R stick minus data display */
unsigned char x_10x2_flag,y_10x2_flag,i_10x2_flag,j_10x2_flag;
/* GoPad setting autofire function with 1-8 button */
static const unsigned char GoPad_Motor_on[] = {0X00,0xff, 0x00, 0x00};
static const unsigned char GoPad_Motor_off[] = {0X00,0x00, 0x00, 0x00};
static const unsigned char ShengYu_L_Motor_on[] = {0Xff,0x00, 0x00, 0x00};
static const unsigned char ShengYu_R_Motor_on[] = {0X00,0xFF, 0x00, 0x00};
static const unsigned char GoPad_AutoFire_on[] = {0X01,0x00, 0xFF, 0x00};
static const unsigned char GoPad_AutoFire_off[] = {0X01,0x00, 0x00, 0x00};
static const unsigned char auto_fire_on[] = {0xff, 0xcd,0x00,0x00};
static const unsigned char auto_fire_off[] = {0x00, 0x0c,0x00,0x00};
static const unsigned char motor_rum_right[] = {0x00, 0x09, 0xff, 0x00};
static const unsigned char motor_rum_left[] = {0x00, 0x09, 0x00, 0xff};
static const unsigned char motor_rum_off[] = {0x00, 0x08, 0x00,0x00};
static const unsigned char led_off[] = {0x00, 0x0e, 0x00,0x00};
static const unsigned char motor_off[] = {0x00, 0x02, 0x00};
static const unsigned char motor_on[] = {0xFF, 0x02, 0x00};
static const unsigned char usb_motor_left[] = {0x03, 0xFF, 0x00, 0x40};
static const unsigned char usb_motor_right[] = {0x03, 0x00, 0xFF, 0x40};
static const unsigned char usb_motor_off[] = {0x03, 0x00, 0x00, 0x40};
static const unsigned char usb_motor_on[] = {0x03, 0xFF, 0xFF, 0x40};
static const unsigned char usb_led_off[] = {0x03, 0x00, 0x00, 0x80};
static const unsigned char usb_led_on[] = {0x03, 0x00, 0x00, 0xC0};
unsigned char flag;
/*******************************************************************/
interrupt void T0_int(void)
{
/* timer0 interrupt for 1ms. */
TF0 = 0; /* clear the interrupt flag */
ET0=0; TR0=0;
TH0 = 0xFC; /* timer1 config as */
TL0 = 0x2E; /*1ms timer */
sof_emit();
TF0 = 0; /* clear the interrupt flag */
ET0=1; TR0=1;
}
/*****************************************************************/
/* interrupt void EX0_int(void)
{
timer0 interrupt for 1ms.
IE0 = 0; clear the interrupt flag
EX0=0;
host_int();
IE0 = 0; clear the interrupt flag
EX0=1;
}*/
/****************************************************************/
void main( )
{ unsigned char SetAutoFire_flag,i;
start:
P0=0x00;
P1=0x0F;
P2=0x00;
P3=0xEF; /* nCS = 0, nRD, nWR, A0 = 1 */
IE=0x00;
TCON=0x05;
TH0 = 0xFC;
TL0 = 0x2E;
TMOD=0x01;
fn = 0;
host_init();
EA=1;
TR0=1; ET0=1;
usb_error=0;
/* display version "user05" */
dis_user:
Dis_ver();
/*poll_data(8, data_in);
if (usb_error == 1)
goto start; */
while((PORTB & 0x40)!=0)
goto dis_user;
/* wait for wake up form suspend. */
enable_tmr();
usb_error=0;
host_init();
delay(1000);
Bus_enum();
/*
if (usb_error == 1)
goto start;*/
rum=0;
main_loop:
/*********************** For ShengYu AxialPad *********************/
if (product_id[0] == 0x03)
{ if (product_id[1] == 0x00)
{
poll_data(7, data_in);
/* if (usb_error == 1)
goto start; */
if (data_flag != 0)
{
x_data = data_in[3]; /*R_Vr_x*/
y_data = data_in[0]; /*L_Vr_x*/
i_data = data_in[2]; /*R_Vr_y*/
j_data = data_in[1]; /*L_Vr_y*/
if(x_data<64){x_data=64-x_data ; x_data = x_data & 0x7f;x_10x2_flag=1;}
else { x_data= x_data-64;x_10x2_flag=0;}
if(y_data<64){y_data=64-y_data ; y_data = y_data & 0x7f;y_10x2_flag=1;}
else { y_data= y_data-64;y_10x2_flag=0;}
if(i_data<64){i_data=64-i_data ; i_data = i_data & 0x7f;i_10x2_flag=1;}
else { i_data= i_data-64;i_10x2_flag=0;}
if(j_data<64){j_data=64-j_data ; j_data = j_data & 0x7f;j_10x2_flag=1;}
else { j_data= j_data-64;j_10x2_flag=0;}
/*
if(x_data<0){x_data=~x_data +1; x_data = x_data & 0x7f;x_10x2_flag=1;}
else { x_10x2_flag=0;}
if(y_data < 0){y_data =~y_data +1;y_data=y_data & 0x7f; y_10x2_flag=1;}
else { y_10x2_flag=0;}
if(i_data<0){ i_data =~ i_data +1; i_data=i_data & 0x7f;i_10x2_flag=1;}
else { i_10x2_flag=0;}
if(j_data<0){j_data =~j_data +1; j_data=j_data & 0x7f; j_10x2_flag=1;}
else { j_10x2_flag=0;}
*/
Led_D1_8 = data_in[5];/*Button 1-8*/
data_in[4]= data_in[4] & 0x0F;
if(data_in[4]==0x00) Led_D9_16=0x00;
if(data_in[4]==0x01) Led_D9_16=0x02;/*Up */
if(data_in[4]==0x02) Led_D9_16=0x10;/*LU */
if(data_in[4]==0x03) Led_D9_16=0x04;/*Right*/
if(data_in[4]==0x04) Led_D9_16=0x20;/*RD */
if(data_in[4]==0x05) Led_D9_16=0x08;/*Down */
if(data_in[4]==0x06) Led_D9_16=0x40;/*LD*/
if(data_in[4]==0x07) Led_D9_16=0x01;/*Lift */
if(data_in[4]==0x08) Led_D9_16=0x80;/*LU */
Led_D17_24= data_in[6] & 0x0F;/*xxxx Enter/Esc/KL/KR */
if( Led_D1_8==0x03) /*2&1 Key is down*/
{ GoPad_set_motor(4, ShengYu_L_Motor_on);};
if( Led_D1_8==0x0A) /*2&4 Key is down*/
{ GoPad_set_motor(4, ShengYu_R_Motor_on);};
if( Led_D1_8==0x06) /*2&3 Key is down*/
{ GoPad_set_motor(4, GoPad_Motor_off);};
}
}
Dis_all();
}
/************************ I73611A *****************************
if (product_id[0] == 0x1A)
if (product_id[1] == 0x61)
{
poll_data(6, data_in);
if (usb_error == 1)
goto start;
if (data_flag != 0)
{
x_data = data_in[1];
y_data = data_in[2];
i_data = 0x00;
j_data = 0x00;
Led_D1_8 = (data_in[3]>>4) | (data_in[4]<<4);
data_in[3] &= 0x0F;
if(data_in[3]==0x00) Led_D9_16=0x00;
if(data_in[3]==0x01) Led_D9_16=0x02;
if(data_in[3]==0x02) Led_D9_16=0x10;
if(data_in[3]==0x03) Led_D9_16=0x04;
if(data_in[3]==0x04) Led_D9_16=0x20;
if(data_in[3]==0x05) Led_D9_16=0x08;
if(data_in[3]==0x06) Led_D9_16=0x40;
if(data_in[3]==0x07) Led_D9_16=0x01;
if(data_in[3]==0x08) Led_D9_16=0x80;
Led_D17_24= data_in[4]>>4;
if(Led_D1_8 & 0x04)
set_report(4, usb_motor_left);
if(Led_D1_8 & 0x01)
set_report(4, usb_motor_right);
if(Led_D1_8 & 0x02)
set_report(4, usb_motor_on);
if(Led_D1_8 & 0x08)
set_report(4, usb_motor_off);
if(Led_D17_24 & 0x01)
set_report(4, usb_led_on);
if(Led_D17_24 & 0x02)
set_report(4, usb_led_off);
}
}
*/
/**********************************************************/
Dis_all();
goto main_loop;
}
/************** end *******************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -