ps2_keyboard.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include <common/glib.h>
  3. #define PS2_KEYBOARD_INTR_VECTOR 0x21 // 键盘的中断向量号
  4. // 定义键盘循环队列缓冲区大小为100bytes
  5. #define ps2_keyboard_buffer_size 8
  6. #define KEYBOARD_CMD_RESET_BUFFER 1
  7. #define PORT_PS2_KEYBOARD_DATA 0x60
  8. #define PORT_PS2_KEYBOARD_STATUS 0x64
  9. #define PORT_PS2_KEYBOARD_CONTROL 0x64
  10. #define PS2_KEYBOARD_COMMAND_WRITE 0x60 // 向键盘发送配置命令
  11. #define PS2_KEYBOARD_COMMAND_READ 0x20 // 读取键盘的配置值
  12. #define PS2_KEYBOARD_PARAM_INIT 0x47 // 初始化键盘控制器的配置值
  13. // ========= 检测键盘控制器输入/输出缓冲区是否已满
  14. #define PS2_KEYBOARD_FLAG_OUTBUF_FULL 0x01 // 键盘的输出缓冲区已满标志位
  15. #define PS2_KEYBOARD_FLAG_INBUF_FULL 0x02 // 键盘的输入缓冲区已满标志位
  16. // 等待向键盘控制器写入信息完成
  17. #define wait_ps2_keyboard_write() while (io_in8(PORT_PS2_KEYBOARD_STATUS) & PS2_KEYBOARD_FLAG_INBUF_FULL)
  18. // 等待从键盘控制器读取信息完成
  19. #define wait_ps2_keyboard_read() while (io_in8(PORT_PS2_KEYBOARD_STATUS) & PS2_KEYBOARD_FLAG_OUTBUF_FULL)
  20. extern struct vfs_file_operations_t ps2_keyboard_fops;
  21. /**
  22. * @brief 初始化键盘驱动程序的函数
  23. *
  24. */
  25. void ps2_keyboard_init();
  26. /**
  27. * @brief 键盘驱动卸载函数
  28. *
  29. */
  30. void ps2_keyboard_exit();
  31. /**
  32. * @brief 解析键盘扫描码
  33. *
  34. */
  35. void ps2_keyboard_analyze_keycode();
  36. /**
  37. * @brief 从缓冲队列中获取键盘扫描码
  38. * @return 键盘扫描码
  39. * 若缓冲队列为空则返回-1
  40. */
  41. int ps2_keyboard_get_scancode();