4 This README is a bit long, just look at the sections you are interested in.
5 You only need to install avr-gcc if you want to build for the Teensy 2.0/2.0++.
6 Everything else needs an arm-none-eabi-gcc compiler (e.g. Infinity keyboard, Teensy 3.0/3.1, McHCK).
9 Linux is the ideal build environment (preferably recent'ish).
10 In the near future I'll make available an Arch Linux VM for building/manufacturing tests.
13 Building on Mac should be ok for 99% of users with Macports (haven't tried Brew).
14 The dfu Bootloader will not build correctly with the old version of arm-none-eabi-gcc that Macports currently has (4.7.3).
15 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).
17 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).
18 Cygwin is currently required along with some non-Cygwin compilers and utilities (because they are not available for Cygwin).
19 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.
20 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).
21 However, make sure that the flash size is no larger than 4096 Bytes or the bootloader will not work.
22 Things will likely break if there are *SPACES IN YOUR PATHS*. I install cygwin to C:\cygwin64.
23 If you are brave and have programming knowledge, I will accept patches to fix any issues regarding spaces in paths.
26 Please give authors credit for modules used if you use in a distributed product :D
30 ----------------------
32 ----------------------
34 Below listed are the Arch Linux pacman names, AUR packages may be required.
36 These depend a bit on which targets you are trying to build, but the general one:
37 - cmake (2.8 and higher)
39 - ctags (recommended, not required)
41 - libusb1.0 (and -devel)
45 AVR Specific (Teensy 1.0/++,2.0/++) (try to use something recent, suggested versions below)
47 - avr-binutils (~2.23.2)
51 ARM Specific (Teensy 3.0/3.1, Infinity Keyboard, McHCK)
53 Arch Linux / Mac Ports
55 - arm-none-eaby-binutils
58 (https://launchpad.net/gcc-arm-embedded/+download)
59 - gcc-arm-none-eabi (win32.zip)
63 ----------------------
65 ----------------------
67 Compiling on Windows does work, just it's a bunch more work.
69 First make sure Cygwin is installed - http://www.cygwin.com/ - 32bit or 64bit is fine. Make sure the following are installed:
71 - git (needed for some compilation info)
78 - ctags (recommended, not required)
80 Please note, I use cygwin term exclusively for any command line options. Unless mentioned otherwise, use it.
81 Do NOT use CMD or Powershell.
83 Also install the Windows version of CMake (3+ is ideal) - http://cmake.org/cmake/resources/software.html
84 Select "Do not add CMake to system PATH".
85 This is in addition to the Cygwin version. This is an easier alternative to installing another C compiler.
86 Add the following line to your .bashrc, making sure the CMake path is correct:
87 echo "alias wincmake=\"PATH='/cygdrive/c/Program Files (x86)/CMake'/bin:'${PATH}' cmake -G 'Unix Makefiles'\"" >> ~/.bashrc
89 Install the PJRC Virtual Serial Port Driver:
90 (http://pjrc.com/teensy/serial_install.exe)
92 Next, install the compiler(s) you want.
100 You just need the Atmel AVR 8-bit Toolchain. The latest should be fine, as of writing it was 3.4.3.
102 http://www.atmel.com/tools/atmelavrtoolchainforwindows.aspx
103 (Atmel AVR 8-bit Toolchain 3.4.3 - Windows)
105 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.
106 Mine is C:\cygwin64\usr\local.
107 (You can also just setup the paths, but this is faster/simpler. Might screw up your Cygwin though).
114 Download the latest GNU Tools for Embedded Processors gcc-arm-none-eabi.
116 https://launchpad.net/gcc-arm-embedded/+download
118 Download "gcc-arm-none-eabi*win32.zip".
120 Then extract all the folders/files in the zip to the Cygwin /usr/local directory.
121 Mine is C:\cygwin64\usr\local.
122 Or, you can setup paths using the installer (you have to be more careful, avoid spaces in paths).
126 ----------------------
128 ----------------------
130 One of the big benefits of using CMake is the ability to build multiple configurations (for different microcontrollers) at the same time.
131 The following sections explain in detail what each CMakeLists.txt configuration option does and what you can change it to.
132 However, it is possible to configure each of these options using the -D command line flag.
134 For example, to build the Infinity Keyboard default configuration:
138 cmake -DCHIP=mk20dx128vlf5 -DScanModule=MD1 -DMacroModule=PartialMap -DOutputModule=pjrcUSB -DDebugModule=full -DBaseMap=defaultMap -DDefaultMap="md1Overlay stdFuncMap" -DPartialMaps="hhkbpro2" ..
141 CMake defaults to the values specified in CMakeLists.txt if not overridden via the command line.
142 NOTE: On Windows, you will have to use "wincmake" instead of "cmake".
146 ----------------------
147 Selecting Microcontroller
148 ----------------------
150 This is where you select the chip you want to compile for.
151 The build system will automatically select the compiler needed to compile for your chip.
153 Open up CMakeLists.txt in your favourite text editor.
160 #| You _MUST_ set this to match the microcontroller you are trying to compile for
161 #| You _MUST_ clean the build directory if you change this value
164 # "at90usb162" # Teensy 1.0 (avr)
165 # "atmega32u4" # Teensy 2.0 (avr)
166 # "at90usb646" # Teensy++ 1.0 (avr)
167 # "at90usb1286" # Teensy++ 2.0 (avr)
168 # "mk20dx128" # Teensy 3.0 (arm)
169 "mk20dx128vlf5" # McHCK mk20dx128vlf5
170 # "mk20dx256" # Teensy 3.1 (arm)
171 CACHE STRING "Microcontroller Chip" )
173 Just uncomment the chip you want, and comment out the old one.
175 NOTE: If you change this option, you will *need* to delete the build directory that is created in the Building sections below.
179 ----------------------
181 ----------------------
183 WARNING: Not all modules are compatible, and some modules may have dependencies on other modules.
185 This is where the options start getting interesting.
186 The Kiibohd Controller is designed around a set of 4 types of modules that correspond to different functionality:
193 The Scan Module is where the most interesting stuff happens. These modules take in "keypress data".
194 A converter Scan Module will interpret a protocol into key press/releases.
195 A matrix Scan Module may inherit from the matrix module to scan keypress from a matrix
196 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).
197 Each Scan Module has it's own default keymap/modifier map. (TODO recommend keymap changing in the Macro Module).
199 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!).
202 The Macro Module takes care of the mapping of the key press/release code into an Output (USB) scan code.
203 Any layering, macros, keypress intelligence/reaction is done here.
206 The Output Module is the module dealing with output from the microcontroller. Currently USB is the only output protocol.
207 Different USB output implementations are available, pjrc being the safest/least featureful one.
208 Debug capabilities may depend on the module selected.
211 The Debug Module enables various things like the Teensy LED on errors, debug terminal output.
212 (TODO get true UART working in avr, not just arm)
216 Open up CMakeLists.txt in your favourite text editor.
223 #| Note: This is the only section you probably want to modify
224 #| Each module is defined by it's own folder (e.g. Scan/Matrix represents the "Matrix" module)
225 #| All of the modules must be specified, as they generate the sources list of files to compile
226 #| Any modifications to this file will cause a complete rebuild of the project
228 #| Please look at the {Scan,Macro,Output,Debug} for information on the modules and how to create new ones
230 ##| Deals with acquiring the keypress information and turning it into a key index
231 set( ScanModule "MD1"
232 CACHE STRING "Scan Module" )
234 ##| Provides the mapping functions for DefaultMap and handles any macro processing before sending to the OutputModule
235 set( MacroModule "PartialMap"
236 CACHE STRING "Macro Module" )
238 ##| Sends the current list of usb key codes through USB HID
239 set( OutputModule "pjrcUSB"
240 CACHE STRING "Output Module" )
242 ##| Debugging source to use, each module has it's own set of defines that it sets
243 set( DebugModule "full"
244 CACHE STRING "Debug Module" )
247 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.
250 There are also CMake options for temporarily selecting modules. But it's easier to just edit the file.
251 e.g. cmake -DScanModuleOverride=<module name>
255 ----------------------
257 ----------------------
268 [master]: cmake .. [...sy/avr-capsense-haata/build](hyatt@901Mas:pts/4)
273 -- Detected Scan Module Source Files:
274 Scan/avr-capsense/scan_loop.c
275 -- Detected Macro Module Source Files:
277 -- Detected Output Module Source Files:
278 Output/pjrc/usb_com.c;Output/pjrc/avr/usb_keyboard_debug.c
279 -- Detected Debug Module Source Files:
280 Debug/full/../led/led.c;Debug/full/../print/print.c
283 -- Build files have been written to: /home/hyatt/Source/Teensy/avr-capsense-haata/build
284 [master]: make [...sy/avr-capsense-haata/build](hyatt@901Mas:pts/4)
285 Scanning dependencies of target kiibohd.elf
286 [ 12%] Building C object CMakeFiles/kiibohd.elf.dir/main.c.o
287 [ 25%] Building C object CMakeFiles/kiibohd.elf.dir/Scan/avr-capsense/scan_loop.c.o
288 [ 37%] Building C object CMakeFiles/kiibohd.elf.dir/Macro/buffer/macro.c.o
289 [ 50%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrc/usb_com.c.o
290 [ 62%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrc/avr/usb_keyboard_debug.c.o
291 [ 75%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/led/led.c.o
292 [ 87%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/print/print.c.o
293 Linking C executable kiibohd.elf
294 Creating load file for Flash: kiibohd.hex
295 Creating Extended Listing: kiibohd.lss
296 Creating Symbol Table: kiibohd.sym
297 [ 87%] Built target kiibohd.elf
298 Scanning dependencies of target SizeAfter
299 [100%] Size after generation:
300 text data bss dec hex filename
301 0 6112 0 6112 17e0 kiibohd.hex
302 5792 320 852 6964 1b34 kiibohd.elf
303 [100%] Built target SizeAfter
307 ----------------------
308 Linux Loading Firmware
309 ----------------------
311 First place the keyboard into re-flash mode.
312 This can be done either by pressing the re-flash button on the PCB/Teensy.
313 Or by entering the Kiibohd Virtual Serial Port and using the 'reload' command.
315 The 'load' script that is created during the build can load the firmware over USB.
316 Either run it with sudo, or install the 98-kiibohd.rules to /etc/udev/rules.d
317 and run: udevadm control --reload-rules
320 To load the newly built firmware:
325 ----------------------
326 Linux Building Bootloader
327 ----------------------
329 *NOTE* Does not apply to Teensy based builds.
343 ----------------------
344 Linux Loading Bootloader
345 ----------------------
347 *NOTE* Does not apply to Teensy based builds.
349 It's recommended to use an SWD-type flasher like a Bus Pirate.
350 There is a convenience script for loading the firmware once the system is setup.
352 cd Bootloader/Scripts
355 The above script requires Ruby, Ruby serial port module, git, and a /dev/buspirate udev rule.
358 https://github.com/mchck/mchck/wiki/Getting-Started
359 https://wiki.archlinux.org/index.php/Bus_pirate
363 ----------------------
365 ----------------------
385 -- Compiler Source Files:
386 Lib/mk20dx.c;Lib/delay.c
389 -- Detected Scan Module Source Files:
390 Scan/MD1/scan_loop.c;Scan/MD1/../MatrixARM/matrix_scan.c
391 -- Detected Macro Module Source Files:
392 Macro/PartialMap/macro.c
393 -- Detected Output Module Source Files:
394 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
395 -- Detected Debug Module Source Files:
396 Debug/full/../cli/cli.c;Debug/full/../led/led.c;Debug/full/../print/print.c
397 -- Found Git: C:/cygwin64/bin/git.exe (found version "2.1.1")
398 -- Found Ctags: C:/cygwin64/bin/ctags.exe (found version "5.8")
399 -- Checking for latest kll version:
400 Current branch master is up to date.
401 -- Detected Layout Files:
402 C:/cygwin64/home/Jacob/controller/Macro/PartialMap/capabilities.kll
403 C:/cygwin64/home/Jacob/controller/Output/pjrcUSB/capabilities.kll
404 C:/cygwin64/home/Jacob/controller/Scan/MD1/defaultMap.kll
405 C:/cygwin64/home/Jacob/controller/kll/layouts/md1Overlay.kll
406 C:/cygwin64/home/Jacob/controller/kll/layouts/stdFuncMap.kll
407 C:/cygwin64/home/Jacob/controller/kll/layouts/hhkbpro2.kll
410 -- Build files have been written to: C:/cygwin64/home/Jacob/controller/build
412 Jacob@DenPC ~/controller/build
414 [ 5%] Generating KLL Layout
415 Scanning dependencies of target kiibohd.elf
416 [ 11%] Building C object CMakeFiles/kiibohd.elf.dir/main.c.obj
417 [ 17%] Building C object CMakeFiles/kiibohd.elf.dir/Lib/mk20dx.c.obj
418 [ 23%] Building C object CMakeFiles/kiibohd.elf.dir/Lib/delay.c.obj
419 [ 29%] Building C object CMakeFiles/kiibohd.elf.dir/Scan/MD1/scan_loop.c.obj
420 [ 35%] Building C object CMakeFiles/kiibohd.elf.dir/Scan/MatrixARM/matrix_scan.c.obj
421 [ 41%] Building C object CMakeFiles/kiibohd.elf.dir/Macro/PartialMap/macro.c.obj
422 [ 47%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/output_com.c.obj
423 [ 52%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/arm/usb_desc.c.obj
424 [ 58%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/arm/usb_dev.c.obj
425 [ 64%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/arm/usb_keyboard.c.obj
426 [ 70%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/arm/usb_mem.c.obj
427 [ 76%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/arm/usb_serial.c.obj
428 [ 82%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/cli/cli.c.obj
429 [ 88%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/led/led.c.obj
430 [ 94%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/print/print.c.obj
431 Linking C executable kiibohd.elf
432 [ 94%] Built target kiibohd.elf
433 Scanning dependencies of target SizeAfter
434 [100%] Chip usage for mk20dx128vlf5
435 SRAM: 32% 5384/16384 bytes
436 Flash: 18% 23296/126976 bytes
437 [100%] Built target SizeAfter
441 If you get the following error, you have not setup wincmake correctly:
444 [ 5%] Generating KLL Layout
445 Scanning dependencies of target kiibohd.elf
446 [ 11%] Building C object CMakeFiles/kiibohd.elf.dir/main.c.o
447 ../main.c:28:19: fatal error: macro.h: No such file or directory
450 compilation terminated.
451 CMakeFiles/kiibohd.elf.dir/build.make:67: recipe for target 'CMakeFiles/kiibohd.elf.dir/main.c.o' failed
452 make[2]: *** [CMakeFiles/kiibohd.elf.dir/main.c.o] Error 1
453 CMakeFiles/Makefile2:98: recipe for target 'CMakeFiles/kiibohd.elf.dir/all' failed
454 make[1]: *** [CMakeFiles/kiibohd.elf.dir/all] Error 2
455 Makefile:75: recipe for target 'all' failed
456 make: *** [all] Error 2
458 If you have already added the line to your ~/.bashrc try restarting your cygwin shell.
462 ----------------------
463 Windows Loading Firmware
464 ----------------------
466 First place the keyboard into re-flash mode.
467 This can be done either by pressing the re-flash button on the PCB/Teensy.
468 Or by entering the Kiibohd Virtual Serial Interface and using the 'reload' command.
470 The 'load' script that is created during the build can load the firmware over USB.
472 To load the newly built firmware:
475 Be patient the couple of times, Windows is slow at installing drivers...
479 ----------------------
481 ----------------------
495 ----------------------
496 Mac OS X Loading Firmware
497 ----------------------
499 First place the keyboard into re-flash mode.
500 This can be done either by pressing the re-flash button on the PCB/Teensy.
501 Or by entering the Kiibohd Virtual Serial Port and using the 'reload' command.
503 The 'load' script that is created during the build can load the firmware over USB.
506 To load the newly built firmware:
511 ----------------------
512 Virtual Serial Port - CLI
513 ----------------------
515 Rather than use a special program that can interpret Raw HID, this controller exposes a USB Serial CDC endpoint.
516 This allows for you to use a generic serial terminal to debug/control the keyboard firmware (e.g. Tera Term, minicom, screen)
523 I generally use screen.
524 You will need sudo/root priviledges if you haven't installed the 98-kiibohd.rules file to /etc/udev/rules.d
527 (Might be ACM1, ACM2, etc.)
534 Make sure the Teensy Virtual Serial Port driver is installed.
535 If possible use screen (as part of Cygwin).
536 Check which COM port the virtual serial port has been assigned to:
537 Device Manager->Ports (COM & LPT)->Teensy USB Serial
538 In brackets it will say which COM port (e.g. COM3)
541 putty works well when using DTR/DSR or RTS/CTS flow control.
542 Connection type: Serial
543 Serial line: <Your COM port, e.g. COM3>
544 Speed: (doesn't matter, it's auto-negotiated)
546 Under Category->Connections->Serial
547 Flow control: DTR/DSR
549 If stuff is hard to read (you have a dumb colour scheme):
550 Category->Window->Colours->Use system colur
551 That seems to make text at least readable (I use a custom colour scheme that makes each colour easy to see -HaaTa).
554 Unfortunately, screen for Cygwin seems to be broken for serial ports, but you can try it...
556 (Might be a different file, ttyS0, ttyACM0, ttyUSB0, etc.)
558 Gnu screen doesn't seem to echo all the characters (it works though).
559 I believe it's a problem with stty, but I don't know how to fix it...
566 I recommend screen (can be installed via Macports).
567 screen /dev/tty.<usb something>