USB Keyboard controller

Post here first, or if you can't find a relevant section!
Post Reply
BennehBoy
Posts: 135
Joined: Sat Jan 04, 2020 2:38 am
Answers: 1

USB Keyboard controller

Post by BennehBoy »

Has anyone had a crack at writing a custom keyboard controller? One that supports macros, key moving, led's etc?

There're plenty of low level stm32 projects out there but I wondered if anyone had done it atop arduino?
ag123
Posts: 1657
Joined: Thu Dec 19, 2019 5:30 am
Answers: 25

Re: USB Keyboard controller

Post by ag123 »

i've been wanting to do something like it
there is this tmk firmware
https://github.com/tmk/tmk_keyboard
that is used in the brownfox diy keyboard
https://deskthority.net/viewtopic.php?t=6050

but to simpify what looks complicated
there are a bunch of usb hid scan codes we'd need to return
https://gist.github.com/MightyPork/6da2 ... 55fdc73db2
so that makes it simplier
my guess is if we don't need the pins for other purpose, we can wire up a keyboard grid
https://en.wikipedia.org/wiki/ISO/IEC_9 ... IEC_9995-1
and basically use the pins for scanning
then return the relevant usb hid scan codes
and that makes it a keyboard

i think there are also some templates for usb hid keyboard 'report types' that is needed for the hid setup in the hid-1.1 specs
https://www.usb.org/document-library/de ... on-hid-111

to save on pins, we could use shift registers, but it may be more of a hassle unless you want to use the pins for something else
e.g. leds, it seemed quite possible to use things like neopixels for the leds and we'd have multi color leds.
but timing and all can be tight

macros is easy once we get the basic keyboard working, it is probably like writing some short cut keys into flash
there are tricky parts as well which is when multi keys are pressed e.g. the alt-ctrl.shift keys along with another key
Last edited by ag123 on Tue Jan 07, 2020 1:46 am, edited 2 times in total.
BennehBoy
Posts: 135
Joined: Sat Jan 04, 2020 2:38 am
Answers: 1

Re: USB Keyboard controller

Post by BennehBoy »

Yeah I think this is why I was looking to lift someone elses code - I've got a stack of various mcu's here and I'm thinking one of the 40x variants would probably be best from an io perspective.
ag123
Posts: 1657
Joined: Thu Dec 19, 2019 5:30 am
Answers: 25

Re: USB Keyboard controller

Post by ag123 »

i think a f103 would work just fine for a keyboard, scanning hardly needs to be more than 100hz for a full loop but with 105 keys that would be 10500 hz for all the keys
to save on pins an easy way out is to use shift registers like 74hc595 and 74hc165 e.g.
Image
a keyboard project has a rather large physical/mechanical project part which is to make the keyboard itself
https://deskthority.net/viewtopic.php?t=6050
https://geekhack.org/index.php?topic=87689.0
looking at the various diy mechanical keyboards projects, it kind of creates a curiosity to want to try building something like that
but i'd guess it'd take some time/effort
part of the motivation is with the mcu under ones disposal, the keyboard is really more than a keyboard, e.g. unused pins can be routed to a header used for adc etc, it is a new 'app scenario' as now it becomes possible to have additional functions that really isn't part of a keyboard, e.g. it could double up as a 'usb-serial dongle'
BennehBoy
Posts: 135
Joined: Sat Jan 04, 2020 2:38 am
Answers: 1

Re: USB Keyboard controller

Post by BennehBoy »

Yeah a lot can be done to 'add value' - for me in keyboard macro definitions would be great.

Teensy seems to have done a lot already in this realm -> https://www.pjrc.com/teensy/td_keyboard.html

I may have a look to see if any of that can be hacked over...
ag123
Posts: 1657
Joined: Thu Dec 19, 2019 5:30 am
Answers: 25

Re: USB Keyboard controller

Post by ag123 »

my main motivation for this is basically a diy mechanical keyboard
what matters here is to start with the usb hid scan codes
https://gist.github.com/MightyPork/6da2 ... 55fdc73db2
these are the codes we'd need to send to the host for particular keys
then when one design the physical circuit one would need to translate those scan locations to USB HID scan codes
doing it this way 'from scratch' has some advantages, one would be less concerned how to wire the columns and rows on the keyboard.
one can even have different circuits e.g. for the shift, alt, ctrl (and now the 'windows') keys as they almost always are pressed together with some other keys. this may save the need for rows and columns diodes. the whole diode array is primarily intended to allow multiple keys to be pressed together so called n keys roll over. using a full set of diodes would presumably allow all many keys to be pressed together and still scan correctly.
this become the iconic ways to make diy keyboards
https://deskthority.net/viewtopic.php?t=6050

but those various other implementations are very relevant too
https://www.pjrc.com/teensy/td_keyboard.html

one of those things is that a keyboard isn't really a keyboard, our little stm32 pill boards
https://en.wikipedia.org/wiki/Infinite_monkey_theorem
can perhaps attempt to test the infinite monkey theorey
The infinite monkey theorem states that a monkey hitting keys at random on a typewriter keyboard for an infinite amount of time will almost surely type any given text, such as the complete works of William Shakespeare.
add a little AI and this would seem more feasible
:lol:
Post Reply

Return to “General discussion”