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

library

?curdirlinks? - Rev 1

?prevdifflink? - Blame - ?getfile?

////////////////////////////////////////////////////////////////////////////////
// Modul pro komunikaci s PS/2 mysi
//
// #DEFINE  DATA     PIN_B0      // musi byt definovan kanal DATA
// #DEFINE  CLK      PIN_B1      // a taky hodiny CLK
//
////////////////////////////////////////////////////////////////////////////////

#define  PRVNI    1000                 // nastaveni prodlevy pred zacatkem vysilani bajtu
#define  DRUHY    2
#define  TRETI    DRUHY

// prikazy
#define  RESET                   0xFF     // resetuje zarizeni
#define  ENABLE_DATA_REPORTING   0xF4     // v pripade STREAM modu povoli odesilani dat
#define  READ_DATA               0xEB     // precte data
#define  STATUS_REQUEST          0xE9     // zjisti aktualni nastaveni
#define  SET_REMOTE_MODE         0xF0     // mys bude uchovavat data a cekat na zeptani
#define  SET_STREAM_MODE         0xEA
#define  SET_RESOLUTION          0xE8
#define  GET_DEVICE_ID           0xF2

#define  1mm                     0x00
#define  05mm                    0x01
#define  025mm                   0x02
#define  0125mm                  0x03


#define SIGN_X 0b1000
#define SIGN_Y 0b10000

void ps2send(byte command)
{
unsigned int8 n;
unsigned int8 parity=0;

   //Request-to-send
   output_float(DATA);
   output_low(CLK);
   delay_us(100);
   // start bit
   output_low(DATA);
   while(input(CLK));         // ceka se na hodiny od mysi (mys zataha za hodiny)
   // 8 bitu
   for(n=0; n<8; n++)
   {
      while(input(CLK));
      output_bit(DATA, command & 1);
      parity += command & 1;
      command >>= 1;
      while(!input(CLK));
   };
   // parita
   while(input(CLK));
   output_bit(DATA, ~parity & 1);
   while(!input(CLK));

   // stop bit
   output_float(DATA);
   while(input(DATA));        // mys musi sama jeste jednou zatahat za hodiny a data
   while(input(CLK));

   // ceka se az nastane klidovy stav
   while(!input(CLK) || !input(DATA));
}


int8 read_byte()           // dodelat paritu
{
unsigned int8 bajt;
unsigned int8 i;
int1  parity=0;

   // cekani na startbit
   while(input(CLK) || input(DATA)); // oba signaly musi byt v 0
   while(!input(CLK));     // ceka se na nabeznou hranu hodin

   bajt = 0;
   for(i=0; i<8; i++)
   {
      while(input(CLK));   // ceka na nulu hodin

      bajt >>= 1;
      bajt |= input(DATA) << 7; // zapise se stav do promene
      parity^=input(DATA);

      while(!input(CLK));  // ceka na jednicku hodin
   };
   while(input(CLK));
   parity^=input(DATA);
//   if (parity)
   while(!input(CLK));  // ceka na jednicku hodin
   while(input(CLK));
   while(!input(CLK));  // ceka na jednicku hodin
   return (bajt);
}


void read_standard_byte(signed int8 *x,*y,unsigned int8 *tl1,*tl2,*tl3)
{
unsigned int8 st,nd,rd;

   st = read_byte();
   nd = read_byte();
   rd = read_byte();

   if ((st & SIGN_X) == SIGN_X) *x=-nd; else *x=nd;
   if ((st & SIGN_Y) == SIGN_Y) *y=-rd; else *y=rd;

   *tl1=st & 1;
   *tl2=(st >> 1) & 1;
   *tl3=(st >> 2) & 1;
}
void ps2break()
{
   output_low(CLK);
}
void ps2enable()
{
   output_float(CLK);
}
{FILE END}
{FOOTER START}

Powered by WebSVN v2.8.3