Mikaku wrote:Do you know of a document with a functional example of a keyboard reset?
I don't think there's anything wrong with the reset commands you're sending to the
keyboard. The problem is how you're using the
keyboard controller to send those commands and receive the responses. Before every read from or write to port 0x60, you must read port 0x64 to see if the keyboard controller is ready. Bit 0 is set when you can read from port 0x60. Bit 1 is clear when you can write to port 0x60.
For example, sending a byte to the keyboard should look something like this:
Code: Select all
bool send_to_keyboard( uint8_t byte_to_keyboard )
{
while( /* timeout */ )
{
if( !(inport_b( 0x64 ) & 0x02) )
{
outport_b( 0x60, byte_to_keyboard );
return true;
}
}
return false;
}
And receiving:
Code: Select all
bool receive_from_keyboard( uint8_t * byte_from_keyboard )
{
while( /* timeout */ )
{
if( inport_b( 0x64 ) & 0x01 )
{
byte_from_keyboard = inport_b( 0x60 );
return true;
}
}
return false;
}
Note that the timeout should be based on actual time, not a number of loop repetitions.
Your IRQ handler doesn't have this limitation: the IRQ itself is how the keyboard controller indicates that you may read one byte from port 0x60. I would enable IRQs before trying to reset the keyboard so the IRQ handler could deal with receiving all the responses from the keyboard, but you don't have to do it like that.