PS2 mouse and keyboard : bad cohabitation

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
SamyPesse
Posts: 17
Joined: Mon Apr 13, 2009 2:56 pm
Location: France

PS2 mouse and keyboard : bad cohabitation

Post by SamyPesse »

Hello, i have made a driver for the ps2 mouse and it's works good but when i test with the keyboard, one time, the keyboard doesnt works and the mouse yes, but one other time, the keyboard works and the mouse not. I thinks the problems is the ps2 controllers, what i need to have a good cohabitation ?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: PS2 mouse and keyboard : bad cohabitation

Post by Combuster »

You can't separate the PS/2 mouse and keyboard code into two drivers. They share the same controller and control ports and need a common part to prevent them from influencing each other.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
SamyPesse
Posts: 17
Joined: Mon Apr 13, 2009 2:56 pm
Location: France

Re: PS2 mouse and keyboard : bad cohabitation

Post by SamyPesse »

How works this common part to prevent them from influencing each other ? because the ps2 mouse and the keyboard use different IRQ,
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: PS2 mouse and keyboard : bad cohabitation

Post by Brendan »

Hi,
Combuster wrote:You can't separate the PS/2 mouse and keyboard code into two drivers. They share the same controller and control ports and need a common part to prevent them from influencing each other.
True, but you can separate it into 3 drivers: one for the PS/2 controller, and one for each device connected to the PS/2 controller. It's not even that hard - all you do is define some sort of interface that allows the keyboard driver and mouse driver to talk to the PS/2 controller's driver.

Of course once you've designed it as 3 separate drivers, you don't necessarily need to implement it as 3 separate drivers. The important thing is having some sort of abstraction between the keyboard/mouse stuff and the controller stuff...


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
mybura
Posts: 18
Joined: Wed Sep 02, 2009 12:59 am

Re: PS2 mouse and keyboard : bad cohabitation

Post by mybura »

The common part is that the KBC will queue data and mix the mouse and keyboard data. So if your Keyboard driver is not aware of the mouse driver, it will throw away mouse data and likewise for the mouse driver.

You read and acknowledge data from the controller using the same ports. Have a look at the attached files. You will see that eventhough two IRQ's are used, reading the data is done in the same way and a decission is made at the time of reading data as to if it is for the Keyboard or the mouse.
Attachments

[The extension pas has been deactivated and can no longer be displayed.]

[The extension pas has been deactivated and can no longer be displayed.]

jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: PS2 mouse and keyboard : bad cohabitation

Post by jal »

mybura wrote:You read and acknowledge data from the controller using the same ports. Have a look at the attached files. You will see that eventhough two IRQ's are used, reading the data is done in the same way and a decission is made at the time of reading data as to if it is for the Keyboard or the mouse.
You make the classic mistake of reading more than one byte when receiving an IRQ. You should not do this: read one byte at each IRQ, and you'll be fine.


JAL
mybura
Posts: 18
Joined: Wed Sep 02, 2009 12:59 am

Re: PS2 mouse and keyboard : bad cohabitation

Post by mybura »

Might explain why on some hardware it works and other it doesn't. I've found that on some ps2 emulated USB hardware the driver would hang on data from the mouse and keyboard at the same time.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: PS2 mouse and keyboard : bad cohabitation

Post by jal »

mybura wrote:Might explain why on some hardware it works and other it doesn't. I've found that on some ps2 emulated USB hardware the driver would hang on data from the mouse and keyboard at the same time.
Could very well be. The hardware expects one byte to be read, then the IRQ to be acknowledged. There's no telling how it reacts when you read a sequence of bytes, then acknowledge a single IRQ. Could be that the other IRQs are still pending, and when you start reading, there's no data (which is not surprising, since you read it all).


JAL
Post Reply