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