?? main.c
字號:
//----------------------------------------------------------------------------
// C main line
//----------------------------------------------------------------------------
#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
#include "main.h"
#include "timer.h"
#include "USB_mk.h"
#include "port.h"
#include "int_func.h"
#include "debug.h"
#define PORT0_UNUSED_PINS 0xFF //@@all pins of port0 is unused
#define RED_LED 0x8
#define PORT1_UNUSED_PINS 0x84 // Pins 2,and 7
BOOL shouldSuspend;//@@a flag indicated suspend
BOOL shouldprotect;//@@a flag indicated protect is necessary or not
UINT16 protect_counter;//inorder to send a broke code and clear USB keyboard's first byte to protect the system
APP_TX_PACKET report_packet;
APP_TX_PACKET_KB report_packet_kb;
INT8 get_int1_new;
INT8 reg_int1_new;
BOOL shouldstartms;//@@a flag indicated mouse timer start is necessary or not
INT8 ms_timer;
UINT8 get_ms0;
UINT8 get_ms1;
UINT8 get_ms2;
UINT8 get_ms3;
UINT8 get_ms4;
INT8 get_int0_new;
INT8 reg_int0_new;
BOOL shouldstartkb;//@@a flag indicated keyboard timer start is necessary or not
INT8 kb_timer;
UINT8 get_kb0;
UINT8 get_kb1;
UINT8 get_kb2;
UINT8 get_kb3;
UINT8 get_kb4;
UINT8 get_kb5;
UINT8 get_kb6;
UINT8 get_kb7;
BOOL R_GUI;
BOOL R_ALT;
BOOL R_SHIFT;
BOOL R_CTRL;
BOOL L_GUI;
BOOL L_ALT;
BOOL L_SHIFT;
BOOL L_CTRL;
static void mk_init( void );//local function,can't be got out this file
void mk_report_init( void );
void main()
{
debug_turn_on_led();
M8C_ClearWDT;// Clear Watchdog
shouldSuspend = FALSE;
OSC_CR0 = 0x1B;//24MHZ CPU
M8C_EnableGInt;
M8C_EnableWatchDog;//Enable WDT
MSTIMER_EnableInt();// Enable timer interrupt
mk_init();
int0_initialize();
int1_initialize();
P02CR = 0x30;//0011 0000,INT0 is occur on falling edge
P03CR = 0x30;//0011 0000,INT1 is occur on falling edge
INT_MSK0 = 0x22;//0010 0010,INT0 and INT1 is enabled
debug_turn_off_led();
// Main loop
for ( ;; )
{
// Clear Watchdog
M8C_ClearWDT;
//Execute USB idle routine
usb_idle();//this function transmit USB signals
} // end for (;;)
}
//--------------------------------------------------------------------------
//
// Function: mk_init
//
// Description:
/// This function initializes all components of the mouse and keyboard application.
///
/// Returns:
/// void
//
//--------------------------------------------------------------------------
static void mk_init( void )
{
port_init();
port_drive_off( PORT0_UNUSED_PINS );// Drive all the unused pins to outputs for power savings.
P1DATA &= ~PORT1_UNUSED_PINS;
usb_init();// Initialized the USB UM
timer_init();
mk_report_init();
}
//--------------------------------------------------------------------------
//@@mouse_report_init
//--------------------------------------------------------------------------
void mk_report_init( void )
{
get_int1_new=0x00;
reg_int1_new=0x01;
get_int0_new=0x00;
reg_int0_new=0x01;
ms_timer=0x00;
kb_timer=0x00;
R_GUI = FALSE;
R_ALT = FALSE;
R_SHIFT = FALSE;
R_CTRL = FALSE;
L_GUI = FALSE;
L_ALT = FALSE;
L_SHIFT = FALSE;
L_CTRL = FALSE;
protect_counter=0x0000;
shouldprotect = FALSE;
}
//--------------------------------------------------------------------------
// mouse_get_report
//
/// This function polls the optics, wheel and buttons for potential events to
/// send over the radio. It also builds the packet payload.
//--------------------------------------------------------------------------
BOOL mouse_get_report( void )
{
BOOL mouse_report_valid = FALSE;
UINT8 xsign;
UINT8 ysign;
UINT8 regx_ms0;
UINT8 regy_ms0;
UINT8 check_ms;
get_int1_new = GET_INT1_NEW();
if(get_int1_new==reg_int1_new && get_int1_new!=0x00)
{
shouldstartms=TRUE;
}
else
{
shouldstartms=FALSE;
reg_int1_new=get_int1_new;
ms_timer=0x00;
}
//MOUSE
if(ms_timer==0x0A)
{
get_ms0=INT1_GET_BUTT();
get_ms1=INT1_GET_X();
get_ms2=INT1_GET_Y();
get_ms3=INT1_GET_Z();
// if(check_ms==get_ms4)//check sum end
// {
regx_ms0=get_ms0;
regy_ms0=get_ms0;
report_packet.buttons = get_ms0 & 0x07;//0x07="0000 0111"
xsign=regx_ms0 & 0x10;
if(xsign == 0x10)
{
if((get_ms1==0x01) || (get_ms1==0x02))
{
report_packet.x=0xff;
}
// else if(get_ms1==0x02)
// {
// report_packet.x=0xff;
// }
else
{
get_ms1=get_ms1-1;
get_ms1=get_ms1>>1;
get_ms1=get_ms1|0x80;
// if((get_ms1>=0xf0) && (get_ms1<=0xff))
// {
report_packet.x=get_ms1;
// }
// else
// {
// report_packet.x=0xf0;
// }
}
}
else// xsign!=0x10
{ //clear the high bit start
get_ms1 = get_ms1 >>1;//cut the first bit
get_ms1 = get_ms1 <<1;//
get_ms1 = get_ms1 >>1;//cut the last bit
//clear the high bit end
// if((get_ms1>=0x00) && (get_ms1<=0x1f))
// {
report_packet.x=get_ms1;
// }
// else
// {
// report_packet.x=0x1f;
// }
}// xsign
ysign=regy_ms0 & 0x20;
if(ysign != 0x20)
{
if(get_ms2==0x00)
{
report_packet.y=get_ms2;
}
else
{
get_ms2=get_ms2-1;
get_ms2=~get_ms2;
get_ms2=get_ms2>>1;
get_ms2=get_ms2 | 0x80;
// if((get_ms2>=0xf0) && (get_ms2<=0xff))
// {
report_packet.y=get_ms2;
// }
// else
// {
// report_packet.y=0xf0;
// }
}
}
else //ysign == 0x20
{//clear the high bit start
if((get_ms2==0xff) || (get_ms2==0xfe))
{
report_packet.y=0x01;
}
else
{
get_ms2 = get_ms2 >>1;//cut the first bit
get_ms2 = get_ms2 <<1;//
get_ms2=~get_ms2;
get_ms2 = get_ms2 >>1;//cut the last bit
//clear the high bit end
// if((get_ms2>=0x01) && (get_ms2<=0x0f))
// {
report_packet.y=get_ms2;
// }
// else
// {
// report_packet.y=0x0f;
// }
}
}// ysign
switch(get_ms3)
{
case 0x00: report_packet.z =0x00;break;
case 0x01: report_packet.z =0xff;break;
case 0x02: report_packet.z =0xfe;break;
case 0x03: report_packet.z =0xfd;break;
case 0x04: report_packet.z =0xfc;break;
case 0x05: report_packet.z =0xfb;break;
case 0x06: report_packet.z =0xfa;break;
case 0x07: report_packet.z =0xf9;break;
case 0xff: report_packet.z =0x01;break;
case 0xfe: report_packet.z =0x02;break;
case 0xfd: report_packet.z =0x03;break;
case 0xfc: report_packet.z =0x04;break;
case 0xfb: report_packet.z =0x05;break;
case 0xfa: report_packet.z =0x06;break;
case 0xf9: report_packet.z =0x07;break;
case 0xf8: report_packet.z =0x08;break;
default: report_packet.z = 0x00;
}
// report_packet.z=0x00;
mouse_report_valid = TRUE;
SET_INT1_NEW();
// }
// else //check_ms error!!
// {
// mouse_report_valid = FALSE;
// SPIS_SET_MOUSE_NEW();
// }
}
else // nothing receive!!
{
report_packet.buttons = 0x00;
report_packet.x = 0x00;
report_packet.y = 0x00;
report_packet.z = 0x00;
}
return ( mouse_report_valid );
}
//MOUSE
BOOL kb_get_report( void )
{
BOOL kb_report_valid = FALSE;
UINT8 form_kb0=0x00;
get_int0_new = GET_INT0_NEW();
if(get_int0_new==reg_int0_new && get_int0_new!=0x00)
{
shouldstartkb=TRUE;
}
else
{
shouldstartkb=FALSE;
reg_int0_new=get_int0_new;
kb_timer=0x00;
}
if(kb_timer==0x0A)
// KEYBOARD
// if(get_kb_new==0x01)
{
//debug_turn_on_led();
protect_counter=0x0000;
shouldprotect = TRUE;
//debug_glimpse();//just for debug!!!!
// decide which code should be send to pc start!
get_kb0=INT0_GET_DATA_KB_00();
get_kb1=INT0_GET_DATA_KB_01();
get_kb2=INT0_GET_DATA_KB_02();
get_kb3=INT0_GET_DATA_KB_03();
get_kb4=INT0_GET_DATA_KB_04();
get_kb5=INT0_GET_DATA_KB_05();
get_kb6=INT0_GET_DATA_KB_06();
get_kb7=INT0_GET_DATA_KB_07();
//initial value
report_packet_kb.kb0 = 0x00;
report_packet_kb.kb1 = 0x00;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -