diff options
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | keyboard/kmac/Makefile.lufa | 130 | ||||
| -rw-r--r-- | keyboard/kmac/Makefile.pjrc | 101 | ||||
| -rw-r--r-- | keyboard/kmac/README.md | 110 | ||||
| -rw-r--r-- | keyboard/kmac/backlight.c | 58 | ||||
| -rw-r--r-- | keyboard/kmac/config.h | 50 | ||||
| -rw-r--r-- | keyboard/kmac/keymap.c | 97 | ||||
| -rw-r--r-- | keyboard/kmac/keymap_winkey.h | 24 | ||||
| -rw-r--r-- | keyboard/kmac/keymap_winkeyless.h | 24 | ||||
| -rw-r--r-- | keyboard/kmac/led.c | 54 | ||||
| -rw-r--r-- | keyboard/kmac/matrix.c | 283 |
11 files changed, 932 insertions, 0 deletions
| @@ -49,6 +49,7 @@ You can find some keyboard specific projects under `converter` and `keyboard` di | |||
| 49 | * [phantom](keyboard/phantom/) - [Phantom] keyboard (by Tranquilite) | 49 | * [phantom](keyboard/phantom/) - [Phantom] keyboard (by Tranquilite) |
| 50 | * [IIgs_Standard](keyboard/IIgs/) - Apple [IIGS] keyboard mod(by JeffreySung) | 50 | * [IIgs_Standard](keyboard/IIgs/) - Apple [IIGS] keyboard mod(by JeffreySung) |
| 51 | * [macway](keyboard/macway/) - [Compact keyboard mod][GH_macway] [retired] | 51 | * [macway](keyboard/macway/) - [Compact keyboard mod][GH_macway] [retired] |
| 52 | * [KMAC](keyboard/kmac/) - Korean custom keyboard | ||
| 52 | 53 | ||
| 53 | [GH_macway]: http://geekhack.org/showwiki.php?title=Island:11930 | 54 | [GH_macway]: http://geekhack.org/showwiki.php?title=Island:11930 |
| 54 | [GH_hhkb]: http://geekhack.org/showwiki.php?title=Island:12047 | 55 | [GH_hhkb]: http://geekhack.org/showwiki.php?title=Island:12047 |
diff --git a/keyboard/kmac/Makefile.lufa b/keyboard/kmac/Makefile.lufa new file mode 100644 index 000000000..09343d4bc --- /dev/null +++ b/keyboard/kmac/Makefile.lufa | |||
| @@ -0,0 +1,130 @@ | |||
| 1 | #---------------------------------------------------------------------------- | ||
| 2 | # On command line: | ||
| 3 | # | ||
| 4 | # make all = Make software. | ||
| 5 | # | ||
| 6 | # make clean = Clean out built project files. | ||
| 7 | # | ||
| 8 | # make coff = Convert ELF to AVR COFF. | ||
| 9 | # | ||
| 10 | # make extcoff = Convert ELF to AVR Extended COFF. | ||
| 11 | # | ||
| 12 | # make program = Download the hex file to the device. | ||
| 13 | # Please customize your programmer settings(PROGRAM_CMD) | ||
| 14 | # | ||
| 15 | # make teensy = Download the hex file to the device, using teensy_loader_cli. | ||
| 16 | # (must have teensy_loader_cli installed). | ||
| 17 | # | ||
| 18 | # make dfu = Download the hex file to the device, using dfu-programmer (must | ||
| 19 | # have dfu-programmer installed). | ||
| 20 | # | ||
| 21 | # make flip = Download the hex file to the device, using Atmel FLIP (must | ||
| 22 | # have Atmel FLIP installed). | ||
| 23 | # | ||
| 24 | # make dfu-ee = Download the eeprom file to the device, using dfu-programmer | ||
| 25 | # (must have dfu-programmer installed). | ||
| 26 | # | ||
| 27 | # make flip-ee = Download the eeprom file to the device, using Atmel FLIP | ||
| 28 | # (must have Atmel FLIP installed). | ||
| 29 | # | ||
| 30 | # make debug = Start either simulavr or avarice as specified for debugging, | ||
| 31 | # with avr-gdb or avr-insight as the front end for debugging. | ||
| 32 | # | ||
| 33 | # make filename.s = Just compile filename.c into the assembler code only. | ||
| 34 | # | ||
| 35 | # make filename.i = Create a preprocessed source file for use in submitting | ||
| 36 | # bug reports to the GCC project. | ||
| 37 | # | ||
| 38 | # To rebuild project do "make clean" then "make all". | ||
| 39 | #---------------------------------------------------------------------------- | ||
| 40 | |||
| 41 | # Target file name (without extension). | ||
| 42 | TARGET = kmac_lufa | ||
| 43 | |||
| 44 | # Directory common source filess exist | ||
| 45 | TOP_DIR = ../.. | ||
| 46 | |||
| 47 | # Directory keyboard dependent files exist | ||
| 48 | TARGET_DIR = . | ||
| 49 | |||
| 50 | |||
| 51 | # List C source files here. (C dependencies are automatically generated.) | ||
| 52 | SRC += keymap.c \ | ||
| 53 | matrix.c \ | ||
| 54 | led.c \ | ||
| 55 | backlight.c | ||
| 56 | |||
| 57 | CONFIG_H = config.h | ||
| 58 | |||
| 59 | |||
| 60 | # MCU name | ||
| 61 | #MCU = at90usb1287 | ||
| 62 | MCU = atmega32u4 | ||
| 63 | |||
| 64 | # Processor frequency. | ||
| 65 | # This will define a symbol, F_CPU, in all source code files equal to the | ||
| 66 | # processor frequency in Hz. You can then use this symbol in your source code to | ||
| 67 | # calculate timings. Do NOT tack on a 'UL' at the end, this will be done | ||
| 68 | # automatically to create a 32-bit value in your source code. | ||
| 69 | # | ||
| 70 | # This will be an integer division of F_USB below, as it is sourced by | ||
| 71 | # F_USB after it has run through any CPU prescalers. Note that this value | ||
| 72 | # does not *change* the processor frequency - it should merely be updated to | ||
| 73 | # reflect the processor speed set externally so that the code can use accurate | ||
| 74 | # software delays. | ||
| 75 | F_CPU = 8000000 | ||
| 76 | |||
| 77 | |||
| 78 | # | ||
| 79 | # LUFA specific | ||
| 80 | # | ||
| 81 | # Target architecture (see library "Board Types" documentation). | ||
| 82 | ARCH = AVR8 | ||
| 83 | |||
| 84 | # Input clock frequency. | ||
| 85 | # This will define a symbol, F_USB, in all source code files equal to the | ||
| 86 | # input clock frequency (before any prescaling is performed) in Hz. This value may | ||
| 87 | # differ from F_CPU if prescaling is used on the latter, and is required as the | ||
| 88 | # raw input clock is fed directly to the PLL sections of the AVR for high speed | ||
| 89 | # clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL' | ||
| 90 | # at the end, this will be done automatically to create a 32-bit value in your | ||
| 91 | # source code. | ||
| 92 | # | ||
| 93 | # If no clock division is performed on the input clock inside the AVR (via the | ||
| 94 | # CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. | ||
| 95 | F_USB = $(F_CPU) | ||
| 96 | |||
| 97 | |||
| 98 | # Build Options | ||
| 99 | # comment out to disable the options. | ||
| 100 | # | ||
| 101 | BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) | ||
| 102 | #MOUSEKEY_ENABLE = yes # Mouse keys(+4700) | ||
| 103 | EXTRAKEY_ENABLE = yes # Audio control and System control(+450) | ||
| 104 | CONSOLE_ENABLE = yes # Console for debug(+400) | ||
| 105 | COMMAND_ENABLE = yes # Commands for debug and configuration | ||
| 106 | #SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend | ||
| 107 | #NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA | ||
| 108 | BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality | ||
| 109 | |||
| 110 | |||
| 111 | # Boot Section Size in bytes | ||
| 112 | # Teensy halfKay 512 | ||
| 113 | # Atmel DFU loader 4096 | ||
| 114 | # LUFA bootloader 4096 | ||
| 115 | OPT_DEFS += -DBOOTLOADER_SIZE=4096 | ||
| 116 | |||
| 117 | |||
| 118 | # Search Path | ||
| 119 | VPATH += $(TARGET_DIR) | ||
| 120 | VPATH += $(TOP_DIR) | ||
| 121 | |||
| 122 | include $(TOP_DIR)/protocol/lufa.mk | ||
| 123 | include $(TOP_DIR)/common.mk | ||
| 124 | include $(TOP_DIR)/rules.mk | ||
| 125 | |||
| 126 | winkey: OPT_DEFS += -DLAYOUT_WINKEY | ||
| 127 | winkey: all | ||
| 128 | |||
| 129 | winkeyless: OPT_DEFS += -DLAYOUT_WINKEYLESS | ||
| 130 | winkeyless: all | ||
diff --git a/keyboard/kmac/Makefile.pjrc b/keyboard/kmac/Makefile.pjrc new file mode 100644 index 000000000..22ee8de47 --- /dev/null +++ b/keyboard/kmac/Makefile.pjrc | |||
| @@ -0,0 +1,101 @@ | |||
| 1 | #---------------------------------------------------------------------------- | ||
| 2 | # On command line: | ||
| 3 | # | ||
| 4 | # make all = Make software. | ||
| 5 | # | ||
| 6 | # make clean = Clean out built project files. | ||
| 7 | # | ||
| 8 | # make coff = Convert ELF to AVR COFF. | ||
| 9 | # | ||
| 10 | # make extcoff = Convert ELF to AVR Extended COFF. | ||
| 11 | # | ||
| 12 | # make program = Download the hex file to the device. | ||
| 13 | # Please customize your programmer settings(PROGRAM_CMD) | ||
| 14 | # | ||
| 15 | # make teensy = Download the hex file to the device, using teensy_loader_cli. | ||
| 16 | # (must have teensy_loader_cli installed). | ||
| 17 | # | ||
| 18 | # make dfu = Download the hex file to the device, using dfu-programmer (must | ||
| 19 | # have dfu-programmer installed). | ||
| 20 | # | ||
| 21 | # make flip = Download the hex file to the device, using Atmel FLIP (must | ||
| 22 | # have Atmel FLIP installed). | ||
| 23 | # | ||
| 24 | # make dfu-ee = Download the eeprom file to the device, using dfu-programmer | ||
| 25 | # (must have dfu-programmer installed). | ||
| 26 | # | ||
| 27 | # make flip-ee = Download the eeprom file to the device, using Atmel FLIP | ||
| 28 | # (must have Atmel FLIP installed). | ||
| 29 | # | ||
| 30 | # make debug = Start either simulavr or avarice as specified for debugging, | ||
| 31 | # with avr-gdb or avr-insight as the front end for debugging. | ||
| 32 | # | ||
| 33 | # make filename.s = Just compile filename.c into the assembler code only. | ||
| 34 | # | ||
| 35 | # make filename.i = Create a preprocessed source file for use in submitting | ||
| 36 | # bug reports to the GCC project. | ||
| 37 | # | ||
| 38 | # To rebuild project do "make clean" then "make all". | ||
| 39 | #---------------------------------------------------------------------------- | ||
| 40 | |||
| 41 | # Target file name (without extension). | ||
| 42 | TARGET = kmac_pjrc | ||
| 43 | |||
| 44 | # Directory common source filess exist | ||
| 45 | TOP_DIR = ../.. | ||
| 46 | |||
| 47 | # Directory keyboard dependent files exist | ||
| 48 | TARGET_DIR = . | ||
| 49 | |||
| 50 | # keyboard dependent files | ||
| 51 | SRC = keymap.c \ | ||
| 52 | matrix.c \ | ||
| 53 | led.c \ | ||
| 54 | backlight.c | ||
| 55 | |||
| 56 | CONFIG_H = config.h | ||
| 57 | |||
| 58 | |||
| 59 | # MCU name, you MUST set this to match the board you are using | ||
| 60 | # type "make clean" after changing this, so all files will be rebuilt | ||
| 61 | #MCU = at90usb162 # Teensy 1.0 | ||
| 62 | MCU = atmega32u4 # Teensy 2.0 | ||
| 63 | #MCU = at90usb646 # Teensy++ 1.0 | ||
| 64 | #MCU = at90usb1286 # Teensy++ 2.0 | ||
| 65 | |||
| 66 | |||
| 67 | # Processor frequency. | ||
| 68 | # Normally the first thing your program should do is set the clock prescaler, | ||
| 69 | # so your program will run at the correct speed. You should also set this | ||
| 70 | # variable to same clock speed. The _delay_ms() macro uses this, and many | ||
| 71 | # examples use this variable to calculate timings. Do not add a "UL" here. | ||
| 72 | F_CPU = 8000000 | ||
| 73 | |||
| 74 | |||
| 75 | # Build Options | ||
| 76 | # comment out to disable the options. | ||
| 77 | # | ||
| 78 | BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) | ||
| 79 | #MOUSEKEY_ENABLE = yes # Mouse keys(+5000) | ||
| 80 | EXTRAKEY_ENABLE = yes # Audio control and System control(+600) | ||
| 81 | CONSOLE_ENABLE = yes # Console for debug | ||
| 82 | COMMAND_ENABLE = yes # Commands for debug and configuration | ||
| 83 | #SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend | ||
| 84 | #NKRO_ENABLE = yes # USB Nkey Rollover(+500) | ||
| 85 | #PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support | ||
| 86 | BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality | ||
| 87 | |||
| 88 | |||
| 89 | # Search Path | ||
| 90 | VPATH += $(TARGET_DIR) | ||
| 91 | VPATH += $(TOP_DIR) | ||
| 92 | |||
| 93 | include $(TOP_DIR)/protocol/pjrc.mk | ||
| 94 | include $(TOP_DIR)/common.mk | ||
| 95 | include $(TOP_DIR)/rules.mk | ||
| 96 | |||
| 97 | winkey: OPT_DEFS += -DLAYOUT_WINKEY | ||
| 98 | winkey: all | ||
| 99 | |||
| 100 | winkeyless: OPT_DEFS += -DLAYOUT_WINKEYLESS | ||
| 101 | winkeyless: all | ||
diff --git a/keyboard/kmac/README.md b/keyboard/kmac/README.md new file mode 100644 index 000000000..8cfe0971d --- /dev/null +++ b/keyboard/kmac/README.md | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | KMAC keyboard firmware | ||
| 2 | ====================== | ||
| 3 | Korean custom keyboard designed by Byungho Kim and KBDMania community. | ||
| 4 | |||
| 5 | *Note that this is not the official firmware* | ||
| 6 | |||
| 7 | Supported models | ||
| 8 | ---------------- | ||
| 9 | At the moment only the TKL models is supported. | ||
| 10 | |||
| 11 | |||
| 12 | Build | ||
| 13 | ----- | ||
| 14 | Move to this directory then just run `make` like: | ||
| 15 | |||
| 16 | $ make -f Makefile.[pjrc|lufa] [winkey|winkeyless] | ||
| 17 | |||
| 18 | Use `Makefile.pjrc` if you want to use PJRC stack or use `Makefile.lufa` for LUFA stack. | ||
| 19 | |||
| 20 | |||
| 21 | Booloader | ||
| 22 | --------- | ||
| 23 | The PCB is hardwired to run the bootloader if the key at the `Caps Lock` position is held down when connecting the keyboard. | ||
| 24 | |||
| 25 | It is still possible to use Boot Magic and Command to access the bootloader though. | ||
| 26 | |||
| 27 | |||
| 28 | Keymap | ||
| 29 | ------ | ||
| 30 | There are 2 different types of PCB. | ||
| 31 | They each have their own keymap file. | ||
| 32 | |||
| 33 | To customize a keymap: | ||
| 34 | 1. Edit the file that corresponds to your PCB. | ||
| 35 | 2. Specify your layout when building. | ||
| 36 | |||
| 37 | ### 1. Winkey | ||
| 38 | This is the default keymap. | ||
| 39 | |||
| 40 | See [keymap_winkey.h](keymap_winkey.h) for detail. | ||
| 41 | |||
| 42 | #### 1.0. Winkey Default Layer | ||
| 43 | ,---. ,---------------. ,---------------. ,---------------. ,-----------. | ||
| 44 | |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau| | ||
| 45 | `---' `---------------' `---------------' `---------------' `-----------' | ||
| 46 | ,-----------------------------------------------------------. ,-----------. | ||
| 47 | |~ | 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp | |Ins|Hom|PgU| | ||
| 48 | |-----------------------------------------------------------| |-----------| | ||
| 49 | |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| |Del|End|PgD| | ||
| 50 | |-----------------------------------------------------------| '-----------' | ||
| 51 | |Fn0 | A| S| D| F| G| H| J| K| L| ;| '|Return | | ||
| 52 | |-----------------------------------------------------------| ,---. | ||
| 53 | |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift | |Up | | ||
| 54 | |-----------------------------------------------------------| ,-----------. | ||
| 55 | |Ctl|Gui|Alt| Space |Alt|Gui|App|Ctl| |Lef|Dow|Rig| | ||
| 56 | `-----------------------------------------------------------' `-----------' | ||
| 57 | |||
| 58 | #### 1.1. Winkey Media Layer | ||
| 59 | ,---. ,---------------. ,---------------. ,---------------. ,-----------. | ||
| 60 | |Led| | | | | | | | | | | | | | | | | | |Slp| | ||
| 61 | `---' `---------------' `---------------' `---------------' `-----------' | ||
| 62 | ,-----------------------------------------------------------. ,-----------. | ||
| 63 | | | | | | | | | | | |Mut|V- |V+ | | | | | | | ||
| 64 | |-----------------------------------------------------------| |-----------| | ||
| 65 | | | | | | | | | | |Stp|Ply|Prv|Nxt|Media| | | | | | ||
| 66 | |-----------------------------------------------------------| '-----------' | ||
| 67 | | | | | | | | | | | | | | | | ||
| 68 | |-----------------------------------------------------------| ,---. | ||
| 69 | | | | |Clc| | | | | | | |Caps | | | | ||
| 70 | |-----------------------------------------------------------| ,-----------. | ||
| 71 | | | | | | | | | | | | | | | ||
| 72 | `-----------------------------------------------------------' `-----------' | ||
| 73 | |||
| 74 | |||
| 75 | ### 2. Winkeyless | ||
| 76 | Layout with 1.5 unit modifiers. | ||
| 77 | |||
| 78 | See [keymap_winkeyless.h](keymap_winkeyless.h) for detail. | ||
| 79 | |||
| 80 | #### 2.0. Winkeyless Default Layer | ||
| 81 | ,---. ,---------------. ,---------------. ,---------------. ,-----------. | ||
| 82 | |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau| | ||
| 83 | `---' `---------------' `---------------' `---------------' `-----------' | ||
| 84 | ,-----------------------------------------------------------. ,-----------. | ||
| 85 | |~ | 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp | |Ins|Hom|PgU| | ||
| 86 | |-----------------------------------------------------------| |-----------| | ||
| 87 | |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| |Del|End|PgD| | ||
| 88 | |-----------------------------------------------------------| '-----------' | ||
| 89 | |Fn0 | A| S| D| F| G| H| J| K| L| ;| '|Return | | ||
| 90 | |-----------------------------------------------------------| ,---. | ||
| 91 | |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift | |Up | | ||
| 92 | |-----------------------------------------------------------| ,-----------. | ||
| 93 | |Ctl |Gui|Alt | Space |Alt |Gui|Ctl | |Lef|Dow|Rig| | ||
| 94 | `-----------------------------------------------------------' `-----------' | ||
| 95 | |||
| 96 | #### 2.1. Winkeyless Media Layer | ||
| 97 | ,---. ,---------------. ,---------------. ,---------------. ,-----------. | ||
| 98 | |Led| | | | | | | | | | | | | | | | | | |Slp| | ||
| 99 | `---' `---------------' `---------------' `---------------' `-----------' | ||
| 100 | ,-----------------------------------------------------------. ,-----------. | ||
| 101 | | | | | | | | | | | |Mut|V- |V+ | | | | | | | ||
| 102 | |-----------------------------------------------------------| |-----------| | ||
| 103 | | | | | | | | | | |Stp|Ply|Prv|Nxt|Media| | | | | | ||
| 104 | |-----------------------------------------------------------| '-----------' | ||
| 105 | | | | | | | | | | | | | | | | ||
| 106 | |-----------------------------------------------------------| ,---. | ||
| 107 | | | | |Clc| | | | | | | |Caps | | | | ||
| 108 | |-----------------------------------------------------------| ,-----------. | ||
| 109 | | | | | | | | | | | | | | ||
| 110 | `-----------------------------------------------------------' `-----------' | ||
diff --git a/keyboard/kmac/backlight.c b/keyboard/kmac/backlight.c new file mode 100644 index 000000000..af38f658a --- /dev/null +++ b/keyboard/kmac/backlight.c | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2013 Mathias Andersson <wraul@dbox.se> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <avr/io.h> | ||
| 19 | #include "backlight.h" | ||
| 20 | |||
| 21 | /* Backlight pin configuration | ||
| 22 | * F-row: High PB1 | ||
| 23 | * W: Low PB4 | ||
| 24 | * A: Low PB2 | ||
| 25 | * S: Low PB3 | ||
| 26 | * D: Low PD7 | ||
| 27 | */ | ||
| 28 | void backlight_set(uint8_t level) | ||
| 29 | { | ||
| 30 | // Set as output. | ||
| 31 | DDRB |= (1<<1) | (1<<2) | (1<<3) | (1<<4); | ||
| 32 | DDRD |= (1<<7); | ||
| 33 | |||
| 34 | // F-row | ||
| 35 | if(level & (1<<0)) | ||
| 36 | { | ||
| 37 | PORTB |= (1<<1); | ||
| 38 | } | ||
| 39 | else | ||
| 40 | { | ||
| 41 | PORTB &= ~(1<<1); | ||
| 42 | } | ||
| 43 | // WASD | ||
| 44 | if(level & (1<<1)) | ||
| 45 | { | ||
| 46 | PORTB &= ~(1<<4); | ||
| 47 | PORTB &= ~(1<<2); | ||
| 48 | PORTB &= ~(1<<3); | ||
| 49 | PORTD &= ~(1<<7); | ||
| 50 | } | ||
| 51 | else | ||
| 52 | { | ||
| 53 | PORTB |= (1<<4); | ||
| 54 | PORTB |= (1<<2); | ||
| 55 | PORTB |= (1<<3); | ||
| 56 | PORTD |= (1<<7); | ||
| 57 | } | ||
| 58 | } | ||
diff --git a/keyboard/kmac/config.h b/keyboard/kmac/config.h new file mode 100644 index 000000000..c88df9451 --- /dev/null +++ b/keyboard/kmac/config.h | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2013 Mathias Andersson <wraul@dbox.se> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #ifndef CONFIG_H | ||
| 19 | #define CONFIG_H | ||
| 20 | |||
| 21 | |||
| 22 | /* USB Device descriptor parameter */ | ||
| 23 | #define VENDOR_ID 0xFEED | ||
| 24 | #define PRODUCT_ID 0x6050 | ||
| 25 | #define DEVICE_VER 0x0104 | ||
| 26 | #define MANUFACTURER KBDMania | ||
| 27 | #define PRODUCT KMAC | ||
| 28 | |||
| 29 | /* message strings */ | ||
| 30 | #define DESCRIPTION t.m.k. keyboard firmware for KMAC | ||
| 31 | |||
| 32 | /* matrix size */ | ||
| 33 | #define MATRIX_ROWS 6 | ||
| 34 | #define MATRIX_COLS 17 | ||
| 35 | |||
| 36 | /* number of backlight levels */ | ||
| 37 | #define BACKLIGHT_LEVELS 3 | ||
| 38 | |||
| 39 | /* define if matrix has ghost */ | ||
| 40 | //#define MATRIX_HAS_GHOST | ||
| 41 | |||
| 42 | /* Set 0 if need no debouncing */ | ||
| 43 | #define DEBOUNCE 5 | ||
| 44 | |||
| 45 | /* key combination for command */ | ||
| 46 | #define IS_COMMAND() ( \ | ||
| 47 | keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ | ||
| 48 | ) | ||
| 49 | |||
| 50 | #endif | ||
diff --git a/keyboard/kmac/keymap.c b/keyboard/kmac/keymap.c new file mode 100644 index 000000000..5474b1b65 --- /dev/null +++ b/keyboard/kmac/keymap.c | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2013 Mathias Andersson <wraul@dbox.se> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | /* | ||
| 19 | * Keymap for KMAC controller | ||
| 20 | */ | ||
| 21 | #include <stdint.h> | ||
| 22 | #include <stdbool.h> | ||
| 23 | #include <avr/pgmspace.h> | ||
| 24 | #include "keycode.h" | ||
| 25 | #include "action.h" | ||
| 26 | #include "action_macro.h" | ||
| 27 | #include "report.h" | ||
| 28 | #include "host.h" | ||
| 29 | #include "debug.h" | ||
| 30 | #include "keymap.h" | ||
| 31 | |||
| 32 | // Convert physical keyboard layout to matrix array. | ||
| 33 | // This is a macro to define keymap easily in keyboard layout form. | ||
| 34 | #define KEYMAP( \ | ||
| 35 | K5A, K5C, K5D, K5E, K5F, K5G, K5H, K5I, K5J, K5K, K5L, K5M, K5N, K5O, K5P, K5Q, \ | ||
| 36 | K4A, K4B, K4C, K4D, K4E, K4F, K4G, K4H, K4I, K4J, K4K, K4L, K4M, K4N, K4O, K4P, K4Q, \ | ||
| 37 | K3A, K3B, K3C, K3D, K3E, K3F, K3G, K3H, K3I, K3J, K3K, K3L, K3M, K3N, K3O, K3P, K3Q, \ | ||
| 38 | K2A, K2B, K2C, K2D, K2E, K2F, K2G, K2H, K2I, K2J, K2K, K2L, K2N, \ | ||
| 39 | K1A, K1C, K1D, K1E, K1F, K1G, K1H, K1I, K1J, K1K, K1L, K1N, K1P, \ | ||
| 40 | K0A, K0B, K0C, K0G, K0K, K0L, K0M, K0N, K0O, K0P, K0Q \ | ||
| 41 | ) { \ | ||
| 42 | /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 */ \ | ||
| 43 | /* 5 */ { KC_##K5A, KC_NO, KC_##K5C, KC_##K5D, KC_##K5E, KC_##K5F, KC_##K5G, KC_##K5H, KC_##K5I, KC_##K5J, KC_##K5K, KC_##K5L, KC_##K5M, KC_##K5N, KC_##K5O, KC_##K5P, KC_##K5Q}, \ | ||
| 44 | /* 4 */ { KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D, KC_##K4E, KC_##K4F, KC_##K4G, KC_##K4H, KC_##K4I, KC_##K4J, KC_##K4K, KC_##K4L, KC_##K4M, KC_##K4N, KC_##K4O, KC_##K4P, KC_##K4Q}, \ | ||
| 45 | /* 3 */ { KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D, KC_##K3E, KC_##K3F, KC_##K3G, KC_##K3H, KC_##K3I, KC_##K3J, KC_##K3K, KC_##K3L, KC_##K3M, KC_##K3N, KC_##K3O, KC_##K3P, KC_##K3Q}, \ | ||
| 46 | /* 2 */ { KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D, KC_##K2E, KC_##K2F, KC_##K2G, KC_##K2H, KC_##K2I, KC_##K2J, KC_##K2K, KC_##K2L, KC_NO, KC_##K2N, KC_NO, KC_NO, KC_NO }, \ | ||
| 47 | /* 1 */ { KC_##K1A, KC_##K1C, KC_##K1D, KC_##K1E, KC_##K1F, KC_##K1G, KC_##K1H, KC_##K1I, KC_##K1J, KC_##K1K, KC_##K1L, KC_NO, KC_NO, KC_##K1N, KC_NO, KC_##K1P, KC_NO }, \ | ||
| 48 | /* 0 */ { KC_##K0A, KC_##K0B, KC_##K0C, KC_NO, KC_NO, KC_##K0G, KC_NO, KC_NO, KC_##K0K, KC_NO, KC_##K0L, KC_NO, KC_##K0M, KC_##K0N, KC_##K0O, KC_##K0P, KC_##K0Q} \ | ||
| 49 | } | ||
| 50 | |||
| 51 | #define KEYMAP_WINKEYLESS( \ | ||
| 52 | K5A, K5C, K5D, K5E, K5F, K5G, K5H, K5I, K5J, K5K, K5L, K5M, K5N, K5O, K5P, K5Q, \ | ||
| 53 | K4A, K4B, K4C, K4D, K4E, K4F, K4G, K4H, K4I, K4J, K4K, K4L, K4M, K4N, K4O, K4P, K4Q, \ | ||
| 54 | K3A, K3B, K3C, K3D, K3E, K3F, K3G, K3H, K3I, K3J, K3K, K3L, K3M, K3N, K3O, K3P, K3Q, \ | ||
| 55 | K2A, K2B, K2C, K2D, K2E, K2F, K2G, K2H, K2I, K2J, K2K, K2L, K2N, \ | ||
| 56 | K1A, K1C, K1D, K1E, K1F, K1G, K1H, K1I, K1J, K1K, K1L, K1N, K1P, \ | ||
| 57 | K0A, K0B, K0C, K0G, K0L, K0M, K0N, K0O, K0P, K0Q \ | ||
| 58 | ) KEYMAP( \ | ||
| 59 | K5A, K5C, K5D, K5E, K5F, K5G, K5H, K5I, K5J, K5K, K5L, K5M, K5N, K5O, K5P, K5Q, \ | ||
| 60 | K4A, K4B, K4C, K4D, K4E, K4F, K4G, K4H, K4I, K4J, K4K, K4L, K4M, K4N, K4O, K4P, K4Q, \ | ||
| 61 | K3A, K3B, K3C, K3D, K3E, K3F, K3G, K3H, K3I, K3J, K3K, K3L, K3M, K3N, K3O, K3P, K3Q, \ | ||
| 62 | K2A, K2B, K2C, K2D, K2E, K2F, K2G, K2H, K2I, K2J, K2K, K2L, K2N, \ | ||
| 63 | K1A, K1C, K1D, K1E, K1F, K1G, K1H, K1I, K1J, K1K, K1L, K1N, K1P, \ | ||
| 64 | K0A, K0B, K0C, K0G, K0L, K0M, NO, K0N, K0O, K0P, K0Q \ | ||
| 65 | ) | ||
| 66 | |||
| 67 | #if defined(LAYOUT_WINKEYLESS) | ||
| 68 | #include "keymap_winkeyless.h" | ||
| 69 | #else | ||
| 70 | #include "keymap_winkey.h" | ||
| 71 | #endif | ||
| 72 | |||
| 73 | #define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0])) | ||
| 74 | #define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0])) | ||
| 75 | |||
| 76 | /* translates key to keycode */ | ||
| 77 | uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) | ||
| 78 | { | ||
| 79 | if (layer < KEYMAPS_SIZE) { | ||
| 80 | return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); | ||
| 81 | } else { | ||
| 82 | // fall back to layer 0 | ||
| 83 | return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]); | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | /* translates Fn keycode to action */ | ||
| 88 | action_t keymap_fn_to_action(uint8_t keycode) | ||
| 89 | { | ||
| 90 | action_t action; | ||
| 91 | if (FN_INDEX(keycode) < FN_ACTIONS_SIZE) { | ||
| 92 | action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]); | ||
| 93 | } else { | ||
| 94 | action.code = ACTION_NO; | ||
| 95 | } | ||
| 96 | return action; | ||
| 97 | } | ||
diff --git a/keyboard/kmac/keymap_winkey.h b/keyboard/kmac/keymap_winkey.h new file mode 100644 index 000000000..3379789ec --- /dev/null +++ b/keyboard/kmac/keymap_winkey.h | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | // KMAC Winkey | ||
| 2 | static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
| 3 | /* 0: qwerty */ | ||
| 4 | KEYMAP(\ | ||
| 5 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, \ | ||
| 6 | GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, \ | ||
| 7 | TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, DEL, END, PGDN, \ | ||
| 8 | FN0, A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, \ | ||
| 9 | LSFT, Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, UP, \ | ||
| 10 | LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT), | ||
| 11 | /* 1: media keys */ | ||
| 12 | KEYMAP(\ | ||
| 13 | FN1, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS,TRNS,SLEP, \ | ||
| 14 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,MUTE,VOLD,VOLU,TRNS, TRNS,TRNS,TRNS, \ | ||
| 15 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,MSTP,MPLY,MPRV,MNXT,MSEL, TRNS,TRNS,TRNS, \ | ||
| 16 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ | ||
| 17 | TRNS, TRNS,TRNS,CALC,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, CAPS, TRNS, \ | ||
| 18 | TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS, TRNS,TRNS,TRNS) | ||
| 19 | }; | ||
| 20 | static const uint16_t PROGMEM fn_actions[] = { | ||
| 21 | [0] = ACTION_LAYER_MOMENTARY(1), | ||
| 22 | [1] = ACTION_BACKLIGHT_STEP() | ||
| 23 | }; | ||
| 24 | |||
diff --git a/keyboard/kmac/keymap_winkeyless.h b/keyboard/kmac/keymap_winkeyless.h new file mode 100644 index 000000000..939ee379b --- /dev/null +++ b/keyboard/kmac/keymap_winkeyless.h | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | // KMAC Winkeyless | ||
| 2 | static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
| 3 | /* 0: qwerty */ | ||
| 4 | KEYMAP_WINKEYLESS(\ | ||
| 5 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, \ | ||
| 6 | GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, \ | ||
| 7 | TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, DEL, END, PGDN, \ | ||
| 8 | FN0, A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, \ | ||
| 9 | LSFT, Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, UP, \ | ||
| 10 | LCTL,LGUI,LALT, SPC, RALT,RGUI,RCTL, LEFT,DOWN,RGHT), | ||
| 11 | /* 1: media keys */ | ||
| 12 | KEYMAP_WINKEYLESS(\ | ||
| 13 | FN1, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS,TRNS,SLEP, \ | ||
| 14 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,MUTE,VOLD,VOLU,TRNS, TRNS,TRNS,TRNS, \ | ||
| 15 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,MSTP,MPLY,MPRV,MNXT,MSEL, TRNS,TRNS,TRNS, \ | ||
| 16 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ | ||
| 17 | TRNS, TRNS,TRNS,CALC,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, CAPS, TRNS, \ | ||
| 18 | TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS, TRNS,TRNS,TRNS) | ||
| 19 | }; | ||
| 20 | static const uint16_t PROGMEM fn_actions[] = { | ||
| 21 | [0] = ACTION_LAYER_MOMENTARY(1), | ||
| 22 | [1] = ACTION_BACKLIGHT_STEP() | ||
| 23 | }; | ||
| 24 | |||
diff --git a/keyboard/kmac/led.c b/keyboard/kmac/led.c new file mode 100644 index 000000000..7fa008a43 --- /dev/null +++ b/keyboard/kmac/led.c | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2012 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <avr/io.h> | ||
| 19 | #include "stdint.h" | ||
| 20 | #include "led.h" | ||
| 21 | |||
| 22 | |||
| 23 | /* LED pin configuration | ||
| 24 | * Scroll Lock: Low PE6 | ||
| 25 | * Caps Lock: Low PB0 | ||
| 26 | */ | ||
| 27 | void led_set(uint8_t usb_led) | ||
| 28 | { | ||
| 29 | // Set as output. | ||
| 30 | DDRB |= (1<<0); | ||
| 31 | DDRE |= (1<<6); | ||
| 32 | |||
| 33 | if (usb_led & (1<<USB_LED_CAPS_LOCK)) | ||
| 34 | { | ||
| 35 | // Output low. | ||
| 36 | PORTB &= ~(1<<0); | ||
| 37 | } | ||
| 38 | else | ||
| 39 | { | ||
| 40 | // Output high. | ||
| 41 | PORTB |= (1<<0); | ||
| 42 | } | ||
| 43 | |||
| 44 | if (usb_led & (1<<USB_LED_SCROLL_LOCK)) | ||
| 45 | { | ||
| 46 | // Output low. | ||
| 47 | PORTE &= ~(1<<6); | ||
| 48 | } | ||
| 49 | else | ||
| 50 | { | ||
| 51 | // Output high. | ||
| 52 | PORTE |= (1<<6); | ||
| 53 | } | ||
| 54 | } | ||
diff --git a/keyboard/kmac/matrix.c b/keyboard/kmac/matrix.c new file mode 100644 index 000000000..5248a29b9 --- /dev/null +++ b/keyboard/kmac/matrix.c | |||
| @@ -0,0 +1,283 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2013 Mathias Andersson <wraul@dbox.se> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <stdint.h> | ||
| 19 | #include <stdbool.h> | ||
| 20 | #include <avr/io.h> | ||
| 21 | #include <util/delay.h> | ||
| 22 | #include "print.h" | ||
| 23 | #include "debug.h" | ||
| 24 | #include "util.h" | ||
| 25 | #include "matrix.h" | ||
| 26 | |||
| 27 | |||
| 28 | #ifndef DEBOUNCE | ||
| 29 | # define DEBOUNCE 0 | ||
| 30 | #endif | ||
| 31 | static uint8_t debouncing = DEBOUNCE; | ||
| 32 | |||
| 33 | /* matrix state(1:on, 0:off) */ | ||
| 34 | static matrix_row_t matrix[MATRIX_ROWS]; | ||
| 35 | static matrix_row_t matrix_debouncing[MATRIX_ROWS]; | ||
| 36 | |||
| 37 | static uint8_t read_rows(void); | ||
| 38 | static uint8_t read_caps(void); | ||
| 39 | static void init_rows(void); | ||
| 40 | static void unselect_cols(void); | ||
| 41 | static void select_col(uint8_t col); | ||
| 42 | |||
| 43 | inline | ||
| 44 | uint8_t matrix_rows(void) | ||
| 45 | { | ||
| 46 | return MATRIX_ROWS; | ||
| 47 | } | ||
| 48 | |||
| 49 | inline | ||
| 50 | uint8_t matrix_cols(void) | ||
| 51 | { | ||
| 52 | return MATRIX_COLS; | ||
| 53 | } | ||
| 54 | |||
| 55 | void matrix_init(void) | ||
| 56 | { | ||
| 57 | unselect_cols(); | ||
| 58 | init_rows(); | ||
| 59 | // initialize matrix state: all keys off | ||
| 60 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { | ||
| 61 | matrix[i] = 0; | ||
| 62 | matrix_debouncing[i] = 0; | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | uint8_t matrix_scan(void) | ||
| 67 | { | ||
| 68 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { // 0-16 | ||
| 69 | select_col(col); | ||
| 70 | _delay_us(3); // TODO: Determine the correct value needed here. | ||
| 71 | uint8_t rows = read_rows(); | ||
| 72 | // Use the otherwise unused col: 0 row: 3 for caps lock. | ||
| 73 | if(col == 0) { | ||
| 74 | rows |= read_caps(); | ||
| 75 | } | ||
| 76 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { // 0-5 | ||
| 77 | bool prev_bit = matrix_debouncing[row] & ((matrix_row_t)1<<col); | ||
| 78 | bool curr_bit = rows & (1<<row); | ||
| 79 | if (prev_bit != curr_bit) { | ||
| 80 | matrix_debouncing[row] ^= ((matrix_row_t)1<<col); | ||
| 81 | if (debouncing) { | ||
| 82 | dprint("bounce!: "); dprintf("%02X", debouncing); dprintln(); | ||
| 83 | } | ||
| 84 | debouncing = DEBOUNCE; | ||
| 85 | } | ||
| 86 | } | ||
| 87 | unselect_cols(); | ||
| 88 | } | ||
| 89 | |||
| 90 | if (debouncing) { | ||
| 91 | if (--debouncing) { | ||
| 92 | _delay_ms(1); | ||
| 93 | } else { | ||
| 94 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 95 | matrix[i] = matrix_debouncing[i]; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | return 1; | ||
| 101 | } | ||
| 102 | |||
| 103 | bool matrix_is_modified(void) | ||
| 104 | { | ||
| 105 | if (debouncing) return false; | ||
| 106 | return true; | ||
| 107 | } | ||
| 108 | |||
| 109 | inline | ||
| 110 | bool matrix_is_on(uint8_t row, uint8_t col) | ||
| 111 | { | ||
| 112 | return (matrix[row] & ((matrix_row_t)1<<col)); | ||
| 113 | } | ||
| 114 | |||
| 115 | inline | ||
| 116 | matrix_row_t matrix_get_row(uint8_t row) | ||
| 117 | { | ||
| 118 | return matrix[row]; | ||
| 119 | } | ||
| 120 | |||
| 121 | void matrix_print(void) | ||
| 122 | { | ||
| 123 | print("\nr/c 0123456789ABCDEF\n"); | ||
| 124 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 125 | xprintf("%02X: %032lb\n", row, bitrev32(matrix_get_row(row))); | ||
| 126 | } | ||
| 127 | } | ||
| 128 | |||
| 129 | uint8_t matrix_key_count(void) | ||
| 130 | { | ||
| 131 | uint8_t count = 0; | ||
| 132 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 133 | count += bitpop32(matrix[i]); | ||
| 134 | } | ||
| 135 | return count; | ||
| 136 | } | ||
| 137 | |||
| 138 | /* Row pin configuration | ||
| 139 | * row: 0 1 2 3 4 5 | ||
| 140 | * pin: D0 D1 D2 D3 D5 B7 | ||
| 141 | * | ||
| 142 | * Caps lock uses its own pin PE2 | ||
| 143 | */ | ||
| 144 | static void init_rows(void) | ||
| 145 | { | ||
| 146 | // Input (DDR:0, PORT:0) | ||
| 147 | DDRD &= ~0b00101111; | ||
| 148 | PORTD &= ~0b00101111; | ||
| 149 | DDRB &= ~(1<<7); | ||
| 150 | PORTB &= ~(1<<7); | ||
| 151 | |||
| 152 | // Input with pull-up (DDR:0, PORT:1) | ||
| 153 | DDRE &= ~(1<<2); | ||
| 154 | PORTE |= (1<<2); | ||
| 155 | } | ||
| 156 | |||
| 157 | static uint8_t read_rows(void) | ||
| 158 | { | ||
| 159 | return (PIND&(1<<0) ? (1<<0) : 0) | | ||
| 160 | (PIND&(1<<1) ? (1<<1) : 0) | | ||
| 161 | (PIND&(1<<2) ? (1<<2) : 0) | | ||
| 162 | (PIND&(1<<3) ? (1<<3) : 0) | | ||
| 163 | (PIND&(1<<5) ? (1<<4) : 0) | | ||
| 164 | (PINB&(1<<7) ? (1<<5) : 0); | ||
| 165 | } | ||
| 166 | |||
| 167 | static uint8_t read_caps(void) | ||
| 168 | { | ||
| 169 | return PINE&(1<<2) ? 0 : (1<<3); | ||
| 170 | } | ||
| 171 | |||
| 172 | /* Columns 0 - 15 | ||
| 173 | * These columns uses two 74HC237D 3 to 8 bit demultiplexers. | ||
| 174 | * col / pin: PC6 PB6 PF0 PF1 PC7 | ||
| 175 | * 0: 1 0 0 0 0 | ||
| 176 | * 1: 1 0 1 0 0 | ||
| 177 | * 2: 1 0 0 1 0 | ||
| 178 | * 3: 1 0 1 1 0 | ||
| 179 | * 4: 1 0 0 0 1 | ||
| 180 | * 5: 1 0 1 0 1 | ||
| 181 | * 6: 1 0 0 1 1 | ||
| 182 | * 7: 1 0 1 1 1 | ||
| 183 | * 8: 0 1 0 0 0 | ||
| 184 | * 9: 0 1 1 0 0 | ||
| 185 | * 10: 0 1 0 1 0 | ||
| 186 | * 11: 0 1 1 1 0 | ||
| 187 | * 12: 0 1 0 0 1 | ||
| 188 | * 13: 0 1 1 0 1 | ||
| 189 | * 14: 0 1 0 1 1 | ||
| 190 | * 15: 0 1 1 1 1 | ||
| 191 | * | ||
| 192 | * col: 16 | ||
| 193 | * pin: PB5 | ||
| 194 | */ | ||
| 195 | static void unselect_cols(void) | ||
| 196 | { | ||
| 197 | DDRB |= (1<<5) | (1<<6); | ||
| 198 | PORTB &= ~((1<<5) | (1<<6)); | ||
| 199 | |||
| 200 | DDRC |= (1<<6) | (1<<7); | ||
| 201 | PORTC &= ~((1<<6) | (1<<7)); | ||
| 202 | |||
| 203 | DDRF |= (1<<0) | (1<<1); | ||
| 204 | PORTF &= ~((1<<0) | (1<<1)); | ||
| 205 | } | ||
| 206 | |||
| 207 | static void select_col(uint8_t col) | ||
| 208 | { | ||
| 209 | // Output high (DDR:1, PORT:1) to select | ||
| 210 | switch (col) { | ||
| 211 | case 0: | ||
| 212 | PORTC |= (1<<6); | ||
| 213 | break; | ||
| 214 | case 1: | ||
| 215 | PORTC |= (1<<6); | ||
| 216 | PORTF |= (1<<0); | ||
| 217 | break; | ||
| 218 | case 2: | ||
| 219 | PORTC |= (1<<6); | ||
| 220 | PORTF |= (1<<1); | ||
| 221 | break; | ||
| 222 | case 3: | ||
| 223 | PORTC |= (1<<6); | ||
| 224 | PORTF |= (1<<0) | (1<<1); | ||
| 225 | break; | ||
| 226 | case 4: | ||
| 227 | PORTC |= (1<<6); | ||
| 228 | PORTC |= (1<<7); | ||
| 229 | break; | ||
| 230 | case 5: | ||
| 231 | PORTC |= (1<<6); | ||
| 232 | PORTF |= (1<<0); | ||
| 233 | PORTC |= (1<<7); | ||
| 234 | break; | ||
| 235 | case 6: | ||
| 236 | PORTC |= (1<<6); | ||
| 237 | PORTF |= (1<<1); | ||
| 238 | PORTC |= (1<<7); | ||
| 239 | break; | ||
| 240 | case 7: | ||
| 241 | PORTC |= (1<<6); | ||
| 242 | PORTF |= (1<<0) | (1<<1); | ||
| 243 | PORTC |= (1<<7); | ||
| 244 | break; | ||
| 245 | case 8: | ||
| 246 | PORTB |= (1<<6); | ||
| 247 | break; | ||
| 248 | case 9: | ||
| 249 | PORTB |= (1<<6); | ||
| 250 | PORTF |= (1<<0); | ||
| 251 | break; | ||
| 252 | case 10: | ||
| 253 | PORTB |= (1<<6); | ||
| 254 | PORTF |= (1<<1); | ||
| 255 | break; | ||
| 256 | case 11: | ||
| 257 | PORTB |= (1<<6); | ||
| 258 | PORTF |= (1<<0) | (1<<1); | ||
| 259 | break; | ||
| 260 | case 12: | ||
| 261 | PORTB |= (1<<6); | ||
| 262 | PORTC |= (1<<7); | ||
| 263 | break; | ||
| 264 | case 13: | ||
| 265 | PORTB |= (1<<6); | ||
| 266 | PORTF |= (1<<0); | ||
| 267 | PORTC |= (1<<7); | ||
| 268 | break; | ||
| 269 | case 14: | ||
| 270 | PORTB |= (1<<6); | ||
| 271 | PORTF |= (1<<1); | ||
| 272 | PORTC |= (1<<7); | ||
| 273 | break; | ||
| 274 | case 15: | ||
| 275 | PORTB |= (1<<6); | ||
| 276 | PORTF |= (1<<0) | (1<<1); | ||
| 277 | PORTC |= (1<<7); | ||
| 278 | break; | ||
| 279 | case 16: | ||
| 280 | PORTB |= (1<<5); | ||
| 281 | break; | ||
| 282 | } | ||
| 283 | } | ||
