2013-10-05 20:53:06 +00:00
The Kiibohd Controller
----------------------
TODO, write some insightful/informative :P
Please give authors credit for modules used if you use in a distributed product :D
----------------------
Dependencies
----------------------
Below listed are the Arch Linux pacman names, AUR packages may be required.
These depend a bit on which targets you are trying to build, but the general one:
- cmake (2.8 and higher)
AVR Specific (Teensy 1.0/++,2.0/++) (try to use something recent, suggested versions below)
2014-04-18 20:16:47 +00:00
- avr-gcc (~4.8.0)
- avr-binutils (~2.23.2)
- avr-libc (~1.8.0)
2013-10-05 20:53:06 +00:00
2014-03-31 08:07:48 +00:00
ARM Specific (Teensy 3.0/3.1) (Sourcery CodeBench Lite for ARM EABI
2013-10-05 20:53:06 +00:00
(http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/)
- arm-none-eabi
2014-03-31 08:07:48 +00:00
OR
- arm-none-eabi-gcc
- arm-none-eaby-binutils
2014-04-10 04:06:57 +00:00
(I've actually had some issues with Sourcery CodeBench on Linux, so I often just use these)
----------------------
Windows Setup
----------------------
Compiling on Windows does work, just it's a bunch more work.
First make sure Cygwin is installed - http://www.cygwin.com/ - 32bit or 64bit is fine. Make sure the following are installed:
- make
- git (needed for some compilation info)
2014-04-18 01:49:40 +00:00
- cmake
- gcc-core
2014-05-27 05:46:03 +00:00
- gcc-g++
2014-04-18 20:16:47 +00:00
- libusb1.0
- libusb1.0-devel
2014-04-10 04:06:57 +00:00
2014-06-07 16:13:57 +00:00
Please note, I use cygwin term exclusively for any command line options. Unless mentioned otherwise use it.
Do NOT use CMD or Powershell.
2014-04-18 01:49:40 +00:00
Also install the Windows version of CMake - http://cmake.org/cmake/resources/software.html
This is in addition to the Cygwin version. This is an easier alternative to installing another C compiler.
Add the following line to your .bashrc, making sure the CMake path is correct:
2014-06-07 16:13:57 +00:00
echo "alias wincmake=\"PATH='/cygdrive/c/Program Files (x86)/CMake 2.8'/bin:\"${PATH}\" cmake" >> ~/.bashrc
2014-04-10 04:06:57 +00:00
2014-05-27 05:46:03 +00:00
Install the PJRC Virtual Serial Port Driver:
(http://pjrc.com/teensy/serial_install.exe)
2014-04-10 04:06:57 +00:00
Next, install the compiler(s) you want.
2014-04-18 20:16:47 +00:00
2014-04-10 04:06:57 +00:00
---------
| AVR GCC |
---------
You just need the Atmel AVR 8-bit Toolchain. The latest should be fine, as of writing it was 3.4.3.
http://www.atmel.com/tools/atmelavrtoolchainforwindows.aspx
2014-04-20 08:08:02 +00:00
(Atmel AVR 8-bit Toolchain 3.4.3 - Windows)
2014-04-10 04:06:57 +00:00
Extract the files to a directory, say C:\avr8-gnu-toolchain. Then copy all the folders in that directory to the Cygwin directory.
Mine is C:\cygwin64.
(You can also just setup the paths, but this is faster/simpler. Might screw up your Cygwin though).
----------
| ARM EABI |
----------
Download the latest version of Mentor Graphics Sourcery CodeBench ARM EABI.
http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/
2014-05-27 05:46:03 +00:00
Look for "Download the EABI Release".
Enter your info to get the download link.
Select the most recent download.
Then download the "IA32 Windows Installer".
2014-04-10 04:06:57 +00:00
Use the installer and make sure you add the binaries to your path within the installer.
2013-10-05 20:53:06 +00:00
----------------------
Selecting Microcontroller
----------------------
2014-04-19 05:57:14 +00:00
This is where you select the chip you want to compile for.
The build system will automatically select the compiler needed to compile for your chip.
2013-10-05 20:53:06 +00:00
2014-04-19 05:57:14 +00:00
Open up CMakeLists.txt in your favourite text editor.
2013-10-05 20:53:06 +00:00
You are looking for:
###
2014-04-19 05:57:14 +00:00
# Chip Selection
2013-10-05 20:53:06 +00:00
#
2014-04-19 05:57:14 +00:00
#| You _MUST_ set this to match the microcontroller you are trying to compile for
#| You _MUST_ clean the build directory if you change this value
2013-10-05 20:53:06 +00:00
#|
2014-04-19 05:57:14 +00:00
set( CHIP
# "at90usb162" # Teensy 1.0 (avr)
# "atmega32u4" # Teensy 2.0 (avr)
# "at90usb646" # Teensy++ 1.0 (avr)
"at90usb1286" # Teensy++ 2.0 (avr)
# "mk20dx128" # Teensy 3.0 (arm)
# "mk20dx256" # Teensy 3.1 (arm)
)
2013-10-05 20:53:06 +00:00
2014-04-19 05:57:14 +00:00
Just uncomment the chip you want, and comment out the old one.
2013-10-05 20:53:06 +00:00
NOTE: If you change this option, you will *need* to delete the build directory that is created in the Building sections below.
----------------------
Selecting Modules
----------------------
WARNING: Not all modules are compatible, and some modules may have dependencies on other modules.
This is where the options start getting interesting.
The Kiibohd Controller is designed around a set of 4 types of modules that correspond to different functionality:
- Scan Module
- Macro Module
2014-03-31 08:07:48 +00:00
- Output Module
2013-10-05 20:53:06 +00:00
- Debug Module
The Scan Module is where the most interesting stuff happens. These modules take in "keypress data".
A converter Scan Module will interpret a protocol into key press/releases.
A matrix Scan Module may inherit from the matrix module to scan keypress from a matrix
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).
Each Scan Module has it's own default keymap/modifier map. (TODO recommend keymap changing in the Macro Module).
2013-11-17 00:40:59 +00:00
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!).
2013-10-05 20:53:06 +00:00
2014-03-31 08:07:48 +00:00
The Macro Module takes care of the mapping of the key press/release code into an Output (USB) scan code.
2013-10-05 20:53:06 +00:00
Any layering, macros, keypress intelligence/reaction is done here.
2014-03-31 08:07:48 +00:00
The Output Module is the module dealing with output from the microcontroller. Currently USB is the only output protocol.
2013-10-05 20:53:06 +00:00
Different USB output implementations are available, pjrc being the safest/least featureful one.
Debug capabilities may depend on the module selected.
The Debug Module enables various things like the Teensy LED on errors, debug terminal output.
(TODO get true UART working in avr, not just arm)
2014-04-19 05:57:14 +00:00
Open up CMakeLists.txt in your favourite text editor.
2013-10-05 20:53:06 +00:00
Look for:
###
# Project Modules
#
#| Note: This is the only section you probably want to modify
#| Each module is defined by it's own folder (e.g. Scan/Matrix represents the "Matrix" module)
#| All of the modules must be specified, as they generate the sources list of files to compile
#| Any modifications to this file will cause a complete rebuild of the project
2014-03-31 08:07:48 +00:00
#| Please look at the {Scan,Macro,Output,Debug}/module.txt for information on the modules and how to create new ones
2013-10-05 20:53:06 +00:00
##| Deals with acquiring the keypress information and turning it into a key index
set( ScanModule "avr-capsense" )
##| Uses the key index and potentially applies special conditions to it, mapping it to a usb key code
set( MacroModule "buffer" )
##| Sends the current list of usb key codes through USB HID
2014-03-31 08:07:48 +00:00
set( OutputModule "pjrc" )
2013-10-05 20:53:06 +00:00
##| Debugging source to use, each module has it's own set of defines that it sets
set( DebugModule "full" )
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.
There are also CMake options for temporarily selecting modules. But it's easier to just edit the file.
e.g. cmake -DScanModuleOverride=<module name>
----------------------
Linux Building
----------------------
From this directory.
mkdir build
cd build
cmake ..
make
Example output:
[master]: cmake .. [...sy/avr-capsense-haata/build](hyatt@901Mas:pts/4)
-- Compiler Family:
avr
-- MCU Selected:
at90usb1286
-- Detected Scan Module Source Files:
Scan/avr-capsense/scan_loop.c
-- Detected Macro Module Source Files:
Macro/buffer/macro.c
2014-03-31 08:07:48 +00:00
-- Detected Output Module Source Files:
Output/pjrc/usb_com.c;Output/pjrc/avr/usb_keyboard_debug.c
2013-10-05 20:53:06 +00:00
-- Detected Debug Module Source Files:
Debug/full/../led/led.c;Debug/full/../print/print.c
-- Configuring done
-- Generating done
-- Build files have been written to: /home/hyatt/Source/Teensy/avr-capsense-haata/build
[master]: make [...sy/avr-capsense-haata/build](hyatt@901Mas:pts/4)
Scanning dependencies of target kiibohd.elf
[ 12%] Building C object CMakeFiles/kiibohd.elf.dir/main.c.o
[ 25%] Building C object CMakeFiles/kiibohd.elf.dir/Scan/avr-capsense/scan_loop.c.o
[ 37%] Building C object CMakeFiles/kiibohd.elf.dir/Macro/buffer/macro.c.o
2014-03-31 08:07:48 +00:00
[ 50%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrc/usb_com.c.o
[ 62%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrc/avr/usb_keyboard_debug.c.o
2013-10-05 20:53:06 +00:00
[ 75%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/led/led.c.o
[ 87%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/print/print.c.o
Linking C executable kiibohd.elf
Creating load file for Flash: kiibohd.hex
Creating Extended Listing: kiibohd.lss
Creating Symbol Table: kiibohd.sym
[ 87%] Built target kiibohd.elf
Scanning dependencies of target SizeAfter
[100%] Size after generation:
text data bss dec hex filename
0 6112 0 6112 17e0 kiibohd.hex
5792 320 852 6964 1b34 kiibohd.elf
[100%] Built target SizeAfter
----------------------
Linux Loading Firmware
----------------------
2014-05-27 05:46:03 +00:00
First place the keyboard into re-flash mode.
This can be done either by pressing the re-flash button on the PCB/Teensy.
Or by entering the Kiibohd Virtual Serial Port and using the 'reload' command.
2013-10-05 20:53:06 +00:00
The 'load' script that is created during the build can load the firmware over USB.
2014-05-27 05:46:03 +00:00
Either run it with sudo, or install the 98-kiibohd.rules to /etc/udev/rules.d
and run: udevadm control --reload-rules
2013-10-05 20:53:06 +00:00
2014-05-27 05:46:03 +00:00
To load the newly built firmware:
2013-10-05 20:53:06 +00:00
./load
----------------------
Windows Building
----------------------
2014-04-10 04:06:57 +00:00
From this directory.
mkdir build
cd build
2014-04-18 01:49:40 +00:00
wincmake -G "Unix Makefiles" ..
2014-06-07 16:13:57 +00:00
make
2014-04-10 04:06:57 +00:00
Example output:
$ cmake -G "Unix Makefiles" ..
-- Compiler Family:
avr
-- MCU Selected:
atmega32u4
-- CPU Selected:
megaAVR
-- Detected Scan Module Source Files:
Scan/SKM67001/../matrix/matrix_scan.c;Scan/SKM67001/../matrix/scan_loop.c
-- Detected Macro Module Source Files:
Macro/PartialMap/macro.c
-- Detected Output Module Source Files:
Output/pjrcUSB/output_com.c;Output/pjrcUSB/avr/usb_keyboard_serial.c
-- Detected Debug Module Source Files:
Debug/full/../cli/cli.c;Debug/full/../led/led.c;Debug/full/../print/print.c
-- Found Git: C:/cygwin64/bin/git.exe (found version "1.7.9")
-- Configuring done
-- Generating done
-- Build files have been written to: C:/cygwin64/home/jacob.alexander/src/capsense-beta/build
jacob.alexander@JALEXANDER2-LT ~/src/capsense-beta/build
$ make
Scanning dependencies of target kiibohd.elf
[ 10%] Building C object CMakeFiles/kiibohd.elf.dir/main.c.obj
[ 20%] Building C object CMakeFiles/kiibohd.elf.dir/Scan/matrix/matrix_scan.c.obj
[ 30%] Building C object CMakeFiles/kiibohd.elf.dir/Scan/matrix/scan_loop.c.obj
[ 40%] Building C object CMakeFiles/kiibohd.elf.dir/Macro/PartialMap/macro.c.obj
[ 50%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/output_com.c.obj
[ 60%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/avr/usb_keyboard_serial.c.obj
[ 70%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/cli/cli.c.obj
[ 80%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/led/led.c.obj
[ 90%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/print/print.c.obj
Linking C executable kiibohd.elf
Creating load file for Flash: kiibohd.hex
Creating Extended Listing: kiibohd.lss
Creating Symbol Table: kiibohd.sym
[ 90%] Built target kiibohd.elf
Scanning dependencies of target SizeAfter
[100%] Size after generation
Flash Usage: data (hex)
RAM Usage: data (elf)
text data bss dec hex filename
0 9738 0 9738 260a kiibohd.hex
7982 1756 264 10002 2712 kiibohd.elf
[100%] Built target SizeAfter
2013-10-05 20:53:06 +00:00
----------------------
Windows Loading Firmware
----------------------
2014-05-27 05:46:03 +00:00
First place the keyboard into re-flash mode.
This can be done either by pressing the re-flash button on the PCB/Teensy.
Or by entering the Kiibohd Virtual Serial Interface and using the 'reload' command.
The 'load' script that is created during the build can load the firmware over USB.
To load the newly built firmware:
./load
Be patient the couple of times, Windows is slow at installing drivers...
2013-10-05 20:53:06 +00:00
----------------------
Mac OS X Building
----------------------
TODO
2014-05-27 05:46:03 +00:00
2013-10-05 20:53:06 +00:00
----------------------
Mac OS X Loading Firmware
----------------------
TODO
2014-05-27 05:46:03 +00:00
2013-10-05 20:53:06 +00:00
----------------------
2014-04-10 04:06:57 +00:00
Virtual Serial Port - CLI
2013-10-05 20:53:06 +00:00
----------------------
2014-04-10 04:06:57 +00:00
Rather than use a special program that can interpret Raw HID, this controller exposes a USB Serial CDC endpoint.
This allows for you to use a generic serial terminal to debug/control the keyboard firmware (e.g. Tera Term, minicom, screen)
2014-05-27 05:46:03 +00:00
2014-04-10 04:06:57 +00:00
-------
| Linux |
-------
I generally use screen.
2014-06-07 16:13:57 +00:00
You will need sudo/root priviledges if you haven't installed the 98-kiibohd.rules file to /etc/udev/rules.d
2014-04-10 04:06:57 +00:00
2014-05-27 05:46:03 +00:00
screen /dev/ttyACM0
(Might be ACM1, ACM2, etc.)
2014-04-10 04:06:57 +00:00
---------
| Windows |
---------
2014-05-27 05:46:03 +00:00
Make sure the Teensy Virtual Serial Port driver is installed.
If possible use screen (as part of Cygwin).
screen /dev/ttyS3
(Might be a different file, ttyS0, ttyACM0, ttyUSB0, etc.)
2014-04-10 04:06:57 +00:00
2014-05-27 06:06:51 +00:00
Gnu screen doesn't seem to echo all the characters (it works though).
I believe it's a problem with stty, but I don't know how to fix it...
putty works well when using DTR/DSR or RTS/CTS flow control.
2014-04-10 04:06:57 +00:00
----------
| Mac OS X |
----------
2013-10-05 20:53:06 +00:00
2014-04-10 04:06:57 +00:00
TODO (What is the usual device name). screen if possible.
2013-10-05 20:53:06 +00:00