?? ps2.c
字號:
globle_isr_disable();
relase_ps2_pins();
retval=ps2_send_sbyte(mdata);
relase_ps2_pins();
globle_isr_enable();
return retval;
}
/********************************************************************************/
/* function : ps2_put_hostbyte() */
/* created : hw-chen */
/* descript : PS2發送數據給主機 */
/********************************************************************************/
char ps2_put_hostbyte(unsigned char mdata)
{ char retval;
globle_isr_disable();
relase_ps2_pins();
retval=ps2_put_sbyte(mdata);
relase_ps2_pins();
globle_isr_enable();
return retval;
}
/********************************************************************************/
/* function : ps2_pro_new_command() */
/* created : hw-chen */
/* descript : PS2處理從主機接收到的新命令 */
/********************************************************************************/
char ps2_pro_new_command(char type)
{ switch(type)
{
case PS2_CMD_RST_SCALING:
ps2_rst_scaling();
break;
case PS2_CMD_SET_SCALING_2_1:
ps2_set_scaling();
break;
case PS2_CMD_SET_RESOLUTION:
ps2_set_resolution_ack();
break;
case PS2_CMD_STATUS_REQUEST:
ps2_status_request();
break;
case PS2_CMD_SET_STREAM_MODE:
ps2_set_stream_mode();
break;
case PS2_CMD_READ_DATA:
ps2_packet_mouse_mdata();
break;
case PS2_CMD_RST_WRAP_MODE:
ps2_rst_wrap_mode();
break;
case PS2_CMD_SET_WRAP_MODE:
ps2_set_wrap_mode();
break;
case PS2_CMD_REMOTE_MODE:
ps2_set_remote_mode();
break;
case PS2_CMD_READ_DEV_TYPE:
ps2_read_device_type();
break;
case PS2_CMD_SET_SAMPLE_RATE:
ps2_set_sample_rate_ack();
break;
case PS2_CMD_ENABLE:
break;
case PS2_CMD_DISABLE:
ps2_disable();
break;
case PS2_CMD_DEFAULT:
ps2_set_default_state();
break;
case PS2_CMD_RESEND:
ps2_resend();
break;
case PS2_CMD_RESET:
ps2_reset();
break;
default:
return 0x0;
}
return 0x1;
}
/********************************************************************************/
/* function : ps2_app_resolution() */
/* created : hw-chen */
/* descript : 如果主機設置了分辨率,計算在分辨率下的計數器的值 */
/* 大多數鼠標采用了400CPI,少數羅技高端鼠標采用了800CPI.400CPI就是說 */
/* 當鼠標每移動一英吋就可反饋400個不同的坐標,換句話說 */
/* 也就是采用400CPI的鼠標可以觀察到你手部0.06毫米的微弱移動,就說明 */
/* CPI越大,光電鼠標就越靈敏. */
/* 我們用的ADNS5020有兩種CPI可選,500和1000,初始化成為1000,用作800 */
/* 1 英寸= 2.5400 厘米=25MM,那么1000/25=40個點就是移動1MM時value=40 */
/* 1 英尺= 12 英寸 = 0.3048 米 */
/* 0x0 <===> 1count/mm */
/* 0x1 <===> 2count/mm */
/* 0x2 <===> 4count/mm */
/* 0x3 <===> 8count/mm */
/********************************************************************************/
char ps2_app_resolution(char value)
{ char res;
res = ps2_parameter.resolution;
res = RES_8MM-res;
if(res)
{ value>>=res;
}
return(value);
}
/********************************************************************************/
/* function : ps2_app_scaling() */
/* created : hw-chen */
/* descript : 如果主機啟動了SCALING操作 */
/********************************************************************************/
signed char ps2_app_scaling(char value)
{ if((ps2_parameter.scale==SC_1_1))
{ return(value);
}
if((value==0x2))
{ return 0x1;
}
if((value==-2))
{ return -1;
}
if((value==0x1))
{ return 0x1;
}
if((value==-1))
{ return -1;
}
if((value==0x3)||(value==-3))
{ return(value);
}
if((value==0x4))
{ return 0x6;
}
if((value==-4))
{ return -6;
}
if((value==0x5))
{ return 0x9;
}
if((value==-5))
{ return -9;
}
if((value>=64))
{ return 127;
}
if((value<=-64))
{ return -127;
}
else
{ return(value<<1);
}
}
/********************************************************************************/
/* function : ps2_3D_5D_mdata() */
/* created : hw-chen */
/* descript : 組裝標準的數據報 */
/********************************************************************************/
void ps2_3D_5D_mdata(void)
{ unsigned char * ptr=ps2_xmit.ps2_buffer;
mouse_status.y_count=-mouse_status.y_count;
ptr[0] = (mouse_status.button_byte&0x7)|0x8|((mouse_status.x_count>>0x3)&0x10)|((mouse_status.y_count>>0x2)&0x20);
ptr[1] = mouse_status.x_count;
ptr[2] = mouse_status.y_count;
ps2_xmit.ps2_xmit=ps2_xmit.ps2_length=0x3;//* send the buffer
mouse_status.change_flag=0x0;
mouse_status.x_count=0x0;
mouse_status.y_count=0x0;
mouse_status.z_count=0x0;
}
/********************************************************************************/
/* function : ps2_packet_mouse_mdata() */
/* created : hw-chen */
/* descript : 組裝一個IBM格式的數據包給主機 */
/********************************************************************************/
void ps2_packet_mouse_mdata(void)
{ ps2_3D_5D_mdata();
}
/********************************************************************************/
/* function : ps2_check_zmouse() */
/* created : hw-chen */
/* descript : 要進入滾輪模式,主機應該發送如下的命令序列 */
/* 1.set sample rate 200 */
/* 2.set sample rate 100 或者 200 */
/* 3.set sample rate 80 */
/* 這個函數必須在受到設置采樣率時調用 */
/********************************************************************************/
unsigned char check_wheel_steps=0x0;
void ps2_check_3D_function(char rate)
{ if((check_wheel_steps==0x1)&&(rate==100))
{ check_wheel_steps=0x2; //* 3D <==> 200 100 80
}
else if((check_wheel_steps==0x2)&&(rate==80))
{ ps2_parameter.zmouse=0x1; //* 3D檢查成功
check_wheel_steps=0x0;
}
else
{ check_wheel_steps=0x0;
}
}
void ps2_check_5D_function(char rate)
{ if((check_wheel_steps==0x1)&&(rate==200))
{ check_wheel_steps=0x2; //* 3D <==> 200 200 80
}
else if((check_wheel_steps==0x2)&&(rate==80))
{ ps2_parameter.zmouse=0x2; //* 5D檢查成功
check_wheel_steps=0x0;
}
else
{ check_wheel_steps=0x0;
}
}
void ps2_check_zmouse(char rate)
{ if((rate==200)&&(check_wheel_steps==0x0))
{ check_wheel_steps=0x1; //* 功能檢查開始
return;
}
if((ps2_parameter.zmouse=0x0)) //* 檢查3D功能鼠標
{ ps2_check_3D_function(rate);
}
else if((ps2_parameter.zmouse=0x1))
{ ps2_check_5D_function(rate);
}
else
{ check_wheel_steps=0x0; //* 復位檢查序列
}
}
/********************************************************************************/
/* function : ps2_pro_host_command() */
/* created : hw-chen */
/* descript : 處理主機發送過來的命令 */
/********************************************************************************/
void ps2_pro_host_command(char command)
{ char i;
/****************************************************************************/
/* WRAP模式,一般用于鼠標測試 */
/****************************************************************************/
if((ps2_parameter.wrap))
{ ps2_last_valid_cmd=0x0;
if((command!=PS2_CMD_RESET)&&(command!=PS2_CMD_RST_WRAP_MODE))
{ ps2_put_hostbyte(command); //* simply send what we received
return;
}
}
/****************************************************************************/
/* 根據上一個命令來處理 */
/****************************************************************************/
switch (ps2_last_valid_cmd)
{
case PS2_CMD_SET_SAMPLE_RATE: //* last command byte was set sample rate, so this must be
if((ps2_set_sample_rate(command))==PS2_ACK) //* the rate itself. if the rate is valid,
{ ps2_put_hostbyte(PS2_ACK); //* ack it
ps2_last_valid_cmd=0x0; //* reset ps2_last_valid_cmd
ps2_error_flag=0x0; //* clear the error count
ps2_check_zmouse(command); //* check for z-mouse enabling
return; //* and return
}
break;
case PS2_CMD_SET_RESOLUTION:
if((ps2_set_resolution(command))==PS2_ACK) //* last command was set resolution, so this must be
{ ps2_put_hostbyte(PS2_ACK); //* ack it
ps2_last_valid_cmd=0x0; //* reset ps2_last_valid_cmd
ps2_error_flag=0x0; //* clear the error count
return; //* and return
}
break;
/****************************************************************************/
/* 處理新接收到的數據,如果接收到新數據,放棄所有等待發送的數據 */
/****************************************************************************/
default:
ps2_xmit.ps2_xmit=0x0;
if((command!=PS2_CMD_SET_SAMPLE_RATE)) //if the command is not set sample rate, reset
{ check_wheel_steps=0x0; //the count of consecutive set sample rate commands received.
}
ps2_put_hostbyte(PS2_ACK); //this command is a valid one, so ack it
ps2_last_valid_cmd=command; //save it
ps2_error_flag=0x0;
if(ps2_pro_new_command(command)) //* 如果新命令正確,直接返回,否則出錯統計
{ return;
}
break;
}
ps2_error_flag+=0x1; //* if we get here, the command was not recognized
if((ps2_error_flag>=0x2)) //* 如果多次錯誤,發送PS2_ERROR
{ ps2_put_hostbyte(PS2_ERROR);
ps2_last_valid_cmd = 0x0;
ps2_error_flag = 0x0;
return;
}
else //* 一次錯誤,重新發送
return;
}
}
/********************************************************************************/
/* function : ps2_reset() */
/* created : hw-chen */
/* descript : 復位PS2鼠標 */
/********************************************************************************/
void ps2_reset(void)
{ ps2_set_default_state();
ps2_pro_bat();
}
/********************************************************************************/
/* function : ps2_resend() */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -