Kiibohd Controller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

README 19KB

10 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. The Kiibohd Controller
  2. ----------------------
  3. This README is a bit long, just look at the sections you are interested in.
  4. You only need to install avr-gcc if you want to build for the Teensy 2.0/2.0++.
  5. Everything else needs an arm-none-eabi-gcc compiler (e.g. Infinity keyboard, Teensy 3.0/3.1, McHCK).
  6. Linux is the ideal build environment (preferably recent'ish).
  7. In the near future I'll make available an Arch Linux VM for building/manufacturing tests.
  8. Building on Mac should be ok for 99% of users with Macports (haven't tried Brew).
  9. The dfu Bootloader will not build correctly with the old version of arm-none-eabi-gcc that Macports currently has (4.7.3).
  10. This is due to a bug with lto (link time optimizations) which makes the resulting binary too big to fit on the chip (must be less than 4096 Bytes).
  11. Building on Windows should also be fine for 99% of users, but takes a bunch of work to setup (because Windows is a crappy dev environment).
  12. Cygwin is currently required along with some non-Cygwin compilers and utilities (because they are not available for Cygwin).
  13. The dfu Bootloader will not build because of a Make 3.81+ bug/feature that removed support for non-Unix (Windows) filenames as dependencies of targets.
  14. If you replace the version of Make in Cygwin it should work (e.g. http://stackoverflow.com/questions/601516/cygwin-make-error-target-pattern-contains-no).
  15. However, make sure that the flash size is no larger than 4096 Bytes or the bootloader will not work.
  16. Things will likely break if there are *SPACES IN YOUR PATHS*. I install cygwin to C:\cygwin64.
  17. If you are brave and have programming knowledge, I will accept patches to fix any issues regarding spaces in paths.
  18. Please give authors credit for modules used if you use in a distributed product :D
  19. ----------------------
  20. General Dependencies
  21. ----------------------
  22. Below listed are the Arch Linux pacman names, AUR packages may be required.
  23. These depend a bit on which targets you are trying to build, but the general one:
  24. - cmake (2.8 and higher)
  25. - git
  26. - ctags (recommended, not required)
  27. - python3
  28. - libusb1.0 (and -devel)
  29. - make
  30. AVR Specific (Teensy 1.0/++,2.0/++) (try to use something recent, suggested versions below)
  31. - avr-gcc (~4.8.0)
  32. - avr-binutils (~2.23.2)
  33. - avr-libc (~1.8.0)
  34. ARM Specific (Teensy 3.0/3.1, Infinity Keyboard, McHCK)
  35. Arch Linux / Mac Ports
  36. - arm-none-eabi-gcc
  37. - arm-none-eaby-binutils
  38. Windows
  39. (https://launchpad.net/gcc-arm-embedded/+download)
  40. - gcc-arm-none-eabi (win32.zip)
  41. ----------------------
  42. Windows Setup
  43. ----------------------
  44. Compiling on Windows does work, just it's a bunch more work.
  45. First make sure Cygwin is installed - http://www.cygwin.com/ - 32bit or 64bit is fine. Make sure the following are installed:
  46. - make
  47. - git (needed for some compilation info)
  48. - cmake
  49. - gcc-core
  50. - gcc-g++
  51. - libusb1.0
  52. - libusb1.0-devel
  53. - python3
  54. - ctags (recommended, not required)
  55. Please note, I use cygwin term exclusively for any command line options. Unless mentioned otherwise, use it.
  56. Do NOT use CMD or Powershell.
  57. Also install the Windows version of CMake (3+ is ideal) - http://cmake.org/cmake/resources/software.html
  58. Select "Do not add CMake to system PATH".
  59. This is in addition to the Cygwin version. This is an easier alternative to installing another C compiler.
  60. Add the following line to your .bashrc, making sure the CMake path is correct:
  61. echo "alias wincmake=\"PATH='/cygdrive/c/Program Files (x86)/CMake'/bin:'${PATH}' cmake -G 'Unix Makefiles'\"" >> ~/.bashrc
  62. Install the PJRC Virtual Serial Port Driver:
  63. (http://pjrc.com/teensy/serial_install.exe)
  64. Next, install the compiler(s) you want.
  65. ---------
  66. | AVR GCC |
  67. ---------
  68. You just need the Atmel AVR 8-bit Toolchain. The latest should be fine, as of writing it was 3.4.3.
  69. http://www.atmel.com/tools/atmelavrtoolchainforwindows.aspx
  70. (Atmel AVR 8-bit Toolchain 3.4.3 - Windows)
  71. Extract the files to a directory, say C:\avr8-gnu-toolchain. Then copy all the folders in that directory to the Cygwin /usr/local directory.
  72. Mine is C:\cygwin64\usr\local.
  73. (You can also just setup the paths, but this is faster/simpler. Might screw up your Cygwin though).
  74. ----------
  75. | ARM EABI |
  76. ----------
  77. Download the latest GNU Tools for Embedded Processors gcc-arm-none-eabi.
  78. https://launchpad.net/gcc-arm-embedded/+download
  79. Download "gcc-arm-none-eabi*win32.zip".
  80. Then extract all the folders/files in the zip to the Cygwin /usr/local directory.
  81. Mine is C:\cygwin64\usr\local.
  82. Or, you can setup paths using the installer (you have to be more careful, avoid spaces in paths).
  83. ----------------------
  84. CMake Info
  85. ----------------------
  86. One of the big benefits of using CMake is the ability to build multiple configurations (for different microcontrollers) at the same time.
  87. The following sections explain in detail what each CMakeLists.txt configuration option does and what you can change it to.
  88. However, it is possible to configure each of these options using the -D command line flag.
  89. For example, to build the Infinity Keyboard default configuration:
  90. mkdir build_infinity
  91. cd build_infinity
  92. cmake -DCHIP=mk20dx128vlf5 -DScanModule=MD1 -DMacroModule=PartialMap -DOutputModule=pjrcUSB -DDebugModule=full -DBaseMap=defaultMap -DDefaultMap="md1Overlay stdFuncMap" -DPartialMaps="hhkbpro2" ..
  93. make
  94. CMake defaults to the values specified in CMakeLists.txt if not overridden via the command line.
  95. NOTE: On Windows, you will have to use "wincmake" instead of "cmake".
  96. ----------------------
  97. Selecting Microcontroller
  98. ----------------------
  99. This is where you select the chip you want to compile for.
  100. The build system will automatically select the compiler needed to compile for your chip.
  101. Open up CMakeLists.txt in your favourite text editor.
  102. You are looking for:
  103. ###
  104. # Chip Selection
  105. #
  106. #| You _MUST_ set this to match the microcontroller you are trying to compile for
  107. #| You _MUST_ clean the build directory if you change this value
  108. #|
  109. set( CHIP
  110. # "at90usb162" # Teensy 1.0 (avr)
  111. # "atmega32u4" # Teensy 2.0 (avr)
  112. # "at90usb646" # Teensy++ 1.0 (avr)
  113. # "at90usb1286" # Teensy++ 2.0 (avr)
  114. # "mk20dx128" # Teensy 3.0 (arm)
  115. "mk20dx128vlf5" # McHCK mk20dx128vlf5
  116. # "mk20dx256" # Teensy 3.1 (arm)
  117. CACHE STRING "Microcontroller Chip" )
  118. Just uncomment the chip you want, and comment out the old one.
  119. NOTE: If you change this option, you will *need* to delete the build directory that is created in the Building sections below.
  120. ----------------------
  121. Selecting Modules
  122. ----------------------
  123. WARNING: Not all modules are compatible, and some modules may have dependencies on other modules.
  124. This is where the options start getting interesting.
  125. The Kiibohd Controller is designed around a set of 4 types of modules that correspond to different functionality:
  126. - Scan Module
  127. - Macro Module
  128. - Output Module
  129. - Debug Module
  130. The Scan Module is where the most interesting stuff happens. These modules take in "keypress data".
  131. A converter Scan Module will interpret a protocol into key press/releases.
  132. A matrix Scan Module may inherit from the matrix module to scan keypress from a matrix
  133. This module just has to give press/release codes, but does have some callback control to other modules depending on the lifecycle for press/release codes (this can be very complicated depending on the protocol).
  134. Each Scan Module has it's own default keymap/modifier map. (TODO recommend keymap changing in the Macro Module).
  135. Some scan modules have very specialized hardware requirements, each module directory should have at least a link to the needed parts and/or schematics (TODO!).
  136. The Macro Module takes care of the mapping of the key press/release code into an Output (USB) scan code.
  137. Any layering, macros, keypress intelligence/reaction is done here.
  138. The Output Module is the module dealing with output from the microcontroller. Currently USB is the only output protocol.
  139. Different USB output implementations are available, pjrc being the safest/least featureful one.
  140. Debug capabilities may depend on the module selected.
  141. The Debug Module enables various things like the Teensy LED on errors, debug terminal output.
  142. (TODO get true UART working in avr, not just arm)
  143. Open up CMakeLists.txt in your favourite text editor.
  144. Look for:
  145. ###
  146. # Project Modules
  147. #
  148. #| Note: This is the only section you probably want to modify
  149. #| Each module is defined by it's own folder (e.g. Scan/Matrix represents the "Matrix" module)
  150. #| All of the modules must be specified, as they generate the sources list of files to compile
  151. #| Any modifications to this file will cause a complete rebuild of the project
  152. #| Please look at the {Scan,Macro,Output,Debug} for information on the modules and how to create new ones
  153. ##| Deals with acquiring the keypress information and turning it into a key index
  154. set( ScanModule "MD1"
  155. CACHE STRING "Scan Module" )
  156. ##| Provides the mapping functions for DefaultMap and handles any macro processing before sending to the OutputModule
  157. set( MacroModule "PartialMap"
  158. CACHE STRING "Macro Module" )
  159. ##| Sends the current list of usb key codes through USB HID
  160. set( OutputModule "pjrcUSB"
  161. CACHE STRING "Output Module" )
  162. ##| Debugging source to use, each module has it's own set of defines that it sets
  163. set( DebugModule "full"
  164. CACHE STRING "Debug Module" )
  165. Look at each module individually for it's requirements. There is chip/architecture dependency checking but some permutations of modules may not be tested/compile.
  166. There are also CMake options for temporarily selecting modules. But it's easier to just edit the file.
  167. e.g. cmake -DScanModuleOverride=<module name>
  168. ----------------------
  169. Linux Building
  170. ----------------------
  171. From this directory.
  172. mkdir build
  173. cd build
  174. cmake ..
  175. make
  176. Example output:
  177. [master]: cmake .. [...sy/avr-capsense-haata/build](hyatt@901Mas:pts/4)
  178. -- Compiler Family:
  179. avr
  180. -- MCU Selected:
  181. at90usb1286
  182. -- Detected Scan Module Source Files:
  183. Scan/avr-capsense/scan_loop.c
  184. -- Detected Macro Module Source Files:
  185. Macro/buffer/macro.c
  186. -- Detected Output Module Source Files:
  187. Output/pjrc/usb_com.c;Output/pjrc/avr/usb_keyboard_debug.c
  188. -- Detected Debug Module Source Files:
  189. Debug/full/../led/led.c;Debug/full/../print/print.c
  190. -- Configuring done
  191. -- Generating done
  192. -- Build files have been written to: /home/hyatt/Source/Teensy/avr-capsense-haata/build
  193. [master]: make [...sy/avr-capsense-haata/build](hyatt@901Mas:pts/4)
  194. Scanning dependencies of target kiibohd.elf
  195. [ 12%] Building C object CMakeFiles/kiibohd.elf.dir/main.c.o
  196. [ 25%] Building C object CMakeFiles/kiibohd.elf.dir/Scan/avr-capsense/scan_loop.c.o
  197. [ 37%] Building C object CMakeFiles/kiibohd.elf.dir/Macro/buffer/macro.c.o
  198. [ 50%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrc/usb_com.c.o
  199. [ 62%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrc/avr/usb_keyboard_debug.c.o
  200. [ 75%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/led/led.c.o
  201. [ 87%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/print/print.c.o
  202. Linking C executable kiibohd.elf
  203. Creating load file for Flash: kiibohd.hex
  204. Creating Extended Listing: kiibohd.lss
  205. Creating Symbol Table: kiibohd.sym
  206. [ 87%] Built target kiibohd.elf
  207. Scanning dependencies of target SizeAfter
  208. [100%] Size after generation:
  209. text data bss dec hex filename
  210. 0 6112 0 6112 17e0 kiibohd.hex
  211. 5792 320 852 6964 1b34 kiibohd.elf
  212. [100%] Built target SizeAfter
  213. ----------------------
  214. Linux Loading Firmware
  215. ----------------------
  216. First place the keyboard into re-flash mode.
  217. This can be done either by pressing the re-flash button on the PCB/Teensy.
  218. Or by entering the Kiibohd Virtual Serial Port and using the 'reload' command.
  219. The 'load' script that is created during the build can load the firmware over USB.
  220. Either run it with sudo, or install the 98-kiibohd.rules to /etc/udev/rules.d
  221. and run: udevadm control --reload-rules
  222. To load the newly built firmware:
  223. ./load
  224. ----------------------
  225. Linux Building Bootloader
  226. ----------------------
  227. *NOTE* Does not apply to Teensy based builds.
  228. From this directory.
  229. cd Bootloader
  230. mkdir build
  231. cd build
  232. cmake ..
  233. make
  234. Example output:
  235. TODO
  236. ----------------------
  237. Linux Loading Bootloader
  238. ----------------------
  239. *NOTE* Does not apply to Teensy based builds.
  240. It's recommended to use an SWD-type flasher like a Bus Pirate.
  241. There is a convenience script for loading the firmware once the system is setup.
  242. cd Bootloader/Scripts
  243. ./swdLoad.bash
  244. The above script requires Ruby, Ruby serial port module, git, and a /dev/buspirate udev rule.
  245. Additional Notes:
  246. https://github.com/mchck/mchck/wiki/Getting-Started
  247. https://wiki.archlinux.org/index.php/Bus_pirate
  248. ----------------------
  249. Windows Building
  250. ----------------------
  251. From this directory.
  252. mkdir build
  253. cd build
  254. wincmake ..
  255. make
  256. Example output:
  257. $ wincmake ..
  258. -- Compiler Family:
  259. arm
  260. -- Chip Selected:
  261. mk20dx128vlf5
  262. -- Chip Family:
  263. mk20dx
  264. -- CPU Selected:
  265. cortex-m4
  266. -- Compiler Source Files:
  267. Lib/mk20dx.c;Lib/delay.c
  268. -- Bootloader Type:
  269. dfu
  270. -- Detected Scan Module Source Files:
  271. Scan/MD1/scan_loop.c;Scan/MD1/../MatrixARM/matrix_scan.c
  272. -- Detected Macro Module Source Files:
  273. Macro/PartialMap/macro.c
  274. -- Detected Output Module Source Files:
  275. Output/pjrcUSB/output_com.c;Output/pjrcUSB/arm/usb_desc.c;Output/pjrcUSB/arm/usb_dev.c;Output/pjrcUSB/arm/usb_keyboard.c;Output/pjrcUSB/arm/usb_mem.c;Output/pjrcUSB/arm/usb_serial.c
  276. -- Detected Debug Module Source Files:
  277. Debug/full/../cli/cli.c;Debug/full/../led/led.c;Debug/full/../print/print.c
  278. -- Found Git: C:/cygwin64/bin/git.exe (found version "2.1.1")
  279. -- Found Ctags: C:/cygwin64/bin/ctags.exe (found version "5.8")
  280. -- Checking for latest kll version:
  281. Current branch master is up to date.
  282. -- Detected Layout Files:
  283. C:/cygwin64/home/Jacob/controller/Macro/PartialMap/capabilities.kll
  284. C:/cygwin64/home/Jacob/controller/Output/pjrcUSB/capabilities.kll
  285. C:/cygwin64/home/Jacob/controller/Scan/MD1/defaultMap.kll
  286. C:/cygwin64/home/Jacob/controller/kll/layouts/md1Overlay.kll
  287. C:/cygwin64/home/Jacob/controller/kll/layouts/stdFuncMap.kll
  288. C:/cygwin64/home/Jacob/controller/kll/layouts/hhkbpro2.kll
  289. -- Configuring done
  290. -- Generating done
  291. -- Build files have been written to: C:/cygwin64/home/Jacob/controller/build
  292. Jacob@DenPC ~/controller/build
  293. $ make
  294. [ 5%] Generating KLL Layout
  295. Scanning dependencies of target kiibohd.elf
  296. [ 11%] Building C object CMakeFiles/kiibohd.elf.dir/main.c.obj
  297. [ 17%] Building C object CMakeFiles/kiibohd.elf.dir/Lib/mk20dx.c.obj
  298. [ 23%] Building C object CMakeFiles/kiibohd.elf.dir/Lib/delay.c.obj
  299. [ 29%] Building C object CMakeFiles/kiibohd.elf.dir/Scan/MD1/scan_loop.c.obj
  300. [ 35%] Building C object CMakeFiles/kiibohd.elf.dir/Scan/MatrixARM/matrix_scan.c.obj
  301. [ 41%] Building C object CMakeFiles/kiibohd.elf.dir/Macro/PartialMap/macro.c.obj
  302. [ 47%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/output_com.c.obj
  303. [ 52%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/arm/usb_desc.c.obj
  304. [ 58%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/arm/usb_dev.c.obj
  305. [ 64%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/arm/usb_keyboard.c.obj
  306. [ 70%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/arm/usb_mem.c.obj
  307. [ 76%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/arm/usb_serial.c.obj
  308. [ 82%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/cli/cli.c.obj
  309. [ 88%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/led/led.c.obj
  310. [ 94%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/print/print.c.obj
  311. Linking C executable kiibohd.elf
  312. [ 94%] Built target kiibohd.elf
  313. Scanning dependencies of target SizeAfter
  314. [100%] Chip usage for mk20dx128vlf5
  315. SRAM: 32% 5384/16384 bytes
  316. Flash: 18% 23296/126976 bytes
  317. [100%] Built target SizeAfter
  318. NOTES:
  319. If you get the following error, you have not setup wincmake correctly:
  320. $ make
  321. [ 5%] Generating KLL Layout
  322. Scanning dependencies of target kiibohd.elf
  323. [ 11%] Building C object CMakeFiles/kiibohd.elf.dir/main.c.o
  324. ../main.c:28:19: fatal error: macro.h: No such file or directory
  325. #include <macro.h>
  326. ^
  327. compilation terminated.
  328. CMakeFiles/kiibohd.elf.dir/build.make:67: recipe for target 'CMakeFiles/kiibohd.elf.dir/main.c.o' failed
  329. make[2]: *** [CMakeFiles/kiibohd.elf.dir/main.c.o] Error 1
  330. CMakeFiles/Makefile2:98: recipe for target 'CMakeFiles/kiibohd.elf.dir/all' failed
  331. make[1]: *** [CMakeFiles/kiibohd.elf.dir/all] Error 2
  332. Makefile:75: recipe for target 'all' failed
  333. make: *** [all] Error 2
  334. If you have already added the line to your ~/.bashrc try restarting your cygwin shell.
  335. ----------------------
  336. Windows Loading Firmware
  337. ----------------------
  338. First place the keyboard into re-flash mode.
  339. This can be done either by pressing the re-flash button on the PCB/Teensy.
  340. Or by entering the Kiibohd Virtual Serial Interface and using the 'reload' command.
  341. The 'load' script that is created during the build can load the firmware over USB.
  342. To load the newly built firmware:
  343. ./load
  344. Be patient the couple of times, Windows is slow at installing drivers...
  345. ----------------------
  346. Mac OS X Building
  347. ----------------------
  348. From this directory.
  349. mkdir build
  350. cd build
  351. cmake ..
  352. make
  353. Example output:
  354. TODO
  355. ----------------------
  356. Mac OS X Loading Firmware
  357. ----------------------
  358. First place the keyboard into re-flash mode.
  359. This can be done either by pressing the re-flash button on the PCB/Teensy.
  360. Or by entering the Kiibohd Virtual Serial Port and using the 'reload' command.
  361. The 'load' script that is created during the build can load the firmware over USB.
  362. To load the newly built firmware:
  363. ./load
  364. ----------------------
  365. Virtual Serial Port - CLI
  366. ----------------------
  367. Rather than use a special program that can interpret Raw HID, this controller exposes a USB Serial CDC endpoint.
  368. This allows for you to use a generic serial terminal to debug/control the keyboard firmware (e.g. Tera Term, minicom, screen)
  369. -------
  370. | Linux |
  371. -------
  372. I generally use screen.
  373. You will need sudo/root priviledges if you haven't installed the 98-kiibohd.rules file to /etc/udev/rules.d
  374. screen /dev/ttyACM0
  375. (Might be ACM1, ACM2, etc.)
  376. ---------
  377. | Windows |
  378. ---------
  379. Make sure the Teensy Virtual Serial Port driver is installed.
  380. If possible use screen (as part of Cygwin).
  381. Check which COM port the virtual serial port has been assigned to:
  382. Device Manager->Ports (COM & LPT)->Teensy USB Serial
  383. In brackets it will say which COM port (e.g. COM3)
  384. putty works well when using DTR/DSR or RTS/CTS flow control.
  385. Connection type: Serial
  386. Serial line: <Your COM port, e.g. COM3>
  387. Speed: (doesn't matter, it's auto-negotiated)
  388. Under Category->Connections->Serial
  389. Flow control: DTR/DSR
  390. If stuff is hard to read (you have a dumb colour scheme):
  391. Category->Window->Colours->Use system colur
  392. That seems to make text at least readable (I use a custom colour scheme that makes each colour easy to see -HaaTa).
  393. Unfortunately, screen for Cygwin seems to be broken for serial ports, but you can try it...
  394. screen /dev/ttyS2
  395. (Might be a different file, ttyS0, ttyACM0, ttyUSB0, etc.)
  396. Gnu screen doesn't seem to echo all the characters (it works though).
  397. I believe it's a problem with stty, but I don't know how to fix it...
  398. ----------
  399. | Mac OS X |
  400. ----------
  401. I recommend screen (can be installed via Macports).
  402. screen /dev/tty.<usb something>