Keyboard driver

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
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Keyboard driver

Post by Karlosoft »

My keyboard driver works on my newer pc, but when I try it on my old laptop (It was new in 1996) it doesn't work.

Code: Select all

void keyboard_handler(struct regs *r)
{
    unsigned char scancode;
    scancode = System->inportb(0x60);
    if (scancode & 0x80)
    {

    }
    else
    {
        System->putc(kbdus[scancode]);
    }
}

extern "C" void start(){
       System->irqInstall(1, keyboard_handler);  
       System->print_pass("PS/2 Keyboard driver", "enabled", 0);
       return;
}
What is wrong O.O?
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Keyboard driver

Post by neon »

Hello,

Define "doesn't work". Please describe what the intent of the software is, what it is doing (or not doing) on your machine, and what debugging steps you have already taken.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
DLBuunk
Member
Member
Posts: 39
Joined: Sun May 18, 2008 9:36 am
Location: The Netherlands

Re: Keyboard driver

Post by DLBuunk »

So it is working on a new computer, but fails on an old laptop. This seems like a KBC problem, not an IRQ one, you might want to post the setup part of the keyboard driver. Seeing your code, you haven't taken the KBC out of emulation mode, you might want to look at the contents of the controller command byte and see if you like it's contents. Oh, and if you get nothing at all, it might be that the keyboard is locked.

For more info about keyboard programming, this http://www.win.tue.nl/~aeb/linux/kbd/scancodes.html is a good resource. (of course, it is also listed at the wiki)
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Keyboard driver

Post by Karlosoft »

This piece of code is a driver loaded by the kernel. In the first machine, where it works, it is installed a general irq handler for line 1 which read the code in the keyboard register and than it translate it in ascii. Eventually it displays it on the screen (the function putc works I'm sure).
On the old laptop irq1 never fires...

Perhaps on old machines have I to send some commands to the keyboard before using it?
DLBuunk
Member
Member
Posts: 39
Joined: Sun May 18, 2008 9:36 am
Location: The Netherlands

Re: Keyboard driver

Post by DLBuunk »

Karlosoft wrote: Perhaps on old machines have I to send some commands to the keyboard before using it?
Yes, that is what i think is happening, the state in which the BIOS leaves the keyboard can be anything, and with old laptops such a state can be, hmm, rather, hmm, funny. So, try to find out what the state is in which the laptop-BIOS leaves the keyboard, and think up a good init-sequence.
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: Keyboard driver

Post by Chandra »

You may also want to try sending the Reset signal to the keyboard and see if the keyboard responds with the ACK byte(0xFA).
There are lots of commands from which you can track if the keyboard is responding or not. If the keyboard is not responding, reinitialize the keyboard port/controller and try again.

Good Luck.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Keyboard driver

Post by Karlosoft »

Isn't 0xfe the system reset command? However now it works sometimes -.-... I added the 0xae command to enable the keyboard. On the other computer it always works...
It's not a problem of the irq I'm sure because the timer handler and the serial port handler are working well.
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Keyboard driver

Post by Karlosoft »

It seems to work when I don't leave the keyboard buffer of the bios empty O.O... ok I'm going to take a break, or I'll start speaking in a sort of keyboard scancode language -.-...
Post Reply