Another keybord question :)

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
Iniclub
Posts: 8
Joined: Sun Jul 15, 2007 3:05 am

Another keybord question :)

Post 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.
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post 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 
Iniclub
Posts: 8
Joined: Sun Jul 15, 2007 3:05 am

Post 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)
User avatar
lode
Posts: 15
Joined: Tue Oct 17, 2006 6:28 pm
Location: Oulu, Finland

Post by lode »

What is the point of disabling the keyboard and then re-enabling it right away?
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post 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?
Iniclub
Posts: 8
Joined: Sun Jul 15, 2007 3:05 am

Post 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; 
.
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post 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.
Post Reply