admin管理员组

文章数量:1278789

I'm developing an OS and encountering an issue with my PS/2 keyboard driver: despite attempting to set the keyboard to scancode set 2, it continues to send scancode set 1 codes.

Below is the function used to set the scancode set:

static void set_default_scancode_set(void) {
    uint8_t resp;
    int i = 0;

    do {
        if (i++ == MAX_RETRY_COUNT) {
            stop();
        }
        outb(PS2_KEYBOARD_DATA, COMMAND_SET_SCANCODE_SET);
        io_wait();
        resp = inb(PS2_KEYBOARD_DATA);
    } while (resp == RESP_RESEND);

    if (resp != RESP_ACK) {
        stop();
    }

    i = 0;
    do {
        if (i++ == MAX_RETRY_COUNT) {
            stop();
        }
        outb(PS2_KEYBOARD_DATA, DEFAULT_SCANCODE_SET);
        io_wait();
        resp = inb(PS2_KEYBOARD_DATA);
    } while (resp == RESP_RESEND);
    if (resp != RESP_ACK) {
        stop();
    }
}

The keyboard is initialized with the following function:

void init_keyboard(void) {
    set_default_scancode_set();
    enable_scanning();
    install_irq_driver(1, ps2_keyboard_callback);
}

Additional Information

  • DEFAULT_SCANCODE_SET is defined as 2.
  • Other constants used (COMMAND_SET_SCANCODE_SET, PS2_KEYBOARD_DATA, etc.) are correctly defined.
  • The keyboard continues to send scancode set 1 codes.

A complete example can be found in the following GitHub repository: GitHub Repo

Edit

This issue was fixed by setting the PS/2 controller command byte (disabling the scancode translation feature).

本文标签: cKeyboard Driver Not Switching to Scancode Set 2 (custom OS)Stack Overflow