Example #1
0
static int ps2ms_do_init( void )
{


    int tries = 10000;
    // Purge buffer
    while( tries-- > 0 && inb( PS2_CTRL_ADDR ) & 0x01 )
        inb( PS2_DATA_ADDR );

    if( tries <= 0 ) goto notfound;

    ps2ms_send_cmd(PS2_CMD_DEV_INIT);

    // hangs
    //ps2ms_send_aux(PS2_CMD_RESET_MOUSE);    ps2ms_aux_wait_ack(); // ignore result

    ps2ms_send_aux(PS2_CMD_ENABLE_MOUSE);
    if( ps2ms_aux_wait_ack() ) goto notfound;

    return 0;

notfound:
    SHOW_ERROR0( 1, "PS/2 mouse not found\n" );
    return ENXIO;

}
Example #2
0
static int ps2ms_do_init( void )
{

    ps2ms_purge_buffer(2);
/*
    int tries = 10000;
    // Purge buffer
    while( tries-- > 0 && inb( PS2_CTRL_ADDR ) & 0x01 )
        inb( PS2_DATA_ADDR );

    if( tries <= 0 ) goto notfound;
*/

    ps2ms_send_cmd(PS2_CMD_DEV_INIT);

    // hangs
    //ps2ms_send_aux(PS2_CMD_RESET_MOUSE);    ps2ms_aux_wait_ack(); // ignore result
#if 0

    ps2ms_send_aux(PS2_CMD_ENABLE_MOUSE);
    if( ps2ms_aux_wait_ack() ) goto notfound;

    // allright, we have some mouse
#else

    SHOW_FLOW0( 2, "PS/2 mouse reset" );
    ps2ms_send_aux( PS2_CMD_RESET_MOUSE );
    ps2ms_purge_buffer(10);

    SHOW_FLOW0( 2, "PS/2 mouse set sample rate" );
    ps2ms_send_aux( 0xF3 ); // set sample rate
    ps2ms_purge_buffer(10);
    //ps2ms_send_aux( 0x0A );
    ps2ms_send_aux( 200 );
    ps2ms_purge_buffer(10);

    ps2ms_send_aux( 0xE6 ); // set scale 2:1
    ps2ms_purge_buffer(10);

    ps2ms_send_aux( 0xE8 ); // set resolution
    ps2ms_purge_buffer(10);
    ps2ms_send_aux( 1 );    // lowest resolution
    ps2ms_purge_buffer(10);

    SHOW_FLOW0( 2, "PS/2 mouse ask ID" );
    ps2ms_send_aux( 0xF2 ); // Ask for ID
    ps2ms_aux_wait_ack();
    unsigned char ps2id = ps2ms_get_data();
    SHOW_FLOW( 0, "PS/2 mouse ID=0x%2X", ps2id );

    ps2ms_purge_buffer(10); // todo make func to wait for ACK for n msec
    ps2ms_send_aux(PS2_CMD_ENABLE_MOUSE);
    if( ps2ms_aux_wait_ack() ) goto notfound;
    //ps2ms_purge_buffer(10); // todo make func to wait for ACK for n msec

#endif
    return 0;

notfound:
    SHOW_ERROR0( 1, "PS/2 mouse not found" );
    return ENXIO;

}