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.markdown 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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,
  6. Teensy 3.0/3.1, McHCK).
  7. Linux is the ideal build environment (preferably recent'ish). In the near
  8. future I'll make available an Arch Linux VM for building/manufacturing tests.
  9. Building on Mac should be ok for 99% of users with Macports or Homebrew. For
  10. Homebrew, use `brew tap PX4/homebrew-px4` to get the arm-none-eabi-gcc installer.
  11. The dfu Bootloader will not build correctly with the old version of
  12. arm-none-eabi-gcc that Macports currently has (4.7.3). This is due to a bug
  13. with lto (link time optimizations) which makes the resulting binary too big to
  14. fit on the chip (must be less than 4096 Bytes).
  15. Building on Windows should also be fine for 99% of users, but takes a bunch of
  16. work to setup (because Windows is a crappy dev environment). Cygwin is
  17. currently required along with some non-Cygwin compilers and utilities (because
  18. they are not available for Cygwin). The dfu Bootloader will not build because
  19. of a Make 3.81+ bug/feature that removed support for non-Unix (Windows)
  20. filenames as dependencies of targets. If you [replace the version of Make in
  21. Cygwin](http://stackoverflow.com/questions/601516/cygwin-make-error-target-pattern-contains-no)
  22. it should work. However, make sure that the flash size is no larger than 4096
  23. Bytes or the bootloader will not work. Things will likely break if there are
  24. **SPACES IN YOUR PATHS**. I install cygwin to `C:\cygwin64`. If you are brave
  25. and have programming knowledge, I will accept patches to fix any issues
  26. regarding spaces in paths.
  27. Please give authors credit for modules used if you use in a distributed
  28. product :D
  29. General Dependencies
  30. --------------------
  31. Below listed are the Arch Linux pacman names, AUR packages may be required.
  32. These depend a bit on which targets you are trying to build, but the general
  33. one:
  34. - cmake (2.8 and higher)
  35. - git
  36. - ctags (recommended, not required)
  37. - python3
  38. - libusb1.0 (and -devel)
  39. - make
  40. AVR Specific (Teensy 1.0/++,2.0/++) (try to use something recent, suggested
  41. versions below)
  42. - avr-gcc (~4.8.0)
  43. - avr-binutils (~2.23.2)
  44. - avr-libc (~1.8.0)
  45. ARM Specific (Teensy 3.0/3.1, Infinity Keyboard, McHCK)
  46. - Arch Linux / Mac Ports
  47. - arm-none-eabi-gcc
  48. - arm-none-eabi-binutils
  49. - Windows (https://launchpad.net/gcc-arm-embedded/+download)
  50. - gcc-arm-none-eabi (win32.zip)
  51. Windows Setup
  52. -------------
  53. Compiling on Windows does work, just it's a bunch more work.
  54. First make sure Cygwin is installed - http://www.cygwin.com/ - 32bit or 64bit
  55. is fine. Make sure the following are installed:
  56. - make
  57. - git (needed for some compilation info)
  58. - cmake
  59. - gcc-core
  60. - gcc-g++
  61. - libusb1.0
  62. - libusb1.0-devel
  63. - python3
  64. - ctags (recommended, not required)
  65. Please note, I use cygwin term exclusively for any command line options.
  66. Unless mentioned otherwise, use it. Do NOT use CMD or Powershell.
  67. Also install the [Windows version of CMake](http://cmake.org/cmake/resources/software.html)
  68. (3+ is ideal) - Select "Do not add CMake to system PATH". This is in addition
  69. to the Cygwin version. This is an easier alternative to installing another C
  70. compiler. Add the following line to your .bashrc, making sure the CMake path
  71. is correct:
  72. echo "alias wincmake=\"PATH='/cygdrive/c/Program Files (x86)/CMake'/bin:'${PATH}' cmake -G 'Unix Makefiles'\"" >> ~/.bashrc
  73. Install the [PJRC Virtual Serial Port Driver](http://pjrc.com/teensy/serial_install.exe).
  74. Next, install the compiler(s) you want.
  75. ### AVR GCC
  76. You just need the
  77. [Atmel AVR 8-bit Toolchain](http://www.atmel.com/tools/atmelavrtoolchainforwindows.aspx).
  78. The latest should be fine, as of writing it was 3.4.3.
  79. Extract the files to a directory, say `C:\avr8-gnu-toolchain`. Then copy all
  80. the folders in that directory to the Cygwin `/usr/local` directory. Mine is
  81. `C:\cygwin64\usr\local`. (You can also just setup the paths, but this is
  82. faster/simpler. Might screw up your Cygwin though).
  83. ### ARM EABI
  84. Download the latest
  85. [GNU Tools for Embedded Processors
  86. gcc-arm-none-eabi](https://launchpad.net/gcc-arm-embedded/+download).
  87. Download `gcc-arm-none-eabi*win32.zip`.
  88. Then extract all the folders/files in the zip to the Cygwin `/usr/local`
  89. directory. Mine is `C:\cygwin64\usr\local`. Or, you can setup paths using
  90. the installer (you have to be more careful, avoid spaces in paths).
  91. CMake Info
  92. ----------
  93. One of the big benefits of using CMake is the ability to build multiple
  94. configurations (for different microcontrollers) at the same time. The
  95. following sections explain in detail what each CMakeLists.txt configuration
  96. option does and what you can change it to. However, it is possible to
  97. configure each of these options using the `-D` command line flag.
  98. For example, to build the Infinity Keyboard default configuration:
  99. ```bash
  100. $ mkdir build_infinity
  101. $ cd build_infinity
  102. $ cmake -DCHIP=mk20dx128vlf5 -DScanModule=MD1 -DMacroModule=PartialMap \
  103. -DOutputModule=pjrcUSB -DDebugModule=full -DBaseMap=defaultMap \
  104. -DDefaultMap="md1Overlay stdFuncMap" -DPartialMaps="hhkbpro2" \
  105. ..
  106. $ make
  107. ```
  108. CMake defaults to the values specified in CMakeLists.txt if not overridden via
  109. the command line.
  110. > NOTE: On Windows, you will have to use "wincmake" instead of "cmake".
  111. Selecting Microcontroller
  112. -------------------------
  113. This is where you select the chip you want to compile for. The build system
  114. will automatically select the compiler needed to compile for your chip.
  115. Open up CMakeLists.txt in your favourite text editor. You are looking for:
  116. ```cmake
  117. ###
  118. # Chip Selection
  119. #
  120. #| You _MUST_ set this to match the microcontroller you are trying to compile for
  121. #| You _MUST_ clean the build directory if you change this value
  122. #|
  123. set( CHIP
  124. # "at90usb162" # Teensy 1.0 (avr)
  125. # "atmega32u4" # Teensy 2.0 (avr)
  126. # "at90usb646" # Teensy++ 1.0 (avr)
  127. # "at90usb1286" # Teensy++ 2.0 (avr)
  128. # "mk20dx128" # Teensy 3.0 (arm)
  129. "mk20dx128vlf5" # McHCK mk20dx128vlf5
  130. # "mk20dx256" # Teensy 3.1 (arm)
  131. CACHE STRING "Microcontroller Chip" )
  132. ```
  133. Just uncomment the chip you want, and comment out the old one.
  134. > NOTE: If you change this option, you will *need* to delete the build
  135. > directory that is created in the Building sections below.
  136. Selecting Modules
  137. -----------------
  138. > WARNING: Not all modules are compatible, and some modules may have
  139. > dependencies on other modules.
  140. This is where the options start getting interesting. The Kiibohd Controller
  141. is designed around a set of 4 types of modules that correspond to different
  142. functionality:
  143. - Scan Module
  144. - Macro Module
  145. - Output Module
  146. - Debug Module
  147. The Scan Module is where the most interesting stuff happens. These modules
  148. take in "keypress data". A converter Scan Module will interpret a protocol
  149. into key press/releases. A matrix Scan Module may inherit from the matrix
  150. module to scan keypress from a matrix This module just has to give
  151. press/release codes, but does have some callback control to other modules
  152. depending on the lifecycle for press/release codes (this can be very
  153. complicated depending on the protocol). Each Scan Module has it's own default
  154. keymap/modifier map. (TODO recommend keymap changing in the Macro Module).
  155. Some scan modules have very specialized hardware requirements, each module
  156. directory should have at least a link to the needed parts and/or schematics
  157. (TODO!).
  158. The Macro Module takes care of the mapping of the key press/release code into
  159. an Output (USB) scan code. Any layering, macros, keypress
  160. intelligence/reaction is done here.
  161. The Output Module is the module dealing with output from the microcontroller.
  162. Currently USB is the only output protocol. Different USB output
  163. implementations are available, pjrc being the safest/least featureful one.
  164. Debug capabilities may depend on the module selected.
  165. The Debug Module enables various things like the Teensy LED on errors, debug
  166. terminal output. (TODO get true UART working in avr, not just arm)
  167. Open up CMakeLists.txt in your favourite text editor. Look for:
  168. ```cmake
  169. ###
  170. # Project Modules
  171. #
  172. #| Note: This is the only section you probably want to modify
  173. #| Each module is defined by it's own folder (e.g. Scan/Matrix represents the "Matrix" module)
  174. #| All of the modules must be specified, as they generate the sources list of files to compile
  175. #| Any modifications to this file will cause a complete rebuild of the project
  176. #| Please look at the {Scan,Macro,Output,Debug} for information on the modules and how to create new ones
  177. ##| Deals with acquiring the keypress information and turning it into a key index
  178. set( ScanModule "MD1"
  179. CACHE STRING "Scan Module" )
  180. ##| Provides the mapping functions for DefaultMap and handles any macro processing before sending to the OutputModule
  181. set( MacroModule "PartialMap"
  182. CACHE STRING "Macro Module" )
  183. ##| Sends the current list of usb key codes through USB HID
  184. set( OutputModule "pjrcUSB"
  185. CACHE STRING "Output Module" )
  186. ##| Debugging source to use, each module has it's own set of defines that it sets
  187. set( DebugModule "full"
  188. CACHE STRING "Debug Module" )
  189. ```
  190. Look at each module individually for it's requirements. There is
  191. chip/architecture dependency checking but some permutations of modules may not
  192. be tested/compile.
  193. There are also CMake options for temporarily selecting modules. But it's
  194. easier to just edit the file. e.g. `cmake -DScanModuleOverride=<module name>`.
  195. Keymap Configuration
  196. --------------------
  197. This is where you define the layout for your keyboard.
  198. Currently, the only way to define kebyoard layouts is using [KLL](https://www.overleaf.com/read/zzqbdwqjfwwf).
  199. KLL is built up of 3 different kinds of keymaps in total.
  200. The BaseMap, DefaultMap and PartialMaps.
  201. For each type of keymap, it is possible to combine multiple .kll files together to create new ones using
  202. the compiler. The order of the files matter, as the right-most file will overwrite any setting in the
  203. previous files.
  204. > NOTE: Each keymap is done after the entire file is processed. This means that within the file the order
  205. > of assignment doesa *not* matter (if you assign the same thing twice, then yes the most recent one
  206. > takes priority).
  207. BaseMap defines what the keyboard can do. This includes specific capabilities of the keyboard (such as USB),
  208. the mapping of Scan Codes to USB Codes and any specific configurations for the keyboard.
  209. In general, the BaseMap rarely needs to be changed. Usually only when adding a new keyboard to the firmware
  210. does the Basemap need any modification.
  211. The BaseMap is what both DefaultMap and PartialMaps are based upon. This allows for a common reference
  212. when defining custom keymappings.
  213. > NOTE: Don't use defaultMap.kll to change your layouts. This will work, but they will not be portable.
  214. The DefaultMap is the normal state of the keyboard, i.e. your default layer.
  215. Using the BaseMap as a base, the DefaultMap is a modification of the BaseMap to what the keyboard should do.
  216. Since the DefaultMap uses USB Code to USB Code translations, this means that keymaps used for one keyboard
  217. will work with another keyboard.
  218. For example, I use Colemak, so this means I only have to define Colemak once for every keyboard that supports
  219. the kiibohd firmware. This is possible because every BaseMap defines the keyboard as a US ANSI like keyboard
  220. layout.
  221. The DefaultMap can also be thought of as Layer 0.
  222. PartialMaps are optional keymaps that can be "stacked" on top of the DefaultMap.
  223. They can be dynamically swapped out using the layer control capabilities:
  224. - layerLatch( `<layer number>` )
  225. - layerLock( `<layer number>` )
  226. - layerShift( `<layer number>` )
  227. layerShift is usually what you want as it works just like a standard shift key.
  228. layerLock is similar to the CapsLock key. While layerLatch is a latch, where only the next key you press
  229. will use that layer (e.g. stickykeys).
  230. A unique aspect of KLL layers is that it's a true stack of layers.
  231. When a layer is activated, only the keys that are specified by the layer will change.
  232. This means, if you define a layer that only sets `CapsLock -> LCtrl` and `LCtrl->Capslock` only those keys
  233. will change when you active the layer. All the other keys will use the layer that is "underneath" to
  234. lookup the keypress (usually the DefaultMap).
  235. This means that you can combine .kll files statically using the compiler or dynamically using the firmware.
  236. You can set the max number of layers by changing the `stateWordSize` define in one of your kll files.
  237. By default it is set to 8 in Macro/PartialMap/capabilities.kll. This means you can have up to 256 layers
  238. total (this includes the DefaultMap).
  239. You can increase this number to either 16 or 32 (this will use more Flash and RAM btw) which will give you
  240. 2^16 and 2^32 possible layers respectively (65 535 and 4 294 967 295).
  241. ```cmake
  242. ###
  243. # Keymap Configuration (do not include the .kll extension)
  244. #
  245. #| Do not include the .kll extension
  246. #| * BaseMap maps the native keyboard scan codes to USB Codes so the layout is compatible with all other layouts
  247. #| * DefaultMap allows the default keymap to be modified from the BaseMap
  248. #| * PartialMaps is a set of dynamically set layers (there is no limit, but too many may use up too much RAM...)
  249. #| BaseMap generally does not need to be changed from "defaultMap"
  250. #|
  251. #| Syntax:
  252. #| myMap
  253. #| * defines a single .kll layout file, double-quotes are needed to distinguish between layers
  254. #| "myMap specialLayer"
  255. #| * defines myMap to be the main layout, then replace specialLayers on top of it
  256. #|
  257. #| - Only for PartialMaps -
  258. #| "myMap specialLayer" "myMap colemak" dvorak
  259. #| * As before, but also generates a second layer at index 2 and third at index 3
  260. #|
  261. #| NOTE: Remember to add key(s) to enable each Partial Layer
  262. #| NOTE2: Layers are always based up the BaseMap (which should be an ANSI-like mapping)
  263. #| NOTE3: Compiler looks in kll/layouts and the build directory for layout files (precedence on build directory)
  264. ##| Set the base keyboard .kll map, defaults to "defaultMap" if not found
  265. ##| Looks in Scan/<Module Name> for the available BaseMaps
  266. set( BaseMap "defaultMap"
  267. CACHE STRING "KLL BaseMap/Scancode Keymapping" )
  268. ##| Layer additonal .kll maps on the BaseMap, layers are in order from 1st to nth
  269. ##| Can be set to ""
  270. set( DefaultMap "md1Overlay stdFuncMap"
  271. CACHE STRING "KLL DefaultMap" )
  272. ##| ParitalMaps available on top of the BaseMap. See above for syntax on specifying multiple layers vs. layering
  273. ##| Can be set to ""
  274. set( PartialMaps "hhkbpro2"
  275. CACHE STRING "KLL PartialMaps/Layer Definitions" )
  276. ```
  277. Linux Building
  278. --------------
  279. From this directory.
  280. ```bash
  281. $ mkdir build
  282. $ cd build
  283. $ cmake ..
  284. $ make
  285. ```
  286. Example output:
  287. ```
  288. $ cmake ..
  289. -- Compiler Family:
  290. arm
  291. -- Chip Selected:
  292. mk20dx128vlf5
  293. -- Chip Family:
  294. mk20dx
  295. -- CPU Selected:
  296. cortex-m4
  297. -- Compiler Source Files:
  298. Lib/mk20dx.c;Lib/delay.c
  299. -- Bootloader Type:
  300. dfu
  301. -- Detected Scan Module Source Files:
  302. Scan/MD1/scan_loop.c;Scan/MD1/../MatrixARM/matrix_scan.c
  303. -- Detected Macro Module Source Files:
  304. Macro/PartialMap/macro.c
  305. -- Detected Output Module Source Files:
  306. Output/pjrcUSB/output_com.c;Output/pjrcUSB/arm/usb_desc.c;Output/pjrcUSB/arm/usb_dev.c;
  307. Output/pjrcUSB/arm/usb_keyboard.c;Output/pjrcUSB/arm/usb_mem.c;Output/pjrcUSB/arm/usb_serial.c
  308. -- Detected Debug Module Source Files:
  309. Debug/full/../cli/cli.c;Debug/full/../led/led.c;Debug/full/../print/print.c
  310. -- Found Git: /usr/bin/git (found version "2.2.1")
  311. -- Found Ctags: /usr/bin/ctags (found version "5.8")
  312. -- Checking for latest kll version:
  313. Current branch master is up to date.
  314. -- Detected Layout Files:
  315. /home/hyatt/Source/controller/Macro/PartialMap/capabilities.kll
  316. /home/hyatt/Source/controller/Output/pjrcUSB/capabilities.kll
  317. /home/hyatt/Source/controller/Scan/MD1/defaultMap.kll
  318. /home/hyatt/Source/controller/kll/layouts/md1Overlay.kll
  319. /home/hyatt/Source/controller/kll/layouts/stdFuncMap.kll
  320. /home/hyatt/Source/controller/kll/layouts/hhkbpro2.kll
  321. -- Configuring done
  322. -- Generating done
  323. -- Build files have been written to: /home/hyatt/Source/controller/build
  324. [master]: make [~/Source/controller/build](hyatt@x230mas:pts/6)
  325. [ 5%] Generating KLL Layout
  326. Scanning dependencies of target kiibohd.elf
  327. [ 11%] Building C object CMakeFiles/kiibohd.elf.dir/main.c.o
  328. [ 17%] Building C object CMakeFiles/kiibohd.elf.dir/Lib/mk20dx.c.o
  329. [ 23%] Building C object CMakeFiles/kiibohd.elf.dir/Lib/delay.c.o
  330. [ 29%] Building C object CMakeFiles/kiibohd.elf.dir/Scan/MD1/scan_loop.c.o
  331. [ 35%] Building C object CMakeFiles/kiibohd.elf.dir/Scan/MatrixARM/matrix_scan.c.o
  332. [ 41%] Building C object CMakeFiles/kiibohd.elf.dir/Macro/PartialMap/macro.c.o
  333. [ 47%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/output_com.c.o
  334. [ 52%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/arm/usb_desc.c.o
  335. [ 58%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/arm/usb_dev.c.o
  336. [ 64%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/arm/usb_keyboard.c.o
  337. [ 70%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/arm/usb_mem.c.o
  338. [ 76%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/arm/usb_serial.c.o
  339. [ 82%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/cli/cli.c.o
  340. [ 88%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/led/led.c.o
  341. [ 94%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/print/print.c.o
  342. Linking C executable kiibohd.elf
  343. [ 94%] Built target kiibohd.elf
  344. Scanning dependencies of target SizeAfter
  345. [100%] Chip usage for mk20dx128vlf5
  346. SRAM: 32% 5384/16384 bytes
  347. Flash: 18% 23384/126976 bytes
  348. [100%] Built target SizeAfter
  349. ```
  350. Linux Loading Firmware
  351. ----------------------
  352. First place the keyboard into re-flash mode. This can be done either by
  353. pressing the re-flash button on the PCB/Teensy. Or by entering the Kiibohd
  354. Virtual Serial Port and using the 'reload' command.
  355. The `load` script that is created during the build can load the firmware over
  356. USB. Either run it with sudo, or install the `98-kiibohd.rules` to
  357. `/etc/udev/rules.d` and run: `udevadm control --reload-rules`.
  358. To load the newly built firmware: `./load`.
  359. Linux Building Bootloader
  360. -------------------------
  361. > NOTE: Does not apply to Teensy based builds.
  362. From this directory.
  363. ```bash
  364. $ cd Bootloader
  365. $ mkdir build
  366. $ cd build
  367. $ cmake ..
  368. $ make
  369. ```
  370. Example output:
  371. ```bash
  372. $ cmake ..
  373. -- Compiler Family:
  374. arm
  375. -- Chip Selected:
  376. mk20dx128vlf5
  377. -- Chip Family:
  378. mk20dx
  379. -- CPU Selected:
  380. cortex-m4
  381. -- Compiler Source Files:
  382. Lib/mk20dx.c;Lib/delay.c
  383. -- Bootloader Type:
  384. dfu
  385. -- Bootloader Source Files:
  386. main.c;dfu.c;dfu.desc.c;flash.c;kinetis.c;usb.c
  387. -- Found Git: /usr/bin/git (found version "2.2.1")
  388. -- Found Ctags: /usr/bin/ctags (found version "5.8")
  389. -- Configuring done
  390. -- Generating done
  391. -- Build files have been written to: /home/hyatt/Source/controller/Bootloader/build
  392. [master]: make [~/Source/controller/Bootloader/build](hyatt@x230mas:pts/6)
  393. Scanning dependencies of target kiibohd_bootloader.elf
  394. [ 11%] Building C object CMakeFiles/kiibohd_bootloader.elf.dir/main.c.o
  395. [ 22%] Building C object CMakeFiles/kiibohd_bootloader.elf.dir/dfu.c.o
  396. [ 33%] Building C object CMakeFiles/kiibohd_bootloader.elf.dir/dfu.desc.c.o
  397. [ 44%] Building C object CMakeFiles/kiibohd_bootloader.elf.dir/flash.c.o
  398. [ 55%] Building C object CMakeFiles/kiibohd_bootloader.elf.dir/kinetis.c.o
  399. [ 66%] Building C object CMakeFiles/kiibohd_bootloader.elf.dir/usb.c.o
  400. [ 77%] Building C object CMakeFiles/kiibohd_bootloader.elf.dir/home/hyatt/Source/controller/Lib/mk20dx.c.o
  401. [ 88%] Building C object CMakeFiles/kiibohd_bootloader.elf.dir/home/hyatt/Source/controller/Lib/delay.c.o
  402. Linking C executable kiibohd_bootloader.elf
  403. [ 88%] Built target kiibohd_bootloader.elf
  404. Scanning dependencies of target SizeAfter
  405. [100%] Chip usage for mk20dx128vlf5
  406. SRAM: 19% 3176/16384 bytes
  407. Flash: 2% 3736/126976 bytes
  408. [100%] Built target SizeAfter
  409. ```
  410. Linux Loading Bootloader
  411. ------------------------
  412. > NOTE: Does not apply to Teensy based builds.
  413. It's recommended to use an SWD-type flasher like a Bus Pirate. There is a
  414. convenience script for loading the firmware once the system is setup.
  415. ```bash
  416. $ cd Bootloader/Scripts
  417. $ ./swdLoad.bash
  418. ```
  419. The above script requires Ruby, Ruby serial port module, git, and a
  420. `/dev/buspirate` udev rule.
  421. Additional Notes:
  422. * https://github.com/mchck/mchck/wiki/Getting-Started (See Bus-Pirate section)
  423. * https://wiki.archlinux.org/index.php/Bus_pirate
  424. Windows Building
  425. ----------------
  426. From this directory.
  427. ```bash
  428. $ mkdir build
  429. $ cd build
  430. $ wincmake ..
  431. $ make
  432. ```
  433. Example output:
  434. ```bash
  435. $ wincmake ..
  436. -- Compiler Family:
  437. arm
  438. -- Chip Selected:
  439. mk20dx128vlf5
  440. -- Chip Family:
  441. mk20dx
  442. -- CPU Selected:
  443. cortex-m4
  444. -- Compiler Source Files:
  445. Lib/mk20dx.c;Lib/delay.c
  446. -- Bootloader Type:
  447. dfu
  448. -- Detected Scan Module Source Files:
  449. Scan/MD1/scan_loop.c;Scan/MD1/../MatrixARM/matrix_scan.c
  450. -- Detected Macro Module Source Files:
  451. Macro/PartialMap/macro.c
  452. -- Detected Output Module Source Files:
  453. 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
  454. -- Detected Debug Module Source Files:
  455. Debug/full/../cli/cli.c;Debug/full/../led/led.c;Debug/full/../print/print.c
  456. -- Found Git: C:/cygwin64/bin/git.exe (found version "2.1.1")
  457. -- Found Ctags: C:/cygwin64/bin/ctags.exe (found version "5.8")
  458. -- Checking for latest kll version:
  459. Current branch master is up to date.
  460. -- Detected Layout Files:
  461. C:/cygwin64/home/Jacob/controller/Macro/PartialMap/capabilities.kll
  462. C:/cygwin64/home/Jacob/controller/Output/pjrcUSB/capabilities.kll
  463. C:/cygwin64/home/Jacob/controller/Scan/MD1/defaultMap.kll
  464. C:/cygwin64/home/Jacob/controller/kll/layouts/md1Overlay.kll
  465. C:/cygwin64/home/Jacob/controller/kll/layouts/stdFuncMap.kll
  466. C:/cygwin64/home/Jacob/controller/kll/layouts/hhkbpro2.kll
  467. -- Configuring done
  468. -- Generating done
  469. -- Build files have been written to: C:/cygwin64/home/Jacob/controller/build
  470. $ make
  471. [ 5%] Generating KLL Layout
  472. Scanning dependencies of target kiibohd.elf
  473. [ 11%] Building C object CMakeFiles/kiibohd.elf.dir/main.c.obj
  474. [ 17%] Building C object CMakeFiles/kiibohd.elf.dir/Lib/mk20dx.c.obj
  475. [ 23%] Building C object CMakeFiles/kiibohd.elf.dir/Lib/delay.c.obj
  476. [ 29%] Building C object CMakeFiles/kiibohd.elf.dir/Scan/MD1/scan_loop.c.obj
  477. [ 35%] Building C object CMakeFiles/kiibohd.elf.dir/Scan/MatrixARM/matrix_scan.c.obj
  478. [ 41%] Building C object CMakeFiles/kiibohd.elf.dir/Macro/PartialMap/macro.c.obj
  479. [ 47%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/output_com.c.obj
  480. [ 52%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/arm/usb_desc.c.obj
  481. [ 58%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/arm/usb_dev.c.obj
  482. [ 64%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/arm/usb_keyboard.c.obj
  483. [ 70%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/arm/usb_mem.c.obj
  484. [ 76%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/arm/usb_serial.c.obj
  485. [ 82%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/cli/cli.c.obj
  486. [ 88%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/led/led.c.obj
  487. [ 94%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/print/print.c.obj
  488. Linking C executable kiibohd.elf
  489. [ 94%] Built target kiibohd.elf
  490. Scanning dependencies of target SizeAfter
  491. [100%] Chip usage for mk20dx128vlf5
  492. SRAM: 32% 5384/16384 bytes
  493. Flash: 18% 23296/126976 bytes
  494. [100%] Built target SizeAfter
  495. ```
  496. ### NOTES:
  497. If you get the following error, you have not setup wincmake correctly:
  498. ```bash
  499. $ make
  500. [ 5%] Generating KLL Layout
  501. Scanning dependencies of target kiibohd.elf
  502. [ 11%] Building C object CMakeFiles/kiibohd.elf.dir/main.c.o
  503. ../main.c:28:19: fatal error: macro.h: No such file or directory
  504. #include <macro.h>
  505. ^
  506. compilation terminated.
  507. CMakeFiles/kiibohd.elf.dir/build.make:67: recipe for target 'CMakeFiles/kiibohd.elf.dir/main.c.o' failed
  508. make[2]: *** [CMakeFiles/kiibohd.elf.dir/main.c.o] Error 1
  509. CMakeFiles/Makefile2:98: recipe for target 'CMakeFiles/kiibohd.elf.dir/all' failed
  510. make[1]: *** [CMakeFiles/kiibohd.elf.dir/all] Error 2
  511. Makefile:75: recipe for target 'all' failed
  512. make: *** [all] Error 2
  513. ```
  514. If you have already added the line to your `~/.bashrc` try restarting your
  515. cygwin shell.
  516. Windows Loading Firmware
  517. ------------------------
  518. First place the keyboard into re-flash mode. This can be done either by
  519. pressing the re-flash button on the PCB/Teensy. Or by entering the Kiibohd
  520. Virtual Serial Interface and using the `reload` command.
  521. The `load` script that is created during the build can load the firmware over
  522. USB.
  523. To load the newly built firmware: `./load`
  524. Be patient the couple of times, Windows is slow at installing drivers...
  525. Mac OS X Building
  526. -----------------
  527. From this directory.
  528. ```bash
  529. $ mkdir build
  530. $ cd build
  531. $ cmake ..
  532. $ make
  533. ```
  534. Example output:
  535. > TODO
  536. Mac OS X Loading Firmware
  537. -------------------------
  538. First place the keyboard into re-flash mode. This can be done either by
  539. pressing the re-flash button on the PCB/Teensy. Or by entering the Kiibohd
  540. Virtual Serial Port and using the `reload` command.
  541. The `load` script that is created during the build can load the firmware over
  542. USB.
  543. To load the newly built firmware: `./load`.
  544. Virtual Serial Port - CLI
  545. -------------------------
  546. Rather than use a special program that can interpret Raw HID, this controller exposes a USB Serial CDC endpoint.
  547. This allows for you to use a generic serial terminal to debug/control the keyboard firmware (e.g. Tera Term, minicom, screen)
  548. ### Linux
  549. I generally use screen. You will need sudo/root priviledges if you haven't
  550. installed the `98-kiibohd.rules` file to `/etc/udev/rules.d`.
  551. ```
  552. $ screen /dev/ttyACM0
  553. # (Might be ACM1, ACM2, etc.)
  554. ```
  555. ### Windows
  556. Make sure the Teensy Virtual Serial Port driver is installed. If possible use
  557. screen (as part of Cygwin). Check which COM port the virtual serial port has
  558. been assigned to: `Device Manager->Ports (COM & LPT)->Teensy USB Serial`. In
  559. brackets it will say which COM port (e.g. COM3)
  560. putty works well when using DTR/DSR or RTS/CTS flow control.
  561. | Setting | Value |
  562. | --------------- | ------------------------------------- |
  563. | Connection type | Serial |
  564. | Serial line | Your COM port, e.g. COM3 |
  565. | Speed | doesn't matter, it's auto-negotiated |
  566. Under `Category->Connections->Serial`: `Flow control: DTR/DSR`.
  567. If stuff is hard to read (you have a dumb colour scheme):
  568. `Category->Window->Colours->Use system color`. That seems to make text at
  569. least readable
  570. > I use a custom colour scheme that makes each colour easy to see.
  571. > -HaaTa.
  572. Unfortunately, screen for Cygwin seems to be broken for serial ports, but you
  573. can try it...
  574. ```bash
  575. $ screen /dev/ttyS2
  576. # Might be a different file, ttyS0, ttyACM0, ttyUSB0, etc.
  577. ```
  578. Gnu screen doesn't seem to echo all the characters (it works though).
  579. I believe it's a problem with stty, but I don't know how to fix it...
  580. ### Mac OS X
  581. I recommend screen (can be installed via Macports).
  582. ```bash
  583. $ screen /dev/tty.<usb something>
  584. ```