Skip to content

Commit a606960

Browse files
committed
Update the hid_get_event docs to explain what's going on.
1 parent 6905718 commit a606960

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/main.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,9 +1081,31 @@ pub extern "C" fn memory_get_region(region: u8) -> common::Option<common::Memory
10811081
}
10821082
}
10831083

1084-
/// Get the next available HID event, if any.
1084+
/// This function doesn't block. It will return `Ok(None)` if there is no event
1085+
/// ready.
10851086
///
1086-
/// This function doesn't block. It will return `Ok(None)` if there is no event ready.
1087+
/// The Pico BIOS gets PS/2 scan-codes (in PS/2 Scan Code Set 2 format) from the
1088+
/// BMC. The BMC receives them from the PS/2 keyboard (as 11-bit words with
1089+
/// stop, stop and parity bits) and buffers them (as raw 8-bit values with the
1090+
/// start/stop/parity bits removed). These scan-codes are converted into
1091+
/// human-readable labels here in this function. The labels are applied as if
1092+
/// you had a US-English keyboard. If you do not have a US-English keyboard, the
1093+
/// labels, will be incorrect, but that doesn't matter. It is the OS's job to
1094+
/// convert those labels (along with the key up or key down event) into Unicode
1095+
/// characters, which is where the country-specific keyboard mapping comes in.
1096+
///
1097+
/// This is a similar model used to that in the IBM PC. Your PC's BIOS cares not
1098+
/// for which country you are; that was MS-DOS's job.
1099+
///
1100+
/// The reason we don't just pass keyboard scan-codes in Scan Code Set 2 (the
1101+
/// power-up default for almost every IBM PS/2 compatible keyboard) is that in
1102+
/// the future your BIOS key get the keyboard input from another source. If it
1103+
/// came from a USB Keyboard, you would have USB HID Scan Codes. If it came from
1104+
/// an SDL2 window under Linux/Windows/macOS, you would have SDL2 specific key
1105+
/// codes. So the BIOS must convert this wide and varied set of HID inputs into
1106+
/// a single KeyCode enum. Plus, Scan Code Set 2 is a pain, because most of the
1107+
/// 'extended' keys they added on the IBM PC/AT actually generate two bytes, not
1108+
/// one. It's much nicer when your Scan Codes always have one byte per key.
10871109
pub extern "C" fn hid_get_event() -> common::Result<common::Option<common::hid::HidEvent>> {
10881110
let mut buffer = [0u8; 8];
10891111

0 commit comments

Comments
 (0)