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 13KB

10 years ago
10 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. The Kiibohd Controller
  2. ----------------------
  3. TODO, write some insightful/informative :P
  4. Please give authors credit for modules used if you use in a distributed product :D
  5. ----------------------
  6. Dependencies
  7. ----------------------
  8. Below listed are the Arch Linux pacman names, AUR packages may be required.
  9. These depend a bit on which targets you are trying to build, but the general one:
  10. - cmake (2.8 and higher)
  11. AVR Specific (Teensy 1.0/++,2.0/++) (try to use something recent, suggested versions below)
  12. - avr-gcc (~4.8.0)
  13. - avr-binutils (~2.23.2)
  14. - avr-libc (~1.8.0)
  15. ARM Specific (Teensy 3.0/3.1) (Sourcery CodeBench Lite for ARM EABI
  16. (http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/)
  17. - arm-none-eabi
  18. OR
  19. - arm-none-eabi-gcc
  20. - arm-none-eaby-binutils
  21. (I've actually had some issues with Sourcery CodeBench on Linux, so I often just use these)
  22. ----------------------
  23. Windows Setup
  24. ----------------------
  25. Compiling on Windows does work, just it's a bunch more work.
  26. First make sure Cygwin is installed - http://www.cygwin.com/ - 32bit or 64bit is fine. Make sure the following are installed:
  27. - make
  28. - git (needed for some compilation info)
  29. - cmake
  30. - gcc-core
  31. - gcc-g++
  32. - libusb1.0
  33. - libusb1.0-devel
  34. Please note, I use cygwin term exclusively for any command line options. Unless mentioned otherwise use it.
  35. Do NOT use CMD or Powershell.
  36. Also install the Windows version of CMake - http://cmake.org/cmake/resources/software.html
  37. This is in addition to the Cygwin version. This is an easier alternative to installing another C compiler.
  38. Add the following line to your .bashrc, making sure the CMake path is correct:
  39. echo "alias wincmake=\"PATH='/cygdrive/c/Program Files (x86)/CMake 2.8'/bin:\"${PATH}\" cmake" >> ~/.bashrc
  40. Install the PJRC Virtual Serial Port Driver:
  41. (http://pjrc.com/teensy/serial_install.exe)
  42. Next, install the compiler(s) you want.
  43. ---------
  44. | AVR GCC |
  45. ---------
  46. You just need the Atmel AVR 8-bit Toolchain. The latest should be fine, as of writing it was 3.4.3.
  47. http://www.atmel.com/tools/atmelavrtoolchainforwindows.aspx
  48. (Atmel AVR 8-bit Toolchain 3.4.3 - Windows)
  49. Extract the files to a directory, say C:\avr8-gnu-toolchain. Then copy all the folders in that directory to the Cygwin directory.
  50. Mine is C:\cygwin64.
  51. (You can also just setup the paths, but this is faster/simpler. Might screw up your Cygwin though).
  52. ----------
  53. | ARM EABI |
  54. ----------
  55. Download the latest version of Mentor Graphics Sourcery CodeBench ARM EABI.
  56. http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/
  57. Look for "Download the EABI Release".
  58. Enter your info to get the download link.
  59. Select the most recent download.
  60. Then download the "IA32 Windows Installer".
  61. Use the installer and make sure you add the binaries to your path within the installer.
  62. ----------------------
  63. Selecting Microcontroller
  64. ----------------------
  65. This is where you select the chip you want to compile for.
  66. The build system will automatically select the compiler needed to compile for your chip.
  67. Open up CMakeLists.txt in your favourite text editor.
  68. You are looking for:
  69. ###
  70. # Chip Selection
  71. #
  72. #| You _MUST_ set this to match the microcontroller you are trying to compile for
  73. #| You _MUST_ clean the build directory if you change this value
  74. #|
  75. set( CHIP
  76. # "at90usb162" # Teensy 1.0 (avr)
  77. # "atmega32u4" # Teensy 2.0 (avr)
  78. # "at90usb646" # Teensy++ 1.0 (avr)
  79. "at90usb1286" # Teensy++ 2.0 (avr)
  80. # "mk20dx128" # Teensy 3.0 (arm)
  81. # "mk20dx256" # Teensy 3.1 (arm)
  82. )
  83. Just uncomment the chip you want, and comment out the old one.
  84. NOTE: If you change this option, you will *need* to delete the build directory that is created in the Building sections below.
  85. ----------------------
  86. Selecting Modules
  87. ----------------------
  88. WARNING: Not all modules are compatible, and some modules may have dependencies on other modules.
  89. This is where the options start getting interesting.
  90. The Kiibohd Controller is designed around a set of 4 types of modules that correspond to different functionality:
  91. - Scan Module
  92. - Macro Module
  93. - Output Module
  94. - Debug Module
  95. The Scan Module is where the most interesting stuff happens. These modules take in "keypress data".
  96. A converter Scan Module will interpret a protocol into key press/releases.
  97. A matrix Scan Module may inherit from the matrix module to scan keypress from a matrix
  98. 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).
  99. Each Scan Module has it's own default keymap/modifier map. (TODO recommend keymap changing in the Macro Module).
  100. 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!).
  101. The Macro Module takes care of the mapping of the key press/release code into an Output (USB) scan code.
  102. Any layering, macros, keypress intelligence/reaction is done here.
  103. The Output Module is the module dealing with output from the microcontroller. Currently USB is the only output protocol.
  104. Different USB output implementations are available, pjrc being the safest/least featureful one.
  105. Debug capabilities may depend on the module selected.
  106. The Debug Module enables various things like the Teensy LED on errors, debug terminal output.
  107. (TODO get true UART working in avr, not just arm)
  108. Open up CMakeLists.txt in your favourite text editor.
  109. Look for:
  110. ###
  111. # Project Modules
  112. #
  113. #| Note: This is the only section you probably want to modify
  114. #| Each module is defined by it's own folder (e.g. Scan/Matrix represents the "Matrix" module)
  115. #| All of the modules must be specified, as they generate the sources list of files to compile
  116. #| Any modifications to this file will cause a complete rebuild of the project
  117. #| Please look at the {Scan,Macro,Output,Debug}/module.txt for information on the modules and how to create new ones
  118. ##| Deals with acquiring the keypress information and turning it into a key index
  119. set( ScanModule "avr-capsense" )
  120. ##| Uses the key index and potentially applies special conditions to it, mapping it to a usb key code
  121. set( MacroModule "buffer" )
  122. ##| Sends the current list of usb key codes through USB HID
  123. set( OutputModule "pjrc" )
  124. ##| Debugging source to use, each module has it's own set of defines that it sets
  125. set( DebugModule "full" )
  126. 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.
  127. There are also CMake options for temporarily selecting modules. But it's easier to just edit the file.
  128. e.g. cmake -DScanModuleOverride=<module name>
  129. ----------------------
  130. Linux Building
  131. ----------------------
  132. From this directory.
  133. mkdir build
  134. cd build
  135. cmake ..
  136. make
  137. Example output:
  138. [master]: cmake .. [...sy/avr-capsense-haata/build](hyatt@901Mas:pts/4)
  139. -- Compiler Family:
  140. avr
  141. -- MCU Selected:
  142. at90usb1286
  143. -- Detected Scan Module Source Files:
  144. Scan/avr-capsense/scan_loop.c
  145. -- Detected Macro Module Source Files:
  146. Macro/buffer/macro.c
  147. -- Detected Output Module Source Files:
  148. Output/pjrc/usb_com.c;Output/pjrc/avr/usb_keyboard_debug.c
  149. -- Detected Debug Module Source Files:
  150. Debug/full/../led/led.c;Debug/full/../print/print.c
  151. -- Configuring done
  152. -- Generating done
  153. -- Build files have been written to: /home/hyatt/Source/Teensy/avr-capsense-haata/build
  154. [master]: make [...sy/avr-capsense-haata/build](hyatt@901Mas:pts/4)
  155. Scanning dependencies of target kiibohd.elf
  156. [ 12%] Building C object CMakeFiles/kiibohd.elf.dir/main.c.o
  157. [ 25%] Building C object CMakeFiles/kiibohd.elf.dir/Scan/avr-capsense/scan_loop.c.o
  158. [ 37%] Building C object CMakeFiles/kiibohd.elf.dir/Macro/buffer/macro.c.o
  159. [ 50%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrc/usb_com.c.o
  160. [ 62%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrc/avr/usb_keyboard_debug.c.o
  161. [ 75%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/led/led.c.o
  162. [ 87%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/print/print.c.o
  163. Linking C executable kiibohd.elf
  164. Creating load file for Flash: kiibohd.hex
  165. Creating Extended Listing: kiibohd.lss
  166. Creating Symbol Table: kiibohd.sym
  167. [ 87%] Built target kiibohd.elf
  168. Scanning dependencies of target SizeAfter
  169. [100%] Size after generation:
  170. text data bss dec hex filename
  171. 0 6112 0 6112 17e0 kiibohd.hex
  172. 5792 320 852 6964 1b34 kiibohd.elf
  173. [100%] Built target SizeAfter
  174. ----------------------
  175. Linux Loading Firmware
  176. ----------------------
  177. First place the keyboard into re-flash mode.
  178. This can be done either by pressing the re-flash button on the PCB/Teensy.
  179. Or by entering the Kiibohd Virtual Serial Port and using the 'reload' command.
  180. The 'load' script that is created during the build can load the firmware over USB.
  181. Either run it with sudo, or install the 98-kiibohd.rules to /etc/udev/rules.d
  182. and run: udevadm control --reload-rules
  183. To load the newly built firmware:
  184. ./load
  185. ----------------------
  186. Windows Building
  187. ----------------------
  188. From this directory.
  189. mkdir build
  190. cd build
  191. wincmake -G "Unix Makefiles" ..
  192. make
  193. Example output:
  194. $ cmake -G "Unix Makefiles" ..
  195. -- Compiler Family:
  196. avr
  197. -- MCU Selected:
  198. atmega32u4
  199. -- CPU Selected:
  200. megaAVR
  201. -- Detected Scan Module Source Files:
  202. Scan/SKM67001/../matrix/matrix_scan.c;Scan/SKM67001/../matrix/scan_loop.c
  203. -- Detected Macro Module Source Files:
  204. Macro/PartialMap/macro.c
  205. -- Detected Output Module Source Files:
  206. Output/pjrcUSB/output_com.c;Output/pjrcUSB/avr/usb_keyboard_serial.c
  207. -- Detected Debug Module Source Files:
  208. Debug/full/../cli/cli.c;Debug/full/../led/led.c;Debug/full/../print/print.c
  209. -- Found Git: C:/cygwin64/bin/git.exe (found version "1.7.9")
  210. -- Configuring done
  211. -- Generating done
  212. -- Build files have been written to: C:/cygwin64/home/jacob.alexander/src/capsense-beta/build
  213. jacob.alexander@JALEXANDER2-LT ~/src/capsense-beta/build
  214. $ make
  215. Scanning dependencies of target kiibohd.elf
  216. [ 10%] Building C object CMakeFiles/kiibohd.elf.dir/main.c.obj
  217. [ 20%] Building C object CMakeFiles/kiibohd.elf.dir/Scan/matrix/matrix_scan.c.obj
  218. [ 30%] Building C object CMakeFiles/kiibohd.elf.dir/Scan/matrix/scan_loop.c.obj
  219. [ 40%] Building C object CMakeFiles/kiibohd.elf.dir/Macro/PartialMap/macro.c.obj
  220. [ 50%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/output_com.c.obj
  221. [ 60%] Building C object CMakeFiles/kiibohd.elf.dir/Output/pjrcUSB/avr/usb_keyboard_serial.c.obj
  222. [ 70%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/cli/cli.c.obj
  223. [ 80%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/led/led.c.obj
  224. [ 90%] Building C object CMakeFiles/kiibohd.elf.dir/Debug/print/print.c.obj
  225. Linking C executable kiibohd.elf
  226. Creating load file for Flash: kiibohd.hex
  227. Creating Extended Listing: kiibohd.lss
  228. Creating Symbol Table: kiibohd.sym
  229. [ 90%] Built target kiibohd.elf
  230. Scanning dependencies of target SizeAfter
  231. [100%] Size after generation
  232. Flash Usage: data (hex)
  233. RAM Usage: data (elf)
  234. text data bss dec hex filename
  235. 0 9738 0 9738 260a kiibohd.hex
  236. 7982 1756 264 10002 2712 kiibohd.elf
  237. [100%] Built target SizeAfter
  238. ----------------------
  239. Windows Loading Firmware
  240. ----------------------
  241. First place the keyboard into re-flash mode.
  242. This can be done either by pressing the re-flash button on the PCB/Teensy.
  243. Or by entering the Kiibohd Virtual Serial Interface and using the 'reload' command.
  244. The 'load' script that is created during the build can load the firmware over USB.
  245. To load the newly built firmware:
  246. ./load
  247. Be patient the couple of times, Windows is slow at installing drivers...
  248. ----------------------
  249. Mac OS X Building
  250. ----------------------
  251. TODO
  252. ----------------------
  253. Mac OS X Loading Firmware
  254. ----------------------
  255. TODO
  256. ----------------------
  257. Virtual Serial Port - CLI
  258. ----------------------
  259. Rather than use a special program that can interpret Raw HID, this controller exposes a USB Serial CDC endpoint.
  260. This allows for you to use a generic serial terminal to debug/control the keyboard firmware (e.g. Tera Term, minicom, screen)
  261. -------
  262. | Linux |
  263. -------
  264. I generally use screen.
  265. You will need sudo/root priviledges if you haven't installed the 98-kiibohd.rules file to /etc/udev/rules.d
  266. screen /dev/ttyACM0
  267. (Might be ACM1, ACM2, etc.)
  268. ---------
  269. | Windows |
  270. ---------
  271. Make sure the Teensy Virtual Serial Port driver is installed.
  272. If possible use screen (as part of Cygwin).
  273. screen /dev/ttyS3
  274. (Might be a different file, ttyS0, ttyACM0, ttyUSB0, etc.)
  275. Gnu screen doesn't seem to echo all the characters (it works though).
  276. I believe it's a problem with stty, but I don't know how to fix it...
  277. putty works well when using DTR/DSR or RTS/CTS flow control.
  278. ----------
  279. | Mac OS X |
  280. ----------
  281. TODO (What is the usual device name). screen if possible.