unable to change scancode set. pls help

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
hegde1997
Member
Member
Posts: 40
Joined: Mon Jan 30, 2012 7:36 am
Location: Bangalore, India
Contact:

unable to change scancode set. pls help

Post by hegde1997 »

I don't know what is wrong but i am unable to change the scan code set and when i read in to see which scan code is set, i got value 25
pls help.

Code: Select all

#define _KbdCommand 0x64
#define _KbdRW 0x60
#define _KbdLed_cmd 0xED
#define _KbdSc_code_cmd 0xF0
#define _KbdAck 0xFA
#define _KbdResend 0xFE
#define _CapsL_val 4
#define _NumL_val 2
#define _ScrlL_val 1

void init_keyboard()
{
	led_status=0;
	kbd_on=true;
	
	outbyte(' ');
	
	kbdstatus_init();
	set_irq_handler(1,irq1_keyb);
	
	kbd_scancode_set(scancode_set);
	kbd_write(0xf0,_KbdRW);
	outb(0,_KbdRW);
	outbyte(kbd_read(_KbdRW));	
}

Code: Select all

void kbd_io_wait()
{
	uint8 a; 
	do
	{
		a=inb(_KbdCommand);
	}while(a&2);
	
}
char kbd_write(uint8 bytes, uint16 port)
{
	kbd_io_wait();
	outb(port,bytes);
	if(inb(port)==_KbdAck)
	  return 1;
	else if(inb(port)==_KbdResend) //{// try maximum 3 more times
	  return kbd_cmd_resend(port,port,bytes);
	  
	return 0;
}
uint8 kbd_read(uint16 port)
{
	while(!(inb(_KbdCommand)&1)) ;//wait till output buffer is full
	 return inb(port);
}

char kbd_cmd_resend(uint16 inport,uint16 outport,uint8 data)
{
	kbd_io_wait();
	outb(outport,data);// make maximum of 3 tries
	if(inb(inport)==_KbdAck)
	  return 1;
	else if(inb(inport)==_KbdResend)
	 {
		 kbd_io_wait();
		 outb(outport,data);
	 }
	if(inb(inport)==_KbdAck)
	  return 1;
	else if(inb(inport)==_KbdResend)
	 {
		 kbd_io_wait();
		 outb(outport,data);
	 }	
	if(inb(inport)==_KbdAck)
	  return 1;
	return 0;	
}
Walking my way in making my OS
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: unable to change scancode set. pls help

Post by Brendan »

Hi,

Normally, the keyboard uses scancode set 2, and the PS/2 controller converts this into scancode set 1. For example; if you press F5 the keyboard sends the make code 0x03 to the PS/2 controller, and the PS/2 controller converts this into 0x3F, and software (e.g. an OS) would read the value 0x3F from the PS/2 controller.

This translation happens for all data sent from the keyboard to the computer (not just make and break codes). For example, if you ask the keyboard which scancode set it's using and it sends 0x02 back, then the PS/2 controller would convert this into 0x41 (as far as I can tell), and software (e.g. an OS) would read the value 0x41 from the PS/2 controller. Of course different values from the keyboard can be translated into the same value. For example, if your software receives the value 0x41 from the PS/2 controller then the keyboard itself may have sent 0x02 or 0x83, and there's no way to tell what was originally sent.

Your "PS/2 controller driver" should probably disable this translation as part of its initialisation (e.g. before your "PS/2 keyboard driver" is started). To do this you want to read the "PS/2 Controller Configuration Byte", then clear bit 6 and write the result back.

Also note that a lot of keyboards only support scancode set 2, and a lot of keyboards don't support the "get current scan code set" command.


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.
User avatar
hegde1997
Member
Member
Posts: 40
Joined: Mon Jan 30, 2012 7:36 am
Location: Bangalore, India
Contact:

Re: unable to change scancode set. pls help

Post by hegde1997 »

thanks a lot. One more wierd thing is that in qemu i get 156 and in vmware 25 so now i will deal with that disabling the translation and get back.

thank you
Walking my way in making my OS
Post Reply