Page 1 of 1

Another keybord question :)

Posted: Sun Aug 26, 2007 4:40 am
by Iniclub
My ISR and interupts work fine , but I have a problem in the keybord driver .
when I want to detect that a key is released it dosn't work , this is my code :

Code: Select all

 char charTable[]={..........All the keybord keys......}
 char ShiftcharTable[]={..... All the keybord keys +shift.....}
 char printable[]={.... ALL the non printable keys.......}
  void KbHandler(void)
{
	char key;
	unsigned char cmd; 
	char ascii;
	key =inportb(0x60);//read the pressed key

	if(key<sizeof(charTable))//if down
	{
	  //if shift 
	if((key==LSHIFT)|| (key==RSHIFT)) up=1;
	else
	{  if(up)ascii=ShiftcharTable[key];
	   else ascii=charTable[key];
                   //On verifie que c'est un caractere imprimable
	   int i=1,j;
	   for(j=0;j<sizeof(non_printable);j++)
	   if(ascii==non_printable[j]){
	       i=0;
	       break;
	    };

	  if(i)
	  {  
	     add(ascii); //On la met dans le buffer 
	   }
	}
	}
	[b]else
	{
		if(key>=0x80)
		{
			if((key==(RSHIFT+0x80))||(key==(LSHIFT+0x80))) up=0;
		}
	}[/b]	

	cmd=inportb(0x61);
	outportb(0x61,cmd | 0x80);  //disable the keybord
	outportb(0x61,cmd); //
	outportb(0xA0,0x20);//EOI to the slave 
	outportb(0x20,0x20);//EOI to the master
};
the problem here is that the sequence in blod it's not accesd , when a key is released? If some one knows why ,please help.

Posted: Mon Aug 27, 2007 7:26 pm
by frank
What does this do exactly? Have you tried it without it?

Code: Select all

outportb(0x61,cmd | 0x80);  //disable the keybord
   outportb(0x61,cmd); // 
Also maybe the first if should be

Code: Select all

if(!(key & 0x80)) //if down 

Posted: Thu Aug 30, 2007 3:17 am
by Iniclub
the :

Code: Select all

outportb(0x61,cmd | 0x80);  //disable the keybord  
if to disable the keyboard (set bit 3 to 1)
and

Code: Select all

outportb(Ox61,cmd)
is to enable the keyboard with the previous state

for the second sugestion I'll try it, I think that it's a problem of compilation because when I gebug the condition i not evaluated in the first if this is why I used "sizeof", to make a call and force the compilation. I should compile in another distribution. (I am using Damn vunerable Linux)

Posted: Fri Aug 31, 2007 10:08 am
by lode
What is the point of disabling the keyboard and then re-enabling it right away?

Posted: Fri Aug 31, 2007 7:55 pm
by frank
I think that because you are reseting the keyboard each time you are making the keyboard controller "forget" that the key was pressed. If the key wasn't pressed how can it be released?

Posted: Sat Sep 01, 2007 11:25 am
by Iniclub
I think that because you are reseting the keyboard each time you are making the keyboard controller "forget" that the key was pressed. If the key wasn't pressed how can it be released?
I don't think so, because it's an electronic process when a key is released it hase its own scan code.

Well , I have tryed to print a message a message when a key is released and it works .
So the problem is in the test :

Code: Select all

if((key==(RSHIFT+0x80))||(key==(LSHIFT+0x80))) up=0; 
.

Posted: Wed Sep 05, 2007 2:21 am
by bewing
Lode wrote:What is the point of disabling the keyboard and then re-enabling it right away?
On some hardware (old obsolete hardware?) it is the only way to "ack" a scancode. If you do not do it, you will get the same scancode repeated forever, every time you read the keyboard.