root / proj / libs / kbc / include / kbc.h @ 351
History | View | Annotate | Download (4.19 KB)
1 | 334 | up20180642 | #ifndef KBC_H_INCLUDED
|
---|---|---|---|
2 | #define KBC_H_INCLUDED
|
||
3 | |||
4 | 145 | up20180655 | /**
|
5 | 334 | up20180642 | * @defgroup kbc kbc
|
6 | 351 | up20180642 | * @ingroup libs
|
7 | 334 | up20180642 | * @brief KBC module.
|
8 | *
|
||
9 | * @{
|
||
10 | 145 | up20180655 | */
|
11 | |||
12 | 257 | up20180642 | /* KBC IRQ Line */
|
13 | 334 | up20180642 | /** @brief KBC Controller IRQ Line */
|
14 | #define KBC_IRQ 1 |
||
15 | /** @brief Mouse IRQ Line */
|
||
16 | #define MOUSE_IRQ 12 |
||
17 | 257 | up20180642 | |
18 | /* Delay for KBC */
|
||
19 | 334 | up20180642 | /** @brief KBC Response Delay */
|
20 | #define DELAY 20000 |
||
21 | /** @brief Number of tries to issue command before timeout */
|
||
22 | #define KBC_NUM_TRIES 20 |
||
23 | 257 | up20180642 | |
24 | /* I/O Ports Addresses */
|
||
25 | 334 | up20180642 | /** @brief Address to send commands to KBC */
|
26 | #define KBC_CMD 0x64 |
||
27 | /** @brief Address to write KBC Command Arguments */
|
||
28 | #define KBC_CMD_ARG 0x60 |
||
29 | /** @brief KBC Status Register address */
|
||
30 | #define STATUS_REG 0x64 |
||
31 | /** @brief Address of Output Buffer of KBC */
|
||
32 | #define OUTPUT_BUF 0x60 |
||
33 | 257 | up20180642 | |
34 | /* KBC Commands */
|
||
35 | 334 | up20180642 | /** @brief Read KBC Command Byte */
|
36 | #define READ_KBC_CMD 0x20 |
||
37 | /** @brief Write KBC Command Byte */
|
||
38 | #define WRITE_KBC_CMD 0x60 |
||
39 | /** @brief KBC Diagnostic Tests */
|
||
40 | #define KBC_SELF_TEST 0xAA |
||
41 | /** @brief Tests Keyboard Clock and Data lines */
|
||
42 | #define KBC_INT_TEST 0xAB |
||
43 | /** @brief Disable KBC Interface */
|
||
44 | #define KBC_INT_DISABLE 0xAD |
||
45 | /** @brief Enable KBC Interface */
|
||
46 | #define KBC_INT_ENABLE 0xAE |
||
47 | /** @brief Disable Mouse */
|
||
48 | #define MOUSE_DISABLE 0xA7 |
||
49 | /** @brief Enable Mouse */
|
||
50 | #define MOUSE_ENABLE 0xA8 |
||
51 | /** @brief Tests Mouse data line */
|
||
52 | #define MOUSE_INT_TEST 0xA9 |
||
53 | /** @brief Write a byte directly to the mouse */
|
||
54 | #define MOUSE_WRITE_B 0xD4 |
||
55 | 257 | up20180642 | |
56 | /* Status Byte Masking */
|
||
57 | 334 | up20180642 | /** @brief Output Buffer State */
|
58 | #define OUT_BUF_FUL BIT(0) |
||
59 | /** @brief Input Buffer State */
|
||
60 | #define IN_BUF_FULL BIT(1) |
||
61 | /** @brief System Flag */
|
||
62 | #define SYS_FLAG BIT(2) |
||
63 | /** @brief Identifier of type of byte in input buffer */
|
||
64 | #define DATA_CMD_WRITE BIT(3) |
||
65 | /** @brief Keyboard inihibited */
|
||
66 | #define INH_FLAG BIT(4) |
||
67 | /** @brief Mouse Data */
|
||
68 | #define AUX_MOUSE BIT(5) |
||
69 | /** @brief Time Out Error - Invalid Data */
|
||
70 | #define TIME_OUT_REC BIT(6) |
||
71 | /** @brief Parity Error - Invalid Data */
|
||
72 | #define PARITY_ERROR BIT(7) |
||
73 | 257 | up20180642 | |
74 | /* Scancode Constants */
|
||
75 | 334 | up20180642 | /** @brief ESC Break Code */
|
76 | #define ESC_BREAK_CODE 0x81 |
||
77 | /** @brief First byte of a two byte Scancode */
|
||
78 | #define TWO_BYTE_CODE 0xE0 |
||
79 | /** @brief Bit to distinguish between Make code and Break code */
|
||
80 | #define BREAK_CODE_BIT BIT(7) |
||
81 | 257 | up20180642 | |
82 | /* Command byte masks */
|
||
83 | 334 | up20180642 | /** @brief Enable Keyboard Interrupts */
|
84 | #define INT_KBD BIT(0) |
||
85 | /** @brief Enable Mouse Interrupts */
|
||
86 | #define INT_MOU BIT(1) |
||
87 | /** @brief Disable Keyboard */
|
||
88 | #define DIS_KBD BIT(4) |
||
89 | /** @brief Disable Mouse */
|
||
90 | #define DIS_MOU BIT(5) |
||
91 | 257 | up20180642 | |
92 | 145 | up20180655 | /**
|
93 | * @brief High-level function that reads the command byte of the KBC
|
||
94 | * @param cmd Pointer to variable where command byte read from KBC will be stored
|
||
95 | * @return 0 if operation was successful, 1 otherwise
|
||
96 | */
|
||
97 | int (kbc_read_cmd)(uint8_t *cmd);
|
||
98 | |||
99 | /**
|
||
100 | * @brief High-level function that changes the command byte of the KBC
|
||
101 | * @param cmd New value for command byte of KBC
|
||
102 | * @return 0 if operation was successful, 1 otherwise
|
||
103 | */
|
||
104 | int (kbc_change_cmd)(uint8_t cmd);
|
||
105 | |||
106 | /**
|
||
107 | * @brief High-level function that restores KBC to normal state
|
||
108 | 334 | up20180642 | *
|
109 | 145 | up20180655 | * High-level function that restores KBC to normal state, because lcf_start
|
110 | * changes the command byte of KBC. If this function is not used, there is a
|
||
111 | * chance that the keyboard and keyboard interrupts remain disabled.
|
||
112 | * @return 0 if operation was successful, 1 otherwise
|
||
113 | */
|
||
114 | int (kbc_restore_keyboard)();
|
||
115 | |||
116 | /**
|
||
117 | * @brief Low-level function to issue a command to keyboard
|
||
118 | * @param cmd command to be issued
|
||
119 | * @return 0 if operation was successful, 1 otherwise
|
||
120 | */
|
||
121 | int (kbc_issue_cmd)(uint8_t cmd);
|
||
122 | |||
123 | /**
|
||
124 | * @brief Low-level function to issue an argument of a command
|
||
125 | 321 | up20180642 | * @param arg argument to be issued
|
126 | 145 | up20180655 | * @return 0 if operation was successful, 1 otherwise
|
127 | */
|
||
128 | int (kbc_issue_arg)(uint8_t arg);
|
||
129 | |||
130 | /**
|
||
131 | * @brief Low-level function for reading byte from keyboard
|
||
132 | 334 | up20180642 | *
|
133 | 145 | up20180655 | * Low-level function for reading byte from keyboard. Waits until output buffer
|
134 | * is full
|
||
135 | 321 | up20180642 | * @param byte Pointer to variable where byte read from keyboard will be stored
|
136 | 145 | up20180655 | * @return 0 if operation was successful, 1 otherwise
|
137 | */
|
||
138 | int (kbc_read_byte)(uint8_t *byte);
|
||
139 | |||
140 | 334 | up20180642 | /**
|
141 | * @}
|
||
142 | */
|
||
143 | |||
144 | 145 | up20180655 | #endif //KBC_H_INCLUDED |