OSDev.org

The Place to Start for Operating System Developers
It is currently Tue May 14, 2024 11:50 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: USB mouse doesn't work
PostPosted: Tue Oct 24, 2023 2:18 am 
Offline

Joined: Thu May 04, 2023 7:54 pm
Posts: 7
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.


Top
 Profile  
 
 Post subject: Re: USB mouse doesn't work
PostPosted: Tue Oct 24, 2023 3:59 am 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 296
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?

_________________
https://github.com/VendelinSlezak/BleskOS


Top
 Profile  
 
 Post subject: Re: USB mouse doesn't work
PostPosted: Wed Oct 25, 2023 12:08 am 
Offline

Joined: Thu May 04, 2023 7:54 pm
Posts: 7
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:
#define  wait_KB_write()   while(inb(PORT_KB_STATUS) & KBSTATUS_IBF)

Code:
 
  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:
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.


Top
 Profile  
 
 Post subject: Re: USB mouse doesn't work
PostPosted: Wed Oct 25, 2023 1:57 am 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 296
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.

_________________
https://github.com/VendelinSlezak/BleskOS


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 21 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group