Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern void irq_ack(int);
- typedef enum ps2_mouse_commands {
- MOUSE_PORT = 0x60,
- MOUSE_STATUS = 0x64,
- MOUSE_ABIT = 0x02,
- MOUSE_BBIT = 0x01,
- MOUSE_WRITE = 0xD4,
- MOUSE_F_BIT = 0x20,
- MOUSE_V_BIT = 0x08
- } ps2_mouse_command_t;
- typedef enum ps2_mouse_flags {
- MOUSE_LEFT = 1 << 0,
- MOUSE_RIGHT = 1 << 1,
- MOUSE_MIDDLE = 1 << 2,
- MOUSE_ALWAYS_ONE = 1 << 3,
- MOUSE_X_SIGN_BIT = 1 << 4,
- MOUSE_Y_SIGN_BIT = 1 << 5,
- MOUSE_X_OVERFLOW = 1 << 6,
- MOUSE_Y_OVERFLOW = 1 << 7,
- } ps2_mouse_flag_t;
- static void mouse_wait(unsigned char a_type) {
- uint32_t timeout = 100000;
- if (!a_type) {
- while (--timeout) {
- if ((inb(MOUSE_STATUS) & MOUSE_BBIT) == 1) {
- return;
- }
- }
- return;
- } else {
- while (--timeout) {
- if (!((inb(MOUSE_STATUS) & MOUSE_ABIT))) {
- return;
- }
- }
- return;
- }
- }
- static void mouse_write(uint8_t command) {
- mouse_wait(1);
- outb(0x64, 0xD4);
- mouse_wait(1);
- outb(0x60, command);
- }
- static uint8_t mouse_read() {
- mouse_wait(0);
- return inb(0x60);
- }
- void ps2_mouse_irq(void*) {
- kprintf("------------------------------- MOUSE\n");
- uint8_t status = inb(MOUSE_STATUS);
- while (status & MOUSE_BBIT)
- {
- char mouse_in = inb(MOUSE_PORT);
- status = inb(MOUSE_STATUS);
- }
- irq_ack(12);
- }
- extern void irq_set_handler(uint8_t num, void (*handler)(void*));
- void ps2_keyboard_reset() {
- uint8_t tmp = inb(0x61);
- outb(0x61, tmp | 0x80);
- outb(0x61, tmp & 0x7F);
- inb(0x60);
- }
- bool ps2_mouse_init(void) {
- uint8_t _status;
- asm("cli");
- mouse_wait(1);
- outb(MOUSE_STATUS, 0xA8);
- mouse_wait(1);
- outb(MOUSE_STATUS, 0x20);
- mouse_wait(0);
- _status = inb(0x60) | 2;
- mouse_wait(1);
- outb(MOUSE_STATUS, 0x60);
- mouse_wait(1);
- outb(MOUSE_PORT, _status);
- mouse_write(0xF6);
- mouse_read();
- mouse_write(0xF4);
- mouse_read();
- irq_set_handler(12, ps2_mouse_irq);
- //ps2_keyboard_reset();
- asm("sti");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement