?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 // resetuje zarizeni
15 #define ENABLE_DATA_REPORTING 0xF4 // v pripade STREAM modu povoli odesilani dat
16 #define READ_DATA 0xEB // precte data
17 #define STATUS_REQUEST 0xE9 // zjisti aktualni nastaveni
18 #define SET_REMOTE_MODE 0xF0 // mys bude uchovavat data a cekat na zeptani
19 #define SET_STREAM_MODE 0xEA
20 #define SET_RESOLUTION 0xE8
21 #define GET_DEVICE_ID 0xF2
22  
23 #define 1mm 0x00
24 #define 05mm 0x01
25 #define 025mm 0x02
26 #define 0125mm 0x03
27  
28  
29 #define SIGN_X 0b1000
30 #define SIGN_Y 0b10000
31  
32 void ps2send(byte command)
33 {
34 unsigned int8 n;
35 unsigned int8 parity=0;
36  
37 //Request-to-send
38 output_float(DATA);
39 output_low(CLK);
40 delay_us(100);
41 // start bit
42 output_low(DATA);
43 while(input(CLK)); // ceka se na hodiny od mysi (mys zataha za hodiny)
44 // 8 bitu
45 for(n=0; n<8; n++)
46 {
47 while(input(CLK));
48 output_bit(DATA, command & 1);
49 parity += command & 1;
50 command >>= 1;
51 while(!input(CLK));
52 };
53 // parita
54 while(input(CLK));
55 output_bit(DATA, ~parity & 1);
56 while(!input(CLK));
57  
58 // stop bit
59 output_float(DATA);
60 while(input(DATA)); // mys musi sama jeste jednou zatahat za hodiny a data
61 while(input(CLK));
62  
63 // ceka se az nastane klidovy stav
64 while(!input(CLK) || !input(DATA));
65 }
66  
67  
68 int8 read_byte() // dodelat paritu
69 {
70 unsigned int8 bajt;
71 unsigned int8 i;
72 int1 parity=0;
73  
74 // cekani na startbit
75 while(input(CLK) || input(DATA)); // oba signaly musi byt v 0
76 while(!input(CLK)); // ceka se na nabeznou hranu hodin
77  
78 bajt = 0;
79 for(i=0; i<8; i++)
80 {
81 while(input(CLK)); // ceka na nulu hodin
82  
83 bajt >>= 1;
84 bajt |= input(DATA) << 7; // zapise se stav do promene
85 parity^=input(DATA);
86  
87 while(!input(CLK)); // ceka na jednicku hodin
88 };
89 while(input(CLK));
90 parity^=input(DATA);
91 // if (parity)
92 while(!input(CLK)); // ceka na jednicku hodin
93 while(input(CLK));
94 while(!input(CLK)); // ceka na jednicku hodin
95 return (bajt);
96 }
97  
98  
99 void read_standard_byte(signed int8 *x,*y,unsigned int8 *tl1,*tl2,*tl3)
100 {
101 unsigned int8 st,nd,rd;
102  
103 st = read_byte();
104 nd = read_byte();
105 rd = read_byte();
106  
107 if ((st & SIGN_X) == SIGN_X) *x=-nd; else *x=nd;
108 if ((st & SIGN_Y) == SIGN_Y) *y=-rd; else *y=rd;
109  
110 *tl1=st & 1;
111 *tl2=(st >> 1) & 1;
112 *tl3=(st >> 2) & 1;
113 }
114 void ps2break()
115 {
116 output_low(CLK);
117 }
118 void ps2enable()
119 {
120 output_float(CLK);
121 }
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3