Here is my function to write a one-byte command (with no required data) to the keyboard.
Code: Select all
//Sends a command byte to the keyboard.
kbd_response_t send_command_byte(uint8_t cmd){
int i = 0;
kbd_response_t toreturn = {true, RESEND};
do{
bool waserror = send_byte_to_kbd(cmd);
received_interrupt = false;
//No error when sending the byte? Then check for the response
if(!waserror){
//Loop until out keyboard interrupt says we received a response
while(!received_interrupt);
uint8_t response = inb(PS2_DATA_REG);
//If we didn't get asked for a resend, then it was sent successfully
if(response != RESEND){
toreturn.send_error = false;
toreturn.response_code = response;
return toreturn;
}
}
}
while(i < MAX_RESEND_ATTEMPTS);
//Return a keyboard response saying we encountered an error
return toreturn;
}
Code: Select all
void handle_keyboard_interrupt(){
if(!initialized){
received_interrupt = true;
return;
}
//Read the scan code
}
Obviously then, the problem is the way I wait for the interrupt to occur. I suppose my question is: What's the best way to wait for the interrupt? Should I just find some way to slow down the loop, or is it better practice to wait for the interrupt in a different way?