{"id":1646,"date":"2017-05-27T22:18:48","date_gmt":"2017-05-28T02:18:48","guid":{"rendered":"https:\/\/pappp.net\/?p=1646"},"modified":"2017-05-28T11:06:47","modified_gmt":"2017-05-28T15:06:47","slug":"microchorder","status":"publish","type":"post","link":"https:\/\/pappp.net\/?p=1646","title":{"rendered":"MicroChorder"},"content":{"rendered":"<p>I hacked together an Arduino Micro firmware that is a drop-in replacement for a Spiffchorder, long version and code below the fold.<br \/>\n<!--more--><\/p>\n<p>My <a href=\"https:\/\/pappp.net\/?p=1466\">old Spiffchorder<\/a> board is no longer enumerating on USB, so I decided I needed to replace it.  I figured the right thing to do was replace with a more modern microcontroller that has an integrated hardware USB stack instead of VUSB and some zenier diodes, most likely an Atmega 32U4 because they&#8217;re about the right size, familiar, and available on nice cheap breakout boards (usually as &#8220;Arduino Micro&#8221; or similar).<\/p>\n<p>While I was reading up, I saw that in the interim the original Spiffchorder folks had designed themselves <a href=\"http:\/\/chorder.cs.vassar.edu\/featherchorder\">FeatherChorder<\/a>, which uses an <a href=\"https:\/\/learn.adafruit.com\/adafruit-feather-32u4-bluefruit-le\/overview\">Adafruit Feather Bluatooth LE<\/a> to construct a Bluetooth 7-key chorder.  The Feather BLE is, helpfully, a 32U4 Arduino with a Bluetooth module hardwired to the SPI pins. <\/p>\n<p>So, the obvious solution is to grab the keyer-handling code from FeatherChorder, replace the Bluetooth HID functionality with USB HID functionality, and call it a day.  In principle this is straightforward because USB and Bluetooth use the same <a href=\"http:\/\/www.usb.org\/developers\/hidpage\/Hut1_12v2.pdf\">scan codes<\/a> (PDF Warning) and data format for HID devices, and there is a first-party USB Keyboard library for 32U4 based Arduinos. In actual fact, it&#8217;s a little annoying because the Arduino Keyboard library is easy instead of simple; the functions all take ASCII characters or #define&#8217;d magic numbers instead of scan codes, then beats them up to generate scan codes.  <\/p>\n<p>At this point I compared alternatives:<br \/>\n1. Try to hack it to work with the Keyboard library<br \/>\n2. Try to do it directly with the HID library<br \/>\n3. Make a modified version of the Keyboard library to match FeatherChorder&#8217;s expectations<br \/>\n4. Make a modified version of the Keyboard library that matches the USB HID spec<br \/>\n5. Just start from scratch<\/p>\n<p>I gave (1) a quick pass and determined it would never work right for the whole keyboard, (2) would be ugly and involve a bunch of things that would be easier to do under (3), and (4) and (5) would be too more work than I wanted right now. <\/p>\n<p>So (3) was the most pleasant\/useful, and Keyboard_RAW which does modifier keys and such in a convenient-but-nonstandard way to match the FeatherChorder functions was born. It was still a small pain in the dick because C++ is a terrible language, but nothing out of the ordinary. <\/p>\n<p>The library code is attached in case someone else wants to use it, but I&#8217;m not posting these things somewhere source-control-y because it&#8217;s an ugly hack to minimize the work between FeatherChorder and a working USB device rather than a quality general-purpose library, and I still like to imagine I can avoid contributing to the world being built on top of crap. The &#8220;right&#8221; solution is probably to add some raw functions to the keyboard library upstream.<\/p>\n<p>A couple bucks to get whatever random 32U4 based Arduino Micro compatible knockoff was <a href=\"https:\/\/www.amazon.com\/gp\/product\/B01HCXMBOU\/\">available<\/a> cheapest with Prime shipping and two days later, MicroChorder. <\/p>\n<p>Right now I just have my old keyer plugged in to [PRMINCF]=[8765432] with an 8th pin the Gnd adjacent to 2, which is nicely hardware minimal. I do still want to make a more presentable keyer sometime, likely with lighter switches, MX Browns feel good but are a little too fatiguing.<\/p>\n<p>If anyone wants to build their own, here are the <a href=\"https:\/\/pappp.net\/wp-content\/uploads\/2017\/05\/Keyboard_RAW.tar.gz\">Keyboard_RAW<\/a> library and <a href=\"https:\/\/pappp.net\/wp-content\/uploads\/2017\/05\/MicroChorder.tar.gz\">MicroChorder<\/a> Arduino sketch.  They aren&#8217;t works of art (or mostly my code), and have some missing bits (no media key support), but are tested in that I typed most of this post on one.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I hacked together an Arduino Micro firmware that is a drop-in replacement for a Spiffchorder, long version and code below the fold.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,8,37,1,10],"tags":[],"class_list":["post-1646","post","type-post","status-publish","format-standard","hentry","category-computers","category-diy","category-electronics","category-general","category-objects"],"_links":{"self":[{"href":"https:\/\/pappp.net\/index.php?rest_route=\/wp\/v2\/posts\/1646","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pappp.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pappp.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pappp.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pappp.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1646"}],"version-history":[{"count":0,"href":"https:\/\/pappp.net\/index.php?rest_route=\/wp\/v2\/posts\/1646\/revisions"}],"wp:attachment":[{"href":"https:\/\/pappp.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1646"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pappp.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1646"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pappp.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1646"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}