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

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