USB mouse doesn't work

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
marcrew
Posts: 7
Joined: Thu May 04, 2023 7:54 pm

USB mouse doesn't work

Post by marcrew »

hello guys. my computer has ps/2 controller and my OS is working well with ps2 keyboard , usb keyboard and ps2 mouse. But it doesnot support usb mouse. Actually when I turn on USB legacy support, the BIOS itself can recognize both usb keyboard and mouse.

how should I do to make the usb mouse working? i dont want to develop usb driver.
Klakap
Member
Member
Posts: 297
Joined: Sat Mar 10, 2018 10:16 am

Re: USB mouse doesn't work

Post by Klakap »

BIOS with legacy support turned on should emulate connected USB keyboard and USB mouse as ps/2 keyboard and ps/2 mouse. So I would suspect that something is wrong with your ps/2 mouse driver. What about showing your code so we can take look on it?
marcrew
Posts: 7
Joined: Thu May 04, 2023 7:54 pm

Re: USB mouse doesn't work

Post by marcrew »

Klakap wrote:BIOS with legacy support turned on should emulate connected USB keyboard and USB mouse as ps/2 keyboard and ps/2 mouse. So I would suspect that something is wrong with your ps/2 mouse driver. What about showing your code so we can take look on it?
thanks Klakap for the reply. Ps/2 mouse is working but usb mouse is not. my code is like below

this it the init part

Code: Select all

#define  wait_KB_write()	while(inb(PORT_KB_STATUS) & KBSTATUS_IBF) 

Code: Select all

  
  wait_KB_write();
  kbd_write_command(0xA8);

  wait_KB_write();
  kbd_write_command(0xD4);  
  wait_KB_write();
  kbd_write_output(0xF4);

  wait_KB_write();
  kbd_write_command(0x60);
  wait_KB_write();
  kbd_write_output(0x47);  
this part is the interrupt handling

Code: Select all

static inline void handle_mouse_event(unsigned char scancode)
{
  if (mouse_reply_expected) {
    if (scancode == AUX_ACK) {
      mouse_reply_expected--;
      printk("mouse ack is %x\n", scancode);
      return;
    }
    else
    {
      printk("ERROR:mouse ack is %x\n", scancode);
      mouse_reply_expected--;
      return;
    }
    mouse_reply_expected = 0;
  }

  if (aux_count) {
    int head = queue->head;
    queue->buf[head] = scancode;
    head = (head + 1) & (AUX_BUF_SIZE-1);
    if (head != queue->tail) {
      queue->head = head;
    }

    /* if the input queue is active, add to it */
    if( driver_input_handler_ps2 ) {
      driver_input_handler_ps2( &scancode, 1 );
    } else {
      /* post this byte to termios */
      //rtems_termios_enqueue_raw_characters( termios_ttyp_paux, (char *)&scancode, 1 );
    }
  }
}

/*
 * This reads the keyboard status port, and does the
 * appropriate action.
 *
 * It requires that we hold the keyboard controller
 * spinlock.
 */
static unsigned char handle_kbd_event(void)
{
  unsigned char status = kbd_read_status();
  unsigned int work = 10000;

  while (status & KBD_STAT_OBF) {
    unsigned char scancode;
    scancode = kbd_read_input();
    if (status & KBD_STAT_MOUSE_OBF) 
    {
      handle_mouse_event(scancode);
    } 
    else 
    {
      
      printk("pc_keyb: %X ", scancode );
    }
    status = kbd_read_status();
    if(!work--) {
      printk("pc_keyb: controller jammed (0x%02X).\n", status);
      break;
    }
  }
  return status;
}

static void ps2_mouse_interrupt(void * unused)
{
  handle_kbd_event();
}
after this is done , I cannot receive any usb mouse data stream.
Klakap
Member
Member
Posts: 297
Joined: Sat Mar 10, 2018 10:16 am

Re: USB mouse doesn't work

Post by Klakap »

Huh. This may somehow work in emulator but on real hardware there are so many things that can go wrong it is no surprise that USB mouse emulated as ps/2 mouse do not work.

Few points:
1) You are not initalizing ps/2 controller at all, you only enable second channel, interrupts and assume everything will go fine.
2) You are not initalizing ps/2 mouse at all, you only send one command to start streaming (also it is not good idea to do this before enabling interrupts). You are not even resetting mouse so it can be in any state and you do not know how many bytes will mouse send in one packet.
3) When you receive IRQ1 you can be sure this byte is from first ps/2 channel and when you receive IRQ12 you can be sure this byte is from second ps/2 channel. You do not need to do any “tests” from which channel is byte.

You should wrote code for initalizing ps/2 controller, then detect if there are some devices on channels, if yes, reset them(command 0xFF), receive their ID(command 0xF2) what will tell you if it is keyboard or mouse(and how many bytes will mouse send in one packet). When you are sure there is some device, you can do some more initalization(like enabling wheel), then start streaming(command 0xF4) and then you can expect to receive data.
Post Reply