diff options
Diffstat (limited to 'docs')
-rw-r--r-- | docs/BUILD_GUIDE.md | 103 | ||||
-rw-r--r-- | docs/CYGWIN_GUIDE.md | 352 | ||||
-rw-r--r-- | docs/FUSE.txt | 50 | ||||
-rw-r--r-- | docs/HAND_WIRE.md | 321 | ||||
-rw-r--r-- | docs/PCB_GUIDE.md | 151 | ||||
-rw-r--r-- | docs/POWER.txt | 62 | ||||
-rw-r--r-- | docs/TMK_README.md | 243 | ||||
-rw-r--r-- | docs/USB_NKRO.txt | 160 | ||||
-rw-r--r-- | docs/VAGRANT_GUIDE.md | 27 | ||||
-rw-r--r-- | docs/basic_how_keyboards_work.md | 96 | ||||
-rw-r--r-- | docs/build_old.md | 187 | ||||
-rw-r--r-- | docs/keycode.txt | 261 | ||||
-rw-r--r-- | docs/keymap_config_h_example.h | 8 | ||||
-rw-r--r-- | docs/keymap_makefile_example.mk | 21 | ||||
-rw-r--r-- | docs/keymap_old.md | 685 | ||||
-rw-r--r-- | docs/other_projects.md | 62 |
16 files changed, 2789 insertions, 0 deletions
diff --git a/docs/BUILD_GUIDE.md b/docs/BUILD_GUIDE.md new file mode 100644 index 0000000000..78cf00b917 --- /dev/null +++ b/docs/BUILD_GUIDE.md @@ -0,0 +1,103 @@ +# This guide has now been included in the main readme - please reference that one instead. + +## Build Environment Setup + +### Windows (Vista and later) +1. If you have ever installed WinAVR, uninstall it. +2. Install [MHV AVR Tools](https://infernoembedded.com/sites/default/files/project/MHV_AVR_Tools_20131101.exe). Disable smatch, but **be sure to leave the option to add the tools to the PATH checked**. +3. Install [MinGW](https://sourceforge.net/projects/mingw/files/Installer/mingw-get-setup.exe/download). During installation, uncheck the option to install a graphical user interface. **DO NOT change the default installation folder.** The scripts depend on the default location. +4. Clone this repository. [This link will download it as a zip file, which you'll need to extract.](https://github.com/qmk/qmk_firmware/archive/master.zip) Open the extracted folder in Windows Explorer. +5. Double-click on the 1-setup-path-win batch script to run it. You'll need to accept a User Account Control prompt. Press the spacebar to dismiss the success message in the command prompt that pops up. +6. Right-click on the 2-setup-environment-win batch script, select "Run as administrator", and accept the User Account Control prompt. This part may take a couple of minutes, and you'll need to approve a driver installation, but once it finishes, your environment is complete! +7. Future build commands should be run from the standard Windows command prompt, which you can find by searching for "command prompt" from the start menu or start screen. Ignore the "MHV AVR Shell". + +### Mac +If you're using [homebrew,](http://brew.sh/) you can use the following commands: + + brew tap osx-cross/avr + brew install avr-libc + brew install dfu-programmer + +This is the recommended method. If you don't have homebrew, [install it!](http://brew.sh/) It's very much worth it for anyone who works in the command line. + +You can also try these instructions: + +1. Install Xcode from the App Store. +2. Install the Command Line Tools from `Xcode->Preferences->Downloads`. +3. Install [DFU-Programmer][dfu-prog]. + +### Linux +Install AVR GCC, AVR libc, and dfu-progammer with your favorite package manager. + +Debian/Ubuntu example: + + sudo apt-get update + sudo apt-get install gcc-avr avr-libc dfu-programmer + +### Vagrant +If you have any problems building the firmware, you can try using a tool called Vagrant. It will set up a virtual computer with a known configuration that's ready-to-go for firmware building. OLKB does NOT host the files for this virtual computer. Details on how to set up Vagrant are in the [VAGRANT_GUIDE file](VAGRANT_GUIDE.md). + +## Verify Your Installation +1. If you haven't already, obtain this repository ([https://github.com/qmk/qmk_firmware](https://github.com/qmk/qmk_firmware)). You can either download it as a zip file and extract it, or clone it using the command line tool git or the Github Desktop application. +2. Open up a terminal or command prompt and navigate to the `qmk_firmware` folder using the `cd` command. The command prompt will typically open to your home directory. If, for example, you cloned the repository to your Documents folder, then you would type `cd Documents/qmk_firmware`. If you extracted the file from a zip, then it may be named `qmk_firmware-master` instead. +3. To confirm that you're in the correct location, you can display the contents of your current folder using the `dir` command on Windows, or the `ls` command on Linux or Mac. You should see several files, including `readme.md` and a `quantum` folder. From here, you need to navigate to the appropriate folder under `keyboards/`. For example, if you're building for a Planck, run `cd keyboards/planck`. +4. Once you're in the correct keyboard-specific folder, run the `make` command. This should output a lot of information about the build process. More information about the `make` command can be found below. + +## Customizing, Building, and Deploying Your Firmware + +### The Make command + +The `make` command is how you compile the firmware into a .hex file, which can be loaded by a dfu programmer (like dfu-progammer via `make dfu`) or the [Teensy loader](https://www.pjrc.com/teensy/loader.html) (only used with Teensys). You can run `make` from the root (`/`), your keyboard folder (`/keyboards/<keyboard>/`), or your keymap folder (`/keyboards/<keyboard>/keymaps/<keymap>/`) if you have a `Makefile` there (see the example [here](/doc/keymap_makefile_example.mk)). + +By default, this will generate a `<keyboard>_<keymap>.hex` file in whichever folder you run `make` from. These files are ignored by git, so don't worry about deleting them when committing/creating pull requests. + +* The "root" (`/`) folder is the qmk_firmware folder, in which are `doc`, `keyboard`, `quantum`, etc. +* The "keyboard" folder is any keyboard project's folder, like `/keyboards/planck`. +* The "keymap" folder is any keymap's folder, like `/keyboards/planck/keymaps/default`. + +Below is a list of the useful `make` commands in QMK: + +* `make` - cleans automatically and builds your keyboard and keymap depending on which folder you're in. This defaults to the "default" layout (unless in a keymap folder), and Planck keyboard in the root folder + * `make keyboard=<keyboard>` - specifies the keyboard (only to be used in root) + * `make keymap=<keymap>` - specifies the keymap (only to be used in root and keyboard folder - not needed when in keymap folder) +* `make quick` - skips the clean step (cannot be used immediately after modifying config.h or Makefiles) +* `make dfu` - (requires dfu-programmer) builds and flashes the keymap to your keyboard once placed in reset/dfu mode (button or press `KC_RESET`). This does not work for Teensy-based keyboards like the ErgoDox EZ. + * `keyboard=` and `keymap=` are compatible with this +* `make all-keyboards` - builds all keymaps for all keyboards and outputs status of each (use in root) +* `make all-keyboards-default` - builds all default keymaps for all keyboards and outputs status of each (use in root) +* `make all-keymaps [keyboard=<keyboard>]` - builds all of the keymaps for whatever keyboard folder you're in, or specified by `<keyboard>` +* `make all-keyboards-quick`, `make all-keyboards-default-quick` and `make all-keymaps-quick [keyboard=<keyboard>]` - like the normal "make-all-*" commands, but they skip the clean steps + +Other, less useful functionality: + +* `make COLOR=false` - turns off color output +* `make SILENT=true` - turns off output besides errors/warnings +* `make VERBOSE=true` - outputs all of the avr-gcc stuff (not interesting) + +### The Makefile + +There are 3 different `make` and `Makefile` locations: + +* root (`/`) +* keyboard (`/keyboards/<keyboard>/`) +* keymap (`/keyboards/<keyboard>/keymaps/<keymap>/`) + +The root contains the code used to automatically figure out which keymap or keymaps to compile based on your current directory and commandline arguments. It's considered stable, and shouldn't be modified. The keyboard one will contain the MCU set-up and default settings for your keyboard, and shouldn't be modified unless you are the producer of that keyboard. The keymap Makefile can be modified by users, and is optional. It is included automatically if it exists. You can see an example [here](/doc/keymap_makefile_example.mk) - the last few lines are the most important. The settings you set here will override any defaults set in the keyboard Makefile. **It is required if you want to run `make` in the keymap folder.** + +### The `config.h` file + +There are 2 `config.h` locations: + +* keyboard (`/keyboards/<keyboard>/`) +* keymap (`/keyboards/<keyboard>/keymaps/<keymap>/`) + +The keyboard `config.h` is included only if the keymap one doesn't exist. The format to use for your custom one [is here](/doc/keymap_config_h_example.h). If you want to override a setting from the parent `config.h` file, you need to do this: + +``` +#undef MY_SETTING +#define MY_SETTING 4 +``` + +For a value of `4` for this imaginary setting. So we `undef` it first, then `define` it. + +You can then override any settings, rather than having to copy and paste the whole thing. diff --git a/docs/CYGWIN_GUIDE.md b/docs/CYGWIN_GUIDE.md new file mode 100644 index 0000000000..05d71961a4 --- /dev/null +++ b/docs/CYGWIN_GUIDE.md @@ -0,0 +1,352 @@ +#Planck Advanced (but not too advanced) `cygwin` Users Guide +If you are a user of the [cygwin environment](https://cygwin.com) in Windows and want the freedom to use the latest tools available, then this is the guide for you. If compiling your own copy of the latest and greatest Gnu C Compiler makes you super happy, then this is the guide for you. If the command line make you smile, then this is the guide for you. + +This guide was written step by step as I went through the process on a `Windows 10` `x86_64` and a `Windows 7` `amd k10` based system. This should be generally applicable to to any `Windows` environment with `cygwin`. + +#####Do not skip steps. Do not move past a step until the previous step finishes successfully. + +Based on [avr-libc installation guide](http://www.nongnu.org/avr-libc/user-manual/install_tools.html) + +##Get the Required Packages +Download the `cygwin` setup ([x86_64](https://cygwin.com/setup-x86_64.exe)) and install the default system plus the following if they are not already selected: +- devel/git +- devel/gcc-core +- devel/gcc-g++ +- devel/flex +- devel/bison +- devel/make +- devel/texinfo +- devel/gettext-devel +- devel/automake +- devel/autoconfig +- devel/libtool +- text/gettext +- libs/libgcc1 +- interpreters/m4 +- web/wget +- archive/unzip + +The following sources will be required: +- [gmp](https://gmplib.org/) (6.1.0) +- [mpfr](http://www.mpfr.org/) (3.1.4) +- [mpc](http://www.multiprecision.org/) (1.0.3) +- [binutils](https://www.sourceware.org/binutils/) (2.26) +- [gcc](https://gcc.gnu.org/) (5.3.0) +- [avr-libc](http://www.nongnu.org/avr-libc/) (2.0.0) + +The `dfu-programmer` will be required to flash the new firmware +- [dfu-programmer](https://dfu-programmer.github.io/) (0.7.2) + +The set of commands below will create a directory (`~/local/avr`) for the sources you compile to be installed on the machine and a directory (`~/src`) for these source files to be stored. The commands then download the sources of the needed packages and unpack them. Note: the expand commands are different depending on if the packages are offered as a `bz2` or `gz` archive +``` +$ mkdir ~/local +$ mkdir ~/local/avr +$ mkdir ~/src +$ cd ~/src +$ wget https://gmplib.org/download/gmp/gmp-6.1.0.tar.bz2 +$ wget http://www.mpfr.org/mpfr-3.1.4/mpfr-3.1.4.tar.bz2 +$ wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz +$ wget http://ftp.gnu.org/gnu/binutils/binutils-2.26.tar.gz +$ wget http://mirror0.babylon.network/gcc/releases/gcc-5.3.0/gcc-5.3.0.tar.gz +$ wget http://download.savannah.gnu.org/releases/avr-libc/avr-libc-2.0.0.tar.bz2 +$ tar -xjf gmp-6.1.0.tar.bz2 +$ tar -xjf mpfr-3.1.4.tar.bz2 +$ tar -zxf mpc-1.0.3.tar.gz +$ tar -zxf binutils-2.26.tar.gz +$ tar -zxf gcc-5.3.0.tar.gz +$ tar -xjf avr-libc-2.0.0.tar.bz2 +``` + +##Setup the Build Environment +These commands will set up the install directory and the `PATH` variable, which will allow you to access your installed packages. Note: if you close the `cygwin` terminal window, you will need to rerun these commands, they are not permanent. +``` +$ PREFIX=$HOME/local/avr +$ export PREFIX +$ PATH=/usr/local/bin:/usr/local/lib:/usr/local/include:/bin:/lib:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS +$ PATH=$PATH:$PREFIX/bin:$PREFIX/lib +$ export PATH +``` + +##The `gcc` Required Math Library Packages +The following packages are required to be complied and installed in order to compile `gcc`. They are not sufficiently available through the `cygwin` package system, so we have to make them ourselves. They must be complied in this order because each one depends on the previous. Verfiy that for each package, `make check` returns all passing and no fails. + +###Build and Install `gmp` +``` +$ cd ~/src/gmp-6.1.0 +$ ./configure --enable-static --disable-shared +$ make +$ make check +$ make install +``` + +###Build and Install `mpfr` +``` +$ cd ~/src/mpfr-3.1.4 +$ ./configure --with-gmp-build=../gmp-6.1.0 --enable-static --disable-shared +$ make +$ make check +$ make install +``` + +###Build and Install `mpc` +``` +$ cd ~/src/mpc-1.0.3 +$ ./configure --with-gmp=/usr/local --with-mpfr=/usr/local --enable-static --disable-shared +$ make +$ make check +$ make install +``` + +##OPTIONAL Part +You can build and install a brand new `gcc` or you can use the one supplied by `cygwin`. This will take about 4-5 hours to compile (It is a "native build", so it does the entire build **3 times**. This takes a long while). + +###Build and Install `gcc` for Your Machine +``` +$ cd ~/src/gcc-5.3.0 +$ mkdir obj-local +$ cd obj-local +$ ../configure --enable-languages=c,c++ --with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local --enable-static --disable-shared +$ make +$ make install +``` +##End OPTIONAL Part + +###Build and Install `binutils` for Your Machine +``` +$ cd ~/src/binutils-2.26 +$ mkdir obj-local +$ cd obj-local +$ ../configure +$ make +$ make install +``` + +##Buliding `binutils`, `gcc`, and `avr-libc` for the AVR system +Now we can make the critical stuff for compiling our firmware: `binutils`, `gcc`, and `avr-libc` for the AVR architecture. These allow us to build and manipulate the firmware for the keyboard. + +###Build `binutils` for AVR +If you plan to build and install `avr-gdb` also, use the `gdb` install at the end of this guide as it also builds the `binutils` +``` +$ cd ~/src/binutils-2.26 +$ mkdir obj-avr +$ cd obj-avr +$ ../configure --prefix=$PREFIX --target=avr --disable-nls +$ make +$ make install +``` + +###Build `gcc` for AVR +``` +$ cd ~/src/gcc-5.3.0 +$ mkdir obj-avr +$ cd obj-avr +$ ../configure --prefix=$PREFIX --target=avr --enable-languages=c,c++ --with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local --enable-static --disable-shared --disable-nls --disable-libssp --with-dwarf2 +$ make +$ make install +``` + +###Build `avr-libc` for AVR +For building the `avr-libc`, we have to specify the host build system. In my case it is `x86_64-unknown-cygwin`. You can look for build system type in the `gcc` configure notes for the proper `--build` specification to pass when you configure `avr-libc`. +``` +$ cd ~/src/avr-libc-2.0.0 +$ ./configure --prefix=$PREFIX --build=x86_64-unknown-cygwin --host=avr +$ make +$ make install +``` + +##Building 'dfu-programmer' for flashing the firmware via USB and installing the drivers +We can either build our own, or use the precomplied binaries. The precompiled binaries don't play well with `cygwin` so it is better to build them ourselves. The procedure for the precompiled binaries is included at the end of this guide. + +### Build and Install the `libusb` +The `dfu-programmer` requires `libusb` so that it can interact with the USB system. These repos must be bootstrapped in order to create an appropriate `./configure` and `Makefile` for your system. +``` +$ cd ~/src +$ git clone https://github.com/libusb/libusb.git +$ cd libusb +$ ./bootstrap.sh +$ ./configure +$ make +$ make install +``` + +### Build and Install the `dfu-programmer` +``` +$ cd ~/src +$ git clone https://github.com/dfu-programmer/dfu-programmer.git +$ cd dfu-programmer +$ ./bootstrap.sh +$ ./configure +$ make +$ make install +``` + +Verify the installation with: +``` +$ which dfu-programmer +/usr/local/bin/dfu-programmer + +$ dfu-programmer +dfu-programmer 0.7.2 +https://github.com/dfu-programmer/dfu-programmer +Type 'dfu-programmer --help' for a list of commands + 'dfu-programmer --targets' to list supported target devices +``` +If you are not getting the above result, you will not be able to flash the firmware! + +###Install the USB drivers +The drivers are included in the windows binary version of [`dfu-programmer` 0.7.2](http://iweb.dl.sourceforge.net/project/dfu-programmer/dfu-programmer/0.7.2/dfu-programmer-win-0.7.2.zip). +``` +$ cd ~/src +$ wget http://iweb.dl.sourceforge.net/project/dfu-programmer/dfu-programmer/0.7.2/dfu-programmer-win-0.7.2.zip +$ unzip dfu-programmer-win-0.7.2.zip -d dfu-programmer-win-0.7.2 +``` + +or + +The official drivers are found in [Atmel's `FLIP` installer](http://www.atmel.com/images/Flip%20Installer%20-%203.4.7.112.exe). Download and then install `FLIP`. Upon installation, the drivers will be found in `C:\Program Files (x86)\Atmel\Flip 3.4.7\usb`. + +Then, from an **administrator-privileged** `Windows` terminal, run the following command (adjust the path for username, etc. as necessary) and accept the prompt that pops up: +``` +C:\> pnputil -i -a C:\cygwin64\home\Kevin\src\dfu-programmer-win-0.7.2\dfu-prog-usb-1.2.2\atmel_usb_dfu.inf +or +C:\> pnputil -i -a "C:\Program Files (x86)\Atmel\Flip 3.4.7\usb\atmel_usb_dfu.inf" +``` + +This should be the result: +``` +Microsoft PnP Utility + +Processing inf : atmel_usb_dfu.inf +Successfully installed the driver on a device on the system. +Driver package added successfully. +Published name : oem104.inf + + +Total attempted: 1 +Number successfully imported: 1 +``` + +Alternatively, the `Windows` driver can be installed when prompted by `Windows` when the keyboard is attached. Do not let `Windows` search for a driver; specify the path to search for a driver and point it to the `atmel_usb_dfu.inf` file. + +##Building and Flashing the Planck firmware! +If you did everything else right. This part should be a snap! Grab the latest sources from `github`, make the Plank firmware, then flash it. + +###Build Planck and Load the Firmware +``` +$ cd ~/src +$ git clone https://github.com/qmk/qmk_firmware.git +$ cd qmk_firmware/keyboards/planck +$ make +``` + +Make sure there are no errors. You should end up with this or something similar: +``` +Creating load file for Flash: planck.hex +avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature planck.elf planck.hex + +Creating load file for EEPROM: planck.eep +avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \ +--change-section-lma .eeprom=0 --no-change-warnings -O ihex planck.elf planck.eep || exit 0 + +Creating Extended Listing: planck.lss +avr-objdump -h -S -z planck.elf > planck.lss + +Creating Symbol Table: planck.sym +avr-nm -n planck.elf > planck.sym + +Size after: + text data bss dec hex filename + 18602 82 155 18839 4997 planck.elf + +-------- end -------- +``` + +If you do not get the above, you **did not** build the firmware, and you will have nothing to flash. If you have the fresh clone from `github`, it was probably something gone wrong in this install process, go check and see what didn't work and threw errors or what steps you might have missed. + +But if everything went OK, you are ready to flash! Press the reset button on the bottom of the Planck, wait two seconds, then: +``` +$ make dfu +``` +. +. +. +profit!!! + + + + + +##extra bits... + +###Installing Precompiled `dfu-programmer` Binaries (not recommended for `cygwin`) +To install the `dfu-programmer` from the binaries, we must get if from [the `dfu-programmer` website](https://dfu-programmer.github.io/) ([0.7.2](http://iweb.dl.sourceforge.net/project/dfu-programmer/dfu-programmer/0.7.2/dfu-programmer-win-0.7.2.zip)). + +Copy this file into your `cygwin` home\src directory. (For me, it is `C:\cygwin64\home\Kevin\src`), extract the files, move `dfu-programmer.exe` to `~/local/avr/bin`. Most obnoxiously, the `libusb0_x86.dll` and `libusb0.sys` need to be moved from `./dfu-prog-usb-1.2.2/x86/` to a directory in the `Windows` `PATH` and the `cygwin` `PATH`. This is because the `dfu-programmer` binary is `mingw` based, not `cygwin` based, so the `dlls` do not cooperate. I achieved acceptable pathing by moving the files to `C:\cygwin64\home\Kevin\local\avr\bin` Then, in a `WINDOWS` command prompt running (Adjusting your path for username, etc. as needed): +``` +C:\> set PATH=%PATH%;C:\cygwin64\home\Kevin\local\avr\bin +``` + +Then, rename `libusb0_x86.dll` to `libusb0.dll`. + +You can tell that you were successful by trying to execute 'dfu-programmer' from the 'cygwin' prompt: +``` +$ which dfu-programmer +/home/Kevin/local/avr/bin/dfu-programmer + +$ dfu-programmer +dfu-programmer 0.7.2 +https://github.com/dfu-programmer/dfu-programmer +Type 'dfu-programmer --help' for a list of commands + 'dfu-programmer --targets' to list supported target devices +``` + +If you are not getting the above result, you will not be able to flash the firmware! +- Try making sure your `PATH` variables are set correctly for both `Windows` and `cygwin`. +- Make sure the `dll` is named correctly. +- Do not extract it with `cygwin`'s `unzip` as it does not set the executable permission. If you did it anyway, do `chmod +x dfu-programmer.exe`. +- Still have problems? Try building it instead. + + +##Debugging Tools + +These tools are for debugging your firmware, etc. before flashing. Theoretically, it can save your memory from wearing out. However, these tool do not work 100% for the Planck firmware. + +### `gdb` for AVR +`gdb` has a simulator for AVR but it does not support all instructions (like WDT), so it immediately crashes when running the Planck firmware (because `lufa.c` disables the WDT in the first few lines of execution). But it can still be useful in debugging example code and test cases, if you know how to use it. + +``` +$ cd ~/src +$ git clone git://sourceware.org/git/binutils-gdb.git +$ cd binutils-gdb +$ mkdir obj-avr +$ cd obj-avr +$ ../configure --prefix=$PREFIX --target=avr --build=x86_64-unknown-cygwin --with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local --disable-nls --enable-static +$ make +$ make install +``` + +### `simulavr` +`simulavr` is an AVR simulator. It runs the complied AVR elfs. `simulavr` does not support the `atmega32u4` device... it does `atmega32` but that is not good enough for the firmware (no PORTE and other things), so you cannot run the Planck firmware. I use it to simulate ideas I have for features in separate test projects. + +This one is a major pain in the butt because it has a lot of dependencies and it is buggy. I will do my best to explain it but... it was hard to figure out. A few things need to be changed in the 'Makefile' to make it work in `cygwin`. + + +``` +$ cd ~/src +$ git clone https://github.com/Traumflug/simulavr.git +$ cd simulavr +$ ./bootstrap +$ ./configure --prefix=$PREFIX --enable-static --disable-tcl --disable-doxygen-doc +``` + Edit `src/Makefile.am` now so that `-no-undefined` is included (I did this by removing the SYS_MINGW conditional surrounding `libsim_la_LDFLAGS += -no-undefined` and `libsimulavr_la_LDFLAGS += -no-undefined \ libsimulavr_la_LIBADD += $(TCL_LIB)`. Also, `$(EXEEXT)` is added after `kbdgentables` in two places. + +``` +$ make +$ make install +``` + + +TODO: +- git repos for all sources +- command line magic for cygwin setup +- better options for `dfu-drivers` diff --git a/docs/FUSE.txt b/docs/FUSE.txt new file mode 100644 index 0000000000..99ddd2d186 --- /dev/null +++ b/docs/FUSE.txt @@ -0,0 +1,50 @@ +Atmega32u4 Fuse/Lock Bits for Planck/Atomic/Preonic +========================= + + Low Fuse: 0x5E + High Fuse: 0x99 + Extended Fuse: 0xF3 + Lock Byte: 0xFF + + +ATMega168P Fuse/Lock Bits +========================= +This configuration is from usbasploader's Makefile. + + HFUSE 0xD6 + LFUSE 0xDF + EFUSE 0x00 + LOCK 0x3F(intact) + +#--------------------------------------------------------------------- +# ATMega168P +#--------------------------------------------------------------------- +# Fuse extended byte: +# 0x00 = 0 0 0 0 0 0 0 0 <-- BOOTRST (boot reset vector at 0x1800) +# \+/ +# +------- BOOTSZ (00 = 2k bytes) +# Fuse high byte: +# 0xd6 = 1 1 0 1 0 1 1 0 +# ^ ^ ^ ^ ^ \-+-/ +# | | | | | +------ BODLEVEL 0..2 (110 = 1.8 V) +# | | | | + --------- EESAVE (preserve EEPROM over chip erase) +# | | | +-------------- WDTON (if 0: watchdog always on) +# | | +---------------- SPIEN (allow serial programming) +# | +------------------ DWEN (debug wire enable) +# +-------------------- RSTDISBL (reset pin is enabled) +# Fuse low byte: +# 0xdf = 1 1 0 1 1 1 1 1 +# ^ ^ \ / \--+--/ +# | | | +------- CKSEL 3..0 (external >8M crystal) +# | | +--------------- SUT 1..0 (crystal osc, BOD enabled) +# | +------------------ CKOUT (if 0: Clock output enabled) +# +-------------------- CKDIV8 (if 0: divide by 8) + + +# Lock Bits +# 0x3f = - - 1 1 1 1 1 1 +# \ / \-/ \-/ +# | | +----- LB 2..1 (No memory lock features enabled) +# | +--------- BLB0 2..1 (No restrictions for SPM or LPM accessing the Application section) +# +--------------- BLB1 2..1 (No restrictions for SPM or LPM accessing the Boot Loader section) + diff --git a/docs/HAND_WIRE.md b/docs/HAND_WIRE.md new file mode 100644 index 0000000000..17ef3116f9 --- /dev/null +++ b/docs/HAND_WIRE.md @@ -0,0 +1,321 @@ +# Quantum Hand-wiring Guide + +Parts list: +* *x* keyswitches (MX, Matias, Gateron, etc) +* *x* diodes +* Keyboard plate (metal, plastic, cardboard, etc) +* Wire (strained for wiring to the Teensy, anything for the rows/columns) +* Soldering iron set at 600ºF or 315ºC (if temperature-controlled) +* Resin-cored solder (leaded or lead-free) +* Adequate ventilation/a fan +* Tweezers (optional) +* Wire cutters/snippers + +## How the matrix works (why we need diodes) + +The microcontroller (in this case, the Teensy 2.0) will be setup up via the firmware to send a logical 1 to the columns, one at a time, and read from the rows, all at once - this process is called matrix scanning. The matrix is a bunch of open switches that, by default, don't allow any current to pass through - the firmware will read this as no keys being pressed. As soon as you press one key down, the logical 1 that was coming from the column the keyswitch is attached to gets passed through the switch and to the corresponding row - check out the following 2x2 example: + + Column 0 being scanned Column 1 being scanned + x x + col0 col1 col0 col1 + | | | | + row0 ---(key0)---(key1) row0 ---(key0)---(key1) + | | | | + row1 ---(key2)---(key3) row1 ---(key2)---(key3) + +The `x` represents that the column/row associated has a value of 1, or is HIGH. Here, we see that no keys are being pressed, so no rows get an `x`. For one keyswitch, keep in mind that one side of the contacts is connected to its row, and the other, its column. + +When we press `key0`, `col0` gets connected to `row0`, so the values that the firmware receives for that row is `0b01` (the `0b` here means that this is a bit value, meaning all of the following digits are bits - 0 or 1 - and represent the keys in that column). We'll use this notation to show when a keyswitch has been pressed, to show that the column and row are being connected: + + Column 0 being scanned Column 1 being scanned + x x + col0 col1 col0 col1 + | | | | + x row0 ---(-+-0)---(key1) row0 ---(-+-0)---(key1) + | | | | + row1 ---(key2)---(key3) row1 ---(key2)---(key3) + +We can now see that `row0` has an `x`, so has the value of 1. As a whole, the data the firmware receives when `key0` is pressed is + + col0: 0b01 + col1: 0b00 + │└row0 + └row1 + +A problem arises when you start pressing more than one key at a time. Looking at our matrix again, it should become pretty obvious: + + Column 0 being scanned Column 1 being scanned + x x + col0 col1 col0 col1 + | | | | + x row0 ---(-+-0)---(-+-1) x row0 ---(-+-0)---(-+-1) + | | | | + x row1 ---(key2)---(-+-3) x row1 ---(key2)---(-+-3) + + Remember that this ^ is still connected to row1 + +The data we get from that is: + + col0: 0b11 + col1: 0b11 + │└row0 + └row1 + +Which isn't accurate, since we only have 3 keys pressed down, not all 4. This behavior is called ghosting, and only happens in odd scenarios like this, but can be much more common on a bigger keyboard. The way we can get around this is by placing a diode after the keyswitch, but before it connects to its row. A diode only allows current to pass through one way, which will protect our other columns/rows from being activated in the previous example. We'll represent a dioded matrix like this; + + Column 0 being scanned Column 1 being scanned + x x + col0 col1 col0 col1 + │ │ | │ + (key0) (key1) (key0) (key1) + ! │ ! │ ! | ! │ + row0 ─────┴────────┘ │ row0 ─────┴────────┘ │ + │ │ | │ + (key2) (key3) (key2) (key3) + ! ! ! ! + row1 ─────┴────────┘ row1 ─────┴────────┘ + +In practical applications, the black line of the diode will be placed facing the row, and away from the keyswitch - the `!` in this case is the diode, where the gap represents the black line. A good way to remember this is to think of this symbol: `>|` + +Now when we press the three keys, invoking what would be a ghosting scenario: + + Column 0 being scanned Column 1 being scanned + x x + col0 col1 col0 col1 + │ │ │ │ + (┌─┤0) (┌─┤1) (┌─┤0) (┌─┤1) + ! │ ! │ ! │ ! │ + x row0 ─────┴────────┘ │ x row0 ─────┴────────┘ │ + │ │ │ │ + (key2) (┌─┘3) (key2) (┌─┘3) + ! ! ! ! + row1 ─────┴────────┘ x row1 ─────┴────────┘ + +Things act as they should! Which will get us the following data: + + col0: 0b01 + col1: 0b11 + │└row0 + └row1 + +The firmware can then use this correct data to detect what it should do, and eventually, what signals it needs to send to the OS. + +## The actual hand-wiring + +### Getting things in place + +When starting this, you should have all of your stabilisers and keyswitches already installed (and optionally keycaps). If you're using a Cherry-type stabiliser (plate-mounted only, obviously), you'll need to install that before your keyswitches. If you're using Costar ones, you can installed them afterwards. + +To make things easier on yourself, make sure all of the keyswitches are oriented the same way (if they can be - not all layouts support this). Despite this, it's important to remember that the contacts on the keyswitches are completely symmetrical. We'll be using the keyswitch's left side contact for wiring the rows, and the right side one for wiring the columns. + +Get your soldering iron heated-up and collect the rest of the materials from the part list at the beginning of the guide. Place your keyboard so that the bottoms of the keyswitches are accessible - it may be a good idea to place it on a cloth to protect your keyswitches/keycaps. + +Before continuing, plan out where you're going to place your Teensy. If you're working with a board that has a large (6.25u) spacebar, it may be a good idea to place it in-between switches against the plate. Otherwise, you may want to trim some of the leads on the keyswitches where you plan on putting it - this will make it a little harder to solder the wire/diodes, but give you more room to place the Teensy. + +### Preparing the diodes + +It's a little easier to solder the diodes in place if you bend them at a 90º angle immediately after the black line - this will help to make sure you put them on the right way (direction matters), and in the correct position. The diodes will look like this when bent (with longer leads): + + ┌─────┬─┐ + ───┤ │ ├─┐ + └─────┴─┘ │ + │ + +We'll be using the long lead at the bent end to connect it to the elbow (bent part) of the next diode, creating the row. + +### Soldering the diodes + +Starting at the top-left switch, place the diode (with tweezers if you have them) on the switch so that the diode itself is vertically aligned, and the black line is facing toward you. The straight end of the diode should be touching the left contact on the switch, and the bent end should be facing to the right and resting on the switch there, like this: + + │o + ┌┴┐ o + │ │ O + ├─┤ + └┬┘ + └───────────── + +Letting the diode rest, grab your solder, and touch both it and the soldering iron to the left contact at the same time - the rosin in the solder should make it easy for the solder to flow over both the diode and the keyswitch contact. The diode may move a little, and if it does, carefully position it back it place by grabbing the bent end of the diode - the other end will become hot very quickly. If you find that it's moving too much, using needle-nose pliers of some sort may help to keep the diode still when soldering. + +The smoke that the rosin releases is harmful, so be careful not to breath it or get it in your eyes/face. + +After soldering things in place, it may be helpful to blow on the joint to push the smoke away from your face, and cool the solder quicker. You should see the solder develop a matte (not shiney) surface as it solidifies. Keep in mind that it will still be very hot afterwards, and will take a couple minutes to be cool to touch. Blow on it will accelerate this process. + +When the first diode is complete, the next one will need to be soldered to both the keyswitch, and the previous diode at the new elbow. That will look something like this: + + │o │o + ┌┴┐ o ┌┴┐ o + │ │ O │ │ O + ├─┤ ├─┤ + └┬┘ └┬┘ + └────────────────┴───────────── + +After completing a row, use the wire cutters to trim the excess wire from the tops of the diodes, and from the right side on the final switch. This process will need to completed for each row you have. + +When all of the diodes are completely soldered, it's a good idea to quickly inspect each one to ensure that your solder joints are solid and sturdy - repairing things after this is possible, but more difficult. + +### Soldering the columns + +You'll have some options in the next process - it's a good idea to insulate the column wires (since the diodes aren't), but if you're careful enough, you can use exposed wires for the columns - it's not recommended, though. If you're using single-cored wire, stripping the plastic off of the whole wire and feeding it back on is probably the best option, but can be difficult depending on the size and materials. You'll want to leave parts of the wire exposed where you're going to be solder it onto the keyswitch. + +If you're using stranded wire, it's probably easiest to just use a lot of small wires to connect each keyswitch along the column. It's possible to use one and melt through the insulation, but this isn't recommended, will produce even more harmful fumes, and can ruin your soldering iron. + +Before beginning to solder, it helps to have your wire pre-bent (if using single-cored), or at least have an idea of how you're going to route the column (especially if you're making a staggered board). Where you go in particular doesn't matter too much, as we'll be basing our keymap definitions on how it was wired - just make sure every key in a particular row is in a unique column, and that they're in order from left to right. + +If you're not using any insulation, you can try to keep the column wires elevated, and solder them near the tips of the keyswitch contacts - if the wires are sturdy enough, they won't short out to the row wiring an diodes. + +### Wiring things to the Teensy + +Now that the matrix itself is complete, it's time to connect what you've done to the Teensy. You'll be needing the number of pins equal to your number of columns + your number of rows. There are some pins on the Teensy that are special, like D6 (the LED on the chip), or some of the UART, SPI, I2C, or PWM channels, but only avoid those if you're planning something in addition to a keyboard. If you're unsure about wanting to add something later, you should have enough pins in total to avoid a couple. + +The pins you'll absolutely have to avoid are: GND, VCC, AREF, and RST - all the others are usable and accessible in the firmware. + +Place the Teensy where you plan to put it - you'll have to cut wires to length in the next step, and you'll want to make sure they reach. + +Starting with the first column on the right side, measure out how much wire you'll need to connect it to the first pin on the Teensy - it helps to pick a side that you'll be able to work down, to keep the wires from overlapping too much. It may help to leave a little bit of slack so things aren't too tight. Cut the piece of wire, and solder it to the Teensy, and then the column - you can solder it anywhere along the column, but it may be easiest at the keyswitch. Just be sure the wire doesn't separate from the keyswitch when soldering. + +As you move from column to column, it'll be helpful to write the locations of the pins down. We'll use this data to setup the matrix in the future. + +When you're done with the columns, start with the rows in the same process, from top to bottom, and write them all down. Again, you can solder anywhere along the row, as long as it's after the diode - soldering before the diode (on the keyswitch side) will cause that row not to work. + +As you move along, be sure that the Teensy is staying in place - recutting and soldering the wires is a pain! + +### Getting some basic firmware set-up + +From here, you should have a working keyboard with the correct firmware. Before we attach the Teensy permanently to the keyboard, let's quickly get some firmware loaded onto the Teensy so we can test each keyswitch. + +To start out, download [the firmware](https://github.com/qmk/qmk_firmware/) - we'll be using my (Jack's) fork of TMK called QMK/Quantum. We'll be doing a lot from the Terminal/command prompt, so get that open, along with a decent text editor like [Sublime Text](http://www.sublimetext.com/). + +The first thing we're going to do is create a new project using the script in the root directory of the firmware. In your terminal, run this command with `<project_name>` replaced by the name of your project - it'll need to be different from any other project in the `keyboards/` folder: + + util/new_project.sh <project_name> + +You'll want to navigate to the `keyboards/<project_name>/` folder by typing, like the print-out from the script specifies: + + cd keyboards/<project_name> + +#### config.h + +The first thing you're going to want to modify is the `config.h` file. Find `MATRIX_ROWS` and `MATRIX_COLS` and change their definitions to match the dimensions of your keyboard's matrix. + +Farther down are `MATRIX_ROW_PINS` and `MATRIX_COL_PINS`. Change their definitions to match how you wired up your matrix (looking from the top of the keyboard, the rows run top-to-bottom and the columns run left-to-right). Likewise, change the definition of `UNUSED_PINS` to match the pins you did not use (this will save power). + +#### \<project_name\>.h + +The next file you'll want to look at is `<project_name>.h`. You're going to want to rewrite the `KEYMAP` definition - the format and syntax here is extremely important, so pay attention to how things are setup. The first half of the definition are considered the arguments - this is the format that you'll be following in your keymap later on, so you'll want to have as many k*xy* variables here as you do keys. The second half is the part that the firmware actually looks at, and will contain gaps depending on how you wired your matrix. + +We'll dive into how this will work with the following example. Say we have a keyboard like this: + + ┌───┬───┬───┐ + │ │ │ │ + ├───┴─┬─┴───┤ + │ │ │ + └─────┴─────┘ + +This can be described by saying the top row is 3 1u keys, and the bottom row is 2 1.5u keys. The difference between the two rows is important, because the bottom row has an unused column spot (3 v 2). Let's say that this is how we wired the columns: + + ┌───┬───┬───┐ + │ ┋ │ ┋ │ ┋ │ + ├─┋─┴─┬─┴─┋─┤ + │ ┋ │ ┋ │ + └─────┴─────┘ + +The middle column is unused on the bottom row in this example. Our `KEYMAP` definition would look like this: + + #define KEYMAP( \ + k00, k01, k02, \ + k10, k11, \ + ) \ + { \ + { k00, k01, k02 }, \ + { k10, KC_NO, k11 }, \ + } + +Notice how the top half is spaced to resemble our physical layout - this helps us understand which keys are associated with which columns. The bottom half uses the keycode `KC_NO` where there is no keyswitch wired in. It's easiest to keep the bottom half aligned in a grid to help us make sense of how the firmware actually sees the wiring. + +Let's say that instead, we wired our keyboard like this (a fair thing to do): + + ┌───┬───┬───┐ + │ ┋ │ ┋│ ┋ │ + ├─┋─┴─┬┋┴───┤ + │ ┋ │┋ │ + └─────┴─────┘ + +This would require our `KEYMAP` definition to look like this: + + #define KEYMAP( \ + k00, k01, k02, \ + k10, k11, \ + ) \ + { \ + { k00, k01, k02 }, \ + { k10, k11, KC_NO }, \ + } + +Notice how the `k11` and `KC_NO` switched places to represent the wiring, and the unused final column on the bottom row. Sometimes it'll make more sense to put a keyswitch on a particular column, but in the end, it won't matter, as long as all of them are accounted for. You can use this process to write out the `KEYMAP` for your entire keyboard - be sure to remember that your keyboard is actually backwards when looking at the underside of it. + +#### keymaps/default.c + +This is the actual keymap for your keyboard, and the main place you'll make changes as you perfect your layout. `default.c` is the file that gets pull by default when typing `make`, but you can make other files as well, and specify them by typing `make KEYMAP=<variant>`, which will pull `keymaps/<variant>.c`. + +The basis of a keymap is its layers - by default, layer 0 is active. You can activate other layers, the highest of which will be referenced first. Let's start with our base layer. + +Using our previous example, let's say we want to create the following layout: + + ┌───┬───┬───┐ + │ A │ 1 │ H │ + ├───┴─┬─┴───┤ + │ TAB │ SPC │ + └─────┴─────┘ + +This can be accomplished by using the following `keymaps` definition: + + const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = KEYMAP( /* Base */ + KC_A, KC_1, KC_H, \ + KC_TAB, KC_SPC \ + ), + }; + +Note that the layout of the keycodes is similar to the physical layout of our keyboard - this make it much easier to see what's going on. A lot of the keycodes should be fairly obvious, but for a full list of them, check out [tmk_code/doc/keycode.txt](https://github.com/qmk/qmk_firmware/blob/master/tmk_core/doc/keycode.txt) - there are also a lot of aliases to condense your keymap file. + +It's also important to use the `KEYMAP` function we defined earlier - this is what allows the firmware to associate our intended readable keymap with the actual wiring. + +#### Compiling your firmware + +After you've written out your entire keymap, you're ready to get the firmware compiled and onto your Teensy. Before compiling, you'll need to get your [development environment set-up](/doc/BUILD_GUIDE.md) - you can skip the dfu-programmer instructions, but you'll need to download and install the [Teensy Loader](https://www.pjrc.com/teensy/loader.html) to get the firmware on your Teensy. + +Once everything is installed, running `make` in the terminal should get you some output, and eventually a `<project_name>.hex` file in that folder. If you're having trouble with this step, see the end of the guide for the trouble-shooting section. + +Once you have your `<project_name>.hex` file, open up the Teensy loader application, and click the file icon. From here, navigate to your `QMK/keyboards/<project_name>/` folder, and select the `<project_name>.hex` file. Plug in your keyboard and press the button on the Teensy - you should see the LED on the device turn off once you do. The Teensy Loader app will change a little, and the buttons should be clickable - click the download button (down arrow), and then the reset button (right arrow), and your keyboard should be ready to go! + +#### Testing your firmware + +Carefully flip your keyboard over, open up a new text document, and try typing - you should get the characters that you put into your keymap. Test each key, and note the ones that aren't working. Here's a quick trouble-shooting guide for non-working keys: + +0. Flip the keyboard back over and short the keyswitch's contacts with a piece wire - this will eliminate the possibility of the keyswitch being bad and needing to be replaced. +1. Check the solder points on the keyswitch - these need to be plump and whole. If you touch it with a moderate amount of force and it comes apart, it's not strong enough. +2. Check the solder joints on the diode - if the diode is loose, part of your row may register, while the other may not. +3. Check the solder joints on the columns - if your column wiring is loose, part or all of the column may not work. +4. Check the solder joints on both sides of the wires going to/from the Teensy - the wires need to be fully soldered and connect to both sides. +5. Check the <project_name>.h file for errors and incorrectly placed `KC_NO`s - if you're unsure where they should be, instead duplicate a k*xy* variable. +6. Check to make sure you actually compiled the firmware and flashed the Teensy correctly. Unless you got error messages in the terminal, or a pop-up during flashing, you probably did everything correctly. + +If you've done all of these things, keep in mind that sometimes you might have had multiple things affecting the keyswitch, so it doesn't hurt to test the keyswitch by shorting it out at the end. + +#### Securing the Teensy, finishing your hardware, getting fancier firmware + +Now that you have a working board, it's time to get things in their permanent positions. I've often used liberal amounts of hot glue to secure and insulate things, so if that's your style, start spreading that stuff like butter. Otherwise, double-sided tape is always an elegant solution, and electrical tape is a distant second. Due to the nature of these builds, a lot of this part is up to you and how you planned (or didn't plan) things out. + +There are a lot of possibilities inside the firmware - check out the [readme](https://github.com/qmk/qmk_firmware/blob/master/readme.md) for a full feature list, and dive into the different project (Planck, Ergodox EZ, etc) to see how people use all of them. You can always stop by [the OLKB subreddit for help!](http://reddit.com/r/olkb) + +## Trouble-shooting compiling + +### Windows + +#### fork: Resource temporarily unavailable + +http://www.avrfreaks.net/forum/windows-81-compilation-error + +### Mac + +### Linux diff --git a/docs/PCB_GUIDE.md b/docs/PCB_GUIDE.md new file mode 100644 index 0000000000..16de711142 --- /dev/null +++ b/docs/PCB_GUIDE.md @@ -0,0 +1,151 @@ +# Planck Firmware Guide + +## Setting up the environment + +### Windows +1. Install [MHV AVR Tools](https://infernoembedded.com/sites/default/files/project/MHV_AVR_Tools_20131101.exe). Disable smatch, but **be sure to leave the option to add the tools to the PATH checked**. +2. Install [MinGW](https://sourceforge.net/projects/mingw/files/Installer/mingw-get-setup.exe/download). During installation, uncheck the option to install a graphical user interface. **DO NOT change the default installation folder.** The scripts depend on the default location. +3. Clone this repository. [This link will download it as a zip file, which you'll need to extract.](https://github.com/qmk/qmk_firmware/archive/master.zip) Open the extracted folder in Windows Explorer. +4. Right-click on the 1-setup-path-win batch script, select "Run as administrator", and accept the User Account Control prompt. Press the spacebar to dismiss the success message in the command prompt that pops up. +5. Right-click on the 2-setup-environment-win batch script, select "Run as administrator", and accept the User Account Control prompt. This part may take a couple of minutes, and you'll need to approve a driver installation, but once it finishes, your environment is complete! + + +### Mac + +If you're using homebrew, you can use the following commands: + + brew tap osx-cross/avr + brew install avr-libc + brew install dfu-programmer + +Otherwise, these instructions will work: + +1. Install Xcode from the App Store. +2. Install the Command Line Tools from `Xcode->Preferences->Downloads`. +3. Install [DFU-Programmer][dfu-prog]. + +### Linux +1. Install AVR GCC with your favorite package manager. +2. Install [DFU-Programmer][dfu-prog]. + +Note that, since it will be directly accessing USB hardware, the +`dfu-programmer` program needs to be run as root. + +## Verify Your Installation +1. Clone the following repository: https://github.com/qmk/qmk_firmware +2. Open a Terminal and `cd` into `qmk_firmware/keyboards/planck` +3. Run `make`. This should output a lot of information about the build process. + +## Using the built-in functions + +Here is a list of some of the functions available from the command line: + +* `make clean`: clean the environment - may be required in-between builds +* `make`: compile the code +* `make KEYMAP=<keymap>`: compile with the extended keymap file `extended_keymaps/extended_keymap_<keymap>.c` +* `make dfu`: build and flash the layout to the PCB +* `make dfu-force`: build and force-flash the layout to the PCB (may be require for first flash) + +Generally, the instructions to flash the PCB are as follows: + +1. Make changes to the appropriate keymap file +2. Save the file +3. `make clean` +4. Press the reset button on the PCB/press the key with the `RESET` keycode +5. `make <arguments> dfu` - use the necessary `KEYMAP=<keymap>` and/or `COMMON=true` arguments here. + +## Troubleshooting +If you see something like this + + 0 [main] sh 13384 sync_with_child: child 9716(0x178) died before initialization with status code 0xC0000142 + 440 [main] sh 13384 sync_with_child: *** child state waiting for longjmp + /usr/bin/sh: fork: Resource temporarily unavailable + +after running 'make' on Windows than you are encountering a very popular issue with WinAVR on Windows 8.1 and 10. +You can easily fix this problem by replacing msys-1.0.dll in WinAVR/utils/bin with [this one](http://www.madwizard.org/download/electronics/msys-1.0-vista64.zip). +Restart your system and everything should work fine! + + +If you see this + + dfu-programmer atmega32u4 erase + process_begin: CreateProcess(NULL, dfu-programmer atmega32u4 erase, ...) failed. + make (e=2): The system cannot find the file specified. + make: *** [dfu] Error 2 + +when trying to 'make dfu' on Windows you need to copy the dfu-programmer.exe to qmk_firmware/keyboards/planck. + + +## Quantum MK Firmware + +### Keymap + +Unlike the other keymaps, prefixing the keycodes with `KC_` is required. A full list of the keycodes is available [here](https://github.com/qmk/qmk_firmware/blob/master/tmk_core/doc/keycode.txt). For the keycodes available only in the extended keymap, see this [header file](https://github.com/qmk/qmk_firmware/blob/master/quantum/keymap_common.h). + +You can use modifiers with keycodes like this: + + LCTL(KC_C) + +Which will generate Ctrl+c. These are daisy-chainable, meaning you can do things like: + + LCTL(LALT(KC_C)) + +That will generate Ctrl+Alt+c. The entire list of these functions is here: + +* `LCTL()`: Left control +* `LSFT()` / `S()`: Left shift +* `LALT()`: Left alt/opt +* `LGUI()`: Left win/cmd +* `RCTL()`: Right control +* `RSFT()`: Right shift +* `RALT()`: Right alt/opt +* `RGUI()`: Right win/cmd + +`S(KC_1)`-like entries are useful in writing keymaps for the Planck. + +### Other keycodes + +A number of other keycodes have been added that you may find useful: + +* `CM_<key>`: the Colemak equivalent of a key (in place of `KC_<key>`), when using Colemak in software (`CM_O` generates `KC_SCLN`) +* `RESET`: jump to bootloader for flashing (same as press the reset button) +* `BL_STEP`: step through the backlight brightnesses +* `BL_<0-15>`: set backlight brightness to 0-15 +* `BL_DEC`: lower the backlight brightness +* `BL_INC`: raise the backlight brightness +* `BL_TOGG`: toggle the backlight on/off + +### Function layers + +The extended keymap extends the number of function layers from 32 to the near-infinite value of 256. Rather than using `FN<num>` notation (still available, but limited to `FN0`-`FN31`), you can use the `FUNC(<num>)` notation. `F(<num>)` is a shortcut for this. + +The function actions are unchanged, and you can see the full list of them [here](https://github.com/jackhumbert/tmk_keyboard/blob/master/common/action_code.h). They are explained in detail [here](https://github.com/jackhumbert/tmk_keyboard/blob/master/doc/keymap.md#2-action). + +### Macros + +Macros have been setup in the `keymaps/keymap_default.c` file so that you can use `M(<num>)` to access a macro in the `action_get_macro` section on your keymap. The switch/case structure you see here is required, and is setup for `M(0)` - you'll need to copy and paste the code to look like this (e.g. to support `M(3)`): + + switch(id) { + case 0: + return MACRODOWN(TYPE(KC_A), END); + break; + case 1: + return MACRODOWN(TYPE(KC_B), END); + break; + case 2: + return MACRODOWN(TYPE(KC_C), END); + break; + case 3: + return MACRODOWN(TYPE(KC_D), END); + break; + } + return MACRO_NONE; + +`MACRODOWN()` is a shortcut for `(record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE)` which tells the macro to execute when the key is pressed. Without this, the macro will be executed on both the down and up stroke. + +[cygwin]: https://www.cygwin.com/ +[mingw]: http://www.mingw.org/ +[mhv]: https://infernoembedded.com/products/avr-tools +[winavr]: http://winavr.sourceforge.net/ +[crosspack]: http://www.obdev.at/products/crosspack/index.html +[dfu-prog]: http://dfu-programmer.sourceforge.net/ diff --git a/docs/POWER.txt b/docs/POWER.txt new file mode 100644 index 0000000000..0abbbe48e8 --- /dev/null +++ b/docs/POWER.txt @@ -0,0 +1,62 @@ +Time to Sleep +============= +USB suspend no activity on USB line for 3ms +No Interaction no user interaction + matrix has no change + matrix has no switch on + + +AVR Power Management +==================== + +V-USB suspend + USB suspend + http://vusb.wikidot.com/examples + +MCUSR MCU Status Register + WDRF Watchdog Reset Flag + BORF + EXTRF + PORF Power-on Reset Flag + +SMCR Sleep Mode Control Register + SE Sleep Enable + SM2:0 + #define set_sleep_mode(mode) \ + #define SLEEP_MODE_IDLE (0) + #define SLEEP_MODE_ADC _BV(SM0) + #define SLEEP_MODE_PWR_DOWN _BV(SM1) + #define SLEEP_MODE_PWR_SAVE (_BV(SM0) | _BV(SM1)) + #define SLEEP_MODE_STANDBY (_BV(SM1) | _BV(SM2)) + #define SLEEP_MODE_EXT_STANDBY (_BV(SM0) | _BV(SM1) | _BV(SM2)) + + +ACSR Analog Comparator Control and Status Register + To disable Analog Comparator + ACSR = 0x80; + or + ACSR &= ~_BV(ACIE); + ACSR |= _BV(ACD); + + ACD: Analog Comparator Disable + When this bit is written logic one, the power to the Analog Comparator is + switched off. This bit can be set at any time to turn off the Analog + Comparator. This will reduce power consumption in Active and Idle mode. + When changing the ACD bit, the Analog Comparator Interrupt must be disabled + by clearing the ACIE bit in ACSR. Otherwise an interrupt can occur when + the bit is changed. + +DIDR1 Digital Input Disable Register 1 + AIN1D + AIN0D + When this bit is written logic one, the digital input buffer on the AIN1/0 pin is disabled. The corresponding PIN Register bit will always read as zero when this bit is set. When an analog signal is applied to the AIN1/0 pin and the digital input from this pin is not needed, this bit should be written logic one to reduce power consumption in the digital input buffer. + + +PRR Power Reduction Register + PRTWI + PRTIM2 + PRTIM0 + PRTIM1 + PRSPI + PRUSART0 + PRADC diff --git a/docs/TMK_README.md b/docs/TMK_README.md new file mode 100644 index 0000000000..e3438eda2b --- /dev/null +++ b/docs/TMK_README.md @@ -0,0 +1,243 @@ +# TMK Documenation + +Features +-------- +These features can be used in your keyboard. + +* Multi-layer Keymap - Multiple keyboard layouts with layer switching +* Mouse key - Mouse control with keyboard +* System Control Key - Power Down, Sleep, Wake Up and USB Remote Wake up +* Media Control Key - Volume Down/Up, Mute, Next/Prev track, Play, Stop and etc +* USB NKRO - 120 keys(+ 8 modifiers) simultaneously +* PS/2 mouse support - PS/2 mouse(TrackPoint) as composite device +* Keyboard protocols - PS/2, ADB, M0110, Sun and other old keyboard protocols +* User Function - Customizable function of key with writing code +* Macro - Very primitive at this time +* Keyboard Tricks - Oneshot modifier and modifier with tapping feature +* Debug Console - Messages for debug and interaction with firmware +* Virtual DIP Switch - Configurations stored EEPROM(Boot Magic) +* Locking CapsLock - Mechanical switch support for CapsLock +* Breathing Sleep LED - Sleep indicator with charm during USB suspend +* Backlight - Control backlight levels + + + +Projects +-------- +You can find some keyboard specific projects under `converter` and `keyboard` directory. + +## Main projects + +### OLKB products +* [planck](keyboards/planck/) - [Planck] Ortholinear 40% keyboard +* [preonic](keyboards/preonic/) - [Preonic] Ortholinear 50% keyboard +* [atomic](keyboards/atomic/) - [Atomic] Ortholinear 60% keyboard + +### Ergodox EZ +* [ergodox_ez](keyboards/ergodox/ez) - [Ergodox_EZ] Assembled split keyboard + +## Other projects + +### converter +* [ps2_usb](converter/ps2_usb/) - [PS/2 keyboard to USB][GH_ps2] +* [adb_usb](converter/adb_usb/) - [ADB keyboard to USB][GH_adb] +* [m0110_usb](converter/m0110_usb) - [Macintosh 128K/512K/Plus keyboard to USB][GH_m0110] +* [terminal_usb](converter/terminal_usb/) - [IBM Model M terminal keyboard(PS/2 scancode set3) to USB][GH_terminal] +* [news_usb](converter/news_usb/) - [Sony NEWS keyboard to USB][GH_news] +* [x68k_usb](converter/x68k_usb/) - [Sharp X68000 keyboard to USB][GH_x68k] +* [sun_usb](converter/sun_usb/) - [Sun] to USB(type4, 5 and 3?) +* [pc98_usb](converter/pc98_usb/) - [PC98] to USB +* [usb_usb](converter/usb_usb/) - USB to USB(experimental) +* [ascii_usb](converter/ascii_usb/) - ASCII(Serial console terminal) to USB +* [ibm4704_usb](converter/ibm4704_usb) - [IBM 4704 keyboard Converter][GH_ibm4704] + +### keyboard +* [hhkb](keyboards/hhkb/) - [Happy Hacking Keyboard pro][GH_hhkb] hasu's main board +* [gh60](keyboards/gh60/) - [GH60] DIY 60% keyboard [prototype][GH60_proto] hasu's second board +* [hbkb](keyboards/hbkb/) - [Happy Buckling spring keyboard][GH_hbkb](IBM Model M 60% mod) +* [hid_liber](keyboards/hid_liber/) - [HID liberation][HID_liber] controller (by alaricljs) +* [phantom](keyboards/phantom/) - [Phantom] keyboard (by Tranquilite) +* [IIgs_Standard](keyboards/IIgs/) - Apple [IIGS] keyboard mod(by JeffreySung) +* [macway](keyboards/macway/) - [Compact keyboard mod][GH_macway] [retired] +* [KMAC](keyboards/kmac/) - Korean custom keyboard +* [Lightsaber](keyboards/lightsaber/) - Korean custom keyboard +* [Infinity](keyboards/infinity/) - Massdrop [Infinity keyboard][Infinity] +* [NerD](keyboards/nerd/) - Korean custom keyboard +* [KittenPaw](keyboards/kitten_paw) - Custom Majestouch controller +* [Lightpad](keyboards/lightpad) - Korean custom keypad +* [ghost_squid](keyboards/ghost_squid/) - [The Ghost Squid][ghost_squid] controller for [Cooler Master QuickFire XT][cmxt] + +### Extenal projects using tmk_keyboard +* [ErgoDox_cub-uanic][cub-uanic] - Split Ergonomic Keyboard [ErgoDox][ergodox_org] +* [mcdox][mcdox_tmk] - [mcdox][mcdox] + + +[GH_macway]: http://geekhack.org/showwiki.php?title=Island:11930 +[GH_hhkb]: http://geekhack.org/showwiki.php?title=Island:12047 +[GH_ps2]: http://geekhack.org/showwiki.php?title=Island:14618 +[GH_adb]: http://geekhack.org/showwiki.php?title=Island:14290 +[GH_hhkb_bt]: http://geekhack.org/showwiki.php?title=Island:20851 +[GH_m0110]: http://geekhack.org/showwiki.php?title=Island:24965 +[GH_news]: http://geekhack.org/showwiki.php?title=Island:25759 +[GH_terminal]: http://geekhack.org/showwiki.php?title=Island:27272 +[GH_x68k]: http://geekhack.org/showwiki.php?title=Island:29060 +[GH_hbkb]: http://geekhack.org/showwiki.php?title=Island:29483 +[GH_ibm4704]: http://geekhack.org/index.php?topic=54706.0 +[HID_liber]: http://deskthority.net/wiki/HID_Liberation_Device_-_DIY_Instructions +[Phantom]: http://geekhack.org/index.php?topic=26742 +[GH60]: http://geekhack.org/index.php?topic=34959 +[GH60_proto]: http://geekhack.org/index.php?topic=37570.0 +[PC98]: http://en.wikipedia.org/wiki/NEC_PC-9801 +[Sun]: http://en.wikipedia.org/wiki/Sun-3 +[IIGS]: http://en.wikipedia.org/wiki/Apple_IIGS +[Infinity]: https://www.massdrop.com/buy/infinity-keyboard-kit +[ghost_squid]: http://deskthority.net/wiki/Costar_replacement_controllers#The_Ghost_Squid +[cmxt]: http://gaming.coolermaster.com/en/products/keyboard/quickfirext/ +[ergodox_org]: http://ergodox.org/ +[cub-uanic]: https://github.com/cub-uanic/tmk_keyboard/tree/master/keyboard/ergodox +[mcdox]: https://github.com/DavidMcEwan/mcdox +[mcdox_tmk]: https://github.com/DavidMcEwan/tmk_keyboard/tree/master/keyboard/mcdox +[Planck]: http://olkb.co/planck +[Preonic]: http://olkb.co/preonic +[Atomic]: http://olkb.co/atomic +[Ergodox_EZ]: https://www.indiegogo.com/projects/ergodox-ez-an-incredible-mechanical-keyboard + + +License +------- +**GPLv2** or later. Some protocol files are under **Modified BSD License**. + +Third party libraries like LUFA, PJRC and V-USB have their own license respectively. + + + +Build Firmware and Program Controller +------------------------------------- +See [build environment setup](/readme.md#build-environment-setup), or the readme in the particular keyboards/* folder. + + + +Change your keymap +------------------ +See [doc/keymap.md](tmk_core/doc/keymap.md). + + + +Magic Commands +-------------- +To see help press `Magic` + `H`. + +`Magic` key combination is `LShift` + `RShift` in many project, but `Power` key on ADB converter. +`Magic` keybind can be vary on each project, check `config.h` in project directory. + +Following commands can be also executed with `Magic` + key. In console mode `Magic` keybind is not needed. + + ----- Command Help ----- + c: enter console mode + d: toggle debug enable + x: toggle matrix debug + k: toggle keyboard debug + m: toggle mouse debug + v: print device version & info + t: print timer count + s: print status + e: print eeprom config + n: toggle NKRO + 0/F10: switch to Layer0 + 1/F1: switch to Layer1 + 2/F2: switch to Layer2 + 3/F3: switch to Layer3 + 4/F4: switch to Layer4 + PScr: power down/remote wake-up + Caps: Lock Keyboard(Child Proof) + Paus: jump to bootloader + + + +Boot Magic Configuration - Virtual DIP Switch +--------------------------------------------- +Boot Magic are executed during boot up time. Press Magic key below then plug in keyboard cable. +Note that you must use keys of **Layer 0** as Magic keys. These settings are stored in EEPROM so that retain your configure over power cycles. + +To avoid configuring accidentally additive salt key `KC_SPACE` also needs to be pressed along with the following configuration keys. The salt key is configurable in `config.h`. See [tmk_core/common/bootmagic.h](tmk_core/common/bootmagic.h). + +#### General +- Skip reading EEPROM to start with default configuration(`ESC`) +- Clear configuration stored in EEPROM to reset configuration(`Backspace`) + +#### Bootloader +- Kick up Bootloader(`B`) + +#### Debug +- Debug enable(`D`) +- Debug matrix enable(`D`+`X`) +- Debug keyboard enable(`D`+`K`) +- Debug mouse enable(`D`+`M`) + +#### Keymap +- Swap Control and CapsLock(`Left Control`) +- Change CapsLock to Control(`Caps Lock`) +- Swap LeftAlt and Gui(`Left Alt`) +- Swap RightAlt and Gui(`Right Alt`) +- Disable Gui(`Left Gui`) +- Swap Grave and Escape(`Grave`) +- Swap BackSlash and BackSpace(`Back Slash`) +- Enable NKRO on boot(`N`) + +#### Default Layer +- Set Default Layer to 0(`0`) +- Set Default Layer to 1(`1`) +- Set Default Layer to 2(`2`) +- Set Default Layer to 3(`3`) +- Set Default Layer to 4(`4`) +- Set Default Layer to 5(`5`) +- Set Default Layer to 6(`6`) +- Set Default Layer to 7(`7`) + + + +Mechanical Locking support +-------------------------- +This feature makes it possible for you to use mechanical locking switch for `CapsLock`, `NumLock` +or `ScrollLock`. To enable this feature define these macros in `config.h` and use `KC_LCAP`, `KC_LN +UM` or `KC_LSCR` in keymap for locking key instead of normal `KC_CAPS`, `KC_NLCK` or `KC_SLCK`. Res +ync option tries to keep switch state consistent with keyboard LED state. + + #define LOCKING_SUPPORT_ENABLE + #define LOCKING_RESYNC_ENABLE + + + +Start Your Own Project +----------------------- +**TBD** + + + +Debugging +-------- +Use PJRC's `hid_listen` to see debug messages. You can use the tool for debug even if firmware use LUFA stack. + +You can use xprintf() to display debug info on `hid_listen`, see `tmk_core/common/xprintf.h`. + + + +Files and Directories +------------------- +### Top +* tmk_core/ - core library +* keyboards/ - keyboard projects +* converter/ - protocol converter projects +* doc/ - documents + + + +Coding Style +------------- +- Doesn't use Tab to indent, use 4-spaces instead. + + + +Other Keyboard Firmware Projects +------------------ +You can learn a lot about keyboard firmware from these. See [doc/other_projects.md](tmk_core/doc/other_projects.md). diff --git a/docs/USB_NKRO.txt b/docs/USB_NKRO.txt new file mode 100644 index 0000000000..d9f1d12292 --- /dev/null +++ b/docs/USB_NKRO.txt @@ -0,0 +1,160 @@ +USB NKRO MEMO +============= +2010/12/09 + + +References +---------- +USB - boot mode, NKRO, compatibility, etc... + http://geekhack.org/showthread.php?t=13162 +NKey Rollover - Overview, Testing Methodology, and Results + http://geekhack.org/showwiki.php?title=NKey+Rollover+-+Overview+Testing+Methodology+and+Results +dfj's NKRO(2010/06) + http://geekhack.org/showpost.php?p=191195&postcount=251 + http://geekhack.org/showthread.php?p=204389#post204389 + + +Terminology +--------- +NKRO +ghost +matrix +mechanical with diodes +membrane + + +OS Support Status +----------------- +USB NKRO is possible *without* a custom driver. +At least following OS's supports. + Windows7 64bit + WindowsXP + Windows2000 SP4 + Ubuntu10.4(Linux 2.6) + MacOSX(To be tested) + + +Custom Driver for USB NKRO +-------------------------- +NOT NEEDED +at least when using following report formats on Windows, Linux or MacOSX. + + +USB NKRO methods +---------------- +1. Virtual keyboards + Keyboard can increase its KRO by using virtual keyboards with Standard or Extended report. + If the keyboard has 2 virtual keyboard with Standard report(6KRO), it gets 12KRO. + Using this method means the keyboard is a composite device. + +2. Extended report + It needs large report size for this method to achieve NKRO. + If a keyboard has 101keys, it needs 103byte report. It seems to be inefficient. + +3. Bitmap report + If the keyboard has less than 128keys, 16byte report will be enough for NKRO. + The 16byte report seems to be reasonable cost to get NKRO. + + +Report Format +------------- +Other report formats than followings are possible, though these format are typical one. + +1. Standard 8bytes + modifiers(bitmap) 1byte + reserved 1byte(not used) + keys(array) 1byte*6 +Standard report can send 6keys plus 8modifiers simultaneously. +Standard report is used by most keyboards in the marketplace. +Standard report is identical to boot protocol report. +Standard report is hard to suffer from compatibility problems. + +2. Extended standard 16,32,64bytes + modifiers(bitmap) 1byte + reserved 1byte(not used) + keys(array) 1byte*(14,32,62) +Extended report can send N-keys by using N+2bytes. +Extended report is expected to be compatible with boot protocol. + +3. Bitmap 16,32,64bytes + keys(bitmap) (16,32)bytes +Bitmap report can send at most 128keys by 16bytes and 256keys by 32bytes. +Bitmap report can achieve USB NKRO efficiently in terms of report size. +Bitmap report needs a deliberation for boot protocol implementation. +Bitmap report descriptor sample: + 0x05, 0x01, // Usage Page (Generic Desktop), + 0x09, 0x06, // Usage (Keyboard), + 0xA1, 0x01, // Collection (Application), + // bitmap of modifiers + 0x75, 0x01, // Report Size (1), + 0x95, 0x08, // Report Count (8), + 0x05, 0x07, // Usage Page (Key Codes), + 0x19, 0xE0, // Usage Minimum (224), + 0x29, 0xE7, // Usage Maximum (231), + 0x15, 0x00, // Logical Minimum (0), + 0x25, 0x01, // Logical Maximum (1), + 0x81, 0x02, // Input (Data, Variable, Absolute), ;Modifier byte + // LED output report + 0x95, 0x05, // Report Count (5), + 0x75, 0x01, // Report Size (1), + 0x05, 0x08, // Usage Page (LEDs), + 0x19, 0x01, // Usage Minimum (1), + 0x29, 0x05, // Usage Maximum (5), + 0x91, 0x02, // Output (Data, Variable, Absolute), + 0x95, 0x01, // Report Count (1), + 0x75, 0x03, // Report Size (3), + 0x91, 0x03, // Output (Constant), + // bitmap of keys + 0x95, (REPORT_BYTES-1)*8, // Report Count (), + 0x75, 0x01, // Report Size (1), + 0x15, 0x00, // Logical Minimum (0), + 0x25, 0x01, // Logical Maximum(1), + 0x05, 0x07, // Usage Page (Key Codes), + 0x19, 0x00, // Usage Minimum (0), + 0x29, (REPORT_BYTES-1)*8-1, // Usage Maximum (), + 0x81, 0x02, // Input (Data, Variable, Absolute), + 0xc0 // End Collection +where REPORT_BYTES is a report size in bytes. + + +Considerations +-------------- +Compatibility + boot protocol + minor/old system + Some BIOS doesn't send SET_PROTOCOL request, a keyboard can't switch to boot protocol mode. + This may cause a problem on a keyboard which uses other report than Standard. +Reactivity + USB polling time + OS/Driver processing time + + +Windows Problem +--------------- +1. Windows accepts only 6keys in case of Standard report. + It should be able to send 6keys plus 8modifiers. +2. Windows accepts only 10keys in case of 16bytes Extended report. + It should be able to send 14keys plus 8modifiers. +3. Windows accepts only 18keys in case of 32bytes Extended report. + It should be able to send 30keys plus 8modifiers. +If keys are pressed in excess of the number, wrong keys are registered on Windows. + +This problem will be reportedly fixed soon.(2010/12/05) + http://forums.anandtech.com/showpost.php?p=30873364&postcount=17 + + +Tools for testing NKRO +---------------------- +Browser App: +http://www.microsoft.com/appliedsciences/content/projects/KeyboardGhostingDemo.aspx +http://random.xem.us/rollover.html + +Windows: +AquaKeyTest.exe http://geekhack.org/showthread.php?t=6643 + +Linux: +xkeycaps +xev +showkeys + +EOF diff --git a/docs/VAGRANT_GUIDE.md b/docs/VAGRANT_GUIDE.md new file mode 100644 index 0000000000..439e78da7d --- /dev/null +++ b/docs/VAGRANT_GUIDE.md @@ -0,0 +1,27 @@ +# Quick Start Directions + +This project includes a Vagrantfile that will allow you to build a new firmware for your keyboard very easily without major changes to your primary operating system. This also ensures that when you clone the project and perform a build, you have the exact same environment as anyone else using the Vagrantfile to build. This makes it much easier for people to help you troubleshoot any issues you encounter. + +## Requirements + +Using the `/Vagrantfile` in this repository requires you have [Vagrant](http://www.vagrantup.com/) as well as [VirtualBox](https://www.virtualbox.org/) (or [VMware Workstation](https://www.vmware.com/products/workstation) and [Vagrant VMware plugin](http://www.vagrantup.com/vmware) but the (paid) VMware plugin requires a licensed copy of VMware Workstation/Fusion). + +*COMPATIBILITY NOTICE* Certain versions of Virtualbox 5 appear to have an incompatibility with the Virtualbox extensions installed in the boxes in this Vagrantfile. If you encounter any issues with the /vagrant mount not succeeding, please upgrade your version of Virtualbox to at least 5.0.12. **Alternately, you can try running the following command:** `vagrant plugin install vagrant-vbguest` + + +Other than having Vagrant and Virtualbox installed and possibly a restart of your computer afterwards, you can simple run a 'vagrant up' anywhere inside the folder where you checked out this project and it will start a Linux virtual machine that contains all the tools required to build this project. There is a post Vagrant startup hint that will get you off on the right foot, otherwise you can also reference the build documentation below. + +Build Firmware and Program Controller +------------------------------------- +See [/doc/BUIDE_GUIDE.md](/doc/BUILD_GUIDE.md), or the readme in the particular keyboards/* folder. + +Change your keymap +------------------ +See [/doc/keymap.md](/doc/keymap.md). + +## Flashing the firmware + +The "easy" way to flash the firmware is using a tool from your host OS like the Teensy programming app. [ErgoDox EZ](/keyboards/ergodox/readme.md) gives a great example. + +If you want to program via the command line you can uncomment the ['modifyvm'] lines in the Vagrantfile to enable the USB passthrough into Linux and then program using the command line tools like dfu-util/dfu-programmer or you can install the Teensy CLI version. + diff --git a/docs/basic_how_keyboards_work.md b/docs/basic_how_keyboards_work.md new file mode 100644 index 0000000000..73c3f5c5fc --- /dev/null +++ b/docs/basic_how_keyboards_work.md @@ -0,0 +1,96 @@ +# How keys are registered, and interpreted by computers + +In this file, you can will learn the concepts of how keyboards work over USB, +and you'll be able to better understand what you can expect from changing your +firmware directly. + +## Schematic view + +Whenever you type on 1 particular key, here is the chain of actions taking +place: + +``` text ++------+ +-----+ +----------+ +----------+ +----+ +| User |-------->| Key |------>| Firmware |----->| USB wire |---->| OS | ++------+ +-----+ +----------+ +----------+ |----+ +``` + +This scheme is a very simple view of what's going on, and more details follow +in the next sections. + +## 1. You Press a Key + +Whenever you press a key, the firmware of your keyboard can register this event. +It can register when the key is pressed, held and released. + +This usually happens with a [periodic scan of key presses with a frequency around 100 hz](https://github.com/benblazak/ergodox-firmware/blob/master/references.md#typical-keyboard-information). +This speed often is limited by the mechanical key response time, the protocol +to transfer those key presses (here USB HID), and by the software it is used in. + +## 2. What the Firmware Sends + +The [HID specification](http://www.usb.org/developers/hidpage/Hut1_12v2.pdf) +tells what a keyboard can actually send through USB to have a chance to be +properly recognised. This includes a pre-defined list of keycodes which are +simple numbers from `0x00` to `0xE7`. The firmware assigns a keycode to each +key of the keyboard. + +The firmware does not send actually letters or characters, but only keycodes. +Thus, by modifying the firmware, you only can modify what keycode is sent over +USB for a given key. + +## 3. What the Operating System Does + +Once the keycode reaches the operating system, a piece of software has to have +it match an actual character thanks to a keyboard layout. For example, if your +layout is set to QWERTY, a sample of the matching table is as follow: + +``` text +| keycode | character | +|---------+-----------| +| 0x04 | a/A | +| 0x05 | b/B | +| 0x06 | c/C | +| ... | ... | +| 0x1C | y/Y | +| 0x1D | z/Z | +| ... | ... | +|---------+-----------| +``` + +## Back to the firmware + +As the layout is generally fixed (unless you create your own), the firmware can +actually call a keycode by its layout name directly to ease things for you. + +This is exactly what is done here with `KC_A` actually representing `0x04` in +QWERTY. The full list can be found in `keycode.txt`. + +## List of Characters You Can Send + +Putting aside shortcuts, having a limited set of keycodes mapped to a limited +layout means that **the list of characters you can assign to a given key only +is the ones present in the layout**. + +For example, this means that if you have a QWERTY US layout, and you want to +assign 1 key to produce `€` (euro currency symbol), you are unable to do so, +because the QWERTY US layout does not have such mapping. You could fix that by +using a QWERTY UK layout, or a QWERTY US International. + +You may wonder why a keyboard layout containing all of Unicode is not devised +then? The limited number of keycode available through USB simply disallow such +a thing. + +## How to (Maybe) Enter Unicode Characters + +You can have the firmware send *sequences of keys* to use the [software Unicode +Input +Method](https://en.wikipedia.org/wiki/Unicode_input#Hexadecimal_code_input) of +the target operating system, thus effectively entering characters independently +of the layout defined in the OS. + +Yet, it does come with multiple disadvantages: + + - Tied to a specific OS a a time (need recompilation when changing OS); + - Within a given OS, does not work in all software; + - Limited to a subset of Unicode on some systems. diff --git a/docs/build_old.md b/docs/build_old.md new file mode 100644 index 0000000000..5c2d57d02d --- /dev/null +++ b/docs/build_old.md @@ -0,0 +1,187 @@ +Build Firmware and Program Controller +===================================== + +## This guide may be out-dated - use doc/BUILD_GUIDE.md instead + +Download and Install +-------------------- +### 1. Install Tools + +1. **Toolchain** On Windows install [MHV AVR Tools][mhv] for AVR GCC compiler and [Cygwin][cygwin](or [MinGW][mingw]) for shell terminal. On Mac you can use [CrossPack][crosspack]. On Linux you can install AVR GCC (and avr-libc) with your favorite package manager or run the avr_setup.sh script in the root of this repository. + +2. **Programmer** On Windows install [Atmel FLIP][flip]. On Mac and Linux install [dfu-programmer][dfu-prog]. + +3. **Driver** On Windows you start DFU bootloader on the chip first time you will see 'Found New Hardware Wizard' to install driver. If you install device driver properly you can find chip name like 'ATmega32U4' under 'LibUSB-Win32 Devices' tree on 'Device Manager'. If not you shall need to update its driver on 'Device Manager'. You will find the driver in `FLIP` install directory like: C:\Program Files (x86)\Atmel\Flip 3.4.5\usb\. In case of `dfu-programmer` use its driver. + +If you use PJRC Teensy you don't need step 2 and 3 above, just get [Teensy loader][teensy-loader]. + + +### 2. Download source +You can find firmware source at github: + +- <https://github.com/tmk/tmk_keyboard> + +If you are familiar with `Git` tools you are recommended to use it but you can also download zip archive from: + +- <https://github.com/tmk/tmk_keyboard/archive/master.zip> + + +Build firmware +-------------- +### 1. Open terminal +Open terminal window to get access to commands. Use Cygwin(or MingGW) `shell terminal` in Windows or `Terminal.app` on Mac OSX. In Windows press `Windows` key and `R` then enter `cmd` in 'Run command' dialog showing up. + +### 2. Change directory +Move to project directory in the firmware source. + + cd tmk_keyboard/{'keyboard' or 'converter'}/<project> + +### 3. Make +Build firmware using GNU `make` command. You'll see `<project>_<variant>.hex` file in that directory unless something unexpected occurs in build process. + + + make -f Makefile.<variant> clean + make -f Makefile.<variant> + + + + +Program Controller +------------------ +Now you have **hex** file to program on current directory. This **hex** is only needed to program your controller, other files are used for development and you may leave and forget them. + +### 1. Start bootloader +How to program controller depends on controller chip and its board design. To program AVR USB chips you'll need to start it up in bootloader mode. Most of boards with the chip have a push button to let bootloader come up. Consult with your controller board manual. + +### 2. Program with DFU bootloader +Stock AVR USB chip including ATmega32U4 has DFU bootloader by factory default. `FLIP` is a DFU programmer on Windows offered by Atmel. Open source command line tool `dfu-programmer` also supports AVR chips, it runs on Linux, Mac OSX and even Windows. + +To program AVR chip with DFU bootloader use `FLIP` or `dfu-programmer`. +If you have a proper program command in `Makefile` just type this. + +`FLIP` has two version of tool, GUI app and command line program. If you want GUI see tutorial below. +To use command line tool run this command. Note that you need to set PATH variable properly. + + $ make -f Makefile.<variant> flip + +Or to program with `dfu-programmer` run: + + $ make -f Makefile.<variant> dfu + +#### FLIP GUI tutorial +1. On menu bar click Device -> Select, then. `ATmega32u4`. +2. On menu bar click Settings -> Communication -> USB, then click 'Open' button on 'USB Port Connection' dialog. +At this point you'll see grey-outed widgets on the app get colored and ready. + +3. On menu bar click File -> Load HEX File, then select your firmware hex file on File Selector dialog. +4. On 'Operations Flow' panel click 'Run' button to load the firmware binary to the chip. Note that you should keep 'Erase', 'Blank Check', 'Program' and 'Verify' check boxes selected. +5. Re-plug USB cord or click 'Start Application' button to restart your controller. +Done. + +See also these instructions if you need. + +- <http://code.google.com/p/micropendous/wiki/LoadingFirmwareWithFLIP> +- <http://www.atmel.com/Images/doc7769.pdf> + + +### 3. Program with Teensy Loader +If you have PJRC Teensy see instruction of `Teensy Loader`. + +- <http://www.pjrc.com/teensy/loader.html> + +Or use this command if you have command line version of Teensy Loader installed. + + $ make -f Makefile.<variant> teensy + + +### 4. Program with Other programmer +You may want to use other programmer like `avrdude` with AVRISPmkII, Arduino or USBasp. In that case you can still use make target `program` for build with configuring `PROGRAM_CMD` in Makefile. + + $ make -f Makefile.<variant> program + + +[cygwin]: https://www.cygwin.com/ +[mingw]: http://www.mingw.org/ +[mhv]: https://infernoembedded.com/products/avr-tools +[winavr]: http://winavr.sourceforge.net/ +[crosspack]: http://www.obdev.at/products/crosspack/index.html +[flip]: http://www.atmel.com/tools/FLIP.aspx +[dfu-prog]: http://dfu-programmer.sourceforge.net/ +[teensy-loader]:http://www.pjrc.com/teensy/loader.html + + + +Makefile Options +---------------- +### 1. MCU and Frequency. + + MCU = atmega32u4 # Teensy 2.0 + #MCU = at90usb1286 # Teensy++ 2.0 + F_CPU = 16000000 + +Set your MCU and its clock in Hz. + + # Boot Section Size in *bytes* + # Teensy halfKay 512 + # Atmel DFU loader 4096 + # LUFA bootloader 4096 + OPT_DEFS += -DBOOTLOADER_SIZE=4096 + +If you are using PJRC Teensy use `512` for `BOOTLOADER_SIZE`, otherwise use `4096` unless you are sure. + +### 2. Features +Optional. Note that ***comment out*** with `#` to disable them. + + BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) + MOUSEKEY_ENABLE = yes # Mouse keys(+4700) + EXTRAKEY_ENABLE = yes # Audio control and System control(+450) + CONSOLE_ENABLE = yes # Console for debug(+400) + COMMAND_ENABLE = yes # Commands for debug and configuration + SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend + #NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA + #BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality + +### 3. Programmer +Optional. Set proper command for your controller, bootloader and programmer. This command can be used with `make program`. Not needed if you use `FLIP`, `dfu-programmer` or `Teensy Loader`. + + # avrdude with AVRISPmkII + PROGRAM_CMD = avrdude -p $(MCU) -c avrispmkII -P USB -U flash:w:$(TARGET).hex + + # avrdude with USBaspLoader + PROGRAM_CMD = avrdude -p $(MCU) -c usbasp -U flash:w:$(TARGET).hex + + # avrdude with arduino + PROGRAM_CMD = avrdude -p $(MCU) -c arduino -P COM1 -b 57600 -U flash:w:$(TARGET).hex + + + +Config.h Options +---------------- +### 1. Magic command key combination + + #define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT))) + +### 2. Mechanical Locking Support for CapsLock + + /* Mechanical locking CapsLock support. Use KC_LCAP instead of KC_CAPS in keymap */ + #define CAPSLOCK_LOCKING_ENABLE + /* Locking CapsLock re-synchronize hack */ + #define CAPSLOCK_LOCKING_RESYNC_ENABLE + +### 3. Disable Debug and Print + + /* disable debug print */ + #define NO_DEBUG + + /* disable print */ + #define NO_PRINT + +### 4. Disable Action Features + + #define NO_ACTION_LAYER + #define NO_ACTION_TAPPING + #define NO_ACTION_ONESHOT + #define NO_ACTION_MACRO + #define NO_ACTION_FUNCTION + +***TBD*** diff --git a/docs/keycode.txt b/docs/keycode.txt new file mode 100644 index 0000000000..687406fdab --- /dev/null +++ b/docs/keycode.txt @@ -0,0 +1,261 @@ +Keycode Symbol Table +==================== +Keycodes are defined in `common/keycode.h`. +Range of 00-A4 and E0-E7 are identical with HID Usage: +<http://www.usb.org/developers/hidpage/Hut1_12v2.pdf> +Virtual keycodes are defined out of above range to support special actions. + + +Keycode Symbol Short name Description +-------------------------------------------------------------------------------- +KC_NO 00 Reserved (no event indicated) +KC_ROLL_OVER 01 Keyboard ErrorRollOver +KC_POST_FAIL 02 Keyboard POSTFail +KC_UNDEFINED 03 Keyboard ErrorUndefined +KC_A 04 Keyboard a and A +KC_B 05 Keyboard b and B +KC_C 06 Keyboard c and C +KC_D 07 Keyboard d and D +KC_E 08 Keyboard e and E +KC_F 09 Keyboard f and F +KC_G 0A Keyboard g and G +KC_H 0B Keyboard h and H +KC_I 0C Keyboard i and I +KC_J 0D Keyboard j and J +KC_K 0E Keyboard k and K +KC_L 0F Keyboard l and L +KC_M 10 Keyboard m and M +KC_N 11 Keyboard n and N +KC_O 12 Keyboard o and O +KC_P 13 Keyboard p and P +KC_Q 14 Keyboard q and Q +KC_R 15 Keyboard r and R +KC_S 16 Keyboard s and S +KC_T 17 Keyboard t and T +KC_U 18 Keyboard u and U +KC_V 19 Keyboard v and V +KC_W 1A Keyboard w and W +KC_X 1B Keyboard x and X +KC_Y 1C Keyboard y and Y +KC_Z 1D Keyboard z and Z +KC_1 1E Keyboard 1 and ! +KC_2 1F Keyboard 2 and @ +KC_3 20 Keyboard 3 and # +KC_4 21 Keyboard 4 and $ +KC_5 22 Keyboard 5 and % +KC_6 23 Keyboard 6 and ^ +KC_7 24 Keyboard 7 and & +KC_8 25 Keyboard 8 and * +KC_9 26 Keyboard 9 and ( +KC_0 27 Keyboard 0 and ) +KC_ENTER KC_ENT 28 Keyboard Return (ENTER) +KC_ESCAPE KC_ESC 29 Keyboard ESCAPE +KC_BSPACE KC_BSPC 2A Keyboard DELETE (Backspace) +KC_TAB 2B Keyboard Tab +KC_SPACE KC_SPC 2C Keyboard Spacebar +KC_MINUS KC_MINS 2D Keyboard - and (underscore) +KC_EQUAL KC_EQL 2E Keyboard = and + +KC_LBRACKET KC_LBRC 2F Keyboard [ and { +KC_RBRACKET KC_RBRC 30 Keyboard ] and } +KC_BSLASH KC_BSLS 31 Keyboard \ and | +KC_NONUS_HASH KC_NUHS 32 Keyboard Non-US # and ~ +KC_SCOLON KC_SCLN 33 Keyboard ; and : +KC_QUOTE KC_QUOT 34 Keyboard ‘ and “ +KC_GRAVE KC_GRV 35 Keyboard Grave Accent and Tilde +KC_COMMA KC_COMM 36 Keyboard , and < +KC_DOT 37 Keyboard . and > +KC_SLASH KC_SLSH 38 Keyboard / and ? +KC_CAPSLOCK KC_CAPS 39 Keyboard Caps Lock +KC_F1 3A Keyboard F1 +KC_F2 3B Keyboard F2 +KC_F3 3C Keyboard F3 +KC_F4 3D Keyboard F4 +KC_F5 3E Keyboard F5 +KC_F6 3F Keyboard F6 +KC_F7 40 Keyboard F7 +KC_F8 41 Keyboard F8 +KC_F9 42 Keyboard F9 +KC_F10 43 Keyboard F10 +KC_F11 44 Keyboard F11 +KC_F12 45 Keyboard F12 +KC_PSCREEN KC_PSCR 46 Keyboard PrintScreen1 +KC_SCKLOCK KC_SLCK 47 Keyboard Scroll Lock11 +KC_PAUSE KC_PAUS 48 Keyboard Pause1 +KC_INSERT KC_INS 49 Keyboard Insert1 +KC_HOME 4A Keyboard Home1 +KC_PGUP 4B Keyboard PageUp1 +KC_DELETE KC_DEL 4C Keyboard Delete Forward +KC_END 4D Keyboard End1 +KC_PGDOWN KC_PGDN 4E Keyboard PageDown1 +KC_RIGHT KC_RGHT 4F Keyboard RightArrow1 +KC_LEFT 50 Keyboard LeftArrow1 +KC_DOWN 51 Keyboard DownArrow1 +KC_UP 52 Keyboard UpArrow1 +KC_NUMLOCK KC_NLCK 53 Keypad Num Lock and Clear11 +KC_KP_SLASH KC_PSLS 54 Keypad / +KC_KP_ASTERISK KC_PAST 55 Keypad * +KC_KP_MINUS KC_PMNS 56 Keypad - +KC_KP_PLUS KC_PPLS 57 Keypad + +KC_KP_ENTER KC_PENT 58 Keypad ENTER5 +KC_KP_1 KC_P1 59 Keypad 1 and End +KC_KP_2 KC_P2 5A Keypad 2 and Down Arrow +KC_KP_3 KC_P3 5B Keypad 3 and PageDn +KC_KP_4 KC_P4 5C Keypad 4 and Left Arrow +KC_KP_5 KC_P5 5D Keypad 5 +KC_KP_6 KC_P6 5E Keypad 6 and Right Arrow +KC_KP_7 KC_P7 5F Keypad 7 and Home +KC_KP_8 KC_P8 60 Keypad 8 and Up Arrow +KC_KP_9 KC_P9 61 Keypad 9 and PageUp +KC_KP_0 KC_P0 62 Keypad 0 and Insert +KC_KP_DOT KC_PDOT 63 Keypad . and Delete +KC_NONUS_BSLASH KC_NUBS 64 Keyboard Non-US \ and | +KC_APPLICATION KC_APP 65 Keyboard Application10 +KC_POWER 66 Keyboard Power9 +KC_KP_EQUAL KC_PEQL 67 Keypad = +KC_F13 68 Keyboard F13 +KC_F14 69 Keyboard F14 +KC_F15 6A Keyboard F15 +KC_F16 6B Keyboard F16 +KC_F17 6C Keyboard F17 +KC_F18 6D Keyboard F18 +KC_F19 6E Keyboard F19 +KC_F20 6F Keyboard F20 +KC_F21 70 Keyboard F21 +KC_F22 71 Keyboard F22 +KC_F23 72 Keyboard F23 +KC_F24 73 Keyboard F24 +KC_EXECUTE 74 Keyboard Execute +KC_HELP 75 Keyboard Help +KC_MENU 76 Keyboard Menu +KC_SELECT 77 Keyboard Select +KC_STOP 78 Keyboard Stop +KC_AGAIN 79 Keyboard Again +KC_UNDO 7A Keyboard Undo +KC_CUT 7B Keyboard Cut +KC_COPY 7C Keyboard Copy +KC_PASTE 7D Keyboard Paste +KC_FIND 7E Keyboard Find +KC__MUTE 7F Keyboard Mute +KC__VOLUP 80 Keyboard Volume Up +KC__VOLDOWN 81 Keyboard Volume Down +KC_LOCKING_CAPS 82 Keyboard Locking Caps Lock12 +KC_LOCKING_NUM 83 Keyboard Locking Num Lock12 +KC_LOCKING_SCROLL 84 Keyboard Locking Scroll Lock12 +KC_KP_COMMA KC_PCMM 85 Keypad Comma27 +KC_KP_EQUAL_AS400 86 Keypad Equal Sign29 +KC_INT1 KC_RO 87 Keyboard International115,28 +KC_INT2 KC_KANA 88 Keyboard International216 +KC_INT3 KC_JYEN 89 Keyboard International317 +KC_INT4 KC_HENK 8A Keyboard International418 +KC_INT5 KC_MHEN 8B Keyboard International519 +KC_INT6 8C Keyboard International620 +KC_INT7 8D Keyboard International721 +KC_INT8 8E Keyboard International822 +KC_INT9 8F Keyboard International922 +KC_LANG1 90 Keyboard LANG125 +KC_LANG2 91 Keyboard LANG226 +KC_LANG3 92 Keyboard LANG330 +KC_LANG4 93 Keyboard LANG431 +KC_LANG5 94 Keyboard LANG532 +KC_LANG6 95 Keyboard LANG68 +KC_LANG7 96 Keyboard LANG78 +KC_LANG8 97 Keyboard LANG88 +KC_LANG9 98 Keyboard LANG98 +KC_ALT_ERASE 99 Keyboard Alternate Erase7 +KC_SYSREQ 9A Keyboard SysReq/Attention1 +KC_CANCEL 9B Keyboard Cancel +KC_CLEAR 9C Keyboard Clear +KC_PRIOR 9D Keyboard Prior +KC_RETURN 9E Keyboard Return +KC_SEPARATOR 9F Keyboard Separator +KC_OUT A0 Keyboard Out +KC_OPER A1 Keyboard Oper +KC_CLEAR_AGAIN A2 Keyboard Clear/Again +KC_CRSEL A3 Keyboard CrSel/Props +KC_EXSEL A4 Keyboard ExSel +/* Modifiers */ +KC_LCTRL KC_LCTL E0 Keyboard LeftControl +KC_LSHIFT KC_LSFT E1 Keyboard LeftShift +KC_LALT E2 Keyboard LeftAlt +KC_LGUI E3 Keyboard Left GUI(Windows/Apple/Meta key) +KC_RCTRL KC_RCTL E4 Keyboard RightControl +KC_RSHIFT KC_RSFT E5 Keyboard RightShift +KC_RALT E6 Keyboard RightAlt +KC_RGUI E7 Keyboard Right GUI(Windows/Apple/Meta key) + +/* + * Virtual keycodes + */ +/* System Control */ +KC_SYSTEM_POWER KC_PWR System Power Down +KC_SYSTEM_SLEEP KC_SLEP System Sleep +KC_SYSTEM_WAKE KC_WAKE System Wake +/* Consumer Page */ +KC_AUDIO_MUTE KC_MUTE +KC_AUDIO_VOL_UP KC_VOLU +KC_AUDIO_VOL_DOWN KC_VOLD +KC_MEDIA_NEXT_TRACK KC_MNXT +KC_MEDIA_PREV_TRACK KC_MPRV +KC_MEDIA_STOP KC_MSTP +KC_MEDIA_PLAY_PAUSE KC_MPLY +KC_MEDIA_SELECT KC_MSEL +KC_MAIL KC_MAIL +KC_CALCULATOR KC_CALC +KC_MY_COMPUTER KC_MYCM +KC_WWW_SEARCH KC_WSCH +KC_WWW_HOME KC_WHOM +KC_WWW_BACK KC_WBAK +KC_WWW_FORWARD KC_WFWD +KC_WWW_STOP KC_WSTP +KC_WWW_REFRESH KC_WREF +KC_WWW_FAVORITES KC_WFAV +/* Mousekey */ +KC_MS_UP KC_MS_U Mouse Cursor Up +KC_MS_DOWN KC_MS_D Mouse Cursor Down +KC_MS_LEFT KC_MS_L Mouse Cursor Left +KC_MS_RIGHT KC_MS_R Mouse Cursor Right +KC_MS_BTN1 KC_BTN1 Mouse Button 1 +KC_MS_BTN2 KC_BTN2 Mouse Button 2 +KC_MS_BTN3 KC_BTN3 Mouse Button 3 +KC_MS_BTN4 KC_BTN4 Mouse Button 4 +KC_MS_BTN5 KC_BTN5 Mouse Button 5 +KC_MS_WH_UP KC_WH_U Mouse Wheel Up +KC_MS_WH_DOWN KC_WH_D Mouse Wheel Down +KC_MS_WH_LEFT KC_WH_L Mouse Wheel Left +KC_MS_WH_RIGHT KC_WH_R Mouse Wheel Right +KC_MS_ACCEL0 KC_ACL0 Mouse Acceleration 0 +KC_MS_ACCEL1 KC_ACL1 Mouse Acceleration 1 +KC_MS_ACCEL2 KC_ACL2 Mouse Acceleration 2 +/* Fn key */ +KC_FN0 +KC_FN1 +KC_FN2 +KC_FN3 +KC_FN4 +KC_FN5 +KC_FN6 +KC_FN7 +KC_FN8 +KC_FN9 +KC_FN10 +KC_FN11 +KC_FN12 +KC_FN13 +KC_FN14 +KC_FN15 +KC_FN16 +KC_FN17 +KC_FN18 +KC_FN19 +KC_FN20 +KC_FN21 +KC_FN22 +KC_FN23 +KC_FN24 +KC_FN25 +KC_FN26 +KC_FN27 +KC_FN28 +KC_FN29 +KC_FN30 +KC_FN31 diff --git a/docs/keymap_config_h_example.h b/docs/keymap_config_h_example.h new file mode 100644 index 0000000000..8893d122e0 --- /dev/null +++ b/docs/keymap_config_h_example.h @@ -0,0 +1,8 @@ +#ifndef CONFIG_USER_H +#define CONFIG_USER_H + +#include "../../config.h" + +// place overrides here + +#endif diff --git a/docs/keymap_makefile_example.mk b/docs/keymap_makefile_example.mk new file mode 100644 index 0000000000..f4671a9d11 --- /dev/null +++ b/docs/keymap_makefile_example.mk @@ -0,0 +1,21 @@ +# Build Options +# change to "no" to disable the options, or define them in the Makefile in +# the appropriate keymap folder that will get included automatically +# +BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) +MOUSEKEY_ENABLE = yes # Mouse keys(+4700) +EXTRAKEY_ENABLE = yes # Audio control and System control(+450) +CONSOLE_ENABLE = no # Console for debug(+400) +COMMAND_ENABLE = yes # Commands for debug and configuration +NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work +BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality +MIDI_ENABLE = no # MIDI controls +AUDIO_ENABLE = no # Audio output on port C6 +UNICODE_ENABLE = no # Unicode +BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID +RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. Do not enable this with audio at the same time. +SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend + +ifndef QUANTUM_DIR + include ../../../../Makefile +endif
\ No newline at end of file diff --git a/docs/keymap_old.md b/docs/keymap_old.md new file mode 100644 index 0000000000..3ea138ea8f --- /dev/null +++ b/docs/keymap_old.md @@ -0,0 +1,685 @@ +Keymap framework - how to define your keymap +============================================ +***NOTE: This is updated for QMK but this is still work in progress. This may still be inconsistent with the source code.*** + +QMK is based on TMK. Understanding the essential changes made should help you understand variable names etc. + +## TMK vs. QMK + +| Firmware |TMK |QMK | +|---------------------------|-----------------------|-------------------------| +| Maintainer |hasu |Jack Humbert et al. | +| Build path customization | `TMK_DIR = ...` | `include .../Makefile` | +| `keymaps` data | 3D array of `uint8_t` holding **keycode** | 3D array of `uint16_t` holding **action code** | +| `fn_actions` data | 1D array of `uint16_t` holding **action code** | 1D array of `uint16_t` holding **action code** | + +Since QMK is based on TMK and uses major portion of TMK code as is, understanding the essential changes made should help you understand the code. + +## 0. Keymap and layers +In QMK, **`const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS]`** holds multiple **layers** of keymap information in **16 bit** data holding the **action code**. You can define **32 layers** at most. + +For trivial key definitions, the higher 8 bits of the **action code** are all 0 and the lower 8 bits holds the USB HID usage code generated by the key as **keycode**. + +Respective layers can be validated simultaneously. Layers are indexed with 0 to 31 and higher layer has precedence. + + Keymap: 32 Layers Layer: action code matrix + ----------------- --------------------- + stack of layers array_of_action_code[row][column] + ____________ precedence _______________________ + / / | high / ESC / F1 / F2 / F3 .... + 31 /___________// | /-----/-----/-----/----- + 30 /___________// | / TAB / Q / W / E .... + 29 /___________/ | /-----/-----/-----/----- + : _:_:_:_:_:__ | : /LCtrl/ A / S / D .... + : / : : : : : / | : / : : : : + 2 /___________// | 2 `-------------------------- + 1 /___________// | 1 `-------------------------- + 0 /___________/ V low 0 `-------------------------- + + +Sometimes, the action code stored in keymap may be referred as keycode in some documents due to the TMK history. + +### 0.1 Keymap layer status +Keymap layer has its state in two 32 bit parameters: + +* **`default_layer_state`** indicates a base keymap layer(0-31) which is always valid and to be referred. +* **`layer_state`** () has current on/off status of the layer on its each bit. + +Keymap has its state in two parameter **`default_layer`** indicates a base keymap layer(0-31) which is always valid and to be referred, **`keymap_stat`** is 16bit variable which has current on/off status of layers on its each bit. +Keymap layer '0' is usually `default_layer` and which is the only valid layer and other layers is initially off after boot up firmware, though, you can configured them in `config.h`. +To change `default_layer` will be useful when you switch key layout completely, say you want Colmak instead of Qwerty. + + Initial state of Keymap Change base layout + ----------------------- ------------------ + + 31 31 + 30 30 + 29 29 + : : + : : ____________ + 2 ____________ 2 / / + 1 / / ,->1 /___________/ + ,->0 /___________/ | 0 + | | + `--- default_layer = 0 `--- default_layer = 1 + layer_state = 0x00000001 layer_state = 0x00000002 + +On the other hand, you shall change `layer_state` to overlay base layer with some layers for feature such as navigation keys, function key(F1-F12), media keys or special actions. + + Overlay feature layer + --------------------- bit|status + ____________ ---+------ + 31 / / 31 | 0 + 30 /___________// -----> 30 | 1 + 29 /___________/ -----> 29 | 1 + : : | : + : ____________ : | : + 2 / / 2 | 0 + ,->1 /___________/ -----> 1 | 1 + | 0 0 | 0 + | + + `--- default_layer = 1 | + layer_state = 0x60000002 <-' + + + +### 0.2 Layer Precedence and Transparency +Note that ***higher layer has higher priority on stack of layers***, namely firmware falls down from top layer to bottom to look up keycode. Once it spots keycode other than **`KC_TRNS`**(transparent) on a layer it stops searching and lower layers aren't referred. + +You can place `KC_TRANS` on overlay layer changes just part of layout to fall back on lower or base layer. +Key with `KC_TRANS` (`KC_TRNS` and `_______` are the alias) doesn't has its own keycode and refers to lower valid layers for keycode, instead. +See example below. + + +### 0.3 Keymap Example +Keymap in this QMK is **`static const uint16_t PROGMEM keymaps[]`** C array in fact and you can define layers in it with **`KEYMAP()`** C macro and keycodes. To use complex actions you need to define `Fn` keycode in **`fn_actions[]`** array. It holds the 16 bit quantum keycode (action code). + +> Please note that keymap in the TMK, which QMK was forked from, is **`static const uint8_t PROGMEM keymaps[]`** C array which holds the 8 bit keycode (~USB HID usage code). + +This is a keymap example for [HHKB](http://en.wikipedia.org/wiki/Happy_Hacking_Keyboard) keyboard. +This example has three layers, 'QWERTY' as base layer, 'FN' and 'MOUSE'. + +In this example, + + `MO(layer)` is a **momentary layer switching** key. + +You can find other keymap definitions in file `keymap.c` located on project directories. +``` +/* + * dbroqua HHKB Layout + */ +#include "hhkb.h" + +#define BASE 0 +#define FN 1 +#define MOUSE 2 + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + /* BASE Level: Default Layer + * ,-----------------------------------------------------------------------------------------. + * | Esc | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | \ | ` | + * |-----------------------------------------------------------------------------------------+ + * | Tab | Q | W | E | R | T | Y | U | I | O | P | [ | ] | Bksp | + * |-----------------------------------------------------------------------------------------+ + * | Ctrl | A | S | D | F | G | H | J | K | L | ; | ' | Enter | + * |-----------------------------------------------------------------------------------------+ + * | Shift | Z | X | C | V | B | N | M | , | . | / | Shift | fn | + * +-----------------------------------------------------------------------------------------+ + * | Gui | Alt | Space | AltGr |Mouse| + * `----------------------------------------------------------------´ + */ + [BASE] = KEYMAP( + KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSLS, KC_GRV, \ + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSPC, \ + KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, \ + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, MO(FN), \ + KC_LGUI, KC_LALT, /* */ KC_SPC, KC_RALT, MO(MOUSE) + ), + + /* FN Layer + * ,-----------------------------------------------------------------------------------------. + * | Pwr | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F0 | F11 | F12 | Ins | Del| + * |-----------------------------------------------------------------------------------------+ + * | Caps | | | | | | | |PrtSc| Slck| Paus| Up | | | + * |-----------------------------------------------------------------------------------------+ + * | | Vol-| Vol+| Mute| | | * | / | Home| PgUp| Left |Right| | + * |-----------------------------------------------------------------------------------------+ + * | | Prev| Play| Next| | | + | - | End |PgDwn| Down| | | + * +-----------------------------------------------------------------------------------------+ + * | | | | Stop | | + * `----------------------------------------------------------------´ + */ + [FN] = KEYMAP( + KC_PWR, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_INS, KC_DEL, \ + KC_CAPS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PSCR, KC_SLCK, KC_PAUS, KC_UP, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_VOLD, KC_VOLU, KC_MUTE, KC_TRNS, KC_TRNS, KC_PAST, KC_PSLS, KC_HOME, KC_PGUP, KC_LEFT, KC_RGHT, KC_TRNS, \ + KC_TRNS, KC_MPRV, KC_MPLY, KC_MNXT, KC_TRNS, KC_TRNS, KC_PPLS, KC_PMNS, KC_END, KC_PGDN, KC_DOWN, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_MSTP, KC_TRNS + ), + + /* MOUSE Layer + * ,-----------------------------------------------------------------------------------------. + * | | | | | | | | | | | | | | | | + * |-----------------------------------------------------------------------------------------+ + * | | | WUp | | | | | | | | Btn1| Up | Btn2| | + * |-----------------------------------------------------------------------------------------+ + * | | WLt | WDn | WRt | | | | | | | Left |Right| | + * |-----------------------------------------------------------------------------------------+ + * | | | | | | | | | | Btn3| Down| | | + * +-----------------------------------------------------------------------------------------+ + * | | | | | | + * `----------------------------------------------------------------´ + */ + [MOUSE] = KEYMAP( + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_WH_U, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_BTN1, KC_MS_U, KC_BTN2, KC_TRNS, \ + KC_TRNS, KC_WH_L, KC_WH_D, KC_WH_R, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MS_L, KC_MS_R, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_BTN3, KC_MS_D, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS + ) +}; + +const uint16_t PROGMEM fn_actions[] = { + +}; + +const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) +{ + // MACRODOWN only works in this function + switch(id) { + case 0: + if (record->event.pressed) { + register_code(KC_RSFT); + } else { + unregister_code(KC_RSFT); + } + break; + } + return MACRO_NONE; +}; +``` + + +## 1. Keycode +See [`tmk_core/common/keycode.h`](../tmk_core/common/keycode.h) or keycode table below for the detail. Keycode is internal **8bit code** to indicate action performed on key in keymap. Keycodes are based on [HID Usage Keyboard/Keypad Page(0x07)](http://www.usb.org/developers/hidpage/Hut1_12v2.pdf) plus special codes in the `0xA5-DF` range. + +Keycode has `KC_` prefixed symbol respectively. Most of keycodes like `KC_A` have simple action registers key to host on press and unregister on release, while some of other keycodes has some special actions like `Fn` keys, Media control keys, System control keys and Mousekeys. + +keymaps[] + +In `KEYMAP()` macro, TMK recommends you to keep prefix part `KC_` of keycode to keep keymap compact. For example, just use `A` instead you place `KC_A` in `KEYMAP()`. But this doesn't apply for QMK. + +The `KEYMAP()` macro defines correspondence between the physical key location to the electrical key connection. + +Some keycodes has 7-letter **short name** such as `KC_COMM` in addition to descriptive name `KC_COMMA`, you'll prefer short one in `KEYMAP()`. + +### 1.0 Other key +- `KC_NO` for no action +- `KC_TRNS` for layer transparency (See above) + +### 1.1 Normal key +- `KC_A` to `KC_Z`, `KC_1` to `KC_0` for alpha numeric key +- `KC_MINS`, `KC_EQL`, `KC_GRV`, `KC_RBRC`, `KC_LBRC`, `KC_COMM`, `KC_DOT`, `KC_BSLS`, `KC_SLSH`, `KC_SCLN`, `KC_QUOT` +- `KC_ESC`, `KC_TAB`, `KC_SPC`, `KC_BSPC`, `KC_ENT`, `KC_DEL`, `KC_INS` +- `KC_UP`, `KC_DOWN`, `KC_RGHT`, `KC_LEFT`, `KC_PGUP`, `KC_PGDN`, `KC_HOME`, `KC_END` +- `KC_CAPS`, `KC_NLCK`, `KC_SLCK`, `KC_PSCR`, `KC_PAUS`, `KC_APP`, `KC_F1` to `KC_F24` +- `KC_P1` to `KC_P0`, `KC_PDOT`, `KC_PCMM`, `KC_PSLS`, `KC_PAST`, `KC_PMNS`, `KC_PPLS`, `KC_PEQL`, `KC_PENT` for keypad. + +### 1.2 Modifier +There are 8 modifiers which has discrimination between left and right. + +- `KC_LCTL` and `KC_RCTL` for Control +- `KC_LSFT` and `KC_RSFT` for Shift +- `KC_LALT` and `KC_RALT` for Alt +- `KC_LGUI` and `KC_RGUI` for Windows key or Command key in Mac + +### 1.3 Mousekey +- `KC_MS_U`, `KC_MS_D`, `KC_MS_L`, `KC_MS_R` for mouse cursor +- `KC_WH_U`, `KC_WH_D`, `KC_WH_L`, `KC_WH_R` for mouse wheel +- `KC_BTN1`, `KC_BTN2`, `KC_BTN3`, `KC_BTN4`, `KC_BTN5` for mouse buttons + +### 1.4 System & Media key +- `KC_PWR`, `KC_SLEP`, `KC_WAKE` for Power, Sleep, Wake +- `KC_MUTE`, `KC_VOLU`, `KC_VOLD` for audio volume control +- `KC_MNXT`, `KC_MPRV`, `KC_MSTP`, `KC_MPLY`, `KC_MSEL` for media control +- `KC_MAIL`, `KC_CALC`, `KC_MYCM` for application launch +- `KC_WSCH`, `KC_WHOM`, `KC_WBAK`, `KC_WFWD`, `KC_WSTP`, `KC_WREF`, `KC_WFAV` for web browser operation + +### 1.5 Fn key +You don't need to use this functionality under QMK since this is a backward compatibility functionality. Unlike TMK, you can write action code itself directly in **`static const uint16_t PROGMEM keymaps[]`** C array using `MO(layer)`, etc. + +`KC_FNnn` are keycodes for `Fn` key which not given any actions at the beginning unlike most of keycodes has its own inborn action. To use these keycodes in `KEYMAP()` you need to assign action you want at first. Action of `Fn` key is defined in `fn_actions[]` and its index of the array is identical with number part of `KC_FNnn`. Thus `KC_FN0` keycode indicates the action defined in first element of the array. ***Only 32 `Fn` keys can be defined at most.*** + + +### 1.6 Keycode Table + See keycode table in [`doc/keycode.txt`](./keycode.txt) for description of keycodes. + + In regard to implementation side most of keycodes are identical with [HID usage][HID_usage](pdf) sent to host for real and some virtual keycodes are defined to support special actions. +[HID_usage]: http://www.usb.org/developers/hidpage/Hut1_12v2.pdf + + + +## 2. Action +See [`common/action_code.h`](../common/action_code.h). Action is a **16bit code** and defines function to perform on events of a key like press, release, holding and tapping. + +Most of keys just register 8bit scancode to host, but to support other complex features needs 16bit extended action codes internally. However, using 16bit action codes in keymap results in double size in memory compared to using just keycodes. To avoid this waste 8bit keycodes are used in `KEYMAP()` instead of action codes. + +***You can just use keycodes of `Normal key`, `Modifier`, `Mousekey` and `System & Media key` in keymap*** to indicate corresponding actions instead of using action codes. While ***to use other special actions you should use keycode of `Fn` key defined in `fn_actions[]`.*** + + +### 2.1 Key Action +This is a simple action that registers scancodes(HID usage in fact) to host on press event of key and unregister on release. + +#### Parameters ++ **mods**: { ` MOD_LCTL`, ` MOD_LSFT`, ` MOD_LALT`, ` MOD_LGUI`, + ` MOD_RCTL`, ` MOD_RSFT`, ` MOD_RALT`, ` MOD_RGUI` } ++ **key**: keycode + + +#### 2.1.1 Normal key and Modifier +***This action usually won't be used expressly in keymap*** because you can just use keycodes in `KEYMAP()` instead. + +You can define these actions on *'A'* key and *'left shift'* modifier with: + + ACTION_KEY(KC_A) + ACTION_KEY(KC_LSFT) + +#### 2.1.2 Modified key +This action is comprised of strokes of modifiers and a key. `Macro` action is needed if you want more complex key strokes. + +Say you want to assign a key to `Shift + 1` to get character *'!'* or `Alt + Tab` to switch application windows. + + ACTION_MODS_KEY(MOD_LSFT, KC_1) + ACTION_MODS_KEY(MOD_LALT, KC_TAB) + +Or `Alt,Shift + Tab` can be defined. `ACTION_MODS_KEY(mods, key)` requires **4-bit modifier state** and a **keycode** as arguments. See `keycode.h` for `MOD_BIT()` macro. + + ACTION_MODS_KEY(MOD_LALT | MOD_LSFT, KC_TAB) + +#### 2.1.3 Multiple Modifiers +Registers multiple modifiers with pressing a key. To specify multiple modifiers use `|`. + + ACTION_MODS(MOD_ALT | MOD_LSFT) + +#### 2.1.3 Modifier with Tap key([Dual role][dual_role]) +Works as a modifier key while holding, but registers a key on tap(press and release quickly). + + + ACTION_MODS_TAP_KEY(MOD_RCTL, KC_ENT) + + + +### 2.2 Layer Action +These actions operate layers of keymap. + +#### Parameters +You can specify a **target layer** of action and **when the action is executed**. Some actions take a **bit value** for bitwise operation. + + ++ **layer**: `0`-`31` ++ **on**: { `ON_PRESS` | `ON_RELEASE` | `ON_BOTH` } ++ **bits**: 4-bit value and 1-bit mask bit + + +#### 2.2.1 Default Layer +Default Layer is a layer which always is valid and referred to when actions is not defined on other overlay layers. + +This sets Default Layer to given parameter `layer` and activate it. + + ACTION_DEFAULT_LAYER_SET(layer) + + +#### 2.2.2 Momentary +Turns on `layer` momentarily while holding, in other words it activates when key is pressed and deactivate when released. + + ACTION_LAYER_MOMENTARY(layer) + + +#### 2.2.3 Toggle Switch +Turns on `layer` with first type(press and release) and turns off with next. + + ACTION_LAYER_TOGGLE(layer) + + +#### 2.2.4 Momentary Switch with tap key +Turns on `layer` momentary while holding, but registers key on tap(press and release quickly). + + ACTION_LAYER_TAP_KEY(layer, key) + + +#### 2.2.5 Momentary Switch with tap toggle +Turns on `layer` momentary while holding and toggles it with serial taps. + + ACTION_LAYER_TAP_TOGGLE(layer) + + +#### 2.2.6 Invert state of layer +Inverts current state of `layer`. If the layer is on it becomes off with this action. + + ACTION_LAYER_INVERT(layer, on) + + +#### 2.2.7 Turn On layer +Turns on layer state. + + ACTION_LAYER_ON(layer, on) + +Turns on layer state on press and turns off on release. + + ACTION_LAYER_ON_OFF(layer) + + +#### 2.2.8 Turn Off layer +Turns off layer state. + + ACTION_LAYER_OFF(layer, on) + +Turns off layer state on press and activates on release. + + ACTION_LAYER_OFF_ON(layer) + + +#### 2.2.9 Set layer +Turn on layer only. +`layer_state = (1<<layer) [layer: 0-31]` + + ACTION_LAYER_SET(layer, on) + +Turns on layer only and clear all layer on release.. + + ACTION_LAYER_SET_CLEAR(layer) + + +#### 2.2.10 Bitwise operation + +**part** indicates which part of 32bit layer state(0-7). **bits** is 5-bit value. **on** indicates when the action is executed. + + ACTION_LAYER_BIT_AND(part, bits, on) + ACTION_LAYER_BIT_OR(part, bits, on) + ACTION_LAYER_BIT_XOR(part, bits, on) + ACTION_LAYER_BIT_SET(part, bits, on) + +These actions works with parameters as following code. + + uint8_t shift = part*4; + uint32_t mask = (bits&0x10) ? ~(0xf<<shift) : 0; + uint32_t layer_state = layer_state <bitop> ((bits<<shift)|mask); + + +Default Layer also has bitwise operations, they are executed when key is released. + + ACTION_DEFAULT_LAYER_BIT_AND(part, bits) + ACTION_DEFAULT_LAYER_BIT_OR(part, bits) + ACTION_DEFAULT_LAYER_BIT_XOR(part, bits) + ACTION_DEFAULT_LAYER_BIT_SET(part, bits) + + + +### 2.3 Macro action +***TBD*** + +`Macro` action indicates complex key strokes. + + MACRO( D(LSHIFT), D(D), END ) + MACRO( U(D), U(LSHIFT), END ) + MACRO( I(255), T(H), T(E), T(L), T(L), W(255), T(O), END ) + +#### 2.3.1 Macro Commands +- **I()** change interval of stroke. +- **D()** press key +- **U()** release key +- **T()** type key(press and release) +- **W()** wait +- **END** end mark + +#### 2.3.2 Examples + +***TODO: sample implementation*** +See `keyboards/hhkb/keymap.c` for sample. + + + +### 2.4 Function action +***TBD*** + +There are two type of action, normal `Function` and tappable `Function`. +These actions call user defined function with `id`, `opt`, and key event information as arguments. + +#### 2.4.1 Function +To define normal `Function` action in keymap use this. + + ACTION_FUNCTION(id, opt) + +#### 2.4.2 Function with tap +To define tappable `Function` action in keymap use this. + + ACTION_FUNCTION_TAP(id, opt) + +#### 2.4.3 Implement user function +`Function` actions can be defined freely with C by user in callback function: + + void keymap_call_function(keyrecord_t *event, uint8_t id, uint8_t opt) + +This C function is called every time key is operated, argument `id` selects action to be performed and `opt` can be used for option. Function `id` can be 0-255 and `opt` can be 0-15. + + `keyrecord_t` is comprised of key event and tap count. `keyevent_t` indicates which and when key is pressed or released. From `tap_count` you can know tap state, 0 means no tap. These information will be used in user function to decide how action of key is performed. + + typedef struct { + keyevent_t event; + uint8_t tap_count; + } keyrecord_t; + + typedef struct { + key_t key; + bool pressed; + uint16_t time; + } keyevent_t; + + typedef struct { + uint8_t col; + uint8_t row; + } key_t; + +***TODO: sample implementation*** +See `keyboards/hhkb/keymap.c` for sample. + + + +### 2.5 Backlight Action +These actions control the backlight. + +#### 2.5.1 Change backlight level +Increase backlight level. + + ACTION_BACKLIGHT_INCREASE() + +Decrease backlight level. + + ACTION_BACKLIGHT_DECREASE() + +Step through backlight levels. + + ACTION_BACKLIGHT_STEP() + +Turn a specific backlight level on or off. + + ACTION_BACKLIGHT_LEVEL(1) + +#### 2.5.2 Turn on / off backlight +Turn the backlight on and off without changing level. + + ACTION_BACKLIGHT_TOGGLE() + + + +### 2.6 Swap-Hands Action +The swap-hands action allows support for one-handed keyboards without requiring a separate layer. Set `ONEHAND_ENABLE` in the Makefile and define a `hand_swap_config` entry in your keymap. Now whenever the `ACTION_SWAP_HANDS` command key is pressed the keyboard is mirrored. For instance, to type "Hello, World" on QWERTY you would type `^Ge^s^s^w^c W^wr^sd` + +### 2.6.1 Configuration +The configuration table is a simple 2-dimensional array to map from column/row to new column/row. Example `hand_swap_config` for Planck: + +``` +const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = { + {{11, 0}, {10, 0}, {9, 0}, {8, 0}, {7, 0}, {6, 0}, {5, 0}, {4, 0}, {3, 0}, {2, 0}, {1, 0}, {0, 0}}, + {{11, 1}, {10, 1}, {9, 1}, {8, 1}, {7, 1}, {6, 1}, {5, 1}, {4, 1}, {3, 1}, {2, 1}, {1, 1}, {0, 1}}, + {{11, 2}, {10, 2}, {9, 2}, {8, 2}, {7, 2}, {6, 2}, {5, 2}, {4, 2}, {3, 2}, {2, 2}, {1, 2}, {0, 2}}, + {{11, 3}, {10, 3}, {9, 3}, {8, 3}, {7, 3}, {6, 3}, {5, 3}, {4, 3}, {3, 3}, {2, 3}, {1, 3}, {0, 3}}, +}; +``` + +Note that the array indices are reversed same as the matrix and the values are of type `keypos_t` which is `{col, row}` and all values are zero-based. In the example above, `hand_swap_config[2][4]` (third row, fifth column) would return {7, 2} (third row, eighth column). + +### 2.6.2 Advanced Swap Commands +- **`ACTION_SWAP_HANDS()`** Swaps hands when pressed, returns to normal when released (momentary). +- **`ACTION_SWAP_HANDS_TOGGLE()`** Toggles swap on and off with every keypress. +- **`ACTION_SWAP_HANDS_TAP_TOGGLE()`** Toggles with a tap; momentary when held. +- **`ACTION_SWAP_HANDS_TAP_KEY(key)`** Sends `key` with a tap; momentary swap when held. +- **`ACTION_SWAP_HANDS_ON_OFF()`** Alias for `ACTION_SWAP_HANDS()` +- **`ACTION_SWAP_HANDS_OFF_ON()`** Momentarily turns off swap. +- **`ACTION_SWAP_HANDS_ON()`** Turns on swapping and leaves it on. +- **`ACTION_SWAP_HANDS_OFF()`** Turn off swapping and leaves it off. Good for returning to a known state. + + + +## 3. Layer switching Example +There are some ways to switch layer with 'Layer' actions. + +### 3.1 Momentary switching +Momentary switching changes layer only while holding Fn key. + +This action makes 'Layer 1' active(valid) on key press event and inactive on release event. Namely you can overlay a layer on lower layers or default layer temporarily with this action. + + ACTION_LAYER_MOMENTARY(1) + + +Note that after switching on press the actions on destination layer(Layer 1) are performed. +***Thus you shall need to place an action to go back on destination layer***, or you will be stuck in destination layer without way to get back. Usually you need to place same action or 'KC_TRNS` on destination layer to get back. + + +### 3.2 Toggle switching +Toggle switching performed after releasing a key. With this action you can keep staying on the destination layer until you type the key again to return. + +This performs toggle switching action of 'Layer 2'. + + ACTION_LAYER_TOGGLE(2) + + + +### 3.3 Momentary switching with Tap key +These actions switch a layer only while holding a key but register the key on tap. **Tap** means to press and release a key quickly. + + ACTION_LAYER_TAP_KEY(2, KC_SCLN) + +With this you can place a layer switching action on normal key like ';' without losing its original key register function. This action allows you to have layer switching action without necessity of a dedicated key. It means you can have it even on home row of keyboard. + + + +### 3.4 Momentary switching with Tap Toggle +This switches layer only while holding a key but toggle layer with several taps. **Tap** means to press and release key quickly. + + ACTION_LAYER_TAP_TOGGLE(1) + +Number of taps can be configured with `TAPPING_TOGGLE` in `config.h`, `5` by default. + + + +### 3.5 Momentary switching with Modifiers +This registers modifier key(s) simultaneously with layer switching. + + ACTION_LAYER_MODS(2, MOD_LSFT | MOD_LALT) + + + +## 4. Tapping +Tapping is to press and release a key quickly. Tapping speed is determined with setting of `TAPPING_TERM`, which can be defined in `config.h`, 200ms by default. + +### 4.1 Tap Key +This is a feature to assign normal key action and modifier including layer switching to just same one physical key. This is a kind of [Dual role key][dual_role]. It works as modifier when holding the key but registers normal key when tapping. + +Modifier with tap key: + + ACTION_MODS_TAP_KEY(MOD_RSFT, KC_GRV) + +Layer switching with tap key: + + ACTION_LAYER_TAP_KEY(2, KC_SCLN) + +[dual_role]: http://en.wikipedia.org/wiki/Modifier_key#Dual-role_keys + +When user hold a key after tap, it repeat the tapped key rather to hold a modifier key. +If you prefer to hold a modifier instead, define `TAPPING_FORCE_HOLD` in `config.h`. +See https://github.com/qmk/qmk_firmware/issues/889 for the detail. + +### 4.2 Tap Toggle +This is a feature to assign both toggle layer and momentary switch layer action to just same one physical key. It works as momentary layer switch when holding a key but toggle switch with several taps. + + ACTION_LAYER_TAP_TOGGLE(1) + + +### 4.3 Oneshot Modifier +This runs onetime effects which modify only on just one following key. It works as normal modifier key when holding down while oneshot modifier when tapping. The behavior of oneshot modifiers is similar to the [sticky keys](https://en.wikipedia.org/wiki/StickyKeys) functionality found in most operating systems. + + ACTION_MODS_ONESHOT(MOD_LSFT) + +Oneshot layer key: + + ACTION_LAYER_ONESHOT(MY_LAYER) + +Say you want to type 'The', you have to push and hold Shift key before type 't' then release it before type 'h' and 'e', otherwise you'll get 'THe' or 'the' unintentionally. With Oneshot Modifier you can tap Shift then type 't', 'h' and 'e' normally, you don't need to holding Shift key properly here. This mean you can release Shift before 't' is pressed down. + +Oneshot effect is cancel unless following key is pressed down within `ONESHOT_TIMEOUT` of `config.h`. No timeout when it is `0` or not defined. + +Most implementations of sticky keys allow you to lock a modifier by double tapping the modifier. The layer then remains locked untill the modifier is tapped again. To enable this behaviour for oneshot modifiers set `ONESHOT_TAP_TOGGLE` to the number taps required. The feature is disabled if `ONESHOT_TAP_TOGGLE<2` or not defined. + + +### 4.4 Tap Toggle Mods +Similar to layer tap toggle, this works as a momentary modifier when holding, but toggles on with several taps. A single tap will 'unstick' the modifier again. + + ACTION_MODS_TAP_TOGGLE(MOD_LSFT) + + + + +## 5. Legacy Keymap +In QMK, `tmk_core/common/keymap.c` is missing and its replacement `quantum/keymap_common.c` lacks Legacy Keymap support. + +Legacy Keymap uses two arrays `fn_layer[]` and `fn_keycode[]` to define Fn key. The index of arrays corresponds with postfix number of `Fn` key. Array `fn_layer[]` indicates destination layer to switch and `fn_keycode[]` has keycodes to send when tapping `Fn` key. + +In the following legacy keymap setting example, `Fn0`, `Fn1` and `Fn2` switch layer to 1, 2 and 2 respectively. `Fn2` registers `Space` key when tapping while `Fn0` and `Fn1` doesn't send any key. + + static const uint8_t PROGMEM fn_layer[] = { + 1, // Fn0 + 2, // Fn1 + 2, // Fn2 + }; + + static const uint8_t PROGMEM fn_keycode[] = { + KC_NO, // Fn0 + KC_NO, // Fn1 + KC_SPC, // Fn2 + }; + +Under QMK, these can be realized using action code ACTION_LAYER_TAP_KEY(1, KC_NO), ACTION_LAYER_TAP_KEY(2, KC_NO), and ACTION_LAYER_TAP_KEY(2, KC_SPC) in the `keymaps` directly. + +## 6. Terminology +***TBD*** +### keymap +is comprised of multiple layers. +### layer +is matrix of keycodes. +### key +is physical button on keyboard or logical switch on software. +### keycode +is codes used on firmware. +### action +is a function assigned on a key. +### layer transparency +Using transparent keycode one layer can refer key definition on other lower layer. +### layer precedence +Top layer has higher precedence than lower layers. +### tapping +is to press and release a key quickly. +### Fn key +is key which executes a special action like layer switching, mouse key, macro or etc. +### dual role key +<http://en.wikipedia.org/wiki/Modifier_key#Dual-role_keys> diff --git a/docs/other_projects.md b/docs/other_projects.md new file mode 100644 index 0000000000..bf980b0a9e --- /dev/null +++ b/docs/other_projects.md @@ -0,0 +1,62 @@ +Other Keyboard Firmware Projects +================================ +## PJRC USB Keyboard/Mouse Example[USB][PJRC][Teensy][AVR] +- <http://www.pjrc.com/teensy/usb_keyboard.html> +- <http://www.pjrc.com/teensy/usb_mouse.html> + +## kbupgrade[USB][V-USB][AVR] +- <http://github.com/rhomann/kbupgrade> +- <http://geekhack.org/showwiki.php?title=Island:8406> + +## c64key[USB][V-USB][AVR] +- <http://symlink.dk/projects/c64key/> + +## rump[USB][V-USB][AVR] +- <http://mg8.org/rump/> +- <http://github.com/clee/rump> + +## dulcimer[USB][V-USB][AVR] +- <http://www.schatenseite.de/dulcimer.html> + +## humblehacker-keyboard[USB][LUFA][AVR][Ergo] +- <http://github.com/humblehacker> +- <http://www.humblehacker.com/keyboard/> +- <http://geekhack.org/showwiki.php?title=Island:6292> + +## ps2avr[PS/2][AVR] +- <http://sourceforge.net/projects/ps2avr/> + +## ErgoDox[Ergo][Split][USB][AVR] +- <http://geekhack.org/index.php?topic=22780.0> +- <https://github.com/benblazak/ergodox-firmware> +- <https://github.com/cub-uanic/tmk_keyboard> + +## Suka's keyboard collection[Ergo][Split][3DPrinting][USB][AVR] +- <http://deskthority.net/workshop-f7/my-diy-keyboard-collection-or-how-i-became-a-kb-geek-t2534.html> +- <https://github.com/frobiac/adnw> + +## bpiphany's AVR-Keyboard[PJRC][AVR][USB] +- <https://github.com/BathroomEpiphanies/AVR-Keyboard> +- <http://deskthority.net/wiki/HID_Liberation_Device_-_DIY_Instructions> +- <http://deskthority.net/wiki/Phantom> + +## USB-USB keyboard remapper[converter][USB-USB][AVR][Arduino] +- <http://forum.colemak.com/viewtopic.php?pid=10837> +- <https://github.com/darkytoothpaste/keymapper> + +## USB-USB converter threads[converter][USB-USB] +- <http://deskthority.net/workshop-f7/is-remapping-a-usb-keyboard-using-teensy-possible-t2841-30.html> +- <http://geekhack.org/index.php?topic=19458.0> + +## kbdbabel.org[converter][vintage][protocol][8051] +Great resource of vintage keyboard protocol information and code + +- <http://www.kbdbabel.org/> + +## Haata's kiibohd Controller[converter][vintage][protocol][AVR][PJRC][Cortex] +A lots of vintage keyboard protocol supports + +- <http://gitorious.org/kiibohd-controller> + +## Kinesis ergonomic keyboard firmware replacement[V-USB][LUFA][Ergo] +- <https://github.com/chrisandreae/kinesis-firmware> |