-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnadim-notes.txt
50 lines (29 loc) · 2.21 KB
/
nadim-notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Command Structure
1. Command Byte:
The host sends a single byte (8 bits) representing the command. For example, this could be a command to reset the keyboard or set specific LED states.
2. Data Byte(s) (Optional):
Some commands require additional data bytes. These must follow the command byte.
Keyboard Responses
The keyboard responds to commands in the following ways:
1. ACK (Acknowledge):
Sent as 0xFA to confirm the command or data was received correctly.
2. Resend:
Sent as 0xFE to indicate an error in the last received command or data byte. The host should retransmit the last byte.
Scan Code Sets
Different keyboards or systems can use different scan code sets to encode key presses. There are three standard sets:
1. Scan Code Set 1:
Used by older IBM PCs; rarely used today.
2. Scan Code Set 2:
The most commonly used scan code set in modern PS/2 keyboards.
3. Scan Code Set 3:
Primarily used in specialized applications. It is more customizable than the other sets.
Types of Scan Codes :-
There are three types of scan codes, depending on the event and the scan code set used:
1. Make Code:
Sent when a key is pressed. It indicates which key was pressed.
2. Break Code:
Sent when a key is released. It is typically the make code prefixed with 0xF0 in some scan code sets.
3. Extended Code:
Some keys (e.g., arrow keys, function keys) generate an additional prefix byte (0xE0) to indicate an extended key, followed by the make/break code.
The command isn't completed until you've received an ACK for it. For example, if you send a command and the keyboard responds with "0xFE (resend)" then you have to send the command again (possibly limited to 3 retries before you give up and assume the keyboard doesn't support the command you're sending or there's been a hardware failure).
There is no standard for "key codes" - it's something you have to make up or invent for your OS.I personally like the idea of having an 8-bit key code where the highest 3 bits determine which row on the keyboard and the lowest 5 bits determine which column (essentially, the keyboard is treated as a grid of up to 8 rows and up to 32 columns of keys).