?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 1

Line No. Rev Author Line
1 1 kaklik ////////////////////////////////////////////////////////////////////////////////
2 // Modul pro komunikaci s PS/2 mysi
3 //
4 // #DEFINE DATA PIN_B0 // musi byt definovan kanal DATA
5 // #DEFINE CLK PIN_B1 // a taky hodiny CLK
6 //
7 ////////////////////////////////////////////////////////////////////////////////
8  
9 #define PRVNI 1000 // nastaveni prodlevy pred zacatkem vysilani bajtu
10 #define DRUHY 2
11 #define TRETI DRUHY
12  
13 // prikazy
14 #define RESET 0xFF
15 #define ENABLE_DATA_REPORTING 0xF4
16 #define READ_DATA 0xEB
17 #define STATUS_REQUEST 0xE9
18 #define SET_REMOTE_MODE 0xF0
19 #define SET_STREAM_MODE 0xEA
20 #define GET_DEVICE_ID 0xF2
21  
22  
23 #define SIGN_X 0b1000
24 #define SIGN_Y 0b10000
25  
26 void send(byte command)
27 {
28 unsigned int8 n;
29 unsigned int8 parity=0;
30  
31 //Request-to-send
32 output_float(DATA);
33 output_low(CLK);
34 delay_us(100);
35 // start bit
36 output_low(DATA);
37 while(input(CLK)); // ceka se na hodiny od mysi (mys zataha za hodiny)
38 // 8 bitu
39 for(n=0; n<8; n++)
40 {
41 while(input(CLK));
42 output_bit(DATA, command & 1);
43 parity += command & 1;
44 command >>= 1;
45 while(!input(CLK));
46 };
47 // parita
48 while(input(CLK));
49 output_bit(DATA, ~parity & 1);
50 while(!input(CLK));
51  
52 // stop bit
53 output_float(DATA);
54 while(input(DATA)); // mys musi sama jeste jednou zatahat za hodiny a data
55 while(input(CLK));
56  
57 // ceka se az nastane klidovy stav
58 while(!input(CLK) || !input(DATA));
59 }
60  
61  
62 int8 read_byte() // dodelat paritu
63 {
64 unsigned int8 bajt;
65 unsigned int8 i;
66 int1 parity=0;
67  
68 // cekani na startbit
69 while(input(CLK) || input(DATA)); // oba signaly musi byt v 0
70 while(!input(CLK)); // ceka se na nabeznou hranu hodin
71  
72 bajt = 0;
73 for(i=0; i<8; i++)
74 {
75 while(input(CLK)); // ceka na nulu hodin
76  
77 bajt >>= 1;
78 bajt |= input(DATA) << 7; // zapise se stav do promene
79 parity^=input(DATA);
80  
81 while(!input(CLK)); // ceka na jednicku hodin
82 };
83 while(input(CLK));
84 parity^=input(DATA);
85 // if (parity)
86 while(!input(CLK)); // ceka na jednicku hodin
87 while(input(CLK));
88 while(!input(CLK)); // ceka na jednicku hodin
89 return (bajt);
90 }
91  
92  
93 void read_standard_byte(signed int8 *x,*y,unsigned int8 *tl1,*tl2,*tl3)
94 {
95 unsigned int8 st,nd,rd;
96  
97 st = read_byte();
98 nd = read_byte();
99 rd = read_byte();
100  
101 if ((st & SIGN_X) == SIGN_X) *x=-nd; else *x=nd;
102 if ((st & SIGN_Y) == SIGN_Y) *y=-rd; else *y=rd;
103  
104 *tl1=st & 1;
105 *tl2=(st >> 1) & 1;
106 *tl3=(st >> 2) & 1;
107 }
108 void ps2break()
109 {
110 output_low(CLK);
111 }
112 void ps2enable()
113 {
114 output_float(CLK);
115 }
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3