How does a USB keyboard work?

Ben Eater34 minutes read

PS2 keyboards use four pins for power and communication, sending bursts of data with clock pulses and various bits. USB keyboards operate at different speeds, signal their speed through data signals, and require a computer for communication initiation.

Insights

  • PS2 keyboards use a simple four-pin interface for power and communication, while USB keyboards have a more complex setup with additional pins for ground, power, and data signals.
  • USB keyboards operate at different speeds, signaling their speed through specific pins, and involve intricate data decoding processes, including NRZI encoding, bit stuffing, and differential pair transmission for enhanced signal integrity.

Get key ideas from YouTube videos. It’s free

Recent questions

  • How does a USB keyboard differ from a PS2 keyboard?

    USB keyboards use four pins for power and data, while PS2 keyboards use only four pins for communication. USB keyboards operate at different speeds, with low speed at 1.5 Mbps and full speed at 12 Mbps. USB keyboards signal their speed by pulling D- high for low speed and D+ high for full speed. USB keyboards require connection to a computer for communication initiation. USB keyboards send more data than PS2 keyboards, but USB's faster speed compensates for the increased data transfer.

  • What is the process of decoding USB data packets?

    Analyzing USB data involves decoding J and K states, identifying packet boundaries, and interpreting sync patterns. USB data uses NRZI encoding, where a one is represented by no level change and a zero by a level change. NRZI encoding aids in reliable data detection by focusing on transitions between voltage levels. Using a differential pair in USB data transmission reduces interference susceptibility and emissions, enhancing signal integrity. Level changes indicate zeros, crucial for clock recovery and bit counting. USB protocol uses bit stuffing to ensure signal transitions, preventing miscounts.

  • How do USB keyboards handle key presses?

    Keyboard responses vary based on key presses, with modifier keys represented by specific bits. Limitations exist in detecting simultaneous key presses beyond six due to internal connections in the keyboard matrix. Negotiating with a computer can allow for more than six simultaneous key presses, although six is the typical default outside of specialized gaming hardware. Initial setup is required when plugging in a keyboard, involving communication with the computer to establish parameters and configurations.

  • What are the key components of a USB data packet?

    Decoded first four bits as 1001 represent an "in" packet. Following four bits are the complement of the first four, serving as a data integrity check. Address, endpoint, and CRC are decoded from subsequent bits, with CRC checking address and endpoint. Address 24, endpoint 1, and CRC F4BF indicate an "in" command for keyboard data retrieval. Data packet decoded with eight bytes of zeros and a CRC F4BF for data integrity. Acknowledgement packet decoded as a response to the data packet.

  • How does USB protocol ensure data integrity?

    USB keyboards use NRZI encoding, bit stuffing, and CRC checks to ensure data integrity. NRZI encoding aids in reliable data detection by focusing on transitions between voltage levels. Level changes indicate zeros, crucial for clock recovery and bit counting. USB protocol uses bit stuffing to ensure signal transitions, preventing miscounts. Address, endpoint, and CRC are decoded from subsequent bits, with CRC checking address and endpoint. USB keyboards send more data than PS2 keyboards, but USB's faster speed compensates for the increased data transfer.

Related videos

Summary

00:00

"Keyboard Interface: PS2 vs USB Communication"

  • PS2 style keyboard interface uses only four pins, with two for power (ground and 5 volts) and two for communication signals.
  • Each key press or release sends bursts of data containing 11 clock pulses, start bit, 8 data bits, parity bit, and stop bit.
  • USB keyboards use four pins for ground, 5V power, and two data signals (D+ and D-).
  • USB operates at different speeds (low, full, high), with low speed at 1.5 Mbps and full speed at 12 Mbps.
  • USB keyboards signal their speed by pulling D- high for low speed and D+ high for full speed.
  • USB keyboards require connection to a computer for communication initiation.
  • Analyzing USB data involves decoding J and K states, identifying packet boundaries, and interpreting sync patterns.
  • USB data uses NRZI encoding, where a one is represented by no level change and a zero by a level change.
  • NRZI encoding aids in reliable data detection by focusing on transitions between voltage levels.
  • Using a differential pair in USB data transmission reduces interference susceptibility and emissions, enhancing signal integrity.

13:45

"USB Protocol: Clock Recovery and Data Integrity"

  • Level changes indicate zeros, crucial for clock recovery and bit counting.
  • USB protocol uses bit stuffing to ensure signal transitions, preventing miscounts.
  • Decoded first four bits as 1001, representing an "in" packet.
  • Following four bits are the complement of the first four, serving as a data integrity check.
  • Address, endpoint, and CRC are decoded from subsequent bits, with CRC checking address and endpoint.
  • Address 24, endpoint 1, and CRC F4BF indicate an "in" command for keyboard data retrieval.
  • Data packet decoded with eight bytes of zeros and a CRC F4BF for data integrity.
  • Acknowledgement packet decoded as a response to the data packet.
  • Keyboard responses vary based on key presses, with modifier keys represented by specific bits.
  • Limitations exist in detecting simultaneous key presses beyond six due to internal connections in the keyboard matrix.

27:48

Keyboard Setup and Latency Comparison in Computers

  • Negotiating with a computer can allow for more than six simultaneous key presses, although six is the typical default outside of specialized gaming hardware.
  • Initial setup is required when plugging in a keyboard, involving communication with the computer to establish parameters and configurations.
  • USB keyboards send more data than PS2 keyboards, but USB's faster speed compensates for the increased data transfer.
  • USB keyboards may introduce latency due to polling intervals, with USB keyboards polling every 16 milliseconds compared to PS2 keyboards' immediate data transmission.
  • Higher quality USB keyboards operating at full speed may have polling intervals as short as one millisecond, minimizing latency and making them comparable to PS2 keyboards in practical use.
Channel avatarChannel avatarChannel avatarChannel avatarChannel avatar

Try it yourself — It’s free.