XaiJu
beneater
beneater

patreon


How does a USB keyboard work?

This is sort of a continuation of my other videos on keyboards, but really it's more of an exploration of the low level operation of USB. Hope you find it interesting!

As always, let me know if you see any bits that are confusing or wrong, and thanks again for your support!

-Ben

How does a USB keyboard work?

Comments

Really big thanks for this video. This explained more than i ever thought i'd want to know about USB, but as with every one of your videos you had me glued to the screen for the entire duration

I have a wireless USB mouse plug on a switch, and when I swap over to windows, the laptop freezes for several seconds, call it 10 billion clock cycles. I'm not sure what windows is doing for those but it sure seems important. Switching it over to my Linux desktop, I've never noticed any kind of discontinuity, just a log file entry. I'd like to make some sort of USB switch that doesn't "unplug" from the computers, just keeps sending nothing instead. But I don't know how hard that would be to create.

Tony Hammitt

Doesn't Ben usually plug the channel and the hand-built computer kit?

Ryan Helinski

Hi Ben, this is exactly the video I was hoping for! Could you add a link to the USB specification?

Alex Clink

on the other side, how does usb vs ps/2 pertain to use of system resources. on a modern system it would be difficult to ascertain as there are so many processes going. trying to figure out how many clock cycles it takes to pole the keyboard and get a key press on usb verses the keyboard triggering an interrupt and receiving the scan code(s) with ps/2. with your 6502 bread board computer it may be possible to determine. on a modern embedded device with a low level operating system this may be possible, but i don't think a modern cpu will function on a breadboard. the use of a micro controller to handle USB or PS/2 communications may be a solution. I assume the full USB protocol requires the operating system but a limited subset of the devices may be able to be handled with a micro controller. for example if the device(computer) only uses certain usb devices like a keyboard, mouse, etc. USB seems to be very software dependent.

Michael McDonnell

Showing USB signals in a lab setting like that was so informative. My understanding jumped up a whole level now that I've watched you figure out the signal and protocol. Thanks for the excellent work!

Mitch Reynolds

I found this video highly interesting. Knowing little about the specifics of USB, this seems to be a great introduction to show the lowest level up wards - signaling, encoding of bits as transitions, bit stuffing and division into packets and I felt like I could follow along without any difficulty. In regards to the latency of full speed USB vs. PS/2 and the comparison of polling rate vs. PS/2 transmission delay, the numbers presented here make a compelling case the the inherent difference is not large, however I can see discussion centering around other possible sources of delay for PS/2 vs. USB, such as delays in the software stack; delays introduced by USB hubs (internal or external.)

Phil Dennis

Excellent deep dive into usb! The buildup of your videos is genius: first with the printouts and then the fancy hardware. Great job!

Richard

One day, I'll meet someone with reflexes better than 16ms... I will bow down to the GOD of FPS gaming... :P

Scott Miller

Having written a number of drivers over simple serial, I totally get the advantage of having a common protocol layer for all devices (stops devices from freaking out at 'garbage' commands) but polling just seems so inefficient ; even if it is off loaded to the bus controller.

Peter Stevens

I think it would be feasible. Just like the PS2 uses external circuitry to buffer the key input, the USB would need something similar. Then the 6502 could read that data in when it's ready. Alternatively, USB could be implemented on a different, limited functionality CPU that just handles IO. Many old 8 bit computers had multiple processors in them for just this reason, actually.

Warren Garabrandt

Interestingly, there was a discussion about USB keyboards, 6 vs. N key rollover, HID vs. Boot mode and the likes on the Adafruit discord server a short while ago. An Adafruit employee, Dan Halbert, has gone through and done some research into this "myth", and shared a great resource about it that sums it up in fairly short order, as opposed to the USB spec and its hundreds of pages of specs and details without clarifications! https://www.devever.net/~hl/usbnkro

Hugo Dahl

Interesting... Based on this, is it even feasible (@ 1.5 mbit speed) for an 8-bit 1mhz. CPU to support USB or will it be either infeasible based on clock speed, or too much code to be useful? For that matter, how do the USB to PS/2 adapters work? (small IC in there doing translation?) Thx.

Michael Weitman

Great video as always! I’d only mention that the end felt very abrup

Hey Ben, what do you envision the end game to be with your project? I'd like to see being able to use the hardware in its 1980s 1990s state to do something including writing some basic software games.

I liked that we have a LCD and ps2 keyboard connected now let's do something like a simple wozmon to read and write to memory or to simply load software including basic. At this point it seems like we're focusing solely on the hardware. I'd like to delve into more of the software side to put to use the hardware we've built.

Was about to ask how you determine what device sends what packet, but you explain it at a later part of the video. There's one part where there is slight variance in timing between the computer's IN packet and the data packet sent by the Dell keyboard --was wondering why that is. Otherwise, I think all questions that might arise are answered really well in the video as usual. Thanks as always.

Aleksey Smolenchuk

Awesome video! Now I have (or will have when this goes live) a video I can point people to when they claim PS/2 is better than USB. :D Also, that's a LOT of complexity to implement on a 6502, and the low signaling voltage might also be a problem to TTL logic. I guess you could use some op amps to boost the voltage up for decoding, and either another op amp to transmit or a voltage divider to step down the transmit voltage. The problem might be that there are likely hundreds of different kinds of keyboards and mice out there. Is there a way to cheat and just detect a generic keyboard ID, or generic mouse ID, then blindly charge ahead hoping it works (maybe not 100% compatible, but enough to get started)?

Warren Garabrandt

Almost a necessary continuation of the PS/2 video 😊

Ryan Helinski

Audio turns relatively low at 5:25


More Creators