PS/2 I/O

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
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

PS/2 I/O

Post by Roman »

I am currently implementing PS/2 support for my OS. What is wrong with this code? getCurrentScanCodeSet() always returns ACKs (0xFA). sendByteToPort() and receiveByteFromPort() doesn't cause the problem. PS2DataPort = 0x60.

Code: Select all

uint8_t getCurrentScanCodeSet()
{
        sendByteToPort(PS2DataPort, 0xF0);
        sendByteToPort(PS2DataPort, 0x00);

        uint8_t receivedByteFromPS2DataPort = receiveByteFromPort(PS2DataPort);

        printf("Received 0x%x from 0x60.\n", receivedByteFromPS2DataPort);
        if(receivedByteFromPS2DataPort == 0xFE)
        {
                printf("RESEND: aborting...\n");
                return 4;
        }

        receivedByteFromPS2DataPort = receiveByteFromPort(PS2DataPort);

        printf("Received 0x%x from 0x60.\n", receivedByteFromPS2DataPort);

        return receivedByteFromPS2DataPort;
}
PS2Test() returns true. (seems like it works correctly)

Code: Select all

bool PS2Test()
{
        sendByteToPort(PS2DataPort, 0xEE);

        uint8_t receivedByteFromPS2DataPort = receiveByteFromPort(PS2DataPort);

        if(receivedByteFromPS2DataPort == 0xEE) return true;
        else return false;
}
Where should I send PS/2 commands and receive answers?
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: PS/2 I/O

Post by Nable »

I think that you should read this article: http://wiki.osdev.org/%228042%22_PS/2_Controller , it's about the whole 8042 controller. After you know how to work with controller, then you can add code for specific devices that can be connected to it.

Shorter answer: bytes sent to 0x60 port don't go directly to PS/2 keyboard, they go to 8042 controller, he interprets them and if you give him right commands, then he'll send right bytes to keyboard/mouse.
Post Reply