diff options
| author | tmk <nobody@nowhere> | 2013-06-23 09:19:04 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2013-06-23 09:19:04 +0900 |
| commit | 5a0415749d6cd6a095d9c3fbb335360ec5fa59e0 (patch) | |
| tree | 7ed39e24295fbf853625a12fe273ea3ab4c7b202 | |
| parent | 9de9d719527c7a8cac71d0bc49ba1d2d4f63cf06 (diff) | |
| parent | 25ad212c4adae5a27dd2d5a4e9d6bcdfc17edb1b (diff) | |
| download | qmk_firmware-5a0415749d6cd6a095d9c3fbb335360ec5fa59e0.tar.gz qmk_firmware-5a0415749d6cd6a095d9c3fbb335360ec5fa59e0.zip | |
Merge branch 'Wraul-kmac'
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | common.mk | 5 | ||||
| -rw-r--r-- | common/action.c | 21 | ||||
| -rw-r--r-- | common/action_code.h | 18 | ||||
| -rw-r--r-- | common/backlight.c | 77 | ||||
| -rw-r--r-- | common/backlight.h | 41 | ||||
| -rw-r--r-- | common/command.c | 9 | ||||
| -rw-r--r-- | common/eeconfig.c | 8 | ||||
| -rw-r--r-- | common/eeconfig.h | 7 | ||||
| -rw-r--r-- | common/keyboard.c | 5 | ||||
| -rw-r--r-- | common/suspend.c | 7 | ||||
| -rw-r--r-- | doc/build.md | 1 | ||||
| -rw-r--r-- | doc/keymap.md | 21 | ||||
| -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 |
23 files changed, 1153 insertions, 0 deletions
| @@ -23,6 +23,7 @@ These features can be used in your keyboard. | |||
| 23 | * Virtual DIP Switch - Configurations stored EEPROM(Boot Magic) | 23 | * Virtual DIP Switch - Configurations stored EEPROM(Boot Magic) |
| 24 | * Locking CapsLock - Mechanical switch support for CapsLock | 24 | * Locking CapsLock - Mechanical switch support for CapsLock |
| 25 | * Breathing Sleep LED - Sleep indicator with charm during USB suspend | 25 | * Breathing Sleep LED - Sleep indicator with charm during USB suspend |
| 26 | * Backlight - Control backlight levels | ||
| 26 | 27 | ||
| 27 | 28 | ||
| 28 | Projects | 29 | Projects |
| @@ -48,6 +49,7 @@ You can find some keyboard specific projects under `converter` and `keyboard` di | |||
| 48 | * [phantom](keyboard/phantom/) - [Phantom] keyboard (by Tranquilite) | 49 | * [phantom](keyboard/phantom/) - [Phantom] keyboard (by Tranquilite) |
| 49 | * [IIgs_Standard](keyboard/IIgs/) - Apple [IIGS] keyboard mod(by JeffreySung) | 50 | * [IIgs_Standard](keyboard/IIgs/) - Apple [IIGS] keyboard mod(by JeffreySung) |
| 50 | * [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 | ||
| 51 | 53 | ||
| 52 | [GH_macway]: http://geekhack.org/showwiki.php?title=Island:11930 | 54 | [GH_macway]: http://geekhack.org/showwiki.php?title=Island:11930 |
| 53 | [GH_hhkb]: http://geekhack.org/showwiki.php?title=Island:12047 | 55 | [GH_hhkb]: http://geekhack.org/showwiki.php?title=Island:12047 |
| @@ -63,6 +63,11 @@ ifdef SLEEP_LED_ENABLE | |||
| 63 | OPT_DEFS += -DNO_SUSPEND_POWER_DOWN | 63 | OPT_DEFS += -DNO_SUSPEND_POWER_DOWN |
| 64 | endif | 64 | endif |
| 65 | 65 | ||
| 66 | ifdef BACKLIGHT_ENABLE | ||
| 67 | SRC += $(COMMON_DIR)/backlight.c | ||
| 68 | OPT_DEFS += -DBACKLIGHT_ENABLE | ||
| 69 | endif | ||
| 70 | |||
| 66 | 71 | ||
| 67 | # Search Path | 72 | # Search Path |
| 68 | VPATH += $(TOP_DIR)/common | 73 | VPATH += $(TOP_DIR)/common |
diff --git a/common/action.c b/common/action.c index c7c8f71f2..b1fa0e31c 100644 --- a/common/action.c +++ b/common/action.c | |||
| @@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 20 | #include "mousekey.h" | 20 | #include "mousekey.h" |
| 21 | #include "command.h" | 21 | #include "command.h" |
| 22 | #include "led.h" | 22 | #include "led.h" |
| 23 | #include "backlight.h" | ||
| 23 | #include "action_layer.h" | 24 | #include "action_layer.h" |
| 24 | #include "action_tapping.h" | 25 | #include "action_tapping.h" |
| 25 | #include "action_oneshot.h" | 26 | #include "action_oneshot.h" |
| @@ -292,6 +293,26 @@ void process_action(keyrecord_t *record) | |||
| 292 | action_macro_play(action_get_macro(record, action.func.id, action.func.opt)); | 293 | action_macro_play(action_get_macro(record, action.func.id, action.func.opt)); |
| 293 | break; | 294 | break; |
| 294 | #endif | 295 | #endif |
| 296 | #ifdef BACKLIGHT_ENABLE | ||
| 297 | case ACT_BACKLIGHT: | ||
| 298 | if (!event.pressed) { | ||
| 299 | switch (action.backlight.id) { | ||
| 300 | case BACKLIGHT_INCREASE: | ||
| 301 | backlight_increase(); | ||
| 302 | break; | ||
| 303 | case BACKLIGHT_DECREASE: | ||
| 304 | backlight_decrease(); | ||
| 305 | break; | ||
| 306 | case BACKLIGHT_TOGGLE: | ||
| 307 | backlight_toggle(); | ||
| 308 | break; | ||
| 309 | case BACKLIGHT_STEP: | ||
| 310 | backlight_step(); | ||
| 311 | break; | ||
| 312 | } | ||
| 313 | } | ||
| 314 | break; | ||
| 315 | #endif | ||
| 295 | case ACT_COMMAND: | 316 | case ACT_COMMAND: |
| 296 | break; | 317 | break; |
| 297 | #ifndef NO_ACTION_FUNCTION | 318 | #ifndef NO_ACTION_FUNCTION |
diff --git a/common/action_code.h b/common/action_code.h index 0933dce13..2272091cc 100644 --- a/common/action_code.h +++ b/common/action_code.h | |||
| @@ -85,6 +85,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 85 | * 1100|opt | id(8) Macro play? | 85 | * 1100|opt | id(8) Macro play? |
| 86 | * 1100|1111| id(8) Macro record? | 86 | * 1100|1111| id(8) Macro record? |
| 87 | * | 87 | * |
| 88 | * ACT_BACKLIGHT(1101): | ||
| 89 | * 1101|xxxx| id(8) Backlight commands | ||
| 90 | * | ||
| 88 | * ACT_COMMAND(1110): | 91 | * ACT_COMMAND(1110): |
| 89 | * 1110|opt | id(8) Built-in Command exec | 92 | * 1110|opt | id(8) Built-in Command exec |
| 90 | * | 93 | * |
| @@ -109,6 +112,7 @@ enum action_kind_id { | |||
| 109 | ACT_LAYER_TAP1 = 0b1011, | 112 | ACT_LAYER_TAP1 = 0b1011, |
| 110 | /* Extensions */ | 113 | /* Extensions */ |
| 111 | ACT_MACRO = 0b1100, | 114 | ACT_MACRO = 0b1100, |
| 115 | ACT_BACKLIGHT = 0b1101, | ||
| 112 | ACT_COMMAND = 0b1110, | 116 | ACT_COMMAND = 0b1110, |
| 113 | ACT_FUNCTION = 0b1111 | 117 | ACT_FUNCTION = 0b1111 |
| 114 | }; | 118 | }; |
| @@ -157,6 +161,9 @@ typedef union { | |||
| 157 | uint8_t page :2; | 161 | uint8_t page :2; |
| 158 | uint8_t kind :4; | 162 | uint8_t kind :4; |
| 159 | } usage; | 163 | } usage; |
| 164 | struct action_backlight { | ||
| 165 | uint8_t id :8; | ||
| 166 | } backlight; | ||
| 160 | struct action_command { | 167 | struct action_command { |
| 161 | uint8_t id :8; | 168 | uint8_t id :8; |
| 162 | uint8_t opt :4; | 169 | uint8_t opt :4; |
| @@ -272,10 +279,21 @@ enum layer_pram_tap_op { | |||
| 272 | /* | 279 | /* |
| 273 | * Extensions | 280 | * Extensions |
| 274 | */ | 281 | */ |
| 282 | enum backlight_id { | ||
| 283 | BACKLIGHT_INCREASE = 0, | ||
| 284 | BACKLIGHT_DECREASE = 1, | ||
| 285 | BACKLIGHT_TOGGLE = 2, | ||
| 286 | BACKLIGHT_STEP = 3, | ||
| 287 | }; | ||
| 275 | /* Macro */ | 288 | /* Macro */ |
| 276 | #define ACTION_MACRO(id) ACTION(ACT_MACRO, (id)) | 289 | #define ACTION_MACRO(id) ACTION(ACT_MACRO, (id)) |
| 277 | #define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP<<8 | (id)) | 290 | #define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP<<8 | (id)) |
| 278 | #define ACTION_MACRO_OPT(id, opt) ACTION(ACT_MACRO, (opt)<<8 | (id)) | 291 | #define ACTION_MACRO_OPT(id, opt) ACTION(ACT_MACRO, (opt)<<8 | (id)) |
| 292 | /* Backlight */ | ||
| 293 | #define ACTION_BACKLIGHT_INCREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_INCREASE) | ||
| 294 | #define ACTION_BACKLIGHT_DECREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_DECREASE) | ||
| 295 | #define ACTION_BACKLIGHT_TOGGLE() ACTION(ACT_BACKLIGHT, BACKLIGHT_TOGGLE) | ||
| 296 | #define ACTION_BACKLIGHT_STEP() ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP) | ||
| 279 | /* Command */ | 297 | /* Command */ |
| 280 | #define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (addr)) | 298 | #define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (addr)) |
| 281 | /* Function */ | 299 | /* Function */ |
diff --git a/common/backlight.c b/common/backlight.c new file mode 100644 index 000000000..00dc04a07 --- /dev/null +++ b/common/backlight.c | |||
| @@ -0,0 +1,77 @@ | |||
| 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 "backlight.h" | ||
| 19 | #include "eeconfig.h" | ||
| 20 | #include "debug.h" | ||
| 21 | |||
| 22 | backlight_config_t backlight_config; | ||
| 23 | |||
| 24 | void backlight_init(void) | ||
| 25 | { | ||
| 26 | /* check signature */ | ||
| 27 | if (!eeconfig_is_enabled()) { | ||
| 28 | eeconfig_init(); | ||
| 29 | } | ||
| 30 | backlight_config.raw = eeconfig_read_backlight(); | ||
| 31 | backlight_set(backlight_config.enable ? backlight_config.level : 0); | ||
| 32 | } | ||
| 33 | |||
| 34 | void backlight_increase(void) | ||
| 35 | { | ||
| 36 | if(backlight_config.level < BACKLIGHT_LEVELS) | ||
| 37 | { | ||
| 38 | backlight_config.level++; | ||
| 39 | backlight_config.enable = 1; | ||
| 40 | eeconfig_write_backlight(backlight_config.raw); | ||
| 41 | } | ||
| 42 | dprintf("backlight increase: %u\n", backlight_config.level); | ||
| 43 | backlight_set(backlight_config.level); | ||
| 44 | } | ||
| 45 | |||
| 46 | void backlight_decrease(void) | ||
| 47 | { | ||
| 48 | if(backlight_config.level > 0) | ||
| 49 | { | ||
| 50 | backlight_config.level--; | ||
| 51 | backlight_config.enable = !!backlight_config.level; | ||
| 52 | eeconfig_write_backlight(backlight_config.raw); | ||
| 53 | } | ||
| 54 | dprintf("backlight decrease: %u\n", backlight_config.level); | ||
| 55 | backlight_set(backlight_config.level); | ||
| 56 | } | ||
| 57 | |||
| 58 | void backlight_toggle(void) | ||
| 59 | { | ||
| 60 | backlight_config.enable ^= 1; | ||
| 61 | eeconfig_write_backlight(backlight_config.raw); | ||
| 62 | dprintf("backlight toggle: %u\n", backlight_config.enable); | ||
| 63 | backlight_set(backlight_config.enable ? backlight_config.level : 0); | ||
| 64 | } | ||
| 65 | |||
| 66 | void backlight_step(void) | ||
| 67 | { | ||
| 68 | backlight_config.level++; | ||
| 69 | if(backlight_config.level > BACKLIGHT_LEVELS) | ||
| 70 | { | ||
| 71 | backlight_config.level = 0; | ||
| 72 | } | ||
| 73 | backlight_config.enable = !!backlight_config.level; | ||
| 74 | eeconfig_write_backlight(backlight_config.raw); | ||
| 75 | dprintf("backlight step: %u\n", backlight_config.level); | ||
| 76 | backlight_set(backlight_config.level); | ||
| 77 | } | ||
diff --git a/common/backlight.h b/common/backlight.h new file mode 100644 index 000000000..685c422ae --- /dev/null +++ b/common/backlight.h | |||
| @@ -0,0 +1,41 @@ | |||
| 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 BACKLIGHT_H | ||
| 19 | #define BACKLIGHT_H | ||
| 20 | |||
| 21 | #include <stdint.h> | ||
| 22 | #include <stdbool.h> | ||
| 23 | |||
| 24 | typedef union { | ||
| 25 | uint8_t raw; | ||
| 26 | struct { | ||
| 27 | bool enable:1; | ||
| 28 | uint8_t level:7; | ||
| 29 | }; | ||
| 30 | } backlight_config_t; | ||
| 31 | |||
| 32 | void backlight_init(void); | ||
| 33 | |||
| 34 | void backlight_increase(void); | ||
| 35 | void backlight_decrease(void); | ||
| 36 | void backlight_toggle(void); | ||
| 37 | void backlight_step(void); | ||
| 38 | |||
| 39 | void backlight_set(uint8_t level); | ||
| 40 | |||
| 41 | #endif | ||
diff --git a/common/command.c b/common/command.c index 73a72b4a1..4649e00ab 100644 --- a/common/command.c +++ b/common/command.c | |||
| @@ -31,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 31 | #include "sleep_led.h" | 31 | #include "sleep_led.h" |
| 32 | #include "led.h" | 32 | #include "led.h" |
| 33 | #include "command.h" | 33 | #include "command.h" |
| 34 | #include "backlight.h" | ||
| 34 | 35 | ||
| 35 | #ifdef MOUSEKEY_ENABLE | 36 | #ifdef MOUSEKEY_ENABLE |
| 36 | #include "mousekey.h" | 37 | #include "mousekey.h" |
| @@ -149,6 +150,14 @@ static void print_eeconfig(void) | |||
| 149 | print(".no_gui: "); print_dec(kc.no_gui); print("\n"); | 150 | print(".no_gui: "); print_dec(kc.no_gui); print("\n"); |
| 150 | print(".swap_grave_esc: "); print_dec(kc.swap_grave_esc); print("\n"); | 151 | print(".swap_grave_esc: "); print_dec(kc.swap_grave_esc); print("\n"); |
| 151 | print(".swap_backslash_backspace: "); print_dec(kc.swap_backslash_backspace); print("\n"); | 152 | print(".swap_backslash_backspace: "); print_dec(kc.swap_backslash_backspace); print("\n"); |
| 153 | |||
| 154 | #ifdef BACKLIGHT_ENABLE | ||
| 155 | backlight_config_t bc; | ||
| 156 | bc.raw = eeconfig_read_backlight(); | ||
| 157 | print("backlight_config.raw: "); print_hex8(bc.raw); print("\n"); | ||
| 158 | print(".enable: "); print_dec(bc.enable); print("\n"); | ||
| 159 | print(".level: "); print_dec(bc.level); print("\n"); | ||
| 160 | #endif | ||
| 152 | } | 161 | } |
| 153 | #endif | 162 | #endif |
| 154 | 163 | ||
diff --git a/common/eeconfig.c b/common/eeconfig.c index a833f4db9..5bd47dc6a 100644 --- a/common/eeconfig.c +++ b/common/eeconfig.c | |||
| @@ -10,6 +10,9 @@ void eeconfig_init(void) | |||
| 10 | eeprom_write_byte(EECONFIG_DEFAULT_LAYER, 0); | 10 | eeprom_write_byte(EECONFIG_DEFAULT_LAYER, 0); |
| 11 | eeprom_write_byte(EECONFIG_KEYMAP, 0); | 11 | eeprom_write_byte(EECONFIG_KEYMAP, 0); |
| 12 | eeprom_write_byte(EECONFIG_MOUSEKEY_ACCEL, 0); | 12 | eeprom_write_byte(EECONFIG_MOUSEKEY_ACCEL, 0); |
| 13 | #ifdef BACKLIGHT_ENABLE | ||
| 14 | eeprom_write_byte(EECONFIG_BACKLIGHT, 0); | ||
| 15 | #endif | ||
| 13 | } | 16 | } |
| 14 | 17 | ||
| 15 | void eeconfig_enable(void) | 18 | void eeconfig_enable(void) |
| @@ -35,3 +38,8 @@ void eeconfig_write_default_layer(uint8_t val) { eeprom_write_byte(EECONFIG_DEFA | |||
| 35 | 38 | ||
| 36 | uint8_t eeconfig_read_keymap(void) { return eeprom_read_byte(EECONFIG_KEYMAP); } | 39 | uint8_t eeconfig_read_keymap(void) { return eeprom_read_byte(EECONFIG_KEYMAP); } |
| 37 | void eeconfig_write_keymap(uint8_t val) { eeprom_write_byte(EECONFIG_KEYMAP, val); } | 40 | void eeconfig_write_keymap(uint8_t val) { eeprom_write_byte(EECONFIG_KEYMAP, val); } |
| 41 | |||
| 42 | #ifdef BACKLIGHT_ENABLE | ||
| 43 | uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); } | ||
| 44 | void eeconfig_write_backlight(uint8_t val) { eeprom_write_byte(EECONFIG_BACKLIGHT, val); } | ||
| 45 | #endif | ||
diff --git a/common/eeconfig.h b/common/eeconfig.h index 0b605fc7b..e1b5ae282 100644 --- a/common/eeconfig.h +++ b/common/eeconfig.h | |||
| @@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 19 | #define EECONFIG_H | 19 | #define EECONFIG_H |
| 20 | 20 | ||
| 21 | #include <stdint.h> | 21 | #include <stdint.h> |
| 22 | #include <stdbool.h> | ||
| 22 | 23 | ||
| 23 | 24 | ||
| 24 | #define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEED | 25 | #define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEED |
| @@ -29,6 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 29 | #define EECONFIG_DEFAULT_LAYER (uint8_t *)3 | 30 | #define EECONFIG_DEFAULT_LAYER (uint8_t *)3 |
| 30 | #define EECONFIG_KEYMAP (uint8_t *)4 | 31 | #define EECONFIG_KEYMAP (uint8_t *)4 |
| 31 | #define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5 | 32 | #define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5 |
| 33 | #define EECONFIG_BACKLIGHT (uint8_t *)6 | ||
| 32 | 34 | ||
| 33 | 35 | ||
| 34 | /* debug bit */ | 36 | /* debug bit */ |
| @@ -64,4 +66,9 @@ void eeconfig_write_default_layer(uint8_t val); | |||
| 64 | uint8_t eeconfig_read_keymap(void); | 66 | uint8_t eeconfig_read_keymap(void); |
| 65 | void eeconfig_write_keymap(uint8_t val); | 67 | void eeconfig_write_keymap(uint8_t val); |
| 66 | 68 | ||
| 69 | #ifdef BACKLIGHT_ENABLE | ||
| 70 | uint8_t eeconfig_read_backlight(void); | ||
| 71 | void eeconfig_write_backlight(uint8_t val); | ||
| 72 | #endif | ||
| 73 | |||
| 67 | #endif | 74 | #endif |
diff --git a/common/keyboard.c b/common/keyboard.c index 6bc6fae6e..d1821a099 100644 --- a/common/keyboard.c +++ b/common/keyboard.c | |||
| @@ -31,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 31 | #include "bootmagic.h" | 31 | #include "bootmagic.h" |
| 32 | #include "eeconfig.h" | 32 | #include "eeconfig.h" |
| 33 | #include "mousekey.h" | 33 | #include "mousekey.h" |
| 34 | #include "backlight.h" | ||
| 34 | 35 | ||
| 35 | 36 | ||
| 36 | #ifdef MATRIX_HAS_GHOST | 37 | #ifdef MATRIX_HAS_GHOST |
| @@ -65,6 +66,10 @@ void keyboard_init(void) | |||
| 65 | #ifdef BOOTMAGIC_ENABLE | 66 | #ifdef BOOTMAGIC_ENABLE |
| 66 | bootmagic(); | 67 | bootmagic(); |
| 67 | #endif | 68 | #endif |
| 69 | |||
| 70 | #ifdef BACKLIGHT_ENABLE | ||
| 71 | backlight_init(); | ||
| 72 | #endif | ||
| 68 | } | 73 | } |
| 69 | 74 | ||
| 70 | /* | 75 | /* |
diff --git a/common/suspend.c b/common/suspend.c index 6029fe7ff..146b96d5c 100644 --- a/common/suspend.c +++ b/common/suspend.c | |||
| @@ -1,10 +1,14 @@ | |||
| 1 | #include "suspend.h" | 1 | #include "suspend.h" |
| 2 | #include "matrix.h" | 2 | #include "matrix.h" |
| 3 | #include "action.h" | 3 | #include "action.h" |
| 4 | #include "backlight.h" | ||
| 4 | 5 | ||
| 5 | 6 | ||
| 6 | void suspend_power_down(void) | 7 | void suspend_power_down(void) |
| 7 | { | 8 | { |
| 9 | #ifdef BACKLIGHT_ENABLE | ||
| 10 | backlight_set(0); | ||
| 11 | #endif | ||
| 8 | #ifndef NO_SUSPEND_POWER_DOWN | 12 | #ifndef NO_SUSPEND_POWER_DOWN |
| 9 | // Enable watchdog to wake from MCU sleep | 13 | // Enable watchdog to wake from MCU sleep |
| 10 | cli(); | 14 | cli(); |
| @@ -50,6 +54,9 @@ void suspend_wakeup_init(void) | |||
| 50 | // clear matrix and keyboard state | 54 | // clear matrix and keyboard state |
| 51 | matrix_init(); | 55 | matrix_init(); |
| 52 | clear_keyboard(); | 56 | clear_keyboard(); |
| 57 | #ifdef BACKLIGHT_ENABLE | ||
| 58 | backlight_init(); | ||
| 59 | #endif | ||
| 53 | } | 60 | } |
| 54 | 61 | ||
| 55 | #ifndef NO_SUSPEND_POWER_DOWN | 62 | #ifndef NO_SUSPEND_POWER_DOWN |
diff --git a/doc/build.md b/doc/build.md index 88504f096..ae8565010 100644 --- a/doc/build.md +++ b/doc/build.md | |||
| @@ -132,6 +132,7 @@ Optional. Note that ***comment out*** to disable them. | |||
| 132 | COMMAND_ENABLE = yes # Commands for debug and configuration | 132 | COMMAND_ENABLE = yes # Commands for debug and configuration |
| 133 | SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend | 133 | SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend |
| 134 | #NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA | 134 | #NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA |
| 135 | #BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality | ||
| 135 | 136 | ||
| 136 | ### 3. Programmer | 137 | ### 3. Programmer |
| 137 | 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 `Teesy Loader`. | 138 | 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 `Teesy Loader`. |
diff --git a/doc/keymap.md b/doc/keymap.md index 474a706e0..7d979eb7c 100644 --- a/doc/keymap.md +++ b/doc/keymap.md | |||
| @@ -430,6 +430,27 @@ See `keyboard/hhkb/keymap.c` for sample. | |||
| 430 | 430 | ||
| 431 | 431 | ||
| 432 | 432 | ||
| 433 | ### 2.5 Backlight Action | ||
| 434 | These actions control the backlight. | ||
| 435 | |||
| 436 | #### 2.5.1 Change backlight level | ||
| 437 | Increase backlight level. | ||
| 438 | |||
| 439 | ACTION_BACKLIGHT_INCREASE() | ||
| 440 | |||
| 441 | Decrease backlight level. | ||
| 442 | |||
| 443 | ACTION_BACKLIGHT_DECREASE() | ||
| 444 | |||
| 445 | Step through backlight levels. | ||
| 446 | |||
| 447 | ACTION_BACKLIGHT_STEP() | ||
| 448 | |||
| 449 | #### 2.5.2 Turn on / off backlight | ||
| 450 | Turn the backlight on and off without changing level. | ||
| 451 | |||
| 452 | ACTION_BACKLIGHT_TOGGLE() | ||
| 453 | |||
| 433 | 454 | ||
| 434 | 455 | ||
| 435 | ## 3. Layer switching Example | 456 | ## 3. Layer switching Example |
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 | } | ||
